Featured image of post Customizing auto-hide behavior for Waybar in Hyprland

Customizing auto-hide behavior for Waybar in Hyprland

Waybar is great, it keeps information like datetime, battery, network, etc. at a glance on the desktop. With Hyprland, it also shows workspaces and running applications.

As great as it is, there is one problem. It takes up screen space.

Waybar on laptop

This is a huge issue on my 13" laptop screen.

Strategizing

From what I found online and what I experimented, there were two relatively easy ways to hide Waybar.

  1. Toggle visibility with a keybind: The most straightforward way. Just needs a keybind in Hyprland config to send signals to Waybar.
  2. Only show when mouse is at a specific region: Windows and some Linux DEs do it this way. Seems like it needs some scripting to do it on Hyprland, but still doable.

During the research I learned from the wiki that Waybar supports two types of signals:

  1. SIGUSR1
  2. SIGUSR2

Both are listened by Waybar, and their behaviors can be configured in Waybar config file as: show, hide, toggle, reload, noop.

The ones interested me were show and hide. These would allow me to do control visibility from anywhere in my Hyprland config.

Now, with my workflow, I want to minimize the usage of my mouse. So option 2 was out. I also wasn’t a big fan of option 1, since it I would have to remember to hide the bar every time I check something on it.

My Solution

Then I remembered something I did in Final Fantasy 14. There was an option to show a particular UI element like a menu bar only when a key is held down (or was it toggling between two menu bars? I don’t remember exactly). This behavior was what I wanted.

I wanted to show Waybar only when meta key is held down.

Since all of my window and workspace-related keybindings used the meta key, it would allow me to:

  1. Hold down meta key to show waybar, quickly glance workspaces, apps, etc.
  2. Input rest of the keybinding, and waybar would be hidden automatically when meta key is released.

When I want to check some info on waybar, I would just briefly hold down meta key.

Waybar config

Aside from some styling changes, I just needed to add these two lines to the waybar config file ~/.config/waybar/config.jsonc.

1
2
"on-sigusr1": "show",
"on-sigusr2": "hide",

Quick test:

1
2
kill -SIGUSR1 $(pidof waybar)  # show
kill -SIGUSR2 $(pidof waybar)  # hide

Hyprland config

On Hyprland side, things get a little tricky.

The keybinding itself was pretty straightforward. All I need was binds for holding/releasing in ~/.config/hypr/hyprland.conf.

1
2
3
4
5
# waybar - show on press, hide on release
bindt = , SUPER_L, exec, killall -SIGUSR1 waybar
bindt = , SUPER_R, exec, killall -SIGUSR1 waybar
bindrt = SUPER, SUPER_L, exec, killall -SIGUSR2 waybar
bindrt = SUPER, SUPER_R, exec, killall -SIGUSR2 waybar

The submap issue

However, as I tested it, I found that the bindrt did not work in one specific scenario: when I entered a submap with the meta key held down.

Waybar would stay visible after I’ve entered the submap and released the meta key, which is okay but not expected. It’s actually a pretty good way to remind myself that I’m in a submap.

It would then stay open when I exit the submap, which is expected, but not okay. Obviously there’s nothing to trigger the SIGUSR2 when exiting the submap, so it stays there. It would stay there until I press the meta key again, which is a bit annoying.

Since this is a very specific problem, I went with a very specific solution, just by launching a tiny script to monitor submap status and hide waybar when exiting a submap.

waybar-submap-monitor.sh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/bin/bash
# hide waybar when exiting hyprland submap

if pidof -x -o $$ "$(basename "$0")" > /dev/null; then
    echo "Another instance of $(basename "$0") is already running. Exiting."
    exit 1
fi

socat -U - UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock | while read -r line; do
    if [[ "$line" == "submap>>" ]]; then
        killall -SIGUSR2 waybar
    fi
done

And launched it in the Hyprland config:

1
exec = $bindir/waybar-submap-monitor.sh

The outcome

With that, I had a waybar that only shows when meta key is held down, with the added bonus of showing the active submap.

Built with Hugo
Theme Stack designed by Jimmy