Closed skyline75489 closed 1 year ago
I was also trying to handle the state when the application is completely hidden (covered by other application). This causes the application to become "background" in Instrument:
But I failed to find a way to do so. Any idea?
I was also trying to handle the state when the application is completely hidden (covered by other application).
Technically if the window is still open but obscured, it can still be rendered because vibrancy material in a window in front of it, or being pulled in exposé. Maybe occlusionState
(which has a notification) can help?
Oh yeah, exposé. That's a feature that I haven't been used for quite some time. Maybe we can at lease reduce the refresh rate to 1sec when the window is not visible based on occlusionState
. Even without handling occlusionState
, the CPU usage is now at ~2% when the window is minimized with this PR. This is about the right amount of CPU usage I'd expect from a music app.
Regarding occlusionState
with some quick tests:
windowDidChangeOcclusionState
method to the database controller. (There is the applicationDidChangeOcclusionState
equivalent for the app delegate, but it's not the right place to put it.)NSWindowOcclusionStateVisible
is documented, there's also 0x2000
set, but it's undocumented. (Means AND it instead of equality.)occlusionState
. Switching window via the dock or Cmd+Tab will make it be not visible, but using exposé or selecting another to switch doesn't seem to trigger that occlusion event.Overall, it looks like a better option that handles almost all window-not-visible states.
Seems that occlusionState
is way better than Miniaturization. I'll find some time to update this PR later 🥂
You OK with other changes in this PR? Let me know if I'm doing something weird. I haven't really been an expert regarding macOS. I had my time developing on iOS several years ago.
I left a comment regarding the change to clearPlaybackProgress
; the miniaturization one we just addressed.
Could it be that you didn't submit the review? I didn't see any comment. I sometimes also forget the submission :)
FWIW, retested:
- Switching workspaces definitely makes the window be not visible in
occlusionState
. Switching window via the dock or Cmd+Tab will make it be not visible, but using exposé or selecting another to switch doesn't seem to trigger that occlusion event.
This doesn't seem to be accurate after I checked again; occlusion behaves normally if completely obscured.
I think this looks good to me.
componentFormatter
with simple implementation to reduce overhead.