Improved analog support for scrolling, and allow speed adjustments.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 6 Mar 2013 11:41:25 +0000 (12:41 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 6 Mar 2013 11:41:25 +0000 (12:41 +0100)
English.lproj/MainMenu.xib
NJOutputController.h
NJOutputController.m
NJOutputMouseScroll.h
NJOutputMouseScroll.m

index bd4f12a66c93ad6130e097565e6454add83fe691..9cce48b7d2d880cea6fafbb4a9fec59b34cc19c3 100644 (file)
                                                                                                                        <string key="NSFrameSize">{200, 298}</string>
                                                                                                                        <reference key="NSSuperview" ref="698362889"/>
                                                                                                                        <reference key="NSWindow"/>
-                                                                                                                       <reference key="NSNextKeyView" ref="1036252745"/>
+                                                                                                                       <reference key="NSNextKeyView" ref="892486973"/>
                                                                                                                        <bool key="NSEnabled">YES</bool>
                                                                                                                        <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
                                                                                                                        <bool key="NSControlAllowsExpansionToolTips">YES</bool>
                                                                                        <string key="NSFrameSize">{202, 300}</string>
                                                                                        <reference key="NSSuperview" ref="977242492"/>
                                                                                        <reference key="NSWindow"/>
-                                                                                       <reference key="NSNextKeyView" ref="892486973"/>
+                                                                                       <reference key="NSNextKeyView" ref="698362889"/>
                                                                                        <int key="NSsFlags">150034</int>
                                                                                        <reference key="NSVScroller" ref="1036252745"/>
                                                                                        <reference key="NSHScroller" ref="892486973"/>
                                                                        <reference key="NSNextResponder" ref="206489479"/>
                                                                        <int key="NSvFlags">256</int>
                                                                        <array class="NSMutableArray" key="NSSubviews">
+                                                                               <object class="NSSlider" id="792189805">
+                                                                                       <reference key="NSNextResponder" ref="606740242"/>
+                                                                                       <int key="NSvFlags">268</int>
+                                                                                       <string key="NSFrame">{{228, 52}, {140, 12}}</string>
+                                                                                       <reference key="NSSuperview" ref="606740242"/>
+                                                                                       <reference key="NSWindow"/>
+                                                                                       <string key="NSReuseIdentifierKey">_NS:9</string>
+                                                                                       <bool key="NSEnabled">YES</bool>
+                                                                                       <object class="NSSliderCell" key="NSCell" id="423057230">
+                                                                                               <int key="NSCellFlags">-2080374784</int>
+                                                                                               <int key="NSCellFlags2">262144</int>
+                                                                                               <string key="NSContents"/>
+                                                                                               <string key="NSCellIdentifier">_NS:9</string>
+                                                                                               <reference key="NSControlView" ref="792189805"/>
+                                                                                               <double key="NSMaxValue">30</double>
+                                                                                               <double key="NSMinValue">0.0</double>
+                                                                                               <double key="NSValue">15</double>
+                                                                                               <double key="NSAltIncValue">0.0</double>
+                                                                                               <int key="NSNumberOfTickMarks">0</int>
+                                                                                               <int key="NSTickMarkPosition">1</int>
+                                                                                               <bool key="NSAllowsTickMarkValuesOnly">NO</bool>
+                                                                                               <bool key="NSVertical">NO</bool>
+                                                                                       </object>
+                                                                                       <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
+                                                                               </object>
                                                                                <object class="NSSlider" id="385416822">
                                                                                        <reference key="NSNextResponder" ref="606740242"/>
                                                                                        <int key="NSvFlags">268</int>
                                                                                <object class="NSSegmentedControl" id="875916470">
                                                                                        <reference key="NSNextResponder" ref="606740242"/>
                                                                                        <int key="NSvFlags">265</int>
-                                                                                       <string key="NSFrame">{{226, 132}, {179, 15}}</string>
+                                                                                       <string key="NSFrame">{{227, 132}, {178, 15}}</string>
                                                                                        <reference key="NSSuperview" ref="606740242"/>
                                                                                        <reference key="NSWindow"/>
                                                                                        <reference key="NSNextKeyView" ref="385416822"/>
                                                                                                                <int key="NSSegmentItemImageScaling">0</int>
                                                                                                        </object>
                                                                                                        <object class="NSSegmentItem">
-                                                                                                               <double key="NSSegmentItemWidth">42</double>
+                                                                                                               <double key="NSSegmentItemWidth">41</double>
                                                                                                                <string key="NSSegmentItemLabel">↓</string>
                                                                                                                <int key="NSSegmentItemImageScaling">0</int>
                                                                                                        </object>
                                                                                <object class="NSSegmentedControl" id="921829691">
                                                                                        <reference key="NSNextResponder" ref="606740242"/>
                                                                                        <int key="NSvFlags">265</int>
-                                                                                       <string key="NSFrame">{{226, 55}, {180, 24}}</string>
+                                                                                       <string key="NSFrame">{{227, 64}, {178, 15}}</string>
                                                                                        <reference key="NSSuperview" ref="606740242"/>
                                                                                        <reference key="NSWindow"/>
-                                                                                       <reference key="NSNextKeyView"/>
+                                                                                       <reference key="NSNextKeyView" ref="792189805"/>
                                                                                        <string key="NSReuseIdentifierKey">_NS:9</string>
                                                                                        <bool key="NSEnabled">YES</bool>
                                                                                        <object class="NSSegmentedCell" key="NSCell" id="301345285">
                                                                                                <int key="NSCellFlags">67108864</int>
-                                                                                               <int key="NSCellFlags2">0</int>
-                                                                                               <object class="NSFont" key="NSSupport" id="515740949">
-                                                                                                       <string key="NSName">LucidaGrande</string>
-                                                                                                       <double key="NSSize">13</double>
-                                                                                                       <int key="NSfFlags">16</int>
-                                                                                               </object>
+                                                                                               <int key="NSCellFlags2">262144</int>
+                                                                                               <reference key="NSSupport" ref="22"/>
                                                                                                <string key="NSCellIdentifier">_NS:9</string>
                                                                                                <reference key="NSControlView" ref="921829691"/>
                                                                                                <array class="NSMutableArray" key="NSSegmentImages">
                                                                                                        <object class="NSSegmentItem">
-                                                                                                               <double key="NSSegmentItemWidth">87</double>
-                                                                                                               <string key="NSSegmentItemLabel">Up</string>
+                                                                                                               <double key="NSSegmentItemWidth">68</double>
+                                                                                                               <string key="NSSegmentItemLabel">↑</string>
+                                                                                                               <string key="NSSegmentItemTooltip">Scroll up continuously</string>
                                                                                                                <bool key="NSSegmentItemSelected">YES</bool>
                                                                                                                <int key="NSSegmentItemImageScaling">0</int>
                                                                                                        </object>
                                                                                                        <object class="NSSegmentItem">
-                                                                                                               <double key="NSSegmentItemWidth">86</double>
-                                                                                                               <string key="NSSegmentItemLabel">Down</string>
+                                                                                                               <double key="NSSegmentItemWidth">67</double>
+                                                                                                               <string key="NSSegmentItemLabel">↓</string>
+                                                                                                               <string key="NSSegmentItemTooltip">Scroll down continuously</string>
                                                                                                                <int key="NSSegmentItemTag">1</int>
                                                                                                                <int key="NSSegmentItemImageScaling">0</int>
                                                                                                        </object>
+                                                                                                       <object class="NSSegmentItem">
+                                                                                                               <string key="NSSegmentItemLabel">⤒</string>
+                                                                                                               <string key="NSSegmentItemTooltip">Scroll up one step</string>
+                                                                                                               <int key="NSSegmentItemImageScaling">0</int>
+                                                                                                       </object>
+                                                                                                       <object class="NSSegmentItem">
+                                                                                                               <string key="NSSegmentItemLabel">⤓</string>
+                                                                                                               <string key="NSSegmentItemTooltip">Scroll down one step</string>
+                                                                                                               <int key="NSSegmentItemImageScaling">0</int>
+                                                                                                       </object>
                                                                                                </array>
                                                                                                <int key="NSSegmentStyle">1</int>
                                                                                        </object>
                                                                                        <object class="NSSegmentedCell" key="NSCell" id="514491330">
                                                                                                <int key="NSCellFlags">67108864</int>
                                                                                                <int key="NSCellFlags2">0</int>
-                                                                                               <reference key="NSSupport" ref="515740949"/>
+                                                                                               <object class="NSFont" key="NSSupport">
+                                                                                                       <string key="NSName">LucidaGrande</string>
+                                                                                                       <double key="NSSize">13</double>
+                                                                                                       <int key="NSfFlags">16</int>
+                                                                                               </object>
                                                                                                <string key="NSCellIdentifier">_NS:9</string>
                                                                                                <reference key="NSControlView" ref="125828224"/>
                                                                                                <array class="NSMutableArray" key="NSSegmentImages">
                                                                                <string key="NSFrameSize">{198, 198}</string>
                                                                                <reference key="NSSuperview" ref="947403733"/>
                                                                                <reference key="NSWindow"/>
-                                                                               <reference key="NSNextKeyView" ref="968378655"/>
+                                                                               <reference key="NSNextKeyView" ref="553414014"/>
                                                                                <bool key="NSEnabled">YES</bool>
                                                                                <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
                                                                                <bool key="NSControlAllowsExpansionToolTips">YES</bool>
                                                <string key="NSFrame">{{0, 20}, {200, 200}}</string>
                                                <reference key="NSSuperview" ref="671181514"/>
                                                <reference key="NSWindow"/>
-                                               <reference key="NSNextKeyView" ref="553414014"/>
+                                               <reference key="NSNextKeyView" ref="947403733"/>
                                                <int key="NSsFlags">150034</int>
                                                <reference key="NSVScroller" ref="968378655"/>
                                                <reference key="NSHScroller" ref="553414014"/>
                                                <string key="NSFrame">{{66, -1}, {134, 23}}</string>
                                                <reference key="NSSuperview" ref="671181514"/>
                                                <reference key="NSWindow"/>
-                                               <reference key="NSNextKeyView"/>
                                                <string key="NSReuseIdentifierKey">_NS:22</string>
                                                <bool key="NSEnabled">YES</bool>
                                                <object class="NSButtonCell" key="NSCell" id="517346822">
                                        </object>
                                        <int key="connectionID">886</int>
                                </object>
+                               <object class="IBConnectionRecord">
+                                       <object class="IBActionConnection" key="connection">
+                                               <string key="label">scrollSpeedChanged:</string>
+                                               <reference key="source" ref="801536542"/>
+                                               <reference key="destination" ref="792189805"/>
+                                       </object>
+                                       <int key="connectionID">890</int>
+                               </object>
+                               <object class="IBConnectionRecord">
+                                       <object class="IBOutletConnection" key="connection">
+                                               <string key="label">scrollSpeedSlider</string>
+                                               <reference key="source" ref="801536542"/>
+                                               <reference key="destination" ref="792189805"/>
+                                       </object>
+                                       <int key="connectionID">891</int>
+                               </object>
                                <object class="IBConnectionRecord">
                                        <object class="IBOutletConnection" key="connection">
                                                <string key="label">keyDelegate</string>
                                                        <reference ref="194275224"/>
                                                        <reference ref="57697638"/>
                                                        <reference ref="385416822"/>
+                                                       <reference ref="792189805"/>
                                                </array>
                                                <reference key="parent" ref="206489479"/>
                                                <string key="objectName">Output Editor Pane</string>
                                                <reference key="object" ref="5417367"/>
                                                <reference key="parent" ref="385416822"/>
                                        </object>
+                                       <object class="IBObjectRecord">
+                                               <int key="objectID">887</int>
+                                               <reference key="object" ref="792189805"/>
+                                               <array class="NSMutableArray" key="children">
+                                                       <reference ref="423057230"/>
+                                               </array>
+                                               <reference key="parent" ref="606740242"/>
+                                       </object>
+                                       <object class="IBObjectRecord">
+                                               <int key="objectID">888</int>
+                                               <reference key="object" ref="423057230"/>
+                                               <reference key="parent" ref="792189805"/>
+                                       </object>
                                </array>
                        </object>
                        <dictionary class="NSMutableDictionary" key="flattenedProperties">
                                <string key="734.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="735.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="744.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-                               <integer value="0" key="745.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
+                               <integer value="1" key="745.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
                                <string key="745.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="748.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="749.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-                               <integer value="0" key="750.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
+                               <integer value="3" key="750.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
                                <string key="750.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="754.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <integer value="0" key="755.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
                                </object>
                                <string key="883.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="884.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+                               <object class="NSMutableDictionary" key="887.IBAttributePlaceholdersKey">
+                                       <string key="NS.key.0">ToolTip</string>
+                                       <object class="IBToolTipAttribute" key="NS.object.0">
+                                               <string key="name">ToolTip</string>
+                                               <reference key="object" ref="792189805"/>
+                                               <string key="toolTip">Mouse scroll speed</string>
+                                       </object>
+                               </object>
+                               <string key="887.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+                               <string key="888.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="92.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                        </dictionary>
                        <dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
                        <nil key="activeLocalization"/>
                        <dictionary class="NSMutableDictionary" key="localizations"/>
                        <nil key="sourceID"/>
-                       <int key="maxID">886</int>
+                       <int key="maxID">891</int>
                </object>
                <object class="IBClassDescriber" key="IBDocument.Classes">
                        <array class="NSMutableArray" key="referencedPartialClassDescriptions">
                                                <string key="mdirChanged:">id</string>
                                                <string key="mouseSpeedChanged:">id</string>
                                                <string key="radioChanged:">id</string>
+                                               <string key="scrollSpeedChanged:">id</string>
                                                <string key="sdirChanged:">id</string>
                                        </dictionary>
                                        <dictionary class="NSMutableDictionary" key="actionInfosByName">
                                                        <string key="name">radioChanged:</string>
                                                        <string key="candidateClassName">id</string>
                                                </object>
+                                               <object class="IBActionInfo" key="scrollSpeedChanged:">
+                                                       <string key="name">scrollSpeedChanged:</string>
+                                                       <string key="candidateClassName">id</string>
+                                               </object>
                                                <object class="IBActionInfo" key="sdirChanged:">
                                                        <string key="name">sdirChanged:</string>
                                                        <string key="candidateClassName">id</string>
                                                <string key="mouseSpeedSlider">NSSlider</string>
                                                <string key="radioButtons">NSMatrix</string>
                                                <string key="scrollDirSelect">NSSegmentedControl</string>
+                                               <string key="scrollSpeedSlider">NSSlider</string>
                                                <string key="title">NSTextField</string>
                                        </dictionary>
                                        <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
                                                        <string key="name">scrollDirSelect</string>
                                                        <string key="candidateClassName">NSSegmentedControl</string>
                                                </object>
+                                               <object class="IBToOneOutletInfo" key="scrollSpeedSlider">
+                                                       <string key="name">scrollSpeedSlider</string>
+                                                       <string key="candidateClassName">NSSlider</string>
+                                               </object>
                                                <object class="IBToOneOutletInfo" key="title">
                                                        <string key="name">title</string>
                                                        <string key="candidateClassName">NSTextField</string>
index de8b4171fe687338a4ecc04e992d217e1f242643..f8052e786c3d628af0ffa5b646fe2934ad307f19 100644 (file)
@@ -20,6 +20,7 @@
     IBOutlet NSSlider *mouseSpeedSlider;
     IBOutlet NSSegmentedControl *mouseBtnSelect;
     IBOutlet NSSegmentedControl *scrollDirSelect;
+    IBOutlet NSSlider *scrollSpeedSlider;
     IBOutlet NSTextField *title;
     IBOutlet NSPopUpButton *mappingPopup;
     IBOutlet NJMappingsController *mappingsController;
@@ -34,6 +35,7 @@
 - (IBAction)mbtnChanged:(id)sender;
 - (IBAction)sdirChanged:(id)sender;
 - (IBAction)mouseSpeedChanged:(id)sender;
+- (IBAction)scrollSpeedChanged:(id)sender;
 
 - (void)focusKey;
 
index e60a83e742fda18539db22973520302cff303aae..f3eca24b79c50a6857e45e0f60214bf8a5b10196 100644 (file)
     
     if (row != 5) {
         scrollDirSelect.selectedSegment = -1;
+        scrollSpeedSlider.floatValue = scrollSpeedSlider.minValue;
         [scrollDirSelect resignIfFirstResponder];
-    } else if (scrollDirSelect.selectedSegment == -1)
-        scrollDirSelect.selectedSegment = 0;    
+    } else {
+        if (scrollDirSelect.selectedSegment == -1)
+            scrollDirSelect.selectedSegment = 0;
+        if (scrollDirSelect.selectedSegment < 2
+            && !scrollSpeedSlider.floatValue)
+            scrollSpeedSlider.floatValue = 15.f;
+        else if (scrollDirSelect.selectedSegment >= 2
+                 && scrollSpeedSlider.floatValue)
+            scrollSpeedSlider.floatValue = scrollSpeedSlider.minValue;
+    }
+        
 }
 
 - (IBAction)radioChanged:(NSView *)sender {
     [self commit];
 }
 
