You are not logged in.
Hello,
I use the lemonbar to display some informations about my system. The lemonbar
use a shell script to display informations. Sometimes I want to refresh my status bar.
To be brief: is it possible to refresh the status bar without checking for example every 2 seconds with
a "sleep 2" command ?
Let's take an example: with my window manager I switch
from desktop 1 to desktop 2. At the moment I use a sleep command and I refresh the information
every 2 seconds. Is there a way my shell script get notified about the switch from desktop 1 to desktop 2 and can refresh
the information in my status bar ? So it would be not necessary to execute a sleep command every two seconds.
Until now I found nothing. An idea is to react to a keyboard shortcut (the switch from desktop 1 to desktop 2), but
I don't know if it's possible. Perhaps something with a signal ? I also know some X events are generated by creating or closing windows
for example. I don't know if reacting to X events would be another possibility.
Thank you!
Offline
I'm not sure if shell scripts lend themselves particularly well to listening to events.
When I change the sound volume, the new value is saved to a file that is read by the tmux status bar script. The script runs every 15 seconds.
Would something like that be enough?
Offline
I'm not sure if it's possible to use something else than a shell script. But if somebody has an idea
with something else, I'm also interested. Perhaps it would be possible to interact with a shell script.
When I read your solution, for me it would be the same as using a "sleep 15" in a shell script. So it's
already what I have at the moment.
Offline
Shell scripts are good to react to filesystem events thanks to inotify-wait included in inotify-tools plackage.
But maybe this is more helpful to karol, sorry.
Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !
Offline
Whether any hooks or events are exposed for a shell script to listen to is entirely dependent on your window manager. Otherwise you'll have to do what you're doing right now and poll using either wmctrl, xdotool, or something equivalent.
Offline
You could try something like this: (untested)
CHECK=$HOME/.cache/x-changed
mkfifo $CHECK
(
vnr=$XDG_VTNR
while new=$XDG_VTNR
[ $vnr = $new ]
do sleep 1
done
echo $new > $CHECK
) &
read RET <$CHECK
rm -f "$CHECK"
echo "New VT: $RET"
hth
Last edited by esa (2015-06-05 13:41:08)
Offline
^You're simply polling in an even more inefficient manner.
Offline
Thank you for all your ideas! I will follow the advice of SaintOfCloud. At the moment I have
no window manager, so I have no hooks I can use. I will keep the sleep command.
Offline
@ SaintofCloud, how is that?
Its not looping a 15sec sleep, but it would continue as soon the variable changes (actualy the file its content is written).
And it is something to work with/on to get started.
Yeah, a sleep is more efficent that mkfifo... /sarcasm off
Last edited by esa (2015-06-06 12:14:15)
Offline
Polling is inefficient, but will work everywhere, while trying to solve a specific problem generally leads to a much more efficient solution; abstraction is not always good...
Eg: if a WM writes the current desktop in a file, then you can just watch that file via inotify and do an event driven action.
As a side note: how do you switch "desktops" without a WM? Was it just an example?
Last edited by kokoko3k (2015-06-06 12:28:06)
Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !
Offline
You could try something like this: (untested)
CHECK=$HOME/.cache/x-changed mkfifo $CHECK ( vnr=$XDG_VTNR while new=$XDG_VTNR [ $vnr = $new ] do sleep 1 done echo $new > $CHECK ) & read RET <$CHECK rm -f "$CHECK" echo "New VT: $RET"
hth
Not only is that inefficient, it doesn't even come close to addressing the question at hand. XDG_VTNR has nothing to do with the desktop/workspace number within X. The former is the number of the current VT, the latter is an abstraction created by window managers running on a single VT.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Eg: if a WM writes the current desktop in a file, then you can just watch that file via inotify and do an event driven action.
I will keep it in mind. I have to check, but it's possible I can use that solution.
As a side note: how do you switch "desktops" without a WM? Was it just an example?
Yes, it was an example. If I change in the future I could use the solution for the chosen wm.
But at the moment I can create groups. Each groups get a number and I can raise or hide all applications
in that group. So it's the same problem.
Offline