gnome-shell-extensions-negesti icon indicating copy to clipboard operation
gnome-shell-extensions-negesti copied to clipboard

don't lose focus when focus follows mouse is enabled

Open wbolster opened this issue 7 years ago • 11 comments

would it be possible to force the window that i just moved to keep focus?

right now, when i move a window using a keyboard shortcut, and the window resizes in such a way that the mouse cursor is no longer inside the window's frame, the window loses focus. i assume this happens because i use "focus follows mouse".

this is annoying, since i now need to switch (super-tab) back to the window that i just moved (and which already had focus), depending on the mouse position (which i usually don't know since i was using the keyboard).

wbolster avatar Sep 12 '16 09:09 wbolster

Just tried to add "re focus" the window after it was moved but with "focus follows mouse" the focus immediately jumps 'back'. I guess that would only be possible if the extension moves the mouse when a window is moved

negesti avatar Sep 12 '16 14:09 negesti

conceptually, it is possible to have the mouse pointer outside the window, even with focus follows mouse, since that's what happens when alt-tab is used. perhaps something else (order of events?) cause the "jump back" behaviour?

otherwise, moving the mouse pointer within the new bounds would be perfectly acceptable. the window moves on the screen, so the pointer needs repositioning anyway before it can be used in a meaningful way. moving it inside the new bounds would even reduce the travel distance.

wbolster avatar Sep 12 '16 16:09 wbolster

First of all, you are absolutely right this is really annoying when follow mouse is enabled.

I tried multiple ways to (re-)focus the moved window (Main.activateWindow, MetaWindow.focus, MetaWindow.activate). All of them can be used to change focus a window. At least using looking glass.

MetaWindow has a number of events (signals) including position-changed and size-changed. Unfortunately it seems to be to early to re-focus the moved window inside this event listeners. There is no "unfocus" signal which would be the easiest way.

The pnly remaining option I can think about is kind of a delay call inside the event listener of the resize/move event.

Maybe @73 can help us here. He developed the "move focus" feature.

negesti avatar Sep 12 '16 17:09 negesti

so meta_window_focus() does not work (with current timestamp)? that's unfortunate.

did you try the hacky way: a timeout function that refocuses after 0.1 second? :disappointed:

wbolster avatar Sep 13 '16 12:09 wbolster

what about .activate()?

https://github.com/negesti/gnome-shell-extensions-negesti/blob/develop/moveFocus.js#L161-L166

wbolster avatar Sep 13 '16 12:09 wbolster

@wbolster are you still using the extension? if not i will close this issue

negesti avatar Nov 24 '16 18:11 negesti

yes i still use it. and why would you close it? it has not been resolved after all. better to leave issues open and visible for others to avoid duplicates or even encourage contributors...

wbolster avatar Nov 28 '16 02:11 wbolster

Thanks for your feedback. I just wanted to know, if someone is using the extension with focus follows mouse. The bug is not really easy to fix. I hope I can fix this, once 3.22 is fully supported. Maybe 3.22 allows us to move the mouse :)

negesti avatar Nov 28 '16 20:11 negesti

I'm also using focus follows mouse and unfortunately this extension doesn't play nice with it.

I have a suggestion for a workaround.

Instead of trying to keep the focus on the window that was moved, record the last position of the mouse.

If the last position of the mouse hasn't changed since this extension was used to change a window, we can say that the user hasn't actively used the mouse to change the focus.

Therefore we can simply ignore the change in focus and thus this extension can simply continue to operate on the same window until the cursor position has changed.

tobimensch avatar Jul 18 '17 08:07 tobimensch

Changes of focus induced by another user interaction such as some key combination like alt tab would also have to be taken into account by this workaround to be consistent.

tobimensch avatar Jul 18 '17 08:07 tobimensch

In the mean time I found a hack, that solves the problem, if you can live with the mouse following the window. I call this the mouse follows window feature:

You need to have xdotool installed. This will only work on X.

Put the following line in the top of extension.js:

const Util = imports.misc.util;

Put the following line as the last line of _resize: function, which should be approximately line 800: Util.spawn(['/usr/bin/xdotool', 'mousemove', (targetRectangle.x + targetRectangle.width/2).toString(), (targetRectangle.y + targetRectangle.height/2).toString()]);

Put the following line as the second to last line of _moveToCornerKeepSize: function, before the return line, which is approximately line 560: Util.spawn(['/usr/bin/xdotool', 'mousemove', (x + pos.width/2).toString(), (y + pos.height/2).toString()]);

Maybe someone can turn this into an option in the preference dialog.

tobimensch avatar Jul 18 '17 15:07 tobimensch