Preface

The challenge is, to process Hersbtclient Idle Event

HerbstluftWM event produced by --idle command. Event based statusbar require us to create our own tools, to manage the flow from one process, and pipe the output to other process.

Interval based itself could be considered as timer event. To combine both herbstluftWM idle event and interval event, we need to create our own event producer.

$ herbstclient --idle

HerbstluftWM: Event Idle


Pipe

How many Pipes ?

In shell it is basically just a pipe:

Dzen2

This is a two tier pipes, since content processing happened between pipe. The content processing itself is a complex part. And there are some pipe and fork combinations as well.

herbstclient --idle | content_processing | dzen2

Lemonbar

This is a three tier pipes, just like Dzen2, except Lemonbar pipe clickable areas to a shell.

herbstclient --idle | content_processing | lemonbar | sh

Unidirectional

The requirement of Dzen2 is unidirectional, it means one way communication. Simple.

The idle event as an input, feed the content process, the content process produce an output to Dzen2. While Dzen2 process act as a writer, idle event process act as a reader.

Bidirectional

The requirement of Lemonbar is bidirectional, it means tow ways communication. Lemonbar read input and write output at the same time. Lemonbar process act as a reader and writer in the same time.

For each language we must carefully chose Pipe methods, that support bidirectional, since most pipe only support unidirectional.

Content Process

Content process live in an infinite loop which write to statusbar whether it is Dzen2 or Lemonbar. This has no issue with unidirectional loops But this create an issue in a application logic for bidirectional Lemonbar, which has another loop to write to shell.

Both loops live at the same time. There is no loop notation sufficient, to implement this complex logic, without blocking each other. The solution is to fork the infinite loop as a new process, outside the shell loop.

Combined Event

TBD

What if we want to put other stuff in our lovely panel, such as date? Or any system monitoring information such as CPU, Memory, HDD, temperature, uname or even MPD?

These system monitoring is usually called in interval based. Date can be based on one second interval. And other stuff can be groupped in longer interval. And uname called only once, or one hour interval if you wish.

Luckily we can treat these interval as event. Consider this combined event, consist of idle event and interval event.

combined_event | content_processing | statusbar

Since we need to alter the original event, to create new combined event, we need an intermediate process. As an intermediate process, we need to pipe both loop, into cat.

Since both event also loops that write in the same time, as the intermediate process being read. We need to fork both loop.


To Be Done

TBD

This article is, still unfinished. Here are what I need to do.

  • The source code is still missing one main feature about combining these two:

    • herbsclient idle event based, and

    • custom interval based.

  • Putting it all together with other statusbar, and main HerbstluftWM configuration.


Multi Language Implementation

The original script has beenported from BASH, Perl, Python, Ruby, PHP, Lua, and finally the compiled Haskell.

Why Port ?

Because Piping and Forking is a very interesting topic. Challenging, and no sufficient tutorial in internet, especially for real life example. That is why I’m eager to pour them down in a blog.

Reading

You might desire to read previous post, that contain the basic of this tutorial, with simple example.


What is not in this Guidance

No Window Manager in this tutorial.

Separate Window Manager Tutorial, and Statusbar Tutorial.

One of the most complex part of Window Manager is Statusbar. It is considered third party. It deserve its own article. And I did wrote a specific article exploring statusbar.

The code given is complete, but I breakdown the tutorial into two parts.

  1. HerbstluftWM Tag Status: Statusbar (not this article) Focusing on tags: herbstclient tag_status

  2. HerbstluftWM Event Idle: Advance Pipe and Fork (this article) Focusing on event: herbstclient --idle

This will only discuss about Piping and Forking.


Dzen2 or Lemonbar.

What Statusbar ?

Lemonbar, as it is a continuation of previous part using Lemonbar.

Source code is available for both Dzen2 and Lemonbar.

Directory Structure

The idea is Focus

We only use output script. But the tutorial will show the output script step by step, from simple code to the final form.

The project itself separated into panel, pipehandler, helper, output, gmc.

.
├── panel
|
├── 01-testparams
├── 02-testoutput
|
├── pipehandler
├── helper
├── output
└── gmc

Blog Post

The rest is in their respective article.

Let's get it started.

Dotfiles (Dzen2 Source Code)

Dotfiles (Lemonbar Source Code)


Thank you for Reading.