-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b369575
commit eef3aa4
Showing
11 changed files
with
205 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// CursorButton.swift | ||
// Calendr | ||
// | ||
// Created by Paker on 19/02/23. | ||
// | ||
|
||
import Cocoa | ||
|
||
class CursorButton: NSButton { | ||
|
||
private var trackingArea: NSTrackingArea? | ||
private let cursor: NSCursor? | ||
|
||
init(cursor: NSCursor? = .pointingHand) { | ||
self.cursor = cursor | ||
super.init(frame: .zero) | ||
refusesFirstResponder = true | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// 🔨 For some reason addCursorRect is not reliable, | ||
// maybe because the container may clip the touch area and mess up | ||
// the mouse enter detection, but to be honest I have no idea why | ||
override func updateTrackingAreas() { | ||
|
||
if let trackingArea = trackingArea { | ||
removeTrackingArea(trackingArea) | ||
} | ||
|
||
trackingArea = NSTrackingArea( | ||
rect: bounds, | ||
options: [.cursorUpdate, .mouseMoved, .mouseEnteredAndExited, .activeAlways], | ||
owner: self | ||
) | ||
|
||
addTrackingArea(trackingArea!) | ||
|
||
super.updateTrackingAreas() | ||
} | ||
|
||
override func cursorUpdate(with event: NSEvent) { | ||
super.cursorUpdate(with: event) | ||
cursor?.set() | ||
} | ||
|
||
override func mouseMoved(with event: NSEvent) { | ||
super.mouseMoved(with: event) | ||
cursorUpdate(with: event) | ||
} | ||
|
||
override func mouseExited(with event: NSEvent) { | ||
super.mouseExited(with: event) | ||
super.cursorUpdate(with: event) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.