Skip to content

Commit

Permalink
chore: remove outdated mouse observer logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ejbills committed Dec 28, 2024
1 parent 6cad44e commit dbe78ee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
8 changes: 4 additions & 4 deletions DockDoor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.4;
CURRENT_PROJECT_VERSION = 1.5;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DockDoor/Preview Content\"";
DEVELOPMENT_TEAM = 2Q775S63Q3;
Expand All @@ -798,7 +798,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.4;
MARKETING_VERSION = 1.5;
PRODUCT_BUNDLE_IDENTIFIER = com.ethanbills.DockDoor;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -815,7 +815,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.4;
CURRENT_PROJECT_VERSION = 1.5;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DockDoor/Preview Content\"";
DEVELOPMENT_TEAM = 2Q775S63Q3;
Expand All @@ -832,7 +832,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.4;
MARKETING_VERSION = 1.5;
PRODUCT_BUNDLE_IDENTIFIER = com.ethanbills.DockDoor;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class MouseTrackingNSView: NSView {
private var globalMouseMonitor: Any?
private var inactivityTimer: Timer?

private let baseDistanceThreshold: CGFloat = 600
private let inactivityTimeout: TimeInterval = 10.0

init(appName: String, mouseLocation: CGPoint, bestGuessMonitor: NSScreen, dockPosition: DockPosition, frame frameRect: NSRect = .zero) {
Expand All @@ -41,7 +40,6 @@ class MouseTrackingNSView: NSView {
fadeOutDuration = Defaults[.fadeOutDuration]
super.init(frame: frameRect)
setupTrackingArea()
setupMouseMonitors()
setupGlobalMouseMonitor()
}

Expand Down Expand Up @@ -75,26 +73,6 @@ class MouseTrackingNSView: NSView {
}
}

private func setupMouseMonitors() {
// The trackingTimer is used to track any lingering cases where the user does not interact with the window at all.
// In such cases, we hide the window if it goes a decent distance from the initial location of the dock icon.
// We use a timer to poll the mosue location as global and local mouse listeners are unreliable inside views.
let dist = dockPosition == .bottom ? bestGuessMonitor.frame.height * 0.5 : bestGuessMonitor.frame.width * 0.5
trackingTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { [weak self] _ in
guard let self else { return }
checkMouseDistance(dist: dist)
}
}

private func checkMouseDistance(dist: CGFloat) {
let currentMousePosition = DockObserver.cgPointFromNSPoint(NSEvent.mouseLocation, forScreen: bestGuessMonitor)
if currentMousePosition.distance(to: mouseLocation) > dist {
DispatchQueue.main.async { [weak self] in
self?.hideWindow()
}
}
}

deinit {
clearTimers()
if let monitor = globalMouseMonitor {
Expand Down

0 comments on commit dbe78ee

Please sign in to comment.