Since window manager is out of topic in this tutorial,
I present only panel HerbstluftWM screenshot.
Dzen2
Lemonbar
1: Directory Structure
Directory Structure has been explained in preface.
For both Dzen2 and Lemonbar, the structure are the same.
This figure will explain how it looks
in Lua script directory.
Special customization can be done in output script,
without changing the whole stuff.
2: Common Module
Lua is an embedding language. It is suppose to be light.
No wonder it lacks of standard function for daily coding,
such as split, trim, sleep,
that we are going to use in this project.
I don’t like to grumble.
I’d better collect from some resurces in the internet.
The original herbstluftwm panel example,
contain statusbar for each monitor.
The default is using monitor 0,
although you can use other monitor as well.
I do not implement statusbar in multi monitor since I only have my notebook.
But I’ll pass the argument anyway for learning purpose.
Here it is our code in Lua.
helper.lua
Calling external module in Lua using relative directory
need special tricks.
Now in main code we can call
This will display 0 or else such as 1,
depend on the script argument given.
Get Monitor Geometry
HerbstluftWM give this little tools to manage monitor geometry
by getting monitor rectangle.
This will show something similar to this.
Consider wrap the code into function.
And get an array as function return.
helper.lua
Consider call this function from script later.
To print array in Lua,
we just have to wrap it in table.concat(geometry, ' ').
Just remember that Lua array is not zero based.
This will produce
Get Panel Geometry
The Panel geometry is completely depend on the user flavor and taste.
You can put it, on top, or bottom, or hanging somewhere.
You can create gap on both left and right.
Consider this example:
helper.lua
We are going to use this X Y W H,
to get lemonbar parameter.
This will show something similar to this result,
depend on your monitor size.
Get Lemonbar Parameters
We almost done.
This is the last step.
We wrap it all inside this function below.
helper.lua
4: Testing The Parameters
Consider this code 01-testparams.lua.
The script call the above function to get lemon parameters.
This will produce output
something similar to this result
Since we want to use panel, we have to adjust the desktop gap,
giving space at the top and bottom.
For more information, do $ man herbsluftclient,
and type \pad to search what it means.
In script, it looks like this below.
6: Color Schemes
Using a simple data structure key-value pairs,
we have access to google material color
for use with dzen2 or lemonbar.
Having a nice pallete to work with,
makes our panel more fun.
Officialy there is a no way to define constant in Lua.
Lua does not differ between these two.
Mutable State: Segment Variable
The different between interval based and event based is that,
with interval based all panel segment are recalculated,
while with event based only recalculate the trigerred segment.
In this case, we only have two segment in panel.
Tag
Title
output.lua
In script, we initialize the variable as below
Each segment buffered.
And will be called while rendering the panel.
Global Constant: Tag Name
Assuming that herbstclient tag status
only consist of nine number element.
We can manage custom tag names,
consist of nine string element.
We can also freely using unicode string instead of plain one.
As response to herbstclient event idle,
these two function set the state of segment variable.
output.lua
This function above turn the tag status string
into array of tags for later use.
output.lua
We will call these two functions later.
10: Decorating: Window Title
This is self explanatory.
I put separator, just in case you want to add other segment.
And then returning string as result.
output.lua
.
11: Decorating: Tag Status
This transform each plain tag such as .2,
to decorated tag names such as 二 ni.
Note that it only process one tag.
We process all tags in a loop in other function.
This has some parts:
Pre Text: Color setting for Main Text
(Background, Foreground, Underline).
Arrow before the text, only for active tag.
Main Text: Tag Name by number,
each with their tag state #, +,
., |, !,
and each tag has clickable area setting.
Post Text:
Arrow after the text, only for active tag.
Color Reset: %{B-},
%{F-}, %{-u}
(Background, Foreground, Underline).
output.lua
12: Combine The Segments
Now it is time to combine all segments to compose one panel.
Lemonbar is using %{l} to align left segment,
and %{r} to align right segment.
All tags processed in a loop.
output.lua
13: Testing The Output
Consider this code 02-testoutput.lua.
The script using pipe as feed to lemonbar.
We append -p parameter to make the panel persistent.
This will produce a panel on top.
The panel only contain the initialized version of the text.
It does not really interact with the HerbstluftWM event.
You can also click the clickable area to see it’s result.
It only show text, not executed yet.