FelixKratz / JankyBorders

A lightweight window border system for macOS
GNU General Public License v3.0
860 stars 19 forks source link

Toggle border option would be nice #74

Open thomasbecker opened 4 months ago

thomasbecker commented 4 months ago

First of all: Thx for all the work you put in jankyborders and sketchy bar.

Would be nice to have a toggle border command. Currently I'm toggling yabai gap/padding and jankyborder with this skhd mapping which works, but is a little hacky:

alt - p : yabai -m space --toggle padding ; yabai -m space --toggle gap ; if [[ -f /tmp/borders ]]; then borders width=0 ; rm /tmp/borders ; else borders width=5 ; touch /tmp/borders ; fi
Mccranky83 commented 4 months ago
alt - p : yabai -m space --toggle padding ; yabai -m space --toggle gap ; if [[ -f /tmp/borders ]]; then borders width=0 ; rm /tmp/borders ; else borders width=5 ; touch /tmp/borders ; fi

Because the padding does not take into account the width of the borders, I reckon the state of the borders should match that of yabai's padding. Say if the initial state has both padding and borders toggled on, and [[ -f /tmp/borders ]] is falsy, then skhd should map to borders width=0; touch /tmp/borders, thus turning both padding and borders off.

Frankly, what I'm trying to say is that the value assigned to borders' width in thomasbecker's command should be flipped.

alt - a : yabai -m space --toggle padding; yabai -m space --toggle gap; if [[ -f /tmp/borders ]]; then borders width=5; rm -rf /tmp/borders; else touch /tmp/borders; borders width=0; fi

Still, the padding and borders may not be coordinated at all, because the initial state is not anchored. Currently, I use this script and toggle borders alongside yabai paddings:

#!/usr/bin/env zsh

file_path=~/.config/borders/switch

flags=($(awk '{ print $NF }' $file_path))

toggle_setting() {
  local setting=$1
  local bool_value=$2
  sed -i "" "s/${setting}:.*/${setting}: ${bool_value}/" $file_path
}

if [[ ${flags[0]} = ${flags[1]} && ${flags[1]} = "on" ]]; then
  toggle_setting "borders" "off"
  borders width=0
  toggle_setting "padding" "off"
  yabai -m space --toggle padding
  yabai -m space --toggle gap
elif [[ ${flags[0]} = ${flags[1]} && ${flags[1]} = "off" ]]; then
  toggle_setting "borders" "on"
  borders width=5
  toggle_setting "padding" "on"
  yabai -m space --toggle padding
  yabai -m space --toggle gap
elif [[ ${flags[0]} = "off" && ${flags[1]} = "on" ]]; then
  toggle_setting "padding" "on"
  yabai -m space --toggle padding
  yabai -m space --toggle gap
elif [[ ${flags[0]} = "on" && ${flags[1]} = "off" ]]; then
  toggle_setting "padding" "off"
  yabai -m space --toggle padding
  yabai -m space --toggle gap
fi

awk '{ print $1, $NF }' $file_path
# Toggle desktop offset
alt - a : sh $HOME/.local/share/my_scripts/toggle_borders.sh
## switch is a text file containing two lines
padding: on
borders: on