Preface
Goal: Manage Herbstclient process trigerred by idle event
Focusing in "herbstclient --idle".
This is the next Part, of the previous Tutorial. This tutorial cover Lemonbar. In order to use Dzen2, any reader could use the source code in github.
Table of Content
Reference
Reading
Before you jump off to scripting, you might desire to read this overview.
All The Source Code:
Impatient coder like me, like to open many tab on browser.
-
Lemonbar: gitlab.com/…/dotfiles/…/bash/
The PipeHandler Source File:
Let’s have a look at pipehandler.sh
in github.
Statusbar Screenshot
Dzen2
Lemonbar
1: Without Idle event
Let’s have a look at our main
panel.sh
in github.
At the end of the script, we finally call lemonbar
with detach_lemon
function.
View Source File:
Run Lemon, Run !
This detach_lemon
function.
is just a function that enable
the lemonbar running process to be detached,
using fork &
.
The real function is run_lemon
.
Note: that we want to ignore idle event for a while.
And append the -p
for a while,
to make the statusbar persistent.
Statusbar Initialization
Here we have the content_init
.
It is just an initialization of global variable.
We are going to have some loop later in different function,
to do the real works.
Now is time to try the panel, on your terminal.
Note: that we already reach this stage in our previous article.
These two functions, set_tag_value
and set_windowtitle
, have already been discussed.
View Source File:
Simple version. No idle event. Only statusbar initialization.
2: With Idle event
Consider this content_walk
call,
after content_init
call,
inside the run_lemon
.
Wrapping Idle Event into Code
content_walk
is the heart of this script.
We have to capture every event,
and process the event in event handler.
Walk step by step, Process event by event
After the event handler,
we will get the statusbar text, in the same way,
we did in content_init
.
3: The Event Handler
For each idle event, there are multicolumn string. The first string define the event origin.
The origin is either reload
, or quit_panel
,
tag_changed
, or tag_flags
,
or tag_added
, or tag_removed
,
or focus_changed
, or window_title_changed
.
More complete event, can be read in herbstclient manual.
All we need is to pay attention to this two function.
set_tag_value
and set_windowtitle
.
Actually that’s all we need to have a functional lemonbar. This is the minimum version.
View Source File:
With idle event. The heart of the script.
4: Lemonbar Clickable Areas
This is specific issue for lemonbar, that we don’t have in dzen2.
Consider have a look at
output.sh
.
Issue: Lemonbar put the output on terminal instead of executing the command.
Consider going back to
pipehandler.sh
.
We need to pipe the lemonbar output to shell. It means Lemonbar read input and write output at the same time.
How does it work ?
All we need to do is to pipe the output to sh
.
And voilla !! The magic happened.
Now we have real clickable areas.
View Source File:
Piping lemonbar output to shell, implementing lemonbar clickable area.
5: Interval Based Event
We can put custom event other than idle event in statusbar panel. This event, such as date event, called based on time interval in second. Luckily we can treat interval as event.
It is a little bit tricky, because we have to make, a combined event that consist of, idle event (asynchronous) and interval event (synchronous). Merging two different paralel process into one.
This is an overview of what we want to achieve.
In real code later, we do not need the timestamp.
interval
string is enough to trigger interval event.
View Testbed Source File:
Before merging combined event into main code, consider this test in an isolated fashion.
6: Combined Event
Preparing The View
This is what it looks like, an overview of what we want to achieve.
Consider make a progress in
output.sh
.
And a few enhancement in
pipehandler.sh
.
Expanding The Event Controller
All we need to do is to split out content_walk
into
-
content_walk
: combined event. -
content_event_idle
: HerbstluftWM idle event. Forked, as background processing. -
content_event_interval
: Custom date time event. Forked, as background processing.
This above is the most complex part. We are almost done.
View Source File:
Combined event consist of both, synchronous interval event and asynchronous idle event.
7: Dual Bar
The idea of this article comes from the fact
that herbsclient --idle
is asynchronous event.
If you need another bar, just simply use Conky
instead.
-
Dzen2:
-
Lemonbar:
We only need one function to do this in
pipehandler.pm
.
And execute the function main script in
panel.pl
.
View Source File:
Dual Bar, detach_lemon_conky
function.
8: Avoid Zombie Apocalypse
Zombie are scary, and fork does have a tendecy to become a zombie. Application that utilize several forks should be aware of this threat. The reason why I use fork instead of thread is, because the original herbstluftwm configuration coming from bash, and this bash script is using fork.
However, you can use this short script to reduce zombie population.
It won’t kill all zombie, but works for most case.
You might still need htop
,
and kill -9
manually.
9: Putting Them All Together
I also created compact for version,
for use with main HerbstluftWM configuration,
in ~/.config/herbstluftwm/
directory.
After reunification, they are not very long scripts after all.
Desktop Screenshot
Fullscreen, Dual Panel, Zero Gap.
Conclusion
Enjoy the statusbar ! Enjoy the window manager !