X11/wl/mir: Introduce new block scopes to hold variables.

This makes the project compile successfully
when -Wdeclaration-after-statement is enabled.
This commit is contained in:
Sebastian Rasmussen 2017-06-01 00:02:57 +08:00
parent 372e908682
commit 2a23666e00
6 changed files with 271 additions and 215 deletions

View File

@ -138,6 +138,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
if (id != monitor->mir.outputId) if (id != monitor->mir.outputId)
continue; continue;
{
MirOutputConnectionState state = mir_output_get_connection_state(output); MirOutputConnectionState state = mir_output_get_connection_state(output);
bool enabled = mir_output_is_enabled(output); bool enabled = mir_output_is_enabled(output);
@ -148,7 +149,10 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
"Mir: Monitor no longer connected"); "Mir: Monitor no longer connected");
return NULL; return NULL;
} }
}
{
int numModes = mir_output_get_num_modes(output); int numModes = mir_output_get_num_modes(output);
modes = calloc(numModes, sizeof(GLFWvidmode)); modes = calloc(numModes, sizeof(GLFWvidmode));
@ -166,6 +170,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
FillInRGBBitsFromPixelFormat(&modes[*found], currentFormat); FillInRGBBitsFromPixelFormat(&modes[*found], currentFormat);
} }
}
break; break;
} }

View File

@ -205,14 +205,16 @@ static void handlePointerMotion(_GLFWwindow* window,
{ {
if (_glfw.mir.disabledCursorWindow != window) if (_glfw.mir.disabledCursorWindow != window)
return; return;
else
const int dx = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_relative_x); {
const int dy = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_relative_y); int dx = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_relative_x);
const int current_x = window->virtualCursorPosX; int dy = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_relative_y);
const int current_y = window->virtualCursorPosY; int current_x = window->virtualCursorPosX;
int current_y = window->virtualCursorPosY;
_glfwInputCursorPos(window, dx + current_x, dy + current_y); _glfwInputCursorPos(window, dx + current_x, dy + current_y);
} }
}
else else
{ {
const int x = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_x); const int x = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_x);
@ -701,13 +703,15 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
cursor->mir.conf = mir_cursor_configuration_from_buffer_stream(stream, xhot, yhot); cursor->mir.conf = mir_cursor_configuration_from_buffer_stream(stream, xhot, yhot);
{
MirGraphicsRegion region; MirGraphicsRegion region;
mir_buffer_stream_get_graphics_region(stream, &region);
unsigned char* pixels = image->pixels; unsigned char* pixels = image->pixels;
char* dest = region.vaddr; char* dest;
int i; int i;
mir_buffer_stream_get_graphics_region(stream, &region);
dest = region.vaddr;
for (i = 0; i < i_w * i_h; i++, pixels += 4) for (i = 0; i < i_w * i_h; i++, pixels += 4)
{ {
unsigned int alpha = pixels[3]; unsigned int alpha = pixels[3];
@ -716,6 +720,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
*dest++ = (char)(pixels[0] * alpha / 255); *dest++ = (char)(pixels[0] * alpha / 255);
*dest++ = (char)alpha; *dest++ = (char)alpha;
} }
}
mir_buffer_stream_swap_buffers_sync(stream); mir_buffer_stream_swap_buffers_sync(stream);
cursor->mir.customCursor = stream; cursor->mir.customCursor = stream;

View File

