diff options
author | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2017-02-24 16:20:07 +0100 |
---|---|---|
committer | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2017-02-24 16:20:07 +0100 |
commit | c977ef2968f22d0379a857aa2fe1668547bb50c0 (patch) | |
tree | 05e1c472ea4fbeb8e58c940bc4a8b84231fb7fed /pugl | |
parent | adaf38d0984087ba9b6281dde46749dfb29a2a38 (diff) | |
download | sherlock.lv2-c977ef2968f22d0379a857aa2fe1668547bb50c0.tar.xz |
Implement special key handling on MacOS
Diffstat (limited to 'pugl')
-rw-r--r-- | pugl/pugl_osx.m | 101 |
1 files changed, 84 insertions, 17 deletions
diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m index d2681cb..9f97f20 100644 --- a/pugl/pugl_osx.m +++ b/pugl/pugl_osx.m @@ -33,6 +33,7 @@ struct PuglInternalsImpl { PuglOpenGLView* glview; id window; NSEvent* nextEvent; + unsigned mods; #ifdef PUGL_HAVE_CAIRO cairo_surface_t* surface; cairo_t* cr; @@ -150,6 +151,9 @@ struct PuglInternalsImpl { NSOpenGLPFAAccelerated, NSOpenGLPFAColorSize, 32, NSOpenGLPFADepthSize, 32, + NSOpenGLPFAMultisample, + NSOpenGLPFASampleBuffers, 1, + NSOpenGLPFASamples, 4, 0 }; @@ -166,6 +170,7 @@ struct PuglInternalsImpl { if (self) { [[self openGLContext] makeCurrentContext]; [self reshape]; + [NSOpenGLContext clearCurrentContext]; } return self; } @@ -245,6 +250,39 @@ getModifiers(PuglView* view, NSEvent* ev) return mods; } +static PuglKey +keySymToSpecial(PuglView* view, NSEvent* ev) +{ + NSString* chars = [ev charactersIgnoringModifiers]; + if([chars length] == 1) { + switch ([chars characterAtIndex:0]) { + case NSF1FunctionKey: return PUGL_KEY_F1; + case NSF2FunctionKey: return PUGL_KEY_F2; + case NSF3FunctionKey: return PUGL_KEY_F3; + case NSF4FunctionKey: return PUGL_KEY_F4; + case NSF5FunctionKey: return PUGL_KEY_F5; + case NSF6FunctionKey: return PUGL_KEY_F6; + case NSF7FunctionKey: return PUGL_KEY_F7; + case NSF8FunctionKey: return PUGL_KEY_F8; + case NSF9FunctionKey: return PUGL_KEY_F9; + case NSF10FunctionKey: return PUGL_KEY_F10; + case NSF11FunctionKey: return PUGL_KEY_F11; + case NSF12FunctionKey: return PUGL_KEY_F12; + case NSLeftArrowFunctionKey: return PUGL_KEY_LEFT; + case NSUpArrowFunctionKey: return PUGL_KEY_UP; + case NSRightArrowFunctionKey: return PUGL_KEY_RIGHT; + case NSDownArrowFunctionKey: return PUGL_KEY_DOWN; + case NSPageUpFunctionKey: return PUGL_KEY_PAGE_UP; + case NSPageDownFunctionKey: return PUGL_KEY_PAGE_DOWN; + case NSHomeFunctionKey: return PUGL_KEY_HOME; + case NSEndFunctionKey: return PUGL_KEY_END; + case NSInsertFunctionKey: return PUGL_KEY_INSERT; + /* special keys (SHIFT, CTRL, ALT, SUPER) are handled in [flagsChanged] */ + } + } + return (PuglKey)0; +} + -(void)updateTrackingAreas { if (trackingArea != nil) { @@ -415,7 +453,7 @@ getModifiers(PuglView* view, NSEvent* ev) getModifiers(puglview, event), [event keyCode], puglDecodeUTF8((const uint8_t*)str), - 0, // TODO: Special keys? + keySymToSpecial(puglview, event), { 0, 0, 0, 0, 0, 0, 0, 0 }, false }; @@ -441,7 +479,7 @@ getModifiers(PuglView* view, NSEvent* ev) getModifiers(puglview, event), [event keyCode], puglDecodeUTF8((const uint8_t*)str), - 0, // TODO: Special keys? + keySymToSpecial(puglview, event), { 0, 0, 0, 0, 0, 0, 0, 0 }, false, }; @@ -451,21 +489,47 @@ getModifiers(PuglView* view, NSEvent* ev) - (void) flagsChanged:(NSEvent*)event { - // TODO: Is this a sensible way to handle special keys? - /* - const unsigned mods = getModifiers(puglview, event); - if ((mods & PUGL_MOD_SHIFT) != (puglview->mods & PUGL_MOD_SHIFT)) { - puglview->specialFunc(puglview, mods & PUGL_MOD_SHIFT, PUGL_KEY_SHIFT); - } else if ((mods & PUGL_MOD_CTRL) != (puglview->mods & PUGL_MOD_CTRL)) { - puglview->specialFunc(puglview, mods & PUGL_MOD_CTRL, PUGL_KEY_CTRL); - } else if ((mods & PUGL_MOD_ALT) != (puglview->mods & PUGL_MOD_ALT)) { - puglview->specialFunc(puglview, mods & PUGL_MOD_ALT, PUGL_KEY_ALT); - } else if ((mods & PUGL_MOD_SUPER) != (puglview->mods & PUGL_MOD_SUPER)) { - puglview->specialFunc(puglview, mods & PUGL_MOD_SUPER, PUGL_KEY_SUPER); - } - puglview->mods = mods; + const unsigned mods = getModifiers(puglview, event); + PuglEventType type = PUGL_NOTHING; + PuglKey special = 0; + + if ((mods & PUGL_MOD_SHIFT) != (puglview->impl->mods & PUGL_MOD_SHIFT)) { + type = mods & PUGL_MOD_SHIFT ? PUGL_KEY_PRESS : PUGL_KEY_RELEASE; + special = PUGL_KEY_SHIFT; + } else if ((mods & PUGL_MOD_CTRL) != (puglview->impl->mods & PUGL_MOD_CTRL)) { + type = mods & PUGL_MOD_CTRL ? PUGL_KEY_PRESS : PUGL_KEY_RELEASE; + special = PUGL_KEY_CTRL; + } else if ((mods & PUGL_MOD_ALT) != (puglview->impl->mods & PUGL_MOD_ALT)) { + type = mods & PUGL_MOD_ALT ? PUGL_KEY_PRESS : PUGL_KEY_RELEASE; + special = PUGL_KEY_ALT; + } else if ((mods & PUGL_MOD_SUPER) != (puglview->impl->mods & PUGL_MOD_SUPER)) { + type = mods & PUGL_MOD_SUPER ? PUGL_KEY_PRESS : PUGL_KEY_RELEASE; + special = PUGL_KEY_SUPER; + } + + if (special != 0) { + const NSPoint wloc = [self eventLocation:event]; + const NSPoint rloc = [NSEvent mouseLocation]; + PuglEventKey ev = { + type, + puglview, + 0, + [event timestamp], + wloc.x, + puglview->height - wloc.y, + rloc.x, + [[NSScreen mainScreen] frame].size.height - rloc.y, + mods, + [event keyCode], + 0, + special, + { 0, 0, 0, 0, 0, 0, 0, 0 }, + false + }; + puglDispatchEvent(puglview, (PuglEvent*)&ev); } - */ + + puglview->impl->mods = mods; } @end @@ -498,8 +562,11 @@ puglLeaveContext(PuglView* view, bool flush) #endif if (flush) { - [[view->impl->glview openGLContext] flushBuffer]; + //[[view->impl->glview openGLContext] flushBuffer]; + glFlush(); + glSwapAPPLE(); } + [NSOpenGLContext clearCurrentContext]; } int |