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

Add FARTHEST_DIR_SEL for windows #1167

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kiryph
Copy link

@kiryph kiryph commented Feb 23, 2022

This PR is useful to enable circulation (aka cyclic or periodic boundaries) requested in #1165.

Following excerpt of an skhd file illustrates how to define mappings to use the added FARTHEST_DIR_SEL

# Left ⇧ ^ h
shift + ctrl - h : yabai -m window --focus west \
|| yabai -m window --focus farthest_east

# Down ⇧ ^ j
shift + ctrl - j : yabai -m window --focus south \
|| yabai -m window --focus farthest_north

# Up ⇧ ^ k
shift + ctrl - k : yabai -m window --focus north \
|| yabai -m window --focus farthest_south

# Right ⇧ ^ l
shift + ctrl - l : yabai -m window --focus east \
|| yabai -m window --focus farthest_west

Similar mappings can be defined for --swap, --stack and --warp.

@kiryph
Copy link
Author

kiryph commented Jul 21, 2022

Simpler Solutions with jq min_by/max_by(.frame.x)

This is simpler compared to the PR since it ignores the y-coordinate. In complex window layouts, the behaviour of the PR can be viewed as more desirable since two windows with the same x-coordinate are distinguished by the y-coordinate and the one with the closer y-coordinate is returned.

Windows

  1. Focus Most Right Window across Displays
yabai -m window --focus $(yabai -m query --windows | jq '[.[] | select(."is-visible")] | max_by(.frame.x) | .id')
  1. Focus Most Left Window across Displays
yabai -m window --focus $(yabai -m query --windows | jq '[.[] | select(."is-visible")] | min_by(.frame.x) | .id')
  1. Focus Most Left Window on Right Display
yabai -m window --focus $(yabai -m query --windows --display east | jq '[.[] | select(."is-visible")] | min_by(.frame.x) | .id')
  1. Focus Most Right Window on Left Display
yabai -m window --focus $(yabai -m query --windows --display west | jq '[.[] | select(."is-visible")] | max_by(.frame.x) | .id')

Displays

This approach can also be used to determine for displays the farthest east/west display

  1. Focus Most Right Display
yabai -m display --focus $(yabai -m query --displays | jq 'max_by(.frame.x) | .index')
  1. Focus Most Left Display
yabai -m display --focus $(yabai -m query --displays | jq 'min_by(.frame.x) | .index')

@kiryph
Copy link
Author

kiryph commented Jul 25, 2022

Solution with jq min_by/max_by and minimize perpendicular coordinate

  1. Focus Top Window on Current Space
CUR=$(yabai -m query --windows --window | jq -rc) &&\
MIN_Y=$(yabai -m query --windows --space | jq -e '[.[] | select(."is-visible")] | min_by(.frame.y) | .frame.y') &&\
FARTHEST_NORTH=$(yabai -m query --windows --space | jq -e --argjson min_y $MIN_Y --argjson cur $CUR \
'[.[] | select(."is-visible" and .frame.y == $min_y and .frame.y < $cur.frame.y)] | min_by((.frame.x - $cur.frame.x)|fabs) | .id') &&\
yabai -m window --focus $FARTHEST_NORTH;
  1. Focus Bottom Window on Current Space
CUR=$(yabai -m query --windows --window | jq -rc) &&\
MAX_Y=$(yabai -m query --windows --space | jq -e '[.[] | select(."is-visible")] | max_by(.frame.y) | .frame.y') &&\
FARTHEST_SOUTH=$(yabai -m query --windows --space | jq -e --argjson max_y $MAX_Y --argjson cur $CUR \
'[.[] | select(."is-visible" and .frame.y == $max_y and .frame.y > $cur.frame.y)] | min_by((.frame.x-$cur.frame.x)|fabs) | .id') &&\
yabai -m window --focus $FARTHEST_SOUTH;
  1. Focus Most Left Window on Current Space
CUR=$(yabai -m query --windows --window | jq -rc) &&\
MIN_X=$(yabai -m query --windows --space | jq -e '[.[] | select(."is-visible")] | min_by(.frame.x) | .frame.x') &&\
FARTHEST_WEST=$(yabai -m query --windows --space | jq -e --argjson min_x $MIN_X --argjson cur $CUR \
'[.[] | select(."is-visible" and .frame.x == $min_x and .frame.x < $cur.frame.x)] | min_by((.frame.y-$cur.frame.y)|fabs) | .id') &&\
yabai -m window --focus $FARTHEST_WEST;
  1. Focus Most Right Window on Current Space
CUR=$(yabai -m query --windows --window | jq -rc) &&\
MAX_X=$(yabai -m query --windows --space | jq -e '[.[] | select(."is-visible")] | max_by(.frame.x) | .frame.x') &&\
FARTHEST_EAST=$(yabai -m query --windows --space | jq -e --argjson max_x $MAX_X --argjson cur $CUR \
'[.[] | select(."is-visible" and .frame.x == $max_x and .frame.x > $cur.frame.x)] | min_by((.frame.y-$cur.frame.y)|fabs) | .id') &&\
yabai -m window --focus $FARTHEST_EAST;

However, a builtin solution can be faster. These shell scripts consist of

  • 3x yabai queries
  • 3x invocations of jq and
  • the final user action

@Bellavene
Copy link

Yes, with this it would be so much easier

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