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

Issue when focusing most recent window on a space #544

Closed
noib3 opened this issue May 28, 2020 · 11 comments
Closed

Issue when focusing most recent window on a space #544

noib3 opened this issue May 28, 2020 · 11 comments
Labels
bug Something isn't working

Comments

@noib3
Copy link

noib3 commented May 28, 2020

I have the following commands to create a new space and move there the focused window, and to focus a space:

alt + cmd - n : yabai -m space --create && \
                yabai -m window --space last && yabai -m space --focus last && yabai -m window --focus recent
alt - 1 : yabai -m space --focus 1 && yabai -m window --focus recent
alt - 2 : yabai -m space --focus 2 && yabai -m window --focus recent

I would expect --focus recent to focus the most recent window on a space, however sometimes that doesn't work. There are various situations where it doesn't work, but the simplest one that I've been able to reproduce is the following.

Start with 3 windows on space 1 (the only space for now), then issue the command bind to alt + cmd - n to create a second space, move the window there, focus the space and focus the window.

Now go back to space 1 with alt - 1, switch focus from one window to the other, then go back to space 2 with alt - 2. I find that the window is space 2 is now not focused, and if I go back to space 1 the focus switches between the two windows.

Am I using the wrong commands in the bindings or is this a bug? I'm on version 2.4.3.

@koekeishiya
Copy link
Owner

koekeishiya commented May 29, 2020

The recently focused window id is just a global storage, and is not stored per space, but the lookup is only performed in the active space. This means that if you are on space 1 and have window A and B opened, moving the focus from A to B, will make A the recent window. Focusing the recent window will try to lookup A by ID in the active space, and in this case it will find and focus it, and make B the recent window. If you now switch to space 2, A will become the recent window, and if you try to focus recent now it will fail, because A is not located in the currently active space.

So I agree that this a bug. Now the question is if we want recent to be space specific or global. My initial implementation was for this to be a global thing, but I think maybe the most recent in a space itself is more valuable, since we already have recent as both a space and display selector already.

Note also that the recent selector only works for managed windows, and will ignore any floating window.

@koekeishiya koekeishiya added the bug Something isn't working label May 29, 2020
@noib3
Copy link
Author

noib3 commented May 29, 2020

Is there a way to fix this with the tools available in version 2.4.3? If recent were to become space specific I'd need to upgrade to have that functionality, but I really don't want to lose window borders.

@koekeishiya
Copy link
Owner

I don't think this is possible to do without code changes. For what it's worth I ported the yabai border functionality (with feature parity) into a standalone application: https://github.com/koekeishiya/limelight

@koekeishiya
Copy link
Owner

Actually after thinking some more, I think the recent selector in yabai should work the way it does, but it should work across all spaces. macOS already does track the most recent focused within a space and will automatically focus that window when you activate said space.

@koekeishiya koekeishiya added the addressed on master; not released Fixed upstream, but not yet released label May 29, 2020
@noib3
Copy link
Author

noib3 commented May 29, 2020

For what it's worth I ported the yabai border functionality (with feature parity) into a standalone application: https://github.com/koekeishiya/limelight

Oh, didn't know that. I just built limelight and it works as expected, but how do I recover the option to specify border=off in yabai rules?

Btw, after upgrading to version 3.0.2 I'm having problems starting yabai as a service with homebrew. Even after installing the new scripting addition, I get a yabai-msg: failed to connect to socket error.

I tried removing yabai from the accessibility options hoping I'd get prompted to grant access again, but that's not happening. Any advice?

macOS already does track the most recent focused within a space and will automatically focus that window when you activate said space.

It doesn't for me, after focusing a space I have to manually focus a window in that space. That's why I added yabai -m window --focus recent to my space-switching bindings, I hoped it would solve that problem.

@noib3
Copy link
Author

noib3 commented May 30, 2020

It doesn't for me, after focusing a space I have to manually focus a window in that space.

I found out the reason for that is I have unchecked the option When switching to an application, switch to a Space with open windows for the application in the mission control preferences.

That's Apple fault's though, there's a difference between not switching to a space with windows open for the focused application, and not focusing the most recent window when switching spaces.

@koekeishiya
Copy link
Owner

but how do I recover the option to specify border=off in yabai rules?

You'd have to port the window rules system from yabai to limelight I guess.

Btw, after upgrading to version 3.0.2 I'm having problems starting yabai as a service with homebrew. Even after installing the new scripting addition, I get a yabai-msg: failed to connect to socket error.

Does it work if you run it directly from the terminal? Are there any crash logs (check Console.app > Crash Reports). Does brew work if you install the --head version?

@noib3
Copy link
Author

noib3 commented May 30, 2020

Installing from head worked, but I think I just needed to manually add the yabai binary in the accessibility apps.

That's Apple fault's though, there's a difference between not switching to a space with windows open for the focused application, and not focusing the most recent window when switching spaces.

Is there a way to fix this? I'd like to leave that checked, but without losing the ability to focus the most recent window when I switch to a different space.

@koekeishiya
Copy link
Owner

koekeishiya commented May 30, 2020 via email

@koekeishiya koekeishiya removed the addressed on master; not released Fixed upstream, but not yet released label Jun 5, 2020
@noib3
Copy link
Author

noib3 commented Nov 5, 2020

I'm sorry to reopen this issue, but I'm still struggling with focusing the most recent window on a space when switching spaces. It's quite a bit annoying having to manually focus a window (with cmd-tab or the mouse) every single time I switch a space.

I tried the solution you suggested in your last reply, i.e.

alt - 1 : yabai -m space --focus 1 && yabai -m window --focus "$(yabai -m query --windows --space | jq .[0].id)"
alt - 2 : yabai -m space --focus 2 && yabai -m window --focus "$(yabai -m query --windows --space | jq .[0].id)"

but it doesn't seem to work. Btw, I still have When switching to an application, switch to a Space with open windows for the application unchecked in System Preferences -> Mission Control.

@alexwforsythe
Copy link

Note: fixed in #719

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants