Skip to content

Commit 010c20e

Browse files
committed
Abstract the shift and mask for mouse button event processing into manifest
constants on MacOS in preparation for including more buttons from gaming mice.
1 parent 108075d commit 010c20e

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
- (void) pushEventToQueue: (sqInputEvent *) evt;
5252
- (void) fakeMouseWheelKeyboardEventsKeyCode: (int) keyCode ascii: (int) ascii windowIndex: (int) windowIndex;
5353
- (int) mapMouseAndModifierStateToSqueakBits: (NSEvent *) event;
54-
- (int) translateCocoaModifiersToSqueakModifiers: (NSUInteger) modifiers;
54+
- (int) translateCocoaModifiersToSqueak: (NSUInteger) modifiers;
5555
- (void) recordDragEvent: (int) dragType numberOfFiles: (int) numFiles where: (NSPoint) local_point windowIndex: (sqInt) windowIndex view:(NSView *)aView;
5656
- (void) recordURLEvent: (int) dragType numberOfFiles: (int) numFiles;
5757
- (void) recordWindowEvent: (int) type window: (NSWindow *) window;

platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.m

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ Some of this code was funded via a grant from the European Smalltalk User Group
4747
extern struct VirtualMachine* interpreterProxy;
4848
extern SqueakOSXAppDelegate *gDelegateApp;
4949

50-
static int buttonState=0;
50+
static int buttonState = 0;
5151

