Skip to content

Commit

Permalink
Merge pull request #1366 from SkyrilHD/hapticFeedback
Browse files Browse the repository at this point in the history
Add Haptic Feedback Support for Window Snapping
  • Loading branch information
rxhanson authored Apr 23, 2024
2 parents a7b7885 + 16cb30d commit 67ae3d5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
27 changes: 20 additions & 7 deletions Rectangle/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -3638,20 +3638,20 @@ DQ
<objects>
<viewController storyboardIdentifier="HookshotConfigViewController" id="t2d-Q7-RLy" customClass="SnapAreaViewController" customModule="Rectangle" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="yfQ-gV-dm5">
<rect key="frame" x="0.0" y="0.0" width="654" height="731"/>
<rect key="frame" x="0.0" y="0.0" width="654" height="757"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView distribution="fill" orientation="vertical" alignment="centerX" spacing="30" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="9T6-Lr-8m1">
<rect key="frame" x="20" y="30" width="614" height="671"/>
<rect key="frame" x="20" y="30" width="614" height="697"/>
<subviews>
<stackView distribution="fill" orientation="vertical" alignment="leading" spacing="20" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5k8-dN-bzX">
<rect key="frame" x="20" y="557" width="574" height="114"/>
<rect key="frame" x="20" y="557" width="574" height="140"/>
<subviews>
<stackView distribution="fill" orientation="vertical" alignment="leading" spacing="10" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5Le-Om-VLZ">
<rect key="frame" x="0.0" y="20" width="267" height="94"/>
<rect key="frame" x="0.0" y="20" width="267" height="120"/>
<subviews>
<button verticalHuggingPriority="750" horizontalCompressionResistancePriority="1000" verticalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="3wO-pf-nsb">
<rect key="frame" x="-2" y="77" width="189" height="18"/>
<rect key="frame" x="-2" y="103" width="189" height="18"/>
<buttonCell key="cell" type="check" title="Snap windows by dragging" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="1ui-PL-TkR">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -3661,7 +3661,7 @@ DQ
</connections>
</button>
<button verticalHuggingPriority="750" horizontalCompressionResistancePriority="1000" verticalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="9Ed-T3-hCA">
<rect key="frame" x="-2" y="51" width="257" height="18"/>
<rect key="frame" x="-2" y="77" width="257" height="18"/>
<buttonCell key="cell" type="check" title="Restore window size when unsnapped" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="UZP-5q-D5Y">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -3671,7 +3671,7 @@ DQ
</connections>
</button>
<button verticalHuggingPriority="750" horizontalCompressionResistancePriority="1000" verticalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="cbx-fa-jJh">
<rect key="frame" x="-2" y="25" width="132" height="18"/>
<rect key="frame" x="-2" y="51" width="132" height="18"/>
<buttonCell key="cell" type="check" title="Animate footprint" bezelStyle="regularSquare" imagePosition="left" inset="2" id="kx2-tZ-lk8">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -3680,6 +3680,16 @@ DQ
<action selector="toggleAnimateFootprint:" target="t2d-Q7-RLy" id="qo7-sw-gbY"/>
</connections>
</button>
<button verticalHuggingPriority="750" horizontalCompressionResistancePriority="1000" verticalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="idz-Fq-8Qx">
<rect key="frame" x="-2" y="25" width="126" height="18"/>
<buttonCell key="cell" type="check" title="Haptic feedback" bezelStyle="regularSquare" imagePosition="left" inset="2" id="r2Y-cY-tgn">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="toggleHapticFeedback:" target="t2d-Q7-RLy" id="fYe-DO-EgM"/>
</connections>
</button>
<button verticalHuggingPriority="750" horizontalCompressionResistancePriority="1000" verticalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="vrs-iM-XVL" userLabel="Mission Control Dragging Checkbox">
<rect key="frame" x="-2" y="-1" width="269" height="18"/>
<buttonCell key="cell" type="check" title="Disable fast dragging to Mission Control" bezelStyle="regularSquare" imagePosition="left" inset="2" id="3hZ-Cs-EZ6">
Expand All @@ -3696,12 +3706,14 @@ DQ
<integer value="1000"/>
<integer value="1000"/>
<integer value="1000"/>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
<box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="RAB-qk-O6q">
Expand Down Expand Up @@ -4205,6 +4217,7 @@ DQ
<outlet property="bottomPortraitSelect" destination="ZYO-D7-C2a" id="pZd-mp-0yk"/>
<outlet property="bottomRightLandscapeSelect" destination="jVF-3c-sL0" id="eYi-gy-RF3"/>
<outlet property="bottomRightPortraitSelect" destination="lje-Rc-9Hj" id="bxP-nE-cgS"/>
<outlet property="hapticFeedbackCheckbox" destination="idz-Fq-8Qx" id="5Wb-6e-kmA"/>
<outlet property="leftLandscapeSelect" destination="jqR-m9-Kh7" id="wBI-Th-vtz"/>
<outlet property="leftPortraitSelect" destination="NlH-2s-Bb2" id="r9T-BM-YbN"/>
<outlet property="missionControlDraggingCheckbox" destination="vrs-iM-XVL" id="xgC-0R-SeA"/>
Expand Down
2 changes: 2 additions & 0 deletions Rectangle/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Defaults {
static let missionControlDragging = OptionalBoolDefault(key: "missionControlDragging")
static let enhancedUI = IntEnumDefault<EnhancedUI>(key: "enhancedUI", defaultValue: .disableEnable)
static let footprintAnimationDurationMultiplier = FloatDefault(key: "footprintAnimationDurationMultiplier", defaultValue: 0)
static let hapticFeedbackOnSnap = OptionalBoolDefault(key: "hapticFeedbackOnSnap")
static let missionControlDraggingAllowedOffscreenDistance = FloatDefault(key: "missionControlDraggingAllowedOffscreenDistance", defaultValue: 25)
static let missionControlDraggingDisallowedDuration = IntDefault(key: "missionControlDraggingDisallowedDuration", defaultValue: 250)
static let doubleClickTitleBar = IntDefault(key: "doubleClickTitleBar")
Expand Down Expand Up @@ -153,6 +154,7 @@ class Defaults {
missionControlDragging,
enhancedUI,
footprintAnimationDurationMultiplier,
hapticFeedbackOnSnap,
missionControlDraggingAllowedOffscreenDistance,
missionControlDraggingDisallowedDuration,
doubleClickTitleBar,
Expand Down
7 changes: 7 additions & 0 deletions Rectangle/PrefsWindow/SnapAreaViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class SnapAreaViewController: NSViewController {
@IBOutlet weak var windowSnappingCheckbox: NSButton!
@IBOutlet weak var unsnapRestoreButton: NSButton!
@IBOutlet weak var animateFootprintCheckbox: NSButton!
@IBOutlet weak var hapticFeedbackCheckbox: NSButton!
@IBOutlet weak var missionControlDraggingCheckbox: NSButton!

@IBOutlet weak var topLeftLandscapeSelect: NSPopUpButton!
Expand Down Expand Up @@ -51,6 +52,11 @@ class SnapAreaViewController: NSViewController {
Defaults.footprintAnimationDurationMultiplier.value = newSetting
}

@IBAction func toggleHapticFeedback(_ sender: NSButton) {
let newSetting: Bool = sender.state == .on
Defaults.hapticFeedbackOnSnap.enabled = newSetting
}

@IBAction func toggleMissionControlDragging(_ sender: NSButton) {
let newSetting: Bool = sender.state == .off
Defaults.missionControlDragging.enabled = newSetting
Expand Down Expand Up @@ -81,6 +87,7 @@ class SnapAreaViewController: NSViewController {
windowSnappingCheckbox.state = Defaults.windowSnapping.userDisabled ? .off : .on
unsnapRestoreButton.state = Defaults.unsnapRestore.userDisabled ? .off : .on
animateFootprintCheckbox.state = Defaults.footprintAnimationDurationMultiplier.value > 0 ? .on : .off
hapticFeedbackCheckbox.state = Defaults.hapticFeedbackOnSnap.userEnabled ? .on : .off
missionControlDraggingCheckbox.state = Defaults.missionControlDragging.userDisabled ? .on : .off
missionControlDraggingCheckbox.isHidden = !Defaults.missionControlDragging.userDisabled
loadSnapAreas()
Expand Down
5 changes: 5 additions & 0 deletions Rectangle/Snapping/SnappingManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ class SnappingManager {
if snapArea == currentSnapArea {
return
}

if Defaults.hapticFeedbackOnSnap.userEnabled {
NSHapticFeedbackManager.defaultPerformer.perform(.alignment, performanceTime: .now)
}

let currentWindow = Window(id: windowId, rect: currentRect)

if let newBoxRect = getBoxRect(hotSpot: snapArea, currentWindow: currentWindow) {
Expand Down
20 changes: 19 additions & 1 deletion Rectangle/mul.lproj/Main.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -35623,6 +35623,24 @@
}
}
},
"r2Y-cY-tgn.title" : {
"comment" : "Class = \"NSButtonCell\"; title = \"Haptic feedback\"; ObjectID = \"r2Y-cY-tgn\";",
"extractionState" : "extracted_with_value",
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Haptisches Feedback"
}
},
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Haptic feedback"
}
}
}
},
"R4o-n2-Eq4.title" : {
"comment" : "Class = \"NSMenuItem\"; title = \"Zoom\"; ObjectID = \"R4o-n2-Eq4\";",
"extractionState" : "manual",
Expand Down Expand Up @@ -47169,7 +47187,7 @@
},
"de" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "Einstellungen…"
}
},
Expand Down

0 comments on commit 67ae3d5

Please sign in to comment.