Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lucaswerkmeister/activate-window-by-title
GNOME Shell extension exposing a D-Bus interface to activate the window with the given title
https://github.com/lucaswerkmeister/activate-window-by-title
dbus gnome-shell-extension
Last synced: 2 months ago
JSON representation
GNOME Shell extension exposing a D-Bus interface to activate the window with the given title
- Host: GitHub
- URL: https://github.com/lucaswerkmeister/activate-window-by-title
- Owner: lucaswerkmeister
- License: gpl-2.0
- Created: 2022-04-23T14:57:32.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-20T19:10:54.000Z (3 months ago)
- Last Synced: 2024-10-04T12:50:02.104Z (3 months ago)
- Topics: dbus, gnome-shell-extension
- Language: JavaScript
- Homepage: https://extensions.gnome.org/extension/5021/activate-window-by-title/
- Size: 30.3 KB
- Stars: 36
- Watchers: 3
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Activate Window By Title
This is a GNOME Shell extension to activate (focus, bring to the foreground) a window
based on its title (or `WM_CLASS`, see below).
It exposes a D-Bus interface with methods for this purpose;
it has no user interface of its own,
but can be called from the command line or other programs.## D-Bus usage
The extension, when activated, extends the `org.gnome.Shell` service on the session bus
with a `/de/lucaswerkmeister/ActivateWindowByTitle` object,
which implements the `de.lucaswerkmeister.ActivateWindowByTitle` interface containing the following methods:- **activateByTitle**, to activate the window with the given full, exact title
- **activateByPrefix**, to activate the window whose title starts with the given prefix
- **activateBySuffix**, to activate the window whose title ends with the given suffix
- **activateBySubstring**, to activate the window whose title contains the given string
- **activateByWmClass**, to activate the window with the given full, exact name part of its `WM_CLASS`
- **activateByWmClassInstance**, to activate the window with the given full, exact instance part of its `WM_CLASS`Each method takes a single string argument,
and returns a single boolean indicating whether such a window was found or not.
Strings are matched case-sensitively.
Furthermore, activating a window also activates its workspace.The `WM_CLASS` is originally an X concept, but is available under Wayland as well
(exposed via `get_wm_class()` and `get_wm_class_instance()` on a `Meta.Window`).
It’s a pair of strings (name, instance) forming a kind of “application name”,
and both are more “stable” than the title (which may include changing details);
I believe the name is supposed to be more general than the instance,
but looking at some windows on my system I can’t really tell a difference,
both components seem mostly the same apart from arbitrary capitalization or punctuation differences.
Still, the `WM_CLASS` may be useful for activating a certain application regardless of its current window title
(e.g. GNOME Terminal does not include an application name in the window title).
You can see current name and instance strings in Looking Glass (Alt+F2 `lg`):
```js
global.get_window_actors().map(a => a.get_meta_window()).map(w => `${w.get_wm_class()} (${w.get_wm_class_instance()})`)
```By default, the extension goes through the windows in the order in which Mutter returns them
and activates the first one that matches the criterion.
If you are often working with ambiguous titles and need more control over this,
you can change the behavior by calling the **setSortOrder** method with one of the following strings:- *default*: no sorting.
This is intended for users who expect the match to be unambiguous anyways,
and removes the overhead of sorting the list of windows.
As of GNOME 46, it appears to be equivalent to *lowest_user_time* in practice.
- *lowest_user_time*: sort by ascending [user time](https://gnome.pages.gitlab.gnome.org/mutter/meta/method.Window.get_user_time.html).
The user time is updated each time you interact with a window,
so the window with the lowest user time will be the one you least recently interacted with.
- *highest_user_time*: sort by descending user time.
This will be the matching window you most recently interacted with.
- *lowest_window_id*: sort by ascending [window ID](https://gnome.pages.gitlab.gnome.org/mutter/meta/method.Window.get_id.html).
Mutter makes few guarantees about the window ID,
but it’s usually monotonically increasing (though it [can overflow](https://gitlab.gnome.org/GNOME/mutter/-/blob/a68385a179/src/core/display.c#L3507)),
which means the window with the lowest window ID should be the “oldest” one.
- *highest_window_id*: sort by descending window ID.
This will usually be the matching window that was most recently created.The method also returns the previous sort order, in case you want to restore it later.
Note that the sort order is currently not persisted anywhere
(it will start as *default* in each new GNOME Shell session).## Command line usage
You can call these methods using your favorite D-Bus command line tool, for example:
```sh
busctl --user call \
org.gnome.Shell \
/de/lucaswerkmeister/ActivateWindowByTitle \
de.lucaswerkmeister.ActivateWindowByTitle \
activateBySubstring \
s 'Firefox'
``````sh
gdbus call --session \
--dest org.gnome.Shell \
--object-path /de/lucaswerkmeister/ActivateWindowByTitle \
--method de.lucaswerkmeister.ActivateWindowByTitle.activateBySubstring \
'Firefox'
```## License
GNU GPL v2 or later.