Skip to content

Commit c0cd1cc

Browse files
committed
Delay taking action on mouse click. Fixes responsiveness
Also, distinguish LMB and other events
1 parent 6138fe8 commit c0cd1cc

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Spaceman/View/StatusBar.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class StatusBar: NSObject, NSMenuDelegate {
7474
guard let event = NSApp.currentEvent else {
7575
return
7676
}
77-
DispatchQueue.main.async {
77+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
7878
if event.type == .rightMouseDown {
7979
// Show the menu on right-click
8080
if let sbMenu = self.statusBarMenu {
@@ -84,27 +84,29 @@ class StatusBar: NSObject, NSMenuDelegate {
8484
sbMenu.popUp(positioning: nil, at: menuOrigin, in: nil)
8585
sbButton.isHighlighted = false
8686
}
87-
} else {
87+
} else if (event.type == .leftMouseDown) {
8888
// Switch desktops on left click
8989
let locationInButton = sbButton.convert(event.locationInWindow, from: sbButton)
9090

9191
self.spaceSwitcher.switchUsingLocation(
9292
widths: self.iconCreator.widths,
9393
horizontal: locationInButton.x,
9494
onError: self.flashStatusBar)
95+
} else {
96+
print("Other event: \(event.type)")
9597
}
9698
}
9799
}
98100

99101
func flashStatusBar() {
100102
if let button = statusBarItem.button {
101-
let duration: TimeInterval = 0.1
103+
let blinkInterval: TimeInterval = 0.1
102104
button.isHighlighted = true
103-
DispatchQueue.main.asyncAfter(deadline: .now() + duration) {
105+
DispatchQueue.main.asyncAfter(deadline: .now() + blinkInterval) {
104106
button.isHighlighted = false
105-
DispatchQueue.main.asyncAfter(deadline: .now() + duration) {
107+
DispatchQueue.main.asyncAfter(deadline: .now() + blinkInterval) {
106108
button.isHighlighted = true
107-
DispatchQueue.main.asyncAfter(deadline: .now() + duration) {
109+
DispatchQueue.main.asyncAfter(deadline: .now() + blinkInterval) {
108110
button.isHighlighted = false
109111
}
110112
}

0 commit comments

Comments
 (0)