aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-06-07 19:40:54 -0400
committerDavid Robillard <d@drobilla.net>2022-06-07 21:17:22 -0400
commitbc1419ec41543ba75381c24c5151ff35a012ac0e (patch)
tree0a6711528ea3b5d7f98b02bab8b1c7fc531c366c
parentd462f742adfbb1188105d5b7470aa4ddc4ac80fd (diff)
downloadpugl-bc1419ec41543ba75381c24c5151ff35a012ac0e.tar.gz
pugl-bc1419ec41543ba75381c24c5151ff35a012ac0e.tar.bz2
pugl-bc1419ec41543ba75381c24c5151ff35a012ac0e.zip
X11: Simplify dispatchX11Events()
-rw-r--r--src/x11.c75
1 files changed, 44 insertions, 31 deletions
diff --git a/src/x11.c b/src/x11.c
index 7800fed..1be6a8e 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -808,11 +808,9 @@ translateEvent(PuglView* const view, XEvent xevent)
event = translatePropertyNotify(view, xevent.xproperty);
break;
case VisibilityNotify:
- if (xevent.xvisibility.state == VisibilityFullyObscured) {
- event.type = PUGL_UNMAP;
- } else {
- event.type = PUGL_MAP;
- }
+ event.type = (xevent.xvisibility.state == VisibilityFullyObscured)
+ ? PUGL_UNMAP
+ : PUGL_MAP;
break;
case MapNotify:
event.type = PUGL_MAP;
@@ -1370,6 +1368,23 @@ handleTimerEvent(PuglWorld* const world, const XEvent xevent)
}
static PuglStatus
+dispatchCurrentConfiguration(PuglView* const view)
+{
+ // Get initial window position and size
+ XWindowAttributes attrs;
+ XGetWindowAttributes(view->world->impl->display, view->impl->win, &attrs);
+
+ // Build an initial configure event in case the WM doesn't send one
+ PuglEvent configureEvent = {{PUGL_CONFIGURE, 0}};
+ configureEvent.configure.x = (PuglCoord)attrs.x;
+ configureEvent.configure.y = (PuglCoord)attrs.y;
+ configureEvent.configure.width = (PuglSpan)attrs.width;
+ configureEvent.configure.height = (PuglSpan)attrs.height;
+
+ return puglDispatchEvent(view, &configureEvent);
+}
+
+static PuglStatus
dispatchX11Events(PuglWorld* const world)
{
PuglStatus st0 = PUGL_SUCCESS;
@@ -1402,14 +1417,6 @@ dispatchX11Events(PuglWorld* const world)
next.xkey.keycode == xevent.xkey.keycode) {
continue;
}
- } else if (xevent.type == FocusIn) {
- if (impl->xic) {
- XSetICFocus(impl->xic);
- }
- } else if (xevent.type == FocusOut) {
- if (impl->xic) {
- XUnsetICFocus(impl->xic);
- }
} else if (xevent.type == SelectionClear) {
PuglX11Clipboard* const board =
getX11SelectionClipboard(view, xevent.xselectionclear.selection);
@@ -1425,30 +1432,36 @@ dispatchX11Events(PuglWorld* const world)
// Translate X11 event to Pugl event
const PuglEvent event = translateEvent(view, xevent);
- if (event.type == PUGL_EXPOSE) {
- // Expand expose event to be dispatched after loop
- mergeExposeEvents(&view->impl->pendingExpose.expose, &event.expose);
- } else if (event.type == PUGL_CONFIGURE) {
+ switch (event.type) {
+ case PUGL_CONFIGURE:
// Update configure event to be dispatched after loop
view->impl->pendingConfigure = event;
- } else if (event.type == PUGL_MAP) {
- // Get initial window position and size
- XWindowAttributes attrs;
- XGetWindowAttributes(view->world->impl->display, view->impl->win, &attrs);
-
- // Build an initial configure event in case the WM doesn't send one
- PuglEvent configureEvent = {{PUGL_CONFIGURE, 0}};
- configureEvent.configure.x = (PuglCoord)attrs.x;
- configureEvent.configure.y = (PuglCoord)attrs.y;
- configureEvent.configure.width = (PuglSpan)attrs.width;
- configureEvent.configure.height = (PuglSpan)attrs.height;
-
+ break;
+ case PUGL_MAP:
// Dispatch an initial configure (if necessary), then the map event
- st0 = puglDispatchEvent(view, &configureEvent);
+ st0 = dispatchCurrentConfiguration(view);
st1 = puglDispatchEvent(view, &event);
- } else {
+ break;
+ case PUGL_EXPOSE:
+ // Expand expose event to be dispatched after loop
+ mergeExposeEvents(&view->impl->pendingExpose.expose, &event.expose);
+ break;
+ case PUGL_FOCUS_IN:
+ // Set the input context focus
+ if (impl->xic) {
+ XSetICFocus(impl->xic);
+ }
+ break;
+ case PUGL_FOCUS_OUT:
+ // Unset the input context focus
+ if (impl->xic) {
+ XUnsetICFocus(impl->xic);
+ }
+ break;
+ default:
// Dispatch event to application immediately
st0 = puglDispatchEvent(view, &event);
+ break;
}
}