ewmh_m2m icon indicating copy to clipboard operation
ewmh_m2m copied to clipboard

focus window after moving

Open andrei-a-papou opened this issue 5 years ago • 8 comments

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.

andrei-a-papou avatar Nov 05 '19 18:11 andrei-a-papou

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:

  • What is your xfwm version? (see below)
  • What is your screen setup? (even if it should not impact the behavior)
  • When does your lose the focus? (which application, how many (other) windows, etc.)
  • What is your focus behavior? (xfce4-settings-manager > Window Manager > Focus, Window Manager Tweaks > Focus)

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

AlexisBRENON avatar Nov 06 '19 07:11 AlexisBRENON

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 avatar Nov 17 '19 10:11 andrei-a-papou

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 avatar Nov 17 '19 10:11 andrei-a-papou

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!

andrei-a-papou avatar Nov 17 '19 10:11 andrei-a-papou

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

  • If after moving the window your mouse hover another window, this one get the focus;
  • If after moving the window your mouse hover the desktop, the moved window keep the focus.
  • There probably are other combinations, but I gave up to test them all.

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 avatar Nov 18 '19 13:11 AlexisBRENON

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.

AlexisBRENON avatar Jan 08 '20 08:01 AlexisBRENON

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

andrei-a-papou avatar Feb 24 '20 19:02 andrei-a-papou

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

xpufx avatar Apr 15 '22 16:04 xpufx