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

Space focusing issues with Sonoma 14.1 (23B74) #1937

Closed
doadam opened this issue Oct 26, 2023 · 37 comments
Closed

Space focusing issues with Sonoma 14.1 (23B74) #1937

doadam opened this issue Oct 26, 2023 · 37 comments

Comments

@doadam
Copy link

doadam commented Oct 26, 2023

Since upgrading to Sonoma 14.1 (build 23B74), there are 2 new issues which I didn't have before (I was on Sonoma 14.0 previously):

  1. Space focus doesn't work unless the source display and destination display are different
  2. Space focusing is animated, where it used to just be instant. This is also the case with yabai -m config window_animation_duration 0.0. It used to be instant without this as well.

Here's my config file:

#!/usr/bin/env bash

# Disable Apple's shitty window manager
launchctl unload -F /System/Library/LaunchAgents/com.apple.WindowManager.plist > /dev/null 2>&1 &

sudo yabai --load-sa
yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"

# global settings
yabai -m config debug_output on

yabai -m config mouse_follows_focus          on
yabai -m config focus_follows_mouse          autoraise

yabai -m config window_placement             second_child
yabai -m config window_topmost               off

yabai -m config window_opacity               off
yabai -m config window_opacity_duration      0.0
yabai -m config window_shadow                on

yabai -m config active_window_opacity        1.0
yabai -m config normal_window_opacity        0.90
yabai -m config split_ratio                  0.50
yabai -m config auto_balance                 off

# Mouse support
yabai -m config mouse_modifier               alt
yabai -m config mouse_action1                move
yabai -m config mouse_action2                resize

# general space settings
yabai -m config layout                       stack
yabai -m config top_padding                  0
yabai -m config bottom_padding               0
yabai -m config left_padding                 0
yabai -m config right_padding                0
yabai -m config window_gap                   0

I also tried installing from HEAD (#40d1075) but this had no effect.

Needless to say, SIP is disabled (everything worked fine on 14.0 for me). Here's the output from csrutil:

csrutil status                                                                                                                                                                                                                         
System Integrity Protection status: unknown (Custom Configuration).

Configuration:
	Apple Internal: disabled
	Kext Signing: enabled
	Filesystem Protections: disabled
	Debugging Restrictions: disabled
	DTrace Restrictions: enabled
	NVRAM Protections: disabled
	BaseSystem Verification: enabled
	Boot-arg Restrictions: disabled
	Kernel Integrity Protections: enabled
	Authenticated Root Requirement: enabled

I also enabled debug prints, but nothing was printed when I tried switching spaces.

Let me know if any more information is needed.

@rwijtvliet
Copy link

Suspected duplicate of #1936

@doadam
Copy link
Author

doadam commented Oct 27, 2023

Suspected duplicate of #1936

I also thought so, but I don't get this pop-up. Also the payload (which is the code that runs inside the Docker to my understanding) does work for other things like moving a window or changing stacked windows. This is why I believe it is not a duplicate, but we shall see.

@liuduwei
Copy link

liuduwei commented Oct 27, 2023

Suspected duplicate of #1936

I also thought so, but I don't get this pop-up. Also the payload (which is the code that runs inside the Docker to my understanding) does work for other things like moving a window or changing stacked windows. This is why I believe it is not a duplicate, but we shall see.

i didn't get that pop-up too. i also thought that it's not a duplicate, because i run yabai -m space --focus prev in the console, there is no error or warning message output. if that pop-up show means scripting-addtion execute failed, the console will output corresponding messages when i run yabai -m space --focus prev.

@kabaliwths
Copy link

By the way, if you attempt to switch the focus to the same space you are currently on, you will receive the message 'Cannot focus an already focused space.' However, for any other action, whether it's by label or using the previous/next function, it doesn't work.

@davidandradeduarte
Copy link

I'm also having the exact same issue.

@jakehamilton
Copy link

I have just upgraded to Sonoma 14.1 and Yabai v6.0.0. I'm having the same issue with yabai -m space --focus next (or numbered workspace) not having any effect. I did not get a popup as #1936 mentions.

@mescalas
Copy link

Same issue here

@dvrkoo
Copy link

dvrkoo commented Oct 30, 2023

same issue here

@TuralAsgar
Copy link

@koekeishiya, I appreciate your all efforts on this open source.
How can we solve this problem?

@denis-anashkin
Copy link

same here. no popup with error also

@ccimponeriu1996
Copy link

same here

@philipphoertnagl
Copy link

philipphoertnagl commented Oct 30, 2023

I posted a week ago, when I upgraded MacOS to Sonoma 14.0 that I had problems with yabai -m config focus_follows_mouse autofocus but then with upgrading yabai to 6.0 it seemed to be fixed, but now again, my focus does not switch when I hover with my mouse, although I did NOT upgrade MacOS to Sonoma 14.1. But when I restart my MacBook all seems to work again normally. So there might be still the issue, that some things over time get weird with Sonoma and yabai ....

@simonemargio
Copy link

simonemargio commented Oct 31, 2023

I posted a week ago, when I upgraded MacOS to Sonoma 14.0 that I had problems with yabai -m config focus_follows_mouse but then with upgrading yabai to 6.0 it seemed to be fixed, but now again, my focus does not switch when I hover with my mouse, although I did NOT upgrade MacOS to Sonoma 14.1. But when I restart my MacBook all seems to work again normally. So there might be still the issue, that some things over time get weird with Sonoma and yabai ....

Same problem, Sonoma 14.0 + yabai 6.0.0, and autofocus with the mouse sometimes doesn't work and then strangely it starts working again. The only thing I've noticed is that this problem occurs when the Mac turns on from a Sleep state or similar.

@hb0nes
Copy link

hb0nes commented Oct 31, 2023

+1, space switching doesn't work on Sonoma 14.1.

When I run yabai --verbose, this is the only thing that I see:

EVENT_HANDLER_DAEMON_MESSAGE: space --focus 1

When I use Mac's built in space-switching, that works and Yabai also broadcasts that event:

event_signal_flush: transmitting space_changed to 1 subscriber(s)

@Rodion-Bozhenko
Copy link

Same issue here

1 similar comment
@kalamov
Copy link

kalamov commented Nov 1, 2023

Same issue here

@rayjanoka
Copy link

rayjanoka commented Nov 1, 2023

while we wait for a fix I was able to map my space switch keys here. I just had to disable the shortcuts in my .skhdrc first.

image

@konstruktor227
Copy link

konstruktor227 commented Nov 2, 2023

Same issue here on Sonoma 14.1 and yabai 6.0.0. Both space --create and space --focus commands seem to do nothing. Moving windows to spaces once they have been created via mission control is working fine though.

@suinly
Copy link

suinly commented Nov 2, 2023

Same problem (Sonoma 14.1, yabai 6.0.0). But if you're in the space of a second display, switching to the first display works fine (with a space changing animation).

@henrythor
Copy link

henrythor commented Nov 2, 2023

You can also just remap your skhd to emit another keystroke, I for instance have space switching in MacOS linked to ctrl-left so I can do this:

alt - p : yabai -m space --focus prev || skhd -k "ctrl - left"
alt - n : yabai -m space --focus next || skhd -k "ctrl - right"

@doadam
Copy link
Author

doadam commented Nov 2, 2023

I'm using hammerspoon for key binding, and had Opt+number to switch to a specific space.
I have 2 displays and found a hacky workaround.
The animation is still there and there are some sleeps, but at least I can navigate spaces now:

-- Function to get the active space ID and a table of visible spaces
function getSpaceInfo()
    -- Execute the yabai command to fetch the JSON output
    local yabaiOutput = hs.execute(yabai_path .. " -m query --spaces")

    -- Decode the JSON output to a Lua table
    local spaces, decodeError = hs.json.decode(yabaiOutput)

    if not spaces then
        hs.printf("JSON decode err: %s", decodeError)
        return nil, nil
    end
    
    local focusedSpace = nil
    local visibleSpaces = {}
    
    -- Iterate through the spaces
    for _, space in ipairs(spaces) do
        if space["has-focus"] == true then
            focusedSpace = space
        end
        if space["is-visible"] == true then
            table.insert(visibleSpaces, space)
        end
    end

    return focusedSpace, visibleSpaces
end

function focus_space_id(space_id)
    yabai({"-m", "space", "--focus", '' .. space_id})
end

for k,v in pairs({'1', '2', '3', '4', '5', '6', '7', '8', '9', '10'}) do
    hs.hotkey.bind({"alt"}, '' .. k % 10, function()
        local focusedSpace, visibleSpaces = getSpaceInfo()

        if focusedSpace then
            local targetDisplay = math.ceil(tonumber(k) / 5)
            local currentDisplay = focusedSpace.display
            --print("targetDisplay: ", targetDisplay)
            --print("currentDisplay: ", currentDisplay)

            if targetDisplay == currentDisplay then
                -- If the target and current display are the same, focus another space first
                for _, space in ipairs(visibleSpaces) do
                    if space.display ~= currentDisplay then
                        --print("Focusing space ", space.index, " first")
                        focus_space_id(space.index)

                        hs.timer.doAfter(0.05, function()
                            focus_space_id(k)
                        end)

                        return
                    end
                end
            end

            -- Focus the requested space
            focus_space_id(k)
        end
    end)
end

@henrythor
Copy link

I'm using hammerspoon for key binding, and had Opt+number to switch to a specific space. I have 2 displays and found a hacky workaround. The animation is still there and there are some sleeps, but at least I can navigate spaces now:

-- Function to get the active space ID and a table of visible spaces
function getSpaceInfo()
    -- Execute the yabai command to fetch the JSON output
    local yabaiOutput = hs.execute(yabai_path .. " -m query --spaces")

    -- Decode the JSON output to a Lua table
    local spaces, decodeError = hs.json.decode(yabaiOutput)

    if not spaces then
        hs.printf("JSON decode err: %s", decodeError)
        return nil, nil
    end
    
    local focusedSpace = nil
    local visibleSpaces = {}
    
    -- Iterate through the spaces
    for _, space in ipairs(spaces) do
        if space["has-focus"] == true then
            focusedSpace = space
        end
        if space["is-visible"] == true then
            table.insert(visibleSpaces, space)
        end
    end

    return focusedSpace, visibleSpaces
end

function focus_space_id(space_id)
    yabai({"-m", "space", "--focus", '' .. space_id})
end

for k,v in pairs({'1', '2', '3', '4', '5', '6', '7', '8', '9', '10'}) do
    hs.hotkey.bind({"alt"}, '' .. k % 10, function()
        local focusedSpace, visibleSpaces = getSpaceInfo()

        if focusedSpace then
            local targetDisplay = math.ceil(tonumber(k) / 5)
            local currentDisplay = focusedSpace.display
            --print("targetDisplay: ", targetDisplay)
            --print("currentDisplay: ", currentDisplay)

            if targetDisplay == currentDisplay then
                -- If the target and current display are the same, focus another space first
                for _, space in ipairs(visibleSpaces) do
                    if space.display ~= currentDisplay then
                        --print("Focusing space ", space.index, " first")
                        focus_space_id(space.index)

                        hs.timer.doAfter(0.05, function()
                            focus_space_id(k)
                        end)

                        return
                    end
                end
            end

            -- Focus the requested space
            focus_space_id(k)
        end
    end)
end

FYI to get the current space you can use yabai -m query --spaces --space and to get the spaces on the current display you can do yabai -m query --displays --display | jq -c '.spaces'

You could get the next space up or down by doing yabai -m query --spaces --space | jq -c '.index + 1' / yabai -m query --spaces --space | jq -c '.index - 1' and you could check if that space is within your current display's list of spaces using something like if [ $(jq --null-input --argjson spaces "$SPACES" -c --argjson next_space "$NEXT_SPACE" '$next_space|IN($spaces[])') = "true" ]; then ... fi

All things I used to do when yabai was working for me :P

@suinly
Copy link

suinly commented Nov 3, 2023

The animation is still there

@henrythor I hope this is helpful. I changed the animation in System Preferences - Accessibility - Display - Reduce Motion. This is not a complete disabling of the animation, but a change to a fading effect.

@doadam
Copy link
Author

doadam commented Nov 3, 2023

I'm using hammerspoon for key binding, and had Opt+number to switch to a specific space. I have 2 displays and found a hacky workaround. The animation is still there and there are some sleeps, but at least I can navigate spaces now:

-- Function to get the active space ID and a table of visible spaces

function getSpaceInfo()

-- Execute the yabai command to fetch the JSON output
local yabaiOutput = hs.execute(yabai_path .. " -m query --spaces")
-- Decode the JSON output to a Lua table
local spaces, decodeError = hs.json.decode(yabaiOutput)
if not spaces then
    hs.printf("JSON decode err: %s", decodeError)
    return nil, nil
end
local focusedSpace = nil
local visibleSpaces = {}
-- Iterate through the spaces
for _, space in ipairs(spaces) do
    if space["has-focus"] == true then
        focusedSpace = space
    end
    if space["is-visible"] == true then
        table.insert(visibleSpaces, space)
    end
end
return focusedSpace, visibleSpaces

end

function focus_space_id(space_id)

yabai({"-m", "space", "--focus", '' .. space_id})

end

for k,v in pairs({'1', '2', '3', '4', '5', '6', '7', '8', '9', '10'}) do

hs.hotkey.bind({"alt"}, '' .. k % 10, function()
    local focusedSpace, visibleSpaces = getSpaceInfo()
    if focusedSpace then
        local targetDisplay = math.ceil(tonumber(k) / 5)
        local currentDisplay = focusedSpace.display
        --print("targetDisplay: ", targetDisplay)
        --print("currentDisplay: ", currentDisplay)
        if targetDisplay == currentDisplay then
            -- If the target and current display are the same, focus another space first
            for _, space in ipairs(visibleSpaces) do
                if space.display ~= currentDisplay then
                    --print("Focusing space ", space.index, " first")
                    focus_space_id(space.index)
                    hs.timer.doAfter(0.05, function()
                        focus_space_id(k)
                    end)
                    return
                end
            end
        end
        -- Focus the requested space
        focus_space_id(k)
    end
end)

end

FYI to get the current space you can use yabai -m query --spaces --space and to get the spaces on the current display you can do yabai -m query --displays --display | jq -c '.spaces'

You could get the next space up or down by doing yabai -m query --spaces --space | jq -c '.index + 1' / yabai -m query --spaces --space | jq -c '.index - 1' and you could check if that space is within your current display's list of spaces using something like if [ $(jq --null-input --argjson spaces "$SPACES" -c --argjson next_space "$NEXT_SPACE" '$next_space|IN($spaces[])') = "true" ]; then ... fi

All things I used to do when yabai was working for me :P

I prefer doing it with as few yabai calls as possible because each call has a slight overhead, which is noticeable if you switch spaces quickly :)

