AlexisBRENON / ewmh_m2m

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

focus window after moving #4

Closed andrei-a-papou closed 3 months ago

andrei-a-papou commented 4 years ago

I'm running this tool under Xfce, and the windows lose focus after being moved to the other monitor. Sometimes this is desirable, sometimes not.

It would be nice to be able to optionally re-focus the window after moving it.

Currently running this via a shell wrapper (move-to-monitor is installed in a virtualenv and the env needs to be activated), so it's easy to add something like xdotool windowfocus --sync "$window_id" to the script. But a native python solution would be nicer and less hackish, IMO.

Thanks.

AlexisBRENON commented 4 years ago

I also use Xfce and I do not experience this problem (the moved window always keep the focus). This is the expected behavior, following the one when you move a window to another workspace, or around your desktop.

Can you make the bug more reproducible:

By the way, what is the use case to "lose the focus while moving". While not particularly hard to implement such option, it would make the code more complicated and require to make a choice: which window to focus?

Thanks.

$ xfwm4 --version

    This is xfwm4 version 4.14.0 (revision ed87ef663) for Xfce 4.14
    Released under the terms of the GNU General Public License.
    Compiled against GTK+-3.24.10, using GTK+-3.24.12.

    Build configuration and supported features:
    - Startup notification support:                 Yes
    - XSync support:                                Yes
    - Render support:                               Yes
    - Xrandr support:                               Yes
    - Xpresent support:                             Yes
    - Embedded compositor:                          Yes
    - Epoxy support:                                Yes
    - KDE systray proxy (deprecated):               No
andrei-a-papou commented 4 years ago

Sorry for the delay.

Xfwm info:

xfwm4 --version
    This is xfwm4 version 4.12.4 (revision 7844952) for Xfce 4.12
    Released under the terms of the GNU General Public License.
    Compiled against GTK+-2.24.31, using GTK+-2.24.31.

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

Typical screen setup: image (1366x768 laptop screen plus a 1920x1080 external monitor)

When do you lose focus? Hard to see a straight pattern, seems to happen when I move the window on top of another (already focused) window. However, I don't use Xfwm's focus-stealing prevention (see below).

What is your focus behavior? image image

Thanks!

andrei-a-papou commented 4 years ago

By the way, what is the use case to "lose the focus while moving".

I believe this is similar to moving a window to a different workspace without switching to the workspace itself. Kinda like moving the window out of the way for the time being.

Let's say I have two windows on my laptop screen. One window is key to my current work, the other is just a reference window I need to look at from time to time.

In this scenario I think it'd be useful to move the reference window to another monitor and then re-focus the primary window (or not lose the primary window's focus in the first place).

Currently I hit Super+Enter to move the window to another monitor and then Super-Alt to switch back to the previous window.

While not particularly hard to implement such option, it would make the code more complicated and require to make a choice: which window to focus?

Perhaps one solution would be to focus the previously focused window?

andrei-a-papou commented 4 years ago

By the way, I've been using ewmh_m2m for some time now, and really like it! Great job and keep up the good work, Alexis!

AlexisBRENON commented 4 years ago

From what I can see you choose the "Focus follows mouse" option. With this activated, I can reproduce the behavior:

So I can try to explictly give the focus to the moved window (which I expect to be the default behavior). Implementing the other behavior may be a little bit tricky (I don't know if there is a simple way to retrieve the last focused window...). I'll take a look, so stay tuned.

By the way, thanks you!

AlexisBRENON commented 4 years ago

Thanks for the patience.

I try to play with the ACTIVE_WINDOW and STATE_FOCUSED properties of the window but without great success from my point of view.

Let's give a try to the related branch, and let me know if it matches your expectations.

From the documentation, I understand that it is the ACTIVE_WINDOW property that have to be set. However, I suppose that even if I set it correctly, the window manager make a new check after my own call, and thus change the active window after me.

andrei-a-papou commented 4 years ago

I tested the focus_management branch (installed in a virtual env using pip install .). It produces inconsistent results -- sometimes the window I move gets the focus, and sometimes it's another window.

So for now I went back to my hackish solution:

window_id="$(xdotool getactivewindow)"

move-to-monitor

# focus the window:
wmctrl -i -a "$window_id"
sleep 0.5
xdotool windowfocus --sync "$window_id"

This works with no issues. Alexis, it's no big deal, really. If you can emulate the shell code above in Python and provide a CLI switch (like --focus), that would be great. If not -- no big deal, it's just a focus quirk, I can easily work around it.

Thanks, Andrei

xpufx commented 2 years ago

https://github.com/calandoa/movescreen is able to do this with the 'm|mouse' option.