Skip to content

Conversation

@ChrisTitusTech
Copy link
Owner

Event-Driven Polybar Tag Updates

Overview

Modified DWM and the polybar dwm-tags script to use event-driven updates instead of polling every second. This reduces CPU usage and provides instant visual feedback when switching tags.

How It Works

1. DWM Changes (dwm.c)

  • Added updatepolybar() function that sets an X property DWM_TAG_UPDATE on the root window
  • Called updatepolybar() in key functions:
    • view() - when switching to a different tag
    • tag() - when moving a window to a tag
    • toggletag() - when toggling tag membership
    • toggleview() - when toggling tag visibility

2. Script Changes (polybar/scripts/dwm-tags.sh)

  • Added --tail mode that listens for X property changes using xprop -spy
  • Refactored tag generation into update_tags() function
  • When run with --tail, the script:
    1. Outputs initial state
    2. Listens for DWM_TAG_UPDATE property changes
    3. Updates display whenever the property changes

3. Polybar Config (polybar/themes/minimal/modules/dwm-tags.ini)

  • Changed from interval = 1 to tail = true
  • Added --tail argument to the script execution

Benefits

  • Lower CPU usage: No more polling every second
  • Instant updates: Visual changes happen immediately when tags switch
  • More efficient: Only updates when something actually changes
  • Backward compatible: Script still works in polling mode without --tail argument

To Apply Changes

  1. Recompile and install DWM: sudo make clean install
  2. Restart DWM (typically Mod+Shift+R or re-login)
  3. Restart polybar: ~/.local/share/dwm-titus/polybar/launch.sh

The polybar module will now update instantly when you switch workspaces instead of polling every second.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants