aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-03-09 21:49:57 +0100
committerDavid Robillard <d@drobilla.net>2020-03-09 22:17:44 +0100
commita303b9374dbb9eeef1a31dcad3cb0a4e9b7fd5a3 (patch)
treeb0da0689c1a8c0e3678fdd4c86ec6cf3e5b234a1
parent9c82ba0aa44856130479de0667ee4cf2be1f2b37 (diff)
X11: Factor out converting PuglEventExpose to XExposeEvent
-rw-r--r--pugl/detail/x11.c66
1 files changed, 50 insertions, 16 deletions
diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c
index bcc0b49..9c9fdfa 100644
--- a/pugl/detail/x11.c
+++ b/pugl/detail/x11.c
@@ -589,6 +589,51 @@ puglRequestAttention(PuglView* view)
return PUGL_SUCCESS;
}
+static XEvent
+puglEventToX(PuglView* view, const PuglEvent* event)
+{
+ XEvent xev = {0};
+ xev.xany.send_event = True;
+
+ switch (event->type) {
+ case PUGL_EXPOSE: {
+ const double x = floor(event->expose.x);
+ const double y = floor(event->expose.y);
+ const double w = ceil(event->expose.x + event->expose.width) - x;
+ const double h = ceil(event->expose.y + event->expose.height) - y;
+
+ xev.xexpose.type = Expose;
+ xev.xexpose.serial = 0;
+ xev.xexpose.display = view->impl->display;
+ xev.xexpose.window = view->impl->win;
+ xev.xexpose.x = (int)x;
+ xev.xexpose.y = (int)y;
+ xev.xexpose.width = (int)w;
+ xev.xexpose.height = (int)h;
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ return xev;
+}
+
+static PuglStatus
+puglSendEvent(PuglView* view, const PuglEvent* event)
+{
+ XEvent xev = puglEventToX(view, event);
+
+ if (xev.type) {
+ if (XSendEvent(view->impl->display, view->impl->win, False, 0, &xev)) {
+ return PUGL_SUCCESS;
+ }
+ }
+
+ return PUGL_UNSUPPORTED_TYPE;
+}
+
#ifndef PUGL_DISABLE_DEPRECATED
PuglStatus
puglWaitForEvent(PuglView* view)
@@ -794,27 +839,16 @@ puglPostRedisplay(PuglView* view)
PuglStatus
puglPostRedisplayRect(PuglView* view, PuglRect rect)
{
+ const PuglEventExpose event = {
+ PUGL_EXPOSE, 0, rect.x, rect.y, rect.width, rect.height, 0
+ };
+
if (view->world->impl->dispatchingEvents) {
// Currently dispatching events, add/expand expose for the loop end
- const PuglEventExpose event = {
- PUGL_EXPOSE, 0, rect.x, rect.y, rect.width, rect.height, 0
- };
-
mergeExposeEvents(&view->impl->pendingExpose, (const PuglEvent*)&event);
} else if (view->visible) {
// Not dispatching events, send an X expose so we wake up next time
- const double x = floor(rect.x);
- const double y = floor(rect.y);
- const double w = ceil(rect.x + rect.width) - x;
- const double h = ceil(rect.y + rect.height) - y;
-
- XExposeEvent ev = {Expose, 0, True,
- view->impl->display, view->impl->win,
- (int)x, (int)y,
- (int)w, (int)h,
- 0};
-
- XSendEvent(view->impl->display, view->impl->win, False, 0, (XEvent*)&ev);
+ return puglSendEvent(view, (const PuglEvent*)&event);
}
return PUGL_SUCCESS;