forge icon indicating copy to clipboard operation
forge copied to clipboard

Keep focus on pointer monitor after workspace switch

Open cnharrison opened this issue 2 months ago • 1 comments

Summary

  • fix the bug where enabling “Move pointer with the focus” causes workspace switches to highlight the window on a monitor whose workspace didn’t change
  • reuse the pointer’s monitor/workspace when rebuilding the tree so focus returns to the monitor that actually switched workspaces
  • after the workspace switch completes, refocus and warp the pointer back to that monitor so it stays active

Behavior Change

  • Before: switching workspaces with pointer warp enabled caused Mutter to revive a static window on another monitor, Forge warped the pointer there, and focus jumped away from the monitor whose workspace you actually changed.
  • After: Forge remembers which monitor the pointer belonged to, reorders its window list for that monitor, and re-applies focus (plus pointer warp) back to that monitor when the workspace switch finishes.

Impact

  • Multi-monitor users with pointer warping enabled keep focus on the monitor whose workspace they switched to, instead of having it jump to a static secondary display.

Testing

  • GNOME 46.3 (Wayland)
  • move-pointer-focus-enabled=true
  • Switching workspaces keeps focus/pointer on the monitor associated with the new workspace; other monitors no longer steal focus.

cnharrison avatar Oct 10 '25 02:10 cnharrison

It looks like the GH actions failure is due to source code formatting issues:

❯ nvm use latest
Now using Node v24.7.0 (npm 11.5.1) ~/.local/share/nvm/v24.7.0/bin/node
❯ npm test --verbose
npm verbose cli /home/juarezr/.local/share/nvm/v24.7.0/bin/node /home/juarezr/.local/share/nvm/v24.7.0/bin/npm
npm info using [email protected]
npm info using [email protected]
npm verbose title npm test
npm verbose argv "test" "--loglevel" "verbose"
npm verbose logfile logs-max:10 dir:/home/juarezr/.npm/_logs/2025-10-12T19_12_50_039Z-
npm verbose logfile /home/juarezr/.npm/_logs/2025-10-12T19_12_50_039Z-debug-0.log

> [email protected] test
> prettier --list-different "./**/*.{js,jsx,ts,tsx,json}"

lib/extension/window.js
lib/prefs/metadata.js
npm verbose cwd /home/juarezr/src/gnome/forge
npm verbose os Linux 6.14.0-33-generic
npm verbose node v24.7.0
npm verbose npm  v11.5.1
npm verbose exit 1
npm verbose code 1
❯ npm run format

> [email protected] format
> prettier --write "./**/*.{js,jsx,ts,tsx,json}"

lib/extension/window.js 158ms
lib/prefs/metadata.js 5ms

It looks like prettier doesn't like multiline closures:

diff --git a/lib/extension/window.js b/lib/extension/window.js
index 7323159..30112a3 100644
--- a/lib/extension/window.js
+++ b/lib/extension/window.js
@@ -1928,15 +1928,13 @@ export class WindowManager extends GObject.Object {
       return;
     }
 
-    const candidateNodes = this.tree
-      .getNodeByType(NODE_TYPES.WINDOW)
-      .filter((node) => {
-        if (!node.isTile()) return false;
-        const meta = node.nodeValue;
-        if (!meta || meta.minimized) return false;
-        const metaWorkspace = meta.get_workspace();
-        return meta.get_monitor() === monitor && metaWorkspace && metaWorkspace.index() === workspace;
-      });
+    const candidateNodes = this.tree.getNodeByType(NODE_TYPES.WINDOW).filter((node) => {
+      if (!node.isTile()) return false;
+      const meta = node.nodeValue;
+      if (!meta || meta.minimized) return false;
+      const metaWorkspace = meta.get_workspace();
+      return meta.get_monitor() === monitor && metaWorkspace && metaWorkspace.index() === workspace;
+    });
 
     if (candidateNodes.length === 0) return;

Running npm run format and committing should solve the issue.

juarezr avatar Oct 12 '25 19:10 juarezr