Preface
Goal: Show the Herbstclient Tag.
Focusing in "herbstclient tag_status".
This tutorial cover Lemonbar, and in order to use Dzen2, any reader could use the source code in github.
Table of Content
-
Preface: Table of Content
-
2: Get Geometry
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/…/python/
Screenshot
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 Python script
directory.
Special customization can be done in output script, without changing the whole stuff.
2: Get Geometry
Let’s have a look at helper.py
in github.
View Source File:
Get Script Argument
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 Python.
helper.py
And 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.py
Consider call this function from script later.
To print array in Python,
we just have to wrap it in ' '.join(geometry)
.
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.py
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.py
3: Testing The Parameters
Consider this code 01-testparams.py
.
The script call the above function to get lemon parameters.
This will produce output something similar to this result
Or in Dzen2 version:
View Source File:
4: Adjusting the Desktop
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.
5: 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.
gmc.py
View Source File:
6: Preparing Output
Let’s have a look at output.py
in github.
View Source File:
7: Global Variable and Constant
Officialy there is a no way to define constant in Python. Python does not differ between these two, for that reason we distinguish global constant with capital case.
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.py
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.
output.py
Global Constant: Decoration
output.py
Decoration consist lemonbar formatting tag.
8: Segment Variable
As response to herbstclient event idle, these two function set the state of segment variable.
output.py
This function above turn the tag status string into array of tags for later use.
output.py
We will call these two functions later.
9: 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.py
10: 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.py
11: 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.py
12: Testing The Output
Consider this code 02-testoutput.py
.
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.
View Source File:
Coming up Next
It is already a long tutorial. It is time to take a break for a while.
We are going to continue on next tutorial to cover interaction between the script process and HerbstluftWM idle event.
Enjoy the statusbar !