DEV Community

Mirko Vukušić
Mirko Vukušić

Posted on

4 2

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 fullscreen-toggle.sh and put it somewhere (mine are in ~/scripts/). Also make it executable:

#!/bin/sh
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/fullscreen-toggle.sh
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.

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more