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,33 +138,38 @@ 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);
bool enabled = mir_output_is_enabled(output);
// We must have been disconnected
if (!enabled || state != mir_output_connection_state_connected)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, MirOutputConnectionState state = mir_output_get_connection_state(output);
"Mir: Monitor no longer connected"); bool enabled = mir_output_is_enabled(output);
return NULL;
// We must have been disconnected
if (!enabled || state != mir_output_connection_state_connected)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Monitor no longer connected");
return NULL;
}
} }
int numModes = mir_output_get_num_modes(output);
modes = calloc(numModes, sizeof(GLFWvidmode));
for (*found = 0; *found < numModes; (*found)++)
{ {
const MirOutputMode* mode = mir_output_get_mode(output, *found); int numModes = mir_output_get_num_modes(output);
int width = mir_output_mode_get_width(mode); modes = calloc(numModes, sizeof(GLFWvidmode));
int height = mir_output_mode_get_height(mode);
double refreshRate = mir_output_mode_get_refresh_rate(mode);
MirPixelFormat currentFormat = mir_output_get_current_pixel_format(output);
modes[*found].width = width; for (*found = 0; *found < numModes; (*found)++)
modes[*found].height = height; {
modes[*found].refreshRate = refreshRate; const MirOutputMode* mode = mir_output_get_mode(output, *found);
int width = mir_output_mode_get_width(mode);
int height = mir_output_mode_get_height(mode);
double refreshRate = mir_output_mode_get_refresh_rate(mode);
MirPixelFormat currentFormat = mir_output_get_current_pixel_format(output);
FillInRGBBitsFromPixelFormat(&modes[*found], currentFormat); modes[*found].width = width;
modes[*found].height = height;
modes[*found].refreshRate = refreshRate;
FillInRGBBitsFromPixelFormat(&modes[*found], currentFormat);
}
} }
break; break;

View File

@ -205,13 +205,15 @@ static void handlePointerMotion(_GLFWwindow* window,
{ {
if (_glfw.mir.disabledCursorWindow != window) if (_glfw.mir.disabledCursorWindow != window)
return; return;
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;
const int dx = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_relative_x); _glfwInputCursorPos(window, dx + current_x, dy + current_y);
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;
_glfwInputCursorPos(window, dx + current_x, dy + current_y);
} }
else else
{ {
@ -701,20 +703,23 @@ 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;
mir_buffer_stream_get_graphics_region(stream, &region);
unsigned char* pixels = image->pixels;
char* dest = region.vaddr;
int i;
for (i = 0; i < i_w * i_h; i++, pixels += 4)
{ {
unsigned int alpha = pixels[3]; MirGraphicsRegion region;
*dest++ = (char)(pixels[2] * alpha / 255); unsigned char* pixels = image->pixels;
*dest++ = (char)(pixels[1] * alpha / 255); char* dest;
*dest++ = (char)(pixels[0] * alpha / 255); int i;
*dest++ = (char)alpha;
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];
*dest++ = (char)(pixels[2] * alpha / 255);
*dest++ = (char)(pixels[1] * alpha / 255);
*dest++ = (char)(pixels[0] * alpha / 255);
*dest++ = (char)alpha;
}
} }
mir_buffer_stream_swap_buffers_sync(stream); mir_buffer_stream_swap_buffers_sync(stream);

View File

@ -763,16 +763,20 @@ 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* target = data;
for (i = 0; i < image->width * image->height; i++, source += 4)
{
unsigned int alpha = source[3];
*target++ = (unsigned char) ((source[2] * alpha) / 255); {
*target++ = (unsigned char) ((source[1] * alpha) / 255); unsigned char* source = (unsigned char*) image->pixels;
*target++ = (unsigned char) ((source[0] * alpha) / 255); unsigned char* target = data;
*target++ = (unsigned char) alpha;
for (i = 0; i < image->width * image->height; i++, source += 4)
{
unsigned int alpha = source[3];
*target++ = (unsigned char) ((source[2] * alpha) / 255);
*target++ = (unsigned char) ((source[1] * alpha) / 255);
*target++ = (unsigned char) ((source[0] * alpha) / 255);
*target++ = (unsigned char) alpha;
}
} }
cursor->wl.buffer = cursor->wl.buffer =

View File

