FelixKratz / SketchyBar

A highly customizable macOS status bar replacement
https://felixkratz.github.io/SketchyBar/
GNU General Public License v3.0
5.25k stars 82 forks source link

SketchyBar sometimes vanishes unexpectedly. #512

Open CassandraCat opened 4 months ago

CassandraCat commented 4 months ago

sometimes after my mac goes into screensaver mode and I enter my password to return to the main screen, sketchybar disappears suddenly. however, when I repeat the steps, sketchybar reappears. like this:

image

btw, i am using multiple-bars.

FelixKratz commented 3 months ago

This has been a problem for quite some time now and I was able resolve all those prior problems but something with the wake event seems to be going wrong still #430, #422, #97, #497. The fact that the bar reappears after a further lock->unlock makes a freeze implausible. I think it must have to do with the wake event not being received properly such that the bar internally thinks the computer is still sleeping.

CrossR commented 3 months ago

I'm able to reproduce this bug fairly easily (I think).

If I just close the lid on my MacBook Air, then re-open it basically straight away, and then wake the device with the keyboard, say by pressing spacebar, I can repro some form of weird behaviour, that I think is this bug. (Sometimes for whatever reason, the device won't actually sleep, so you may need to keep the lid closed for a second or two).

Doing that gives me the following behaviour:

This is on a device with only a single screen etc, so I don't think its something to do with that, at least in my case.

Now, I've done a bit of poking and I could be entirely wrong (I've only really given a quick glance over the code...) but something that looks fairly suspect to me is the didWake function in workspace.m: Is there a reason it is hooked up to both NSWorkspaceDidWakeNotification and com.apple.screenIsUnlocked?

I ask, because if I print out all the events that are being processed as I do the steps outlined above, every time I see the bar behave funny and go away / or come back once hidden, its because there has been two SYSTEM_WOKE events: One for the NSWorkspaceDidWakeNotification and one for com.apple.screenIsUnlocked, and these events come one after another.

If instead I just lock my screen, or close the laptop lid for a few minutes, any of the interactions that don't cause the bar to vanish, there is only a single SYSTEM_WOKE event.

Is it possible that there is some weird interaction happening if two SYSTEM_WOKE interactions run at the same time / in quick succession?

If I just comment out the com.apple.screenIsUnlocked version, it "fixes" it for me, though I'm sure causes other issues with other events, so something a bit more sophisticated to not run both events could be needed, assuming this is a fix at all.

FelixKratz commented 3 months ago

Thank you for the investigation. It is indeed true that the system wake event is posted into the event loop in both cases. This is on purpose because having multiple wake events should make the bug appear less frequently, as a similar bug was reported even before this code change was made. Having two system wake events creates no interplay as in both cases the bars are created entirely from scratch (thats at least how it should be).

I originally thought this bug was because we call the system woke code in: https://github.com/FelixKratz/SketchyBar/blob/4194da0bd277b9b2fd2535eb963a7fd6468a0464/src/bar_manager.c#L1011 too early such that the api we use to enumerate the active displays wrongfully reports no active display, which would lead to all bars being destroyed but not recreated. On my system this bug happens very infrequently (once a month) and I was not able to find any way to reliably reproduce it in all the prior issues listed above.

I never sleep my laptop with the menubar action, only by closing the lid or letting the system time out, maybe I could try that.

It would be interesting which of the two events is responsible for the single wake call, ie screen unlock or wake?

You mention that you wake the device with the space key after opening the lid, does opening the lid not wake the system automatically?

adrianvalenz commented 1 month ago

After I close my laptop completely and open it the first time, sketchybar disappears. Second time I close my laptop completely and open it for the second time and it reappears. Upon every close and opening of laptop it alternates states (visible sketchybar, not visible, visible, not visible, and so on...)

Then I proceeded to almost close my laptop (not completely as I can still see the screen and keyboard) but enough so the screen goes black...then I move it back up to wake the screen but sketchybar is not visible...I do this 3 more times in a row (almost closing it but not) to sleep the screen so when I move it back up to wake it sketchybar is not visible (those 3 times).

Finally I close the laptop completely and open it and because the sketchybar was not visible upon completely closing it, it reappears when I open the laptop.

Second test I did was repeatedly Sleep and Lock Screen from the Apple menu bar and sketchybar never seemed to disappears. So it appears some different method is being called when you actually fully close the laptop.

I hope this helps.

Edit: Would be interested to see how sketchybar reacts by testing the Sleep/Lock Screen buttons from the menu bar when the laptop is closed in clamshell while being connected to an external monitor.

Edit 2: When Sleeping the screen via Apple menu, if I wake with the touchpad, sketchybar persists...when I wake it with a key like the spacebar, it disappears, and then I can wake it again with the touchpad sketchybar reappears. This is all done back to back without every closing the laptop. It seems how the screen wakes up is a factor.

Also tried the touch id and entering password to get back onto the desktop from the lockscreen and sketchybar persists. So it seems to happen in or around the screen Sleeping only and how it wakes up.