cocoa-cb: simplify cursor hiding and make it less greedy

for reasons unknown to me the NSCursor (un)hide functions can be
completely unreliable and the cursor can have an unknown state. this
only happens on some system and wasn't able to reproduce this. it's
probably some dumb race condition that might be possible to work around,
though because of the lack of reproducibility on my end it's hard to
test.

i decided to rework the cursor hiding code yet again and make it a lot
less greedy. the cursor will now always unhide when moved and there
will never be a situation again the cursor can't be unhidden again.
on the other hand there might be edge cases now where the cursor won't
hide immediately and you have to move it slightly to make it disappear
again. this should be an acceptable tradeoff.

Fixes #6886
This commit is contained in:
der richter 2020-02-01 13:02:58 +01:00
parent 2607a2b892
commit 3ad9c32a5f
3 changed files with 7 additions and 12 deletions

View File

@ -120,6 +120,7 @@ class EventsView: NSView {
if mpv?.mouseEnabled() ?? true {
cocoa_put_key_with_modifiers(SWIFT_KEY_MOUSE_ENTER, 0)
}
cocoaCB.updateCursorVisibility()
}
override func mouseExited(with event: NSEvent) {
@ -127,6 +128,7 @@ class EventsView: NSView {
cocoa_put_key_with_modifiers(SWIFT_KEY_MOUSE_LEAVE, 0)
}
cocoaCB.titleBar?.hide()
cocoaCB.setCursorVisiblility(true)
}
override func mouseMoved(with event: NSEvent) {

View File

@ -183,7 +183,7 @@ class Window: NSWindow, NSWindowDelegate {
func windowDidEnterFullScreen(_ notification: Notification) {
isInFullscreen = true
cocoaCB.mpv?.setConfigProperty(fullscreen: isInFullscreen)
cocoaCB.updateCusorVisibility()
cocoaCB.updateCursorVisibility()
endAnimation(frame)
cocoaCB.titleBar?.show()
}
@ -517,12 +517,13 @@ class Window: NSWindow, NSWindowDelegate {
}
func windowDidBecomeKey(_ notification: Notification) {
cocoaCB.updateCusorVisibility()
cocoaCB.updateCursorVisibility()
}
func windowDidChangeOcclusionState(_ notification: Notification) {
if occlusionState.contains(.visible) {
cocoaCB.layer?.update(force: true)
cocoaCB.updateCursorVisibility()
}
}

View File

@ -28,7 +28,6 @@ class CocoaCB: NSObject {
var layer: VideoLayer?
var link: CVDisplayLink?
var cursorHidden: Bool = false
var cursorVisibilityWanted: Bool = true
@objc var isShuttingDown: Bool = false
@ -267,19 +266,12 @@ class CocoaCB: NSObject {
&displaySleepAssertion)
}
func updateCusorVisibility() {
func updateCursorVisibility() {
setCursorVisiblility(cursorVisibilityWanted)
}
func setCursorVisiblility(_ visible: Bool) {
let visibility = visible ? true : !(view?.canHideCursor() ?? false)
if visibility && cursorHidden {
NSCursor.unhide()
cursorHidden = false;
} else if !visibility && !cursorHidden {
NSCursor.hide()
cursorHidden = true
}
NSCursor.setHiddenUntilMouseMoves(!visible && (view?.canHideCursor() ?? false))
}
func updateICCProfile() {