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

Remove cmd+tab space switch animation #1235

Closed
searene opened this issue Apr 17, 2022 · 24 comments
Closed

Remove cmd+tab space switch animation #1235

searene opened this issue Apr 17, 2022 · 24 comments
Labels
suggestion Request for new feature or some form of enhancement

Comments

@searene
Copy link

searene commented Apr 17, 2022

First of all, thanks for creating such an amazing app! I've been using i3wm on Linux for a long time, and I cannot believe I just found a window management app on macOS too!

Currently, I've configured 10 spaces, and I use skhd and yabai to switch to different spaces with shortcuts. The really good thing is, yabai disables the space-switching animation by default. That's really great. For someone who constantly switches between spaces, the animation is really annoying.

There's just one thing left: If I use cmd + tab to switch between apps located in different spaces, macOS still shows the animation for me. I'm wondering if I can use yabai to reimplement the functionality of cmd + tab and use skhd to map the shortcut. That way the animation would go away too. But I cannot. I cannot find the previously focused window in yabai, which is crucial to this functionality. Maybe I missed something. Is it achievable?

@diocletiann
Copy link

I would contribute $ for this. That animation annoys me very time. There's an alternate task switcher called Alt-Tab, if it issued yabai focus window commands instead of the native ones we'd have a solution.

https://github.com/lwouis/alt-tab-macos

@koekeishiya
Copy link
Owner

koekeishiya commented Apr 18, 2022

The macOS cmd + tab application switcher basically calls the following function to list the applications in most-recently-used order: https://github.com/koekeishiya/yabai/blob/master/src/process_manager.c#L186

I have been thinking about trying to make a better window switcher myself, and have a couple of thoughts, but never felt like getting started. The window switcher is also a part of Dock.app, so it might be possible to work around the animation by patching the code through the scripting-addition, but I have not investigated this part.

@koekeishiya
Copy link
Owner

I cannot find the previously focused window in yabai, which is crucial to this functionality. Maybe I missed something. Is it achievable?

The most recent window should be obtainable through the recent selector. Try yabai -m query --windows --window recent to list details about it.

@diocletiann
Copy link

diocletiann commented Apr 18, 2022

So AltTab shows the index of the destination space in the switcher popup. If it just issued yabai -m space --focus <index> before its native switch command we'd have a solution.

@searene
Copy link
Author

searene commented Apr 19, 2022

I cannot find the previously focused window in yabai, which is crucial to this functionality. Maybe I missed something. Is it achievable?

The most recent window should be obtainable through the recent selector. Try yabai -m query --windows --window recent to list details about it.

Thanks! That's the command I want. Strictly implementing Cmd + Tab may be hard, but at least I can switch between apps with it! In case anyone needs it, here is my command to switch between apps using yabai:

recent_space=`yabai -m query --windows --window recent | jq '.space'` && recent_window=`yabai -m query --windows --window recent | jq '.id'` && yabai -m space --focus "${recent_space}" && yabai -m window --focus "${recent_window}"

@koekeishiya
Copy link
Owner

For what it's worth, TotalSpaces v2.99 is able to remove the animation for cmd+tab (working on Big Sur 11.6.1), although I am not sure exactly what they do to achieve that, but it is at least possible at a technical level.

@koekeishiya
Copy link
Owner

Spent some time investigating this and got a working POC on Big Sur 11.6.1 (Intel). Will look into Monterey (and also Apple Silicon) later.

@koekeishiya koekeishiya changed the title Is it possible to implement Cmd + Tab using yabai? Remove cmd+tab space switch animation Apr 19, 2022
@koekeishiya koekeishiya added suggestion Request for new feature or some form of enhancement wip Work in progress labels Apr 19, 2022
@koekeishiya
Copy link
Owner

koekeishiya commented Apr 20, 2022

Hm not sure how doable this is for Apple Silicon. It loads an immediate value directly into a SIMD register (that is then used for the animation duration), instead of loading the value out of memory like in the x64 version. To make this change we need to patch that instruction, but for some reason it won't let me make that region of memory writable.

Edit: And shortly after making this comment, I got it working.

@koekeishiya
Copy link
Owner

Short summary; these changes removes:

  1. The space switch animation when clicking icons in the Dock that force a space change.
  2. The space switch animation when selecting an application with cmd+tab that force a space change.
  3. The space switch animation when focusing a space using the default macOS mission-control keyboard shortcuts (numeric ones, not left/right).

This is still a work in progress, meaning that not all OS versions are supported yet.

I have currently tested and verified that this is working on macOS Big Sur 11.6.1 (Intel), but believe it should also work on Monterey 12.3.1 (Intel).

