aboutsummaryrefslogtreecommitdiff
path: root/pugl
diff options
context:
space:
mode:
authorGravatar David Robillard <d@drobilla.net>2016-09-01 22:26:22 -0400
committerGravatar David Robillard <d@drobilla.net>2016-09-01 22:26:22 -0400
commit02d2704a0be7443907f5752c00b71feb58cc11dd (patch)
treef2d22fd08c10b2ff1f7762d0dc8feb3561aafa5d /pugl
parent252421757e4e8ca9f482f2885ef9c09492c06757 (diff)
downloadsynthpod-02d2704a0be7443907f5752c00b71feb58cc11dd.zip
synthpod-02d2704a0be7443907f5752c00b71feb58cc11dd.tar.gz
synthpod-02d2704a0be7443907f5752c00b71feb58cc11dd.tar.bz2
synthpod-02d2704a0be7443907f5752c00b71feb58cc11dd.tar.xz
Add PUGL_CLOSE event
This allows purely event-driven applications to handle window close. Something more extensible for WM message seems like it might be a good idea here, but I can't think of specific uses, so this will do.
Diffstat (limited to 'pugl')
-rw-r--r--pugl/event.h10
-rw-r--r--pugl/pugl_internal.h6
-rw-r--r--pugl/pugl_osx.m9
-rw-r--r--pugl/pugl_win.cpp5
-rw-r--r--pugl/pugl_x11.c20
5 files changed, 33 insertions, 17 deletions
diff --git a/pugl/event.h b/pugl/event.h
index 2c48369..8ed1b2e 100644
--- a/pugl/event.h
+++ b/pugl/event.h
@@ -38,6 +38,7 @@ typedef enum {
PUGL_BUTTON_RELEASE,
PUGL_CONFIGURE,
PUGL_EXPOSE,
+ PUGL_CLOSE,
PUGL_KEY_PRESS,
PUGL_KEY_RELEASE,
PUGL_ENTER_NOTIFY,
@@ -117,6 +118,15 @@ typedef struct {
} PuglEventExpose;
/**
+ Window close event.
+*/
+typedef struct {
+ PuglEventType type; /**< PUGL_CLOSE. */
+ PuglView* view; /**< View that received this event. */
+ uint32_t flags; /**< Bitwise OR of PuglEventFlag values. */
+} PuglEventClose;
+
+/**
Key press/release event.
Keys that correspond to a Unicode character have `character` and `utf8` set.
diff --git a/pugl/pugl_internal.h b/pugl/pugl_internal.h
index 23abebf..d4ba126 100644
--- a/pugl/pugl_internal.h
+++ b/pugl/pugl_internal.h
@@ -324,6 +324,12 @@ puglDispatchEvent(PuglView* view, const PuglEvent* event)
puglLeaveContext(view, true);
}
break;
+ case PUGL_CLOSE:
+ if (view->closeFunc) {
+ view->closeFunc(view);
+ }
+ view->redisplay = false;
+ break;
case PUGL_MOTION_NOTIFY:
view->event_timestamp_ms = event->motion.time;
view->mods = event->motion.state;
diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m
index ecf9373..72e4da9 100644
--- a/pugl/pugl_osx.m
+++ b/pugl/pugl_osx.m
@@ -82,8 +82,13 @@ struct PuglInternalsImpl {
- (BOOL)windowShouldClose:(id)sender
{
- if (puglview->closeFunc)
- puglview->closeFunc(puglview);
+ const PuglEventClose ev = {
+ PUGL_CLOSE,
+ puglview,
+ 0
+ };
+ puglDispatchEvent(puglview, (PuglEvent*)&ev);
+
return YES;
}
diff --git a/pugl/pugl_win.cpp b/pugl/pugl_win.cpp
index c061f25..eb87197 100644
--- a/pugl/pugl_win.cpp
+++ b/pugl/pugl_win.cpp
@@ -574,10 +574,7 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_QUIT:
case PUGL_LOCAL_CLOSE_MSG:
- if (view->closeFunc) {
- view->closeFunc(view);
- view->redisplay = false;
- }
+ event.close.type = PUGL_CLOSE;
break;
default:
return DefWindowProc(
diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c
index 4d7010b..f91aa24 100644
--- a/pugl/pugl_x11.c
+++ b/pugl/pugl_x11.c
@@ -461,6 +461,14 @@ translateEvent(PuglView* view, XEvent xevent)
}
switch (xevent.type) {
+ case ClientMessage: {
+ char* type = XGetAtomName(view->impl->display,
+ xevent.xclient.message_type);
+ if (!strcmp(type, "WM_PROTOCOLS")) {
+ event.type = PUGL_CLOSE;
+ }
+ break;
+ }
case ConfigureNotify:
event.type = PUGL_CONFIGURE;
event.configure.x = xevent.xconfigure.x;
@@ -605,17 +613,7 @@ puglProcessEvents(PuglView* view)
XEvent xevent;
while (XPending(view->impl->display) > 0) {
XNextEvent(view->impl->display, &xevent);
- if (xevent.type == ClientMessage) {
- // Handle close message
- char* type = XGetAtomName(view->impl->display,
- xevent.xclient.message_type);
- if (!strcmp(type, "WM_PROTOCOLS") && view->closeFunc) {
- view->closeFunc(view);
- view->redisplay = false;
- }
- XFree(type);
- continue;
- } else if (xevent.type == KeyRelease) {
+ if (xevent.type == KeyRelease) {
// Ignore key repeat if necessary
if (view->ignoreKeyRepeat &&
XEventsQueued(view->impl->display, QueuedAfterReading)) {