aboutsummaryrefslogtreecommitdiffstats
path: root/pugl/detail
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-08-04 23:20:04 +0200
committerDavid Robillard <d@drobilla.net>2019-09-03 08:34:56 +0200
commit67a5799618186beecd0ea028101395de3569345f (patch)
treef0f264c0d3e9965a8143d6effd990f41bb306635 /pugl/detail
parent59359e4f3d81231e7c665aa53ceeba7de0671d95 (diff)
downloadpugl-67a5799618186beecd0ea028101395de3569345f.tar.gz
pugl-67a5799618186beecd0ea028101395de3569345f.tar.bz2
pugl-67a5799618186beecd0ea028101395de3569345f.zip
Make almost everything return a status
Prepares the API for proper error handling, even though there isn't any for these functions yet.
Diffstat (limited to 'pugl/detail')
-rw-r--r--pugl/detail/implementation.c9
-rw-r--r--pugl/detail/mac.m18
-rw-r--r--pugl/detail/win.c28
-rw-r--r--pugl/detail/x11.c22
4 files changed, 50 insertions, 27 deletions
diff --git a/pugl/detail/implementation.c b/pugl/detail/implementation.c
index abfd654..6ff71e2 100644
--- a/pugl/detail/implementation.c
+++ b/pugl/detail/implementation.c
@@ -190,22 +190,25 @@ puglGetContext(PuglView* view)
return view->backend->getContext(view);
}
-void
+PuglStatus
puglEnterContext(PuglView* view, bool drawing)
{
view->backend->enter(view, drawing);
+ return PUGL_SUCCESS;
}
-void
+PuglStatus
puglLeaveContext(PuglView* view, bool drawing)
{
view->backend->leave(view, drawing);
+ return PUGL_SUCCESS;
}
-void
+PuglStatus
puglSetEventFunc(PuglView* view, PuglEventFunc eventFunc)
{
view->eventFunc = eventFunc;
+ return PUGL_SUCCESS;
}
/** Return the code point for buf, or the replacement character on error. */
diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m
index bf845fc..8570709 100644
--- a/pugl/detail/mac.m
+++ b/pugl/detail/mac.m
@@ -713,7 +713,7 @@ puglConstraint(id item, NSLayoutAttribute attribute, float constant)
constant: constant];
}
-int
+PuglStatus
puglCreateWindow(PuglView* view, const char* title)
{
PuglInternals* impl = view->impl;
@@ -798,19 +798,21 @@ puglCreateWindow(PuglView* view, const char* title)
return 0;
}
-void
+PuglStatus
puglShowWindow(PuglView* view)
{
[view->impl->window setIsVisible:YES];
updateViewRect(view);
view->visible = true;
+ return PUGL_SUCCESS;
}
-void
+PuglStatus
puglHideWindow(PuglView* view)
{
[view->impl->window setIsVisible:NO];
view->visible = false;
+ return PUGL_SUCCESS;
}
void
@@ -829,13 +831,14 @@ puglFreeViewInternals(PuglView* view)
free(view->impl);
}
-void
+PuglStatus
puglGrabFocus(PuglView* view)
{
NSWindow* window = [view->impl->wrapperView window];
[window makeKeyWindow];
[window makeFirstResponder:view->impl->wrapperView];
+ return PUGL_SUCCESS;
}
bool
@@ -847,7 +850,7 @@ puglHasFocus(const PuglView* view)
[[impl->wrapperView window] firstResponder] == impl->wrapperView);
}
-void
+PuglStatus
puglRequestAttention(PuglView* view)
{
if (![view->impl->window isKeyWindow]) {
@@ -859,6 +862,8 @@ puglRequestAttention(PuglView* view)
userInfo:nil
repeats:YES];
}
+
+ return PUGL_SUCCESS;
}
PuglStatus
@@ -931,10 +936,11 @@ puglGetTime(const PuglWorld* world)
return (mach_absolute_time() / 1e9) - world->startTime;
}
-void
+PuglStatus
puglPostRedisplay(PuglView* view)
{
[view->impl->drawView setNeedsDisplay: YES];
+ return PUGL_SUCCESS;
}
PuglNativeWindow
diff --git a/pugl/detail/win.c b/pugl/detail/win.c
index e761654..7be1363 100644
--- a/pugl/detail/win.c
+++ b/pugl/detail/win.c
@@ -133,7 +133,7 @@ puglPollEvents(PuglWorld* world, const double timeout)
return PUGL_SUCCESS;
}
-int
+PuglStatus
puglCreateWindow(PuglView* view, const char* title)
{
PuglInternals* impl = view->impl;
@@ -147,18 +147,18 @@ puglCreateWindow(PuglView* view, const char* title)
// Register window class if necessary
if (!puglRegisterWindowClass(view->world->className)) {
- return 1;
+ return PUGL_ERR_UNKNOWN;
}
if (!view->backend || !view->backend->configure) {
- return 1;
+ return PUGL_ERR_UNKNOWN;
}
int st = view->backend->configure(view);
if (st || !impl->surface) {
- return 2;
+ return PUGL_ERR_SET_FORMAT;
} else if ((st = view->backend->create(view))) {
- return 3;
+ return PUGL_ERR_CREATE_CONTEXT;
}
if (title) {
@@ -167,10 +167,10 @@ puglCreateWindow(PuglView* view, const char* title)
SetWindowLongPtr(impl->hwnd, GWLP_USERDATA, (LONG_PTR)view);
- return 0;
+ return PUGL_SUCCESS;
}
-void
+PuglStatus
puglShowWindow(PuglView* view)
{
PuglInternals* impl = view->impl;
@@ -178,15 +178,17 @@ puglShowWindow(PuglView* view)
ShowWindow(impl->hwnd, SW_SHOWNORMAL);
SetFocus(impl->hwnd);
view->visible = true;
+ return PUGL_SUCCESS;
}
-void
+PuglStatus
puglHideWindow(PuglView* view)
{
PuglInternals* impl = view->impl;
ShowWindow(impl->hwnd, SW_HIDE);
view->visible = false;
+ return PUGL_SUCCESS;
}
void
@@ -658,10 +660,11 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
return 0;
}
-void
+PuglStatus
puglGrabFocus(PuglView* view)
{
SetFocus(view->impl->hwnd);
+ return PUGL_SUCCESS;
}
bool
@@ -670,7 +673,7 @@ puglHasFocus(const PuglView* view)
return GetFocus() == view->impl->hwnd;
}
-void
+PuglStatus
puglRequestAttention(PuglView* view)
{
if (!view->impl->mouseTracked || !puglHasFocus(view)) {
@@ -678,6 +681,8 @@ puglRequestAttention(PuglView* view)
SetTimer(view->impl->hwnd, PUGL_URGENT_TIMER_ID, 500, NULL);
view->impl->flashing = true;
}
+
+ return PUGL_SUCCESS;
}
PuglStatus
@@ -760,11 +765,12 @@ puglGetTime(const PuglWorld* world)
world->startTime);
}
-void
+PuglStatus
puglPostRedisplay(PuglView* view)
{
InvalidateRect(view->impl->hwnd, NULL, false);
view->redisplay = true;
+ return PUGL_SUCCESS;
}
PuglNativeWindow
diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c
index e4da9d9..43cfb18 100644
--- a/pugl/detail/x11.c
+++ b/pugl/detail/x11.c
@@ -168,7 +168,7 @@ getSizeHints(const PuglView* view)
return sizeHints;
}
-int
+PuglStatus
puglCreateWindow(PuglView* view, const char* title)
{
PuglInternals* const impl = view->impl;
@@ -239,19 +239,21 @@ puglCreateWindow(PuglView* view, const char* title)
return 0;
}
-void
+PuglStatus
puglShowWindow(PuglView* view)
{
XMapRaised(view->impl->display, view->impl->win);
puglPostRedisplay(view);
view->visible = true;
+ return PUGL_SUCCESS;
}
-void
+PuglStatus
puglHideWindow(PuglView* view)
{
XUnmapWindow(view->impl->display, view->impl->win);
view->visible = false;
+ return PUGL_SUCCESS;
}
void
@@ -514,11 +516,12 @@ translateEvent(PuglView* view, XEvent xevent)
return event;
}
-void
+PuglStatus
puglGrabFocus(PuglView* view)
{
XSetInputFocus(
view->impl->display, view->impl->win, RevertToNone, CurrentTime);
+ return PUGL_SUCCESS;
}
bool
@@ -530,7 +533,7 @@ puglHasFocus(const PuglView* view)
return focusedWindow == view->impl->win;
}
-void
+PuglStatus
puglRequestAttention(PuglView* view)
{
PuglInternals* const impl = view->impl;
@@ -553,6 +556,8 @@ puglRequestAttention(PuglView* view)
False,
SubstructureNotifyMask | SubstructureRedirectMask,
&event);
+
+ return PUGL_SUCCESS;
}
PuglStatus
@@ -697,10 +702,11 @@ puglGetTime(const PuglWorld* world)
return ((double)ts.tv_sec + ts.tv_nsec / 1000000000.0) - world->startTime;
}
-void
+PuglStatus
puglPostRedisplay(PuglView* view)
{
view->redisplay = true;
+ return PUGL_SUCCESS;
}
PuglNativeWindow
@@ -777,7 +783,7 @@ puglSetAspectRatio(PuglView* const view,
return PUGL_SUCCESS;
}
-void
+PuglStatus
puglSetTransientFor(PuglView* view, PuglNativeWindow parent)
{
Display* display = view->world->impl->display;
@@ -788,4 +794,6 @@ puglSetTransientFor(PuglView* view, PuglNativeWindow parent)
XSetTransientForHint(display, view->impl->win,
(Window)view->transientParent);
}
+
+ return PUGL_SUCCESS;
}