+- (void)scrollSpeedChanged:(NSSlider *)sender {
+    [radioButtons selectCellAtRow:5 column:0];
+    [sender.window makeFirstResponder:sender];
+    if (!sender.floatValue && scrollDirSelect.selectedSegment < 2)
+        scrollDirSelect.selectedSegment += 2;
+    else if (sender.floatValue && scrollDirSelect.selectedSegment >= 2)
+        scrollDirSelect.selectedSegment -= 2;
+    [self commit];
+}
+
 - (NJOutput *)currentOutput {
     return mappingsController.currentMapping[inputController.selectedInput];
 }
         }
         case 5: {
             NJOutputMouseScroll *ms = [[NJOutputMouseScroll alloc] init];
-            ms.amount = scrollDirSelect.selectedSegment ? 1 : -1;
+            ms.direction = (scrollDirSelect.selectedSegment & 1) ? 1 : -1;
+            ms.speed = scrollDirSelect.selectedSegment < 2
+                ? scrollSpeedSlider.floatValue
+                : 0.f;
             return ms;
         }
         case 6: {
     }
     else if ([output isKindOfClass:NJOutputMouseScroll.class]) {
         [radioButtons selectCellAtRow:5 column:0];
-        scrollDirSelect.selectedSegment = [(NJOutputMouseScroll *)output amount] > 0;
+        int direction = [(NJOutputMouseScroll *)output direction];
+        float speed = [(NJOutputMouseScroll *)output speed];
+        scrollDirSelect.selectedSegment = (direction > 0) + !speed * 2;
+        scrollSpeedSlider.floatValue = speed;
     }
     else if ([output isKindOfClass:NJOutputSwitchMouseMode.class]) {
         [radioButtons selectCellAtRow:6 column:0];
index 6ef2cdcfcdb476b25eee1e216b59c8a96101b66c..dd0444a332975dee66b06c2066b87bfaf902eabd 100644 (file)
@@ -9,6 +9,7 @@
 
 @interface NJOutputMouseScroll : NJOutput
 
-@property (nonatomic, assign) int amount;
+@property (nonatomic, assign) int direction;
+@property (nonatomic, assign) float speed;
 
 @end
index 4aa614db0aa3cfe75e8ed1c3ef3337ac6174b287..7bbf4f80c37973f2add69a609932fc2b8f1ebeea 100644 (file)
@@ -7,51 +7,47 @@
 
 #import "NJOutputMouseScroll.h"
 
-@implementation NJOutputMouseScroll {
-    int sign;
-}
+@implementation NJOutputMouseScroll
 
 + (NSString *)serializationCode {
     return @"mouse scroll";
 }
 
 - (NSDictionary *)serialize {
-    return @{ @"type": self.class.serializationCode, @"amount": @(_amount) };
+    return @{ @"type": self.class.serializationCode,
+              @"direction": @(_direction),
+              @"speed": @(_speed)
+              };
 }
 
 + (NJOutput *)outputDeserialize:(NSDictionary *)serialization
                   withMappings:(NSArray *)mappings {
        NJOutputMouseScroll *output = [[NJOutputMouseScroll alloc] init];
-    output.amount = [serialization[@"amount"] intValue];
+    output.direction = [serialization[@"direction"] intValue];
+    output.speed = [serialization[@"direction"] floatValue];
        return output;
 }
 
+- (BOOL)isContinuous {
+    return !!self.speed;
+}
+
 - (void)trigger {
-    if (!self.magnitude) {
+    if (!self.speed) {
         CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
                                                           kCGScrollEventUnitLine,
                                                           1,
-                                                          _amount);
+                                                          _direction);
         CGEventPost(kCGHIDEventTap, scroll);
         CFRelease(scroll);
     }
 }
 
 - (BOOL)update:(NJDeviceController *)jc {
-    if (fabsf(self.magnitude) < 0.01f) {
-        sign = 0;
+    if (self.magnitude < 0.05f)
         return NO; // dead zone
-    }
     
-    // If the input crossed over High/Low, this output is done.
-    if (!sign)
-        sign = self.magnitude < 0 ? -1 : 1;
-    else if (sign / self.magnitude < 0) {
-        sign = 0;
-        return NO;
-    }
-
-    int amount = (int)(16.f * fabsf(self.magnitude) * _amount);
+    int amount = (int)(_speed * self.magnitude * _direction);
     CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
                                                       kCGScrollEventUnitPixel,
                                                       1,
@@ -62,8 +58,4 @@
     return YES;
 }
 
-- (BOOL)isContinuous {
-    return YES;
-}
-
 @end