Skip to content

Commit

Permalink
Inherit and update WindowSwitcherPopup
Browse files Browse the repository at this point in the history
Instead of directly updating `Main.activateWindow` to include
`movePointer`, inherit and update `WindowSwitcherPopup`, which contains
a `Main.activateWindow` call inside of it. This has the benefit of being
analogous to `AppSwitcherPopup` which fixed the Alt+Tab problem for
`switch-windows` setting in GNOME shortcuts.
  • Loading branch information
lucasresck committed Nov 15, 2022
1 parent bd7a688 commit fede46d
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,18 @@ const { Clutter, Meta, GObject } = imports.gi;
const Main = imports.ui.main;
const altTab = imports.ui.altTab;

let CurrentMonitorWindowSwitcherPopup;
let CurrentMonitorAppSwitcherPopup;
let extension = null;

class Extension {
constructor() {
this.origMethods = {
"Main.activateWindow": Main.activateWindow,
"windowSwitcherPopup": altTab.WindowSwitcherPopup,
"appSwitcherPopup": altTab.AppSwitcherPopup
};

Main.activateWindow = (window, ...args) => {
this.movePointer();
this.origMethods["Main.activateWindow"](window, ...args);
};

altTab.WindowSwitcherPopup = CurrentMonitorWindowSwitcherPopup;
altTab.AppSwitcherPopup = CurrentMonitorAppSwitcherPopup;

const seat = Clutter.get_default_backend().get_default_seat();
Expand All @@ -42,18 +39,26 @@ class Extension {
);
}

destroy() {
Main.activateWindow = this.origMethods["Main.activateWindow"];
altTab.AppSwitcherPopup = this.origMethods["appSwitcherPopup"];
}

movePointer() {
const [x, y] = global.get_pointer();
this.vdevice.notify_absolute_motion(global.get_current_time(), x, y);
}

destroy() {
altTab.WindowSwitcherPopup = this.origMethods["windowSwitcherPopup"];
altTab.AppSwitcherPopup = this.origMethods["appSwitcherPopup"];
}
}

function init() {
CurrentMonitorWindowSwitcherPopup = GObject.registerClass(
class CurrentMonitorWindowSwitcherPopup extends altTab.WindowSwitcherPopup {
_finish() {
extension.movePointer();
super._finish();
}
}
);
CurrentMonitorAppSwitcherPopup = GObject.registerClass(
class CurrentMonitorAppSwitcherPopup extends altTab.AppSwitcherPopup {
_finish(timestamp) {
Expand Down

0 comments on commit fede46d

Please sign in to comment.