Skip to content

Commit

Permalink
Fix clang-tidy issues in Windows code
Browse files Browse the repository at this point in the history
  • Loading branch information
drobilla committed Oct 21, 2020
1 parent d678291 commit 74a2b23
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 34 deletions.
51 changes: 24 additions & 27 deletions include/pugl/detail/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,9 @@ puglRealize(PuglView* view)
return PUGL_BAD_BACKEND;
}

PuglStatus st;
if ((st = view->backend->configure(view))) {
return st;
} else if ((st = view->backend->create(view))) {
PuglStatus st = PUGL_SUCCESS;
if ((st = view->backend->configure(view)) ||
(st = view->backend->create(view))) {
return st;
}

Expand Down Expand Up @@ -418,9 +417,9 @@ initKeyEvent(PuglEventKey* event,
const PuglKey special = keySymToSpecial(vkey);
if (special) {
if (ext && (special == PUGL_KEY_CTRL || special == PUGL_KEY_ALT)) {
event->key = special + 1u; // Right hand key
event->key = (uint32_t)special + 1u; // Right hand key
} else {
event->key = special;
event->key = (uint32_t)special;
}
} else if (!dead) {
// Translate unshifted key
Expand Down Expand Up @@ -511,33 +510,33 @@ constrainAspect(const PuglView* const view,
{
const float minA = (float)view->minAspectX / (float)view->minAspectY;
const float maxA = (float)view->maxAspectX / (float)view->maxAspectY;
const int w = size->right - size->left;
const int h = size->bottom - size->top;
const float a = (float)w / (float)h;
const float w = (float)(size->right - size->left);
const float h = (float)(size->bottom - size->top);
const float a = w / h;

switch (wParam) {
case WMSZ_TOP:
size->top = (a < minA ? (LONG)(size->bottom - w * minA) :
a > maxA ? (LONG)(size->bottom - w * maxA) :
size->top = (a < minA ? (LONG)((float)size->bottom - w * minA) :
a > maxA ? (LONG)((float)size->bottom - w * maxA) :
size->top);
break;
case WMSZ_TOPRIGHT:
case WMSZ_RIGHT:
case WMSZ_BOTTOMRIGHT:
size->right = (a < minA ? (LONG)(size->left + h * minA) :
a > maxA ? (LONG)(size->left + h * maxA) :
size->right = (a < minA ? (LONG)((float)size->left + h * minA) :
a > maxA ? (LONG)((float)size->left + h * maxA) :
size->right);
break;
case WMSZ_BOTTOM:
size->bottom = (a < minA ? (LONG)(size->top + w * minA) :
a > maxA ? (LONG)(size->top + w * maxA) :
size->bottom = (a < minA ? (LONG)((float)size->top + w * minA) :
a > maxA ? (LONG)((float)size->top + w * maxA) :
size->bottom);
break;
case WMSZ_BOTTOMLEFT:
case WMSZ_LEFT:
case WMSZ_TOPLEFT:
size->left = (a < minA ? (LONG)(size->right - h * minA) :
a > maxA ? (LONG)(size->right - h * maxA) :
size->left = (a < minA ? (LONG)((float)size->right - h * minA) :
a > maxA ? (LONG)((float)size->right - h * maxA) :
size->left);
break;
}
Expand All @@ -546,15 +545,12 @@ constrainAspect(const PuglView* const view,
static LRESULT
handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
{
PuglEvent event;
PuglEvent event = {{PUGL_NOTHING, 0}};
RECT rect = {0, 0, 0, 0};
POINT pt = {0, 0};
MINMAXINFO* mmi = NULL;
void* dummy_ptr = NULL;
RECT rect;
MINMAXINFO* mmi;
POINT pt;

memset(&event, 0, sizeof(event));

event.any.type = PUGL_NOTHING;
if (InSendMessageEx(dummy_ptr)) {
event.any.flags |= PUGL_IS_SEND_EVENT;
}
Expand Down Expand Up @@ -686,14 +682,14 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_MOUSEWHEEL:
initScrollEvent(&event, view, lParam);
event.scroll.dy = GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA;
event.scroll.dy = GET_WHEEL_DELTA_WPARAM(wParam) / (double)WHEEL_DELTA;
event.scroll.direction = (event.scroll.dy > 0
? PUGL_SCROLL_UP
: PUGL_SCROLL_DOWN);
break;
case WM_MOUSEHWHEEL:
initScrollEvent(&event, view, lParam);
event.scroll.dx = GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA;
event.scroll.dx = GET_WHEEL_DELTA_WPARAM(wParam) / (double)WHEEL_DELTA;
event.scroll.direction = (event.scroll.dx > 0
? PUGL_SCROLL_RIGHT
: PUGL_SCROLL_LEFT);
Expand Down Expand Up @@ -1094,7 +1090,8 @@ puglSetClipboard(PuglView* const view,
// Measure string and allocate global memory for clipboard
const char* str = (const char*)data;
const int wlen = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (wlen + 1) * sizeof(wchar_t));
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE,
(size_t)(wlen + 1) * sizeof(wchar_t));
if (!mem) {
CloseClipboard();
return PUGL_UNKNOWN_ERROR;
Expand Down
5 changes: 2 additions & 3 deletions include/pugl/detail/win_cairo.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ puglWinCairoOpen(PuglView* view)
PuglInternals* const impl = view->impl;
PuglWinCairoSurface* const surface = (PuglWinCairoSurface*)impl->surface;

cairo_status_t st = CAIRO_STATUS_SUCCESS;
if (!(surface->surface = cairo_win32_surface_create(surface->drawDc)) ||
(st = cairo_surface_status(surface->surface)) ||
cairo_surface_status(surface->surface) ||
!(surface->cr = cairo_create(surface->surface)) ||
(st = cairo_status(surface->cr))) {
cairo_status(surface->cr)) {
return PUGL_CREATE_CONTEXT_FAILED;
}

Expand Down
4 changes: 1 addition & 3 deletions include/pugl/detail/win_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ puglWinGlConfigure(PuglView* view)
// Set pixel format for fake window
const PuglWinPFD fakePfd = puglWinGetPixelFormatDescriptor(view->hints);
const int fakePfId = ChoosePixelFormat(fakeWin.hdc, &fakePfd);
if (!fakePfId) {
return puglWinError(&fakeWin, PUGL_SET_FORMAT_FAILED);
} else if (!SetPixelFormat(fakeWin.hdc, fakePfId, &fakePfd)) {
if (!fakePfId || !SetPixelFormat(fakeWin.hdc, fakePfId, &fakePfd)) {
return puglWinError(&fakeWin, PUGL_SET_FORMAT_FAILED);
}

Expand Down
2 changes: 1 addition & 1 deletion test/test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ logError(const char* fmt, ...)
{
fprintf(stderr, "error: ");

va_list args;
va_list args; // NOLINT
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
Expand Down

0 comments on commit 74a2b23

Please sign in to comment.