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

View File

@ -205,14 +205,16 @@ static void handlePointerMotion(_GLFWwindow* window,
{
if (_glfw.mir.disabledCursorWindow != window)
return;
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);
const int current_x = window->virtualCursorPosX;
const int current_y = window->virtualCursorPosY;
else
{
int dx = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_relative_x);
int dy = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_relative_y);
int current_x = window->virtualCursorPosX;
int current_y = window->virtualCursorPosY;
_glfwInputCursorPos(window, dx + current_x, dy + current_y);
}
}
else
{
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);
{
MirGraphicsRegion region;
mir_buffer_stream_get_graphics_region(stream, &region);
unsigned char* pixels = image->pixels;
char* dest = region.vaddr;
char* dest;
int i;
mir_buffer_stream_get_graphics_region(stream, &region);
dest = region.vaddr;
for (i = 0; i < i_w * i_h; i++, pixels += 4)
{
unsigned int alpha = pixels[3];
@ -716,6 +720,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
*dest++ = (char)(pixels[0] * alpha / 255);
*dest++ = (char)alpha;
}
}
mir_buffer_stream_swap_buffers_sync(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);
close(fd);
{
unsigned char* source = (unsigned char*) image->pixels;
unsigned char* target = data;
for (i = 0; i < image->width * image->height; i++, source += 4)
{
unsigned int alpha = source[3];
@ -774,6 +777,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
*target++ = (unsigned char) ((source[0] * alpha) / 255);
*target++ = (unsigned char) alpha;
}
}
cursor->wl.buffer =
wl_shm_pool_create_buffer(pool, 0,

View File

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

View File

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

View File

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