Giter Site home page Giter Site logo

dwmbar's Introduction

dwmbar

dwmbar is a simple status bar for the dwm tiling window manager.

Installation

Configure by editing the source code in dwmbar.c then install:

sudo make install

The program sets the name of the root windows to a text formatted for the status2d patch of dwm.

Description

I was not satisfied with existing status bar for dwm so I wrote my own. In particular I didn't want to call shell scripts to fetch basic informations and preferred using a more efficient polling technique than just calling a function every second. In the end, this little project strives to be the most efficient possible.

To get into more detail, standard status bars use a single thread and sleep for a pre-determined number of seconds before updating all the informations. I used this technique with great success in a previous application but it suffers from a major drawback: the smaller the update interval the snappier the bar, but also the more it draws resources. This becomes a problem for me when I was changing the sound of my computer. I wanted quick feedback but updating the status every tenth of a second seemed ridiculous. I looked for other alternatives, such as sending a signal to the status bar every time the "volume script" changes its value but in the ends I chose to monitor files for changes using inotify.

Features

The status bar can display several values:

  • current keyboard layout
  • cpu temperature
  • fan speed
  • ram used
  • percentage of remaining battery
  • power consumption
  • brightness level
  • sound level
  • a clock

Technical details

Each value is contained in a Block. A Block has an icon, a color and a text content. For each block a listener and a callback are defined. The listener calls the callback whenever the content of the block should be updated.

The application is multi-threaded, and each block runs in its own thread. Thus they can update themselve independently of each other. When a block's listener fires the associated callback, the content of the block changes and a global pthread_cond_t condition variable is unblocked. The main function can then loop over all the blocks, see which one has changed, and then set the output text accordingly.

Three types of listeners are implemented:

  • time_listener: the simplest one, simply sleep for a given interval then launch the callback.
  • aligned_time_listener: a variant of the first listener, update a block every n seconds but align the interval on an unix timestamp. For example, the clock should be updated every 60 seconds, but I want it to change instantaneously when the minute changes. For that, we align the update interval on the timestamp 1592384460, which is exactly 09:01:00 GMT.
  • file_listener: update the block every time the content of a file changes. It uses the inotify linux kernel library to monitor the specified files.

The aligned time listener is only used for the clock.

The file listener is used for all the values changed via a custom script, which writes the new value in a file every time it is called, namely the volume, the brightness and the current keyboard layout.

Unfortunately for the rest of the values the time listener is used. It is simply not possible to react to events such as a change in the cpu temperature or a drop of the battery level. Still, I use a different update interval, based on how often I want some informations to be updated.

dwmbar's People

Contributors

thomaschevalier avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.