@TuralAsgar
Copy link

I'm using hammerspoon for key binding, and had Opt+number to switch to a specific space. I have 2 displays and found a hacky workaround. The animation is still there and there are some sleeps, but at least I can navigate spaces now:

-- Function to get the active space ID and a table of visible spaces
function getSpaceInfo()
    -- Execute the yabai command to fetch the JSON output
    local yabaiOutput = hs.execute(yabai_path .. " -m query --spaces")

    -- Decode the JSON output to a Lua table
    local spaces, decodeError = hs.json.decode(yabaiOutput)

    if not spaces then
        hs.printf("JSON decode err: %s", decodeError)
        return nil, nil
    end
    
    local focusedSpace = nil
    local visibleSpaces = {}
    
    -- Iterate through the spaces
    for _, space in ipairs(spaces) do
        if space["has-focus"] == true then
            focusedSpace = space
        end
        if space["is-visible"] == true then
            table.insert(visibleSpaces, space)
        end
    end

    return focusedSpace, visibleSpaces
end

function focus_space_id(space_id)
    yabai({"-m", "space", "--focus", '' .. space_id})
end

for k,v in pairs({'1', '2', '3', '4', '5', '6', '7', '8', '9', '10'}) do
    hs.hotkey.bind({"alt"}, '' .. k % 10, function()
        local focusedSpace, visibleSpaces = getSpaceInfo()

        if focusedSpace then
            local targetDisplay = math.ceil(tonumber(k) / 5)
            local currentDisplay = focusedSpace.display
            --print("targetDisplay: ", targetDisplay)
            --print("currentDisplay: ", currentDisplay)

            if targetDisplay == currentDisplay then
                -- If the target and current display are the same, focus another space first
                for _, space in ipairs(visibleSpaces) do
                    if space.display ~= currentDisplay then
                        --print("Focusing space ", space.index, " first")
                        focus_space_id(space.index)

                        hs.timer.doAfter(0.05, function()
                            focus_space_id(k)
                        end)

                        return
                    end
                end
            end

            -- Focus the requested space
            focus_space_id(k)
        end
    end)
