diff options
author | David Robillard <d@drobilla.net> | 2019-08-04 23:20:04 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-09-03 08:34:56 +0200 |
commit | 67a5799618186beecd0ea028101395de3569345f (patch) | |
tree | f0f264c0d3e9965a8143d6effd990f41bb306635 /pugl | |
parent | 59359e4f3d81231e7c665aa53ceeba7de0671d95 (diff) | |
download | pugl-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')
-rw-r--r-- | pugl/detail/implementation.c | 9 | ||||
-rw-r--r-- | pugl/detail/mac.m | 18 | ||||
-rw-r--r-- | pugl/detail/win.c | 28 | ||||
-rw-r--r-- | pugl/detail/x11.c | 22 | ||||
-rw-r--r-- | pugl/pugl.h | 20 |
5 files changed, 60 insertions, 37 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; } diff --git a/pugl/pugl.h b/pugl/pugl.h index 51c86a1..4182225 100644 --- a/pugl/pugl.h +++ b/pugl/pugl.h @@ -561,7 +561,7 @@ puglGetVisible(PuglView* view); /** Request a redisplay on the next call to puglDispatchEvents(). */ -PUGL_API void +PUGL_API PuglStatus puglPostRedisplay(PuglView* view); /** @@ -636,7 +636,7 @@ puglSetParentWindow(PuglView* view, PuglNativeWindow parent); This is used for things like dialogs, to have them associated with the window they are a transient child of properly. */ -PUGL_API void +PUGL_API PuglStatus puglSetTransientFor(PuglView* view, PuglNativeWindow parent); /** @@ -644,19 +644,19 @@ puglSetTransientFor(PuglView* view, PuglNativeWindow parent); @return 1 (pugl does not currently support multiple windows). */ -PUGL_API int +PUGL_API PuglStatus puglCreateWindow(PuglView* view, const char* title); /** Show the current window. */ -PUGL_API void +PUGL_API PuglStatus puglShowWindow(PuglView* view); /** Hide the current window. */ -PUGL_API void +PUGL_API PuglStatus puglHideWindow(PuglView* view); /** @@ -716,7 +716,7 @@ puglGetContext(PuglView* view); @param view The view being entered. @param drawing If true, prepare for drawing. */ -PUGL_API void +PUGL_API PuglStatus puglEnterContext(PuglView* view, bool drawing); /** @@ -728,7 +728,7 @@ puglEnterContext(PuglView* view, bool drawing); @param view The view being left. @param drawing If true, finish drawing, for example by swapping buffers. */ -PUGL_API void +PUGL_API PuglStatus puglLeaveContext(PuglView* view, bool drawing); /** @@ -745,7 +745,7 @@ typedef PuglStatus (*PuglEventFunc)(PuglView* view, const PuglEvent* event); /** Set the function to call when an event occurs. */ -PUGL_API void +PUGL_API PuglStatus puglSetEventFunc(PuglView* view, PuglEventFunc eventFunc); /** @@ -757,7 +757,7 @@ puglHasFocus(const PuglView* view); /** Grab the input focus. */ -PUGL_API void +PUGL_API PuglStatus puglGrabFocus(PuglView* view); /** @@ -767,7 +767,7 @@ puglGrabFocus(PuglView* view); from the user. The exact effect depends on the platform, but is usually something like flashing a task bar entry. */ -PUGL_API void +PUGL_API PuglStatus puglRequestAttention(PuglView* view); /** |