| 1 |
/* |
| 2 |
This file is part of IanniX, a graphical real-time open-source sequencer for digital art |
| 3 |
Copyright (C) 2010-2015 — IanniX Association |
| 4 |
|
| 5 |
Project Manager: Thierry Coduys (http://www.le-hub.org) |
| 6 |
Development: Guillaume Jacquemin (https://www.buzzinglight.com) |
| 7 |
|
| 8 |
This file was written by Guillaume Jacquemin. |
| 9 |
|
| 10 |
IanniX is a free software: you can redistribute it and/or modify |
| 11 |
it under the terms of the GNU General Public License as published by |
| 12 |
the Free Software Foundation, either version 3 of the License, or |
| 13 |
any later version. |
| 14 |
|
| 15 |
This program is distributed in the hope that it will be useful, |
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
GNU General Public License for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License |
| 21 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 |
*/ |
| 23 |
|
| 24 |
#include "extwacommanager.h" |
| 25 |
|
| 26 |
#import <Cocoa/Cocoa.h> |
| 27 |
#import "qwacom/WacomTabletDriver.h" |
| 28 |
#import "qwacom/TabletAEDictionary.h" |
| 29 |
|
| 30 |
ExtWacomManager::ExtWacomManager() { |
| 31 |
mLastUsedTablet = 0; |
| 32 |
mContextID = 0; |
| 33 |
mTabletOfContext = 0; |
| 34 |
|
| 35 |
absoluteX = absoluteY = absoluteZ = pressure = tangentialPressure = tiltX = tiltY = rotation = deviceID = 0; |
| 36 |
|
| 37 |
NSEventMask observedTypes = NSTabletPointMask |
| 38 |
| NSTabletProximityMask |
| 39 |
|
| 40 |
| NSMouseMovedMask |
| 41 |
| NSLeftMouseDraggedMask |
| 42 |
| NSRightMouseDraggedMask |
| 43 |
| NSOtherMouseDraggedMask |
| 44 |
|
| 45 |
| NSLeftMouseDownMask |
| 46 |
| NSRightMouseDownMask |
| 47 |
| NSOtherMouseDownMask |
| 48 |
|
| 49 |
| NSLeftMouseUpMask |
| 50 |
| NSRightMouseUpMask |
| 51 |
| NSOtherMouseUpMask; |
| 52 |
|
| 53 |
// We will watch and log all these events as they come to us. |
| 54 |
[NSEvent addLocalMonitorForEventsMatchingMask:observedTypes handler:^(NSEvent* theEvent) { |
| 55 |
setValuesFromEvent(theEvent); |
| 56 |
return theEvent; |
| 57 |
}]; |
| 58 |
} |
| 59 |
|
| 60 |
ExtWacomManager::~ExtWacomManager() { |
| 61 |
if(mContextID) |
| 62 |
[WacomTabletDriver destroyContext:mContextID]; |
| 63 |
} |
| 64 |
|
| 65 |
void ExtWacomManager::setMouseControl(bool val) { |
| 66 |
// If we changed tablets since creating the context, we need to start over |
| 67 |
if((mLastUsedTablet != mTabletOfContext) && (mContextID)) { |
| 68 |
[WacomTabletDriver destroyContext:mContextID]; |
| 69 |
mContextID = 0; |
| 70 |
} |
| 71 |
// If no context, create one |
| 72 |
if(!mContextID) { |
| 73 |
mContextID = [WacomTabletDriver createContextForTablet:mLastUsedTablet type:pContextTypeDefault]; |
| 74 |
mTabletOfContext = mLastUsedTablet; |
| 75 |
} |
| 76 |
|
| 77 |
NSAppleEventDescriptor *routingDesc = [WacomTabletDriver routingTableForContext:mContextID]; |
| 78 |
Boolean newMovesCursor = val; |
| 79 |
|
| 80 |
[WacomTabletDriver setBytes:&newMovesCursor |
| 81 |
ofSize:sizeof(Boolean) |
| 82 |
ofType:typeBoolean |
| 83 |
forAttribute:pContextMovesSystemCursor |
| 84 |
routingTable:routingDesc]; |
| 85 |
} |
| 86 |
|
| 87 |
void ExtWacomManager::setValuesFromEvent(void *event) { |
| 88 |
NSEvent *theEvent = (NSEvent*)event; |
| 89 |
NSEventType eventType = [theEvent type]; |
| 90 |
BOOL isMouseEvent = NO; |
| 91 |
BOOL isTabletPointEvent = NO; |
| 92 |
|
| 93 |
|
| 94 |
// Establish which events we may safely query for subtype |
| 95 |
if(eventType == NSMouseMoved |
| 96 |
|| eventType == NSLeftMouseDragged |
| 97 |
|| eventType == NSRightMouseDragged |
| 98 |
|| eventType == NSOtherMouseDragged |
| 99 |
|
| 100 |
|| eventType == NSLeftMouseDown |
| 101 |
|| eventType == NSRightMouseDown |
| 102 |
|| eventType == NSOtherMouseDown |
| 103 |
|
| 104 |
|| eventType == NSLeftMouseUp |
| 105 |
|| eventType == NSRightMouseUp |
| 106 |
|| eventType == NSOtherMouseUp ) { |
| 107 |
isMouseEvent = YES; |
| 108 |
} |
| 109 |
|
| 110 |
// Find tablet point events (both pure and embedded) |
| 111 |
if(eventType == NSTabletPoint || (isMouseEvent == YES && [theEvent subtype] == NSTabletPointEventSubtype)) |
| 112 |
isTabletPointEvent = YES; |
| 113 |
|
| 114 |
if(eventType == NSTabletProximity) { |
| 115 |
qDebug("%d", mLastUsedTablet); |
| 116 |
mLastUsedTablet = [theEvent systemTabletID]; |
| 117 |
qDebug("%d", mLastUsedTablet); |
| 118 |
//penName = [self nameOfPen:[theEvent pointingDeviceSerialNumber]]; |
| 119 |
} |
| 120 |
|
| 121 |
// Mouse move |
| 122 |
if(eventType == NSMouseMoved) { |
| 123 |
/* |
| 124 |
[mMouseMoveLocationXField setFloatValue:[theEvent locationInWindow].x]; |
| 125 |
[mMouseMoveLocationYField setFloatValue:[theEvent locationInWindow].y]; |
| 126 |
[mMouseMoveDeltaXField setFloatValue:[theEvent deltaX]]; |
| 127 |
[mMouseMoveDeltaYField setFloatValue:[theEvent deltaY]]; |
| 128 |
[mMouseMoveModifiersField setStringValue:modifierString]; |
| 129 |
[mMouseMoveIsTabletEventField setStringValue:(isTabletPointEvent ? @"Yes" : @"No")]; |
| 130 |
*/ |
| 131 |
} |
| 132 |
|
| 133 |
// Mouse down |
| 134 |
if(eventType == NSLeftMouseDown || eventType == NSRightMouseDown || eventType == NSOtherMouseDown ) { |
| 135 |
/* |
| 136 |
[mMouseDownLocationXField setFloatValue:[theEvent locationInWindow].x]; |
| 137 |
[mMouseDownLocationYField setFloatValue:[theEvent locationInWindow].y]; |
| 138 |
[mMouseDownModifiersField setStringValue:modifierString]; |
| 139 |
[mMouseDownIsTabletEventField setStringValue:(isTabletPointEvent ? @"Yes" : @"No")]; |
| 140 |
*/ |
| 141 |
} |
| 142 |
|
| 143 |
// Mouse Dragged |
| 144 |
if(eventType == NSLeftMouseDragged || eventType == NSRightMouseDragged || eventType == NSOtherMouseDragged ) { |
| 145 |
/* |
| 146 |
[mMouseDragLocationXField setFloatValue:[theEvent locationInWindow].x]; |
| 147 |
[mMouseDragLocationYField setFloatValue:[theEvent locationInWindow].y]; |
| 148 |
[mMouseDragDeltaXField setFloatValue:[theEvent deltaX]]; |
| 149 |
[mMouseDragDeltaYField setFloatValue:[theEvent deltaY]]; |
| 150 |
[mMouseDragModifiersField setStringValue:modifierString]; |
| 151 |
[mMouseDragIsTabletEventField setStringValue:(isTabletPointEvent ? @"Yes" : @"No")]; |
| 152 |
|
| 153 |
[mMouseDragIsTabletEventField setNeedsDisplay:YES]; |
| 154 |
*/ |
| 155 |
} |
| 156 |
|
| 157 |
// Mouse up |
| 158 |
if(eventType == NSLeftMouseUp || eventType == NSRightMouseUp || eventType == NSOtherMouseUp) { |
| 159 |
/* |
| 160 |
[mMouseUpLocationXField setFloatValue:[theEvent locationInWindow].x]; |
| 161 |
[mMouseUpLocationYField setFloatValue:[theEvent locationInWindow].y]; |
| 162 |
[mMouseUpModifiersField setStringValue:modifierString]; |
| 163 |
[mMouseUpIsTabletEventField setStringValue:(isTabletPointEvent ? @"Yes" : @"No")]; |
| 164 |
*/ |
| 165 |
} |
| 166 |
|
| 167 |
// Set field valid for Tablet Point events |
| 168 |
if(isTabletPointEvent == YES) { |
| 169 |
/* |
| 170 |
[mAbsoluteXField setIntValue:[theEvent absoluteX]]; |
| 171 |
[mAbsoluteYField setIntValue:[theEvent absoluteY]]; |
| 172 |
[mAbsoluteZField setIntValue:[theEvent absoluteZ]]; |
| 173 |
|
| 174 |
[mPressureField setFloatValue:[theEvent pressure]]; |
| 175 |
[mTangentialPressureField setFloatValue:[theEvent tangentialPressure]]; |
| 176 |
|
| 177 |
[mTiltXField setFloatValue:[theEvent tilt].x]; |
| 178 |
[mTiltYField setFloatValue:[theEvent tilt].y]; |
| 179 |
[mRotationField setFloatValue:[theEvent rotation]]; |
| 180 |
|
| 181 |
[mDeviceIDField setIntValue:[theEvent deviceID]]; |
| 182 |
*/ |
| 183 |
absoluteX = [theEvent absoluteX]; |
| 184 |
absoluteY = [theEvent absoluteY]; |
| 185 |
absoluteZ = [theEvent absoluteZ]; |
| 186 |
pressure = [theEvent pressure]; |
| 187 |
tangentialPressure = [theEvent tangentialPressure]; |
| 188 |
tiltX = [theEvent tilt].x; |
| 189 |
tiltY = [theEvent tilt].y; |
| 190 |
rotation = [theEvent rotation]; |
| 191 |
deviceID = [theEvent deviceID]; |
| 192 |
qDebug("%d, %f %f %f => %f", deviceID, absoluteX, absoluteY, absoluteZ, pressure); |
| 193 |
} |
| 194 |
|
| 195 |
// Set Fields valid for point or proximity events |
| 196 |
if(isTabletPointEvent == YES || eventType == NSTabletProximity) { |
| 197 |
/* |
| 198 |
[mDeviceIDField setIntValue:[theEvent deviceID]]; |
| 199 |
*/ |
| 200 |
} |
| 201 |
|
| 202 |
if(eventType == NSTabletProximity) { |
| 203 |
/* |
| 204 |
[mTransducerNameField setStringValue:penName]; |
| 205 |
[mTransducerSerialNumberField setStringValue:[NSString stringWithFormat:@"0x%X", [theEvent pointingDeviceSerialNumber]]]; |
| 206 |
*/ |
| 207 |
} |
| 208 |
} |
| 209 |
|