Mouse improvements. Segment and snap the mouse move and scroll speed for easier match...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Sat, 9 Mar 2013 14:02:25 +0000 (15:02 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Sat, 9 Mar 2013 14:02:25 +0000 (15:02 +0100)
Classes/NJOutputController.m
Classes/NJOutputMouseButton.h
Classes/NJOutputMouseButton.m
Classes/NJOutputMouseMove.m
Classes/NJOutputMouseScroll.m
Info.plist
Resources/English.lproj/MainMenu.xib

index bcafe0d3a96f207feb1b5207a636ed0593db8863..ebedb1b7239cc288905c20a3b3b791b710fd750f 100644 (file)
@@ -59,7 +59,7 @@
         if (mouseDirSelect.selectedSegment == -1)
             mouseDirSelect.selectedSegment = 0;
         if (!mouseSpeedSlider.floatValue)
-            mouseSpeedSlider.floatValue = 4;
+            mouseSpeedSlider.floatValue = 10;
     }
     
     if (row != 4) {
@@ -77,7 +77,7 @@
             scrollDirSelect.selectedSegment = 0;
         if (scrollDirSelect.selectedSegment < 2
             && !scrollSpeedSlider.floatValue)
-            scrollSpeedSlider.floatValue = 15.f;
+            scrollSpeedSlider.floatValue = 15;
         else if (scrollDirSelect.selectedSegment >= 2
                  && scrollSpeedSlider.floatValue)
             scrollSpeedSlider.floatValue = scrollSpeedSlider.minValue;
 
 - (void)sdirChanged:(NSView *)sender {
     [radioButtons selectCellAtRow:5 column:0];
+    if (scrollDirSelect.selectedSegment >= 2)
+        scrollSpeedSlider.floatValue = 0;
     [sender.window makeFirstResponder:sender];
     [self commit];
 }
         }
         case 4: {
             NJOutputMouseButton *mb = [[NJOutputMouseButton alloc] init];
-            mb.button = mouseBtnSelect.selectedSegment == 0 ? kCGMouseButtonLeft : kCGMouseButtonRight;
+            mb.humanIndexedButton = mouseBtnSelect.selectedSegment;
             return mb;
         }
         case 5: {
     }
     else if ([output isKindOfClass:NJOutputMouseButton.class]) {
         [radioButtons selectCellAtRow:4 column:0];
-        mouseBtnSelect.selectedSegment = [(NJOutputMouseButton *)output button] == kCGMouseButtonLeft ? 0 : 1;
+        mouseBtnSelect.selectedSegment = [(NJOutputMouseButton *)output humanIndexedButton];
     }
     else if ([output isKindOfClass:NJOutputMouseScroll.class]) {
         [radioButtons selectCellAtRow:5 column:0];
index 4d790e51dd8726127d8a00bef8f48d3597519cdf..24d39b04039dacc6c9927ea6dce1d83faa4a7629 100644 (file)
@@ -10,5 +10,9 @@
 @interface NJOutputMouseButton : NJOutput
 
 @property (nonatomic, assign) CGMouseButton button;
+    // Indexed as left, right, center.
+
+@property (nonatomic, assign) int humanIndexedButton;
+    // Indexed as left, center, right.
 
 @end
index bc286bd35b4b82047acc5a2d764fd81184c24bb3..c9fe0eb13e64de6320b6713b0169ba89331889a9 100644 (file)
 - (void)trigger {
     CGFloat height = NSScreen.mainScreen.frame.size.height;
     NSPoint mouseLoc = NSEvent.mouseLocation;
-    CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown;
+    CGEventType eventType = _button == kCGMouseButtonLeft ? kCGEventLeftMouseDown
+                          : _button == kCGMouseButtonRight ? kCGEventRightMouseDown
+                          : kCGEventOtherMouseDown;
     CGEventRef click = CGEventCreateMouseEvent(NULL,
                                                eventType,
                                                CGPointMake(mouseLoc.x, height - mouseLoc.y),
                                                _button);
 
     if (clickCount >= 3 || [upTime compare:[NSDate date]] == NSOrderedAscending
-        || !CGPointEqualToPoint(NSEvent.mouseLocation, clickPosition))
+        || !CGPointEqualToPoint(mouseLoc, clickPosition))
         clickCount = 1;
     else
         ++clickCount;
     CGEventSetIntegerValueField(click, kCGMouseEventClickState, clickCount);
-    
     CGEventPost(kCGHIDEventTap, click);
     CFRelease(click);
+    clickPosition = mouseLoc;
 }
 
 - (void)untrigger {
     upTime = [NJOutputMouseButton dateWithClickInterval];
-    clickPosition = NSEvent.mouseLocation;
+    NSPoint mouseLoc = NSEvent.mouseLocation;
     CGFloat height = NSScreen.mainScreen.frame.size.height;
-    CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp;
+    CGEventType eventType = _button == kCGMouseButtonLeft ? kCGEventLeftMouseUp
+                          : _button == kCGMouseButtonRight ? kCGEventRightMouseUp
+                          : kCGEventOtherMouseUp;
     CGEventRef click = CGEventCreateMouseEvent(NULL,
                                                eventType,
-                                               CGPointMake(clickPosition.x, height - clickPosition.y),
+                                               CGPointMake(mouseLoc.x, height - mouseLoc.y),
                                                _button);
     CGEventSetIntegerValueField(click, kCGMouseEventClickState, clickCount);
     CGEventPost(kCGHIDEventTap, click);
     CFRelease(click);
 }
 
