aboutsummaryrefslogtreecommitdiffstats
path: root/pugl/pugl_x11.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-04-29 02:53:47 +0000
committerDavid Robillard <d@drobilla.net>2012-04-29 02:53:47 +0000
commit4e6368d019e2543e6bf792f182486732d6f5a3f5 (patch)
tree4c2545feea12ebacfda281c9905a410820c55fe1 /pugl/pugl_x11.c
parente346dc20fb1fcbc8f895d7c46e3ec54628d3db0c (diff)
downloadpugl-4e6368d019e2543e6bf792f182486732d6f5a3f5.tar.gz
pugl-4e6368d019e2543e6bf792f182486732d6f5a3f5.tar.bz2
pugl-4e6368d019e2543e6bf792f182486732d6f5a3f5.zip
Proper key press and release support on X11.
Clearer mouse callback API.
Diffstat (limited to 'pugl/pugl_x11.c')
-rw-r--r--pugl/pugl_x11.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c
index 33f0b42..5844f2d 100644
--- a/pugl/pugl_x11.c
+++ b/pugl/pugl_x11.c
@@ -104,7 +104,8 @@ puglCreate(PuglNativeWindow parent, const char* title, int width, int height)
attr.border_pixel = 0;
attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask
- | ButtonPressMask | PointerMotionMask | StructureNotifyMask;
+ | ButtonPressMask | ButtonReleaseMask
+ | PointerMotionMask | StructureNotifyMask;
impl->win = XCreateWindow(
impl->display, xParent,
@@ -194,20 +195,40 @@ puglProcessEvents(PuglWindow* win)
}
break;
case ButtonPress:
+ case ButtonRelease:
if (win->mouseFunc) {
win->mouseFunc(win,
- event.xbutton.button, event.xbutton.state,
+ event.xbutton.button, event.type == ButtonPress,
event.xbutton.x, event.xbutton.y);
}
break;
case KeyPress:
- case KeyRelease:
if (win->keyboardFunc) {
KeySym sym = XKeycodeToKeysym(
win->impl->display, event.xkey.keycode, 0);
win->keyboardFunc(win, event.type == KeyPress, sym);
}
break;
+ case KeyRelease: {
+ bool retriggered = false;
+ if (XEventsQueued(win->impl->display, QueuedAfterReading)) {
+ XEvent next;
+ XPeekEvent(win->impl->display, &next);
+ if (next.type == KeyPress &&
+ next.xkey.time == event.xkey.time &&
+ next.xkey.keycode == event.xkey.keycode) {
+ // Key repeat, ignore fake KeyPress event
+ XNextEvent(win->impl->display, &event);
+ retriggered = true;
+ }
+ }
+
+ if (!retriggered && win->keyboardFunc) {
+ KeySym sym = XKeycodeToKeysym(
+ win->impl->display, event.xkey.keycode, 0);
+ win->keyboardFunc(win, false, sym);
+ }
+ }
case ClientMessage:
if (!strcmp(XGetAtomName(win->impl->display,
event.xclient.message_type),