mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: detect mouseEntered/Exit on frame change
This commit is contained in:
@ -283,6 +283,25 @@ extension Ghostty {
|
|||||||
// The size represents our final size we're going for.
|
// The size represents our final size we're going for.
|
||||||
let scaledSize = self.convertToBacking(size)
|
let scaledSize = self.convertToBacking(size)
|
||||||
ghostty_surface_set_size(surface, UInt32(scaledSize.width), UInt32(scaledSize.height))
|
ghostty_surface_set_size(surface, UInt32(scaledSize.width), UInt32(scaledSize.height))
|
||||||
|
|
||||||
|
// Frame changes do not always call mouseEntered/mouseExited, so we do some
|
||||||
|
// calculations ourself to call those events.
|
||||||
|
if let window = self.window {
|
||||||
|
let mouseScreen = NSEvent.mouseLocation
|
||||||
|
let mouseWindow = window.convertPoint(fromScreen: mouseScreen)
|
||||||
|
let mouseView = self.convert(mouseWindow, from: nil)
|
||||||
|
let isEntered = self.isMousePoint(mouseView, in: bounds)
|
||||||
|
if (isEntered) {
|
||||||
|
mouseEntered(with: NSEvent())
|
||||||
|
} else {
|
||||||
|
mouseExited(with: NSEvent())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If we don't have a window, then our mouse can NOT be in our view.
|
||||||
|
// When the window comes back, I believe this event fires again so
|
||||||
|
// we'll get a mouseEntered.
|
||||||
|
mouseExited(with: NSEvent())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setCursorShape(_ shape: ghostty_mouse_shape_e) {
|
func setCursorShape(_ shape: ghostty_mouse_shape_e) {
|
||||||
@ -562,20 +581,18 @@ extension Ghostty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func cursorUpdate(with event: NSEvent) {
|
override func cursorUpdate(with event: NSEvent) {
|
||||||
if (focused) {
|
switch (cursorVisible) {
|
||||||
switch (cursorVisible) {
|
case .visible, .hidden:
|
||||||
case .visible, .hidden:
|
// Do nothing, stable state
|
||||||
// Do nothing, stable state
|
break
|
||||||
break
|
|
||||||
|
|
||||||
case .pendingHidden:
|
case .pendingHidden:
|
||||||
NSCursor.hide()
|
NSCursor.hide()
|
||||||
cursorVisible = .hidden
|
cursorVisible = .hidden
|
||||||
|
|
||||||
case .pendingVisible:
|
case .pendingVisible:
|
||||||
NSCursor.unhide()
|
NSCursor.unhide()
|
||||||
cursorVisible = .visible
|
cursorVisible = .visible
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.set()
|
cursor.set()
|
||||||
|
Reference in New Issue
Block a user