+- (int)humanIndexedButton {
+    switch (_button) {
+        case kCGMouseButtonLeft: return 0;
+        case kCGMouseButtonCenter: return 1;
+        case kCGMouseButtonRight: return 2;
+        default: return 0;
+    }
+}
+
+- (void)setHumanIndexedButton:(int)humanIndexedButton {
+    switch (humanIndexedButton) {
+        case 0: _button = kCGMouseButtonLeft; break;
+        case 1: _button = kCGMouseButtonCenter; break;
+        case 2: _button = kCGMouseButtonRight; break;
+        default: _button = kCGMouseButtonLeft;
+    }
+}
+
 @end
index 884a3d3cf8d358c53f9ead6a17d6b10870b03e50..be8b076cc99dce9e24a0ff85fae7889d486ddffa 100644 (file)
@@ -28,7 +28,7 @@
     output.axis = [serialization[@"axis"] intValue];
     output.speed = [serialization[@"speed"] floatValue];
     if (!output.speed)
-        output.speed = 4;
+        output.speed = 10;
     return output;
 }
 
     return YES;
 }
 
+#define CLAMP(a, l, h) MIN(h, MAX(a, l))
+
 - (BOOL)update:(NJDeviceController *)jc {
     if (self.magnitude < 0.05)
         return NO; // dead zone
     
-    CGFloat height = NSScreen.mainScreen.frame.size.height;
+    CGSize size = NSScreen.mainScreen.frame.size;
     
-    float dx = 0.f, dy = 0.f;
+    CGFloat dx = 0, dy = 0;
     switch (_axis) {
         case 0:
             dx = -self.magnitude * _speed;
             break;
     }
     NSPoint mouseLoc = jc.mouseLoc;
-    mouseLoc.x += dx;
-    mouseLoc.y -= dy;
+    mouseLoc.x = CLAMP(mouseLoc.x + dx, 0, size.width - 1);
+    mouseLoc.y = CLAMP(mouseLoc.y - dy, 0, size.height - 1);
     jc.mouseLoc = mouseLoc;
     
     CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
-                                              CGPointMake(mouseLoc.x, height - mouseLoc.y),
+                                              CGPointMake(mouseLoc.x, size.height - mouseLoc.y),
                                               0);
-    CGEventSetType(move, kCGEventMouseMoved);
     CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, (int)dx);
     CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, (int)dy);
     CGEventPost(kCGHIDEventTap, move);
+
+    if (CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonLeft)) {
+        CGEventSetType(move, kCGEventLeftMouseDragged);
+        CGEventSetIntegerValueField(move, kCGMouseEventButtonNumber, kCGMouseButtonLeft);
+        CGEventPost(kCGHIDEventTap, move);
+    }
+    if (CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonRight)) {
+        CGEventSetType(move, kCGEventRightMouseDragged);
+        CGEventSetIntegerValueField(move, kCGMouseEventButtonNumber, kCGMouseButtonRight);
+        CGEventPost(kCGHIDEventTap, move);
+    }
+    if (CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonCenter)) {
+        CGEventSetType(move, kCGEventOtherMouseDragged);
+        CGEventSetIntegerValueField(move, kCGMouseEventButtonNumber, kCGMouseButtonCenter);
+        CGEventPost(kCGHIDEventTap, move);
+    }
+
     CFRelease(move);
     return YES;
 }
