aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/win.c62
-rw-r--r--src/x11.c65
2 files changed, 65 insertions, 62 deletions
diff --git a/src/win.c b/src/win.c
index 53f7142..93d9eef 100644
--- a/src/win.c
+++ b/src/win.c
@@ -85,6 +85,12 @@ puglWideCharToUtf8(const wchar_t* const wstr, size_t* len)
return NULL;
}
+static PuglStatus
+puglWinStatus(const BOOL success)
+{
+ return success ? PUGL_SUCCESS : PUGL_UNKNOWN_ERROR;
+}
+
static bool
puglRegisterWindowClass(const char* name)
{
@@ -1002,9 +1008,7 @@ puglStartTimer(PuglView* view, uintptr_t id, double timeout)
PuglStatus
puglStopTimer(PuglView* view, uintptr_t id)
{
- return (KillTimer(view->impl->hwnd, PUGL_USER_TIMER_MIN + id)
- ? PUGL_SUCCESS
- : PUGL_UNKNOWN_ERROR);
+ return puglWinStatus(KillTimer(view->impl->hwnd, PUGL_USER_TIMER_MIN + id));
}
PuglStatus
@@ -1232,15 +1236,14 @@ puglSetFrame(PuglView* view, const PuglRect frame)
const RECT rect =
adjustedWindowRect(view, frame.x, frame.y, frame.width, frame.height);
- return SetWindowPos(view->impl->hwnd,
- HWND_TOP,
- rect.left,
- rect.top,
- rect.right - rect.left,
- rect.bottom - rect.top,
- SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER)
- ? PUGL_SUCCESS
- : PUGL_UNKNOWN_ERROR;
+ return puglWinStatus(
+ SetWindowPos(view->impl->hwnd,
+ HWND_TOP,
+ rect.left,
+ rect.top,
+ rect.right - rect.left,
+ rect.bottom - rect.top,
+ SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER));
}
PuglStatus
@@ -1260,16 +1263,11 @@ puglSetPosition(PuglView* const view, const int x, const int y)
const RECT rect = adjustedWindowRect(
view, x, y, view->lastConfigure.width, view->lastConfigure.height);
- return SetWindowPos(view->impl->hwnd,
- HWND_TOP,
- rect.left,
- rect.top,
- 0,
- 0,
- SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER |
- SWP_NOSIZE)
- ? PUGL_SUCCESS
- : PUGL_UNKNOWN_ERROR;
+ const UINT flags =
+ SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSIZE;
+
+ return puglWinStatus(
+ SetWindowPos(view->impl->hwnd, HWND_TOP, rect.left, rect.top, 0, 0, flags));
}
PuglStatus
@@ -1292,16 +1290,16 @@ puglSetSize(PuglView* const view, const unsigned width, const unsigned height)
(long)width,
(long)height);
- return SetWindowPos(view->impl->hwnd,
- HWND_TOP,
- 0,
- 0,
- rect.right - rect.left,
- rect.bottom - rect.top,
- SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER |
- SWP_NOMOVE)
- ? PUGL_SUCCESS
- : PUGL_UNKNOWN_ERROR;
+ const UINT flags =
+ SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOMOVE;
+
+ return puglWinStatus(SetWindowPos(view->impl->hwnd,
+ HWND_TOP,
+ 0,
+ 0,
+ rect.right - rect.left,
+ rect.bottom - rect.top,
+ flags));
}
PuglStatus
diff --git a/src/x11.c b/src/x11.c
index 4eb87ce..5dc92e5 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -99,6 +99,21 @@ static const char* const cursorNames[PUGL_NUM_CURSORS] = {
};
#endif
+/**
+ Convert a return code from an Xlib function to a PuglStatus.
+
+ Careful, Xlib returns are wildly inconsistent, often undocumented, and
+ sometimes even use misleading types (for example, a Status that is actually
+ used as a boolean). The only way to know for a given function is to read
+ the source. For the most part, though, being a remote display protocol,
+ errors are handled asynchronously and return values mean nothing.
+*/
+static PuglStatus
+puglX11Status(const int returnCode)
+{
+ return returnCode ? PUGL_SUCCESS : PUGL_UNKNOWN_ERROR;
+}
+
static bool
initXSync(PuglWorldInternals* const impl)
{
@@ -1480,19 +1495,17 @@ puglSendEvent(PuglView* const view, const PuglEvent* const event)
xev.xclient.data.l[0] = CurrentTime;
xev.xclient.data.l[1] = 1;
- return XSendEvent(display,
- RootWindow(display, impl->screen),
- False,
- SubstructureNotifyMask | SubstructureRedirectMask,
- &xev)
- ? PUGL_SUCCESS
- : PUGL_UNKNOWN_ERROR;
+ return puglX11Status(
+ XSendEvent(display,
+ RootWindow(display, impl->screen),
+ False,
+ SubstructureNotifyMask | SubstructureRedirectMask,
+ &xev));
}
xev = eventToX(view, event);
if (xev.type) {
- return XSendEvent(display, impl->win, False, 0, &xev) ? PUGL_SUCCESS
- : PUGL_UNKNOWN_ERROR;
+ return puglX11Status(XSendEvent(display, impl->win, False, 0, &xev));
}
return PUGL_UNSUPPORTED;
@@ -1659,10 +1672,8 @@ handleSelectionRequest(const PuglWorld* const world,
request->property,
request->time};
- return XSendEvent(
- world->impl->display, note.requestor, True, 0, (XEvent*)&note)
- ? PUGL_SUCCESS
- : PUGL_UNKNOWN_ERROR;
+ return puglX11Status(
+ XSendEvent(world->impl->display, note.requestor, True, 0, (XEvent*)&note));
}
/// Flush pending configure and expose events for all views
@@ -1952,14 +1963,12 @@ puglSetFrame(PuglView* const view, const PuglRect frame)
return PUGL_SUCCESS;
}
- return XMoveResizeWindow(view->world->impl->display,
- view->impl->win,
- frame.x,
- frame.y,
- frame.width,
- frame.height)
- ? PUGL_SUCCESS
- : PUGL_UNKNOWN_ERROR;
+ return puglX11Status(XMoveResizeWindow(view->world->impl->display,
+ view->impl->win,
+ frame.x,
+ frame.y,
+ frame.width,
+ frame.height));
}
PuglStatus
@@ -1978,12 +1987,10 @@ puglSetPosition(PuglView* const view, const int x, const int y)
return PUGL_SUCCESS;
}
- return XMoveWindow(display,
- view->impl->win,
- (int)(x - view->impl->frameExtentLeft),
- (int)(y - view->impl->frameExtentTop))
- ? PUGL_SUCCESS
- : PUGL_UNKNOWN_ERROR;
+ return puglX11Status(XMoveWindow(display,
+ view->impl->win,
+ (int)(x - view->impl->frameExtentLeft),
+ (int)(y - view->impl->frameExtentTop)));
}
PuglStatus
@@ -2002,9 +2009,7 @@ puglSetSize(PuglView* const view, const unsigned width, const unsigned height)
return PUGL_SUCCESS;
}
- return XResizeWindow(display, view->impl->win, width, height)
- ? PUGL_SUCCESS
- : PUGL_UNKNOWN_ERROR;
+ return puglX11Status(XResizeWindow(display, view->impl->win, width, height));
}
PuglStatus