Skip to content

Commit

Permalink
fix: shift key + scroll should scroll the ui
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Apr 27, 2020
1 parent 3420a60 commit d64a6a5
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/ui/main-window/ThumbnailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class ThumbnailsView: NSVisualEffectView {
guard window.shouldShowTheUser else { continue }
let view = ThumbnailsView.recycledViews[index]
view.updateRecycledCellWithNewContent(window,
{ () -> Void in App.app.focusSelectedWindow(window) },
{ () -> Void in Windows.updateFocusedWindowIndex(index) },
height, screen)
{ () -> Void in App.app.focusSelectedWindow(window) },
{ () -> Void in Windows.updateFocusedWindowIndex(index) },
height, screen)
let width = view.frame.size.width
if (currentX + width).rounded(.down) > widthMax {
currentX = CGFloat(0)
Expand Down Expand Up @@ -87,16 +87,34 @@ class ThumbnailsView: NSVisualEffectView {
}

class ScrollView: NSScrollView {
// overriding scrollWheel() turns this false; we force it to be true to enable responsive scrolling
override class var isCompatibleWithResponsiveScrolling: Bool { true }

convenience init() {
self.init(frame: .zero)
documentView = FlippedView(frame: .zero)
drawsBackground = false
hasVerticalScroller = true
scrollerStyle = .overlay
scrollerKnobStyle = .light
horizontalScrollElasticity = .none
usesPredominantAxisScrolling = true
forceOverlayStyle()
}

// holding shift and using the scrolling wheel will generate a horizontal movement
// shift can be part of shortcuts so we force shift scrolls to be vertical
override func scrollWheel(with event: NSEvent) {
if event.modifierFlags.contains(.shift) && event.scrollingDeltaY == 0 {
let cgEvent = event.cgEvent!
cgEvent.setDoubleValueField(.scrollWheelEventDeltaAxis1, value: cgEvent.getDoubleValueField(.scrollWheelEventDeltaAxis2))
cgEvent.setDoubleValueField(.scrollWheelEventDeltaAxis2, value: 0)
super.scrollWheel(with: NSEvent(cgEvent: cgEvent)!)
} else {
super.scrollWheel(with: event)
}
}

// force overlay style after a change in System Preference > General > Show scroll bars
private func forceOverlayStyle() {
NotificationCenter.default.addObserver(forName: NSScroller.preferredScrollerStyleDidChangeNotification, object: nil, queue: nil) { [weak self] _ in
Expand All @@ -107,4 +125,4 @@ class ScrollView: NSScrollView {

class FlippedView: NSView {
override var isFlipped: Bool { true }
}
}

0 comments on commit d64a6a5

Please sign in to comment.