FelixKratz / JankyBorders

A lightweight window border system for macOS
GNU General Public License v3.0
1k stars 18 forks source link

Disable when only one window is active #53

Closed ahan98 closed 7 months ago

ahan98 commented 7 months ago

Hi,

Thanks for the excellent package. Is there a way to disable borders when there is only a single window active?

FelixKratz commented 7 months ago

Sure, you can easily script this with e.g. your window manager. All properties of the borders can be changed at any time, such that you will easily be able to change the active_color to be fully transparent like this:

borders active_color=0x00000000

and then change it back to your preferred color as soon as more than one window is displayed:

borders active_color=0xffff0000

You could for example use the window_created and window_destroyed signals in yabai to receive the scripting events, or you rely on the space_windows_change event in sketchybar for scripting.

ahan98 commented 7 months ago

In case it helps other readers, here's how I achieved this effect with yabai.

At the bottom of ~/.config/yabai/yabairc:

# set the correct starting active_color upon initializing yabai, based on number of windows in current space
n=$(yabai -m query --spaces --space | jq '.windows | length')
if [ $n = 1 ]; then
    borders hidpi=on width=6.0 inactive_color=0x00000000 active_color=0x00000000 &
else
    borders hidpi=on width=6.0 inactive_color=0x00000000 active_color=0xffff9bd2 &
fi

yabai -m signal --add event=window_focused action="$YABAI/update_border_color.sh"

Inside $YABAI/update_border_color.sh (replace $YABAI with the appropriate path):

#!/usr/bin/env bash

n=$(yabai -m query --spaces --space | jq '.windows | length')
if [ $n = 1 ]; then
    borders active_color=0x00000000
else
    borders active_color=0xffff9bd2
fi

Note that the if-else block that I included in ~/.config/yabai/yabairc is not absolutely necessary, since the yabai background process should be initialized upon machine startup, but I included it for completeness to achieve the correct behavior when yabai is reset at any other time.

diogox commented 2 weeks ago

For anyone using Aerospace, add the first line in this snippet:

on-focus-changed = [
  'exec-and-forget [ $(aerospace list-windows --workspace focused | wc -l) -eq 1 ] && borders width=0.0 || borders width=6.0',
  'move-mouse window-lazy-center'  # Mouse lazily follows any focus (window or workspace)
]

It will make the border disappear when there is only one window in the focused workspace.

If you'd like the border to disappear when the layout is fullscreen, follow this ticket.