Window title change in Xephyr

interpretive language scripts


Moderator: Forum moderators

Post Reply
user1111

Window title change in Xephyr

Post by user1111 »

Running Xephyr, and that program sets its window title differently according to whether the mouse/keyboard is locked into the window or not (ctrl-shift key toggles that).

Presently using a script that uses wmctrl to monitor the windows title, along with a sleep 1 within the loop. However that eats cpu. Any suggestions as to a more efficient less cpu intensive way?

Code: Select all

while :; do
   C=`wmctrl -l | grep Xephyr | grep releases | wc -l`
   ...
   sleep 1
done

Even at sleep 1 the action when the change occurs does feel/look laggy, but if the sleep is reduced to 0.2 then the cpu usage spikes even higher.

Perhaps a alternative to the wmctrl to detect the window title change ??

step
Posts: 546
Joined: Thu Aug 13, 2020 9:55 am
Has thanked: 57 times
Been thanked: 198 times
Contact:

Re: Window title change in Xephyr

Post by step »

You can try to shorten that pipeline. Instead of "grep Xephyr | grep releases" you could "grep "Xephyr.*releases" (or "releases.*Xephyr") to save one grep. Instead of "wc -l" you could add option -c to grep. All together "wmctrl -l | grep -c "Xephyr.*releases".

step
Posts: 546
Joined: Thu Aug 13, 2020 9:55 am
Has thanked: 57 times
Been thanked: 198 times
Contact:

Re: Window title change in Xephyr

Post by step »

A completely different approach could be using xdotool to bind actions to the mouse-enter / mouse-leave events on the Xephyr window. Read up about xdotool's behave command...

User avatar
MochiMoppel
Posts: 1243
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 444 times

Re: Window title change in Xephyr

Post by MochiMoppel »

rufwoof wrote: Sat Jan 23, 2021 1:54 pm

Perhaps a alternative to the wmctrl to detect the window title change ??

You could try xprop from the command line:

Code: Select all

xprop -spy  _NET_WM_NAME | sed 's/^.*= /\x07/'

You will have to click on the window you want to monitor and then the script records every change of the window title, accompanied by a beep (hex 07). You can test this with your browser where the title changes frequently.
Instead of manually selecting the window you could fetch the window ID of your program and then start xprop with the -id <WINID> option.

user1111

Re: Window title change in Xephyr

Post by user1111 »

Thanks for the suggestions. I had already changed the code to ...

Code: Select all

WID=$(wmctrl -lp | grep Xephyr | cut -d ' ' -f 1)	
while :; do
	C=$(xprop -id ${WID} WM_NAME | grep releases)

.. along with code to produce a indicator flag within the shared folder tree that within the Xephyr changes to that flag are picked up using a inotifywait (that then sets the desktop background accordingly using xsetroot).

That xprop -spy option however is great. Thanks.

Update code/script ... viewtopic.php?p=15886#p15886

User avatar
MochiMoppel
Posts: 1243
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 444 times

Re: Window title change in Xephyr

Post by MochiMoppel »

rufwoof wrote: Sun Jan 24, 2021 10:57 am

Thanks for the suggestions. I had already changed the code to ...

Code: Select all

WID=$(wmctrl -lp | grep Xephyr | cut -d ' ' -f 1)	
while :; do
	C=$(xprop -id ${WID} WM_NAME | grep releases)

Not much different from your initial code. Surely a little more efficient but still CPU intensive. Not knowing how your code continues I can only guess that based on the value of C your loop does some stuff or , after some sleep, enters another cycle. For the evaluation of the title text you probably don't need C nor do you need grep.

That xprop -spy option however is great. Thanks.

You're welcome. I still consider this the most CPU efficient way. The snippet I posted was just an example. In principle you could run any actions or function upon a title change.

Post Reply

Return to “Scripts”