@ -416,45 +416,46 @@ 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;
unsigned long atomCount;
Atom* supportedAtoms; // Now we need to check the _NET_SUPPORTED property of the root window
unsigned long atomCount; // It should be a list of supported WM protocol and state atoms
atomCount = _glfwGetWindowPropertyX11(_glfw.x11.root,
wmSupported,
XA_ATOM,
(unsigned char**) &supportedAtoms);
// Now we need to check the _NET_SUPPORTED property of the root window // See which of the atoms we support that are supported by the WM
// It should be a list of supported WM protocol and state atoms _glfw.x11.NET_WM_STATE =
atomCount = _glfwGetWindowPropertyX11(_glfw.x11.root, getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE");
wmSupported, _glfw.x11.NET_WM_STATE_ABOVE =
XA_ATOM, getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_ABOVE");
(unsigned char**) &supportedAtoms); _glfw.x11.NET_WM_STATE_FULLSCREEN =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_FULLSCREEN");
_glfw.x11.NET_WM_STATE_MAXIMIZED_VERT =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_MAXIMIZED_VERT");
_glfw.x11.NET_WM_STATE_MAXIMIZED_HORZ =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_MAXIMIZED_HORZ");
_glfw.x11.NET_WM_STATE_DEMANDS_ATTENTION =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_DEMANDS_ATTENTION");
_glfw.x11.NET_WM_FULLSCREEN_MONITORS =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_FULLSCREEN_MONITORS");
_glfw.x11.NET_WM_WINDOW_TYPE =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_WINDOW_TYPE");
_glfw.x11.NET_WM_WINDOW_TYPE_NORMAL =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_WINDOW_TYPE_NORMAL");
_glfw.x11.NET_ACTIVE_WINDOW =
getSupportedAtom(supportedAtoms, atomCount, "_NET_ACTIVE_WINDOW");
_glfw.x11.NET_FRAME_EXTENTS =
getSupportedAtom(supportedAtoms, atomCount, "_NET_FRAME_EXTENTS");
_glfw.x11.NET_REQUEST_FRAME_EXTENTS =
getSupportedAtom(supportedAtoms, atomCount, "_NET_REQUEST_FRAME_EXTENTS");
// See which of the atoms we support that are supported by the WM if (supportedAtoms)
_glfw.x11.NET_WM_STATE = XFree(supportedAtoms);
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE"); }
_glfw.x11.NET_WM_STATE_ABOVE =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_ABOVE");
_glfw.x11.NET_WM_STATE_FULLSCREEN =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_FULLSCREEN");
_glfw.x11.NET_WM_STATE_MAXIMIZED_VERT =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_MAXIMIZED_VERT");
_glfw.x11.NET_WM_STATE_MAXIMIZED_HORZ =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_MAXIMIZED_HORZ");
_glfw.x11.NET_WM_STATE_DEMANDS_ATTENTION =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_DEMANDS_ATTENTION");
_glfw.x11.NET_WM_FULLSCREEN_MONITORS =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_FULLSCREEN_MONITORS");
_glfw.x11.NET_WM_WINDOW_TYPE =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_WINDOW_TYPE");
_glfw.x11.NET_WM_WINDOW_TYPE_NORMAL =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_WINDOW_TYPE_NORMAL");
_glfw.x11.NET_ACTIVE_WINDOW =
getSupportedAtom(supportedAtoms, atomCount, "_NET_ACTIVE_WINDOW");
_glfw.x11.NET_FRAME_EXTENTS =
getSupportedAtom(supportedAtoms, atomCount, "_NET_FRAME_EXTENTS");
_glfw.x11.NET_REQUEST_FRAME_EXTENTS =
getSupportedAtom(supportedAtoms, atomCount, "_NET_REQUEST_FRAME_EXTENTS");
if (supportedAtoms)
XFree(supportedAtoms);
} }
// Look for and initialize supported X11 extensions // Look for and initialize supported X11 extensions
@ -736,17 +737,19 @@ 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;
XcursorPixel* target = native->pixels;
for (i = 0; i < image->width * image->height; i++, target++, source += 4)
{ {
unsigned int alpha = source[3]; unsigned char* source = (unsigned char*) image->pixels;
XcursorPixel* target = native->pixels;
*target = (alpha << 24) | for (i = 0; i < image->width * image->height; i++, target++, source += 4)
((unsigned char) ((source[0] * alpha) / 255) << 16) | {
((unsigned char) ((source[1] * alpha) / 255) << 8) | unsigned int alpha = source[3];
((unsigned char) ((source[2] * alpha) / 255) << 0);
*target = (alpha << 24) |
((unsigned char) ((source[0] * alpha) / 255) << 16) |
((unsigned char) ((source[1] * alpha) / 255) << 8) |
((unsigned char) ((source[2] * alpha) / 255) << 0);
}
} }
cursor = XcursorImageLoadCursor(_glfw.x11.display, native); cursor = XcursorImageLoadCursor(_glfw.x11.display, native);

View File

@ -241,14 +241,17 @@ 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);
if (_glfwCompareVideoModes(best, &mode) == 0)
{ {
native = mi->id; GLFWvidmode mode = vidmodeFromModeInfo(mi, ci);
break; if (_glfwCompareVideoModes(best, &mode) == 0)
{
native = mi->id;
break;
}
} }
} }
@ -360,23 +363,26 @@ 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);
for (j = 0; j < *count; j++)
{ {
if (_glfwCompareVideoModes(result + j, &mode) == 0) GLFWvidmode mode = vidmodeFromModeInfo(mi, ci);
break;
for (j = 0; j < *count; j++)
{
if (_glfwCompareVideoModes(result + j, &mode) == 0)
break;
}
// Skip duplicate modes
if (j < *count)
continue;
(*count)++;
result[*count - 1] = mode;
} }
// Skip duplicate modes
if (j < *count)
continue;
(*count)++;
result[*count - 1] = mode;
} }
XRRFreeOutputInfo(oi); XRRFreeOutputInfo(oi);
@ -453,21 +459,24 @@ 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->green, ramp->green, ramp->size * sizeof(unsigned short));
memcpy(gamma->blue, ramp->blue, ramp->size * sizeof(unsigned short));
memcpy(gamma->red, ramp->red, ramp->size * sizeof(unsigned short)); XRRSetCrtcGamma(_glfw.x11.display, monitor->x11.crtc, gamma);
memcpy(gamma->green, ramp->green, ramp->size * sizeof(unsigned short)); XRRFreeGamma(gamma);
memcpy(gamma->blue, ramp->blue, ramp->size * sizeof(unsigned short)); }
XRRSetCrtcGamma(_glfw.x11.display, monitor->x11.crtc, gamma);
XRRFreeGamma(gamma);
} }
else if (_glfw.x11.vidmode.available) else if (_glfw.x11.vidmode.available)
{ {

View File

@ -426,23 +426,25 @@ static char** parseUriList(char* text, int* count)
(*count)++; (*count)++;
char* path = calloc(strlen(line) + 1, 1);
paths = realloc(paths, *count * sizeof(char*));
paths[*count - 1] = path;
while (*line)
{ {
if (line[0] == '%' && line[1] && line[2]) char* path = calloc(strlen(line) + 1, 1);
{ paths = realloc(paths, *count * sizeof(char*));
const char digits[3] = { line[1], line[2], '\0' }; paths[*count - 1] = path;
*path = strtol(digits, NULL, 16);
line += 2;
}
else
*path = *line;
path++; while (*line)
line++; {
if (line[0] == '%' && line[1] && line[2])
{
const char digits[3] = { line[1], line[2], '\0' };
*path = strtol(digits, NULL, 16);
line += 2;
}
else
*path = *line;
path++;
line++;
}
} }
} }
@ -1096,13 +1098,16 @@ 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); {
if (character != -1) long character = _glfwKeySym2Unicode(keysym);
_glfwInputChar(window, character, mods, plain); if (character != -1)
_glfwInputChar(window, character, mods, plain);
}
} }
return; return;
@ -1249,17 +1254,20 @@ 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,28 +1446,30 @@ static void processEvent(XEvent *event)
_glfwInputCursorPos(window, xpos, ypos); _glfwInputCursorPos(window, xpos, ypos);
XEvent reply;
memset(&reply, 0, sizeof(reply));
reply.type = ClientMessage;
reply.xclient.window = _glfw.x11.xdnd.source;
reply.xclient.message_type = _glfw.x11.XdndStatus;
reply.xclient.format = 32;
reply.xclient.data.l[0] = window->x11.handle;
reply.xclient.data.l[2] = 0; // Specify an empty rectangle
reply.xclient.data.l[3] = 0;
if (_glfw.x11.xdnd.format)
{ {
// Reply that we are ready to copy the dragged data XEvent reply;
reply.xclient.data.l[1] = 1; // Accept with no rectangle memset(&reply, 0, sizeof(reply));
if (_glfw.x11.xdnd.version >= 2)
reply.xclient.data.l[4] = _glfw.x11.XdndActionCopy;
}
XSendEvent(_glfw.x11.display, _glfw.x11.xdnd.source, reply.type = ClientMessage;
False, NoEventMask, &reply); reply.xclient.window = _glfw.x11.xdnd.source;
XFlush(_glfw.x11.display); reply.xclient.message_type = _glfw.x11.XdndStatus;
reply.xclient.format = 32;
reply.xclient.data.l[0] = window->x11.handle;
reply.xclient.data.l[2] = 0; // Specify an empty rectangle
reply.xclient.data.l[3] = 0;
if (_glfw.x11.xdnd.format)
{
// Reply that we are ready to copy the dragged data
reply.xclient.data.l[1] = 1; // Accept with no rectangle
if (_glfw.x11.xdnd.version >= 2)
reply.xclient.data.l[4] = _glfw.x11.XdndActionCopy;
}
XSendEvent(_glfw.x11.display, _glfw.x11.xdnd.source,
False, NoEventMask, &reply);
XFlush(_glfw.x11.display);
}
} }
return; return;
@ -1571,22 +1581,25 @@ 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);
if (window->x11.iconified != iconified)
{ {
if (window->monitor) GLFWbool iconified = (state == IconicState);
if (window->x11.iconified != iconified)
{ {
if (iconified) if (window->monitor)
releaseMonitor(window); {
else if (iconified)
acquireMonitor(window); releaseMonitor(window);
} else
acquireMonitor(window);
}
window->x11.iconified = iconified; window->x11.iconified = iconified;
_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)
@ -1842,31 +1855,33 @@ 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* target = icon;
for (i = 0; i < count; i++)
{ {
*target++ = images[i].width; long* icon = calloc(longCount, sizeof(long));
*target++ = images[i].height; long* target = icon;
for (j = 0; j < images[i].width * images[i].height; j++) for (i = 0; i < count; i++)
{ {
*target++ = (images[i].pixels[j * 4 + 0] << 16) | *target++ = images[i].width;
(images[i].pixels[j * 4 + 1] << 8) | *target++ = images[i].height;
(images[i].pixels[j * 4 + 2] << 0) |
(images[i].pixels[j * 4 + 3] << 24); for (j = 0; j < images[i].width * images[i].height; j++)
{
*target++ = (images[i].pixels[j * 4 + 0] << 16) |
(images[i].pixels[j * 4 + 1] << 8) |
(images[i].pixels[j * 4 + 2] << 0) |
(images[i].pixels[j * 4 + 3] << 24);
}
} }
XChangeProperty(_glfw.x11.display, window->x11.handle,
_glfw.x11.NET_WM_ICON,
XA_CARDINAL, 32,
PropModeReplace,
(unsigned char*) icon,
longCount);
free(icon);
} }
XChangeProperty(_glfw.x11.display, window->x11.handle,
_glfw.x11.NET_WM_ICON,
XA_CARDINAL, 32,
PropModeReplace,
(unsigned char*) icon,
longCount);
free(icon);
} }
else else
{ {
@ -2333,12 +2348,15 @@ void _glfwPlatformPollEvents(void)
#if defined(__linux__) #if defined(__linux__)
_glfwDetectJoystickConnectionLinux(); _glfwDetectJoystickConnectionLinux();
#endif #endif
int count = XPending(_glfw.x11.display);
while (count--)
{ {
XEvent event; int count = XPending(_glfw.x11.display);
XNextEvent(_glfw.x11.display, &event); while (count--)
processEvent(&event); {
XEvent event;
XNextEvent(_glfw.x11.display, &event);
processEvent(&event);
}
} }
window = _glfw.x11.disabledCursorWindow; window = _glfw.x11.disabledCursorWindow;
@ -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); {
if (keysym == NoSymbol) long ch;
return NULL;
const long ch = _glfwKeySym2Unicode(keysym); {
if (ch == -1) KeySym keysym = XkbKeycodeToKeysym(_glfw.x11.display, scancode, 0, 0);
return NULL; if (keysym == NoSymbol)
return NULL;
const size_t count = encodeUTF8(_glfw.x11.keyName, (unsigned int) ch); ch = _glfwKeySym2Unicode(keysym);
if (count == 0) if (ch == -1)
return NULL; return NULL;
}
{
size_t count = encodeUTF8(_glfw.x11.keyName, (unsigned int) ch);
if (count == 0)
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,19 +2703,20 @@ int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
return GLFW_FALSE; return GLFW_FALSE;
} }
xcb_connection_t* connection =
_glfw.x11.x11xcb.XGetXCBConnection(_glfw.x11.display);
if (!connection)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, xcb_connection_t* connection = _glfw.x11.x11xcb.XGetXCBConnection(_glfw.x11.display);
"X11: Failed to retrieve XCB connection"); if (!connection)
return GLFW_FALSE; {
} _glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Failed to retrieve XCB connection");
return GLFW_FALSE;
}
return vkGetPhysicalDeviceXcbPresentationSupportKHR(device, return vkGetPhysicalDeviceXcbPresentationSupportKHR(device,
queuefamily, queuefamily,
connection, connection,
visualID); visualID);
}
} }
else else
{ {