Edit: I am not looking for other ways or better ways to change a window's title or to add titles to tabs in terminals. The answers in the proposed duplicate do not in any way come close to addressing the specific issue of why xdotool search …
does not pick up window titles when the title is set by wmctrl as described above.
OS: Ubuntu 18.04
When I open a gnome-terminal window, the title is dkb@dkb:~
I can change it using
wmctrl -r :ACTIVE: -N "NewName"
but xdotool search …
, doesn't "see" this title:
dkb@dkb:~$ xdotool search --name NewName
dkb@dkb:~$
I just get back the prompt instead of being provided the corresponding window identifier.
On the other hand, I can use xdotool itself to set the title and then xdotool search …
provides the window identifier:
dkb@dkb:~$ xdotool getactivewindow set_window --name NewName
dkb@dkb:~$ xdotool search --name NewName
39845894
dkb@dkb:~$
In other words, if the title is set by xdotool, xdotool search
works as it should:
From man xdotool
search [options] pattern Search for windows with titles, names, or classes with a regular expression pattern. The output is line-delimited list of X window identifiers.
So while it's not a big deal, I'd like to know what the reason is for xdotool not "seeing" the window title set by wmctrl.
We can see that at the very least
xdotool getactivewindow getwindowname
works as intended.So let's go deeper. We can list properties of window using
xprop -id <id>
command. For window with name set bywmctrl
it gives:And for for window with name set by
xdotool
it gives:And we can see that in both cases
_NET_WM_NAME
is set correctly. What is_NET_WM_NAME
? It's an extension for x11 (link, link)So x11 applications should prefer this property over
WM_NAME
. Let's display both of these properties. I've taken C code from here:Only added a
printf("WM_NAME: %s\n", get_string_property("WM_NAME"));
line. Running:So the conclusion is:
xdotool
sets both_NET_WM_NAME
andWN_NAME
but only search byWM_NAME
andwmctrl
sets only_NET_WM_NAME
.