index 812685f527de245846749a33bd9b42d5a37fb4b0..99cec4a2f7724972e3a056b9a3ed97bc0790068f 100644 (file)
@@ -24,7 +24,7 @@
                   withMappings:(NSArray *)mappings {
     NJOutputMouseScroll *output = [[NJOutputMouseScroll alloc] init];
     output.direction = [serialization[@"direction"] intValue];
-    output.speed = [serialization[@"direction"] floatValue];
+    output.speed = [serialization[@"speed"] floatValue];
     return output;
 }
 
index ad99f4a6f9b24b013b592c867f7d572b11e70860..b9ce686b9a1833bc35d10972b8b440838a1cdb93 100644 (file)
@@ -46,7 +46,7 @@
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
-       <string>16</string>
+       <string>63</string>
        <key>LSApplicationCategoryType</key>
        <string>public.app-category.utilities</string>
        <key>NSHumanReadableCopyright</key>
index 22b83f7ace1416b336322e596747e337ba9fde77..0c4cdf5f60024a22dbeeef41cd8fe72d5e5108b0 100644 (file)
@@ -676,58 +676,6 @@ aW5nLg</string>
                                                        <reference key="NSNextResponder" ref="177223957"/>
                                                        <int key="NSvFlags">285</int>
                                                        <array class="NSMutableArray" key="NSSubviews">
-                                                               <object class="NSSlider" id="792189805">
-                                                                       <reference key="NSNextResponder" ref="471332453"/>
-                                                                       <int key="NSvFlags">265</int>
-                                                                       <string key="NSFrame">{{191, 24}, {130, 12}}</string>
-                                                                       <reference key="NSSuperview" ref="471332453"/>
-                                                                       <reference key="NSWindow"/>
-                                                                       <reference key="NSNextKeyView"/>
-                                                                       <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="471332453"/>
-                                                                       <int key="NSvFlags">265</int>
-                                                                       <string key="NSFrame">{{191, 108}, {176, 12}}</string>
-                                                                       <reference key="NSSuperview" ref="471332453"/>
-                                                                       <reference key="NSWindow"/>
-                                                                       <reference key="NSNextKeyView" ref="125828224"/>
-                                                                       <string key="NSReuseIdentifierKey">_NS:9</string>
-                                                                       <bool key="NSEnabled">YES</bool>
-                                                                       <object class="NSSliderCell" key="NSCell" id="5417367">
-                                                                               <int key="NSCellFlags">-2080374784</int>
-                                                                               <int key="NSCellFlags2">262144</int>
-                                                                               <string key="NSContents"/>
-                                                                               <string key="NSCellIdentifier">_NS:9</string>
-                                                                               <reference key="NSControlView" ref="385416822"/>
-                                                                               <double key="NSMaxValue">20</double>
-                                                                               <double key="NSMinValue">0.0</double>
-                                                                               <double key="NSValue">4</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="NSSegmentedControl" id="875916470">
                                                                        <reference key="NSNextResponder" ref="471332453"/>
                                                                        <int key="NSvFlags">265</int>
@@ -747,7 +695,6 @@ aW5nLg</string>
                                                                                        <object class="NSSegmentItem">
                                                                                                <double key="NSSegmentItemWidth">44</double>
                                                                                                <string key="NSSegmentItemLabel">←</string>
-                                                                                               <bool key="NSSegmentItemSelected">YES</bool>
                                                                                                <int key="NSSegmentItemImageScaling">0</int>
                                                                                        </object>
                                                                                        <object class="NSSegmentItem">
@@ -791,7 +738,6 @@ aW5nLg</string>
                                                                                                <double key="NSSegmentItemWidth">64</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">
@@ -816,6 +762,32 @@ aW5nLg</string>
                                                                        </object>
                                                                        <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
                                                                </object>
