I'd like to identify which process a window belongs to in Wayland. Is there anything like xprop for X that allows the user to pick a window by clicking and outputs all window details, including PID?
4 Answers
Good news, there IS something like this built into Gnome Shell, and unlike xprop works with Xorg and Wayland. Ultimately this may fall into the realm of other tooling if you're using KDE, i3, or something else.
To begin with, type the keys "ALT+F2" on the keyboard which will bring up a menu like this:
After that comes up, issue the command lg (for "looking glass).
This will then bring up the looking glass window, from which we can extract window information. Select "window" from the top right corner of the looking glass:
From there, you'll see a list of windows, from which you can click on the name of the window you want to identify.
In this case, I chose gedit for an example:
In the top line of that output you may notice:
Inspecting object: object instance proxy GType: MetaWindowX11 ...
The "GType" will be one of MetaWindowX11 or MetaWindowWayland.
This info comes as per https://fedoraproject.org/wiki/How_to_debug_Wayland_problems
-
10So does this allow to find out the PID of process running the listed window?czerny– czerny2018-04-03 22:55:57 +00:00Commented Apr 3, 2018 at 22:55
-
5So how to use this from a shell in order to determine if a gui is running as wmctrl did?RichieHH– RichieHH2020-08-14 08:07:31 +00:00Commented Aug 14, 2020 at 8:07
-
So when I find my window, what can I do with it ? I couldn' find any commands to run, or even refering to selected windowsmido– smido2024-02-21 19:23:54 +00:00Commented Feb 21, 2024 at 19:23
-
Once the window is identified you can introspect the metadata on the GObject for subsequent development of Gnome3 plugins or programmatic control of the window. Also, you can switch to the "Evaluator" and use the REPL to reference the object.Brian Redbeard– Brian Redbeard2024-02-29 18:28:42 +00:00Commented Feb 29, 2024 at 18:28
-
1To close the looking glass, click on one of the tabs ("Evaluator", "Windows"...), and then press the Escape button on your keyboard.Flimm– Flimm2024-11-20 09:59:32 +00:00Commented Nov 20, 2024 at 9:59
I realised this was something that sway in particular was lacking, so I created a gist to do it.
Behold: wlprop
Type wlprop into a terminal and click a window, it will give you the sway tree output for that particular window:
$ wlprop
# A prompt to select a window will appear
{
"id": 72,
"type": "con",
"orientation": "none",
"percent": 0.5002881844380404,
"urgent": false,
"marks": [],
"focused": false,
"layout": "none",
"border": "pixel",
"current_border_width": 2,
"rect": {
"x": 0,
"y": 26,
"width": 868,
"height": 1130
},
"deco_rect": {
"x": 0,
"y": 0,
"width": 0,
"height": 0
},
"window_rect": {
"x": 2,
"y": 2,
"width": 864,
"height": 1126
},
"geometry": {
"x": 0,
"y": 0,
"width": 1328,
"height": 858
},
"name": "How to identify window by clicking in Wayland - Unix & Linux Stack Exchange — Mozilla Firefox",
"window": null,
"nodes": [],
"floating_nodes": [],
"focus": [],
"fullscreen_mode": 0,
"sticky": false,
"pid": 47844,
"app_id": "firefox",
"visible": true,
"max_render_time": 0,
"shell": "xdg_shell",
"inhibit_idle": false,
"idle_inhibitors": {
"user": "none",
"application": "none"
}
}
You can filter by a specific element by using jq:
$ wlprop | jq -r '.name'
# The same prompt will appear
How to identify window by clicking in Wayland - Unix & Linux Stack Exchange — Mozilla Firefox
Hopefully this solution is elegant enough to fill the xprop shaped hole in everybody's hearts
-
2Is it Sway only or will it work with any DE using wayland?aloisdg– aloisdg2024-04-04 12:30:25 +00:00Commented Apr 4, 2024 at 12:30
-
@aloisdg Sway only, it uses Sway's IPC socket.ForeverZer0– ForeverZer02025-01-13 17:19:17 +00:00Commented Jan 13 at 17:19
-
alright hope to find a non-sway wayland solution :)aloisdg– aloisdg2025-01-14 14:22:58 +00:00Commented Jan 14 at 14:22
In Sway, you can grep for your app against swaymsg -t get_tree, which is like xprop, but for all windows at once.
There is a draft of xdg-foreign protocol extension, which allows obtaining handles of wl_surface's, created by other Wayland clients. Having the handle, you can obtain from it anything you can obtain from surfaces of your client. However, this protocol still has limitations:
- Obviously, it won't work if not implemented in clients.
- It's targeted for clients that know each other, so it does not provide a way to trigger it: your client communicates with a foreign client in some way, not covered by the extension. Then the foreign client publishes a handle for your client via this extension.
- It gains too much control, if compared to
xprop. Actually, you can even draw on foreign surfaces!
So, this is unlikely to become a general way to get surface parameters from any client by any client. But don't lose a hope: there are a lot of examples in tech history when a technology, initially designed for some purpose, became widely used for other purposes, just like car cigarette lighters or Accessibility APIs in Android. Moreover, in the future, there may appear a protocol extension that is more suited for your task, as there is definitely a need for it (for example, for time trackers).




xprop? It shows an awful lot of detail over a window via XWayland, including_NET_WM_PID(CARDINAL), which is the originator process PID.xpropdoesn't have access to Wayland windows, but only to those running on X server.