end

I added this script and reloaded Hammerspoon but it didn't change space when I pressed opt+number.
Should I need other steps after adding and reloading?

@doadam
Copy link
Author

doadam commented Nov 4, 2023

I'm using hammerspoon for key binding, and had Opt+number to switch to a specific space. I have 2 displays and found a hacky workaround. The animation is still there and there are some sleeps, but at least I can navigate spaces now:

-- Function to get the active space ID and a table of visible spaces
function getSpaceInfo()
    -- Execute the yabai command to fetch the JSON output
    local yabaiOutput = hs.execute(yabai_path .. " -m query --spaces")

    -- Decode the JSON output to a Lua table
    local spaces, decodeError = hs.json.decode(yabaiOutput)

    if not spaces then
        hs.printf("JSON decode err: %s", decodeError)
        return nil, nil
    end
    
    local focusedSpace = nil
    local visibleSpaces = {}
    
    -- Iterate through the spaces
    for _, space in ipairs(spaces) do
        if space["has-focus"] == true then
            focusedSpace = space
        end
        if space["is-visible"] == true then
            table.insert(visibleSpaces, space)
        end
    end

    return focusedSpace, visibleSpaces
end

function focus_space_id(space_id)
    yabai({"-m", "space", "--focus", '' .. space_id})
