A modular statusbar for dwm written in C

Related tags

CLI dwmblocks
Overview

dwmblocks

A modular statusbar for dwm written in C. You may think of it as i3blocks, but for dwm.

Features

  • Modular
  • Lightweight
  • Suckless
  • Blocks are clickable
  • Blocks are loaded asynchronously
  • Each block can be externally triggered to update itself
  • Compatible with i3blocks scripts

Apart from these features, this build of dwmblocks is more optimized and fixes the scroll issue due to which the statusbar flickers on scrolling.

Why dwmblocks?

In dwm, you have to set the statusbar through an infinite loop like this:

while :; do
    xsetroot -name "$(date)"
    sleep 30
done

It may not look bad as it is, but it's surely not the most efficient way when you've got to run multiple commands, out of which only few need to be updated as frequently as the others.

# Displaying an unread mail count in the status bar
while :; do
    xsetroot -name "$(mailCount) $(date)"
    sleep 60
done

For example, I display an unread mail count in my statusbar. Ideally, I would want this count to update every thirty minutes, but since I also have a clock in my statusbar which has to be updated every minute, I can't stop the mail count from being updated every minute.

As you can see, this is wasteful. And since my mail count script uses Gmail's APIs, there's a limit to the number of requests I can make, being a free user.

What dwmblocks does is that it allows you to break up the statusbar into multiple blocks, each of which have their own update interval. The commands in a particular block are only executed once in that interval. Hence, we don't run into our problem anymore.

What's even better is that you can externally trigger updation of any specific block.

Installation

The installation is simple, just clone this repository, modify config.h appropriately, and then do a sudo make install.

git clone https://github.com/UtkarshVerma/dwmblocks.git
vi config.h
sudo make install

Usage

To have dwmblocks set your statusbar, you need to run it as a background process on startup. One way is by adding the following to ~/.xinitrc.

dwmblocks &

Modifying the blocks

You can define your statusbar blocks in config.h. Each block has the following properties:

Property Value
Command The command you wish to execute in your block
Update interval Time in seconds, after which you want the block to update. Setting this to 0 will result in the block never being updated.
Update signal Signal to be used for triggering the block. Must be a positive integer.

The syntax for defining a block is:

static Block blocks[] = {
    ...
    {"date", 1800, 1},
    ...
}

Apart from that you can also modify the block delimiters and width of each block as shown.

// Maximum length of each block, expressed in number of characters.
#define CMDLENGTH 50

#define DELIMITER " "

Signalling changes

Most statusbars constantly rerun every script every several seconds to update. This is an option here, but a superior choice is giving your module a signal that you can signal to it to update on a relevant event, rather than having it rerun idly.

For example, the volume module has the update signal 5 by default. Thus, running pkill -RTMIN+5 dwmblocks will update it.

You can also run kill -44 $(pidof dwmblocks) which will have the same effect, but is faster. Just add 34 to your typical signal number.

My volume module never updates on its own, instead I have this command run along side my volume shortcuts in dwm to only update it when relevant.

Note that all modules must have different signal numbers.

Clickable modules

Like i3blocks, this build allows you to build in additional actions into your scripts in response to click events. You can check out my statusbar scripts as references for using the $BLOCK_BUTTON variable.

For this feature to work, you need dwm to be patched with statuscmd.

Credits

This work would not have been possible without Luke's build of dwmblocks and Daniel Bylinka's statuscmd patch.

Issues
  • user-defined signal 1

    user-defined signal 1

    clicking on statusbar/module makes dwmblocks-async crash with code 138 output: user-defined signal 1 dwmblocks

    this happens when used with my modified dwm build + default dwm only patched with dwm-statuscmd-status

    opened by wael444 9
  • Cant click blocks

    Cant click blocks

    hi, thanks for your work, everythings good but i'm having problem with clicking on the blocks as it does nothing. here is my config:

    #define CMDLENGTH 60
    #define DELIMITER " | "
    #define CLICKABLE_BLOCKS
    
    const Block blocks[] = {
        BLOCK("sb-mail",        180,        17),
        BLOCK("sb-news",        1,          18),
        BLOCK("sb-forecast",    18000,      19),
        BLOCK("sb-memory",      1,          20),
        BLOCK("sb-gpu",         1,          21),
        BLOCK("sb-cpu",         1,          22),
        BLOCK("sb-time",        0,          23),
        BLOCK("sb-date",        1,          24),
        // BLOCK("sb-network", 5,    25),
    };
    

    and here is the script for sb-news

    #!/bin/sh
    
    case $BLOCK_BUTTON in
        1) setsid "$TERMINAL" -e newsboat ;;
    esac
    
    . sb-theme
    display "$(cat /tmp/newsupdate 2>/dev/null || echo "$(newsboat -x print-unread | awk '{ if($1>0) print "NEWS:" $1}')")"
    

    i use this statuscmd-status2d-with-signal

    did i do it all correctly?😅 thanks for the help

    Edit: distro- Void linux

    opened by hoaxdream 8
  • DELIMITER is added at end

    DELIMITER is added at end

    image ~~do not mind the colors, only using delimiter as example~~ would it be possible to add a check to attempt to remove if there isn't anything after the delimiter? or is this intentional?

    enhancement 
    opened by wael444 8
  • How to avoid re-runing on click/scroll

    How to avoid re-runing on click/scroll

    I'm not sure if I'm doing this right, but I'd like to use mouse scroll on my volume block. In order to do this, I have to enable scroll buttons in dwm, and by doing it I enable it for ALL the blocks. It works, scrolling triggers my script action but it also reruns calculation too. It's not a problem for the volume block, it is actually desirable, but I have some blocks that take seconds to execute, and scrolling above them makes them execute many times.

    • as far as I know I cannot disable scroll for individual blocks in DWM
    • if I detect mouse scroll in my complex script and exit early, then block is deleted as script output was blank
    • I cannot access old state of the block, a cached version, to return it before early exit

    I'm not sure how to do this or is it even possible.

    opened by psiho 4
  • state bar have a small square is displayed

    state bar have a small square is displayed

    Hello Guys,

    Good day to you.

    I have a small square is displayed at the front of the time, Anyone knows what is the reason for this issue?

    I also have another question.

    I saw the NOTE below.

    Please note that if you are using dwm-flexipatch, then you only need to enable the statuscmd patch through patches.h. There is no need to edit change the definition of getstatusbarpid() as the changes have already been applied there through dwm-flexipatch#190.

    I also using dwm-flexipatch now. May I ask which statuscmd patch are you enabled? Currently, I am enabled:

    #define BAR_DWMBLOCKS_PATCH 1
    #define BAR_STATUS2D_PATCH 1
    

    Are there any other patches that need to enable?

    Thanks, Boyang Yan

    opened by yanboyang713 4
  • unknown signal  dwmblocks

    unknown signal dwmblocks

    to replicate: make dwm from source, patch statuscmd, launch dwmblocks-async, click, get hit with unknown signal. it doesn't even have to run a script! it can just be "echo hello" and it just died!

    now i'm not sure if this can be replicated because this might be something wrong with my system. when using torrinfail/dwmblocks with the statuscmd patch in the README.md it won't work. using statuscmd patch from suckless.org works?

    opened by wael444 4
  • Maximum number of blocks?

    Maximum number of blocks?

    Is there a maximum number of displayable blocks? When I use over 10 blocks, the last ones in the list disappear or visually bug into the middle, but are not clickable.

    bug 
    opened by Pyxels 4
  • Clickability without statuscmd patch?

    Clickability without statuscmd patch?

    Hello there, trying to understand what does that block mean "Earlier, dwmblocks-async used to require a patch to be applied to dwm. However, the code has been redone so there's no need to apply that patch anymore." in clickability section. Is it not nessasery to install statuscmd patch? Mine not working without this patch.

    opened by Tinkerbells 3
  • statusbar is covered by wm_name and has strange square displayed in blocks

    statusbar is covered by wm_name and has strange square displayed in blocks

    1648108915 Above is my statusbar. And as the screenshot can speak itself, the statusbar is wrongly coverd and squares appear in blocks.

    For the first problem, I changed #define CMDLENGTH from 60 to 100, and it didn't worked.

    For the second problem, I've looked through #13, but unfortunately I don't use bakkeby/dwm-flexipatch, so his solution doesn't work for me (while I've patched statuscmd and corrected getstatusbarpid()).

    Here's my config.h for dwmblocks

    #define CMDLENGTH 100
    #define DELIMITER "|"
    #define CLICKABLE_BLOCKS
    
    const Block blocks[] = {
    	BLOCK("sb-battery", 60,    0),
    	BLOCK("sb-volume",   0,    3),
    	BLOCK("sb-light",    0,    2),
    	BLOCK("sb-date",    30,    0)
    };
    

    And my build of dwm is here.

    opened by yuandi42 3
  • Modules are not clickable

    Modules are not clickable

    Trying to switch to lukes build of dwmblocks to this but it seems to be impossible.. Can't click any modules and I have made the changes to the statuscmd patch (I think I did I did it right, the exact line to change wasn't there but something similar was) so clicking does nothing. I also can't get icons to work unless I change all my scripts to use echo and then echo the icon #20 FYI I'm using my own build that's based off of Lukes.

    opened by JimPix1 3
  • double output in statusbar

    double output in statusbar

    Hi sir, do you know why the blocks doubling up? specially the one with icons. it is fixed if i change the volume, this is common when at first boot of pc. Issue

    opened by hoaxdream 3
  • `pkill -RTMIN` and `nohup &` don't work correctly

    `pkill -RTMIN` and `nohup &` don't work correctly

    Sorry to bother you again with stupid questions. Below is a clumsy shell script called sb-mpd, written by me to show mpd status:

    #!/usr/bin/sh
    # show mpd status. WIP
    
    icon=" ------"
    color="^c#7c6f64^"
    if [ $(pidof mpd) ]; then 
        case $BLOCK_BUTTON in
            1) mpc toggle >/dev/null 2>&1 && pkill -RTMIN+15 dwmblocks;;
            2) notify-send "Current Music" "$(mpc status|head -n1)"
               pkill -RTMIN+15 dwmblocks;; # show current music
            3) nohup setsid -f "$TERMINAL" -e ncmpcpp &;;  # right click, open ncmpcpp
            4) mpc prev >/dev/null 2>&1  ;;  # scroll up, previous
            5) mpc next >/dev/null 2>&1  ;;  # scroll down, next
        esac
        stt=$(mpc status | grep '^\[p'| cut -d " " -f 1)
        case $stt in
            *pause*) icon=" PAUSED";;
            *play*)  icon=" PLYING"; color="^c#427b58^";;
        esac
    else 
        case $BLOCK_BUTTON in
            1) mpd && pkill -RTMIN+15 dwmblocks;; # left click to launch mpd
            3) "$TERMINAL" -e "$EDITOR" "$0";; 
        esac
        icon=" NO MPD"
    fi
    
    printf "|$color$icon^d^"
    

    There may be some unicode characters display wrongly since I use nerd fonts.

    The first problem I had encounter with is in the line 22 mpd && pkill -RTMIN+15 dwmblocks. Ideally when I left click the block, mpd should start then the block should refresh, and it work correctlly when I test the command in my terminal. However, when I try to left click the block, blocks doesn't refresh, still showing "NO MPD" (mpd is actually launched though).

    Another problem is about command in the line 11 nohup setsid -f "$TERMINAL" -e ncmpcpp &. In my view, ncmpcpp would be launched independently so that the block can refresh or accept later click event. Well, it doesn't. And htop tree shows that there is a child process echo $(sb-mpd) hanging under dwmblocks.

    I would appreciate for your anwser. P.S.: obviously setsid -f doesn't work either.

    enhancement help wanted 
    opened by yuandi42 9
Owner
Utkarsh Verma
A keen maker, programmer and an Instructables author.
Utkarsh Verma
a shell written in C

shell a shell written in C. CREDITS = https://github.com/brenns10/lsh/blob/master/src/main.c -for most of the template code. This project has a 10% ch

Arin 11 Jul 1, 2021
The KISS file manager: CLI-based, ultra-lightweight, lightning fast, and written in C

CliFM is a CLI-based, shell-like (non-curses) and KISS terminal file manager written in C: simple, fast, and lightweight as hell

leo-arch 481 May 10, 2022
Command-Based Text Editor written in cpp using Linked Lists and Stack

Command Based Text Editor Our goal in this project is to write a command-based text editor in cpp using linked lists and stack. This text editor will

bedirhanbardakci 3 Jun 9, 2021
Windows command line program for Spleeter, written in pure C, no need of Python.

SpleeterMsvcExe is a Windows command line program for Spleeter, which can be used directly. It is written in pure C language, using ffmpeg to read and write audio files, and using Tensorflow C API to make use of Spleeter models. No need to install Python environment, and it does not contain anything related to Python.

Wudi 146 May 4, 2022
A Command-Line-Interface Debugger for 64-bit Windows written in C.

Debugger-For-Windows A command-line-interface debugger for 64-bit Windows. [email protected]:/mnt/c/Projects/C/Debugger$ ./Debugger.exe ./Tests/test.ex

