forked from pyrite-dev/milsko
mac: send mouse/key to both event itself and window, evidently
This commit is contained in:
parent
128a1ec524
commit
dccc402b3d
1 changed files with 32 additions and 14 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
#include "Mw/BaseTypes.h"
|
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
|
|
@ -166,6 +165,8 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
|
|
||||||
[c->application finishLaunching];
|
[c->application finishLaunching];
|
||||||
|
|
||||||
|
c->pointerLocked = MwFALSE;
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
- (void)polygonWithPoints:(MwPoint *)points
|
- (void)polygonWithPoints:(MwPoint *)points
|
||||||
|
|
@ -298,10 +299,19 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
* events we handle */
|
* events we handle */
|
||||||
[self eventProcess:ev];
|
[self eventProcess:ev];
|
||||||
[pool release];
|
[pool release];
|
||||||
|
[self->application updateWindows];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self sendClipboardEvent];
|
[self sendClipboardEvent];
|
||||||
|
|
||||||
|
if (self->pointerLocked && [self->window isMainWindow]) {
|
||||||
|
NSPoint pos = [window frame].origin;
|
||||||
|
pos.x += [window frame].size.width / 2;
|
||||||
|
pos.y += [window frame].size.height / 2;
|
||||||
|
|
||||||
|
CGWarpMouseCursorPosition(pos);
|
||||||
|
}
|
||||||
|
|
||||||
[self->application updateWindows];
|
[self->application updateWindows];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -339,9 +349,10 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
case NSOtherMouseDragged:
|
case NSOtherMouseDragged:
|
||||||
case NSMouseMoved: {
|
case NSMouseMoved: {
|
||||||
MwPoint pos;
|
MwPoint pos;
|
||||||
pos.x = [ev locationInWindow].x;
|
NSPoint pos_translated = pointFlip([ev locationInWindow]);
|
||||||
pos.y = [win contentRectForFrameRect:[win frame]].size.height -
|
pos.x = pos_translated.x;
|
||||||
[ev locationInWindow].y;
|
pos.y = pos_translated.y;
|
||||||
|
printf("%d %d\n", pos.x, pos.y);
|
||||||
MwLLDispatch(h, move, &pos);
|
MwLLDispatch(h, move, &pos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -355,8 +366,7 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
break;
|
break;
|
||||||
case NSKeyDown:
|
case NSKeyDown:
|
||||||
case NSKeyUp: {
|
case NSKeyUp: {
|
||||||
[self handleKeyEvent:ev];
|
[self handleKeyEvent:ev ll:h];
|
||||||
doSendEvent = MwFALSE;
|
|
||||||
}
|
}
|
||||||
case NSCursorUpdate:
|
case NSCursorUpdate:
|
||||||
[self->cursor set];
|
[self->cursor set];
|
||||||
|
|
@ -364,12 +374,9 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
case NSScrollWheel:
|
case NSScrollWheel:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
doSendEvent = MwFALSE;
|
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
if (doSendEvent) {
|
|
||||||
[win sendEvent:ev];
|
[win sendEvent:ev];
|
||||||
}
|
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
}
|
}
|
||||||
|
|
@ -378,6 +385,7 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
MwLLMouse mouse;
|
MwLLMouse mouse;
|
||||||
MwBool isDown = MwTRUE;
|
MwBool isDown = MwTRUE;
|
||||||
NSPoint mousePoint = pointFlip([ev locationInWindow]);
|
NSPoint mousePoint = pointFlip([ev locationInWindow]);
|
||||||
|
MwLL this = [self->handle pointer];
|
||||||
switch ([ev type]) {
|
switch ([ev type]) {
|
||||||
case NSLeftMouseUp:
|
case NSLeftMouseUp:
|
||||||
isDown = MwFALSE;
|
isDown = MwFALSE;
|
||||||
|
|
@ -401,13 +409,15 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
mouse.point.y = mousePoint.y;
|
mouse.point.y = mousePoint.y;
|
||||||
|
|
||||||
if (isDown) {
|
if (isDown) {
|
||||||
|
MwLLDispatch(this, down, &mouse);
|
||||||
MwLLDispatch(ll, down, &mouse);
|
MwLLDispatch(ll, down, &mouse);
|
||||||
} else {
|
} else {
|
||||||
|
MwLLDispatch(this, up, &mouse);
|
||||||
MwLLDispatch(ll, up, &mouse);
|
MwLLDispatch(ll, up, &mouse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)handleKeyEvent:(NSEvent *)ev {
|
- (void)handleKeyEvent:(NSEvent *)ev ll:(MwLL)ll {
|
||||||
int ch;
|
int ch;
|
||||||
MwLL this = [self->handle pointer];
|
MwLL this = [self->handle pointer];
|
||||||
enum {
|
enum {
|
||||||
|
|
@ -537,9 +547,11 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
switch ([ev type]) {
|
switch ([ev type]) {
|
||||||
case NSKeyDown:
|
case NSKeyDown:
|
||||||
MwLLDispatch(this, key, &ch);
|
MwLLDispatch(this, key, &ch);
|
||||||
|
MwLLDispatch(ll, key, &ch);
|
||||||
break;
|
break;
|
||||||
case NSKeyUp:
|
case NSKeyUp:
|
||||||
MwLLDispatch(this, key_released, &ch);
|
MwLLDispatch(this, key_released, &ch);
|
||||||
|
MwLLDispatch(ll, key_released, &ch);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
@ -711,9 +723,7 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
[self->window makeMainWindow];
|
[self->window makeMainWindow];
|
||||||
};
|
};
|
||||||
- (void)grabPointer:(int)toggle {
|
- (void)grabPointer:(int)toggle {
|
||||||
(void)toggle;
|
self->pointerLocked = toggle;
|
||||||
/* MacOS didn't have a "pointer grab" function
|
|
||||||
* until 10.13.2 so I need to do this manually */
|
|
||||||
};
|
};
|
||||||
- (void)setClipboard:(const char *)text {
|
- (void)setClipboard:(const char *)text {
|
||||||
(void)text;
|
(void)text;
|
||||||
|
|
@ -849,6 +859,14 @@ static NSPoint pointFlip(NSPoint point) {
|
||||||
(void)rect;
|
(void)rect;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
- (BOOL)acceptsFirstResponder {
|
||||||
|
return MwTRUE;
|
||||||
|
}
|
||||||
|
- (BOOL)performKeyEquivalent:(NSEvent *)event {
|
||||||
|
(void)event;
|
||||||
|
return MwTRUE;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation MilskoCocoaApplicationDelegate
|
@implementation MilskoCocoaApplicationDelegate
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue