aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.c111
-rw-r--r--src/internal.c12
-rw-r--r--src/internal.h8
-rw-r--r--src/mac.h2
-rw-r--r--src/mac.m214
-rw-r--r--src/mac_cairo.m2
-rw-r--r--src/mac_gl.m2
-rw-r--r--src/mac_stub.m2
-rw-r--r--src/mac_vulkan.m6
-rw-r--r--src/platform.h8
-rw-r--r--src/stub.h2
-rw-r--r--src/types.h31
-rw-r--r--src/win.c232
-rw-r--r--src/win.h21
-rw-r--r--src/win_cairo.c2
-rw-r--r--src/win_gl.c2
-rw-r--r--src/win_stub.c2
-rw-r--r--src/win_vulkan.c2
-rw-r--r--src/x11.c148
-rw-r--r--src/x11.h8
-rw-r--r--src/x11_cairo.c4
-rw-r--r--src/x11_gl.c10
-rw-r--r--src/x11_stub.c4
-rw-r--r--src/x11_vulkan.c4
24 files changed, 345 insertions, 494 deletions
diff --git a/src/common.c b/src/common.c
index 2e6e0e6..c8ac3d4 100644
--- a/src/common.c
+++ b/src/common.c
@@ -4,14 +4,13 @@
// Common implementations of public API functions in the core library
#include "internal.h"
-
#include "platform.h"
#include "types.h"
-#include "pugl/pugl.h"
+#include <pugl/pugl.h>
-#include <limits.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -105,27 +104,37 @@ puglGetWorldString(const PuglWorld* const world, const PuglStringHint key)
}
static void
-puglSetDefaultHints(PuglHints hints)
+puglSetDefaultHints(PuglView* const view)
{
- hints[PUGL_CONTEXT_API] = PUGL_OPENGL_API;
- hints[PUGL_CONTEXT_VERSION_MAJOR] = 2;
- hints[PUGL_CONTEXT_VERSION_MINOR] = 0;
- hints[PUGL_CONTEXT_PROFILE] = PUGL_OPENGL_CORE_PROFILE;
- hints[PUGL_CONTEXT_DEBUG] = PUGL_FALSE;
- hints[PUGL_RED_BITS] = 8;
- hints[PUGL_GREEN_BITS] = 8;
- hints[PUGL_BLUE_BITS] = 8;
- hints[PUGL_ALPHA_BITS] = 8;
- hints[PUGL_DEPTH_BITS] = 0;
- hints[PUGL_STENCIL_BITS] = 0;
- hints[PUGL_SAMPLE_BUFFERS] = PUGL_DONT_CARE;
- hints[PUGL_SAMPLES] = 0;
- hints[PUGL_DOUBLE_BUFFER] = PUGL_TRUE;
- hints[PUGL_SWAP_INTERVAL] = PUGL_DONT_CARE;
- hints[PUGL_RESIZABLE] = PUGL_FALSE;
- hints[PUGL_IGNORE_KEY_REPEAT] = PUGL_FALSE;
- hints[PUGL_REFRESH_RATE] = PUGL_DONT_CARE;
- hints[PUGL_VIEW_TYPE] = PUGL_DONT_CARE;
+ view->hints[PUGL_CONTEXT_API] = PUGL_OPENGL_API;
+ view->hints[PUGL_CONTEXT_VERSION_MAJOR] = 2;
+ view->hints[PUGL_CONTEXT_VERSION_MINOR] = 0;
+ view->hints[PUGL_CONTEXT_PROFILE] = PUGL_OPENGL_CORE_PROFILE;
+ view->hints[PUGL_CONTEXT_DEBUG] = PUGL_FALSE;
+ view->hints[PUGL_RED_BITS] = 8;
+ view->hints[PUGL_GREEN_BITS] = 8;
+ view->hints[PUGL_BLUE_BITS] = 8;
+ view->hints[PUGL_ALPHA_BITS] = 8;
+ view->hints[PUGL_DEPTH_BITS] = 0;
+ view->hints[PUGL_STENCIL_BITS] = 0;
+ view->hints[PUGL_SAMPLE_BUFFERS] = PUGL_DONT_CARE;
+ view->hints[PUGL_SAMPLES] = 0;
+ view->hints[PUGL_DOUBLE_BUFFER] = PUGL_TRUE;
+ view->hints[PUGL_SWAP_INTERVAL] = PUGL_DONT_CARE;
+ view->hints[PUGL_RESIZABLE] = PUGL_FALSE;
+ view->hints[PUGL_IGNORE_KEY_REPEAT] = PUGL_FALSE;
+ view->hints[PUGL_REFRESH_RATE] = PUGL_DONT_CARE;
+ view->hints[PUGL_VIEW_TYPE] = PUGL_DONT_CARE;
+
+ for (unsigned i = 0U; i < PUGL_NUM_POSITION_HINTS; ++i) {
+ view->positionHints[i].x = INT16_MIN;
+ view->positionHints[i].y = INT16_MIN;
+ }
+
+ for (unsigned i = 0U; i < PUGL_NUM_SIZE_HINTS; ++i) {
+ view->sizeHints[i].width = 0U;
+ view->sizeHints[i].height = 0U;
+ }
}
PuglView*
@@ -137,13 +146,8 @@ puglNewView(PuglWorld* const world)
return NULL;
}
- view->world = world;
- view->sizeHints[PUGL_MIN_SIZE].width = 1;
- view->sizeHints[PUGL_MIN_SIZE].height = 1;
- view->defaultX = INT_MIN;
- view->defaultY = INT_MIN;
-
- puglSetDefaultHints(view->hints);
+ view->world = world;
+ puglSetDefaultHints(view);
// Enlarge world view list
const size_t newNumViews = world->numViews + 1U;
@@ -286,32 +290,37 @@ puglGetViewString(const PuglView* const view, const PuglStringHint key)
return view->strings[key];
}
-PuglRect
-puglGetFrame(const PuglView* view)
+PuglPoint
+puglGetPositionHint(const PuglView* const view, const PuglPositionHint hint)
{
- if (view->lastConfigure.type == PUGL_CONFIGURE) {
- // Return the last configured frame
- const PuglRect frame = {view->lastConfigure.x,
- view->lastConfigure.y,
- view->lastConfigure.width,
- view->lastConfigure.height};
- return frame;
+ if (hint == PUGL_CURRENT_POSITION) {
+ PuglPoint pos = {0, 0};
+ if (view->lastConfigure.type == PUGL_CONFIGURE) {
+ pos.x = view->lastConfigure.x;
+ pos.y = view->lastConfigure.y;
+ } else {
+ const PuglPoint defaultPos = view->positionHints[PUGL_DEFAULT_POSITION];
+ if (puglIsValidPosition(defaultPos.x, defaultPos.y)) {
+ pos.x = defaultPos.x;
+ pos.y = defaultPos.y;
+ }
+ }
+ return pos;
}
- // Get the default position if set, or fallback to (0, 0)
- int x = view->defaultX;
- int y = view->defaultY;
- if (!puglIsValidPosition(x, y)) {
- x = 0;
- y = 0;
+ return view->positionHints[hint];
+}
+
+PuglArea
+puglGetSizeHint(const PuglView* const view, const PuglSizeHint hint)
+{
+ if (hint == PUGL_CURRENT_SIZE && view->lastConfigure.type == PUGL_CONFIGURE) {
+ const PuglArea area = {view->lastConfigure.width,
+ view->lastConfigure.height};
+ return area;
}
- // Return the default frame, sanitized if necessary
- const PuglRect frame = {(PuglCoord)x,
- (PuglCoord)y,
- view->sizeHints[PUGL_DEFAULT_SIZE].width,
- view->sizeHints[PUGL_DEFAULT_SIZE].height};
- return frame;
+ return view->sizeHints[hint];
}
PuglStatus
diff --git a/src/internal.c b/src/internal.c
index 38a595a..ca84ed1 100644
--- a/src/internal.c
+++ b/src/internal.c
@@ -5,7 +5,7 @@
#include "types.h"
-#include "pugl/pugl.h"
+#include <pugl/pugl.h>
#include <assert.h>
#include <stdbool.h>
@@ -23,7 +23,8 @@ make_point(const PuglCoord x, const PuglCoord y)
bool
puglIsValidPosition(const int x, const int y)
{
- return x >= INT16_MIN && x <= INT16_MAX && y >= INT16_MIN && y <= INT16_MAX;
+ // INT16_MIN is a sentinel, INT16_MAX is impossible with non-zero size
+ return x > INT16_MIN && x < INT16_MAX && y > INT16_MIN && y < INT16_MAX;
}
bool
@@ -60,9 +61,10 @@ puglGetInitialPosition(const PuglView* const view, const PuglArea size)
return make_point(view->lastConfigure.x, view->lastConfigure.y);
}
- if (puglIsValidPosition(view->defaultX, view->defaultY)) {
+ const PuglPoint defaultPos = view->positionHints[PUGL_DEFAULT_POSITION];
+ if (puglIsValidPosition(defaultPos.x, defaultPos.y)) {
// Use the default position hint set by the application
- return make_point((PuglCoord)view->defaultX, (PuglCoord)view->defaultY);
+ return make_point(defaultPos.x, defaultPos.y);
}
if (view->parent) {
@@ -247,7 +249,7 @@ puglDispatchSimpleEvent(PuglView* view, const PuglEventType type)
type == PUGL_UPDATE || type == PUGL_CLOSE || type == PUGL_LOOP_ENTER ||
type == PUGL_LOOP_LEAVE);
- const PuglEvent event = {{type, 0}};
+ const PuglEvent event = {{type, 0U}};
return puglDispatchEvent(view, &event);
}
diff --git a/src/internal.h b/src/internal.h
index 7387494..8678982 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -9,8 +9,8 @@
#include "attributes.h"
#include "types.h"
-#include "pugl/attributes.h"
-#include "pugl/pugl.h"
+#include <pugl/attributes.h>
+#include <pugl/pugl.h>
#include <stdbool.h>
#include <stddef.h>
@@ -62,7 +62,6 @@ puglStoreSizeHint(PuglView* view,
unsigned height);
/// Handle a changed string property
-PUGL_API
PuglStatus
puglViewStringChanged(PuglView* view, PuglStringHint key, const char* value);
@@ -83,8 +82,7 @@ PuglStatus
puglDispatchSimpleEvent(PuglView* view, PuglEventType type);
/// Process configure event while already in the graphics context
-PUGL_WARN_UNUSED_RESULT
-PuglStatus
+PUGL_WARN_UNUSED_RESULT PuglStatus
puglConfigure(PuglView* view, const PuglEvent* event);
/// Dispatch `event` to `view`, entering graphics context if necessary
diff --git a/src/mac.h b/src/mac.h
index 119e7c8..305cf30 100644
--- a/src/mac.h
+++ b/src/mac.h
@@ -5,7 +5,7 @@
#ifndef PUGL_SRC_MAC_H
#define PUGL_SRC_MAC_H
-#include "pugl/pugl.h"
+#include <pugl/pugl.h>
#import <Cocoa/Cocoa.h>
diff --git a/src/mac.m b/src/mac.m
index 5f9d71e..41d358a 100644
--- a/src/mac.m
+++ b/src/mac.m
@@ -10,7 +10,7 @@
#include "macros.h"
#include "platform.h"
-#include "pugl/pugl.h"
+#include <pugl/pugl.h>
#import <Cocoa/Cocoa.h>
@@ -151,12 +151,6 @@ nsPointFromPoints(const PuglView* view, const NSPoint point)
return NSMakePoint(point.x * scaleFactor, point.y * scaleFactor);
}
-static NSRect
-rectToNsRect(const PuglRect rect)
-{
- return NSMakeRect(rect.x, rect.y, rect.width, rect.height);
-}
-
static NSSize
sizePoints(PuglView* view, const PuglSpan width, const PuglSpan height)
{
@@ -200,7 +194,7 @@ dispatchCurrentChildViewConfiguration(PuglView* const view)
const PuglConfigureEvent ev = {
PUGL_CONFIGURE,
- 0,
+ 0U,
(PuglCoord)framePx.origin.x,
(PuglCoord)framePx.origin.y,
(PuglSpan)framePx.size.width,
@@ -250,7 +244,7 @@ dispatchCurrentChildViewConfiguration(PuglView* const view)
const PuglConfigureEvent ev = {
PUGL_CONFIGURE,
- 0,
+ 0U,
(PuglCoord)contentPx.origin.x,
(PuglCoord)(screenHeight - contentPx.origin.y - contentPx.size.height),
(PuglSpan)contentPx.size.width,
@@ -332,7 +326,7 @@ dispatchCurrentChildViewConfiguration(PuglView* const view)
const PuglExposeEvent ev = {
PUGL_EXPOSE,
- 0,
+ 0U,
(PuglCoord)(rect.origin.x * scaleFactor),
(PuglCoord)viewY,
(PuglSpan)(rect.size.width * scaleFactor),
@@ -497,7 +491,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
const NSPoint rloc = [NSEvent mouseLocation];
const PuglCrossingEvent ev = {
type,
- 0,
+ 0U,
[event timestamp],
wloc.x,
wloc.y,
@@ -538,7 +532,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
const NSPoint rloc = [NSEvent mouseLocation];
const PuglMotionEvent ev = {
PUGL_MOTION,
- 0,
+ 0U,
[event timestamp],
wloc.x,
wloc.y,
@@ -573,7 +567,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
const NSPoint rloc = [NSEvent mouseLocation];
const PuglButtonEvent ev = {
PUGL_BUTTON_PRESS,
- 0,
+ 0U,
[event timestamp],
wloc.x,
wloc.y,
@@ -594,7 +588,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
const NSPoint rloc = [NSEvent mouseLocation];
const PuglButtonEvent ev = {
PUGL_BUTTON_RELEASE,
- 0,
+ 0U,
[event timestamp],
wloc.x,
wloc.y,
@@ -653,7 +647,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
const PuglScrollEvent ev = {
PUGL_SCROLL,
- 0,
+ 0U,
[event timestamp],
wloc.x,
wloc.y,
@@ -685,7 +679,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
const PuglKeyEvent ev = {
PUGL_KEY_PRESS,
- 0,
+ 0U,
[event timestamp],
wloc.x,
wloc.y,
@@ -716,7 +710,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
const PuglKeyEvent ev = {
PUGL_KEY_RELEASE,
- 0,
+ 0U,
[event timestamp],
wloc.x,
wloc.y,
@@ -828,7 +822,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
PuglTextEvent ev = {
PUGL_TEXT,
- 0,
+ 0U,
[event timestamp],
wloc.x,
wloc.y,
@@ -878,7 +872,7 @@ flagDiffers(const uint32_t lhs, const uint32_t rhs, const uint32_t mask)
const bool release = [event type] == NSEventTypeKeyUp;
const PuglKeyEvent ev = {release ? PUGL_KEY_RELEASE : PUGL_KEY_PRESS,
- 0,
+ 0U,
[event timestamp],
wloc.x,
wloc.y,
@@ -920,7 +914,7 @@ flagDiffers(const uint32_t lhs, const uint32_t rhs, const uint32_t mask)
- (void)timerTick:(NSTimer*)userTimer
{
const NSNumber* userInfo = userTimer.userInfo;
- const PuglTimerEvent ev = {PUGL_TIMER, 0, userInfo.unsignedLongValue};
+ const PuglTimerEvent ev = {PUGL_TIMER, 0U, userInfo.unsignedLongValue};
PuglEvent timerEvent;
timerEvent.timer = ev;
@@ -985,7 +979,7 @@ flagDiffers(const uint32_t lhs, const uint32_t rhs, const uint32_t mask)
{
(void)notification;
- PuglEvent ev = {{PUGL_FOCUS_IN, 0}};
+ PuglEvent ev = {{PUGL_FOCUS_IN, 0U}};
ev.focus.mode = PUGL_CROSSING_NORMAL;
puglDispatchEvent(window->puglview, &ev);
}
@@ -994,7 +988,7 @@ flagDiffers(const uint32_t lhs, const uint32_t rhs, const uint32_t mask)
{
(void)notification;
- PuglEvent ev = {{PUGL_FOCUS_OUT, 0}};
+ PuglEvent ev = {{PUGL_FOCUS_OUT, 0U}};
ev.focus.mode = PUGL_CROSSING_NORMAL;
puglDispatchEvent(window->puglview, &ev);
}
@@ -1124,6 +1118,7 @@ updateSizeHint(PuglView* const view, const PuglSizeHint hint)
switch (hint) {
case PUGL_DEFAULT_SIZE:
+ case PUGL_CURRENT_SIZE:
break;
case PUGL_MIN_SIZE:
@@ -1166,8 +1161,8 @@ puglGetAncestorCenter(const PuglView* const view)
const NSRect boundsPx = nsRectFromPoints(view, boundsPt);
const PuglPoint center = {
- (PuglCoord)(boundsPx.origin.x + boundsPx.size.width / 2.0),
- (PuglCoord)(boundsPx.origin.y + boundsPx.size.height / 2.0)};
+ (PuglCoord)(boundsPx.origin.x + (boundsPx.size.width / 2.0)),
+ (PuglCoord)(boundsPx.origin.y + (boundsPx.size.height / 2.0))};
return center;
}
@@ -1216,13 +1211,12 @@ puglRealize(PuglView* view)
CVDisplayLinkRelease(link);
}
- // Get the initial frame to use from the defaults or last configuration
- const PuglArea size = puglGetInitialSize(view);
- const PuglPoint pos = puglGetInitialPosition(view, size);
- const PuglRect initialFrame = {pos.x, pos.y, size.width, size.height};
+ // Get the initial size and position from the defaults or last configuration
+ const PuglArea size = puglGetInitialSize(view);
+ const PuglPoint pos = puglGetInitialPosition(view, size);
// Convert frame to points
- const NSRect framePx = rectToNsRect(initialFrame);
+ const NSRect framePx = NSMakeRect(pos.x, pos.y, size.width, size.height);
const NSRect framePt = NSMakeRect(framePx.origin.x / scaleFactor,
framePx.origin.y / scaleFactor,
framePx.size.width / scaleFactor,
@@ -1308,8 +1302,17 @@ puglRealize(PuglView* view)
((NSWindow*)window).delegate =
[[PuglWindowDelegate alloc] initWithPuglWindow:window];
- // Set basic window hints and attributes
- puglSetFrame(view, initialFrame);
+ // Set window frame
+ const NSRect screenPt = rectToScreen(screen, framePt);
+ const NSRect winFrame = [impl->window frameRectForContentRect:screenPt];
+ [impl->window setFrame:winFrame display:NO];
+
+ // Resize views and move them to (0, 0)
+ const NSRect sizePx = {{0, 0}, {framePx.size.width, framePx.size.height}};
+ const NSRect sizePt = [impl->drawView convertRectFromBacking:sizePx];
+ [impl->wrapperView setFrame:sizePt];
+ [impl->drawView setFrame:sizePt];
+
puglSetTransientParent(view, view->transientParent);
updateSizeHints(view);
@@ -1581,14 +1584,6 @@ puglSendEvent(PuglView* view, const PuglEvent* event)
return PUGL_UNSUPPORTED;
}
-#ifndef PUGL_DISABLE_DEPRECATED
-PuglStatus
-puglWaitForEvent(PuglView* view)
-{
- return puglPollEvents(view->world, -1.0);
-}
-#endif
-
PuglStatus
puglUpdate(PuglWorld* world, const double timeout)
{
@@ -1626,14 +1621,6 @@ puglUpdate(PuglWorld* world, const double timeout)
return PUGL_SUCCESS;
}
-#ifndef PUGL_DISABLE_DEPRECATED
-PuglStatus
-puglProcessEvents(PuglView* view)
-{
- return puglDispatchEvents(view->world);
-}
-#endif
-
double
puglGetTime(const PuglWorld* world)
{
@@ -1720,108 +1707,36 @@ puglGetScaleFactor(const PuglView* const view)
return [viewScreen(view) backingScaleFactor];
}
-PuglStatus
-puglSetFrame(PuglView* view, const PuglRect frame)
-{
- PuglInternals* const impl = view->impl;
- const NSRect framePx = rectToNsRect(frame);
- const NSRect framePt = nsRectToPoints(view, framePx);
-
- if (!impl->wrapperView) {
- // Set defaults to be used when realized
- view->defaultX = frame.x;
- view->defaultY = frame.y;
- view->sizeHints[PUGL_DEFAULT_SIZE].width = (PuglSpan)frame.width;
- view->sizeHints[PUGL_DEFAULT_SIZE].height = (PuglSpan)frame.height;
- return PUGL_SUCCESS;
- }
-
- if (impl->window) {
- const NSRect screenPt = rectToScreen(viewScreen(view), framePt);
-
- // Move and resize window to fit new content rect
- const NSRect winFrame = [impl->window frameRectForContentRect:screenPt];
- [impl->window setFrame:winFrame display:NO];
-
- // Resize views
- const NSRect sizePx = NSMakeRect(0, 0, frame.width, frame.height);
- const NSRect sizePt = [impl->drawView convertRectFromBacking:sizePx];
- [impl->wrapperView setFrame:sizePt];
- [impl->drawView setFrame:sizePt];
- [impl->window dispatchCurrentConfiguration];
- return PUGL_SUCCESS;
- }
-
- // Resize view
- const NSRect sizePx = NSMakeRect(0, 0, frame.width, frame.height);
- const NSRect sizePt = [impl->drawView convertRectFromBacking:sizePx];
-
- [impl->wrapperView setFrame:framePt];
- [impl->drawView setFrame:sizePt];
- return dispatchCurrentChildViewConfiguration(view);
-}
-
-PuglStatus
-puglSetPosition(PuglView* const view, const int x, const int y)
+static PuglStatus
+puglSetWindowPosition(PuglView* const view, const int x, const int y)
{
- if (!puglIsValidPosition(x, y)) {
- return PUGL_BAD_PARAMETER;
- }
-
PuglInternals* const impl = view->impl;
- if (!impl->wrapperView) {
- // Set defaults to be used when realized
- view->defaultX = x;
- view->defaultY = y;
- return PUGL_SUCCESS;
- }
- const PuglRect frame = {(PuglCoord)x,
- (PuglCoord)y,
- view->lastConfigure.width,
- view->lastConfigure.height};
+ const NSRect framePx =
+ NSMakeRect(x, y, view->lastConfigure.width, view->lastConfigure.height);
+
+ const NSRect framePt = nsRectToPoints(view, framePx);
if (impl->window) {
// Adjust top-level window frame
- return puglSetFrame(view, frame);
+ const NSRect screenPt = rectToScreen(viewScreen(view), framePt);
+ [impl->window setFrameOrigin:screenPt.origin];
+ return PUGL_SUCCESS;
}
// Set wrapper view origin
- const NSRect framePx = rectToNsRect(frame);
- const NSRect framePt = nsRectToPoints(view, framePx);
[impl->wrapperView setFrameOrigin:framePt.origin];
- // Set draw view origin
- const NSRect drawPx = NSMakeRect(0, 0, frame.width, frame.height);
- const NSRect drawPt = [impl->drawView convertRectFromBacking:drawPx];
- [impl->drawView setFrameOrigin:drawPt.origin];
-
// Dispatch new configuration
return dispatchCurrentChildViewConfiguration(view);
}
-PuglStatus
-puglSetSize(PuglView* const view, const unsigned width, const unsigned height)
+static PuglStatus
+puglSetWindowSize(PuglView* const view,
+ const unsigned width,
+ const unsigned height)
{
- if (!puglIsValidSize(width, height)) {
- return PUGL_BAD_PARAMETER;
- }
-
PuglInternals* const impl = view->impl;
- if (!impl->wrapperView) {
- // Set defaults to be used when realized
- view->sizeHints[PUGL_DEFAULT_SIZE].width = (PuglSpan)width;
- view->sizeHints[PUGL_DEFAULT_SIZE].height = (PuglSpan)height;
- return PUGL_SUCCESS;
- }
-
- if (impl->window) {
- // Adjust top-level window frame
- PuglRect frame = puglGetFrame(view);
- frame.width = (PuglSpan)width;
- frame.height = (PuglSpan)height;
- return puglSetFrame(view, frame);
- }
// Set wrapper view size
const double scaleFactor = [viewScreen(view) backingScaleFactor];
@@ -1833,11 +1748,40 @@ puglSetSize(PuglView* const view, const unsigned width, const unsigned height)
const NSRect drawPt = [impl->drawView convertRectFromBacking:drawPx];
[impl->drawView setFrameSize:drawPt.size];
+ if (impl->window) {
+ const NSRect framePx =
+ NSMakeRect(view->lastConfigure.x, view->lastConfigure.y, width, height);
+ const NSRect framePt = nsRectToPoints(view, framePx);
+ const NSRect screenPt = rectToScreen(viewScreen(view), framePt);
+
+ // Resize window to fit new content rect
+ const NSRect winFrame = [impl->window frameRectForContentRect:screenPt];
+ [impl->window setFrame:winFrame display:NO];
+ [impl->window dispatchCurrentConfiguration];
+ }
+
// Dispatch new configuration
return dispatchCurrentChildViewConfiguration(view);
}
PuglStatus
+puglSetPositionHint(PuglView* const view,
+ const PuglPositionHint hint,
+ const int x,
+ const int y)
+{
+ if (x <= INT16_MIN || x > INT16_MAX || y <= INT16_MIN || y > INT16_MAX) {
+ return PUGL_BAD_PARAMETER;
+ }
+
+ view->positionHints[hint].x = (PuglCoord)x;
+ view->positionHints[hint].y = (PuglCoord)y;
+
+ return (hint == PUGL_CURRENT_POSITION) ? puglSetWindowPosition(view, x, y)
+ : PUGL_SUCCESS;
+}
+
+PuglStatus
puglSetSizeHint(PuglView* const view,
const PuglSizeHint hint,
const unsigned width,
@@ -1845,7 +1789,9 @@ puglSetSizeHint(PuglView* const view,
{
const PuglStatus st = puglStoreSizeHint(view, hint, width, height);
- return (!st && view->impl->window) ? updateSizeHint(view, hint) : st;
+ return st ? st
+ : (hint == PUGL_CURRENT_SIZE) ? puglSetWindowSize(view, width, height)
+ : updateSizeHint(view, hint);
}
PuglStatus
@@ -1873,7 +1819,7 @@ puglPaste(PuglView* const view)
{
const PuglDataOfferEvent offer = {
PUGL_DATA_OFFER,
- 0,
+ 0U,
puglGetTime(view->world),
};
diff --git a/src/mac_cairo.m b/src/mac_cairo.m
index e4d2f5f..112b727 100644
--- a/src/mac_cairo.m
+++ b/src/mac_cairo.m
@@ -5,7 +5,7 @@
#include "mac.h"
#include "stub.h"
-#include "pugl/cairo.h"
+#include <pugl/cairo.h>
#include <cairo-quartz.h>
diff --git a/src/mac_gl.m b/src/mac_gl.m
index f177bf9..57dfc41 100644
--- a/src/mac_gl.m
+++ b/src/mac_gl.m
@@ -5,7 +5,7 @@
#include "mac.h"
#include "stub.h"
-#include "pugl/gl.h"
+#include <pugl/gl.h>
#ifndef __MAC_10_10
# define NSOpenGLProfileVersion4_1Core NSOpenGLProfileVersion3_2Core
diff --git a/src/mac_stub.m b/src/mac_stub.m
index 9ebedca..c7e4512 100644
--- a/src/mac_stub.m
+++ b/src/mac_stub.m
@@ -5,7 +5,7 @@
#include "mac.h"
#include "stub.h"
-#include "pugl/stub.h"
+#include <pugl/stub.h>
#import <Cocoa/Cocoa.h>
diff --git a/src/mac_vulkan.m b/src/mac_vulkan.m
index 4fdbaf6..f3563e2 100644
--- a/src/mac_vulkan.m
+++ b/src/mac_vulkan.m
@@ -8,9 +8,9 @@
#include "stub.h"
#include "types.h"
-#include "pugl/pugl.h"
-#include "pugl/stub.h"
-#include "pugl/vulkan.h"
+#include <pugl/pugl.h>
+#include <pugl/stub.h>
+#include <pugl/vulkan.h>
#include <vulkan/vulkan_core.h>
#include <vulkan/vulkan_macos.h>
diff --git a/src/platform.h b/src/platform.h
index cfdb1b7..e43a58e 100644
--- a/src/platform.h
+++ b/src/platform.h
@@ -8,13 +8,12 @@
#include "types.h"
-#include "pugl/pugl.h"
+#include <pugl/pugl.h>
PUGL_BEGIN_DECLS
/// Allocate and initialise world internals (implemented once per platform)
-PUGL_MALLOC_FUNC
-PuglWorldInternals*
+PUGL_MALLOC_FUNC PuglWorldInternals*
puglInitWorldInternals(PuglWorldType type, PuglWorldFlags flags);
/// Destroy and free world internals (implemented once per platform)
@@ -22,8 +21,7 @@ void
puglFreeWorldInternals(PuglWorld* world);
/// Allocate and initialise view internals (implemented once per platform)
-PUGL_MALLOC_FUNC
-PuglInternals*
+PUGL_MALLOC_FUNC PuglInternals*
puglInitViewInternals(PuglWorld* world);
/// Destroy and free view internals (implemented once per platform)
diff --git a/src/stub.h b/src/stub.h
index 699bbb9..476aa1a 100644
--- a/src/stub.h
+++ b/src/stub.h
@@ -4,7 +4,7 @@
#ifndef PUGL_SRC_STUB_H
#define PUGL_SRC_STUB_H
-#include "pugl/pugl.h"
+#include <pugl/pugl.h>
#include <stddef.h>
diff --git a/src/types.h b/src/types.h
index bbebbb7..b453f11 100644
--- a/src/types.h
+++ b/src/types.h
@@ -6,7 +6,7 @@
#include "attributes.h"
-#include "pugl/pugl.h"
+#include <pugl/pugl.h>
#include <stdbool.h>
#include <stddef.h>
@@ -21,18 +21,6 @@ typedef struct PuglInternalsImpl PuglInternals;
/// View hints
typedef int PuglHints[PUGL_NUM_VIEW_HINTS];
-/// View position (both X and Y coordinates) or general point
-typedef struct {
- PuglCoord x;
- PuglCoord y;
-} PuglPoint;
-
-/// View size (both X and Y coordinates)
-typedef struct {
- PuglSpan width;
- PuglSpan height;
-} PuglArea;
-
/// Blob of arbitrary data
typedef struct {
void* data; ///< Dynamically allocated data
@@ -57,10 +45,9 @@ struct PuglViewImpl {
uintptr_t transientParent;
PuglConfigureEvent lastConfigure;
PuglHints hints;
+ PuglPoint positionHints[PUGL_NUM_POSITION_HINTS];
PuglArea sizeHints[PUGL_NUM_SIZE_HINTS];
char* strings[PUGL_NUM_STRING_HINTS];
- int defaultX;
- int defaultY;
PuglViewStage stage;
bool resizing;
};
@@ -82,23 +69,21 @@ typedef void PuglSurface;
/// Graphics backend interface
struct PuglBackendImpl {
/// Get visual information from display and setup view as necessary
- PUGL_WARN_UNUSED_RESULT
- PuglStatus (*configure)(PuglView*);
+ PUGL_WARN_UNUSED_RESULT PuglStatus (*configure)(PuglView*);
/// Create surface and drawing context
- PUGL_WARN_UNUSED_RESULT
- PuglStatus (*create)(PuglView*);
+ PUGL_WARN_UNUSED_RESULT PuglStatus (*create)(PuglView*);
/// Destroy surface and drawing context
void (*destroy)(PuglView*);
/// Enter drawing context, for drawing if expose is non-null
- PUGL_WARN_UNUSED_RESULT
- PuglStatus (*enter)(PuglView*, const PuglExposeEvent*);
+ PUGL_WARN_UNUSED_RESULT PuglStatus (*enter)(PuglView*,
+ const PuglExposeEvent*);
/// Leave drawing context, after drawing if expose is non-null
- PUGL_WARN_UNUSED_RESULT
- PuglStatus (*leave)(PuglView*, const PuglExposeEvent*);
+ PUGL_WARN_UNUSED_RESULT PuglStatus (*leave)(PuglView*,
+ const PuglExposeEvent*);
/// Return the puglGetContext() handle for the application, if any
void* (*getContext)(PuglView*);
diff --git a/src/win.c b/src/win.c
index 2cefd8b..a8cd841 100644
--- a/src/win.c
+++ b/src/win.c
@@ -7,7 +7,7 @@
#include "macros.h"
#include "platform.h"
-#include "pugl/pugl.h"
+#include <pugl/pugl.h>
#include <dwmapi.h>
#include <windows.h>
@@ -44,7 +44,8 @@
#ifdef __cplusplus
# define PUGL_INIT_STRUCT \
- {}
+ { \
+ }
#else
# define PUGL_INIT_STRUCT {0}
#endif
@@ -314,16 +315,16 @@ puglRealize(PuglView* view)
puglSetViewString(view, PUGL_WINDOW_TITLE, view->strings[PUGL_WINDOW_TITLE]);
puglSetTransientParent(view, view->transientParent);
- view->impl->scaleFactor = puglWinGetViewScaleFactor(view);
- view->impl->cursor = LoadCursor(NULL, IDC_ARROW);
+ impl->scaleFactor = puglWinGetViewScaleFactor(view);
+ impl->cursor = LoadCursor(NULL, IDC_ARROW);
if (view->hints[PUGL_DARK_FRAME]) {
const BOOL useDarkMode = TRUE;
- if ((DwmSetWindowAttribute(view->impl->hwnd,
+ if ((DwmSetWindowAttribute(impl->hwnd,
DWMWA_USE_IMMERSIVE_DARK_MODE,
&useDarkMode,
sizeof(useDarkMode)) != S_OK)) {
- DwmSetWindowAttribute(view->impl->hwnd,
+ DwmSetWindowAttribute(impl->hwnd,
PRE_20H1_DWMWA_USE_IMMERSIVE_DARK_MODE,
&useDarkMode,
sizeof(useDarkMode));
@@ -349,24 +350,22 @@ puglUnrealize(PuglView* const view)
view->backend->destroy(view);
}
- ReleaseDC(view->impl->hwnd, view->impl->hdc);
- view->impl->hdc = NULL;
-
- DestroyWindow(view->impl->hwnd);
- view->impl->hwnd = NULL;
-
memset(&view->lastConfigure, 0, sizeof(PuglConfigureEvent));
- return PUGL_SUCCESS;
+ ReleaseDC(impl->hwnd, impl->hdc);
+ impl->hdc = NULL;
+
+ const PuglStatus st = puglWinStatus(DestroyWindow(impl->hwnd));
+ impl->hwnd = NULL;
+ return st;
}
PuglStatus
puglShow(PuglView* view, const PuglShowCommand command)
{
PuglInternals* impl = view->impl;
-
+ PuglStatus st = PUGL_SUCCESS;
if (!impl->hwnd) {
- const PuglStatus st = puglRealize(view);
- if (st) {
+ if ((st = puglRealize(view))) {
return st;
}
}
@@ -385,15 +384,13 @@ puglShow(PuglView* view, const PuglShowCommand command)
break;
}
- return PUGL_SUCCESS;
+ return st;
}
PuglStatus
puglHide(PuglView* view)
{
- PuglInternals* impl = view->impl;
-
- ShowWindow(impl->hwnd, SW_HIDE);
+ ShowWindow(view->impl->hwnd, SW_HIDE);
return PUGL_SUCCESS;
}
@@ -679,7 +676,7 @@ handleCrossing(PuglView* view, const PuglEventType type, POINT pos)
const PuglCrossingEvent ev = {
type,
- 0,
+ 0U,
GetMessageTime() / 1e3,
(double)pos.x,
(double)pos.y,
@@ -689,7 +686,7 @@ handleCrossing(PuglView* view, const PuglEventType type, POINT pos)
PUGL_CROSSING_NORMAL,
};
- PuglEvent crossingEvent = {{type, 0}};
+ PuglEvent crossingEvent = {{type, 0U}};
crossingEvent.crossing = ev;
puglDispatchEvent(view, &crossingEvent);
}
@@ -739,7 +736,7 @@ constrainAspect(const PuglView* const view,
static LRESULT
handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
{
- PuglEvent event = {{PUGL_NOTHING, 0}};
+ PuglEvent event = {{PUGL_NOTHING, 0U}};
RECT rect = {0, 0, 0, 0};
POINT pt = {0, 0};
MINMAXINFO* mmi = NULL;
@@ -801,7 +798,7 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_TIMER:
if (wParam >= PUGL_USER_TIMER_MIN) {
- PuglEvent ev = {{PUGL_TIMER, 0}};
+ PuglEvent ev = {{PUGL_TIMER, 0U}};
ev.timer.id = wParam - PUGL_USER_TIMER_MIN;
puglDispatchEvent(view, &ev);
}
@@ -954,8 +951,7 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
PuglStatus
puglGrabFocus(PuglView* view)
{
- SetFocus(view->impl->hwnd);
- return PUGL_SUCCESS;
+ return puglWinStatus(!!SetFocus(view->impl->hwnd));
}
bool
@@ -1040,9 +1036,8 @@ puglStartTimer(PuglView* view, uintptr_t id, double timeout)
{
const UINT msec = (UINT)floor(timeout * 1000.0);
- return (SetTimer(view->impl->hwnd, PUGL_USER_TIMER_MIN + id, msec, NULL)
- ? PUGL_SUCCESS
- : PUGL_UNKNOWN_ERROR);
+ SetTimer(view->impl->hwnd, PUGL_USER_TIMER_MIN + id, msec, NULL);
+ return PUGL_SUCCESS;
}
PuglStatus
@@ -1055,31 +1050,19 @@ PuglStatus
puglSendEvent(PuglView* view, const PuglEvent* event)
{
if (event->type == PUGL_CLOSE) {
- PostMessage(view->impl->hwnd, WM_CLOSE, 0, 0);
- return PUGL_SUCCESS;
+ return puglWinStatus(PostMessage(view->impl->hwnd, WM_CLOSE, 0, 0));
}
if (event->type == PUGL_CLIENT) {
- PostMessage(view->impl->hwnd,
- PUGL_LOCAL_CLIENT_MSG,
- (WPARAM)event->client.data1,
- (LPARAM)event->client.data2);
-
- return PUGL_SUCCESS;
+ return puglWinStatus(PostMessage(view->impl->hwnd,
+ PUGL_LOCAL_CLIENT_MSG,
+ (WPARAM)event->client.data1,
+ (LPARAM)event->client.data2));
}
return PUGL_UNSUPPORTED;
}
-#ifndef PUGL_DISABLE_DEPRECATED
-PuglStatus
-puglWaitForEvent(PuglView* PUGL_UNUSED(view))
-{
- WaitMessage();
- return PUGL_SUCCESS;
-}
-#endif
-
static PuglStatus
puglDispatchViewEvents(PuglView* view)
{
@@ -1156,14 +1139,6 @@ puglUpdate(PuglWorld* world, double timeout)
return st;
}
-#ifndef PUGL_DISABLE_DEPRECATED
-PuglStatus
-puglProcessEvents(PuglView* view)
-{
- return puglUpdate(view->world, 0.0);
-}
-#endif
-
LRESULT CALLBACK
wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
@@ -1199,8 +1174,7 @@ puglGetTime(const PuglWorld* world)
PuglStatus
puglObscureView(PuglView* view)
{
- InvalidateRect(view->impl->hwnd, NULL, false);
- return PUGL_SUCCESS;
+ return puglWinStatus(InvalidateRect(view->impl->hwnd, NULL, false));
}
PuglStatus
@@ -1220,9 +1194,7 @@ puglObscureRegion(PuglView* const view,
const unsigned ch = MIN(view->lastConfigure.height, height);
const RECT r = {cx, cy, cx + (long)cw, cy + (long)ch};
- InvalidateRect(view->impl->hwnd, &r, false);
-
- return PUGL_SUCCESS;
+ return puglWinStatus(InvalidateRect(view->impl->hwnd, &r, false));
}
PuglNativeView
@@ -1236,17 +1208,18 @@ puglViewStringChanged(PuglView* const view,
const PuglStringHint key,
const char* const value)
{
+ PuglStatus st = PUGL_SUCCESS;
if (!view->impl->hwnd) {
- return PUGL_SUCCESS;
+ return st;
}
if (key == PUGL_WINDOW_TITLE) {
ArgStringChar* const titleArg = puglArgStringNew(value);
- SetWindowText(view->impl->hwnd, titleArg);
+ st = puglWinStatus(SetWindowText(view->impl->hwnd, titleArg));
puglArgStringFree(titleArg);
}
- return PUGL_SUCCESS;
+ return st;
}
static RECT
@@ -1271,45 +1244,9 @@ puglGetScaleFactor(const PuglView* const view)
: puglWinGetViewScaleFactor(view);
}
-PuglStatus
-puglSetFrame(PuglView* view, const PuglRect frame)
-{
- if (!view->impl->hwnd) {
- // Set defaults to be used when realized
- view->defaultX = frame.x;
- view->defaultY = frame.y;
- view->sizeHints[PUGL_DEFAULT_SIZE].width = frame.width;
- view->sizeHints[PUGL_DEFAULT_SIZE].height = frame.height;
- return PUGL_SUCCESS;
- }
-
- const RECT rect =
- adjustedWindowRect(view, frame.x, frame.y, frame.width, frame.height);
-
- 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
-puglSetPosition(PuglView* const view, const int x, const int y)
+static PuglStatus
+puglSetWindowPosition(PuglView* const view, const int x, const int y)
{
- if (!puglIsValidPosition(x, y)) {
- return PUGL_BAD_PARAMETER;
- }
-
- if (!view->impl->hwnd) {
- // Set defaults to be used when realized
- view->defaultX = x;
- view->defaultY = y;
- return PUGL_SUCCESS;
- }
-
const RECT rect = adjustedWindowRect(
view, x, y, view->lastConfigure.width, view->lastConfigure.height);
@@ -1320,20 +1257,11 @@ puglSetPosition(PuglView* const view, const int x, const int y)
SetWindowPos(view->impl->hwnd, HWND_TOP, rect.left, rect.top, 0, 0, flags));
}
-PuglStatus
-puglSetSize(PuglView* const view, const unsigned width, const unsigned height)
+static PuglStatus
+puglSetWindowSize(PuglView* const view,
+ const unsigned width,
+ const unsigned height)
{
- if (!puglIsValidSize(width, height)) {
- return PUGL_BAD_PARAMETER;
- }
-
- if (!view->impl->hwnd) {
- // Set defaults to be used when realized
- view->sizeHints[PUGL_DEFAULT_SIZE].width = (PuglSpan)width;
- view->sizeHints[PUGL_DEFAULT_SIZE].height = (PuglSpan)height;
- return PUGL_SUCCESS;
- }
-
const RECT rect = adjustedWindowRect(view,
view->lastConfigure.x,
view->lastConfigure.y,
@@ -1353,12 +1281,33 @@ puglSetSize(PuglView* const view, const unsigned width, const unsigned height)
}
PuglStatus
+puglSetPositionHint(PuglView* const view,
+ const PuglPositionHint hint,
+ const int x,
+ const int y)
+{
+ if (x <= INT16_MIN || x > INT16_MAX || y <= INT16_MIN || y > INT16_MAX) {
+ return PUGL_BAD_PARAMETER;
+ }
+
+ view->positionHints[hint].x = (PuglCoord)x;
+ view->positionHints[hint].y = (PuglCoord)y;
+
+ return (hint == PUGL_CURRENT_POSITION) ? puglSetWindowPosition(view, x, y)
+ : PUGL_SUCCESS;
+}
+
+PuglStatus
puglSetSizeHint(PuglView* const view,
const PuglSizeHint hint,
const unsigned width,
const unsigned height)
{
- return puglStoreSizeHint(view, hint, width, height);
+ const PuglStatus st = puglStoreSizeHint(view, hint, width, height);
+
+ return (!st && hint == PUGL_CURRENT_SIZE)
+ ? puglSetWindowSize(view, width, height)
+ : st;
}
PuglStatus
@@ -1404,15 +1353,14 @@ puglAcceptOffer(PuglView* const view,
const PuglDataEvent data = {
PUGL_DATA,
- 0,
+ 0U,
GetMessageTime() / 1e3,
0,
};
PuglEvent dataEvent;
dataEvent.data = data;
- puglDispatchEvent(view, &dataEvent);
- return PUGL_SUCCESS;
+ return puglDispatchEvent(view, &dataEvent);
}
const void*
@@ -1422,8 +1370,21 @@ puglGetClipboard(PuglView* const view,
{
PuglInternals* const impl = view->impl;
- if (typeIndex > 0U || !IsClipboardFormatAvailable(CF_UNICODETEXT) ||
- !OpenClipboard(impl->hwnd)) {
+ if (typeIndex > 0U || !IsClipboardFormatAvailable(CF_UNICODETEXT)) {
+ return NULL;
+ }
+
+ // Try to open the clipboard several times since others may have locked it
+ BOOL opened = FALSE;
+ static const unsigned max_tries = 16U;
+ for (unsigned i = 0U; !opened && i < max_tries; ++i) {
+ opened = OpenClipboard(impl->hwnd);
+ if (!opened) {
+ Sleep(0);
+ }
+ }
+
+ if (!opened) {
return NULL;
}
@@ -1434,15 +1395,14 @@ puglGetClipboard(PuglView* const view,
return NULL;
}
- free(view->impl->clipboard.data);
- view->impl->clipboard.data =
- puglWideCharToUtf8(wstr, &view->impl->clipboard.len);
+ free(impl->clipboard.data);
+ impl->clipboard.data = puglWideCharToUtf8(wstr, &impl->clipboard.len);
GlobalUnlock(mem);
CloseClipboard();
- *len = view->impl->clipboard.len;
- return view->impl->clipboard.data;
+ *len = impl->clipboard.len;
+ return impl->clipboard.data;
}
PuglStatus
@@ -1453,7 +1413,7 @@ puglSetClipboard(PuglView* const view,
{
PuglInternals* const impl = view->impl;
- PuglStatus st = puglSetBlob(&view->impl->clipboard, data, len);
+ PuglStatus st = puglSetBlob(&impl->clipboard, data, len);
if (st) {
return st;
}
@@ -1498,14 +1458,13 @@ puglPaste(PuglView* const view)
{
const PuglDataOfferEvent offer = {
PUGL_DATA_OFFER,
- 0,
+ 0U,
GetMessageTime() / 1e3,
};
PuglEvent offerEvent;
offerEvent.offer = offer;
- puglDispatchEvent(view, &offerEvent);
- return PUGL_SUCCESS;
+ return puglDispatchEvent(view, &offerEvent);
}
static const TCHAR* const cursor_ids[] = {
@@ -1582,8 +1541,8 @@ puglGetAncestorCenter(const PuglView* const view)
&rect);
const PuglPoint center = {
- (PuglCoord)(rect.left + (rect.right - rect.left) / 2),
- (PuglCoord)(rect.top + (rect.bottom - rect.top) / 2)};
+ (PuglCoord)(rect.left + ((rect.right - rect.left) / 2)),
+ (PuglCoord)(rect.top + ((rect.bottom - rect.top) / 2))};
return center;
}
@@ -1653,7 +1612,6 @@ puglWinConfigure(PuglView* view)
{
PuglInternals* const impl = view->impl;
PuglStatus st = PUGL_SUCCESS;
-
if ((st = puglWinCreateWindow(view, "Pugl", &impl->hwnd, &impl->hdc))) {
return st;
}
@@ -1666,20 +1624,18 @@ puglWinConfigure(PuglView* view)
DestroyWindow(impl->hwnd);
impl->hwnd = NULL;
impl->hdc = NULL;
- return PUGL_SET_FORMAT_FAILED;
+ st = PUGL_SET_FORMAT_FAILED;
}
- return PUGL_SUCCESS;
+ return st;
}
PuglStatus
puglWinEnter(PuglView* view, const PuglExposeEvent* expose)
{
- if (expose) {
- BeginPaint(view->impl->hwnd, &view->impl->paint);
- }
-
- return PUGL_SUCCESS;
+ return expose
+ ? puglWinStatus(!!BeginPaint(view->impl->hwnd, &view->impl->paint))
+ : PUGL_SUCCESS;
}
PuglStatus
diff --git a/src/win.h b/src/win.h
index 84f1d4e..b37db3f 100644
--- a/src/win.h
+++ b/src/win.h
@@ -6,7 +6,7 @@
#include "internal.h"
-#include "pugl/pugl.h"
+#include <pugl/pugl.h>
#include <windows.h>
@@ -37,28 +37,19 @@ struct PuglInternalsImpl {
bool fullscreen;
};
-PUGL_API
-PuglWinPFD
+PUGL_API PuglWinPFD
puglWinGetPixelFormatDescriptor(const PuglHints hints);
-PUGL_WARN_UNUSED_RESULT
-PUGL_API
-PuglStatus
+PUGL_WARN_UNUSED_RESULT PUGL_API PuglStatus
puglWinCreateWindow(PuglView* view, const char* title, HWND* hwnd, HDC* hdc);
-PUGL_WARN_UNUSED_RESULT
-PUGL_API
-PuglStatus
+PUGL_WARN_UNUSED_RESULT PUGL_API PuglStatus
puglWinConfigure(PuglView* view);
-PUGL_WARN_UNUSED_RESULT
-PUGL_API
-PuglStatus
+PUGL_WARN_UNUSED_RESULT PUGL_API PuglStatus
puglWinEnter(PuglView* view, const PuglExposeEvent* expose);
-PUGL_WARN_UNUSED_RESULT
-PUGL_API
-PuglStatus
+PUGL_WARN_UNUSED_RESULT PUGL_API PuglStatus
puglWinLeave(PuglView* view, const PuglExposeEvent* expose);
#endif // PUGL_SRC_WIN_H
diff --git a/src/win_cairo.c b/src/win_cairo.c
index 0aab254..873d395 100644
--- a/src/win_cairo.c
+++ b/src/win_cairo.c
@@ -5,7 +5,7 @@
#include "types.h"
#include "win.h"
-#include "pugl/cairo.h"
+#include <pugl/cairo.h>
#include <cairo-win32.h>
#include <cairo.h>
diff --git a/src/win_gl.c b/src/win_gl.c
index 8607bdd..4f33e36 100644
--- a/src/win_gl.c
+++ b/src/win_gl.c
@@ -5,7 +5,7 @@
#include "types.h"
#include "win.h"
-#include "pugl/gl.h"
+#include <pugl/gl.h>
#include <windows.h>
diff --git a/src/win_stub.c b/src/win_stub.c
index e98357c..d2dc3f3 100644
--- a/src/win_stub.c
+++ b/src/win_stub.c
@@ -5,7 +5,7 @@
#include "types.h"
#include "win.h"
-#include "pugl/stub.h"
+#include <pugl/stub.h>
static PuglStatus
puglWinStubConfigure(PuglView* view)
diff --git a/src/win_vulkan.c b/src/win_vulkan.c
index 2927447..bd3bf45 100644
--- a/src/win_vulkan.c
+++ b/src/win_vulkan.c
@@ -7,7 +7,7 @@
#include "types.h"
#include "win.h"
-#include "pugl/vulkan.h"
+#include <pugl/vulkan.h>
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_win32.h>
diff --git a/src/x11.c b/src/x11.c
index f60528b..3d2e080 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -11,7 +11,7 @@
#include "platform.h"
#include "types.h"
-#include "pugl/pugl.h"
+#include <pugl/pugl.h>
#include <X11/X.h>
#include <X11/Xatom.h>
@@ -70,7 +70,8 @@
#ifdef __cplusplus
# define PUGL_INIT_STRUCT \
- {}
+ { \
+ }
#else
# define PUGL_INIT_STRUCT {0}
#endif
@@ -404,14 +405,18 @@ updateSizeHints(const PuglView* const view)
XSizeHints sizeHints = PUGL_INIT_STRUCT;
if (!view->hints[PUGL_RESIZABLE]) {
- const PuglRect frame = puglGetFrame(view);
+ PuglArea size = puglGetSizeHint(view, PUGL_CURRENT_SIZE);
+ if (!puglIsValidSize(size.width, size.height)) {
+ size = puglGetSizeHint(view, PUGL_DEFAULT_SIZE);
+ }
+
sizeHints.flags = PBaseSize | PMinSize | PMaxSize;
- sizeHints.base_width = (int)frame.width;
- sizeHints.base_height = (int)frame.height;
- sizeHints.min_width = (int)frame.width;
- sizeHints.min_height = (int)frame.height;
- sizeHints.max_width = (int)frame.width;
- sizeHints.max_height = (int)frame.height;
+ sizeHints.base_width = (int)size.width;
+ sizeHints.base_height = (int)size.height;
+ sizeHints.min_width = (int)size.width;
+ sizeHints.min_height = (int)size.height;
+ sizeHints.max_width = (int)size.width;
+ sizeHints.max_height = (int)size.height;
} else {
// Avoid setting PBaseSize for top level views to avoid window manager bugs
const PuglArea defaultSize = view->sizeHints[PUGL_DEFAULT_SIZE];
@@ -522,8 +527,8 @@ puglGetAncestorCenter(const PuglView* const view)
&ancestorAttrs);
const PuglPoint center = {
- (PuglCoord)(ancestorAttrs.x + ancestorAttrs.width / 2),
- (PuglCoord)(ancestorAttrs.y + ancestorAttrs.height / 2)};
+ (PuglCoord)(ancestorAttrs.x + (ancestorAttrs.width / 2)),
+ (PuglCoord)(ancestorAttrs.y + (ancestorAttrs.height / 2))};
return center;
}
@@ -1000,7 +1005,7 @@ translateClientMessage(PuglView* const view, XClientMessageEvent message)
{
Display* const display = view->world->impl->display;
const PuglX11Atoms* const atoms = &view->world->impl->atoms;
- PuglEvent event = {{PUGL_NOTHING, 0}};
+ PuglEvent event = {{PUGL_NOTHING, 0U}};
if (message.message_type == atoms->WM_PROTOCOLS) {
const Atom protocol = (Atom)message.data.l[0];
@@ -1083,7 +1088,7 @@ getCurrentConfiguration(PuglView* const view)
}
// Build a configure event based on the current window configuration
- PuglEvent configureEvent = {{PUGL_CONFIGURE, 0}};
+ PuglEvent configureEvent = {{PUGL_CONFIGURE, 0U}};
configureEvent.configure.x = (PuglCoord)x;
configureEvent.configure.y = (PuglCoord)y;
configureEvent.configure.width = (PuglSpan)attrs.width;
@@ -1114,7 +1119,7 @@ translatePropertyNotify(PuglView* const view, XPropertyEvent message)
{
const PuglInternals* const impl = view->impl;
const PuglX11Atoms* const atoms = &view->world->impl->atoms;
- PuglEvent event = {{PUGL_NOTHING, 0}};
+ PuglEvent event = {{PUGL_NOTHING, 0U}};
if (message.atom == atoms->NET_WM_STATE) {
// Get all the current states set in the window hints
@@ -1164,7 +1169,7 @@ translatePropertyNotify(PuglView* const view, XPropertyEvent message)
static PuglEvent
translateEvent(PuglView* const view, XEvent xevent)
{
- PuglEvent event = {{PUGL_NOTHING, 0}};
+ PuglEvent event = {{PUGL_NOTHING, 0U}};
event.any.flags = xevent.xany.send_event ? PUGL_IS_SEND_EVENT : 0;
switch (xevent.type) {
@@ -1185,6 +1190,9 @@ translateEvent(PuglView* const view, XEvent xevent)
view->impl->mapped = false;
event = makeConfigureEvent(view);
break;
+ case DestroyNotify:
+ view->impl->win = None;
+ break;
case ConfigureNotify:
event = makeConfigureEvent(view);
event.configure.width = (PuglSpan)xevent.xconfigure.width;
@@ -1508,16 +1516,6 @@ puglSendEvent(PuglView* const view, const PuglEvent* const event)
return PUGL_UNSUPPORTED;
}
-#ifndef PUGL_DISABLE_DEPRECATED
-PuglStatus
-puglWaitForEvent(PuglView* const view)
-{
- XEvent xevent;
- XPeekEvent(view->world->impl->display, &xevent);
- return PUGL_SUCCESS;
-}
-#endif
-
static void
mergeExposeEvents(PuglExposeEvent* const dst, const PuglExposeEvent* const src)
{
@@ -1586,7 +1584,7 @@ handleSelectionNotify(const PuglWorld* const world,
Display* const display = view->world->impl->display;
const Atom selection = event->selection;
PuglX11Clipboard* const board = getX11SelectionClipboard(view, selection);
- PuglEvent puglEvent = {{PUGL_NOTHING, 0}};
+ PuglEvent puglEvent = {{PUGL_NOTHING, 0U}};
if (event->target == atoms->TARGETS) {
// Notification of available datatypes
@@ -1596,7 +1594,7 @@ handleSelectionNotify(const PuglWorld* const world,
view, event->requestor, event->property, &numFormats, &formats) &&
!setClipboardFormats(view, board, numFormats, formats)) {
const PuglDataOfferEvent offer = {
- PUGL_DATA_OFFER, 0, (double)event->time / 1e3};
+ PUGL_DATA_OFFER, 0U, (double)event->time / 1e3};
puglEvent.offer = offer;
board->acceptedFormatIndex = UINT32_MAX;
@@ -1673,8 +1671,7 @@ handleSelectionRequest(const PuglWorld* const world,
}
/// Flush pending configure and expose events for all views
-PUGL_WARN_UNUSED_RESULT
-static PuglStatus
+PUGL_WARN_UNUSED_RESULT static PuglStatus
flushExposures(PuglWorld* const world)
{
PuglStatus st0 = PUGL_SUCCESS;
@@ -1727,7 +1724,7 @@ handleTimerEvent(PuglWorld* const world, const XEvent xevent)
for (size_t i = 0; i < world->impl->numTimers; ++i) {
if (world->impl->timers[i].alarm == notify->alarm) {
- PuglEvent event = {{PUGL_TIMER, 0}};
+ PuglEvent event = {{PUGL_TIMER, 0U}};
event.timer.id = world->impl->timers[i].id;
puglDispatchEvent(world->impl->timers[i].view, &event);
}
@@ -1825,14 +1822,6 @@ dispatchX11Events(PuglWorld* const world)
return st;
}
-#ifndef PUGL_DISABLE_DEPRECATED
-PuglStatus
-puglProcessEvents(PuglView* const view)
-{
- return puglUpdate(view->world, 0.0);
-}
-#endif
-
PuglStatus
puglUpdate(PuglWorld* const world, const double timeout)
{
@@ -1871,7 +1860,10 @@ double
puglGetTime(const PuglWorld* const world)
{
struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
+ if (clock_gettime(CLOCK_MONOTONIC, &ts)) {
+ return 0.0;
+ }
+
return ((double)ts.tv_sec + (double)ts.tv_nsec / 1000000000.0) -
world->startTime;
}
@@ -1899,14 +1891,14 @@ puglObscureRegion(PuglView* const view,
const PuglSpan cw = MIN(view->lastConfigure.width, (PuglSpan)width);
const PuglSpan ch = MIN(view->lastConfigure.height, (PuglSpan)height);
- const PuglExposeEvent event = {PUGL_EXPOSE, 0, cx, cy, cw, ch};
+ const PuglExposeEvent event = {PUGL_EXPOSE, 0U, cx, cy, cw, ch};
if (view->world->impl->dispatchingEvents) {
// Currently dispatching events, add/expand expose for the loop end
mergeExposeEvents(&view->impl->pendingExpose.expose, &event);
} else if (view->impl->win) {
// Not dispatching events, send an X expose so we wake up next time
- PuglEvent exposeEvent = {{PUGL_EXPOSE, 0}};
+ PuglEvent exposeEvent = {{PUGL_EXPOSE, 0U}};
exposeEvent.expose = event;
return puglSendEvent(view, &exposeEvent);
}
@@ -1960,65 +1952,41 @@ puglGetScaleFactor(const PuglView* const view)
return view->world->impl->scaleFactor;
}
-PuglStatus
-puglSetFrame(PuglView* const view, const PuglRect frame)
-{
- if (!view->impl->win) {
- // Set defaults to be used when realized
- view->defaultX = frame.x;
- view->defaultY = frame.y;
- view->sizeHints[PUGL_DEFAULT_SIZE].width = frame.width;
- view->sizeHints[PUGL_DEFAULT_SIZE].height = frame.height;
- return PUGL_SUCCESS;
- }
-
- return puglX11Status(XMoveResizeWindow(view->world->impl->display,
- view->impl->win,
- frame.x,
- frame.y,
- frame.width,
- frame.height));
-}
-
-PuglStatus
-puglSetPosition(PuglView* const view, const int x, const int y)
+static PuglStatus
+puglSetWindowPosition(PuglView* const view, const int x, const int y)
{
- Display* const display = view->world->impl->display;
-
- if (!puglIsValidPosition(x, y)) {
- return PUGL_BAD_PARAMETER;
- }
-
- if (!view->impl->win) {
- // Set defaults to be used when realized
- view->defaultX = x;
- view->defaultY = y;
- return PUGL_SUCCESS;
- }
-
- return puglX11Status(XMoveWindow(display,
+ return puglX11Status(XMoveWindow(view->world->impl->display,
view->impl->win,
(int)(x - view->impl->frameExtentLeft),
(int)(y - view->impl->frameExtentTop)));
}
-PuglStatus
-puglSetSize(PuglView* const view, const unsigned width, const unsigned height)
+static PuglStatus
+puglSetWindowSize(PuglView* const view,
+ const unsigned width,
+ const unsigned height)
{
- Display* const display = view->world->impl->display;
+ return !view->impl->win
+ ? PUGL_SUCCESS
+ : puglX11Status(XResizeWindow(
+ view->world->impl->display, view->impl->win, width, height));
+}
- if (!puglIsValidSize(width, height)) {
+PuglStatus
+puglSetPositionHint(PuglView* const view,
+ const PuglPositionHint hint,
+ const int x,
+ const int y)
+{
+ if (x <= INT16_MIN || x > INT16_MAX || y <= INT16_MIN || y > INT16_MAX) {
return PUGL_BAD_PARAMETER;
}
- if (!view->impl->win) {
- // Set defaults to be used when realized
- view->sizeHints[PUGL_DEFAULT_SIZE].width = (PuglSpan)width;
- view->sizeHints[PUGL_DEFAULT_SIZE].height = (PuglSpan)height;
- return PUGL_SUCCESS;
- }
+ view->positionHints[hint].x = (PuglCoord)x;
+ view->positionHints[hint].y = (PuglCoord)y;
- return puglX11Status(XResizeWindow(display, view->impl->win, width, height));
+ return (hint == PUGL_CURRENT_POSITION) ? puglSetWindowPosition(view, x, y)
+ : PUGL_SUCCESS;
}
PuglStatus
@@ -2029,7 +1997,9 @@ puglSetSizeHint(PuglView* const view,
{
const PuglStatus st = puglStoreSizeHint(view, hint, width, height);
- return st ? st : updateSizeHints(view);
+ return st ? st
+ : (hint == PUGL_CURRENT_SIZE) ? puglSetWindowSize(view, width, height)
+ : updateSizeHints(view);
}
PuglStatus
diff --git a/src/x11.h b/src/x11.h
index bc93630..da9b4f6 100644
--- a/src/x11.h
+++ b/src/x11.h
@@ -7,8 +7,8 @@
#include "attributes.h"
#include "types.h"
-#include "pugl/attributes.h"
-#include "pugl/pugl.h"
+#include <pugl/attributes.h>
+#include <pugl/pugl.h>
#include <X11/X.h>
#include <X11/Xlib.h>
@@ -93,9 +93,7 @@ struct PuglInternalsImpl {
bool mapped;
};
-PUGL_WARN_UNUSED_RESULT
-PUGL_API
-PuglStatus
+PUGL_WARN_UNUSED_RESULT PUGL_API PuglStatus
puglX11Configure(PuglView* view);
#endif // PUGL_SRC_X11_H
diff --git a/src/x11_cairo.c b/src/x11_cairo.c
index ff0b154..bc7b133 100644
--- a/src/x11_cairo.c
+++ b/src/x11_cairo.c
@@ -5,8 +5,8 @@
#include "types.h"
#include "x11.h"
-#include "pugl/cairo.h"
-#include "pugl/pugl.h"
+#include <pugl/cairo.h>
+#include <pugl/pugl.h>
#include <cairo-xlib.h>
#include <cairo.h>
diff --git a/src/x11_gl.c b/src/x11_gl.c
index de22b34..527335b 100644
--- a/src/x11_gl.c
+++ b/src/x11_gl.c
@@ -6,8 +6,8 @@
#include "types.h"
#include "x11.h"
-#include "pugl/gl.h"
-#include "pugl/pugl.h"
+#include <pugl/gl.h>
+#include <pugl/pugl.h>
#include <GL/glx.h>
#include <X11/X.h>
@@ -101,8 +101,7 @@ puglX11GlConfigure(PuglView* view)
return PUGL_SUCCESS;
}
-PUGL_WARN_UNUSED_RESULT
-static PuglStatus
+PUGL_WARN_UNUSED_RESULT static PuglStatus
puglX11GlEnter(PuglView* view, const PuglExposeEvent* PUGL_UNUSED(expose))
{
PuglX11GlSurface* surface = (PuglX11GlSurface*)view->impl->surface;
@@ -115,8 +114,7 @@ puglX11GlEnter(PuglView* view, const PuglExposeEvent* PUGL_UNUSED(expose))
: PUGL_FAILURE;
}
-PUGL_WARN_UNUSED_RESULT
-static PuglStatus
+PUGL_WARN_UNUSED_RESULT static PuglStatus
puglX11GlLeave(PuglView* view, const PuglExposeEvent* expose)
{
Display* const display = view->world->impl->display;
diff --git a/src/x11_stub.c b/src/x11_stub.c
index 844b4db..11143fe 100644
--- a/src/x11_stub.c
+++ b/src/x11_stub.c
@@ -1,13 +1,13 @@
// Copyright 2012-2021 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#include "pugl/stub.h"
+#include <pugl/stub.h>
#include "stub.h"
#include "types.h"
#include "x11.h"
-#include "pugl/pugl.h"
+#include <pugl/pugl.h>
const PuglBackend*
puglStubBackend(void)
diff --git a/src/x11_vulkan.c b/src/x11_vulkan.c
index 834ac37..078e524 100644
--- a/src/x11_vulkan.c
+++ b/src/x11_vulkan.c
@@ -8,8 +8,8 @@
#include "types.h"
#include "x11.h"
-#include "pugl/pugl.h"
-#include "pugl/vulkan.h"
+#include <pugl/pugl.h>
+#include <pugl/vulkan.h>
#include <vulkan/vulkan_core.h>
#include <vulkan/vulkan_xlib.h>