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
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
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).
In Sway, you can grep for your app against swaymsg -t get_tree
, which is like xprop
, but for all windows at once.
xprop
? It shows an awful lot of detail over a window via XWayland, including_NET_WM_PID(CARDINAL)
, which is the originator process PID.xprop
doesn't have access to Wayland windows, but only to those running on X server.