Add activateById method
Hi! Thank you for this extension :)
In my use cases I find it useful to be able to target an specific window instance when I have multiple instances of the same application running. The WM_CLASS methods don't help with this since both strings are the same for all instances.
For example, this method allows me to save the ID for the window that currently has the focus, set the focus to some other window, and then return the focus to the original window.
Hm, I’m not convinced by this yet, and I’m not super excited about further diluting the “activate window by title” name :sweat_smile:
I started this extension when Gnome took away the ability to run JavaScript via dbus – if you need to use lg to get the window ID, you’re already in an environment where you can run JS, so what’s the benefit that the extension brings in that case? (Arguably you could say something similar about the WM_CLASS, but that should at least be relatively stable over time, so you only need to use lg to get the WM_CLASS once. I assume the window ID changes with each new session.)
Can you elaborate on your use case a bit more?
I’m not super excited about further diluting the “activate window by title” name 😅
I can understand that, I just felt it fitted nicely with the code structure and the 'activate by WM_CLASS' methods.
Can you elaborate on your use case a bit more?
I need to briefly set the focus to an specific window (by title), and then move the focus back to the window where it originally was. I can't do that by title because I might have multiple windows with the same title (and WM_CLASS), and it would just focus one of these arbitrarily (or the first one, as discussed in #4). With the window ID I can focus the exact window I'm interested in.
I'm using the window-calls-extended extension to get the IDs.
The flow is as follows:
- Capture the current window ID (using the window-calls-extended extension)
- Switch focus to another window (by title)
- Switch back to the previous window, using the captured ID
I can share the full script if interested.
I’m not super excited about further diluting the “activate window by title” name 😅
I can understand that, I just felt it fitted nicely with the code structure and the 'activate by
WM_CLASS' methods.
Yeah, I set myself up for this when I accepted that feature request, didn’t I :laughing:
I'm using the window-calls-extended extension to get the IDs.
That’s neat, I didn’t know about that extension. (More DBUS extensions \o/) But I don’t see a method to get the ID in there? I see a method to get the PID, but I assume that’s not the same thing – a process can probably have multiple windows. (Unfortunately, the Mutter API reference seems to have vanished alongside the rest of Mutter’s website as linked from their README, so I can’t easily look at the docs of get_id() and get_pid() at the moment.)
I can share the full script if interested.
Sure!
Oh, nevermind, I guess you’re using the List method which returns JSON that includes both the ID and PID?
But I don’t see a method to get the ID in there? I see a method to get the PID, but I assume that’s not the same thing – a process can probably have multiple windows. (Unfortunately, the Mutter API reference seems to have vanished alongside the rest of Mutter’s website as linked from their README, so I can’t easily look at the docs of
get_id()andget_pid()at the moment.)
The docs are back up (get_id(), get_pid()), and they’re indeed different.
This looks interesting; any progress?
I think I was still waiting for a reply from @poinu (or someone else) about how a user would get the window ID in the first place – it’s not exactly a technical blocker, but it would also be useful to mention in the README when documenting the new method (in addition to satisfying my own curiosity :P).
I can get window id's with that list window-calls-extended method
Alright, I’ve rebased and updated the change, and also added a bit of debug code that I’ll remove again later. I’ll test this the next time I restart my GNOME Shell (which may be a few days, tbh).
Okay, testing shows that, as I feared, GNOME Shell always passes the D-Bus UINT64 (t) into our JavaScript code as a number, even if this changes the value due to floating-point imprecision. (I was hoping maybe it would be turned into a numeric string in that case…) This means the extension won’t work for IDs above ca. 2^54, which technically is the vast majority of the ID space (but in practice hopefully the shell chooses lower window IDs). I don’t think there’s anything we can do about that.
Tagged and uploaded as version 10 of the extension (now pending review).
Now published \o/