From abe2e0b73b65a57cee356fef7ba7b2a1f9ed3590 Mon Sep 17 00:00:00 2001 From: decodism Date: Sun, 12 Feb 2023 19:07:45 +0100 Subject: [PATCH] fix: bring back mouse hover selection (closes #2317) --- src/logic/Preferences.swift | 2 +- src/logic/Windows.swift | 21 +++++++++++---------- src/ui/main-window/ThumbnailView.swift | 6 ++---- src/ui/main-window/ThumbnailsView.swift | 20 ++++++++++++-------- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/logic/Preferences.swift b/src/logic/Preferences.swift index 82cf5d90..7e2f3f09 100644 --- a/src/logic/Preferences.swift +++ b/src/logic/Preferences.swift @@ -29,7 +29,7 @@ class Preferences { "quitAppShortcut": "Q", "hideShowAppShortcut": "H", "arrowKeysEnabled": "true", - "mouseHoverEnabled": "true", + "mouseHoverEnabled": "false", "cursorFollowFocusEnabled": "false", "showMinimizedWindows": ShowHowPreference.show.rawValue, "showMinimizedWindows2": ShowHowPreference.show.rawValue, diff --git a/src/logic/Windows.swift b/src/logic/Windows.swift index 15372409..0675658d 100644 --- a/src/logic/Windows.swift +++ b/src/logic/Windows.swift @@ -36,11 +36,11 @@ class Windows { if let app = Applications.find(NSWorkspace.shared.frontmostApplication?.processIdentifier), app.focusedWindow == nil, let lastFocusedWindowIndex = getLastFocusedWindowIndex() { - updateFocusedWindowIndex(lastFocusedWindowIndex) + updateHoveredAndFocusedWindowIndexes(lastFocusedWindowIndex) } else { cycleFocusedWindowIndex(1) if focusedWindowIndex == 0 { - updateFocusedWindowIndex(0) + updateHoveredAndFocusedWindowIndexes(0) } } } @@ -99,22 +99,23 @@ class Windows { return nil } - static func updateFocusedWindowIndex(_ newIndex: Int, _ fromMouse: Bool = false) { - if (fromMouse && newIndex == hoveredWindowIndex) || (!fromMouse && newIndex == focusedWindowIndex) { - return - } - if fromMouse { + static func updateHoveredAndFocusedWindowIndexes(_ newIndex: Int, _ fromMouse: Bool = false) { + var index: Int? + if fromMouse && newIndex != hoveredWindowIndex { let oldIndex = hoveredWindowIndex hoveredWindowIndex = newIndex if let oldIndex = oldIndex { ThumbnailsView.highlight(oldIndex) } - } else { + index = hoveredWindowIndex + } + if (!fromMouse || Preferences.mouseHoverEnabled) && newIndex != focusedWindowIndex { let oldIndex = focusedWindowIndex focusedWindowIndex = newIndex ThumbnailsView.highlight(oldIndex) + index = focusedWindowIndex } - let index = fromMouse ? hoveredWindowIndex! : focusedWindowIndex + guard let index = index else { return } ThumbnailsView.highlight(index) let focusedView = ThumbnailsView.recycledViews[index] App.app.thumbnailsPanel.thumbnailsView.scrollView.contentView.scrollToVisible(focusedView.frame) @@ -143,7 +144,7 @@ class Windows { (KeyRepeatTimer.isARepeat || KeyRepeatTimer.timer?.isValid ?? false) { return } - updateFocusedWindowIndex(nextIndex) + updateHoveredAndFocusedWindowIndexes(nextIndex) } static func windowIndexAfterCycling(_ step: Int) -> Int { diff --git a/src/ui/main-window/ThumbnailView.swift b/src/ui/main-window/ThumbnailView.swift index 392d134d..252363a9 100644 --- a/src/ui/main-window/ThumbnailView.swift +++ b/src/ui/main-window/ThumbnailView.swift @@ -186,7 +186,7 @@ class ThumbnailView: NSStackView { windowlessIcon.needsDisplay = true } self.mouseUpCallback = { () -> Void in App.app.focusSelectedWindow(element) } - self.mouseMovedCallback = { () -> Void in Windows.updateFocusedWindowIndex(index, true) } + self.mouseMovedCallback = { () -> Void in Windows.updateHoveredAndFocusedWindowIndexes(index, true) } [quitIcon, closeIcon, minimizeIcon, maximizeIcon].forEach { $0.window_ = element } showOrHideWindowControls(false) // force a display to avoid flickering; see https://github.com/lwouis/alt-tab-macos/issues/197 @@ -263,9 +263,7 @@ class ThumbnailView: NSStackView { func mouseMoved() { showOrHideWindowControls(true) - if Preferences.mouseHoverEnabled { - mouseMovedCallback() - } + mouseMovedCallback() } override func mouseUp(with event: NSEvent) { diff --git a/src/ui/main-window/ThumbnailsView.swift b/src/ui/main-window/ThumbnailsView.swift index 91be1fa0..ce5d73fc 100644 --- a/src/ui/main-window/ThumbnailsView.swift +++ b/src/ui/main-window/ThumbnailsView.swift @@ -71,7 +71,7 @@ class ThumbnailsView: NSVisualEffectView { return leadingSide ? NSMinX($0.frame) < originCenter : NSMaxX($0.frame) > originCenter } ?? iterable.last! let targetIndex = ThumbnailsView.recycledViews.firstIndex(of: targetView)! - Windows.updateFocusedWindowIndex(targetIndex) + Windows.updateHoveredAndFocusedWindowIndexes(targetIndex) } } @@ -228,6 +228,14 @@ class ScrollView: NSScrollView { self?.isCurrentlyScrolling = true } } + + private func resetHoveredWindow() { + if let oldIndex = Windows.hoveredWindowIndex { + Windows.hoveredWindowIndex = nil + ThumbnailsView.highlight(oldIndex) + ThumbnailsView.recycledViews[oldIndex].showOrHideWindowControls(false) + } + } override func mouseMoved(with event: NSEvent) { // disable mouse hover during scrolling as it creates jank during elastic bounces at the start/end of the scrollview @@ -245,19 +253,15 @@ class ScrollView: NSScrollView { let target = target as! ThumbnailView target.mouseMoved() } else { - previousTarget?.showOrHideWindowControls(false) + resetHoveredWindow() } } else { - previousTarget?.showOrHideWindowControls(false) + resetHoveredWindow() } } override func mouseExited(with event: NSEvent) { - if let oldIndex = Windows.hoveredWindowIndex { - Windows.hoveredWindowIndex = nil - ThumbnailsView.highlight(oldIndex) - ThumbnailsView.recycledViews[oldIndex].showOrHideWindowControls(false) - } + resetHoveredWindow() } /// holding shift and using the scrolling wheel will generate a horizontal movement