+                                                               <object class="NSSlider" id="792189805">
+                                                                       <reference key="NSNextResponder" ref="471332453"/>
+                                                                       <int key="NSvFlags">265</int>
+                                                                       <string key="NSFrame">{{191, 24}, {130, 16}}</string>
+                                                                       <reference key="NSSuperview" ref="471332453"/>
+                                                                       <reference key="NSWindow"/>
+                                                                       <reference key="NSNextKeyView"/>
+                                                                       <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">11</int>
+                                                                               <int key="NSTickMarkPosition">1</int>
+                                                                               <bool key="NSAllowsTickMarkValuesOnly">YES</bool>
+                                                                               <bool key="NSVertical">NO</bool>
+                                                                       </object>
+                                                                       <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
+                                                               </object>
                                                                <object class="NSSegmentedControl" id="125828224">
                                                                        <reference key="NSNextResponder" ref="471332453"/>
                                                                        <int key="NSvFlags">265</int>
@@ -837,22 +809,51 @@ aW5nLg</string>
                                                                                <reference key="NSControlView" ref="125828224"/>
                                                                                <array class="NSMutableArray" key="NSSegmentImages">
                                                                                        <object class="NSSegmentItem">
-                                                                                               <double key="NSSegmentItemWidth">87</double>
+                                                                                               <double key="NSSegmentItemWidth">55</double>
                                                                                                <string key="NSSegmentItemLabel">Left</string>
-                                                                                               <bool key="NSSegmentItemSelected">YES</bool>
                                                                                                <int key="NSSegmentItemImageScaling">0</int>
                                                                                        </object>
                                                                                        <object class="NSSegmentItem">
-                                                                                               <double key="NSSegmentItemWidth">86</double>
-                                                                                               <string key="NSSegmentItemLabel">Right</string>
+                                                                                               <string key="NSSegmentItemLabel">Center</string>
                                                                                                <int key="NSSegmentItemTag">1</int>
                                                                                                <int key="NSSegmentItemImageScaling">0</int>
                                                                                        </object>
+                                                                                       <object class="NSSegmentItem">
+                                                                                               <double key="NSSegmentItemWidth">55</double>
+                                                                                               <string key="NSSegmentItemLabel">Right</string>
+                                                                                               <int key="NSSegmentItemImageScaling">0</int>
+                                                                                       </object>
                                                                                </array>
                                                                                <int key="NSSegmentStyle">1</int>
                                                                        </object>
                                                                        <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
                                                                </object>
+                                                               <object class="NSSlider" id="385416822">
+                                                                       <reference key="NSNextResponder" ref="471332453"/>
+                                                                       <int key="NSvFlags">265</int>
+                                                                       <string key="NSFrame">{{191, 108}, {176, 16}}</string>
+                                                                       <reference key="NSSuperview" ref="471332453"/>
+                                                                       <reference key="NSWindow"/>
+                                                                       <reference key="NSNextKeyView" ref="125828224"/>
+                                                                       <string key="NSReuseIdentifierKey">_NS:9</string>
+                                                                       <bool key="NSEnabled">YES</bool>
+                                                                       <object class="NSSliderCell" key="NSCell" id="5417367">
+                                                                               <int key="NSCellFlags">67108864</int>
+                                                                               <int key="NSCellFlags2">262144</int>
+                                                                               <string key="NSContents"/>
+                                                                               <string key="NSCellIdentifier">_NS:9</string>
+                                                                               <reference key="NSControlView" ref="385416822"/>
+                                                                               <double key="NSMaxValue">20</double>
+                                                                               <double key="NSMinValue">0.0</double>
+                                                                               <double key="NSValue">10</double>
+                                                                               <double key="NSAltIncValue">0.0</double>
+                                                                               <int key="NSNumberOfTickMarks">11</int>
+                                                                               <int key="NSTickMarkPosition">1</int>
+                                                                               <bool key="NSAllowsTickMarkValuesOnly">YES</bool>
+                                                                               <bool key="NSVertical">NO</bool>
+                                                                       </object>
+                                                                       <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
+                                                               </object>
                                                                <object class="NSCustomView" id="57697638">
                                                                        <reference key="NSNextResponder" ref="471332453"/>
                                                                        <int key="NSvFlags">265</int>
@@ -2846,13 +2847,13 @@ aW5nLg</string>
                                <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="1" key="745.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
+                               <integer value="2" key="745.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
                                <string key="745.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="749.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-                               <integer value="1" key="750.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
+                               <integer value="0" key="750.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
                                <string key="750.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="754.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-                               <integer value="1" key="755.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
+                               <integer value="0" key="755.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
                                <string key="755.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="778.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="81.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>