Tomer Gibor 1 Nov 3, 2021
Operating system in Terminal written in pure C++

terminal-OS Operating system in Terminal written in pure C++ Features: Mouse tracking Colorful print Window move/resize Hide windows to Taskbar Apps:

Egor Zheltkevich 23 Jan 7, 2022
SimPle SHell - minimalist Unix interactive shell written in a single C file

SimPle SHell - minimalist Unix interactive shell written in a single C file. The shell does not support scripting yet and is in an early stage of development. If you notice any bug, please open an issue on github.

sewe2000 2 Oct 24, 2021
A lightweight utility for parsing PE file formats (EXE, DLL, SYS) written in C/C++

peParser A lightweight utility for parsing PE file formats (EXE, DLL, SYS). Windows Portable Executable (PE) files includes a variety of parsable data

null 17 May 10, 2022
An extremely fast FEC filing parser written in C

FastFEC A C program to stream and parse FEC filings, writing output to CSV. This project is in early stages but works on a wide variety of filings and

The Washington Post 48 May 18, 2022
A CLI program that helps you find classes and plan pre-requisites. Written in C++ and Python.

CourseHelper A CLI program created to help you prepare for course registration. Note: At the moment, this project is built specifically for other UCLA

Kyle Chui 1 Jan 25, 2022
mstatus is a super minimal entirely signal based statusbar for DWM.

mstatus is a uber-minimalistic signal based statusbar for DWM. All components of the statusbar are modules that must either be written by the user, or written by someone else and copied by the user.

Thomas Voss 1 Feb 2, 2022
Modular status bar for dwm written in c.

dwmblocks Modular status bar for dwm written in c. usage To use dwmblocks first run 'make' and then install it with 'sudo make install'. After that yo

C0de 1 Oct 12, 2021
My build of dwm based on dwm-flexipatch.

This dwm 6.2 (67d76bd, 2021-03-29) side project has a different take on dwm patching. It uses preprocessor directives to decide whether or not to incl

Utkarsh Verma 0 Feb 17, 2022
A custom macOS statusbar with shell plugin, interaction and graph support