end

for k,v in pairs({'1', '2', '3', '4', '5', '6', '7', '8', '9', '10'}) do
    hs.hotkey.bind({"alt"}, '' .. k % 10, function()
        local focusedSpace, visibleSpaces = getSpaceInfo()

        if focusedSpace then
            local targetDisplay = math.ceil(tonumber(k) / 5)
            local currentDisplay = focusedSpace.display
            --print("targetDisplay: ", targetDisplay)
            --print("currentDisplay: ", currentDisplay)

            if targetDisplay == currentDisplay then
                -- If the target and current display are the same, focus another space first
                for _, space in ipairs(visibleSpaces) do
                    if space.display ~= currentDisplay then
                        --print("Focusing space ", space.index, " first")
                        focus_space_id(space.index)

                        hs.timer.doAfter(0.05, function()
                            focus_space_id(k)
                        end)

                        return
                    end
                end
            end

            -- Focus the requested space
            focus_space_id(k)
        end
    end)
end

I added this script and reloaded Hammerspoon but it didn't change space when I pressed opt+number. Should I need other steps after adding and reloading?

You need some more functions/code:

local json = require("hs.json")

function init_brew(args)
    output, status, t, rc = hs.execute("brew --prefix", true)
    output = output:gsub("\n", "")
    return output
end

yabai_path = brew_path .. "/bin/yabai"
function yabai(args)
    --print("yabai args: ", hs.inspect(table.pack(args)))
    hs.task.new(yabai_path, nil, function(ud, ...)
        --print("stream", hs.inspect(table.pack(...)))
        return true
    end, args):start()
end

I also use the ReloadConfiguration spoon to auto load on every modification:

hs.loadSpoon("ReloadConfiguration")

The reason I created this yabai function is because most of the yabai commands are ok if they're asynchronous (querying the status isn't, hence the difference in getSpaceInfo) and this makes sure the UI doesn't get stuck if yabai doesn't run instantly.

@brorbw
Copy link

brorbw commented Nov 5, 2023

I have this "native" solution for finding spaces belonging to a display rather than hammerspoon.

readonly SPACE_INDEX=$1

readonly ACTIVE_DISPLAY_ID=$(yabai -m query --spaces |
	jq '.[] | select(."has-focus" == true).display')

readonly SPACES_OF_ACTIVE_DISPLAY=$(yabai -m query --displays |
	jq ".[] | select(.index == $ACTIVE_DISPLAY_ID).spaces")

readonly TARGET_SPACE=$(echo $SPACES_OF_ACTIVE_DISPLAY |
	jq -r ".[$SPACE_INDEX]")

yabai -m space --focus $TARGET_SPACE

@brorbw
Copy link

brorbw commented Nov 5, 2023

It could be a separate issue but it would seem that destroy and create does not work either

@choodfire
Copy link

Any updates on 14.1.1?

@yuser1337
Copy link

Any updates on 14.1.1?

Its the same, doesn't work

@suinly
Copy link

suinly commented Nov 12, 2023

Works in version 6.0.1! 🎉

@choodfire
Copy link

Thank you @koekeishiya!

@frigaut
Copy link

frigaut commented Nov 13, 2023

Yes, can confirm space focus etc work in 6.0.1. Thanks @koekeishiya

@hb0nes
Copy link

hb0nes commented Nov 13, 2023

Can confirm here as well. Can we close this issue?

@konstruktor227
Copy link

Everything working great again after latest update. Thanks @koekeishiya!

@frigaut
Copy link

frigaut commented Nov 14, 2023

Happiness is a fully functioning yabai :-)

@davidandradeduarte
Copy link

davidandradeduarte commented Jan 3, 2024

Just upgraded to Sonoma 14.2.1, and it stopped working again.
yabai doesn't focus any space and there's no error output.

Ignore. I needed to (again) give the necessary system permissions to yabai, after the upgrade.

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