negesti / gnome-shell-extensions-negesti

An gnome-shell extension that makes window movement a lot easier.
GNU General Public License v3.0
287 stars 47 forks source link

don't lose focus when focus follows mouse is enabled #107

Open wbolster opened 8 years ago

wbolster commented 8 years ago

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).

negesti commented 8 years ago

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

wbolster commented 8 years ago

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.

negesti commented 8 years ago

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.

wbolster commented 8 years ago

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 commented 8 years ago

what about .activate()?

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

negesti commented 7 years ago

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

wbolster commented 7 years ago

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...

negesti commented 7 years ago

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 :)

tobimensch commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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.