Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse scroll events #380

Merged
merged 2 commits into from
Jun 28, 2023
Merged

Mouse scroll events #380

merged 2 commits into from
Jun 28, 2023

Conversation

revan
Copy link
Contributor

@revan revan commented Jun 24, 2023

Adds mouse.scrolled and mouse.scrolled.global.

Considerations:

  • This currently captures only vertical scrolling -- horizontal scrolling still fires the event but with a zero delta. Follow-up would be to expose the horizontal delta as well and/or combine them into one signal.
  • I think this only applies to mouse wheels (so no track pad, but we have proper gestures there).

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
Copy link
Owner

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

  • Remove the scroll_script, I don't think it is needed to have this property.
  • Add the internal event codes
  • Rename some variables and properties, i.e. the scroll delta variable is now SCROLL_DELTA
  • Limit the rate at which the scroll events can fire, this is needed in order to not fork-bomb the system when having a fast scroll rate mouse.

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

@revan
Copy link
Contributor Author

revan commented Jun 28, 2023

Looks lovely, thanks for the cleanup and quick review!

@FelixKratz FelixKratz merged commit f0c1d8a into FelixKratz:master Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants