AlexisBRENON / ewmh_m2m

EWMH-compliant move to monitor utility
https://pypi.org/project/ewmh-m2m/
MIT License
89 stars 5 forks source link

Not working with some odd setup #27

Closed Jonybat closed 4 days ago

Jonybat commented 1 year ago

Hi

First of all, thanks for this cool program.

I currently have a landscape 1440p monitor and a left rotated 1080p monitor, on the right of the first monitor. I then use xfce tiling feature to tile windows to the top and bottom halves of the vertical 1080p monitor, effectively giving me 2 almost square windows (~1080x960), instead of one huge vertical one.

This program is able to move the windows between the monitors just fine, and it even keeps the window proportions across these very different displays. The problem happens when i try to move one of those tiled windows on the vertical monitor, which is, nothing happens. If i un-tile or maximize the window, it works.

However, this does not happen with most programs (in fact, i was only able to replicate it so far with firefox-esr), so much so, that to gather the debug logs, i had to run this from a remote ssh session.

So, here is the -vvv output of a successful window move (terminator)

DEBUG:ewmh_m2m.__main__:Detected screens: {Geometry(2560, 0, 1080, 1920), Geometry(0, 0, 2560, 1440)}
DEBUG:ewmh_m2m.__main__:Containing screen: Geometry(2560, 0, 1080, 1920)
DEBUG:ewmh_m2m.__main__:New window geometry: Geometry(0, 27, 2560, 720)

...and here is the same for a failed one (firefox-esr). Both windows were tiled in the same exact position