SketchyBar This is a rewrite of the spacebar project, which itself is a rewrite of the statusbar code from yabai. Features: As many widgets as you lik

Felix Kratz 540 May 15, 2022
My dwm-dotfiles

Intro This repo include 2 color scheme's config, one is Gruvbox, the other is Nord. Each of them include global Dark and Light color scheme which can

null 224 May 7, 2022
dwm is an extremely fast, small, and dynamic window manager for X.

dwm - dynamic window manager dwm is an extremely fast, small, and dynamic window manager for X. My Patches This is in the order that I patched everyth

Christian Chiarulli 29 Apr 17, 2022
Demonstrates implementation of the Windows 10 Acrylic Effect on C++ Win32 Apps using DWM Private APIs and Direct Composition

Win32 Acrylic Effect A Demonstration of Acrylic Effect on C++ Win32 applications using Direct Composition and DWM private APIs. Table of Contents Over

Selastin 88 May 7, 2022
making dwm as beautiful as possible

chadwm (Initial look) (empty workspaces have their color greyed out) NOTE: This is vanilla dwm bar (status2d patch for setting colors) not dwmblocks o

null 697 May 11, 2022
A simple utility that cold patches dwm (uDWM.dll) in order to disable window rounded corners in Windows 11

Win11DisableRoundedCorners A simple utility that cold patches the Desktop Window Manager (uDWM.dll) in order to disable window rounded corners in Wind

Valentin-Gabriel Radu 351 May 15, 2022
my personalized/patched dwm + st

personalized/patched dwm & st dwm patches * centeredmaster fibonacci uselessgap shiftview st patches * blinkingcursor font2 scrollback custom gruvbox

null 4 Mar 28, 2022
Contains ST, Status Bar, DWM, DMenu, Wallpaper and Xinitrc

Very Minimal DWM Setup Contains ST, Joestandring's Dwm-Bar, DWM, DMenu, Wallpaper and .xinitrc Patches & Customization St: Alpha Scrollback Scrollback

Finn Gould 2 Jan 11, 2022
My own dwm setup with patches

dwm - dynamic window manager ============================ dwm is an extremely fast, small, and dynamic window manager for X. Requirements ----------

Nazih Boudaakkar 1 Oct 29, 2021
Alok's dwm build

dwm - dynamic window manager ============================ dwm is an extremely fast, small, and dynamic window manager for X. Requirements ----------

Alok Shandilya 1 Dec 15, 2021
voidwm Jitesh's build of dwm

voidwm Jitesh's build of dwm Getting started Installation Clone the repository and run make: git clone https://github.com/pixxel8/voidwm cd voidwm sud

Jitesh Prajapat 28 Apr 20, 2022
dwm config made with flexipatch

dwm Gruvbox One Dark eww Gruvbox One Dark some info dwm flexipatch - https://github.com/bakkeby/dwm-flexipatch st flexipatch - https://github.com/bakk

Nikita 24 May 1, 2022
johannes sin versjon av dwm

dwm - dynamic window manager ============================ dwm is an extremely fast, small, and dynamic window manager for X. Requirements ----------

Johannes Hove-Henriksen 1 Nov 21, 2021
Making dwm as beautiful as possible!

chadwm (Initial look) (empty workspaces have their color greyed out) NOTE: This is vanilla dwm bar (status2d patch for setting colors) not dwmblocks o

null 699 May 13, 2022
Dotfiles - My dotfiles with dwm and qtile.

Intro This repo include 2 color scheme's config, one is Gruvbox, the other is Nord. Each of them include global Dark and Light color scheme which can

null 228 May 13, 2022
🎁 An easy way to install DWM + Dots

DWM - DOTS ━━━━━━ ❖ ━━━━━━ Window Manager • DWM ?? Tiles Everywhere! Shell • Zsh ?? con oh-my-zsh framework! Terminal • Kitty ?? Una terminal que sopo

linuxmobile ( リナックス ) 32 Apr 30, 2022