├── .gitignore ├── External ├── IOHIDEventData.h ├── IOHIDEventTypes.h ├── SaneSideButtons-Bridging-Header.h ├── TouchEvents.c └── TouchEvents.h ├── LICENSE ├── README.md ├── SaneSideButtons.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ ├── IDEWorkspaceChecks.plist │ └── swiftpm │ └── Package.resolved ├── SaneSideButtons ├── AppDelegate.swift ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ ├── 128@1x.png │ │ ├── 128@2x.png │ │ ├── 16@1x.png │ │ ├── 16@2x.png │ │ ├── 256@1x.png │ │ ├── 256@2x.png │ │ ├── 32@1x.png │ │ ├── 32@2x.png │ │ ├── 512@1x.png │ │ ├── 512@2x.png │ │ └── Contents.json │ ├── BackgroundColor.colorset │ │ └── Contents.json │ ├── Contents.json │ └── MenuIcon.imageset │ │ ├── Contents.json │ │ ├── MenuIcon@1x.png │ │ └── MenuIcon@2x.png ├── Licenses.txt ├── PermissionView.swift ├── SaneSideButtons.entitlements ├── SwipeSimulator.swift ├── en.lproj │ └── Localizable.strings ├── main.swift └── zh-Hans.lproj │ └── Localizable.strings └── icon.png /.gitignore: -------------------------------------------------------------------------------- 1 | xcuserdata/ 2 | **/.DS_Store -------------------------------------------------------------------------------- /External/IOHIDEventData.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * @APPLE_LICENSE_HEADER_START@ 4 | * 5 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. 6 | * 7 | * This file contains Original Code and/or Modifications of Original Code 8 | * as defined in and that are subject to the Apple Public Source License 9 | * Version 2.0 (the 'License'). You may not use this file except in 10 | * compliance with the License. Please obtain a copy of the License at 11 | * http://www.opensource.apple.com/apsl/ and read it before using this 12 | * file. 13 | * 14 | * The Original Code and all software distributed under the License are 15 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 19 | * Please see the License for the specific language governing rights and 20 | * limitations under the License. 21 | * 22 | * @APPLE_LICENSE_HEADER_END@ 23 | */ 24 | 25 | #include "IOHIDEventTypes.h" 26 | 27 | #define IOHIDEVENT_BASE \ 28 | uint32_t size; \ 29 | IOHIDEventType type; \ 30 | uint64_t timestamp; \ 31 | uint32_t options; 32 | 33 | #define IOHIDAXISEVENT_BASE \ 34 | struct { \ 35 | IOFixed x; \ 36 | IOFixed y; \ 37 | IOFixed z; \ 38 | } position; 39 | 40 | // NOTE: original Apple source had "struct IOHIDEventData" instead of typedef 41 | typedef struct _IOHIDEventData { 42 | IOHIDEVENT_BASE; 43 | } IOHIDEventData; 44 | 45 | typedef struct _IOHIDVendorDefinedEventData { 46 | IOHIDEVENT_BASE; 47 | uint16_t usagePage; 48 | uint16_t usage; 49 | uint32_t version; 50 | uint32_t length; 51 | uint8_t data[0]; 52 | } IOHIDVendorDefinedEventData; 53 | 54 | // NOTE: these are additional option flags used with digitizer event 55 | enum { 56 | kIOHIDTransducerRange = 0x00010000, 57 | kIOHIDTransducerTouch = 0x00020000, 58 | kIOHIDTransducerInvert = 0x00040000, 59 | }; 60 | 61 | enum { 62 | kIOHIDDigitizerOrientationTypeTilt = 0, 63 | kIOHIDDigitizerOrientationTypePolar, 64 | kIOHIDDigitizerOrientationTypeQuality 65 | }; 66 | typedef uint8_t IOHIDDigitizerOrientationType; 67 | 68 | #define IOHIDBUTTONEVENT_BASE \ 69 | struct { \ 70 | uint32_t buttonMask; \ 71 | IOFixed pressure; \ 72 | uint8_t buttonNumber; \ 73 | uint8_t clickState; \ 74 | } button; 75 | 76 | typedef struct _IOHIDButtonEventData { 77 | IOHIDEVENT_BASE; 78 | IOHIDBUTTONEVENT_BASE; 79 | } IOHIDButtonEventData; 80 | 81 | typedef struct _IOHIDMouseEventData { 82 | IOHIDEVENT_BASE; 83 | IOHIDAXISEVENT_BASE; 84 | IOHIDBUTTONEVENT_BASE; 85 | } IOHIDMouseEventData; 86 | 87 | typedef struct _IOHIDDigitizerEventData { 88 | IOHIDEVENT_BASE; // options = kIOHIDTransducerRange, kHIDTransducerTouch, kHIDTransducerInvert 89 | IOHIDAXISEVENT_BASE; 90 | 91 | uint32_t transducerIndex; 92 | uint32_t transducerType; // could overload this to include that both the hand and finger id. 93 | uint32_t identity; // Specifies a unique ID of the current transducer action. 94 | uint32_t eventMask; // the type of event that has occurred: range, touch, position (IOHIDDigitizerEventMask?) 95 | uint32_t childEventMask; // CHILD: the type of event that has occurred: range, touch, position 96 | 97 | uint32_t buttonMask; // Bit field representing the current button state 98 | // Pressure field are assumed to be scaled from 0.0 to 1.0 99 | IOFixed tipPressure; // Force exerted against the digitizer surface by the transducer. 100 | IOFixed barrelPressure; // Force exerted directly by the user on a transducer sensor. 101 | 102 | IOFixed twist; // Specifies the clockwise rotation of the cursor around its own major axis. Unsure it the device should declare units via properties or event. My first inclination is force degrees as the is the unit already expected by AppKit, Carbon and OpenGL. 103 | uint32_t orientationType; // Specifies the orientation type used by the transducer. 104 | union { 105 | struct { // X Tilt and Y Tilt are used together to specify the tilt away from normal of a digitizer transducer. In its normal position, the values of X Tilt and Y Tilt for a transducer are both zero. 106 | IOFixed x; // This quantity is used in conjunction with Y Tilt to represent the tilt away from normal of a transducer, such as a stylus. The X Tilt value represents the plane angle between the Y-Z plane and the plane containing the transducer axis and the Y axis. A positive X Tilt is to the right. 107 | IOFixed y; // This value represents the angle between the X-Z and transducer-X planes. A positive Y Tilt is toward the user. 108 | } tilt; 109 | struct { // X Tilt and Y Tilt are used together to specify the tilt away from normal of a digitizer transducer. In its normal position, the values of X Tilt and Y Tilt for a transducer are both zero. 110 | IOFixed altitude; //The angle with the X-Y plane though a signed, semicicular range. Positive values specify an angle downward and toward the positive Z axis. 111 | IOFixed azimuth; // Specifies the counter clockwise rotation of the cursor around the Z axis though a full circular range. 112 | } polar; 113 | struct { 114 | IOFixed quality; // If set, indicates that the transducer is sensed to be in a relatively noise-free region of digitizing. 115 | IOFixed density; 116 | IOFixed irregularity; 117 | IOFixed majorRadius; // units in mm 118 | IOFixed minorRadius; // units in mm 119 | } quality; 120 | } orientation; 121 | } IOHIDDigitizerEventData; 122 | 123 | typedef struct _IOHIDAxisEventData { 124 | IOHIDEVENT_BASE; // options = kHIDAxisRelative 125 | IOHIDAXISEVENT_BASE; 126 | } IOHIDAxisEventData, IOHIDTranslationData, IOHIDRotationEventData, IOHIDScrollEventData, IOHIDScaleEventData, IOHIDVelocityData, IOHIDOrientationEventData; 127 | 128 | typedef struct _IOHIDSwipeEventData { 129 | IOHIDEVENT_BASE; 130 | IOHIDSwipeMask swipeMask; 131 | } IOHIDSwipeEventData; 132 | 133 | /*! 134 | @typedef IOHIDSystemQueueElement 135 | @abstract Memory structure defining the layout of each event queue element 136 | @discussion The IOHIDEventQueueElement represents a portion of mememory in the 137 | new IOHIDEventQueue. It is possible that a event queue element 138 | can contain multiple interpretations of a given event. The first 139 | event is always considered the primary event. 140 | @field version Version of the event queue element 141 | @field size Size, in bytes, of this particular event queue element 142 | @field timeStamp Time at which event was dispatched 143 | @field deviceID ID of the sending device 144 | @field options Options for further developement 145 | @field eventCount The number of events contained in this transaction 146 | @field events Begining offset of contiguous mememory that contains the 147 | pertinent event data 148 | */ 149 | typedef struct _IOHIDSystemQueueElement { 150 | uint64_t timeStamp; 151 | uint64_t deviceID; 152 | uint32_t options; 153 | uint32_t eventCount; 154 | IOHIDEventData events[]; 155 | } IOHIDSystemQueueElement; 156 | -------------------------------------------------------------------------------- /External/IOHIDEventTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * @APPLE_LICENSE_HEADER_START@ 4 | * 5 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. 6 | * 7 | * This file contains Original Code and/or Modifications of Original Code 8 | * as defined in and that are subject to the Apple Public Source License 9 | * Version 2.0 (the 'License'). You may not use this file except in 10 | * compliance with the License. Please obtain a copy of the License at 11 | * http://www.opensource.apple.com/apsl/ and read it before using this 12 | * file. 13 | * 14 | * The Original Code and all software distributed under the License are 15 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 19 | * Please see the License for the specific language governing rights and 20 | * limitations under the License. 21 | * 22 | * @APPLE_LICENSE_HEADER_END@ 23 | */ 24 | 25 | #ifndef _IOKIT_HID_IOHIDEVENTTYPES_H 26 | #define _IOKIT_HID_IOHIDEVENTTYPES_H 27 | 28 | #include 29 | 30 | #define IOHIDEventTypeMask(type) (1< 168 | Please Note: 169 | If you append a child digitizer event to a parent digitizer event, appropriate state will be transfered on to the parent. 170 | @constant kIOHIDDigitizerEventRange Issued when the range state has changed. 171 | @constant kIOHIDDigitizerEventTouch Issued when the touch state has changed. 172 | @constant kIOHIDDigitizerEventPosition Issued when the position has changed. 173 | @constant kIOHIDDigitizerEventStop Issued when motion has achieved a state of calculated non-movement. 174 | @constant kIOHIDDigitizerEventPeak Issues when new maximum values have been detected. 175 | @constant kIOHIDDigitizerEventIdentity Issued when the identity has changed. 176 | @constant kIOHIDDigitizerEventAttribute Issued when an attribute has changed. 177 | @constant kIOHIDDigitizerEventUpSwipe Issued when an up swipe has been detected. 178 | @constant kIOHIDDigitizerEventDownSwipe Issued when an down swipe has been detected. 179 | @constant kIOHIDDigitizerEventLeftSwipe Issued when an left swipe has been detected. 180 | @constant kIOHIDDigitizerEventRightSwipe Issued when an right swipe has been detected. 181 | @constant kIOHIDDigitizerEventSwipeMask Mask used to gather swipe events. 182 | */ 183 | enum { 184 | kIOHIDDigitizerEventRange = 0x00000001, 185 | kIOHIDDigitizerEventTouch = 0x00000002, 186 | kIOHIDDigitizerEventPosition = 0x00000004, 187 | kIOHIDDigitizerEventStop = 0x00000008, 188 | kIOHIDDigitizerEventPeak = 0x00000010, 189 | kIOHIDDigitizerEventIdentity = 0x00000020, 190 | kIOHIDDigitizerEventAttribute = 0x00000040, 191 | kIOHIDDigitizerEventCancel = 0x00000080, 192 | kIOHIDDigitizerEventStart = 0x00000100, 193 | kIOHIDDigitizerEventResting = 0x00000200, 194 | kIOHIDDigitizerEventSwipeUp = 0x01000000, 195 | kIOHIDDigitizerEventSwipeDown = 0x02000000, 196 | kIOHIDDigitizerEventSwipeLeft = 0x04000000, 197 | kIOHIDDigitizerEventSwipeRight = 0x08000000, 198 | kIOHIDDigitizerEventSwipeMask = 0xFF000000, 199 | }; 200 | typedef uint32_t IOHIDDigitizerEventMask; 201 | 202 | enum { 203 | kIOHIDEventOptionIsAbsolute = 0x00000001, 204 | kIOHIDEventOptionIsCollection = 0x00000002, 205 | kIOHIDEventOptionPixelUnits = 0x00000004 206 | }; 207 | typedef uint32_t IOHIDEventOptionBits; 208 | 209 | #endif /* _IOKIT_HID_IOHIDEVENTTYPES_H */ 210 | -------------------------------------------------------------------------------- /External/SaneSideButtons-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | 5 | #include "TouchEvents.h" 6 | -------------------------------------------------------------------------------- /External/TouchEvents.c: -------------------------------------------------------------------------------- 1 | /* 2 | * TouchEvents.c 3 | * TouchSynthesis 4 | * 5 | * Created by Nathan Vander Wilt on 1/13/10. 6 | * Copyright 2010 Calf Trail Software, LLC. All rights reserved. 7 | * 8 | */ 9 | 10 | #include 11 | #include "TouchEvents.h" 12 | #include "IOHIDEventData.h" 13 | 14 | const CFStringRef kTLInfoKeyDeviceID = CFSTR("deviceID"); 15 | const CFStringRef kTLInfoKeyTimestamp = CFSTR("timestamp"); 16 | const CFStringRef kTLInfoKeyGestureSubtype = CFSTR("gestureSubtype"); 17 | const CFStringRef kTLInfoKeyGesturePhase = CFSTR("gesturePhase"); 18 | const CFStringRef kTLInfoKeyMagnification = CFSTR("magnification"); 19 | const CFStringRef kTLInfoKeyRotation = CFSTR("rotation"); 20 | const CFStringRef kTLInfoKeySwipeDirection = CFSTR("swipeDirection"); 21 | const CFStringRef kTLInfoKeyNextSubtype = CFSTR("nextSubtype"); 22 | 23 | const CFStringRef kTLEventKeyType = CFSTR("type"); 24 | const CFStringRef kTLEventKeyTimestamp = CFSTR("timestamp"); 25 | const CFStringRef kTLEventKeyOptions = CFSTR("options"); 26 | 27 | const CFStringRef kTLEventKeyPositionX = CFSTR("position.x"); 28 | const CFStringRef kTLEventKeyPositionY = CFSTR("position.y"); 29 | const CFStringRef kTLEventKeyPositionZ = CFSTR("position.z"); 30 | 31 | const CFStringRef kTLEventKeyTransducerIndex = CFSTR("transducerIndex"); 32 | const CFStringRef kTLEventKeyTransducerType = CFSTR("transducerType"); 33 | const CFStringRef kTLEventKeyIdentity = CFSTR("identity"); 34 | const CFStringRef kTLEventKeyEventMask = CFSTR("eventMask"); 35 | 36 | const CFStringRef kTLEventKeyButtonMask = CFSTR("buttonMask"); 37 | const CFStringRef kTLEventKeyTipPressure = CFSTR("tipPressure"); 38 | const CFStringRef kTLEventKeyBarrelPressure = CFSTR("barrelPressure"); 39 | const CFStringRef kTLEventKeyTwist = CFSTR("twist"); 40 | 41 | const CFStringRef kTLEventKeyQuality = CFSTR("quality"); 42 | const CFStringRef kTLEventKeyDensity = CFSTR("density"); 43 | const CFStringRef kTLEventKeyIrregularity = CFSTR("irregularity"); 44 | const CFStringRef kTLEventKeyMajorRadius = CFSTR("majorRadius"); 45 | const CFStringRef kTLEventKeyMinorRadius = CFSTR("minorRadius"); 46 | 47 | static inline IOFixed tl_float2fixed(double f) { return (IOFixed)(f * 65536.0); } 48 | 49 | static inline void setVendorData(IOHIDVendorDefinedEventData* vd, const void* data) { 50 | memmove(vd->data, data, vd->length); 51 | } 52 | 53 | static void appendHeader(CFMutableDataRef data, uint8_t field, uint8_t type, uint16_t count) { 54 | // serialize header 55 | uint16_t swappedCount = CFSwapInt16HostToBig(count); 56 | CFDataAppendBytes(data, (UInt8*)&swappedCount, sizeof(uint16_t)); 57 | CFDataAppendBytes(data, &type, 1); 58 | CFDataAppendBytes(data, &field, 1); 59 | } 60 | 61 | static void appendField(CFMutableDataRef data, uint8_t field, uint8_t type, uint16_t count, void* fieldData) { 62 | appendHeader(data, field, type, count); 63 | switch (type) { 64 | case 0x00: // uint64_t as UnsignedWide 65 | for (uint16_t i = 0; i < count; ++i) { 66 | uint64_t val = ((uint64_t*)fieldData)[i]; 67 | uint32_t loVal = (uint32_t)val; 68 | uint32_t swappedLoVal = CFSwapInt32HostToBig(loVal); 69 | CFDataAppendBytes(data, (UInt8*)&swappedLoVal, sizeof(uint32_t)); 70 | uint32_t hiVal = (uint32_t)(val >> 32); 71 | uint32_t swappedHiVal = CFSwapInt32HostToBig(hiVal); 72 | CFDataAppendBytes(data, (UInt8*)&swappedHiVal, sizeof(uint32_t)); 73 | } 74 | break; 75 | case 0x10: // uint8_t 76 | for (uint16_t i = 0; i < count; ++i) { 77 | uint8_t val = ((uint8_t*)fieldData)[i]; 78 | CFDataAppendBytes(data, &val, 1); 79 | } 80 | break; 81 | case 0x40: 82 | for (uint16_t i = 0; i < count; ++i) { 83 | uint32_t val = ((uint32_t*)fieldData)[i]; 84 | uint32_t swappedVal = CFSwapInt32HostToBig(val); 85 | CFDataAppendBytes(data, (UInt8*)&swappedVal, sizeof(uint32_t)); 86 | } 87 | break; 88 | case 0xC0: 89 | for (uint16_t i = 0; i < count; ++i) { 90 | Float32 val = ((Float32*)fieldData)[i]; 91 | CFSwappedFloat32 swappedVal = CFConvertFloat32HostToSwapped(val); 92 | CFDataAppendBytes(data, (UInt8*)&swappedVal, sizeof(CFSwappedFloat32)); 93 | } 94 | break; 95 | } 96 | } 97 | 98 | static void appendIntegerField(CFMutableDataRef data, uint8_t field, uint32_t value) { 99 | (void)appendField; 100 | appendHeader(data, field, 0x40, 1); 101 | uint32_t swappedValue = CFSwapInt32HostToBig(value); 102 | CFDataAppendBytes(data, (UInt8*)&swappedValue, sizeof(uint32_t)); 103 | } 104 | 105 | static void appendFloatField(CFMutableDataRef data, uint8_t field, Float32 value) { 106 | appendHeader(data, field, 0xC0, 1); 107 | CFSwappedFloat32 swappedValue = CFConvertFloat32HostToSwapped(value); 108 | CFDataAppendBytes(data, (UInt8*)&swappedValue, sizeof(CFSwappedFloat32)); 109 | } 110 | 111 | static void fillOutBase(CFDictionaryRef info, IOHIDEventData* event) { 112 | CFNumberRef val; 113 | if ((val = CFDictionaryGetValue(info, kTLEventKeyTimestamp))) { 114 | CFNumberGetValue(val, kCFNumberSInt64Type, &event->timestamp); 115 | } 116 | if ((val = CFDictionaryGetValue(info, kTLEventKeyOptions))) { 117 | CFNumberGetValue(val, kCFNumberSInt32Type, &event->options); 118 | } 119 | } 120 | 121 | static void fillOutDigitizer(CFDictionaryRef info, IOHIDDigitizerEventData* event) { 122 | event->size = (uint32_t)sizeof(IOHIDDigitizerEventData); 123 | event->type = kIOHIDEventTypeDigitizer; 124 | CFNumberRef val; 125 | double d; 126 | if ((val = CFDictionaryGetValue(info, kTLEventKeyPositionX))) { 127 | CFNumberGetValue(val, kCFNumberDoubleType, &d); 128 | event->position.x = tl_float2fixed(d); 129 | } 130 | if ((val = CFDictionaryGetValue(info, kTLEventKeyPositionY))) { 131 | CFNumberGetValue(val, kCFNumberDoubleType, &d); 132 | event->position.y = tl_float2fixed(d); 133 | } 134 | if ((val = CFDictionaryGetValue(info, kTLEventKeyPositionZ))) { 135 | CFNumberGetValue(val, kCFNumberDoubleType, &d); 136 | event->position.z = tl_float2fixed(d); 137 | } 138 | 139 | if ((val = CFDictionaryGetValue(info, kTLEventKeyTransducerIndex))) { 140 | CFNumberGetValue(val, kCFNumberSInt32Type, &event->transducerIndex); 141 | } 142 | if ((val = CFDictionaryGetValue(info, kTLEventKeyTransducerType))) { 143 | CFNumberGetValue(val, kCFNumberSInt32Type, &event->transducerType); 144 | } 145 | if ((val = CFDictionaryGetValue(info, kTLEventKeyIdentity))) { 146 | CFNumberGetValue(val, kCFNumberSInt32Type, &event->identity); 147 | } 148 | if ((val = CFDictionaryGetValue(info, kTLEventKeyEventMask))) { 149 | CFNumberGetValue(val, kCFNumberSInt32Type, &event->eventMask); 150 | } 151 | 152 | if ((val = CFDictionaryGetValue(info, kTLEventKeyButtonMask))) { 153 | CFNumberGetValue(val, kCFNumberSInt32Type, &event->buttonMask); 154 | } 155 | if ((val = CFDictionaryGetValue(info, kTLEventKeyTipPressure))) { 156 | CFNumberGetValue(val, kCFNumberDoubleType, &d); 157 | event->tipPressure = tl_float2fixed(d); 158 | } 159 | if ((val = CFDictionaryGetValue(info, kTLEventKeyBarrelPressure))) { 160 | CFNumberGetValue(val, kCFNumberDoubleType, &d); 161 | event->barrelPressure = tl_float2fixed(d); 162 | } 163 | if ((val = CFDictionaryGetValue(info, kTLEventKeyTwist))) { 164 | CFNumberGetValue(val, kCFNumberDoubleType, &d); 165 | event->twist = tl_float2fixed(d); 166 | } 167 | 168 | event->orientationType = kIOHIDDigitizerOrientationTypeQuality; 169 | if ((val = CFDictionaryGetValue(info, kTLEventKeyQuality))) { 170 | CFNumberGetValue(val, kCFNumberDoubleType, &d); 171 | event->orientation.quality.quality = tl_float2fixed(d); 172 | } 173 | if ((val = CFDictionaryGetValue(info, kTLEventKeyDensity))) { 174 | CFNumberGetValue(val, kCFNumberDoubleType, &d); 175 | event->orientation.quality.density = tl_float2fixed(d); 176 | } 177 | if ((val = CFDictionaryGetValue(info, kTLEventKeyIrregularity))) { 178 | CFNumberGetValue(val, kCFNumberDoubleType, &d); 179 | event->orientation.quality.irregularity = tl_float2fixed(d); 180 | } 181 | if ((val = CFDictionaryGetValue(info, kTLEventKeyMajorRadius))) { 182 | CFNumberGetValue(val, kCFNumberDoubleType, &d); 183 | event->orientation.quality.majorRadius = tl_float2fixed(d); 184 | } 185 | if ((val = CFDictionaryGetValue(info, kTLEventKeyMinorRadius))) { 186 | CFNumberGetValue(val, kCFNumberDoubleType, &d); 187 | event->orientation.quality.minorRadius = tl_float2fixed(d); 188 | } 189 | } 190 | 191 | CGEventRef tl_CGEventCreateFromGesture(CFDictionaryRef info, CFArrayRef touches) { 192 | assert(info != NULL); 193 | assert(touches != NULL); 194 | typedef struct { 195 | uint32_t count; 196 | SInt64 sumX; 197 | SInt64 sumY; 198 | SInt64 sumZ; 199 | } AvgPosition; 200 | AvgPosition avgTouch = {}; 201 | AvgPosition avgRange = {}; 202 | AvgPosition avgOther = {}; 203 | CFNumberRef val; 204 | 205 | uint64_t timestamp; 206 | val = CFDictionaryGetValue(info, kTLInfoKeyTimestamp); 207 | if (val) { 208 | CFNumberGetValue(val, kCFNumberSInt64Type, ×tamp); 209 | } 210 | else { 211 | timestamp = mach_absolute_time(); 212 | } 213 | 214 | IOHIDDigitizerEventData parent = {}; 215 | parent.size = (uint32_t)sizeof(IOHIDDigitizerEventData); 216 | parent.type = kIOHIDEventTypeDigitizer; 217 | parent.timestamp = timestamp; 218 | parent.options = kIOHIDEventOptionIsCollection; 219 | parent.transducerType = kIOHIDDigitizerTransducerTypeHand; 220 | 221 | CFMutableDataRef serializedTouches = CFDataCreateMutable(kCFAllocatorDefault, 0); 222 | CFIndex numTouches = CFArrayGetCount(touches); 223 | for (CFIndex touchIdx = 0; touchIdx < numTouches; ++touchIdx) { 224 | CFDictionaryRef touchInfo = CFArrayGetValueAtIndex(touches, touchIdx); 225 | CFNumberRef typeVal = CFDictionaryGetValue(touchInfo, kTLEventKeyType); 226 | if (!typeVal) continue; 227 | 228 | int32_t type; 229 | CFNumberGetValue(typeVal, kCFNumberSInt32Type, &type); 230 | assert(type == kIOHIDEventTypeDigitizer); // only digitizer events currently supported 231 | 232 | IOHIDDigitizerEventData touch = {}; 233 | fillOutBase(touchInfo, (IOHIDEventData*)&touch); 234 | fillOutDigitizer(touchInfo, &touch); 235 | CFDataAppendBytes(serializedTouches, (UInt8*)&touch, touch.size); 236 | 237 | if (touch.identity) parent.options |= touch.options; 238 | parent.childEventMask |= touch.eventMask; 239 | if (touch.options & kIOHIDTransducerTouch) { 240 | ++avgTouch.count; 241 | avgTouch.sumX += touch.position.x; 242 | avgTouch.sumY += touch.position.y; 243 | avgTouch.sumZ += touch.position.z; 244 | } 245 | else if (touch.options & kIOHIDTransducerRange) { 246 | ++avgRange.count; 247 | avgRange.sumX += touch.position.x; 248 | avgRange.sumY += touch.position.y; 249 | avgRange.sumZ += touch.position.z; 250 | } 251 | else { 252 | ++avgOther.count; 253 | avgOther.sumX += touch.position.x; 254 | avgOther.sumY += touch.position.y; 255 | avgOther.sumZ += touch.position.z; 256 | } 257 | } 258 | 259 | // calculate parent position 260 | if (avgTouch.count) { 261 | parent.position.x = (IOFixed)(avgTouch.sumX / avgTouch.count); 262 | parent.position.y = (IOFixed)(avgTouch.sumY / avgTouch.count); 263 | parent.position.z = (IOFixed)(avgTouch.sumZ / avgTouch.count); 264 | } 265 | else if (avgRange.count) { 266 | parent.position.x = (IOFixed)(avgRange.sumX / avgRange.count); 267 | parent.position.y = (IOFixed)(avgRange.sumY / avgRange.count); 268 | parent.position.z = (IOFixed)(avgRange.sumZ / avgRange.count); 269 | } 270 | else if (avgOther.count) { 271 | parent.position.x = (IOFixed)(avgOther.sumX / avgOther.count); 272 | parent.position.y = (IOFixed)(avgOther.sumY / avgOther.count); 273 | parent.position.z = (IOFixed)(avgOther.sumZ / avgOther.count); 274 | } 275 | 276 | // create vendor token 277 | uint64_t deviceID = 0; 278 | val = CFDictionaryGetValue(info, kTLInfoKeyDeviceID); 279 | if (val) { 280 | CFNumberGetValue(val, kCFNumberSInt64Type, &deviceID); 281 | } 282 | UInt8 vendorPayload[40] = {}; 283 | *(uint64_t*)vendorPayload = CFSwapInt64HostToLittle(deviceID); 284 | const size_t vendorPayloadLen = sizeof(vendorPayload); 285 | const size_t vendorDataSize = sizeof(IOHIDVendorDefinedEventData) + vendorPayloadLen; 286 | IOHIDVendorDefinedEventData* vendorData = malloc(vendorDataSize); 287 | vendorData->size = (uint32_t)vendorDataSize; 288 | vendorData->type = kIOHIDEventTypeVendorDefined; 289 | vendorData->usagePage = 0xFF00; 290 | vendorData->usage = 0x1777; 291 | vendorData->version = 1; 292 | vendorData->length = (uint32_t)vendorPayloadLen; 293 | setVendorData(vendorData, vendorPayload); 294 | 295 | // create base event 296 | CGEventRef protoEvent = CGEventCreate(NULL); 297 | CGEventSetType(protoEvent, 29); // NSEventTypeGesture 298 | CGEventSetFlags(protoEvent, 256); // magic 299 | CGEventSetTimestamp(protoEvent, timestamp); 300 | 301 | // serialize base event 302 | CFDataRef baseData = CGEventCreateData(kCFAllocatorDefault, protoEvent); 303 | CFRelease(protoEvent); 304 | CFMutableDataRef gestureData = CFDataCreateMutableCopy(kCFAllocatorDefault, 0, baseData); 305 | CFRelease(baseData); 306 | 307 | // remove gesture fields CGEvent has added before the missing event data (it expects to find them after) 308 | if (CFDataGetLength(gestureData) >= 24) { 309 | CFDataDeleteBytes(gestureData, CFRangeMake(CFDataGetLength(gestureData) - 24, 24)); 310 | } 311 | 312 | // serialize CGEvent field header for IOHID event queue 313 | uint16_t totalSize = (sizeof(IOHIDSystemQueueElement) + vendorDataSize + 314 | (numTouches + 1) * sizeof(IOHIDDigitizerEventData)); 315 | uint16_t swappedTotalSize = CFSwapInt16HostToBig((uint16_t)totalSize); 316 | CFDataAppendBytes(gestureData, (UInt8*)&swappedTotalSize, 2); 317 | CFDataAppendBytes(gestureData, (UInt8[]){0x10, 0x6D}, 2); 318 | 319 | // serialize event queue collection header 320 | IOHIDSystemQueueElement queueElement = {}; 321 | queueElement.timeStamp = timestamp; 322 | queueElement.options = parent.options; 323 | queueElement.eventCount = (uint32_t)numTouches + 2; 324 | CFDataAppendBytes(gestureData, (UInt8*)&queueElement, sizeof(queueElement)); 325 | 326 | // serialize touch event data 327 | CFDataAppendBytes(gestureData, (UInt8*)&parent, parent.size); 328 | CFDataAppendBytes(gestureData, CFDataGetBytePtr(serializedTouches), CFDataGetLength(serializedTouches)); 329 | CFRelease(serializedTouches); 330 | 331 | // serialize vendor data 332 | CFDataAppendBytes(gestureData, (UInt8*)vendorData, vendorDataSize); 333 | free(vendorData); 334 | 335 | // serialize gesture event fields 336 | int32_t gestureSubtype = kTLInfoSubtypeGesture; 337 | val = CFDictionaryGetValue(info, kTLInfoKeyGestureSubtype); 338 | if (val) { 339 | CFNumberGetValue(val, kCFNumberSInt32Type, &gestureSubtype); 340 | } 341 | appendIntegerField(gestureData, 0x6E, gestureSubtype); 342 | appendIntegerField(gestureData, 0x6F, 0); // magic 343 | appendIntegerField(gestureData, 0x70, 0); // magic 344 | 345 | int32_t gesturePhase = 0; // c.f. IOHIDEventPhaseBits 346 | val = CFDictionaryGetValue(info, kTLInfoKeyGesturePhase); 347 | if (val) { 348 | CFNumberGetValue(val, kCFNumberSInt32Type, &gesturePhase); 349 | } 350 | appendIntegerField(gestureData, 0x84, gesturePhase); 351 | appendIntegerField(gestureData, 0x85, 0); // magic? 352 | 353 | if (gestureSubtype == kTLInfoSubtypeMagnify) { 354 | Float32 magnification = 0.0f; 355 | val = CFDictionaryGetValue(info, kTLInfoKeyMagnification); 356 | if (val) { 357 | CFNumberGetValue(val, kCFNumberFloat32Type, &magnification); 358 | } 359 | appendFloatField(gestureData, 0x71, magnification); 360 | } 361 | else if (gestureSubtype == kTLInfoSubtypeRotate) { 362 | Float32 rotation = 0.0f; 363 | val = CFDictionaryGetValue(info, kTLInfoKeyRotation); 364 | if (val) { 365 | CFNumberGetValue(val, kCFNumberFloat32Type, &rotation); 366 | } 367 | appendFloatField(gestureData, 0x72, rotation); 368 | } 369 | else if (gestureSubtype == kTLInfoSubtypeSwipe) { 370 | int32_t swipeDirection = 0; 371 | val = CFDictionaryGetValue(info, kTLInfoKeySwipeDirection); 372 | if (val) { 373 | CFNumberGetValue(val, kCFNumberSInt32Type, &swipeDirection); 374 | } 375 | appendIntegerField(gestureData, 0x73, swipeDirection); 376 | } 377 | else if (gestureSubtype == kTLInfoSubtypeBeginGesture || 378 | gestureSubtype == kTLInfoSubtypeEndGesture) 379 | { 380 | int32_t nextSubtype = 0; 381 | val = CFDictionaryGetValue(info, kTLInfoKeyNextSubtype); 382 | if (val) { 383 | CFNumberGetValue(val, kCFNumberSInt32Type, &nextSubtype); 384 | } 385 | appendIntegerField(gestureData, 0x75, nextSubtype); 386 | } 387 | 388 | appendFloatField(gestureData, 0x8B, 0.0f); // magic? 389 | appendFloatField(gestureData, 0x8C, 0.0f); // magic? 390 | 391 | CGEventRef synthEvent = CGEventCreateFromData(kCFAllocatorDefault, gestureData); 392 | CFRelease(gestureData); 393 | return synthEvent; 394 | } 395 | -------------------------------------------------------------------------------- /External/TouchEvents.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TouchEvents.h 3 | * TouchSynthesis 4 | * 5 | * Created by Nathan Vander Wilt on 1/13/10. 6 | * Copyright 2010 Calf Trail Software, LLC. All rights reserved. 7 | * 8 | */ 9 | 10 | #include 11 | 12 | /* these for info */ 13 | 14 | extern const CFStringRef kTLInfoKeyDeviceID; // required for touches 15 | extern const CFStringRef kTLInfoKeyTimestamp; 16 | extern const CFStringRef kTLInfoKeyGestureSubtype; 17 | extern const CFStringRef kTLInfoKeyGesturePhase; 18 | extern const CFStringRef kTLInfoKeyMagnification; 19 | extern const CFStringRef kTLInfoKeyRotation; // degrees 20 | extern const CFStringRef kTLInfoKeySwipeDirection; 21 | extern const CFStringRef kTLInfoKeyNextSubtype; 22 | 23 | enum { 24 | kTLInfoSubtypeRotate = 0x05, 25 | kTLInfoSubtypeSub6, // may be panning/scrolling 26 | kTLInfoSubtypeMagnify = 0x08, 27 | kTLInfoSubtypeGesture = 0x0B, 28 | kTLInfoSubtypeSwipe = 0x10, 29 | kTLInfoSubtypeBeginGesture = 0x3D, 30 | kTLInfoSubtypeEndGesture 31 | }; 32 | typedef uint32_t TLInfoSubtype; 33 | 34 | enum { 35 | kTLInfoSwipeUp = 1, 36 | kTLInfoSwipeDown = 2, 37 | kTLInfoSwipeLeft = 4, 38 | kTLInfoSwipeRight = 8 39 | }; 40 | typedef uint32_t TLInfoSwipeDirection; 41 | 42 | /* these for touches */ 43 | 44 | extern const CFStringRef kTLEventKeyType; 45 | extern const CFStringRef kTLEventKeyTimestamp; 46 | extern const CFStringRef kTLEventKeyOptions; 47 | 48 | extern const CFStringRef kTLEventKeyPositionX; 49 | extern const CFStringRef kTLEventKeyPositionY; 50 | extern const CFStringRef kTLEventKeyPositionZ; 51 | 52 | extern const CFStringRef kTLEventKeyTransducerIndex; 53 | extern const CFStringRef kTLEventKeyTransducerType; 54 | extern const CFStringRef kTLEventKeyIdentity; 55 | extern const CFStringRef kTLEventKeyEventMask; 56 | 57 | extern const CFStringRef kTLEventKeyButtonMask; 58 | extern const CFStringRef kTLEventKeyTipPressure; 59 | extern const CFStringRef kTLEventKeyBarrelPressure; 60 | extern const CFStringRef kTLEventKeyTwist; 61 | 62 | extern const CFStringRef kTLEventKeyQuality; 63 | extern const CFStringRef kTLEventKeyDensity; 64 | extern const CFStringRef kTLEventKeyIrregularity; 65 | extern const CFStringRef kTLEventKeyMajorRadius; 66 | extern const CFStringRef kTLEventKeyMinorRadius; 67 | 68 | CGEventRef tl_CGEventCreateFromGesture(CFDictionaryRef info, CFArrayRef touches); 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | 3 | Version 2, June 1991 4 | 5 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 6 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 7 | 8 | Everyone is permitted to copy and distribute verbatim copies 9 | of this license document, but changing it is not allowed. 10 | Preamble 11 | 12 | The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. 13 | 14 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. 15 | 16 | To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. 17 | 18 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. 19 | 20 | We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. 21 | 22 | Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. 23 | 24 | Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. 25 | 26 | The precise terms and conditions for copying, distribution and modification follow. 27 | 28 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 29 | 30 | 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". 31 | 32 | Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 33 | 34 | 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. 35 | 36 | You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 37 | 38 | 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: 39 | 40 | a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. 41 | b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. 42 | c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) 43 | These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. 44 | 45 | Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. 46 | 47 | In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 48 | 49 | 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: 50 | 51 | a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, 52 | b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, 53 | c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) 54 | The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. 55 | 56 | If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 57 | 58 | 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 59 | 60 | 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 61 | 62 | 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 63 | 64 | 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. 65 | 66 | If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. 67 | 68 | It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. 69 | 70 | This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 71 | 72 | 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 73 | 74 | 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 75 | 76 | Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 77 | 78 | 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. 79 | 80 | NO WARRANTY 81 | 82 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 83 | 84 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SaneSideButtons 2 |

3 | 4 |

5 | 6 | macOS mostly ignores the M4/M5 mouse buttons, commonly used for navigation. Third-party apps can bind them to ⌘+[ and ⌘+], but this only works in a small number of apps and feels janky. With this tool, your side buttons will simulate 2-finger swipes, allowing you to navigate almost any window with a history. As seen in the Logitech MX Master! 7 | 8 | ## About SaneSideButtons 9 | 10 | SaneSideButtons is a fork of the abandoned [SensibleSideButtons](https://github.com/archagon/sensible-side-buttons) by Alexei Baboulevitch. More information about SensibleSideButtons can be found on his [website](https://sensible-side-buttons.archagon.net/). Please consider using his [Amazon affiliate link](http://amzn.to/2tlwbAB) when making any purchase. 11 | 12 | Starting with version 1.0.7 SaneSideButtons is maintained by [Jan Hülsmann](https://github.com/thealpa) and offers native Apple Silicon support. 13 | 14 | ## Installation 15 | 16 | Download SaneSideButtons from [here](https://github.com/thealpa/SaneSideButtons/releases/download/1.1.0/SaneSideButtons.dmg) or install using Homebrew: 17 | 18 | ```bash 19 | brew install --cask sanesidebuttons 20 | ``` 21 | 22 | ## Compatibility 23 | 24 | - macOS Ventura (13.0) and above 25 | - Intel and Apple Silicon 26 | 27 | ## Automatic launch 28 | To launch SaneSideButtons automatically when you log in on your Mac: 29 | 30 | 1. Click the `System Preferences` icon in the Dock or choose Apple menu  > System Preferences. 31 | 1. Open the `General` preference pane. 32 | 1. Click on `Login Items` in the right preference pane. 33 | 1. Click on the plus button at the bottom of the `Open at Login` pane. 34 | 1. Navigate to your Applications folder (or wherever you put the app) and double-click `SaneSideButtons`. 35 | -------------------------------------------------------------------------------- /SaneSideButtons.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 77; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3D0687F128FC3A6D00EFFFBA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D0687F028FC3A6D00EFFFBA /* AppDelegate.swift */; }; 11 | 3D0687F528FC3A6E00EFFFBA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3D0687F428FC3A6E00EFFFBA /* Assets.xcassets */; }; 12 | 3D06880428FC3B0D00EFFFBA /* TouchEvents.c in Sources */ = {isa = PBXBuildFile; fileRef = 3D06880328FC3B0D00EFFFBA /* TouchEvents.c */; }; 13 | 3D06880728FC3B4C00EFFFBA /* SwipeSimulator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D06880628FC3B4C00EFFFBA /* SwipeSimulator.swift */; }; 14 | 3D06880928FC3B8200EFFFBA /* Licenses.txt in Resources */ = {isa = PBXBuildFile; fileRef = 3D06880828FC3B8200EFFFBA /* Licenses.txt */; }; 15 | 3D06880B28FC3D0900EFFFBA /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D06880A28FC3D0800EFFFBA /* main.swift */; }; 16 | 3D20D345298EB4AE00D74D28 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3D20D347298EB4AE00D74D28 /* Localizable.strings */; }; 17 | 3D25277A28FCA303003BBABD /* PermissionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D25277928FCA303003BBABD /* PermissionView.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 3D0687ED28FC3A6D00EFFFBA /* SaneSideButtons.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SaneSideButtons.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 3D0687F028FC3A6D00EFFFBA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | 3D0687F428FC3A6E00EFFFBA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | 3D0687F928FC3A6E00EFFFBA /* SaneSideButtons.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SaneSideButtons.entitlements; sourceTree = ""; }; 25 | 3D06880028FC3AF000EFFFBA /* IOHIDEventData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IOHIDEventData.h; sourceTree = ""; }; 26 | 3D06880128FC3AFB00EFFFBA /* TouchEvents.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchEvents.h; sourceTree = ""; }; 27 | 3D06880228FC3B0C00EFFFBA /* SaneSideButtons-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SaneSideButtons-Bridging-Header.h"; sourceTree = ""; }; 28 | 3D06880328FC3B0D00EFFFBA /* TouchEvents.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = TouchEvents.c; sourceTree = ""; }; 29 | 3D06880528FC3B1700EFFFBA /* IOHIDEventTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IOHIDEventTypes.h; sourceTree = ""; }; 30 | 3D06880628FC3B4C00EFFFBA /* SwipeSimulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwipeSimulator.swift; sourceTree = ""; }; 31 | 3D06880828FC3B8200EFFFBA /* Licenses.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Licenses.txt; sourceTree = ""; }; 32 | 3D06880A28FC3D0800EFFFBA /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; 33 | 3D20D346298EB4AE00D74D28 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; 34 | 3D25277928FCA303003BBABD /* PermissionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionView.swift; sourceTree = ""; }; 35 | 3D95DB932D40FFCE00A8AC70 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; 36 | /* End PBXFileReference section */ 37 | 38 | /* Begin PBXFrameworksBuildPhase section */ 39 | 3D0687EA28FC3A6D00EFFFBA /* Frameworks */ = { 40 | isa = PBXFrameworksBuildPhase; 41 | buildActionMask = 2147483647; 42 | files = ( 43 | ); 44 | runOnlyForDeploymentPostprocessing = 0; 45 | }; 46 | /* End PBXFrameworksBuildPhase section */ 47 | 48 | /* Begin PBXGroup section */ 49 | 3D0687E428FC3A6D00EFFFBA = { 50 | isa = PBXGroup; 51 | children = ( 52 | 3D0687EF28FC3A6D00EFFFBA /* SaneSideButtons */, 53 | 3D0687FF28FC3AD700EFFFBA /* External */, 54 | 3D0687EE28FC3A6D00EFFFBA /* Products */, 55 | ); 56 | sourceTree = ""; 57 | }; 58 | 3D0687EE28FC3A6D00EFFFBA /* Products */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 3D0687ED28FC3A6D00EFFFBA /* SaneSideButtons.app */, 62 | ); 63 | name = Products; 64 | sourceTree = ""; 65 | }; 66 | 3D0687EF28FC3A6D00EFFFBA /* SaneSideButtons */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 3D06880A28FC3D0800EFFFBA /* main.swift */, 70 | 3D0687F028FC3A6D00EFFFBA /* AppDelegate.swift */, 71 | 3D25277928FCA303003BBABD /* PermissionView.swift */, 72 | 3D06880628FC3B4C00EFFFBA /* SwipeSimulator.swift */, 73 | 3D06880828FC3B8200EFFFBA /* Licenses.txt */, 74 | 3D0687F428FC3A6E00EFFFBA /* Assets.xcassets */, 75 | 3D0687F928FC3A6E00EFFFBA /* SaneSideButtons.entitlements */, 76 | 3D20D347298EB4AE00D74D28 /* Localizable.strings */, 77 | ); 78 | path = SaneSideButtons; 79 | sourceTree = ""; 80 | }; 81 | 3D0687FF28FC3AD700EFFFBA /* External */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 3D06880228FC3B0C00EFFFBA /* SaneSideButtons-Bridging-Header.h */, 85 | 3D06880128FC3AFB00EFFFBA /* TouchEvents.h */, 86 | 3D06880328FC3B0D00EFFFBA /* TouchEvents.c */, 87 | 3D06880528FC3B1700EFFFBA /* IOHIDEventTypes.h */, 88 | 3D06880028FC3AF000EFFFBA /* IOHIDEventData.h */, 89 | ); 90 | path = External; 91 | sourceTree = ""; 92 | }; 93 | /* End PBXGroup section */ 94 | 95 | /* Begin PBXNativeTarget section */ 96 | 3D0687EC28FC3A6D00EFFFBA /* SaneSideButtons */ = { 97 | isa = PBXNativeTarget; 98 | buildConfigurationList = 3D0687FC28FC3A6E00EFFFBA /* Build configuration list for PBXNativeTarget "SaneSideButtons" */; 99 | buildPhases = ( 100 | 3D0687E928FC3A6D00EFFFBA /* Sources */, 101 | 3D0687EA28FC3A6D00EFFFBA /* Frameworks */, 102 | 3D0687EB28FC3A6D00EFFFBA /* Resources */, 103 | ); 104 | buildRules = ( 105 | ); 106 | dependencies = ( 107 | 3D95DB902D40F3FF00A8AC70 /* PBXTargetDependency */, 108 | ); 109 | name = SaneSideButtons; 110 | productName = SaneSideButtons; 111 | productReference = 3D0687ED28FC3A6D00EFFFBA /* SaneSideButtons.app */; 112 | productType = "com.apple.product-type.application"; 113 | }; 114 | /* End PBXNativeTarget section */ 115 | 116 | /* Begin PBXProject section */ 117 | 3D0687E528FC3A6D00EFFFBA /* Project object */ = { 118 | isa = PBXProject; 119 | attributes = { 120 | BuildIndependentTargetsInParallel = 1; 121 | LastSwiftUpdateCheck = 1410; 122 | LastUpgradeCheck = 1620; 123 | TargetAttributes = { 124 | 3D0687EC28FC3A6D00EFFFBA = { 125 | CreatedOnToolsVersion = 14.1; 126 | LastSwiftMigration = 1410; 127 | }; 128 | }; 129 | }; 130 | buildConfigurationList = 3D0687E828FC3A6D00EFFFBA /* Build configuration list for PBXProject "SaneSideButtons" */; 131 | developmentRegion = en; 132 | hasScannedForEncodings = 0; 133 | knownRegions = ( 134 | en, 135 | Base, 136 | "zh-Hans", 137 | ); 138 | mainGroup = 3D0687E428FC3A6D00EFFFBA; 139 | packageReferences = ( 140 | 3D95DB8E2D40F3EC00A8AC70 /* XCRemoteSwiftPackageReference "SwiftLintPlugins" */, 141 | ); 142 | preferredProjectObjectVersion = 77; 143 | productRefGroup = 3D0687EE28FC3A6D00EFFFBA /* Products */; 144 | projectDirPath = ""; 145 | projectRoot = ""; 146 | targets = ( 147 | 3D0687EC28FC3A6D00EFFFBA /* SaneSideButtons */, 148 | ); 149 | }; 150 | /* End PBXProject section */ 151 | 152 | /* Begin PBXResourcesBuildPhase section */ 153 | 3D0687EB28FC3A6D00EFFFBA /* Resources */ = { 154 | isa = PBXResourcesBuildPhase; 155 | buildActionMask = 2147483647; 156 | files = ( 157 | 3D06880928FC3B8200EFFFBA /* Licenses.txt in Resources */, 158 | 3D20D345298EB4AE00D74D28 /* Localizable.strings in Resources */, 159 | 3D0687F528FC3A6E00EFFFBA /* Assets.xcassets in Resources */, 160 | ); 161 | runOnlyForDeploymentPostprocessing = 0; 162 | }; 163 | /* End PBXResourcesBuildPhase section */ 164 | 165 | /* Begin PBXSourcesBuildPhase section */ 166 | 3D0687E928FC3A6D00EFFFBA /* Sources */ = { 167 | isa = PBXSourcesBuildPhase; 168 | buildActionMask = 2147483647; 169 | files = ( 170 | 3D25277A28FCA303003BBABD /* PermissionView.swift in Sources */, 171 | 3D06880B28FC3D0900EFFFBA /* main.swift in Sources */, 172 | 3D0687F128FC3A6D00EFFFBA /* AppDelegate.swift in Sources */, 173 | 3D06880428FC3B0D00EFFFBA /* TouchEvents.c in Sources */, 174 | 3D06880728FC3B4C00EFFFBA /* SwipeSimulator.swift in Sources */, 175 | ); 176 | runOnlyForDeploymentPostprocessing = 0; 177 | }; 178 | /* End PBXSourcesBuildPhase section */ 179 | 180 | /* Begin PBXTargetDependency section */ 181 | 3D95DB902D40F3FF00A8AC70 /* PBXTargetDependency */ = { 182 | isa = PBXTargetDependency; 183 | productRef = 3D95DB8F2D40F3FF00A8AC70 /* SwiftLintBuildToolPlugin */; 184 | }; 185 | /* End PBXTargetDependency section */ 186 | 187 | /* Begin PBXVariantGroup section */ 188 | 3D20D347298EB4AE00D74D28 /* Localizable.strings */ = { 189 | isa = PBXVariantGroup; 190 | children = ( 191 | 3D20D346298EB4AE00D74D28 /* en */, 192 | 3D95DB932D40FFCE00A8AC70 /* zh-Hans */, 193 | ); 194 | name = Localizable.strings; 195 | sourceTree = ""; 196 | }; 197 | /* End PBXVariantGroup section */ 198 | 199 | /* Begin XCBuildConfiguration section */ 200 | 3D0687FA28FC3A6E00EFFFBA /* Debug */ = { 201 | isa = XCBuildConfiguration; 202 | buildSettings = { 203 | ALWAYS_SEARCH_USER_PATHS = NO; 204 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 205 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 206 | CLANG_ANALYZER_NONNULL = YES; 207 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 208 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 209 | CLANG_ENABLE_MODULES = YES; 210 | CLANG_ENABLE_OBJC_ARC = YES; 211 | CLANG_ENABLE_OBJC_WEAK = YES; 212 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 213 | CLANG_WARN_BOOL_CONVERSION = YES; 214 | CLANG_WARN_COMMA = YES; 215 | CLANG_WARN_CONSTANT_CONVERSION = YES; 216 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 217 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 218 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 219 | CLANG_WARN_EMPTY_BODY = YES; 220 | CLANG_WARN_ENUM_CONVERSION = YES; 221 | CLANG_WARN_INFINITE_RECURSION = YES; 222 | CLANG_WARN_INT_CONVERSION = YES; 223 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 224 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 225 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 226 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 227 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 228 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 229 | CLANG_WARN_STRICT_PROTOTYPES = YES; 230 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 231 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 232 | CLANG_WARN_UNREACHABLE_CODE = YES; 233 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 234 | COPY_PHASE_STRIP = NO; 235 | DEAD_CODE_STRIPPING = YES; 236 | DEBUG_INFORMATION_FORMAT = dwarf; 237 | ENABLE_STRICT_OBJC_MSGSEND = YES; 238 | ENABLE_TESTABILITY = YES; 239 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 240 | GCC_C_LANGUAGE_STANDARD = gnu11; 241 | GCC_DYNAMIC_NO_PIC = NO; 242 | GCC_NO_COMMON_BLOCKS = YES; 243 | GCC_OPTIMIZATION_LEVEL = 0; 244 | GCC_PREPROCESSOR_DEFINITIONS = ( 245 | "DEBUG=1", 246 | "$(inherited)", 247 | ); 248 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 249 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 250 | GCC_WARN_UNDECLARED_SELECTOR = YES; 251 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 252 | GCC_WARN_UNUSED_FUNCTION = YES; 253 | GCC_WARN_UNUSED_VARIABLE = YES; 254 | MACOSX_DEPLOYMENT_TARGET = 13.0; 255 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 256 | MTL_FAST_MATH = YES; 257 | ONLY_ACTIVE_ARCH = YES; 258 | SDKROOT = macosx; 259 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 260 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 261 | }; 262 | name = Debug; 263 | }; 264 | 3D0687FB28FC3A6E00EFFFBA /* Release */ = { 265 | isa = XCBuildConfiguration; 266 | buildSettings = { 267 | ALWAYS_SEARCH_USER_PATHS = NO; 268 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 269 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 270 | CLANG_ANALYZER_NONNULL = YES; 271 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 272 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 273 | CLANG_ENABLE_MODULES = YES; 274 | CLANG_ENABLE_OBJC_ARC = YES; 275 | CLANG_ENABLE_OBJC_WEAK = YES; 276 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 277 | CLANG_WARN_BOOL_CONVERSION = YES; 278 | CLANG_WARN_COMMA = YES; 279 | CLANG_WARN_CONSTANT_CONVERSION = YES; 280 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 281 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 282 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 283 | CLANG_WARN_EMPTY_BODY = YES; 284 | CLANG_WARN_ENUM_CONVERSION = YES; 285 | CLANG_WARN_INFINITE_RECURSION = YES; 286 | CLANG_WARN_INT_CONVERSION = YES; 287 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 288 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 289 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 290 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 291 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 292 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 293 | CLANG_WARN_STRICT_PROTOTYPES = YES; 294 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 295 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 296 | CLANG_WARN_UNREACHABLE_CODE = YES; 297 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 298 | COPY_PHASE_STRIP = NO; 299 | DEAD_CODE_STRIPPING = YES; 300 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 301 | ENABLE_NS_ASSERTIONS = NO; 302 | ENABLE_STRICT_OBJC_MSGSEND = YES; 303 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 304 | GCC_C_LANGUAGE_STANDARD = gnu11; 305 | GCC_NO_COMMON_BLOCKS = YES; 306 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 307 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 308 | GCC_WARN_UNDECLARED_SELECTOR = YES; 309 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 310 | GCC_WARN_UNUSED_FUNCTION = YES; 311 | GCC_WARN_UNUSED_VARIABLE = YES; 312 | MACOSX_DEPLOYMENT_TARGET = 13.0; 313 | MTL_ENABLE_DEBUG_INFO = NO; 314 | MTL_FAST_MATH = YES; 315 | SDKROOT = macosx; 316 | SWIFT_COMPILATION_MODE = wholemodule; 317 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 318 | }; 319 | name = Release; 320 | }; 321 | 3D0687FD28FC3A6E00EFFFBA /* Debug */ = { 322 | isa = XCBuildConfiguration; 323 | buildSettings = { 324 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 325 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 326 | CLANG_ENABLE_MODULES = YES; 327 | CODE_SIGN_ENTITLEMENTS = SaneSideButtons/SaneSideButtons.entitlements; 328 | CODE_SIGN_IDENTITY = "-"; 329 | "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; 330 | CODE_SIGN_STYLE = Automatic; 331 | COMBINE_HIDPI_IMAGES = YES; 332 | CURRENT_PROJECT_VERSION = 23; 333 | DEAD_CODE_STRIPPING = YES; 334 | DEVELOPMENT_TEAM = B7HSFEB698; 335 | ENABLE_HARDENED_RUNTIME = NO; 336 | GCC_C_LANGUAGE_STANDARD = gnu17; 337 | GENERATE_INFOPLIST_FILE = YES; 338 | INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; 339 | INFOPLIST_KEY_LSUIElement = YES; 340 | INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2025 Jan Hülsmann. All rights reserved."; 341 | INFOPLIST_KEY_NSPrincipalClass = NSApplication; 342 | LD_RUNPATH_SEARCH_PATHS = ( 343 | "$(inherited)", 344 | "@executable_path/../Frameworks", 345 | ); 346 | MACOSX_DEPLOYMENT_TARGET = 15.0; 347 | MARKETING_VERSION = 1.4.1; 348 | PRODUCT_BUNDLE_IDENTIFIER = com.janhuelsmann.SaneSideButtons; 349 | PRODUCT_NAME = "$(TARGET_NAME)"; 350 | SWIFT_EMIT_LOC_STRINGS = YES; 351 | SWIFT_OBJC_BRIDGING_HEADER = "External/SaneSideButtons-Bridging-Header.h"; 352 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 353 | SWIFT_STRICT_CONCURRENCY = complete; 354 | SWIFT_VERSION = 6.0; 355 | }; 356 | name = Debug; 357 | }; 358 | 3D0687FE28FC3A6E00EFFFBA /* Release */ = { 359 | isa = XCBuildConfiguration; 360 | buildSettings = { 361 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 362 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 363 | CLANG_ENABLE_MODULES = YES; 364 | CODE_SIGN_ENTITLEMENTS = SaneSideButtons/SaneSideButtons.entitlements; 365 | CODE_SIGN_IDENTITY = "-"; 366 | "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; 367 | CODE_SIGN_STYLE = Automatic; 368 | COMBINE_HIDPI_IMAGES = YES; 369 | CURRENT_PROJECT_VERSION = 23; 370 | DEAD_CODE_STRIPPING = YES; 371 | DEVELOPMENT_TEAM = B7HSFEB698; 372 | ENABLE_HARDENED_RUNTIME = YES; 373 | GCC_C_LANGUAGE_STANDARD = gnu17; 374 | GENERATE_INFOPLIST_FILE = YES; 375 | INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; 376 | INFOPLIST_KEY_LSUIElement = YES; 377 | INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2025 Jan Hülsmann. All rights reserved."; 378 | INFOPLIST_KEY_NSPrincipalClass = NSApplication; 379 | LD_RUNPATH_SEARCH_PATHS = ( 380 | "$(inherited)", 381 | "@executable_path/../Frameworks", 382 | ); 383 | MACOSX_DEPLOYMENT_TARGET = 15.0; 384 | MARKETING_VERSION = 1.4.1; 385 | PRODUCT_BUNDLE_IDENTIFIER = com.janhuelsmann.SaneSideButtons; 386 | PRODUCT_NAME = "$(TARGET_NAME)"; 387 | SWIFT_EMIT_LOC_STRINGS = YES; 388 | SWIFT_OBJC_BRIDGING_HEADER = "External/SaneSideButtons-Bridging-Header.h"; 389 | SWIFT_STRICT_CONCURRENCY = complete; 390 | SWIFT_VERSION = 6.0; 391 | }; 392 | name = Release; 393 | }; 394 | /* End XCBuildConfiguration section */ 395 | 396 | /* Begin XCConfigurationList section */ 397 | 3D0687E828FC3A6D00EFFFBA /* Build configuration list for PBXProject "SaneSideButtons" */ = { 398 | isa = XCConfigurationList; 399 | buildConfigurations = ( 400 | 3D0687FA28FC3A6E00EFFFBA /* Debug */, 401 | 3D0687FB28FC3A6E00EFFFBA /* Release */, 402 | ); 403 | defaultConfigurationIsVisible = 0; 404 | defaultConfigurationName = Release; 405 | }; 406 | 3D0687FC28FC3A6E00EFFFBA /* Build configuration list for PBXNativeTarget "SaneSideButtons" */ = { 407 | isa = XCConfigurationList; 408 | buildConfigurations = ( 409 | 3D0687FD28FC3A6E00EFFFBA /* Debug */, 410 | 3D0687FE28FC3A6E00EFFFBA /* Release */, 411 | ); 412 | defaultConfigurationIsVisible = 0; 413 | defaultConfigurationName = Release; 414 | }; 415 | /* End XCConfigurationList section */ 416 | 417 | /* Begin XCRemoteSwiftPackageReference section */ 418 | 3D95DB8E2D40F3EC00A8AC70 /* XCRemoteSwiftPackageReference "SwiftLintPlugins" */ = { 419 | isa = XCRemoteSwiftPackageReference; 420 | repositoryURL = "https://github.com/SimplyDanny/SwiftLintPlugins"; 421 | requirement = { 422 | kind = upToNextMajorVersion; 423 | minimumVersion = 0.58.2; 424 | }; 425 | }; 426 | /* End XCRemoteSwiftPackageReference section */ 427 | 428 | /* Begin XCSwiftPackageProductDependency section */ 429 | 3D95DB8F2D40F3FF00A8AC70 /* SwiftLintBuildToolPlugin */ = { 430 | isa = XCSwiftPackageProductDependency; 431 | package = 3D95DB8E2D40F3EC00A8AC70 /* XCRemoteSwiftPackageReference "SwiftLintPlugins" */; 432 | productName = "plugin:SwiftLintBuildToolPlugin"; 433 | }; 434 | /* End XCSwiftPackageProductDependency section */ 435 | }; 436 | rootObject = 3D0687E528FC3A6D00EFFFBA /* Project object */; 437 | } 438 | -------------------------------------------------------------------------------- /SaneSideButtons.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SaneSideButtons.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SaneSideButtons.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "originHash" : "1fa961aa1dc717cea452f3389668f0f99a254f07e4eb11d190768a53798f744f", 3 | "pins" : [ 4 | { 5 | "identity" : "swiftlintplugins", 6 | "kind" : "remoteSourceControl", 7 | "location" : "https://github.com/SimplyDanny/SwiftLintPlugins", 8 | "state" : { 9 | "revision" : "7a3d77f3dd9f91d5cea138e52c20cfceabf352de", 10 | "version" : "0.58.2" 11 | } 12 | } 13 | ], 14 | "version" : 3 15 | } 16 | -------------------------------------------------------------------------------- /SaneSideButtons/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SaneSideButtons 4 | // 5 | // Created by Jan Hülsmann on 16.10.22. 6 | // 7 | 8 | import AppKit 9 | import SwiftUI 10 | import ServiceManagement 11 | 12 | final class AppDelegate: NSObject, NSApplicationDelegate { 13 | 14 | private var frontmostAppBundleID: String? 15 | private var permissionWindow: NSWindow? 16 | private var isLaunchAtLoginEnabled: Bool { 17 | get { SMAppService.mainApp.status == .enabled } 18 | set { 19 | if newValue { 20 | if SMAppService.mainApp.status == .enabled { 21 | try? SMAppService.mainApp.unregister() 22 | } 23 | try? SMAppService.mainApp.register() 24 | } else { 25 | try? SMAppService.mainApp.unregister() 26 | } 27 | } 28 | } 29 | 30 | // MARK: - Menu Bar 31 | 32 | private let menuBarExtra: NSStatusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) 33 | 34 | // MARK: - Menu Bar Items 35 | 36 | private lazy var menuItemHide: NSMenuItem = { 37 | let title = NSLocalizedString("hide", comment: "Hide menu item") 38 | return NSMenuItem(title: title, action: #selector(self.hideMenuBarExtra), keyEquivalent: "h") 39 | }() 40 | 41 | private let menuItemHideInfo: NSMenuItem = { 42 | let title = NSLocalizedString("hideInfo", comment: "Show again info in menu") 43 | let item = NSMenuItem(title: title, action: nil, keyEquivalent: "") 44 | item.isEnabled = false 45 | return item 46 | }() 47 | 48 | private let menuItemIgnore: NSMenuItem = { 49 | let item = NSMenuItem() 50 | item.tag = 1 51 | return item 52 | }() 53 | 54 | private lazy var menuItemReverse: NSMenuItem = { 55 | let title = NSLocalizedString("reverse", comment: "Reverse buttons") 56 | let item = NSMenuItem(title: title, action: #selector(self.toggleReverse), keyEquivalent: "") 57 | item.tag = 2 58 | return item 59 | }() 60 | 61 | private lazy var menuItemLaunchAtLogin: NSMenuItem = { 62 | let title = NSLocalizedString("launchAtLogin", comment: "Launch at Login") 63 | let item = NSMenuItem(title: title, action: #selector(self.toggleLaunchAtLogin), keyEquivalent: "") 64 | item.tag = 3 65 | return item 66 | }() 67 | 68 | private let menuItemVersion: NSMenuItem? = { 69 | guard let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String else { return nil } 70 | let localizedString = NSLocalizedString("version", comment: "Version menu item") 71 | let versionString = String.localizedStringWithFormat(localizedString, version) 72 | let item = NSMenuItem(title: versionString, action: nil, keyEquivalent: "") 73 | item.isEnabled = false 74 | return item 75 | }() 76 | 77 | private lazy var menuItemAbout: NSMenuItem = { 78 | let title = NSLocalizedString("about", comment: "About menu item") 79 | return NSMenuItem(title: title, action: #selector(self.about), keyEquivalent: "") 80 | }() 81 | 82 | private lazy var itemQuit: NSMenuItem = { 83 | let title = NSLocalizedString("quit", comment: "Quit menu item") 84 | return NSMenuItem(title: title, action: #selector(self.quit), keyEquivalent: "q") 85 | }() 86 | 87 | // MARK: - NSApplicationDelegate 88 | 89 | func applicationDidFinishLaunching(_ aNotification: Notification) { 90 | self.setupTapWithPermissions() 91 | self.setupMenuBarExtra() 92 | } 93 | 94 | func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { 95 | self.menuBarExtra.isVisible = true 96 | return false 97 | } 98 | 99 | func applicationWillTerminate(_ aNotification: Notification) { } 100 | 101 | func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { 102 | return true 103 | } 104 | } 105 | 106 | // MARK: - Functions 107 | 108 | private extension AppDelegate { 109 | @MainActor private func setupMenuBarExtra() { 110 | if let button = self.menuBarExtra.button { 111 | button.image = NSImage(resource: .menuIcon) 112 | } 113 | 114 | let menu = NSMenu() 115 | menu.delegate = self 116 | menu.items = [ 117 | self.menuItemHide, 118 | self.menuItemHideInfo, 119 | .separator(), 120 | self.menuItemIgnore, 121 | self.menuItemReverse, 122 | self.menuItemLaunchAtLogin, 123 | .separator(), 124 | self.menuItemVersion, 125 | self.menuItemAbout, 126 | .separator(), 127 | self.itemQuit 128 | ].compactMap { $0 } 129 | 130 | self.menuBarExtra.menu = menu 131 | } 132 | 133 | @objc private func hideMenuBarExtra() { 134 | self.menuBarExtra.isVisible = false 135 | } 136 | 137 | @MainActor @objc private func about() { 138 | NSApplication.shared.activate(ignoringOtherApps: true) 139 | NSApplication.shared.orderFrontStandardAboutPanel() 140 | } 141 | 142 | @MainActor @objc private func quit() { 143 | NSApplication.shared.terminate(nil) 144 | } 145 | 146 | @objc private func ignoreFrontmostApp() { 147 | guard let frontmostAppBundleID else { return } 148 | SwipeSimulator.shared.addIgnoredApplication(bundleID: frontmostAppBundleID) 149 | } 150 | 151 | @objc private func unignoreFrontmostApp() { 152 | guard let frontmostAppBundleID else { return } 153 | SwipeSimulator.shared.removeIgnoredApplication(bundleID: frontmostAppBundleID) 154 | } 155 | 156 | @objc private func toggleReverse() { 157 | SwipeSimulator.shared.toggleReverseButtons() 158 | } 159 | 160 | @objc private func toggleLaunchAtLogin() { 161 | self.isLaunchAtLoginEnabled.toggle() 162 | } 163 | 164 | // MARK: - Setup & Permissions 165 | 166 | @MainActor private func setupTapWithPermissions() { 167 | self.getEventPermission() 168 | do { 169 | try SwipeSimulator.shared.setupEventTap() 170 | } catch { 171 | if self.permissionWindow == nil { 172 | self.promptPermissions() 173 | } 174 | } 175 | } 176 | 177 | @discardableResult private func getEventPermission() -> Bool { 178 | if !CGPreflightListenEventAccess() { 179 | CGRequestListenEventAccess() 180 | return false 181 | } 182 | return true 183 | } 184 | 185 | @MainActor @objc private func promptPermissions() { 186 | NSApplication.shared.activate(ignoringOtherApps: true) 187 | self.permissionWindow = NSWindow( 188 | contentRect: NSRect(), 189 | styleMask: [.closable, .titled, .fullSizeContentView], 190 | backing: .buffered, 191 | defer: false 192 | ) 193 | self.permissionWindow?.isReleasedWhenClosed = false 194 | self.permissionWindow?.titlebarAppearsTransparent = true 195 | self.permissionWindow?.titleVisibility = .hidden 196 | self.permissionWindow?.toolbar = NSToolbar() 197 | self.permissionWindow?.standardWindowButton(.miniaturizeButton)?.isHidden = true 198 | self.permissionWindow?.standardWindowButton(.zoomButton)?.isHidden = true 199 | self.permissionWindow?.contentView = NSHostingView(rootView: PermissionView()) 200 | self.permissionWindow?.isOpaque = false 201 | self.permissionWindow?.backgroundColor = NSColor(white: 1, alpha: 0) 202 | self.permissionWindow?.center() 203 | self.permissionWindow?.makeKeyAndOrderFront(nil) 204 | self.permissionWindow?.delegate = self 205 | } 206 | } 207 | 208 | // MARK: - NSMenuDelegate 209 | 210 | extension AppDelegate: NSMenuDelegate { 211 | func menuWillOpen(_ menu: NSMenu) { 212 | // Permission Detection 213 | if !SwipeSimulator.shared.isEventTapRunning() { 214 | NSApplication.shared.activate(ignoringOtherApps: true) 215 | if self.permissionWindow == nil { 216 | self.promptPermissions() 217 | } 218 | } 219 | 220 | // Front App Detection 221 | guard let frontApp = NSWorkspace.shared.frontmostApplication, 222 | let frontAppName = frontApp.localizedName, 223 | let frontAppBundleID = frontApp.bundleIdentifier else { 224 | self.frontmostAppBundleID = nil 225 | self.menuBarExtra.menu?.item(withTag: 1)?.isHidden = true 226 | return 227 | } 228 | 229 | self.frontmostAppBundleID = frontAppBundleID 230 | let localizedString = NSLocalizedString("ignore", comment: "Ignore app menu item") 231 | let ignoreString = String.localizedStringWithFormat(localizedString, frontAppName) 232 | if !SwipeSimulator.shared.ignoredApplicationsContain(frontAppBundleID) { 233 | self.menuBarExtra.menu?.item(withTag: 1)?.state = .off 234 | self.menuBarExtra.menu?.item(withTag: 1)?.action = #selector(self.ignoreFrontmostApp) 235 | } else { 236 | self.menuBarExtra.menu?.item(withTag: 1)?.state = .on 237 | self.menuBarExtra.menu?.item(withTag: 1)?.action = #selector(self.unignoreFrontmostApp) 238 | } 239 | self.menuBarExtra.menu?.item(withTag: 1)?.isHidden = false 240 | self.menuBarExtra.menu?.item(withTag: 1)?.title = ignoreString 241 | 242 | // Reverse Buttons State 243 | self.menuBarExtra.menu?.item(withTag: 2)?.state = SwipeSimulator.shared.areButtonsReversed() ? .on : .off 244 | 245 | // Launch at Login Button State 246 | self.menuBarExtra.menu?.item(withTag: 3)?.state = self.isLaunchAtLoginEnabled ? .on : .off 247 | } 248 | } 249 | 250 | // MARK: - NSWindowDelegate 251 | 252 | extension AppDelegate: NSWindowDelegate { 253 | func windowShouldClose(_ sender: NSWindow) -> Bool { 254 | self.permissionWindow = nil 255 | return true 256 | } 257 | } 258 | -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/AppIcon.appiconset/128@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thealpa/SaneSideButtons/21601b72da11158100c2fb24a1cbadbef67e38bd/SaneSideButtons/Assets.xcassets/AppIcon.appiconset/128@1x.png -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/AppIcon.appiconset/128@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thealpa/SaneSideButtons/21601b72da11158100c2fb24a1cbadbef67e38bd/SaneSideButtons/Assets.xcassets/AppIcon.appiconset/128@2x.png -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/AppIcon.appiconset/16@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thealpa/SaneSideButtons/21601b72da11158100c2fb24a1cbadbef67e38bd/SaneSideButtons/Assets.xcassets/AppIcon.appiconset/16@1x.png -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/AppIcon.appiconset/16@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thealpa/SaneSideButtons/21601b72da11158100c2fb24a1cbadbef67e38bd/SaneSideButtons/Assets.xcassets/AppIcon.appiconset/16@2x.png -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/AppIcon.appiconset/256@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thealpa/SaneSideButtons/21601b72da11158100c2fb24a1cbadbef67e38bd/SaneSideButtons/Assets.xcassets/AppIcon.appiconset/256@1x.png -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/AppIcon.appiconset/256@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thealpa/SaneSideButtons/21601b72da11158100c2fb24a1cbadbef67e38bd/SaneSideButtons/Assets.xcassets/AppIcon.appiconset/256@2x.png -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/AppIcon.appiconset/32@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thealpa/SaneSideButtons/21601b72da11158100c2fb24a1cbadbef67e38bd/SaneSideButtons/Assets.xcassets/AppIcon.appiconset/32@1x.png -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/AppIcon.appiconset/32@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thealpa/SaneSideButtons/21601b72da11158100c2fb24a1cbadbef67e38bd/SaneSideButtons/Assets.xcassets/AppIcon.appiconset/32@2x.png -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/AppIcon.appiconset/512@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thealpa/SaneSideButtons/21601b72da11158100c2fb24a1cbadbef67e38bd/SaneSideButtons/Assets.xcassets/AppIcon.appiconset/512@1x.png -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/AppIcon.appiconset/512@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thealpa/SaneSideButtons/21601b72da11158100c2fb24a1cbadbef67e38bd/SaneSideButtons/Assets.xcassets/AppIcon.appiconset/512@2x.png -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "16@1x.png", 5 | "idiom" : "mac", 6 | "scale" : "1x", 7 | "size" : "16x16" 8 | }, 9 | { 10 | "filename" : "16@2x.png", 11 | "idiom" : "mac", 12 | "scale" : "2x", 13 | "size" : "16x16" 14 | }, 15 | { 16 | "filename" : "32@1x.png", 17 | "idiom" : "mac", 18 | "scale" : "1x", 19 | "size" : "32x32" 20 | }, 21 | { 22 | "filename" : "32@2x.png", 23 | "idiom" : "mac", 24 | "scale" : "2x", 25 | "size" : "32x32" 26 | }, 27 | { 28 | "filename" : "128@1x.png", 29 | "idiom" : "mac", 30 | "scale" : "1x", 31 | "size" : "128x128" 32 | }, 33 | { 34 | "filename" : "128@2x.png", 35 | "idiom" : "mac", 36 | "scale" : "2x", 37 | "size" : "128x128" 38 | }, 39 | { 40 | "filename" : "256@1x.png", 41 | "idiom" : "mac", 42 | "scale" : "1x", 43 | "size" : "256x256" 44 | }, 45 | { 46 | "filename" : "256@2x.png", 47 | "idiom" : "mac", 48 | "scale" : "2x", 49 | "size" : "256x256" 50 | }, 51 | { 52 | "filename" : "512@1x.png", 53 | "idiom" : "mac", 54 | "scale" : "1x", 55 | "size" : "512x512" 56 | }, 57 | { 58 | "filename" : "512@2x.png", 59 | "idiom" : "mac", 60 | "scale" : "2x", 61 | "size" : "512x512" 62 | } 63 | ], 64 | "info" : { 65 | "author" : "xcode", 66 | "version" : 1 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/BackgroundColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "color" : { 5 | "color-space" : "srgb", 6 | "components" : { 7 | "alpha" : "0.950", 8 | "blue" : "255", 9 | "green" : "255", 10 | "red" : "255" 11 | } 12 | }, 13 | "idiom" : "mac" 14 | }, 15 | { 16 | "appearances" : [ 17 | { 18 | "appearance" : "luminosity", 19 | "value" : "dark" 20 | } 21 | ], 22 | "color" : { 23 | "color-space" : "srgb", 24 | "components" : { 25 | "alpha" : "1.000", 26 | "blue" : "25", 27 | "green" : "25", 28 | "red" : "25" 29 | } 30 | }, 31 | "idiom" : "mac" 32 | } 33 | ], 34 | "info" : { 35 | "author" : "xcode", 36 | "version" : 1 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/MenuIcon.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "MenuIcon@1x.png", 5 | "idiom" : "mac", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "filename" : "MenuIcon@2x.png", 10 | "idiom" : "mac", 11 | "scale" : "2x" 12 | } 13 | ], 14 | "info" : { 15 | "author" : "xcode", 16 | "version" : 1 17 | }, 18 | "properties" : { 19 | "template-rendering-intent" : "template" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/MenuIcon.imageset/MenuIcon@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thealpa/SaneSideButtons/21601b72da11158100c2fb24a1cbadbef67e38bd/SaneSideButtons/Assets.xcassets/MenuIcon.imageset/MenuIcon@1x.png -------------------------------------------------------------------------------- /SaneSideButtons/Assets.xcassets/MenuIcon.imageset/MenuIcon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thealpa/SaneSideButtons/21601b72da11158100c2fb24a1cbadbef67e38bd/SaneSideButtons/Assets.xcassets/MenuIcon.imageset/MenuIcon@2x.png -------------------------------------------------------------------------------- /SaneSideButtons/Licenses.txt: -------------------------------------------------------------------------------- 1 | SaneSideButtons/LICENSE 2 | Copyright (c) 2023 Jan Hülsmann (mail@janhuelsmann.com) 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | SensibleSideButtons/LICENSE 19 | SensibleSideButtons, a utility that fixes the navigation buttons on third-party mice in macOS 20 | Copyright (C) 2018 Alexei Baboulevitch (ssb@archagon.net) 21 | 22 | This program is free software; you can redistribute it and/or 23 | modify it under the terms of the GNU General Public License 24 | as published by the Free Software Foundation; either version 2 25 | of the License, or (at your option) any later version. 26 | 27 | This program is distributed in the hope that it will be useful, 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | GNU General Public License for more details. 31 | 32 | You should have received a copy of the GNU General Public License 33 | along with this program; if not, write to the Free Software 34 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 35 | 36 | TouchSynthesis/LICENSE 37 | Copyright 2010 Calf Trail Software, LLC. All rights reserved. 38 | 39 | This program is free software; you can redistribute it and/or 40 | modify it under the terms of the GNU General Public License 41 | as published by the Free Software Foundation; either version 2 42 | of the License, or (at your option) any later version. 43 | 44 | This program is distributed in the hope that it will be useful, 45 | but WITHOUT ANY WARRANTY; without even the implied warranty of 46 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 47 | GNU General Public License for more details. 48 | 49 | You should have received a copy of the GNU General Public License 50 | along with this program; if not, write to the Free Software 51 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 52 | 53 | IOHIDEventTypes.h/LICENSE 54 | Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. 55 | 56 | This file contains Original Code and/or Modifications of Original Code 57 | as defined in and that are subject to the Apple Public Source License 58 | Version 2.0 (the 'License'). You may not use this file except in 59 | compliance with the License. Please obtain a copy of the License at 60 | http://www.opensource.apple.com/apsl/ and read it before using this 61 | file. 62 | 63 | The Original Code and all software distributed under the License are 64 | distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 65 | EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 66 | INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 67 | FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 68 | Please see the License for the specific language governing rights and 69 | limitations under the License. 70 | 71 | IOHIDEventData.h/LICENSE 72 | 73 | This file contains Original Code and/or Modifications of Original Code 74 | as defined in and that are subject to the Apple Public Source License 75 | Version 2.0 (the 'License'). You may not use this file except in 76 | compliance with the License. Please obtain a copy of the License at 77 | http://www.opensource.apple.com/apsl/ and read it before using this 78 | file. 79 | 80 | The Original Code and all software distributed under the License are 81 | distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 82 | EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 83 | INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 84 | FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 85 | Please see the License for the specific language governing rights and 86 | limitations under the License. 87 | -------------------------------------------------------------------------------- /SaneSideButtons/PermissionView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PermissionView.swift 3 | // SaneSideButtons 4 | // 5 | // Created by Jan Hülsmann on 16.10.22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct PermissionView: View { 11 | private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect() 12 | 13 | var body: some View { 14 | VStack { 15 | VStack { 16 | Text("authorize_title") 17 | .font(.title) 18 | .fontWeight(.medium) 19 | Text("authorize_subtitle") 20 | .font(.body) 21 | .fontWeight(.medium) 22 | } 23 | .padding(.vertical, 10) 24 | ZStack(alignment: .top) { 25 | Rectangle() 26 | .fill(Color.background) 27 | .frame(width: 600, height: 240) 28 | PermissionContentView() 29 | .padding(.vertical, 20) 30 | } 31 | 32 | } 33 | .background(.thinMaterial) 34 | .onReceive(self.timer) { _ in 35 | self.pollPermissions() 36 | } 37 | } 38 | 39 | private func pollPermissions() { 40 | do { 41 | try SwipeSimulator.shared.setupEventTap() 42 | NSApplication.shared.mainWindow?.close() 43 | } catch { 44 | return 45 | } 46 | } 47 | } 48 | 49 | struct PermissionContentView: View { 50 | @Environment(\.openURL) private var openURL 51 | 52 | private let settingsString: String = "x-apple.systempreferences:com.apple.preference" 53 | private let privacyString: String = ".security?Privacy" 54 | 55 | var body: some View { 56 | VStack { 57 | Text("authorize_description") 58 | .font(.body) 59 | .multilineTextAlignment(.center) 60 | .padding(.horizontal, 40) 61 | .padding(.bottom, 30) 62 | Grid { 63 | GridRow { 64 | Image(systemName: "1.circle.fill") 65 | .font(.title) 66 | .foregroundColor(Color.gray) 67 | Image(systemName: "2.circle.fill") 68 | .font(.title) 69 | .foregroundColor(Color.gray) 70 | Image(systemName: "3.circle.fill") 71 | .font(.title) 72 | .foregroundColor(Color.gray) 73 | } 74 | GridRow { 75 | Button { 76 | if let url = URL(string: self.settingsString) { 77 | self.openURL(url) 78 | } 79 | } label: { 80 | HStack { 81 | Image(systemName: "gear") 82 | Text("settings") 83 | .font(.body) 84 | } 85 | .padding(10) 86 | .background( 87 | RoundedRectangle(cornerRadius: 16) 88 | .fill(.thinMaterial) 89 | .shadow(radius: 2) 90 | ) 91 | }.buttonStyle(.plain) 92 | 93 | Button { 94 | if let url = URL(string: self.settingsString + self.privacyString) { 95 | self.openURL(url) 96 | } 97 | } label: { 98 | HStack { 99 | Image(systemName: "hand.raised.fill") 100 | Text("privacy") 101 | .font(.body) 102 | } 103 | .padding(10) 104 | .background( 105 | RoundedRectangle(cornerRadius: 16) 106 | .fill(.thinMaterial) 107 | .shadow(radius: 2) 108 | ) 109 | }.buttonStyle(.plain) 110 | 111 | Button { 112 | if let url = URL(string: self.settingsString + self.privacyString) { 113 | self.openURL(url) 114 | } 115 | } label: { 116 | HStack { 117 | Image(systemName: "keyboard.badge.eye.fill") 118 | Text("add_to \(Text("a11y").underline()) \(Text("input_monitoring").underline())") 119 | .font(.body) 120 | .multilineTextAlignment(.center) 121 | } 122 | .padding(10) 123 | .background( 124 | RoundedRectangle(cornerRadius: 24) 125 | .fill(.thinMaterial) 126 | .shadow(radius: 2) 127 | ) 128 | }.buttonStyle(.plain) 129 | }.frame(width: 180, height: 90) 130 | } 131 | } 132 | } 133 | } 134 | 135 | #Preview { 136 | PermissionView() 137 | } 138 | -------------------------------------------------------------------------------- /SaneSideButtons/SaneSideButtons.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.automation.apple-events 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /SaneSideButtons/SwipeSimulator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwipeSimulator.swift 3 | // SaneSideButtons 4 | // 5 | // Created by Jan Hülsmann on 16.10.22. 6 | // 7 | 8 | import AppKit 9 | import Synchronization 10 | 11 | final class SwipeSimulator: Sendable { 12 | 13 | enum EventTap: Error { 14 | case failedSetup 15 | } 16 | 17 | private enum Keys { 18 | static let ignored: String = "ignoredApplications" 19 | static let reverse: String = "reverseButtons" 20 | } 21 | 22 | private let swipeBegin: [String: Int] = [ 23 | kTLInfoKeyGestureSubtype as String: kTLInfoSubtypeSwipe, 24 | kTLInfoKeyGesturePhase as String: 1 25 | ] 26 | 27 | private let swipeLeft: [String: Int] = [ 28 | kTLInfoKeyGestureSubtype as String: kTLInfoSubtypeSwipe, 29 | kTLInfoKeySwipeDirection as String: kTLInfoSwipeLeft, 30 | kTLInfoKeyGesturePhase as String: 4 31 | ] 32 | 33 | private let swipeRight: [String: Int] = [ 34 | kTLInfoKeyGestureSubtype as String: kTLInfoSubtypeSwipe, 35 | kTLInfoKeySwipeDirection as String: kTLInfoSwipeRight, 36 | kTLInfoKeyGesturePhase as String: 4 37 | ] 38 | 39 | static let shared = SwipeSimulator() 40 | 41 | // MARK: - Internal State 42 | 43 | /// Whether the CGEvent tap is currently active. 44 | private let eventTapIsRunning: Mutex = Mutex(false) 45 | 46 | /// A list of bundle identifiers that are ignored. 47 | private let ignoredApplications: Mutex<[String]> = Mutex( 48 | UserDefaults.standard.stringArray(forKey: Keys.ignored) ?? [] 49 | ) 50 | 51 | /// Whether the swipe direction is reversed (e.g. right <-> left). 52 | private let reverseButtons: Mutex = Mutex(UserDefaults.standard.bool(forKey: Keys.reverse)) 53 | 54 | private init() { } 55 | 56 | // MARK: - Public 57 | 58 | func areButtonsReversed() -> Bool { 59 | self.reverseButtons.withLock { $0 } 60 | } 61 | 62 | func toggleReverseButtons() { 63 | self.reverseButtons.withLock { reversed in 64 | reversed.toggle() 65 | UserDefaults.standard.set(reversed, forKey: Keys.reverse) 66 | } 67 | } 68 | 69 | func isEventTapRunning() -> Bool { 70 | self.eventTapIsRunning.withLock { $0 } 71 | } 72 | 73 | func addIgnoredApplication(bundleID: String) { 74 | self.ignoredApplications.withLock { applications in 75 | applications.append(bundleID) 76 | UserDefaults.standard.set(applications, forKey: Keys.ignored) 77 | } 78 | } 79 | 80 | func removeIgnoredApplication(bundleID: String) { 81 | self.ignoredApplications.withLock { applications in 82 | applications.removeAll { $0 == bundleID } 83 | UserDefaults.standard.set(applications, forKey: Keys.ignored) 84 | } 85 | } 86 | 87 | func ignoredApplicationsContain(_ bundleID: String) -> Bool { 88 | self.ignoredApplications.withLock { $0.contains(bundleID) } 89 | } 90 | 91 | func setupEventTap() throws { 92 | try self.eventTapIsRunning.withLock { isRunning in 93 | guard !isRunning else { return } 94 | let eventMask = CGEventMask( 95 | 1 << CGEventType.otherMouseDown.rawValue | 1 << CGEventType.otherMouseUp.rawValue 96 | ) 97 | 98 | guard let eventTap = CGEvent.tapCreate( 99 | tap: .cghidEventTap, 100 | place: .headInsertEventTap, 101 | options: .defaultTap, 102 | eventsOfInterest: eventMask, 103 | callback: mouseEventCallBack, 104 | userInfo: nil) 105 | else { 106 | isRunning = false 107 | throw EventTap.failedSetup 108 | } 109 | 110 | let runLoopSource = CFMachPortCreateRunLoopSource(nil, eventTap, 0) 111 | CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, .commonModes) 112 | CGEvent.tapEnable(tap: eventTap, enable: true) 113 | isRunning = true 114 | } 115 | } 116 | 117 | private func fakeSwipe(direction: TLInfoSwipeDirection) { 118 | let eventBegin: CGEvent = tl_CGEventCreateFromGesture(self.swipeBegin as CFDictionary, 119 | [] as CFArray).takeRetainedValue() 120 | 121 | let swipeDirection = self.reverseButtons.withLock { $0 ? direction.reversed : direction } 122 | let eventSwipe: CGEvent? = switch swipeDirection { 123 | case TLInfoSwipeDirection(kTLInfoSwipeLeft): 124 | tl_CGEventCreateFromGesture(self.swipeLeft as CFDictionary, [] as CFArray).takeRetainedValue() 125 | case TLInfoSwipeDirection(kTLInfoSwipeRight): 126 | tl_CGEventCreateFromGesture(self.swipeRight as CFDictionary, [] as CFArray).takeRetainedValue() 127 | default: 128 | nil 129 | } 130 | 131 | guard let eventSwipe else { return } 132 | eventBegin.post(tap: .cghidEventTap) 133 | eventSwipe.post(tap: .cghidEventTap) 134 | } 135 | 136 | fileprivate func handleMouseEvent(type: CGEventType, cgEvent: CGEvent) -> CGEvent? { 137 | guard type == .otherMouseDown && self.isValidApplication() else { 138 | return cgEvent 139 | } 140 | 141 | let number = CGEvent.getIntegerValueField(cgEvent)(.mouseEventButtonNumber) 142 | if number == 3 { 143 | self.fakeSwipe(direction: TLInfoSwipeDirection(kTLInfoSwipeLeft)) 144 | return nil 145 | } else if number == 4 { 146 | self.fakeSwipe(direction: TLInfoSwipeDirection(kTLInfoSwipeRight)) 147 | return nil 148 | } 149 | return cgEvent 150 | } 151 | 152 | private func isValidApplication() -> Bool { 153 | guard let frontAppBundleID = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return true } 154 | return self.ignoredApplications.withLock { !$0.contains(frontAppBundleID) } 155 | } 156 | } 157 | 158 | // swiftlint:disable private_over_fileprivate 159 | fileprivate func mouseEventCallBack(proxy: CGEventTapProxy, 160 | type: CGEventType, 161 | cgEvent: CGEvent, 162 | userInfo: UnsafeMutableRawPointer?) -> Unmanaged? { 163 | guard let cgEvent = SwipeSimulator.shared.handleMouseEvent(type: type, cgEvent: cgEvent) else { return nil } 164 | return Unmanaged.passRetained(cgEvent) 165 | } 166 | 167 | fileprivate extension TLInfoSwipeDirection { 168 | var reversed: TLInfoSwipeDirection { 169 | switch self { 170 | case TLInfoSwipeDirection(kTLInfoSwipeLeft): 171 | return TLInfoSwipeDirection(kTLInfoSwipeRight) 172 | case TLInfoSwipeDirection(kTLInfoSwipeRight): 173 | return TLInfoSwipeDirection(kTLInfoSwipeLeft) 174 | default: 175 | return self 176 | } 177 | } 178 | } 179 | // swiftlint:enable private_over_fileprivate 180 | -------------------------------------------------------------------------------- /SaneSideButtons/en.lproj/Localizable.strings: -------------------------------------------------------------------------------- 1 | /* 2 | Localizable.strings 3 | SaneSideButtons 4 | 5 | Created by Jan Hülsmann on 05.01.23. 6 | 7 | */ 8 | 9 | // MARK: - Menu Bar 10 | 11 | "hide" = "Hide Menu Bar Icon"; 12 | "hideInfo" = "Relaunch App to Show Again"; 13 | "ignore" = "Ignore %@"; 14 | "reverse" = "Reverse Buttons"; 15 | "launchAtLogin" = "Launch at Login"; 16 | "version" = "Version %@"; 17 | "about" = "About"; 18 | "quit" = "Quit"; 19 | 20 | // MARK: - Permissions Window 21 | 22 | "authorize_title" = "Authorize SaneSideButtons"; 23 | "authorize_subtitle" = "We'll have you up and running in just a minute!"; 24 | "authorize_description" = "SaneSideButtons needs your permission to detect mouse events and trigger actions in applications. Follow these steps to authorize it:"; 25 | "settings" = "Go to System Settings"; 26 | "privacy" = "Privacy & Security"; 27 | "add_to %@ %@" = "Add SaneSideButtons to %@ & %@"; 28 | "a11y" = "Accessibility"; 29 | "input_monitoring" = "Input Monitoring"; 30 | -------------------------------------------------------------------------------- /SaneSideButtons/main.swift: -------------------------------------------------------------------------------- 1 | // 2 | // main.swift 3 | // SaneSideButtons 4 | // 5 | // Created by Jan Hülsmann on 16.10.22. 6 | // 7 | 8 | import AppKit 9 | 10 | let app = NSApplication.shared 11 | let delegate = AppDelegate() 12 | app.delegate = delegate 13 | _ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv) 14 | -------------------------------------------------------------------------------- /SaneSideButtons/zh-Hans.lproj/Localizable.strings: -------------------------------------------------------------------------------- 1 | /* 2 | Localizable.strings 3 | SaneSideButtons 4 | 5 | Created by Jan Hülsmann on 05.01.23. 6 | 7 | */ 8 | 9 | // MARK: - Menu Bar 10 | 11 | "hide" = "隐藏菜单栏图标"; 12 | "hideInfo" = "重新启动应用程序以再次显示"; 13 | "ignore" = "忽略 %@"; 14 | "reverse" = "反转按键"; 15 | "launchAtLogin" = "登录时启动"; 16 | "version" = "版本 %@"; 17 | "about" = "关于"; 18 | "quit" = "退出"; 19 | 20 | // MARK: - Permissions Window 21 | 22 | "authorize_title" = "授权 SaneSideButtons"; 23 | "authorize_subtitle" = "我们马上就能让您准备就绪!"; 24 | "authorize_description" = "SaneSideButtons 需要您的授权才能在应用程序中检测鼠标事件并触发操作,请按照以下步骤进行授权:"; 25 | "settings" = "前往系统设置"; 26 | "privacy" = "隐私与安全性"; 27 | "add_to %@ %@" = "添加 SaneSideButtons 到 %@ & %@"; 28 | "a11y" = "辅助功能"; 29 | "input_monitoring" = "输入监控"; 30 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thealpa/SaneSideButtons/21601b72da11158100c2fb24a1cbadbef67e38bd/icon.png --------------------------------------------------------------------------------