LeonMatthes / mousefollowsfocus

A GNOME extension for a more efficient keyboard driven navigation.
GNU General Public License v3.0
16 stars 8 forks source link

[Feature request] Temporarily deactivate when switching between workspaces #4

Open ghost opened 2 years ago

ghost commented 2 years ago

I had configured Dash to Panel to switch workspace on hover and scroll. With Mouse follow focus installed it became awkward that pointer location changes when trying to switch workspaces continuously.

So I suggest that you add:

ghost commented 2 years ago

i've found this alternate extension which doesn't have the issue i had: Alt-Tab Move Mouse

LeonMatthes commented 2 years ago

I don't think disabling the extension for workspace switches is a road I want to go down. Often times I switch workspaces using Super+1/Super+2 with Dash-To-Dock and in these cases I actually want my cursor to follow the window.

However, I have been playing with the idea of disabling the extension temporarily whenever mouse movement is detected. That way, if you're on the keyboard, the extension will make your mouse follow the keyboard, but if you already have your hands on the mouse, it shouldn't jerk it around. I've found this quite distracting, e.g. when interacting with popups.

This solution should solve your problem as well. The issue is I haven't yet found a way to get to the mouse events required for this. If anyone has a pointer to documentation that can achieve this, that would be great.

ghost commented 2 years ago

Yes, that should resolve the issue for me as well.

Here's relevant documentation:

https://gjs-docs.gnome.org/clutter11~11_api/clutter.motionevent

Random things to take into consideration:


Another problem I have is that cursor moves when top bar is clicked on and the maximized window is activated (because top bar is outside of the focused window). I don't know if this can be fixed by your strategy. Alt-Tab Move Mouse doesn't have this issue though as it hooks into Main.activateWindow (only triggers when an existing window is activated by gnome shell). I've made it so newly created window also moves cursor but it's WIP implementation as I don't really know how to write gnome extension code.

ghost commented 2 years ago

Also your get_focused_window seems weird.

function get_focused_window() {
    for (const actor of global.get_window_actors()) {
        if (actor.is_destroyed()) {
            continue;
        }

        const win = actor.get_meta_window();
        if (win.has_focus()) {
            return win;
        }
    }

    return undefined;
}

This would be the cleaner approach:

https://github.com/Dotrar/gnome-centre-focus/blob/main/extension.js#L50

_moveMouse(){
    // get currently focused window 
    const win = global.display.focus_window;
    if (this._seat == null || win == null){
        return;
    }
    ...
}
LeonMatthes commented 2 years ago

Also your get_focused_window seems weird.

function get_focused_window() {
    // ....
}

This would be the cleaner approach:

https://github.com/Dotrar/gnome-centre-focus/blob/main/extension.js#L50

_moveMouse(){
    const win = global.display.focus_window;
    ...
}

Adapted your suggestion, thanks! I did the loop over all actors as that was the first thing I found that worked.

I still find it hard to discover things in the Gnome JS API. The Documentation on gjs-docs.gnome.org feels somewhat lacking 😕

LeonMatthes commented 2 years ago

Yes, that should resolve the issue for me as well.

Here's relevant documentation:

https://gjs-docs.gnome.org/clutter11~11_api/clutter.motionevent

Random things to take into consideration:

* If mouse only has tiny movement then just ignore it. Or even make better by making the threshold level configurable

* If mouse isn't moving but is clicking / dragging, then the mouse is also being held

Another problem I have is that cursor moves when top bar is clicked on and the maximized window is activated (because top bar is outside of the focused window). I don't know if this can be fixed by your strategy. Alt-Tab Move Mouse doesn't have this issue though as it hooks into Main.activateWindow (only triggers when an existing window is activated by gnome shell). I've made it so newly created window also moves cursor but it's WIP implementation as I don't really know how to write gnome extension code.

RE MotionEvent: That seems to be emitted by Clutter Actor. That means the extension would have to register itself with every actor in the scene. Ideally I'd want a single attachment point for the extension, like the Clutter eventFilter. Especially as we also definitely want to capture click events. I have already tried registering an eventfilter with Clutter. Unfortunately that seems to miss events somewhat sporadically. Can't tell why exactly. Also, Wikipedia claims Clutter is deprecated since this year :thinking: So I don't really want to add a dependency for a core feature that may be abandoned in the near future.

The feature would however solve the topbar problem as well. Unsure how to fix it otherwise :thinking: Just checking whether the mouse is in the topbar doesn't really help, as then if you alt-tab whilst the cursor is in the topbar, it wouldn't move.

I've also created a separate issue for this: #5