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

Yabai space focus from different display moved to the wrong space #1053

Closed
weizheheng opened this issue Nov 19, 2021 · 25 comments
Closed

Yabai space focus from different display moved to the wrong space #1053

weizheheng opened this issue Nov 19, 2021 · 25 comments

Comments

@weizheheng
Copy link

weizheheng commented Nov 19, 2021

First of all, thank you so much for the yabai-v4.0.0 release, things are working as before now on a Mac Intel running Monterey 12.0.1, the only issue I am seeing is the space focus between a multiple displays setup.

The problem

  • I have 2 displays and assign space 1-5 on display1 and 6-10 on display 2
  • Let's say, my current focus is on space 1, window 1 (display 1) and I have a window 2 last focused on space 6 (display 2)
  • When I now switch my focus from space 1 to space 7, the focus will first go to space 7 and then move back to space 6
  • Attached is a short clip showing the above scenario
2021-11-19_12-33-56.mp4
@danymat
Copy link

danymat commented Nov 19, 2021

I too can reproduce the bug. What I can do to "force" going to the wanted space is to focus twice at it

@weizheheng
Copy link
Author

I think it has something to do with the previously focused window on that particular display, for example, if I do not have any window focused on my display 2, then I can switch the spaces correctly. I am not good in C, but will try diving into the code and see if I can find the problem 😂.

@humberaquino
Copy link

I have this issue as well. When you want to go to a space in another display that is not focused it seems that yabai performs the action but then switches back to the previous space in the switched display.

PS. thanks a lot for the Monterrey fix!

@hb0nes
Copy link

hb0nes commented Dec 7, 2021

I have this issue as well and it is super annoying as I switch between displays all the time and it just feels very buggy and immature. Has this issue always been around or is it a MacOS 12/Apple Sillicon issue?

@weizheheng
Copy link
Author

I have this issue as well and it is super annoying as I switch between displays all the time and it just feels very buggy and immature. Has this issue always been around or is it a MacOS 12/Apple Sillicon issue?

I think this might be MacOS 12 related, this wasn't an issue before for me.

@sagikazarmark
Copy link

I also have this issue since macOS 12.

@hb0nes
Copy link

hb0nes commented Dec 20, 2021

Has anyone found a smart fix for this? It doesn't happen if you switch to the display first.
I guess with some query magic, we could work around this...

@hb0nes
Copy link

hb0nes commented Dec 20, 2021

I made it like this:

# fast focus desktop
lctrl + alt + cmd - 1  : /Users/b0nes/Personal/scripts/space-switch.sh 1
lctrl + alt + cmd - 2  : /Users/b0nes/Personal/scripts/space-switch.sh 2
lctrl + alt + cmd - 3  : /Users/b0nes/Personal/scripts/space-switch.sh 3
lctrl + alt + cmd - 4  : /Users/b0nes/Personal/scripts/space-switch.sh 4
lctrl + alt + cmd - 5  : /Users/b0nes/Personal/scripts/space-switch.sh 5
lctrl + alt + cmd - 6  : /Users/b0nes/Personal/scripts/space-switch.sh 6
lctrl + alt + cmd - 7  : /Users/b0nes/Personal/scripts/space-switch.sh 7
lctrl + alt + cmd - 8  : /Users/b0nes/Personal/scripts/space-switch.sh 8
lctrl + alt + cmd - 9  : /Users/b0nes/Personal/scripts/space-switch.sh 9
lctrl + alt + cmd - 0  : /Users/b0nes/Personal/scripts/space-switch.sh 10

Script contents:

#!/bin/bash

space=$1

yabai -m display --focus $(yabai -m query --spaces --space $space | jq .display)
yabai -m space --focus $space

Works for me.

@albert-ying
Copy link

Not just focus, moving window command also suffers (yabai -m window --space 8 actually move the window to the frontmost space at that display, instead of 8)

@danymat
Copy link

danymat commented Jan 19, 2022

True, it does the same for me

@hb0nes
Copy link

hb0nes commented Jan 19, 2022 via email

@weizheheng
Copy link
Author

Not just focus, moving window command also suffers (yabai -m window --space 8 actually move the window to the frontmost space at that display, instead of 8)

I didn't seem to have this problem, only the space focus but got it working for now doing something similar to how @hb0nes did it, by first focusing on the display if the space I am switching to is a different display.

@danrocha
Copy link

I didn't seem to have this problem, only the space focus but got it working for now doing something similar to how @hb0nes did it, by first focusing on the display if the space I am switching to is a different display.

Could you share your solution, please? 🙏

@weizheheng
Copy link
Author

I didn't seem to have this problem, only the space focus but got it working for now doing something similar to how @hb0nes did it, by first focusing on the display if the space I am switching to is a different display.

Could you share your solution, please? 🙏

Is actually the same as this #1053 (comment)

Add a script file and change the binding to run the script.

@kunte0
Copy link

kunte0 commented Jan 21, 2022

I didn't seem to have this problem, only the space focus but got it working for now doing something similar to how @hb0nes did it, by first focusing on the display if the space I am switching to is a different display.

Could you share your solution, please? 🙏

No need to run the script. Make sure you have jq installed

cmd - 1 : yabai -m display --focus $(yabai -m query --spaces --space 1 | jq .display); yabai -m space --focus 1
cmd - 2 : yabai -m display --focus $(yabai -m query --spaces --space 2 | jq .display); yabai -m space --focus 2
cmd - 3 : yabai -m display --focus $(yabai -m query --spaces --space 3 | jq .display); yabai -m space --focus 3
cmd - 4 : yabai -m display --focus $(yabai -m query --spaces --space 4 | jq .display); yabai -m space --focus 4
cmd - 5 : yabai -m display --focus $(yabai -m query --spaces --space 5 | jq .display); yabai -m space --focus 5
cmd - 6 : yabai -m display --focus $(yabai -m query --spaces --space 6 | jq .display); yabai -m space --focus 6
cmd - 7 : yabai -m display --focus $(yabai -m query --spaces --space 7 | jq .display); yabai -m space --focus 7
cmd - 8 : yabai -m display --focus $(yabai -m query --spaces --space 8 | jq .display); yabai -m space --focus 8
cmd - 9 : yabai -m display --focus $(yabai -m query --spaces --space 9 | jq .display); yabai -m space --focus 9

@koekeishiya
Copy link
Owner

koekeishiya commented Jan 21, 2022

This is on the latest master with the scripting-addition working on Monterey 12.1:

yabai -m space --focus .. works for me when the target space is NOT the active space of an inactive display.
yabai -m space --focus .. works for me when the target space is NOT the active space of an active display.

yabai -m window --space .. does NOT work for me when the target space is NOT the active space of an inactive display. Window is instead sent to the active space of the display that owns the target space.

yabai -m window --space .. works for me when the target space is NOT the active space of an active display.

The function that appears to have changed behaviour between macOS Big Sur and Monterey is: SLSMoveWindowsToManagedSpace.

I can also reproduce the issue mentioned in the OP.

@koekeishiya
Copy link
Owner

Both issues should now be resolved on the latest master. Closing this because Monterey issues are head-only.

@weizheheng
Copy link
Author

Both issues should now be resolved on the latest master. Closing this because Monterey issues are head-only.

Thank you so much! Work like a charm now.

@hb0nes
Copy link

hb0nes commented Jan 22, 2022 via email

@weizheheng
Copy link
Author

weizheheng commented Jan 22, 2022

Do you have a good method for upgrading to latest master, or did you just compile manually and replace the binary?

For me, I install yabai head through brew. There is a wiki about it.

@hb0nes
Copy link

hb0nes commented Jan 24, 2022 via email

@glingener
Copy link

Just came here while googling the problem. After I switched the screen I often got kicked back directly to the original with the annoying osx animation. The issue still persisted using master.

The source of the problem was in my skhd config:

alt - 1 : yabai -m space --focus 1; yabai -m window --focus first
alt - 2 : yabai -m space --focus 2; yabai -m window --focus first
alt - 3 : yabai -m space --focus 3; yabai -m window --focus first

The yabai -m window --focus first caused the problem. Seams it often got executed on the original space and that caused the move back.

Changing it to

alt - 1 : yabai -m space --focus 1
alt - 2 : yabai -m space --focus 2
alt - 3 : yabai -m space --focus 3

and it works fine.

As replacement of the yabai -m window --focus first I use focus_follows_mouse now.

Just sharing for the case someone else still has the problem after installing master.

Thanks for this great tool.

@koekeishiya
Copy link
Owner

koekeishiya commented Aug 29, 2022

@glingener You could automate your previous keybinding behaviour by using a signal:

yabai -m signal --add event=space_changed action="yabai -m window --focus first"

By default macOS will focus the window that previously had focus on the given space, which is why yabai by default does not override that behaviour.

@HATTER-LONG
Copy link

HATTER-LONG commented Sep 17, 2022

i just update to 4.0.4 and reload install-sa with wiki.
now i have the same problem the send window in different display.
after reinstall yabai not sloved it, anyone have any suggestions ?

like this send window to desktop 2, but it's send to 3 actually:
image

macos Monterey M1 .
yabai 4.0.4

koekeishiya added a commit that referenced this issue Sep 17, 2022
@koekeishiya
Copy link
Owner

My bad, fixed again on master.

jjant added a commit to jjant/nix-config that referenced this issue Nov 26, 2023
This was really buggy and apparently this was already working by
default, see koekeishiya/yabai#1053.
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

No branches or pull requests