I have also verified and tested that it works on macOS Monterey 12.3.1 (Apple Silicon).

@koekeishiya koekeishiya added addressed on master; not released Fixed upstream, but not yet released and removed wip Work in progress labels Apr 21, 2022
@koekeishiya
Copy link
Owner

Should now be working on the following systems:

Intel: macOS Mojave, Catalina, Big Sur, and Monterey.

Apple Silicon: macOS Monterey.

@peppy
Copy link

peppy commented Apr 21, 2022

This is pretty amazing! It allows using -m window --focus with a lot less delay (though still slightly more than switching space using -m space --focus. (tested on 12.3.1 for reference)

Out of curiosity, does this delay removal rely on scripting additions being loaded?

@koekeishiya
Copy link
Owner

koekeishiya commented Apr 21, 2022

Out of curiosity, does this delay removal rely on scripting additions being loaded?

Yep. To achieve this I basically patch the load instruction that would fill in the animation value, to load a zero instead of whatever value they use (0.25 I think it was).

@searene
Copy link
Author

searene commented Apr 21, 2022

Should now be working on the following systems:

Intel: macOS Mojave, Catalina, Big Sur, and Monterey.

Apple Silicon: macOS Monterey.

I'm using macOS Monterey (intel), I confirm that the animation is completely gone. Thanks for the amazing work, that's really helpful!

@diocletiann
Copy link

diocletiann commented Apr 27, 2022

I just installed --HEAD on 12.3.1 on Apple Silicon and the animation is gone! Thank you!

Maybe I'm doing something wrong but yabai -m window --focus commands aren't working correctly. For example, when there is no window to the east, yabai -m window --focus east should fail, but it focuses the window to the west. Sometimes focus east will focus north, sometimes focus south will focus west.

@koekeishiya
Copy link
Owner

Maybe I'm doing something wrong but yabai -m window --focus commands aren't working correctly. For example, when there is no window to the east, yabai -m window --focus east should fail, but it focuses the window to the west. Sometimes focus east will focus north, sometimes focus south will focus west.

Can you post a gif or something with your window layout that produces this issue? I have tried to reproduce it, but am unable to. I do believe there could be an issue here on the master branch, as I did some changes #1220

@diocletiann
Copy link

diocletiann commented Apr 27, 2022

I just reverted back to the regular homebrew package and the issue is gone. I can reinstall --HEAD later if you need me to. You can reproduce by creating two terminal windows, east and west. Select the east-most window and run yabai -m window --focus east which should fail, but it selects the window to the west.

@koekeishiya
Copy link
Owner

koekeishiya commented Apr 27, 2022

I've tried exactly that, but it works correctly for me. See this gif:
focuswindow

Screenshot of the end-frame with full resolution for readability:
commands

This was tested with the latest commit (7e9b09b)

@diocletiann
Copy link

Ok I reinstalled HEAD and I changed yabai -m config window_gap from 0 to 4 to make the recording stand out better and the issue went away lol. 1 or higher works as intended, and 0 works fine on the release version.

@koekeishiya
Copy link
Owner

koekeishiya commented Apr 28, 2022

Probably just a silly off-by-one error. Will look at it later. Thanks for testing.

@koekeishiya
Copy link
Owner

@restfuladi Should be fixed now on the latest master.

@jasikpark
Copy link

a tool that i've enjoyed as an alt to normal cmd+tab is https://contexts.co but it doesn't seem to play nice eventually...

@koekeishiya koekeishiya removed the addressed on master; not released Fixed upstream, but not yet released label May 17, 2022
FelixKratz pushed a commit to FelixKratz/yabai that referenced this issue Aug 18, 2022
FelixKratz pushed a commit to FelixKratz/yabai that referenced this issue Aug 18, 2022
@williamhCode
Copy link

williamhCode commented Oct 25, 2022

I just wanted to mention #1501 which I just opened, since I actually prefer the reduce motion animations than nothing at all. It would be helpful if this was an option!

@NightMachinery
Copy link

@koekeishiya If the only thing that I want from yabai is to disable these silly animations, could I enable SIP after installing yabai? Someone mentioned that the changes persisted even after closing yabai, so I am curious about the most minimal setup that gets rid of this anti-feature from our corporate overlords.

@koekeishiya
Copy link
Owner

You only need the yabai scripting addition to load into Dock.app for the space switch animations (that are listed in my previous comments in this issue) to be removed. Yabai itself does not need to be running. The scripting addition is the extension that requires SIP to be disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion Request for new feature or some form of enhancement
Projects
None yet
Development

No branches or pull requests

7 participants