diff options
author | David Robillard <d@drobilla.net> | 2020-03-09 21:49:57 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-03-09 22:17:44 +0100 |
commit | a303b9374dbb9eeef1a31dcad3cb0a4e9b7fd5a3 (patch) | |
tree | b0da0689c1a8c0e3678fdd4c86ec6cf3e5b234a1 /pugl/detail | |
parent | 9c82ba0aa44856130479de0667ee4cf2be1f2b37 (diff) | |
download | pugl-a303b9374dbb9eeef1a31dcad3cb0a4e9b7fd5a3.tar.gz pugl-a303b9374dbb9eeef1a31dcad3cb0a4e9b7fd5a3.tar.bz2 pugl-a303b9374dbb9eeef1a31dcad3cb0a4e9b7fd5a3.zip |
X11: Factor out converting PuglEventExpose to XExposeEvent
Diffstat (limited to 'pugl/detail')
-rw-r--r-- | pugl/detail/x11.c | 66 |
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; |