aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pugl/pugl.h12
-rw-r--r--pugl/pugl_win.cpp41
-rw-r--r--pugl/pugl_x11.c40
3 files changed, 63 insertions, 30 deletions
diff --git a/pugl/pugl.h b/pugl/pugl.h
index 5473e5f..45e1653 100644
--- a/pugl/pugl.h
+++ b/pugl/pugl.h
@@ -117,14 +117,10 @@ typedef enum {
PUGL_KEY_HOME,
PUGL_KEY_END,
PUGL_KEY_INSERT,
- PUGL_KEY_SHIFT_L,
- PUGL_KEY_SHIFT_R,
- PUGL_KEY_CTRL_L,
- PUGL_KEY_CTRL_R,
- PUGL_KEY_ALT_L,
- PUGL_KEY_ALT_R,
- PUGL_KEY_SUPER_L,
- PUGL_KEY_SUPER_R
+ PUGL_KEY_SHIFT,
+ PUGL_KEY_CTRL,
+ PUGL_KEY_ALT,
+ PUGL_KEY_SUPER,
} PuglKey;
/**
diff --git a/pugl/pugl_win.cpp b/pugl/pugl_win.cpp
index a5c9dde..2cb135c 100644
--- a/pugl/pugl_win.cpp
+++ b/pugl/pugl_win.cpp
@@ -152,6 +152,40 @@ puglDisplay(PuglView* view)
view->redisplay = false;
}
+static PuglKey
+keySymToSpecial(int sym)
+{
+ switch (sym) {
+ case VK_F1: return PUGL_KEY_F1;
+ case VK_F2: return PUGL_KEY_F2;
+ case VK_F3: return PUGL_KEY_F3;
+ case VK_F4: return PUGL_KEY_F4;
+ case VK_F5: return PUGL_KEY_F5;
+ case VK_F6: return PUGL_KEY_F6;
+ case VK_F7: return PUGL_KEY_F7;
+ case VK_F8: return PUGL_KEY_F8;
+ case VK_F9: return PUGL_KEY_F9;
+ case VK_F10: return PUGL_KEY_F10;
+ case VK_F11: return PUGL_KEY_F11;
+ case VK_F12: return PUGL_KEY_F12;
+ case VK_LEFT: return PUGL_KEY_LEFT;
+ case VK_UP: return PUGL_KEY_UP;
+ case VK_RIGHT: return PUGL_KEY_RIGHT;
+ case VK_DOWN: return PUGL_KEY_DOWN;
+ case VK_PRIOR: return PUGL_KEY_PAGE_UP;
+ case VK_NEXT: return PUGL_KEY_PAGE_DOWN;
+ case VK_HOME: return PUGL_KEY_HOME;
+ case VK_END: return PUGL_KEY_END;
+ case VK_INSERT: return PUGL_KEY_INSERT;
+ case VK_SHIFT: return PUGL_KEY_SHIFT;
+ case VK_CONTROL: return PUGL_KEY_CTRL;
+ case VK_MENU: return PUGL_KEY_ALT;
+ case VK_LWIN: return PUGL_KEY_SUPER;
+ case VK_RWIN: return PUGL_KEY_SUPER;
+ }
+ return (PuglKey)0;
+}
+
static void
processMouseEvent(PuglView* view, int button, bool press, LPARAM lParam)
{
@@ -169,6 +203,7 @@ puglProcessEvents(PuglView* view)
PAINTSTRUCT ps;
int button;
bool down = true;
+ PuglKey key;
while (PeekMessage(&msg, /*view->impl->hwnd*/0, 0, 0, PM_REMOVE)) {
switch (msg.message) {
case WM_CREATE:
@@ -219,7 +254,11 @@ puglProcessEvents(PuglView* view)
break;
case WM_KEYDOWN:
case WM_KEYUP:
- if (view->keyboardFunc) {
+ if (key = keySymToSpecial(msg.wParam)) {
+ if (view->specialFunc) {
+ view->specialFunc(view, msg.message == WM_KEYDOWN, key);
+ }
+ } else if (view->keyboardFunc) {
view->keyboardFunc(view, msg.message == WM_KEYDOWN, msg.wParam);
}
break;
diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c
index b22b1ce..c180a9a 100644
--- a/pugl/pugl_x11.c
+++ b/pugl/pugl_x11.c
@@ -232,14 +232,14 @@ keySymToSpecial(KeySym sym)
case XK_Home: return PUGL_KEY_HOME;
case XK_End: return PUGL_KEY_END;
case XK_Insert: return PUGL_KEY_INSERT;
- case XK_Shift_L: return PUGL_KEY_SHIFT_L;
- case XK_Shift_R: return PUGL_KEY_SHIFT_R;
- case XK_Control_L: return PUGL_KEY_CTRL_L;
- case XK_Control_R: return PUGL_KEY_CTRL_R;
- case XK_Alt_L: return PUGL_KEY_ALT_L;
- case XK_Alt_R: return PUGL_KEY_ALT_R;
- case XK_Super_L: return PUGL_KEY_SUPER_L;
- case XK_Super_R: return PUGL_KEY_SUPER_R;
+ case XK_Shift_L: return PUGL_KEY_SHIFT;
+ case XK_Shift_R: return PUGL_KEY_SHIFT;
+ case XK_Control_L: return PUGL_KEY_CTRL;
+ case XK_Control_R: return PUGL_KEY_CTRL;
+ case XK_Alt_L: return PUGL_KEY_ALT;
+ case XK_Alt_R: return PUGL_KEY_ALT;
+ case XK_Super_L: return PUGL_KEY_SUPER;
+ case XK_Super_R: return PUGL_KEY_SUPER;
}
return (PuglKey)0;
}
@@ -314,20 +314,18 @@ puglProcessEvents(PuglView* view)
break;
case KeyPress:
setModifiers(view, event.xkey.state);
- if (view->keyboardFunc) {
- KeySym sym;
- char str[5];
- int n = XLookupString(&event.xkey, str, 4, &sym, NULL);
- PuglKey key = keySymToSpecial(sym);
- if (!key) {
- if (n == 1) {
- view->keyboardFunc(view, true, str[0]);
- } else {
- fprintf(stderr, "warning: Unknown key %X\n", (int)sym);
- }
- } else if (view->specialFunc) {
- view->specialFunc(view, true, key);
+ KeySym sym;
+ char str[5];
+ int n = XLookupString(&event.xkey, str, 4, &sym, NULL);
+ PuglKey key = keySymToSpecial(sym);
+ if (!key && view->keyboardFunc) {
+ if (n == 1) {
+ view->keyboardFunc(view, true, str[0]);
+ } else {
+ fprintf(stderr, "warning: Unknown key %X\n", (int)sym);
}
+ } else if (view->specialFunc) {
+ view->specialFunc(view, true, key);
}
break;
case KeyRelease: {