5252
static int firstScreenHeight = 0;
53+
54+
#define MouseButtonMask 0x7
55+
#define MouseButtonShift 3
56+
5357
/*
5458
* Answer (cache) the height of the main display, needed for transforming
5559
* mac screen coordinates to Squeak screen coordinates.
@@ -204,7 +208,7 @@ - (void) recordCharEvent:(NSString *) unicodeString fromView: (NSView <sqSqueakO
204208
unicode = [unicodeString characterAtIndex: i];
205209

206210
if (mainView.lastSeenKeyBoardStrokeDetails) {
207-
evt.modifiers = [self translateCocoaModifiersToSqueakModifiers: mainView.lastSeenKeyBoardStrokeDetails.modifierFlags];
211+
evt.modifiers = [self translateCocoaModifiersToSqueak: mainView.lastSeenKeyBoardStrokeDetails.modifierFlags];
208212
evt.charCode = mainView.lastSeenKeyBoardStrokeDetails.keyCode;
209213
} else {
210214
evt.modifiers = 0;
@@ -255,7 +259,7 @@ - (void) recordKeyDownEvent:(NSEvent *)theEvent fromView: (NSView <sqSqueakOSXVi
255259
evt.timeStamp = ioMSecs();
256260
evt.charCode = [theEvent keyCode];
257261
evt.pressCode = EventKeyDown;
258-
evt.modifiers = [self translateCocoaModifiersToSqueakModifiers: [theEvent modifierFlags]];
262+
evt.modifiers = [self translateCocoaModifiersToSqueak: [theEvent modifierFlags]];
259263
evt.utf32Code = 0;
260264
evt.reserved1 = 0;
261265
evt.windowIndex = [[aView windowLogic] windowIndex];
@@ -271,7 +275,7 @@ - (void) recordKeyUpEvent:(NSEvent *)theEvent fromView: (NSView <sqSqueakOSXView
271275
evt.timeStamp = ioMSecs();
272276
evt.charCode = [theEvent keyCode];
273277
evt.pressCode = EventKeyUp;
274-
evt.modifiers = [self translateCocoaModifiersToSqueakModifiers: [theEvent modifierFlags]];
278+
evt.modifiers = [self translateCocoaModifiersToSqueak: [theEvent modifierFlags]];
275279
evt.utf32Code = 0;
276280
evt.reserved1 = 0;
277281
evt.windowIndex = aView.windowLogic.windowIndex;
@@ -292,8 +296,8 @@ - (void) recordMouseEvent:(NSEvent *)theEvent fromView: (NSView <sqSqueakOSXView
292296
evt.y = lrintf((float)local_point.y);
293297

294298
int buttonAndModifiers = [self mapMouseAndModifierStateToSqueakBits: theEvent];
295-
evt.buttons = buttonAndModifiers & 0x07;
296-
evt.modifiers = buttonAndModifiers >> 3;
299+
evt.buttons = buttonAndModifiers & MouseButtonMask;
300+
evt.modifiers = buttonAndModifiers >> MouseButtonShift;
297301
#if COGVM | STACKVM
298302
evt.nrClicks = 0;
299303
#else
@@ -318,8 +322,8 @@ - (void) recordMouseButtonEvent:(NSEvent *)theEvent fromView: (NSView <sqSqueakO
318322
evt.y = lrintf((float)local_point.y);
319323

320324
int buttonAndModifiers = [self mapMouseAndModifierStateToSqueakBits: theEvent];
321-
evt.buttons = buttonAndModifiers & 0x07;
322-
evt.modifiers = buttonAndModifiers >> 3;
325+
evt.buttons = buttonAndModifiers & MouseButtonMask;
326+
evt.modifiers = buttonAndModifiers >> MouseButtonShift;
323327
#if COGVM | STACKVM
324328
evt.nrClicks = theEvent.clickCount;
325329
#else
@@ -391,8 +395,8 @@ - (void) recordWheelEvent:(NSEvent *) theEvent fromView: (NSView <sqSqueakOSXVie
391395
prevYDelta = 0;
392396

393397
int buttonAndModifiers = [self mapMouseAndModifierStateToSqueakBits: theEvent];
394-
evt.buttons = buttonAndModifiers & 7;
395-
evt.modifiers = buttonAndModifiers >> 3;
398+
evt.buttons = buttonAndModifiers & MouseButtonMask;
399+
evt.modifiers = buttonAndModifiers >> MouseButtonShift;
396400
evt.windowIndex = aView.windowLogic.windowIndex;
397401
[self pushEventToQueue:(sqInputEvent *) &evt];
398402
}
@@ -470,7 +474,7 @@ - (void) fakeMouseWheelKeyboardEventsKeyCode: (int) keyCode ascii: (int) ascii w
470474
*
471475
* While we could just shift and mask, let's be clean an just check.
472476
*/
473-
- (int) translateCocoaModifiersToSqueakModifiers: (NSUInteger) modifiers {
477+
- (int) translateCocoaModifiersToSqueak: (NSUInteger) modifiers {
474478
return
475479
(modifiers & NSEventModifierFlagShift ? ShiftKeyBit : 0) |
476480
(modifiers & NSEventModifierFlagControl ? CtrlKeyBit : 0) |
@@ -538,7 +542,8 @@ - (int) mapMouseAndModifierStateToSqueakBits: (NSEvent *) event {
538542
}
539543

540544
// button state: low three bits are mouse buttons; next 8 bits are modifier bits
541-
buttonState = ([self translateCocoaModifiersToSqueakModifiers: flags] << 3) | (stButtons & 0x7);
545+
buttonState = ([self translateCocoaModifiersToSqueak: flags] << MouseButtonShift)
546+
| (stButtons & MouseButtonMask);
542547
return buttonState;
543548
}
544549

@@ -553,7 +558,7 @@ - (void) recordDragEvent:(int)dragType numberOfFiles:(int)numFiles where:(NSPoin
553558
evt.dragType= dragType;
554559
evt.x = lrintf(local_point.x);
555560
evt.y = lrintf(local_point.y);
556-
evt.modifiers= (buttonState >> 3);
561+
evt.modifiers= buttonState >> MouseButtonShift;
557562
evt.numFiles= numFiles;
558563
evt.windowIndex = windowIndex;
559564
[self pushEventToQueue: (sqInputEvent *) &evt];

0 commit comments

Comments
 (0)