From 23a1b165950d2f7b738ed42144e1569f0c82793c Mon Sep 17 00:00:00 2001
From: David Robillard <d@drobilla.net>
Date: Mon, 2 Jan 2023 17:04:12 -0500
Subject: X11: Factor out getCurrentConfiguration

---
 src/x11.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/x11.c b/src/x11.c
index b7b78f2..271a0fb 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -753,6 +753,23 @@ translateClientMessage(PuglView* const view, XClientMessageEvent message)
   return event;
 }
 
+static PuglEvent
+getCurrentConfiguration(PuglView* const view)
+{
+  // Get initial window position and size
+  XWindowAttributes attrs;
+  XGetWindowAttributes(view->world->impl->display, view->impl->win, &attrs);
+
+  // Build a configure event with the current position and size
+  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 configureEvent;
+}
+
 static PuglEvent
 translatePropertyNotify(PuglView* const view, XPropertyEvent message)
 {
@@ -1362,17 +1379,7 @@ 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;
-
+  const PuglEvent configureEvent = getCurrentConfiguration(view);
   return puglDispatchEvent(view, &configureEvent);
 }
 
-- 
cgit v1.2.1