aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-03-01 20:07:52 +0100
committerDavid Robillard <d@drobilla.net>2020-03-01 20:32:42 +0100
commit0d37c19ac71d153a093960eadccf791f54fc2547 (patch)
tree68fd172ac323e9f2e77c25dba05f21a73861af27
parent94a2d5c31e6bad7e33a03bf282dc60d08f923526 (diff)
Cleanup: Adjust some code to be more clang-format friendly
-rw-r--r--pugl/detail/implementation.c11
-rw-r--r--pugl/detail/mac.m88
-rw-r--r--pugl/detail/win.c41
-rw-r--r--pugl/detail/win.h18
-rw-r--r--pugl/detail/win_gl.c36
-rw-r--r--pugl/detail/x11.c16
-rw-r--r--test/test_utils.h6
7 files changed, 128 insertions, 88 deletions
diff --git a/pugl/detail/implementation.c b/pugl/detail/implementation.c
index 917efa6..83f63ae 100644
--- a/pugl/detail/implementation.c
+++ b/pugl/detail/implementation.c
@@ -28,6 +28,7 @@
const char*
puglStrerror(const PuglStatus status)
{
+ // clang-format off
switch (status) {
case PUGL_SUCCESS: return "Success";
case PUGL_FAILURE: return "Non-fatal failure";
@@ -40,6 +41,7 @@ puglStrerror(const PuglStatus status)
case PUGL_CREATE_CONTEXT_FAILED: return "Failed to create drawing context";
case PUGL_UNSUPPORTED_TYPE: return "Unsupported data type";
}
+ // clang-format on
return "Unknown error";
}
@@ -136,6 +138,7 @@ puglNewView(PuglWorld* const world)
++world->numViews;
world->views = (PuglView**)realloc(world->views,
world->numViews * sizeof(PuglView*));
+
world->views[world->numViews - 1] = view;
return view;
@@ -280,10 +283,10 @@ puglDecodeUTF8(const uint8_t* buf)
FAIL_IF(buf[0] == 0xF4 && buf[1] >= 0x90);
FAIL_IF((buf[2] & 0xC0u) != 0x80u);
FAIL_IF((buf[3] & 0xC0u) != 0x80u);
- return ((buf[0] << 18u) +
- (buf[1] << 12u) +
- (buf[2] << 6u) +
- buf[3] - 0x3C82080u);
+ return ((buf[0] << 18u) + //
+ (buf[1] << 12u) + //
+ (buf[2] << 6u) + //
+ (buf[3] - 0x3C82080u));
}
return 0xFFFD;
}
diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m
index 36499c0..a9f527f 100644
--- a/pugl/detail/mac.m
+++ b/pugl/detail/mac.m
@@ -245,8 +245,9 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
rloc.x,
[[NSScreen mainScreen] frame].size.height - rloc.y,
getModifiers(event),
- PUGL_CROSSING_NORMAL
+ PUGL_CROSSING_NORMAL,
};
+
puglDispatchEvent(view->puglview, (const PuglEvent*)&ev);
}
@@ -274,8 +275,9 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
[[NSScreen mainScreen] frame].size.height - rloc.y,
getModifiers(event),
0,
- 1
+ 1,
};
+
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
}
@@ -307,8 +309,9 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
rloc.x,
[[NSScreen mainScreen] frame].size.height - rloc.y,
getModifiers(event),
- (uint32_t)[event buttonNumber] + 1
+ (uint32_t)[event buttonNumber] + 1,
};
+
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
}
@@ -325,8 +328,9 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
rloc.x,
[[NSScreen mainScreen] frame].size.height - rloc.y,
getModifiers(event),
- (uint32_t)[event buttonNumber] + 1
+ (uint32_t)[event buttonNumber] + 1,
};
+
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
}
@@ -364,8 +368,9 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
[[NSScreen mainScreen] frame].size.height - rloc.y,
getModifiers(event),
[event scrollingDeltaX],
- [event scrollingDeltaY]
+ [event scrollingDeltaY],
};
+
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
}
@@ -375,13 +380,12 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
return;
}
- const NSPoint wloc = [self eventLocation:event];
- const NSPoint rloc = [NSEvent mouseLocation];
- const PuglKey spec = keySymToSpecial(event);
- const NSString* chars = [event charactersIgnoringModifiers];
- const char* str = [[chars lowercaseString] UTF8String];
- const uint32_t code = (
- spec ? spec : puglDecodeUTF8((const uint8_t*)str));
+ const NSPoint wloc = [self eventLocation:event];
+ const NSPoint rloc = [NSEvent mouseLocation];
+ const PuglKey spec = keySymToSpecial(event);
+ const NSString* chars = [event charactersIgnoringModifiers];
+ const char* str = [[chars lowercaseString] UTF8String];
+ const uint32_t code = (spec ? spec : puglDecodeUTF8((const uint8_t*)str));
const PuglEventKey ev = {
PUGL_KEY_PRESS,
@@ -393,7 +397,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
[[NSScreen mainScreen] frame].size.height - rloc.y,
getModifiers(event),
[event keyCode],
- (code != 0xFFFD) ? code : 0
+ (code != 0xFFFD) ? code : 0,
};
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
@@ -403,15 +407,14 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
}
}
-- (void) keyUp:(NSEvent*)event
+- (void)keyUp:(NSEvent*)event
{
- const NSPoint wloc = [self eventLocation:event];
- const NSPoint rloc = [NSEvent mouseLocation];
- const PuglKey spec = keySymToSpecial(event);
- const NSString* chars = [event charactersIgnoringModifiers];
- const char* str = [[chars lowercaseString] UTF8String];
- const uint32_t code =
- (spec ? spec : puglDecodeUTF8((const uint8_t*)str));
+ const NSPoint wloc = [self eventLocation:event];
+ const NSPoint rloc = [NSEvent mouseLocation];
+ const PuglKey spec = keySymToSpecial(event);
+ const NSString* chars = [event charactersIgnoringModifiers];
+ const char* str = [[chars lowercaseString] UTF8String];
+ const uint32_t code = (spec ? spec : puglDecodeUTF8((const uint8_t*)str));
const PuglEventKey ev = {
PUGL_KEY_RELEASE,
@@ -423,8 +426,9 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
[[NSScreen mainScreen] frame].size.height - rloc.y,
getModifiers(event),
[event keyCode],
- (code != 0xFFFD) ? code : 0
+ (code != 0xFFFD) ? code : 0,
};
+
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
}
@@ -524,17 +528,19 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
range:NSMakeRange(i, i + 1)
remainingRange:nil];
- PuglEventText ev = { PUGL_TEXT,
- 0,
- [event timestamp],
- wloc.x,
- wloc.y,
- rloc.x,
- [[NSScreen mainScreen] frame].size.height - rloc.y,
- getModifiers(event),
- [event keyCode],
- code,
- { 0, 0, 0, 0, 0, 0, 0, 0 } };
+ PuglEventText ev = {
+ PUGL_TEXT,
+ 0,
+ [event timestamp],
+ wloc.x,
+ wloc.y,
+ rloc.x,
+ [[NSScreen mainScreen] frame].size.height - rloc.y,
+ getModifiers(event),
+ [event keyCode],
+ code,
+ { 0, 0, 0, 0, 0, 0, 0, 0 },
+ };
memcpy(ev.string, utf8, len);
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
@@ -1079,13 +1085,15 @@ puglSetClipboard(PuglView* const view,
const PuglBackend*
puglStubBackend(void)
{
- static const PuglBackend backend = {puglStubConfigure,
- puglStubCreate,
- puglStubDestroy,
- puglStubEnter,
- puglStubLeave,
- puglStubResize,
- puglStubGetContext};
+ static const PuglBackend backend = {
+ puglStubConfigure,
+ puglStubCreate,
+ puglStubDestroy,
+ puglStubEnter,
+ puglStubLeave,
+ puglStubResize,
+ puglStubGetContext,
+ };
return &backend;
}
diff --git a/pugl/detail/win.c b/pugl/detail/win.c
index 8a9ff0a..5a3dc43 100644
--- a/pugl/detail/win.c
+++ b/pugl/detail/win.c
@@ -240,6 +240,7 @@ puglFreeWorldInternals(PuglWorld* world)
static PuglKey
keySymToSpecial(WPARAM sym)
{
+ // clang-format off
switch (sym) {
case VK_F1: return PUGL_KEY_F1;
case VK_F2: return PUGL_KEY_F2;
@@ -281,17 +282,21 @@ keySymToSpecial(WPARAM sym)
case VK_SNAPSHOT: return PUGL_KEY_PRINT_SCREEN;
case VK_PAUSE: return PUGL_KEY_PAUSE;
}
+ // clang-format on
+
return (PuglKey)0;
}
static uint32_t
getModifiers(void)
{
+ // clang-format off
return (((GetKeyState(VK_SHIFT) < 0) ? PUGL_MOD_SHIFT : 0u) |
((GetKeyState(VK_CONTROL) < 0) ? PUGL_MOD_CTRL : 0u) |
((GetKeyState(VK_MENU) < 0) ? PUGL_MOD_ALT : 0u) |
((GetKeyState(VK_LWIN) < 0) ? PUGL_MOD_SUPER : 0u) |
((GetKeyState(VK_RWIN) < 0) ? PUGL_MOD_SUPER : 0u));
+ // clang-format on
}
static void
@@ -400,8 +405,9 @@ initKeyEvent(PuglEventKey* event,
// Translate unshifted key
BYTE keyboardState[256] = {0};
wchar_t buf[5] = {0};
- const int ulen = ToUnicode(vkey, vcode, keyboardState, buf, 4, 1<<2);
- event->key = puglDecodeUTF16(buf, ulen);
+
+ event->key = puglDecodeUTF16(
+ buf, ToUnicode(vkey, vcode, keyboardState, buf, 4, 1 << 2));
}
}
@@ -473,8 +479,9 @@ handleCrossing(PuglView* view, const PuglEventType type, POINT pos)
(double)root_pos.x,
(double)root_pos.y,
getModifiers(),
- PUGL_CROSSING_NORMAL
+ PUGL_CROSSING_NORMAL,
};
+
puglDispatchEvent(view, (const PuglEvent*)&ev);
}
@@ -602,6 +609,7 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
if (!view->impl->mouseTracked) {
TRACKMOUSEEVENT tme = {0};
+
tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = view->impl->hwnd;
@@ -846,10 +854,13 @@ puglSetFrame(PuglView* view, const PuglRect frame)
FALSE,
puglWinGetWindowExFlags(view));
- if (!SetWindowPos(view->impl->hwnd, HWND_TOP,
- rect.left, rect.top,
- rect.right - rect.left, rect.bottom - rect.top,
- (SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER))) {
+ if (!SetWindowPos(view->impl->hwnd,
+ HWND_TOP,
+ rect.left,
+ rect.top,
+ rect.right - rect.left,
+ rect.bottom - rect.top,
+ SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER)) {
return PUGL_UNKNOWN_ERROR;
}
}
@@ -973,13 +984,15 @@ puglWinStubLeave(PuglView* view, const PuglEventExpose* expose)
const PuglBackend*
puglStubBackend(void)
{
- static const PuglBackend backend = {puglWinStubConfigure,
- puglStubCreate,
- puglStubDestroy,
- puglWinStubEnter,
- puglWinStubLeave,
- puglStubResize,
- puglStubGetContext};
+ static const PuglBackend backend = {
+ puglWinStubConfigure,
+ puglStubCreate,
+ puglStubDestroy,
+ puglWinStubEnter,
+ puglWinStubLeave,
+ puglStubResize,
+ puglStubGetContext,
+ };
return &backend;
}
diff --git a/pugl/detail/win.h b/pugl/detail/win.h
index e9056b7..4219a36 100644
--- a/pugl/detail/win.h
+++ b/pugl/detail/win.h
@@ -45,16 +45,17 @@ struct PuglInternalsImpl {
static inline PuglWinPFD
puglWinGetPixelFormatDescriptor(const PuglHints hints)
{
- const int rgbBits = (hints[PUGL_RED_BITS] +
- hints[PUGL_GREEN_BITS] +
+ const int rgbBits = (hints[PUGL_RED_BITS] + //
+ hints[PUGL_GREEN_BITS] + //
hints[PUGL_BLUE_BITS]);
+ const DWORD dwFlags = hints[PUGL_DOUBLE_BUFFER] ? PFD_DOUBLEBUFFER : 0;
+
PuglWinPFD pfd;
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
- pfd.dwFlags = PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL;
- pfd.dwFlags |= hints[PUGL_DOUBLE_BUFFER] ? PFD_DOUBLEBUFFER : 0;
+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | dwFlags;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = (BYTE)rgbBits;
pfd.cRedBits = (BYTE)hints[PUGL_RED_BITS];
@@ -70,12 +71,13 @@ puglWinGetPixelFormatDescriptor(const PuglHints hints)
static inline unsigned
puglWinGetWindowFlags(const PuglView* const view)
{
- const bool resizable = view->hints[PUGL_RESIZABLE];
+ const bool resizable = view->hints[PUGL_RESIZABLE];
+ const unsigned sizeFlags = resizable ? (WS_SIZEBOX | WS_MAXIMIZEBOX) : 0;
+
return (WS_CLIPCHILDREN | WS_CLIPSIBLINGS |
(view->parent
- ? WS_CHILD
- : (WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX |
- (resizable ? (WS_SIZEBOX | WS_MAXIMIZEBOX) : 0))));
+ ? WS_CHILD
+ : (WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX | sizeFlags)));
}
static inline unsigned
diff --git a/pugl/detail/win_gl.c b/pugl/detail/win_gl.c
index c09e23a..d722d28 100644
--- a/pugl/detail/win_gl.c
+++ b/pugl/detail/win_gl.c
@@ -109,6 +109,7 @@ puglWinGlConfigure(PuglView* view)
{
PuglInternals* impl = view->impl;
+ // clang-format off
const int pixelAttrs[] = {
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
@@ -125,16 +126,17 @@ puglWinGlConfigure(PuglView* view)
WGL_STENCIL_BITS_ARB, view->hints[PUGL_STENCIL_BITS],
0,
};
+ // clang-format on
PuglWinGlSurface* const surface =
(PuglWinGlSurface*)calloc(1, sizeof(PuglWinGlSurface));
impl->surface = surface;
// Create fake window for getting at GL context
- PuglStatus st = PUGL_SUCCESS;
- PuglFakeWindow fakeWin = { 0, 0 };
- if ((st = puglWinCreateWindow(view, "Pugl Configuration",
- &fakeWin.hwnd, &fakeWin.hdc))) {
+ PuglStatus st = PUGL_SUCCESS;
+ PuglFakeWindow fakeWin = {0, 0};
+ static const char* title = "Pugl Configuration";
+ if ((st = puglWinCreateWindow(view, title, &fakeWin.hwnd, &fakeWin.hdc))) {
return puglWinError(&fakeWin, st);
}
@@ -190,17 +192,21 @@ puglWinGlCreate(PuglView* view)
PuglStatus st = PUGL_SUCCESS;
const int contextAttribs[] = {
- WGL_CONTEXT_MAJOR_VERSION_ARB, view->hints[PUGL_CONTEXT_VERSION_MAJOR],
- WGL_CONTEXT_MINOR_VERSION_ARB, view->hints[PUGL_CONTEXT_VERSION_MINOR],
- WGL_CONTEXT_FLAGS_ARB, (view->hints[PUGL_USE_DEBUG_CONTEXT]
- ? WGL_CONTEXT_DEBUG_BIT_ARB
- : 0),
- WGL_CONTEXT_PROFILE_MASK_ARB,
- (view->hints[PUGL_USE_COMPAT_PROFILE]
- ? WGL_CONTEXT_CORE_PROFILE_BIT_ARB
- : WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB),
- 0
- };
+ WGL_CONTEXT_MAJOR_VERSION_ARB,
+ view->hints[PUGL_CONTEXT_VERSION_MAJOR],
+
+ WGL_CONTEXT_MINOR_VERSION_ARB,
+ view->hints[PUGL_CONTEXT_VERSION_MINOR],
+
+ WGL_CONTEXT_FLAGS_ARB,
+ (view->hints[PUGL_USE_DEBUG_CONTEXT] ? WGL_CONTEXT_DEBUG_BIT_ARB : 0),
+
+ WGL_CONTEXT_PROFILE_MASK_ARB,
+ (view->hints[PUGL_USE_COMPAT_PROFILE]
+ ? WGL_CONTEXT_CORE_PROFILE_BIT_ARB
+ : WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB),
+
+ 0};
// Create real window with desired pixel format
if ((st = puglWinCreateWindow(view, "Pugl", &impl->hwnd, &impl->hdc))) {
diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c
index 347876a..3531b12 100644
--- a/pugl/detail/x11.c
+++ b/pugl/detail/x11.c
@@ -952,13 +952,15 @@ puglSetClipboard(PuglView* const view,
const PuglBackend*
puglStubBackend(void)
{
- static const PuglBackend backend = {puglX11StubConfigure,
- puglStubCreate,
- puglStubDestroy,
- puglStubEnter,
- puglStubLeave,
- puglStubResize,
- puglStubGetContext};
+ static const PuglBackend backend = {
+ puglX11StubConfigure,
+ puglStubCreate,
+ puglStubDestroy,
+ puglStubEnter,
+ puglStubLeave,
+ puglStubResize,
+ puglStubGetContext,
+ };
return &backend;
}
diff --git a/test/test_utils.h b/test/test_utils.h
index 4207576..2142b2d 100644
--- a/test/test_utils.h
+++ b/test/test_utils.h
@@ -40,6 +40,8 @@ typedef struct {
typedef float vec4[4];
typedef vec4 mat4[4];
+// clang-format off
+
static const float cubeStripVertices[] = {
-1.0f, 1.0f, 1.0f, // Front top left
1.0f, 1.0f, 1.0f, // Front top right
@@ -85,6 +87,8 @@ static const float cubeSideLines[] = {
1.0f, -1.0f, -1.0f, // Back bottom right
};
+// clang-format on
+
static inline void
mat4Identity(mat4 m)
{
@@ -150,10 +154,12 @@ perspective(float* m, float fov, float aspect, float zNear, float zFar)
const float q = (zFar + zNear) / depth;
const float qn = 2 * zFar * zNear / depth;
+ // clang-format off
m[0] = w; m[1] = 0; m[2] = 0; m[3] = 0;
m[4] = 0; m[5] = h; m[6] = 0; m[7] = 0;
m[8] = 0; m[9] = 0; m[10] = q; m[11] = -1;
m[12] = 0; m[13] = 0; m[14] = qn; m[15] = 0;
+ // clang-format on
}
static inline int