Hello there,
It’s my first post around here, and I’m not sure if it’s in the appropriate category or properly tagged.
The situation
I’ve been using Gnome for many years now and always had the feeling something wasn’t working properly with window focusing when I switched workspaces on a dual screen setup.
Let’s consider the following situation: I have a primary screen (A) and a secondary screen (B). Changing workspace only affects screen A in the current setup. Let’s say I’m on workspace 1. I have Firefox focused on screen B. I click on VLC that’s on screen A to focus it. I then switch workspace 2, that contains Terminator on screen A.
Intuitively I always expect Terminator to get focused, but it doesn’t. Focus goes to Firefox. Probably because it’s the latest program currently visible that had focus.
This is weird because I would have never changed workspaces if my intention was to focus a program that was already on screen.
What I want to do about it
I believe this is something that can be fixed with an extension. I have no prior knowledge on how to implement an extension. I have read through the GJS guide on extensions. It did show me how to create an empty extension and I’ve learned from it that I could access objects that interact with workspaces and windows from an extension. I couldn’t find any guidance on how to write the actual code that goes in the extension or on how to use importable “gi” modules.
What I want to implement is fairly simple in natural language:
- detect that a workspace switch is in progress ;
- on the main display find the latest window that had focus ;
- focus that window.
Right now I’m reading workspace.js
from the gnome-shell repo just so I can find examples on what can be done with workspaces and windows, as I have no idea where I could find documentation on how these things interact with each other. I’ve also encountered the meta 9 API documentation which I’m reading at the same time as to understand the types I’m seing in workspace.js
.
For context: I’m on Gnome 42.1, running Wayland on ArchLinux.
Why am I here?
I would love it if someone could offer some guidance as to where I should focus my efforts to get this extension going.
For instance I still have no idea on how to listen to a workspace switching event, or how I can interact with the windows on that workspace to focus the latest active one.
Big thanks for reading this, and if you have time to help me.