FelixKratz / JankyBorders

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

glitches when toggling the dock. #99

Open aspauldingcode opened 1 month ago

aspauldingcode commented 1 month ago

The window borders forget the windows have been moved when yabai moves windows due to the dock being toggled on.

This is fixed temporarily by me by setting a borders background color to transparent, so it updates borders. This should however be fixed.

In addition, we should have an option that doesn't do anything but triggers borders. maybe return true successfully without doing anything. This would solve the issue without taking up a useful option. Maybe this could be named borders reload or borders --reload but I'd want this to not reload borders, only update the current process. That's what fixes the gap under the windows when the dock is toggled.

In addition, yabai sometimes forgets to move the windows. So, I've fixed that temporarily too by setting the external_bar size twice.

for the sake of reproducability, I've included my toggle-dock script, defined in my nix config.

# toggle-dock
    (pkgs.writeShellScriptBin "toggle-dock" ''
      dock_state_file="/tmp/dock_state"
      gaps_state_file="/tmp/gaps_state"
      sketchybar_state_file="/tmp/sketchybar_state"

      toggle_dock() {
          local dock_status=$(osascript -e 'tell application "System Events" to get autohide of dock preferences')
          local gaps_status=$(cat "$gaps_state_file")
          local sketchybar_status=$(cat "$sketchybar_state_file")
          update_spaces_and_bar() {
            #sleep 1
            if [ "$gaps_status" = "on" ]; then
                ${yabai} -m config external_bar all:50:1
                ${yabai} -m config external_bar all:50:0
            else
                ${yabai} -m config external_bar all:42:1
                ${yabai} -m config external_bar all:42:0
            fi
            ${borders} background_color=0x000000
          }

          if [ $# -eq 0 ]; then
              # No arguments provided, toggle based on current state
              if [ "$dock_status" = "true" ]; then
                  osascript -e 'tell application "System Events" to set autohide of dock preferences to false'
                  echo "Dock toggled on"
                  echo "on" > "$dock_state_file"  # Save state to file
                  update_spaces_and_bar
              else
                  osascript -e 'tell application "System Events" to set autohide of dock preferences to true'
                  echo "Dock toggled off"
                  echo "off" > "$dock_state_file"  # Save state to file
                  update_spaces_and_bar
              fi

          elif [ "$1" = "on" ]; then
              if [ "$dock_status" = "true" ]; then
                  osascript -e 'tell application "System Events" to set autohide of dock preferences to false'
                  echo "Dock toggled on"
                  echo "on" > "$dock_state_file"  # Save state to file
                  update_spaces_and_bar
              else
                  echo "Dock is already toggled on"
              fi
          elif [ "$1" = "off" ]; then
              if [ "$dock_status" = "false" ]; then
                  osascript -e 'tell application "System Events" to set autohide of dock preferences to true'
                  echo "Dock toggled off"
                  echo "off" > "$dock_state_file"  # Save state to file
                  update_spaces_and_bar
              else
                  echo "Dock is already toggled off"
              fi
          else
              # Invalid argument, toggle based on current state
              if [ "$dock_status" = "true" ]; then
                  osascript -e 'tell application "System Events" to set autohide of dock preferences to false'
                  echo "Dock toggled on"
                  echo "on" > "$dock_state_file"  # Save state to file
                  update_spaces_and_bar
              else
                  osascript -e 'tell application "System Events" to set autohide of dock preferences to true'
                  echo "Dock toggled off"
                  echo "off" > "$dock_state_file"  # Save state to file
                  update_spaces_and_bar
              fi
          fi
      }

      # Example usage
      toggle_dock "$1"
    '')