DEBUG:ewmh_m2m.__main__:Detected screens: {Geometry(2560, 0, 1080, 1920), Geometry(0, 0, 2560, 1440)}
DEBUG:ewmh_m2m.__main__:Containing screen: Geometry(2560, 0, 1080, 1920)
DEBUG:ewmh_m2m.__main__:New window geometry: Geometry(-61, -17, 2683, 759)
Traceback (most recent call last):
  File "/usr/local/bin/move-to-monitor", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/dist-packages/ewmh_m2m/__main__.py", line 65, in main
    move_to_screen(args)
  File "/usr/local/lib/python3.9/dist-packages/ewmh_m2m/__main__.py", line 40, in move_to_screen
    win.geometry = new_window_geometry
  File "/usr/local/lib/python3.9/dist-packages/ewmh_m2m/window.py", line 26, in geometry
    xpybutil.window.moveresize(
  File "/usr/local/lib/python3.9/dist-packages/xpybutil/window.py", line 139, in moveresize
    ewmh.request_moveresize_window(win, x=x, y=y, width=max(1, w),
  File "/usr/local/lib/python3.9/dist-packages/xpybutil/ewmh.py", line 990, in request_moveresize_window
    return revent(window, '_NET_MOVERESIZE_WINDOW',
  File "/usr/local/lib/python3.9/dist-packages/xpybutil/event.py", line 82, in root_send_client_event
    packed = pack_client_message(window, message_type, *data)
  File "/usr/local/lib/python3.9/dist-packages/xpybutil/event.py", line 77, in pack_client_message
    return struct.pack('BBH7I', Event.ClientMessageEvent, 32, 0, window,
struct.error: argument out of range

I guess the question here is why is this specific window being resized to a size bigger than the target display.

This is probably hard for you to replicate, so let me know what more info i can gather.

$ xfwm4 --version
    This is xfwm4 version 4.16.1 (revision 5f61a84ad) for Xfce 4.16
    Released under the terms of the GNU General Public License.
    Compiled against GTK+-3.24.24, using GTK+-3.24.24.

    Build configuration and supported features:
    - Startup notification support:                 Yes
    - XSync support:                                Yes
    - Render support:                               Yes
    - Xrandr support:                               Yes
    - Xpresent support:                             Yes
    - X Input 2 support:                            No
    - Embedded compositor:                          Yes
    - Epoxy support:                                Yes
    - KDE systray proxy (deprecated):               No

$ xrandr --listmonitors
Monitors: 2
 0: +*DP2-1 2560/600x1440/340+0+0  DP2-1
 1: +DP2-2 1080/510x1920/290+2560+0  DP2-2
AlexisBRENON commented 1 year ago

Hi.

Interesting bug, thanks for reporting it.

At first sight, I would bet on the window not properly reporting its geometry before the move. Then all the following computation ends with an invalid value and so the error happens.

How confortable are you with writing some Python code ? If you feel confident, you can add some debug statements to track the window geometry along the process (lines 19, 29-30).

Else I will try to do the change and let you know when you can test.

Jonybat commented 1 year ago

Here you go. Same order and windows as before

DEBUG:ewmh_m2m.__main__:Initial window geometry: Geometry(2560, 960, 1080, 960)
DEBUG:ewmh_m2m.__main__:Detected screens: {Geometry(2560, 0, 1080, 1920), Geometry(0, 0, 2560, 1440)}
DEBUG:ewmh_m2m.__main__:Containing screen: Geometry(2560, 0, 1080, 1920)
DEBUG:ewmh_m2m.__main__:Window geometry: Geometry(2560, 960, 1080, 960)
DEBUG:ewmh_m2m.__main__:Relative geometry: Geometry(0.0, 0.5, 1.0, 0.5)
DEBUG:ewmh_m2m.__main__:New window geometry: Geometry(0, 720, 2560, 720)
DEBUG:ewmh_m2m.__main__:Initial window geometry: Geometry(2534, 937, 1132, 1012)
DEBUG:ewmh_m2m.__main__:Detected screens: {Geometry(2560, 0, 1080, 1920), Geometry(0, 0, 2560, 1440)}
DEBUG:ewmh_m2m.__main__:Containing screen: Geometry(2560, 0, 1080, 1920)
DEBUG:ewmh_m2m.__main__:Window geometry: Geometry(2534, 937, 1132, 1012)
DEBUG:ewmh_m2m.__main__:Relative geometry: Geometry(-0.024074074074074074, 0.48802083333333335, 1.048148148148148, 0.5270833333333333)
DEBUG:ewmh_m2m.__main__:New window geometry: Geometry(-61, 702, 2683, 759)
Traceback (most recent call last):
  File "/usr/local/bin/move-to-monitor", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/dist-packages/ewmh_m2m/__main__.py", line 68, in main
    move_to_screen(args)
  File "/usr/local/lib/python3.9/dist-packages/ewmh_m2m/__main__.py", line 43, in move_to_screen
    win.geometry = new_window_geometry
  File "/usr/local/lib/python3.9/dist-packages/ewmh_m2m/window.py", line 26, in geometry
    xpybutil.window.moveresize(
  File "/usr/local/lib/python3.9/dist-packages/xpybutil/window.py", line 139, in moveresize
    ewmh.request_moveresize_window(win, x=x, y=y, width=max(1, w),
  File "/usr/local/lib/python3.9/dist-packages/xpybutil/ewmh.py", line 990, in request_moveresize_window
    return revent(window, '_NET_MOVERESIZE_WINDOW',
  File "/usr/local/lib/python3.9/dist-packages/xpybutil/event.py", line 82, in root_send_client_event
    packed = pack_client_message(window, message_type, *data)
  File "/usr/local/lib/python3.9/dist-packages/xpybutil/event.py", line 77, in pack_client_message
    return struct.pack('BBH7I', Event.ClientMessageEvent, 32, 0, window,
struct.error: argument out of range
AlexisBRENON commented 1 year ago

Thanks for you quick reply. As expected, the reported geometries are not the same and the computations lead to invalid value. I will try to dig in the documentation to understand why we end up with such window geometry.

Anyway, this is the resulting relative geometries:

       │2560                         3640
      ─┼───────────────────────────────┬─►
      0│                               │
       │                               │
       │                               │
       │                               │
       │                               │
       │                               │
       │                               │
       │                               │
       │                               │
       │                               │
       │                               │
       │                               │
   2534│                               │3666
 937┌──┴───────────────────────────────┼──┐
    │  +960                            │  │
    │  │                               │  │
    │  │                               │  │
    │  │                               │  │
    │  │                               │  │
    │  │                               │  │
    │  │                               │  │
    │  │                               │  │
    │  │                               │  │
    │  │                               │  │
    │  │                               │  │
    │  │                               │  │
    │  │                               │  │
   1920├───────────────────────────────┘  │
    │  │                                  │
1949└──┼──────────────────────────────────┘
       │
       ▼

Quick fix: just clamp the relative geometry between 0 and 1. But this will probably not restore the geometry properly. Need some investigations.

AlexisBRENON commented 2 months ago

@Jonybat Do you still need a fix ? Did you find a workaround ?

Jonybat commented 2 months ago

I completely forgot about this. I don't need the fix anymore, since I have switched to kde plasma