Yabai: Preserve layout after coming back from sleep

Created on 19 Sep 2019  路  10Comments  路  Source: koekeishiya/yabai

I'm using a macbook pro with an external screen. Typically when it comes back from sleep, the macbook wakes up first, with the external screen coming in 10-20 seconds later.

Before the laptop goes to sleep, I have a nice layout with windows uniformly distributed between two monitors. Upon wakeup, because the second monitor takes its time, Yabai lays all of the windows on the laptop screen, and the external monitor is empty. I then manually reshuffle windows.

I dont mind it too much, but was hoping that there's maybe a way to avoid this that I'm missing.

My complements for a wonderful piece of software. I really missed something like this since I switched from Linux and ion3 a number of years ago.

bug help wanted

Most helpful comment

See https://github.com/koekeishiya/chunkwm/issues/355 and https://github.com/koekeishiya/kwm/issues/108 and related issues for some form of history. I don't remember much, if anything, about this issue, other than macOS being absolute crazytown in terms of how it deals with 4k (and 5k?) displays. I don't own a 4k or 5k display and I don't plan on getting one any time soon, so this is not something I will bother spending time on.

All 10 comments

It's weird that it takes your monitor so long to wake up. On my setup the display is available instantly if I didn't disconnect it while the device was sleeping.

If the display disconnects and reconnects there isn't much we can do I think.

Best you can do is subscribe to the display_added signal to move any visible window that satisfies a set of criteria to the newly added display.

I noticed that too. I just locked my screen for bathroom break, and logon again. When I have two external monitors it takes much longer to come back. This is especially noticeable with 5K external monitors. ..and when it comes back the layout is all lost.

I think Mac OS keeps multiple profiles of the arrangement of the monitors. It would be nice if the layout would be saved per profile. For example monitors at my home and the monitors at office are different, but Mac remembers the arrangement for each.

See https://github.com/koekeishiya/chunkwm/issues/355 and https://github.com/koekeishiya/kwm/issues/108 and related issues for some form of history. I don't remember much, if anything, about this issue, other than macOS being absolute crazytown in terms of how it deals with 4k (and 5k?) displays. I don't own a 4k or 5k display and I don't plan on getting one any time soon, so this is not something I will bother spending time on.

I wonder if it'd be a good solution to let the user set a timeout that ticks down when a display gets disconnected, causing yabai to freeze all internal state and queue up events until either a display is connected or the timeout runs down.

As a stop gap, I increased sleep threshhold for my system. Downside: not as energy efficient. Upside: re-layout only happens once a day usually (in the morning).

So this issue can be resolved by using the space uuid as the way to identify spaces, rather than the cgsspaceid. I'll have to see if this is a reasonable change to make with the way yabai is designed.. hopefully it will be fine to make that switch.

I believe this issue is fixed on the latest master, but as mentioned previously I have no way of actually testing this.

Can confirm that it's fixed on my MacOS 10.14. Thank you!

I take it back. Woke my mac from overnight sleep and the windows are all jumbled up on the primary monitor.

Can someone confirm that the layout now persist when a GPU switch occur?

I believe the wake from sleep issue is a combination of another step that needs to be handled.
The fix I did above should remap our internal spaces structure when a new display is added (which happens on a GPU switch, and also when a 4k/5k display wake from sleep). However, I believe that in some cases it will also report a display removed event before the added event. This causes yabai to untile windows in the remove event, and then it has nothing to map back to when we process the add event afterwards.

Can someone run with debug_output on and paste a dump of the event log of what happens in this scenario?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fuckbitchesgitmoney picture fuckbitchesgitmoney  路  4Comments

tsujp picture tsujp  路  3Comments

mattsawyer77 picture mattsawyer77  路  4Comments

stylerw picture stylerw  路  4Comments

koekeishiya picture koekeishiya  路  4Comments