micheledaros / gnome-shell-extension-simulate-switching-workspaces-on-active-monitor

MIT License
24 stars 4 forks source link

On switching workspaces, it should set focus to top window in focused monitor #14

Open volanin opened 2 months ago

volanin commented 2 months ago

When switching workspaces, the focus is changing to the top window in the not-focused monitor. This is annoying, and makes me type in the wrong window all the time. I think a better (and expected) behavior would be for the focus to change to the top window in the focused monitor.

I tried to ajust the extension and added the following function to class WindowWrapper:

focus() {
    this.metaWindow.activate(global.get_current_time());
}

I also added this function in WorkSpacesService, and called it from onWorkspaceChanged():

focusWindowOnActiveMonitor() {
    let focusedMonitorIndex = this.getFocusedMonitor();
    let wrappers = this._getWindowWrappers();

    let windowsOnFocusedMonitor = wrappers
        .filter((it) => it.isNormal())
        .filter((it) => it.initialMonitorIndex === focusedMonitorIndex);

    let topWindow = windowsOnFocusedMonitor.pop();
    if (topWindow) {
        topWindow.focus();
    }
}

It's a simple code and should have worked, making the focus behave nicer... But as soon as focus() is called, it undoes the _moveToDirection() changes. I don't know why this happens, maybe I am missing something simple.