how to move or resize x11 windows (even if they are maximized)?

  • Last Update :
  • Techknowledgy :

Thanks to n.m. comment I found a solution. Here are relevant parts from my python script (it saves and restores state and geometry of all windows, so this example unmaximizes, unmaps and maps all windows):

from time
import sleep
from ewmh
import EWMH
from Xlib
import display, protocol, X
from Xlib.protocol.request
import *
...
ewmh = EWMH()
disp = display.Display()
poll_interval = 0.025 # s
poll_attempts_limit = 10
   ...
   def unmaximize(window):
   ewmh.setWmState(window, 0, "_NET_WM_STATE_MAXIMIZED_VERT")
ewmh.setWmState(window, 0, "_NET_WM_STATE_MAXIMIZED_HORZ")
   ...
   for client in all_win:
   unmaximize(client.window)
ewmh.display.flush()
for client in all_win:
   client.xwin.unmap()
poll_attempts = 0
for client in all_win:
   while client.xwin.get_attributes().map_state == X.IsViewable\
and poll_attempts < poll_attempts_limit:
   sleep(poll_interval)
poll_attempts += 1
for client in all_win:
   client.xwin.map()
poll_attempts = 0
for client in all_win:
   while client.xwin.get_attributes().map_state != X.IsViewable\
and poll_attempts < poll_attempts_limit:
   sleep(poll_interval)
poll_attempts += 1

If you do not want to reconfigure a lot of windows at once, there is no noticeable performance improvement from using python xlib module for unmapping and mapping, it is easier to use xdotool instead:

from os
import system
   ...
   system("xdotool windowunmap --sync " + str(client.window.id))
system("xdotool windowmap   --sync " + str(client.window.id))

If you want to set window geometry in shell script the following example should work even if the window is maximized:

wmctrl - i - r $WID - b remove, maximized_vert, maximized_horz
xdotool windowunmap--sync $WID
xdotool windowmap--sync $WID
wmctrl - i - r $WID - e 0, $x, $y, $width, $height

Suggestion : 2

Thanks to n.m. comment I found a solution. Here are relevant parts from my python script (it saves and restores state and geometry of all windows, so this example unmaximizes, unmaps and maps all windows):,If you want to set window geometry in shell script the following example should work even if the window is maximized:,If you do not want to reconfigure a lot of windows at once, there is no noticeable performance improvement from using python xlib module for unmapping and mapping, it is easier to use xdotool instead:,After executing this code it is possible to set window geometry for any window. all_win is a list of all windows represented as list of custom class objects populated with data from ewmh.getClientList(). Each client.xwin = disp.create_resource_object("window", client.id). Waiting for mapping/unmapping to finish is important, otherwise it will be unreliable. Also, it is necessary to limit poll attempts to prevent infinite loop in case some window gets mapped or unmapped unexpectedly.

Thanks to n.m. comment I found a solution. Here are relevant parts from my python script (it saves and restores state and geometry of all windows, so this example unmaximizes, unmaps and maps all windows):

from time
import sleepfrom ewmh
import EWMHfrom Xlib
import display, protocol, Xfrom Xlib.protocol.request
import * ...ewmh = EWMH() disp = display.Display() poll_interval = 0.025 # spoll_attempts_limit = 10...def unmaximize(window): ewmh.setWmState(window, 0, "_NET_WM_STATE_MAXIMIZED_VERT") ewmh.setWmState(window, 0, "_NET_WM_STATE_MAXIMIZED_HORZ")...
   for client in all_win: unmaximize(client.window) ewmh.display.flush() for client in all_win: client.xwin.unmap() poll_attempts = 0
for client in all_win: while client.xwin.get_attributes().map_state == X.IsViewable\ and poll_attempts < poll_attempts_limit: sleep(poll_interval) poll_attempts += 1
for client in all_win: client.xwin.map() poll_attempts = 0
for client in all_win: while client.xwin.get_attributes().map_state != X.IsViewable\ and poll_attempts < poll_attempts_limit: sleep(poll_interval) poll_attempts += 1

If you do not want to reconfigure a lot of windows at once, there is no noticeable performance improvement from using python xlib module for unmapping and mapping, it is easier to use xdotool instead:

from os
import system...system("xdotool windowunmap --sync " + str(client.window.id)) system("xdotool windowmap   --sync " + str(client.window.id))

If you want to set window geometry in shell script the following example should work even if the window is maximized:

wmctrl - i - r $WID - b remove, maximized_vert, maximized_horzxdotool windowunmap--sync $WIDxdotool windowmap--sync $WIDwmctrl - i - r $WID - e 0, $x, $y, $width, $height

Suggestion : 3

Note: The size of top-level widgets are constrained to 2/3 of the desktop's height and width. You can resize() the widget manually if these bounds are inadequate.,This function uses sizeHint() if it is valid, i.e., the size hint's width and height are >= 0. Otherwise, it sets the size to the children rectangle that covers all child widgets (the union of all child widget rectangles).,Restores the geometry and state of top-level widgets stored in the byte array geometry. Returns true on success; otherwise returns false.,Sets the size policy of the widget to horizontal and vertical, with standard stretch and no height-for-width.

setCursor(Qt::IBeamCursor);
width = baseSize().width() + i * sizeIncrement().width();
height = baseSize().height() + j * sizeIncrement().height();
setUpdatesEnabled(false);
bigVisualChanges();
setUpdatesEnabled(true);
void MainWindow::closeEvent(QCloseEvent * event) {
   if (maybeSave()) {
      writeSettings();
      event - > accept();
   } else {
      event - > ignore();
   }
}
QPixmap pixmap(widget - > size());
widget - > render( & pixmap);
QPainter painter(this);
...
painter.end();
myWidget - > render(this);