@ -763,8 +763,11 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
pool = wl_shm_create_pool(_glfw.wl.shm, fd, length); pool = wl_shm_create_pool(_glfw.wl.shm, fd, length);
close(fd); close(fd);
{
unsigned char* source = (unsigned char*) image->pixels; unsigned char* source = (unsigned char*) image->pixels;
unsigned char* target = data; unsigned char* target = data;
for (i = 0; i < image->width * image->height; i++, source += 4) for (i = 0; i < image->width * image->height; i++, source += 4)
{ {
unsigned int alpha = source[3]; unsigned int alpha = source[3];
@ -774,6 +777,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
*target++ = (unsigned char) ((source[0] * alpha) / 255); *target++ = (unsigned char) ((source[0] * alpha) / 255);
*target++ = (unsigned char) alpha; *target++ = (unsigned char) alpha;
} }
}
cursor->wl.buffer = cursor->wl.buffer =
wl_shm_pool_create_buffer(pool, 0, wl_shm_pool_create_buffer(pool, 0,

View File

@ -416,7 +416,7 @@ static void detectEWMH(void)
XFree(windowFromChild); XFree(windowFromChild);
// We are now fairly sure that an EWMH-compliant window manager is running // We are now fairly sure that an EWMH-compliant window manager is running
{
Atom* supportedAtoms; Atom* supportedAtoms;
unsigned long atomCount; unsigned long atomCount;
@ -456,6 +456,7 @@ static void detectEWMH(void)
if (supportedAtoms) if (supportedAtoms)
XFree(supportedAtoms); XFree(supportedAtoms);
} }
}
// Look for and initialize supported X11 extensions // Look for and initialize supported X11 extensions
// //
@ -736,6 +737,7 @@ Cursor _glfwCreateCursorX11(const GLFWimage* image, int xhot, int yhot)
native->xhot = xhot; native->xhot = xhot;
native->yhot = yhot; native->yhot = yhot;
{
unsigned char* source = (unsigned char*) image->pixels; unsigned char* source = (unsigned char*) image->pixels;
XcursorPixel* target = native->pixels; XcursorPixel* target = native->pixels;
@ -748,6 +750,7 @@ Cursor _glfwCreateCursorX11(const GLFWimage* image, int xhot, int yhot)
((unsigned char) ((source[1] * alpha) / 255) << 8) | ((unsigned char) ((source[1] * alpha) / 255) << 8) |
((unsigned char) ((source[2] * alpha) / 255) << 0); ((unsigned char) ((source[2] * alpha) / 255) << 0);
} }
}
cursor = XcursorImageLoadCursor(_glfw.x11.display, native); cursor = XcursorImageLoadCursor(_glfw.x11.display, native);
XcursorImageDestroy(native); XcursorImageDestroy(native);

View File

@ -241,16 +241,19 @@ GLFWbool _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired)
for (i = 0; i < oi->nmode; i++) for (i = 0; i < oi->nmode; i++)
{ {
const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]); const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]);
if (!modeIsGood(mi)) if (!modeIsGood(mi))
continue; continue;
const GLFWvidmode mode = vidmodeFromModeInfo(mi, ci); {
GLFWvidmode mode = vidmodeFromModeInfo(mi, ci);
if (_glfwCompareVideoModes(best, &mode) == 0) if (_glfwCompareVideoModes(best, &mode) == 0)
{ {
native = mi->id; native = mi->id;
break; break;
} }
} }
}
if (native) if (native)
{ {
@ -360,10 +363,12 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
for (i = 0; i < oi->nmode; i++) for (i = 0; i < oi->nmode; i++)
{ {
const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]); const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]);
if (!modeIsGood(mi)) if (!modeIsGood(mi))
continue; continue;
const GLFWvidmode mode = vidmodeFromModeInfo(mi, ci); {
GLFWvidmode mode = vidmodeFromModeInfo(mi, ci);
for (j = 0; j < *count; j++) for (j = 0; j < *count; j++)
{ {
@ -378,6 +383,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
(*count)++; (*count)++;
result[*count - 1] = mode; result[*count - 1] = mode;
} }
}
XRRFreeOutputInfo(oi); XRRFreeOutputInfo(oi);
XRRFreeCrtcInfo(ci); XRRFreeCrtcInfo(ci);
@ -453,13 +459,15 @@ void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken) if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken)
{ {
if (XRRGetCrtcGammaSize(_glfw.x11.display, monitor->x11.crtc) != ramp->size) if (XRRGetCrtcGammaSize(_glfw.x11.display, monitor->x11.crtc) != ramp->size)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Gamma ramp size must match current ramp size"); "X11: Gamma ramp size must match current ramp size");
return; return;
} }
else
{
XRRCrtcGamma* gamma = XRRAllocGamma(ramp->size); XRRCrtcGamma* gamma = XRRAllocGamma(ramp->size);
memcpy(gamma->red, ramp->red, ramp->size * sizeof(unsigned short)); memcpy(gamma->red, ramp->red, ramp->size * sizeof(unsigned short));
@ -469,6 +477,7 @@ void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
XRRSetCrtcGamma(_glfw.x11.display, monitor->x11.crtc, gamma); XRRSetCrtcGamma(_glfw.x11.display, monitor->x11.crtc, gamma);
XRRFreeGamma(gamma); XRRFreeGamma(gamma);
} }
}
else if (_glfw.x11.vidmode.available) else if (_glfw.x11.vidmode.available)
{ {
XF86VidModeSetGammaRamp(_glfw.x11.display, XF86VidModeSetGammaRamp(_glfw.x11.display,

View File

@ -426,6 +426,7 @@ static char** parseUriList(char* text, int* count)
(*count)++; (*count)++;
{
char* path = calloc(strlen(line) + 1, 1); char* path = calloc(strlen(line) + 1, 1);
paths = realloc(paths, *count * sizeof(char*)); paths = realloc(paths, *count * sizeof(char*));
paths[*count - 1] = path; paths[*count - 1] = path;
@ -445,6 +446,7 @@ static char** parseUriList(char* text, int* count)
line++; line++;
} }
} }
}
return paths; return paths;
} }
@ -1096,14 +1098,17 @@ static void processEvent(XEvent *event)
else else
{ {
KeySym keysym; KeySym keysym;
XLookupString(&event->xkey, NULL, 0, &keysym, NULL); XLookupString(&event->xkey, NULL, 0, &keysym, NULL);
_glfwInputKey(window, key, keycode, GLFW_PRESS, mods); _glfwInputKey(window, key, keycode, GLFW_PRESS, mods);
const long character = _glfwKeySym2Unicode(keysym); {
long character = _glfwKeySym2Unicode(keysym);
if (character != -1) if (character != -1)
_glfwInputChar(window, character, mods, plain); _glfwInputChar(window, character, mods, plain);
} }
}
return; return;
} }
@ -1249,18 +1254,21 @@ static void processEvent(XEvent *event)
if (window->cursorMode == GLFW_CURSOR_DISABLED) if (window->cursorMode == GLFW_CURSOR_DISABLED)
{ {
if (_glfw.x11.disabledCursorWindow != window) if (_glfw.x11.disabledCursorWindow != window)
return; return;
if (_glfw.x11.xi.available) if (_glfw.x11.xi.available)
return; return;
const int dx = x - window->x11.lastCursorPosX; {
const int dy = y - window->x11.lastCursorPosY; int dx = x - window->x11.lastCursorPosX;
int dy = y - window->x11.lastCursorPosY;
_glfwInputCursorPos(window, _glfwInputCursorPos(window,
window->virtualCursorPosX + dx, window->virtualCursorPosX + dx,
window->virtualCursorPosY + dy); window->virtualCursorPosY + dy);
} }
}
else else
_glfwInputCursorPos(window, x, y); _glfwInputCursorPos(window, x, y);
} }
@ -1438,6 +1446,7 @@ static void processEvent(XEvent *event)
_glfwInputCursorPos(window, xpos, ypos); _glfwInputCursorPos(window, xpos, ypos);
{
XEvent reply; XEvent reply;
memset(&reply, 0, sizeof(reply)); memset(&reply, 0, sizeof(reply));
@ -1461,6 +1470,7 @@ static void processEvent(XEvent *event)
False, NoEventMask, &reply); False, NoEventMask, &reply);
XFlush(_glfw.x11.display); XFlush(_glfw.x11.display);
} }
}
return; return;
} }
@ -1571,10 +1581,12 @@ static void processEvent(XEvent *event)
if (event->xproperty.atom == _glfw.x11.WM_STATE) if (event->xproperty.atom == _glfw.x11.WM_STATE)
{ {
const int state = getWindowState(window); const int state = getWindowState(window);
if (state != IconicState && state != NormalState) if (state != IconicState && state != NormalState)
return; return;
const GLFWbool iconified = (state == IconicState); {
GLFWbool iconified = (state == IconicState);
if (window->x11.iconified != iconified) if (window->x11.iconified != iconified)
{ {
if (window->monitor) if (window->monitor)
@ -1589,6 +1601,7 @@ static void processEvent(XEvent *event)
_glfwInputWindowIconify(window, iconified); _glfwInputWindowIconify(window, iconified);
} }
} }
}
else if (event->xproperty.atom == _glfw.x11.NET_WM_STATE) else if (event->xproperty.atom == _glfw.x11.NET_WM_STATE)
{ {
const GLFWbool maximized = _glfwPlatformWindowMaximized(window); const GLFWbool maximized = _glfwPlatformWindowMaximized(window);
@ -1842,6 +1855,7 @@ void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
longCount += 2 + images[i].width * images[i].height; longCount += 2 + images[i].width * images[i].height;
{
long* icon = calloc(longCount, sizeof(long)); long* icon = calloc(longCount, sizeof(long));
long* target = icon; long* target = icon;
@ -1868,6 +1882,7 @@ void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
free(icon); free(icon);
} }
}
else else
{ {
XDeleteProperty(_glfw.x11.display, window->x11.handle, XDeleteProperty(_glfw.x11.display, window->x11.handle,
@ -2333,6 +2348,8 @@ void _glfwPlatformPollEvents(void)
#if defined(__linux__) #if defined(__linux__)
_glfwDetectJoystickConnectionLinux(); _glfwDetectJoystickConnectionLinux();
#endif #endif
{
int count = XPending(_glfw.x11.display); int count = XPending(_glfw.x11.display);
while (count--) while (count--)
{ {
@ -2340,6 +2357,7 @@ void _glfwPlatformPollEvents(void)
XNextEvent(_glfw.x11.display, &event); XNextEvent(_glfw.x11.display, &event);
processEvent(&event); processEvent(&event);
} }
}
window = _glfw.x11.disabledCursorWindow; window = _glfw.x11.disabledCursorWindow;
if (window) if (window)
@ -2476,6 +2494,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
const char* _glfwPlatformGetKeyName(int key, int scancode) const char* _glfwPlatformGetKeyName(int key, int scancode)
{ {
if (!_glfw.x11.xkb.available) if (!_glfw.x11.xkb.available)
return NULL; return NULL;
@ -2485,19 +2504,28 @@ const char* _glfwPlatformGetKeyName(int key, int scancode)
if (!_glfwIsPrintable(_glfw.x11.keycodes[scancode])) if (!_glfwIsPrintable(_glfw.x11.keycodes[scancode]))
return NULL; return NULL;
const KeySym keysym = XkbKeycodeToKeysym(_glfw.x11.display, scancode, 0, 0); {
long ch;
{
KeySym keysym = XkbKeycodeToKeysym(_glfw.x11.display, scancode, 0, 0);
if (keysym == NoSymbol) if (keysym == NoSymbol)
return NULL; return NULL;
const long ch = _glfwKeySym2Unicode(keysym); ch = _glfwKeySym2Unicode(keysym);
if (ch == -1) if (ch == -1)
return NULL; return NULL;
}
const size_t count = encodeUTF8(_glfw.x11.keyName, (unsigned int) ch); {
size_t count = encodeUTF8(_glfw.x11.keyName, (unsigned int) ch);
if (count == 0) if (count == 0)
return NULL; return NULL;
_glfw.x11.keyName[count] = '\0'; _glfw.x11.keyName[count] = '\0';
}
}
return _glfw.x11.keyName; return _glfw.x11.keyName;
} }
@ -2664,6 +2692,7 @@ int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
if (_glfw.vk.KHR_xcb_surface && _glfw.x11.x11xcb.handle) if (_glfw.vk.KHR_xcb_surface && _glfw.x11.x11xcb.handle)
{ {
PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR vkGetPhysicalDeviceXcbPresentationSupportKHR = PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR vkGetPhysicalDeviceXcbPresentationSupportKHR =
(PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR) (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR"); vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR");
@ -2674,8 +2703,8 @@ int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
return GLFW_FALSE; return GLFW_FALSE;
} }
xcb_connection_t* connection = {
_glfw.x11.x11xcb.XGetXCBConnection(_glfw.x11.display); xcb_connection_t* connection = _glfw.x11.x11xcb.XGetXCBConnection(_glfw.x11.display);
if (!connection) if (!connection)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -2688,6 +2717,7 @@ int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
connection, connection,
visualID); visualID);
} }
}
else else
{ {
PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR vkGetPhysicalDeviceXlibPresentationSupportKHR = PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR vkGetPhysicalDeviceXlibPresentationSupportKHR =