FelixKratz / SketchyBar

A highly customizable macOS status bar replacement
https://felixkratz.github.io/SketchyBar/
GNU General Public License v3.0
5.45k stars 85 forks source link

Mouse scroll events #380

Closed revan closed 1 year ago

revan commented 1 year ago

Adds mouse.scrolled and mouse.scrolled.global.

Considerations:

mouse.scrolled I could see being useful for changing volume. mouse.scrolled.global I use to replicate the scroll feature of i3, where scrolling on the empty bar switches workspaces on the screen under mouse (not necessarily the focused screen).

Amended these dotfiles like so:

plugins/yabai.sh

mouse_scrolled() {
  if [ $1 -lt 0 ]; then
    id="$(yabai -m query --spaces --display $2 | jq 'sort_by(.index) | .[map(."is-visible") | index(true) - 1].index')" && yabai -m space --focus "${id}"
  elif [ $1 -gt 0 ]; then
    id="$(yabai -m query --spaces --display $2 | jq 'sort_by(.index) | reverse | .[map(."is-visible") | index(true) - 1].index')" && yabai -m space --focus "${id}"
  fi
}

case "$SENDER" in
  "mouse.clicked") mouse_clicked
  ;;
  "forced") exit 0
  ;;
  "window_focus") window_state 
  ;;
  "windows_on_spaces" | "space_change") windows_on_spaces
  ;;
  "mouse.scrolled.global") mouse_scrolled "$DELTA_VERT" "$DISPLAY"
esac

items/yabai.sh

sketchybar --add event window_focus            \
           --add event windows_on_spaces       \
           --add item yabai left               \
           --set yabai "${yabai[@]}"           \
           --subscribe yabai window_focus      \
                             space_change      \
                             windows_on_spaces \
                             mouse.clicked     \
                             mouse.scrolled.global
FelixKratz commented 1 year ago

Thats certainly a nice idea, I have made some changes to the PR:

Have a look at the changes and once you are happy I will merge.

revan commented 1 year ago

Looks lovely, thanks for the cleanup and quick review!