DEV Community

Mirko Vukušić
Mirko Vukušić

Posted on

How to toggle Polybar on Spectrwm tiling wm

Just a short one on this problem with combination of Spectrwm tiling window manager and Polybar. Managed to sort it out after hours without finding a solution on the web. So here is my hack.

First, the problem... Once you replace the bar that comes with Spectrwm, with Polybar, you have to reserve a portion on top of the screen for Polybar. That's OK, but toggling Polybar leaves that reserved space empty so again you don't get a full screen. On the other hand, if you don't reserve that space, Polybar is displayed above your windows which is also not nice.

My solution is simple:

  1. Leave original bar ON with minimal settings, and remove reserved space for Polybar if you had it configured before (region in config). Only Spectrwm bar config items you need are:
bar_enabled     = 1
bar_border_width    = 0
bar_font        = <any font, just adjust size so bar is as large as Polybar>
bar_format      = ' # <--- something minimal so bar is almost not visible
Enter fullscreen mode Exit fullscreen mode
  1. make sure your original keybinding to toggle Spectrwm bar is still active (Super+b)

  2. install xdotool. Miniature program that can send fake keys to Xorg

  3. write shell script, I named it and put it somewhere (mine are in ~/scripts/). Also make it executable:

xdotool key super+b
polybar-msg cmd toggle
Enter fullscreen mode Exit fullscreen mode

Script is really simple. First, xdotool toggles Spectrwm bar by sending fake keypresses. Then we use polybar-msg to send remote command to Polybar to toggle.

  1. Add new keybinding to Spectrwm conf (~/.spectrwm.comf). I used MOD+Shift+f:
program[toggle_bars] = ~/scripts/
bind[toggle_bars] = MOD+Shift+f
Enter fullscreen mode Exit fullscreen mode

... and we're done! Restart Spectrwm (Super+q) and try it out. Make sure your keybinding was free before assigning it. Also, try running shell script from terminal for test.

Top comments (0)