44static int translateKeySyms(
const KeySym* keysyms,
int width)
79 case XK_ISO_Level3_Shift:
210static void createKeyTables(
void)
212 int scancode, scancodeMin, scancodeMax;
214 memset(
_glfw.x11.keycodes, -1,
sizeof(
_glfw.x11.keycodes));
215 memset(
_glfw.x11.scancodes, -1,
sizeof(
_glfw.x11.scancodes));
225 scancodeMin = desc->min_key_code;
226 scancodeMax = desc->max_key_code;
358 for (scancode = scancodeMin; scancode <= scancodeMax; scancode++)
366 for (
int i = 0; i <
sizeof(keymap) /
sizeof(keymap[0]); i++)
368 if (strncmp(desc->names->keys[scancode].name,
370 XkbKeyNameLength) == 0)
378 for (
int i = 0; i < desc->names->num_key_aliases; i++)
383 if (strncmp(desc->names->key_aliases[i].real,
384 desc->names->keys[scancode].name,
385 XkbKeyNameLength) != 0)
390 for (
int j = 0; j <
sizeof(keymap) /
sizeof(keymap[0]); j++)
392 if (strncmp(desc->names->key_aliases[i].alias,
394 XkbKeyNameLength) == 0)
402 _glfw.x11.keycodes[scancode] = key;
414 scancodeMax - scancodeMin + 1,
417 for (scancode = scancodeMin; scancode <= scancodeMax; scancode++)
421 if (
_glfw.x11.keycodes[scancode] < 0)
423 const size_t base = (scancode - scancodeMin) * width;
424 _glfw.x11.keycodes[scancode] = translateKeySyms(&keysyms[base], width);
428 if (
_glfw.x11.keycodes[scancode] > 0)
429 _glfw.x11.scancodes[
_glfw.x11.keycodes[scancode]] = scancode;
437static GLFWbool hasUsableInputMethodStyle(
void)
440 XIMStyles* styles =
NULL;
445 for (
unsigned int i = 0; i < styles->count_styles; i++)
447 if (styles->supported_styles[i] == (XIMPreeditNothing | XIMStatusNothing))
458static void inputMethodDestroyCallback(XIM im, XPointer clientData, XPointer callData)
463static void inputMethodInstantiateCallback(Display* display,
473 if (!hasUsableInputMethodStyle())
482 XIMCallback callback;
483 callback.callback = (XIMProc) inputMethodDestroyCallback;
484 callback.client_data =
NULL;
494static Atom getAtomIfSupported(Atom* supportedAtoms,
495 unsigned long atomCount,
496 const char* atomName)
500 for (
unsigned long i = 0; i < atomCount; i++)
502 if (supportedAtoms[i] == atom)
511static void detectEWMH(
void)
515 Window* windowFromRoot =
NULL;
517 _glfw.x11.NET_SUPPORTING_WM_CHECK,
519 (
unsigned char**) &windowFromRoot))
529 Window* windowFromChild =
NULL;
531 _glfw.x11.NET_SUPPORTING_WM_CHECK,
533 (
unsigned char**) &windowFromChild))
535 XFree(windowFromRoot);
543 if (*windowFromRoot != *windowFromChild)
545 XFree(windowFromRoot);
546 XFree(windowFromChild);
550 XFree(windowFromRoot);
551 XFree(windowFromChild);
558 Atom* supportedAtoms =
NULL;
559 const unsigned long atomCount =
561 _glfw.x11.NET_SUPPORTED,
563 (
unsigned char**) &supportedAtoms);
567 _glfw.x11.NET_WM_STATE =
568 getAtomIfSupported(supportedAtoms, atomCount,
"_NET_WM_STATE");
569 _glfw.x11.NET_WM_STATE_ABOVE =
570 getAtomIfSupported(supportedAtoms, atomCount,
"_NET_WM_STATE_ABOVE");
571 _glfw.x11.NET_WM_STATE_FULLSCREEN =
572 getAtomIfSupported(supportedAtoms, atomCount,
"_NET_WM_STATE_FULLSCREEN");
573 _glfw.x11.NET_WM_STATE_MAXIMIZED_VERT =
574 getAtomIfSupported(supportedAtoms, atomCount,
"_NET_WM_STATE_MAXIMIZED_VERT");
575 _glfw.x11.NET_WM_STATE_MAXIMIZED_HORZ =
576 getAtomIfSupported(supportedAtoms, atomCount,
"_NET_WM_STATE_MAXIMIZED_HORZ");
577 _glfw.x11.NET_WM_STATE_DEMANDS_ATTENTION =
578 getAtomIfSupported(supportedAtoms, atomCount,
"_NET_WM_STATE_DEMANDS_ATTENTION");
579 _glfw.x11.NET_WM_FULLSCREEN_MONITORS =
580 getAtomIfSupported(supportedAtoms, atomCount,
"_NET_WM_FULLSCREEN_MONITORS");
581 _glfw.x11.NET_WM_WINDOW_TYPE =
582 getAtomIfSupported(supportedAtoms, atomCount,
"_NET_WM_WINDOW_TYPE");
583 _glfw.x11.NET_WM_WINDOW_TYPE_NORMAL =
584 getAtomIfSupported(supportedAtoms, atomCount,
"_NET_WM_WINDOW_TYPE_NORMAL");
585 _glfw.x11.NET_WORKAREA =
586 getAtomIfSupported(supportedAtoms, atomCount,
"_NET_WORKAREA");
587 _glfw.x11.NET_CURRENT_DESKTOP =
588 getAtomIfSupported(supportedAtoms, atomCount,
"_NET_CURRENT_DESKTOP");
589 _glfw.x11.NET_ACTIVE_WINDOW =
590 getAtomIfSupported(supportedAtoms, atomCount,
"_NET_ACTIVE_WINDOW");
591 _glfw.x11.NET_FRAME_EXTENTS =
592 getAtomIfSupported(supportedAtoms, atomCount,
"_NET_FRAME_EXTENTS");
593 _glfw.x11.NET_REQUEST_FRAME_EXTENTS =
594 getAtomIfSupported(supportedAtoms, atomCount,
"_NET_REQUEST_FRAME_EXTENTS");
597 XFree(supportedAtoms);
618 &
_glfw.x11.vidmode.eventBase,
619 &
_glfw.x11.vidmode.errorBase);
622#if defined(__CYGWIN__)
636 &
_glfw.x11.xi.majorOpcode,
637 &
_glfw.x11.xi.eventBase,
638 &
_glfw.x11.xi.errorBase))
640 _glfw.x11.xi.major = 2;
641 _glfw.x11.xi.minor = 0;
645 &
_glfw.x11.xi.minor) == Success)
652#if defined(__CYGWIN__)
697 &
_glfw.x11.randr.eventBase,
698 &
_glfw.x11.randr.errorBase))
701 &
_glfw.x11.randr.major,
702 &
_glfw.x11.randr.minor))
705 if (
_glfw.x11.randr.major > 1 ||
_glfw.x11.randr.minor >= 3)
711 "X11: Failed to query RandR version");
741 RROutputChangeNotifyMask);
744#if defined(__CYGWIN__)
765#if defined(__CYGWIN__)
780 &
_glfw.x11.xinerama.major,
781 &
_glfw.x11.xinerama.minor))
788 _glfw.x11.xkb.major = 1;
789 _glfw.x11.xkb.minor = 0;
792 &
_glfw.x11.xkb.majorOpcode,
793 &
_glfw.x11.xkb.eventBase,
794 &
_glfw.x11.xkb.errorBase,
795 &
_glfw.x11.xkb.major,
796 &
_glfw.x11.xkb.minor);
810 _glfw.x11.xkb.group = (
unsigned int)state.group;
813 XkbGroupStateMask, XkbGroupStateMask);
818#if defined(__CYGWIN__)
831#if defined(__CYGWIN__)
846 &
_glfw.x11.xrender.errorBase,
847 &
_glfw.x11.xrender.eventBase))
850 &
_glfw.x11.xrender.major,
851 &
_glfw.x11.xrender.minor))
858#if defined(__CYGWIN__)
875 &
_glfw.x11.xshape.errorBase,
876 &
_glfw.x11.xshape.eventBase))
879 &
_glfw.x11.xshape.major,
880 &
_glfw.x11.xshape.minor))
898 _glfw.x11.GLFW_SELECTION =
909 _glfw.x11.CLIPBOARD_MANAGER =
911 _glfw.x11.SAVE_TARGETS =
929 _glfw.x11.WM_PROTOCOLS =
933 _glfw.x11.WM_DELETE_WINDOW =
935 _glfw.x11.NET_SUPPORTED =
937 _glfw.x11.NET_SUPPORTING_WM_CHECK =
939 _glfw.x11.NET_WM_ICON =
941 _glfw.x11.NET_WM_PING =
943 _glfw.x11.NET_WM_PID =
945 _glfw.x11.NET_WM_NAME =
947 _glfw.x11.NET_WM_ICON_NAME =
949 _glfw.x11.NET_WM_BYPASS_COMPOSITOR =
951 _glfw.x11.NET_WM_WINDOW_OPACITY =
953 _glfw.x11.MOTIF_WM_HINTS =
959 snprintf(name,
sizeof(name),
"_NET_WM_CM_S%u",
_glfw.x11.screen);
971static void getSystemContentScale(
float* xscale,
float* yscale)
976 float xdpi = 96.f, ydpi = 96.f;
992 if (type && strcmp(type,
"String") == 0)
993 xdpi = ydpi = atof(value.addr);
1000 *xscale = xdpi / 96.f;
1001 *yscale = ydpi / 96.f;
1006static Cursor createHiddenCursor(
void)
1008 unsigned char pixels[16 * 16 * 4] = { 0 };
1015static Window createHelperWindow(
void)
1017 XSetWindowAttributes wa;
1018 wa.event_mask = PropertyChangeMask;
1023 DefaultVisual(
_glfw.x11.display,
_glfw.x11.screen),
1029static int errorHandler(Display *display, XErrorEvent* event)
1031 if (
_glfw.x11.display != display)
1034 _glfw.x11.errorCode =
event->error_code;
1047 _glfw.x11.errorCode = Success;
1066 buffer,
sizeof(buffer));
1085 native->xhot = xhot;
1086 native->yhot = yhot;
1088 unsigned char* source = (
unsigned char*) image->
pixels;
1089 XcursorPixel* target = native->pixels;
1091 for (i = 0; i < image->
width * image->
height; i++, target++, source += 4)
1093 unsigned int alpha = source[3];
1095 *target = (alpha << 24) |
1096 ((
unsigned char) ((source[0] * alpha) / 255) << 16) |
1097 ((
unsigned char) ((source[1] * alpha) / 255) << 8) |
1098 ((
unsigned char) ((source[2] * alpha) / 255) << 0);
1118 if (strcmp(setlocale(LC_CTYPE,
NULL),
"C") == 0)
1119 setlocale(LC_CTYPE,
"");
1121#if defined(__CYGWIN__)
1337 if (
_glfw.x11.xlib.utf8LookupString &&
_glfw.x11.xlib.utf8SetWMProperties)
1344 if (!
_glfw.x11.display)
1346 const char* display = getenv(
"DISPLAY");
1350 "X11: Failed to open display %s", display);
1355 "X11: The DISPLAY environment variable is missing");
1361 _glfw.x11.screen = DefaultScreen(
_glfw.x11.display);
1365 getSystemContentScale(&
_glfw.x11.contentScaleX, &
_glfw.x11.contentScaleY);
1367 if (!initExtensions())
1370 _glfw.x11.helperWindowHandle = createHelperWindow();
1371 _glfw.x11.hiddenCursorHandle = createHiddenCursor();
1380 inputMethodInstantiateCallback,
1392 if (
_glfw.x11.helperWindowHandle)
1395 _glfw.x11.helperWindowHandle)
1401 _glfw.x11.helperWindowHandle = None;
1404 if (
_glfw.x11.hiddenCursorHandle)
1407 _glfw.x11.hiddenCursorHandle = (Cursor) 0;
1410 free(
_glfw.x11.primarySelectionString);
1411 free(
_glfw.x11.clipboardString);
1415 inputMethodInstantiateCallback,
1424 if (
_glfw.x11.display)
1487#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
1492#if defined(__linux__)
1495#if defined(_GLFW_BUILD_DLL)
void _glfwTerminateEGL(void)
void _glfwTerminateGLX(void)
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
#define GLFW_KEY_NUM_LOCK
#define GLFW_KEY_KP_DECIMAL
#define GLFW_KEY_KP_ENTER
#define GLFW_KEY_APOSTROPHE
#define GLFW_KEY_RIGHT_ALT
#define GLFW_KEY_BACKSPACE
#define GLFW_KEY_GRAVE_ACCENT
#define GLFW_KEY_LEFT_ALT
#define GLFW_KEY_SEMICOLON
#define GLFW_KEY_RIGHT_BRACKET
#define GLFW_KEY_LEFT_SHIFT
#define GLFW_KEY_CAPS_LOCK
#define GLFW_KEY_KP_MULTIPLY
#define GLFW_KEY_LEFT_CONTROL
#define GLFW_KEY_KP_SUBTRACT
#define GLFW_KEY_BACKSLASH
#define GLFW_KEY_KP_DIVIDE
#define GLFW_KEY_LEFT_BRACKET
#define GLFW_KEY_RIGHT_CONTROL
#define GLFW_KEY_RIGHT_SUPER
#define GLFW_KEY_KP_EQUAL
#define GLFW_KEY_PAGE_DOWN
#define GLFW_KEY_SCROLL_LOCK
#define GLFW_KEY_PRINT_SCREEN
#define GLFW_KEY_LEFT_SUPER
#define GLFW_KEY_RIGHT_SHIFT
void _glfwInputError(int code, const char *format,...)
#define _GLFW_VERSION_NUMBER
#define _GLFW_MESSAGE_SIZE
void _glfwInitTimerPOSIX(void)
GLFWbool xcbVulkanSurface
struct _GLFWinitconfig::@17 x11
_GLFWwindow * windowListHead
struct _GLFWlibrary::@23 hints
struct _GLFWwindow * next
void _glfwInputErrorX11(int error, const char *message)
void _glfwReleaseErrorHandlerX11(void)
const char * _glfwPlatformGetVersionString(void)
void _glfwPlatformTerminate(void)
int _glfwPlatformInit(void)
void _glfwGrabErrorHandlerX11(void)
Cursor _glfwCreateCursorX11(const GLFWimage *image, int xhot, int yhot)
void _glfwPollMonitorsX11(void)