2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
2016-08-18 23:42:15 +02:00
|
|
|
// GLFW 3.3 X11 - www.glfw.org
|
2010-09-07 17:34:51 +02:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2002-2006 Marcus Geelnard
|
2016-11-21 16:23:59 +01:00
|
|
|
// Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org>
|
2010-09-07 17:34:51 +02:00
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2013-04-17 17:31:29 +02:00
|
|
|
#include <X11/Xresource.h>
|
|
|
|
|
2010-10-13 04:04:43 +02:00
|
|
|
#include <stdlib.h>
|
2011-09-22 14:10:03 +02:00
|
|
|
#include <string.h>
|
2012-04-05 17:29:08 +02:00
|
|
|
#include <limits.h>
|
2013-07-10 11:42:14 +02:00
|
|
|
#include <stdio.h>
|
2014-12-18 02:52:06 +01:00
|
|
|
#include <locale.h>
|
2010-09-08 17:01:39 +02:00
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2011-01-04 23:07:34 +01:00
|
|
|
// Translate an X11 key code to a GLFW key code.
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2015-08-16 15:35:12 +02:00
|
|
|
static int translateKeyCode(int scancode)
|
2011-01-04 23:07:34 +01:00
|
|
|
{
|
|
|
|
int keySym;
|
|
|
|
|
2015-01-05 21:55:15 +01:00
|
|
|
// Valid key code range is [8,255], according to the Xlib manual
|
2014-03-30 16:23:22 +02:00
|
|
|
if (scancode < 8 || scancode > 255)
|
2013-05-30 17:19:12 +02:00
|
|
|
return GLFW_KEY_UNKNOWN;
|
2011-01-04 23:07:34 +01:00
|
|
|
|
2014-05-18 12:24:29 +02:00
|
|
|
if (_glfw.x11.xkb.available)
|
2011-01-04 23:07:34 +01:00
|
|
|
{
|
2014-04-24 07:10:58 +02:00
|
|
|
// Try secondary keysym, for numeric keypad keys
|
|
|
|
// Note: This way we always force "NumLock = ON", which is intentional
|
|
|
|
// since the returned key code should correspond to a physical
|
|
|
|
// location.
|
2014-03-30 16:23:22 +02:00
|
|
|
keySym = XkbKeycodeToKeysym(_glfw.x11.display, scancode, 0, 1);
|
2014-04-24 07:10:58 +02:00
|
|
|
switch (keySym)
|
|
|
|
{
|
|
|
|
case XK_KP_0: return GLFW_KEY_KP_0;
|
|
|
|
case XK_KP_1: return GLFW_KEY_KP_1;
|
|
|
|
case XK_KP_2: return GLFW_KEY_KP_2;
|
|
|
|
case XK_KP_3: return GLFW_KEY_KP_3;
|
|
|
|
case XK_KP_4: return GLFW_KEY_KP_4;
|
|
|
|
case XK_KP_5: return GLFW_KEY_KP_5;
|
|
|
|
case XK_KP_6: return GLFW_KEY_KP_6;
|
|
|
|
case XK_KP_7: return GLFW_KEY_KP_7;
|
|
|
|
case XK_KP_8: return GLFW_KEY_KP_8;
|
|
|
|
case XK_KP_9: return GLFW_KEY_KP_9;
|
|
|
|
case XK_KP_Separator:
|
|
|
|
case XK_KP_Decimal: return GLFW_KEY_KP_DECIMAL;
|
|
|
|
case XK_KP_Equal: return GLFW_KEY_KP_EQUAL;
|
|
|
|
case XK_KP_Enter: return GLFW_KEY_KP_ENTER;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2016-07-17 15:38:40 +02:00
|
|
|
// Now try primary keysym for function keys (non-printable keys)
|
|
|
|
// These should not depend on the current keyboard layout
|
2014-03-30 16:23:22 +02:00
|
|
|
keySym = XkbKeycodeToKeysym(_glfw.x11.display, scancode, 0, 0);
|
2014-04-24 07:10:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-18 12:24:29 +02:00
|
|
|
int dummy;
|
|
|
|
KeySym* keySyms;
|
|
|
|
|
2014-03-30 16:23:22 +02:00
|
|
|
keySyms = XGetKeyboardMapping(_glfw.x11.display, scancode, 1, &dummy);
|
2014-05-18 12:24:29 +02:00
|
|
|
keySym = keySyms[0];
|
|
|
|
XFree(keySyms);
|
2011-01-04 23:07:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (keySym)
|
|
|
|
{
|
|
|
|
case XK_Escape: return GLFW_KEY_ESCAPE;
|
|
|
|
case XK_Tab: return GLFW_KEY_TAB;
|
|
|
|
case XK_Shift_L: return GLFW_KEY_LEFT_SHIFT;
|
|
|
|
case XK_Shift_R: return GLFW_KEY_RIGHT_SHIFT;
|
|
|
|
case XK_Control_L: return GLFW_KEY_LEFT_CONTROL;
|
|
|
|
case XK_Control_R: return GLFW_KEY_RIGHT_CONTROL;
|
|
|
|
case XK_Meta_L:
|
|
|
|
case XK_Alt_L: return GLFW_KEY_LEFT_ALT;
|
|
|
|
case XK_Mode_switch: // Mapped to Alt_R on many keyboards
|
|
|
|
case XK_ISO_Level3_Shift: // AltGr on at least some machines
|
|
|
|
case XK_Meta_R:
|
|
|
|
case XK_Alt_R: return GLFW_KEY_RIGHT_ALT;
|
|
|
|
case XK_Super_L: return GLFW_KEY_LEFT_SUPER;
|
|
|
|
case XK_Super_R: return GLFW_KEY_RIGHT_SUPER;
|
|
|
|
case XK_Menu: return GLFW_KEY_MENU;
|
|
|
|
case XK_Num_Lock: return GLFW_KEY_NUM_LOCK;
|
|
|
|
case XK_Caps_Lock: return GLFW_KEY_CAPS_LOCK;
|
2013-02-21 18:39:22 +01:00
|
|
|
case XK_Print: return GLFW_KEY_PRINT_SCREEN;
|
2011-01-04 23:07:34 +01:00
|
|
|
case XK_Scroll_Lock: return GLFW_KEY_SCROLL_LOCK;
|
|
|
|
case XK_Pause: return GLFW_KEY_PAUSE;
|
|
|
|
case XK_Delete: return GLFW_KEY_DELETE;
|
|
|
|
case XK_BackSpace: return GLFW_KEY_BACKSPACE;
|
|
|
|
case XK_Return: return GLFW_KEY_ENTER;
|
|
|
|
case XK_Home: return GLFW_KEY_HOME;
|
|
|
|
case XK_End: return GLFW_KEY_END;
|
|
|
|
case XK_Page_Up: return GLFW_KEY_PAGE_UP;
|
|
|
|
case XK_Page_Down: return GLFW_KEY_PAGE_DOWN;
|
|
|
|
case XK_Insert: return GLFW_KEY_INSERT;
|
|
|
|
case XK_Left: return GLFW_KEY_LEFT;
|
|
|
|
case XK_Right: return GLFW_KEY_RIGHT;
|
|
|
|
case XK_Down: return GLFW_KEY_DOWN;
|
|
|
|
case XK_Up: return GLFW_KEY_UP;
|
|
|
|
case XK_F1: return GLFW_KEY_F1;
|
|
|
|
case XK_F2: return GLFW_KEY_F2;
|
|
|
|
case XK_F3: return GLFW_KEY_F3;
|
|
|
|
case XK_F4: return GLFW_KEY_F4;
|
|
|
|
case XK_F5: return GLFW_KEY_F5;
|
|
|
|
case XK_F6: return GLFW_KEY_F6;
|
|
|
|
case XK_F7: return GLFW_KEY_F7;
|
|
|
|
case XK_F8: return GLFW_KEY_F8;
|
|
|
|
case XK_F9: return GLFW_KEY_F9;
|
|
|
|
case XK_F10: return GLFW_KEY_F10;
|
|
|
|
case XK_F11: return GLFW_KEY_F11;
|
|
|
|
case XK_F12: return GLFW_KEY_F12;
|
|
|
|
case XK_F13: return GLFW_KEY_F13;
|
|
|
|
case XK_F14: return GLFW_KEY_F14;
|
|
|
|
case XK_F15: return GLFW_KEY_F15;
|
|
|
|
case XK_F16: return GLFW_KEY_F16;
|
|
|
|
case XK_F17: return GLFW_KEY_F17;
|
|
|
|
case XK_F18: return GLFW_KEY_F18;
|
|
|
|
case XK_F19: return GLFW_KEY_F19;
|
|
|
|
case XK_F20: return GLFW_KEY_F20;
|
|
|
|
case XK_F21: return GLFW_KEY_F21;
|
|
|
|
case XK_F22: return GLFW_KEY_F22;
|
|
|
|
case XK_F23: return GLFW_KEY_F23;
|
|
|
|
case XK_F24: return GLFW_KEY_F24;
|
|
|
|
case XK_F25: return GLFW_KEY_F25;
|
|
|
|
|
|
|
|
// Numeric keypad
|
|
|
|
case XK_KP_Divide: return GLFW_KEY_KP_DIVIDE;
|
|
|
|
case XK_KP_Multiply: return GLFW_KEY_KP_MULTIPLY;
|
|
|
|
case XK_KP_Subtract: return GLFW_KEY_KP_SUBTRACT;
|
|
|
|
case XK_KP_Add: return GLFW_KEY_KP_ADD;
|
|
|
|
|
|
|
|
// These should have been detected in secondary keysym test above!
|
|
|
|
case XK_KP_Insert: return GLFW_KEY_KP_0;
|
|
|
|
case XK_KP_End: return GLFW_KEY_KP_1;
|
|
|
|
case XK_KP_Down: return GLFW_KEY_KP_2;
|
|
|
|
case XK_KP_Page_Down: return GLFW_KEY_KP_3;
|
|
|
|
case XK_KP_Left: return GLFW_KEY_KP_4;
|
|
|
|
case XK_KP_Right: return GLFW_KEY_KP_6;
|
|
|
|
case XK_KP_Home: return GLFW_KEY_KP_7;
|
|
|
|
case XK_KP_Up: return GLFW_KEY_KP_8;
|
|
|
|
case XK_KP_Page_Up: return GLFW_KEY_KP_9;
|
|
|
|
case XK_KP_Delete: return GLFW_KEY_KP_DECIMAL;
|
|
|
|
case XK_KP_Equal: return GLFW_KEY_KP_EQUAL;
|
|
|
|
case XK_KP_Enter: return GLFW_KEY_KP_ENTER;
|
|
|
|
|
|
|
|
// Last resort: Check for printable keys (should not happen if the XKB
|
|
|
|
// extension is available). This will give a layout dependent mapping
|
|
|
|
// (which is wrong, and we may miss some keys, especially on non-US
|
|
|
|
// keyboards), but it's better than nothing...
|
|
|
|
case XK_a: return GLFW_KEY_A;
|
|
|
|
case XK_b: return GLFW_KEY_B;
|
|
|
|
case XK_c: return GLFW_KEY_C;
|
|
|
|
case XK_d: return GLFW_KEY_D;
|
|
|
|
case XK_e: return GLFW_KEY_E;
|
|
|
|
case XK_f: return GLFW_KEY_F;
|
|
|
|
case XK_g: return GLFW_KEY_G;
|
|
|
|
case XK_h: return GLFW_KEY_H;
|
|
|
|
case XK_i: return GLFW_KEY_I;
|
|
|
|
case XK_j: return GLFW_KEY_J;
|
|
|
|
case XK_k: return GLFW_KEY_K;
|
|
|
|
case XK_l: return GLFW_KEY_L;
|
|
|
|
case XK_m: return GLFW_KEY_M;
|
|
|
|
case XK_n: return GLFW_KEY_N;
|
|
|
|
case XK_o: return GLFW_KEY_O;
|
|
|
|
case XK_p: return GLFW_KEY_P;
|
|
|
|
case XK_q: return GLFW_KEY_Q;
|
|
|
|
case XK_r: return GLFW_KEY_R;
|
|
|
|
case XK_s: return GLFW_KEY_S;
|
|
|
|
case XK_t: return GLFW_KEY_T;
|
|
|
|
case XK_u: return GLFW_KEY_U;
|
|
|
|
case XK_v: return GLFW_KEY_V;
|
|
|
|
case XK_w: return GLFW_KEY_W;
|
|
|
|
case XK_x: return GLFW_KEY_X;
|
|
|
|
case XK_y: return GLFW_KEY_Y;
|
|
|
|
case XK_z: return GLFW_KEY_Z;
|
|
|
|
case XK_1: return GLFW_KEY_1;
|
|
|
|
case XK_2: return GLFW_KEY_2;
|
|
|
|
case XK_3: return GLFW_KEY_3;
|
|
|
|
case XK_4: return GLFW_KEY_4;
|
|
|
|
case XK_5: return GLFW_KEY_5;
|
|
|
|
case XK_6: return GLFW_KEY_6;
|
|
|
|
case XK_7: return GLFW_KEY_7;
|
|
|
|
case XK_8: return GLFW_KEY_8;
|
|
|
|
case XK_9: return GLFW_KEY_9;
|
|
|
|
case XK_0: return GLFW_KEY_0;
|
|
|
|
case XK_space: return GLFW_KEY_SPACE;
|
|
|
|
case XK_minus: return GLFW_KEY_MINUS;
|
|
|
|
case XK_equal: return GLFW_KEY_EQUAL;
|
|
|
|
case XK_bracketleft: return GLFW_KEY_LEFT_BRACKET;
|
|
|
|
case XK_bracketright: return GLFW_KEY_RIGHT_BRACKET;
|
|
|
|
case XK_backslash: return GLFW_KEY_BACKSLASH;
|
|
|
|
case XK_semicolon: return GLFW_KEY_SEMICOLON;
|
|
|
|
case XK_apostrophe: return GLFW_KEY_APOSTROPHE;
|
|
|
|
case XK_grave: return GLFW_KEY_GRAVE_ACCENT;
|
|
|
|
case XK_comma: return GLFW_KEY_COMMA;
|
|
|
|
case XK_period: return GLFW_KEY_PERIOD;
|
|
|
|
case XK_slash: return GLFW_KEY_SLASH;
|
|
|
|
case XK_less: return GLFW_KEY_WORLD_1; // At least in some layouts...
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2013-05-30 17:19:12 +02:00
|
|
|
// No matching translation was found
|
|
|
|
return GLFW_KEY_UNKNOWN;
|
2011-01-04 23:07:34 +01:00
|
|
|
}
|
|
|
|
|
2014-03-30 16:23:22 +02:00
|
|
|
// Create key code translation tables
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2014-03-30 16:23:22 +02:00
|
|
|
static void createKeyTables(void)
|
2011-01-02 11:18:14 +01:00
|
|
|
{
|
2014-03-30 16:23:22 +02:00
|
|
|
int scancode, key;
|
2011-01-02 11:18:14 +01:00
|
|
|
|
2016-09-07 15:43:39 +02:00
|
|
|
memset(_glfw.x11.keycodes, -1, sizeof(_glfw.x11.keycodes));
|
|
|
|
memset(_glfw.x11.scancodes, -1, sizeof(_glfw.x11.scancodes));
|
2011-01-02 11:18:14 +01:00
|
|
|
|
2014-05-18 12:24:29 +02:00
|
|
|
if (_glfw.x11.xkb.available)
|
2014-04-24 07:10:58 +02:00
|
|
|
{
|
|
|
|
// Use XKB to determine physical key locations independently of the current
|
|
|
|
// keyboard layout
|
2011-01-02 11:18:14 +01:00
|
|
|
|
2014-03-30 16:23:22 +02:00
|
|
|
char name[XkbKeyNameLength + 1];
|
2015-08-14 17:54:24 +02:00
|
|
|
XkbDescPtr desc = XkbGetMap(_glfw.x11.display, 0, XkbUseCoreKbd);
|
|
|
|
XkbGetNames(_glfw.x11.display, XkbKeyNamesMask, desc);
|
2011-01-04 23:07:34 +01:00
|
|
|
|
2014-04-24 07:10:58 +02:00
|
|
|
// Find the X11 key code -> GLFW key code mapping
|
2015-08-14 17:54:24 +02:00
|
|
|
for (scancode = desc->min_key_code; scancode <= desc->max_key_code; scancode++)
|
2014-04-24 07:10:58 +02:00
|
|
|
{
|
2015-08-14 17:54:24 +02:00
|
|
|
memcpy(name, desc->names->keys[scancode].name, XkbKeyNameLength);
|
|
|
|
name[XkbKeyNameLength] = '\0';
|
2014-04-24 07:10:58 +02:00
|
|
|
|
|
|
|
// Map the key name to a GLFW key code. Note: We only map printable
|
|
|
|
// keys here, and we use the US keyboard layout. The rest of the
|
|
|
|
// keys (function keys) are mapped using traditional KeySym
|
|
|
|
// translations.
|
2014-03-30 16:23:22 +02:00
|
|
|
if (strcmp(name, "TLDE") == 0) key = GLFW_KEY_GRAVE_ACCENT;
|
|
|
|
else if (strcmp(name, "AE01") == 0) key = GLFW_KEY_1;
|
|
|
|
else if (strcmp(name, "AE02") == 0) key = GLFW_KEY_2;
|
|
|
|
else if (strcmp(name, "AE03") == 0) key = GLFW_KEY_3;
|
|
|
|
else if (strcmp(name, "AE04") == 0) key = GLFW_KEY_4;
|
|
|
|
else if (strcmp(name, "AE05") == 0) key = GLFW_KEY_5;
|
|
|
|
else if (strcmp(name, "AE06") == 0) key = GLFW_KEY_6;
|
|
|
|
else if (strcmp(name, "AE07") == 0) key = GLFW_KEY_7;
|
|
|
|
else if (strcmp(name, "AE08") == 0) key = GLFW_KEY_8;
|
|
|
|
else if (strcmp(name, "AE09") == 0) key = GLFW_KEY_9;
|
|
|
|
else if (strcmp(name, "AE10") == 0) key = GLFW_KEY_0;
|
|
|
|
else if (strcmp(name, "AE11") == 0) key = GLFW_KEY_MINUS;
|
|
|
|
else if (strcmp(name, "AE12") == 0) key = GLFW_KEY_EQUAL;
|
|
|
|
else if (strcmp(name, "AD01") == 0) key = GLFW_KEY_Q;
|
|
|
|
else if (strcmp(name, "AD02") == 0) key = GLFW_KEY_W;
|
|
|
|
else if (strcmp(name, "AD03") == 0) key = GLFW_KEY_E;
|
|
|
|
else if (strcmp(name, "AD04") == 0) key = GLFW_KEY_R;
|
|
|
|
else if (strcmp(name, "AD05") == 0) key = GLFW_KEY_T;
|
|
|
|
else if (strcmp(name, "AD06") == 0) key = GLFW_KEY_Y;
|
|
|
|
else if (strcmp(name, "AD07") == 0) key = GLFW_KEY_U;
|
|
|
|
else if (strcmp(name, "AD08") == 0) key = GLFW_KEY_I;
|
|
|
|
else if (strcmp(name, "AD09") == 0) key = GLFW_KEY_O;
|
|
|
|
else if (strcmp(name, "AD10") == 0) key = GLFW_KEY_P;
|
|
|
|
else if (strcmp(name, "AD11") == 0) key = GLFW_KEY_LEFT_BRACKET;
|
|
|
|
else if (strcmp(name, "AD12") == 0) key = GLFW_KEY_RIGHT_BRACKET;
|
|
|
|
else if (strcmp(name, "AC01") == 0) key = GLFW_KEY_A;
|
|
|
|
else if (strcmp(name, "AC02") == 0) key = GLFW_KEY_S;
|
|
|
|
else if (strcmp(name, "AC03") == 0) key = GLFW_KEY_D;
|
|
|
|
else if (strcmp(name, "AC04") == 0) key = GLFW_KEY_F;
|
|
|
|
else if (strcmp(name, "AC05") == 0) key = GLFW_KEY_G;
|
|
|
|
else if (strcmp(name, "AC06") == 0) key = GLFW_KEY_H;
|
|
|
|
else if (strcmp(name, "AC07") == 0) key = GLFW_KEY_J;
|
|
|
|
else if (strcmp(name, "AC08") == 0) key = GLFW_KEY_K;
|
|
|
|
else if (strcmp(name, "AC09") == 0) key = GLFW_KEY_L;
|
|
|
|
else if (strcmp(name, "AC10") == 0) key = GLFW_KEY_SEMICOLON;
|
|
|
|
else if (strcmp(name, "AC11") == 0) key = GLFW_KEY_APOSTROPHE;
|
|
|
|
else if (strcmp(name, "AB01") == 0) key = GLFW_KEY_Z;
|
|
|
|
else if (strcmp(name, "AB02") == 0) key = GLFW_KEY_X;
|
|
|
|
else if (strcmp(name, "AB03") == 0) key = GLFW_KEY_C;
|
|
|
|
else if (strcmp(name, "AB04") == 0) key = GLFW_KEY_V;
|
|
|
|
else if (strcmp(name, "AB05") == 0) key = GLFW_KEY_B;
|
|
|
|
else if (strcmp(name, "AB06") == 0) key = GLFW_KEY_N;
|
|
|
|
else if (strcmp(name, "AB07") == 0) key = GLFW_KEY_M;
|
|
|
|
else if (strcmp(name, "AB08") == 0) key = GLFW_KEY_COMMA;
|
|
|
|
else if (strcmp(name, "AB09") == 0) key = GLFW_KEY_PERIOD;
|
|
|
|
else if (strcmp(name, "AB10") == 0) key = GLFW_KEY_SLASH;
|
|
|
|
else if (strcmp(name, "BKSL") == 0) key = GLFW_KEY_BACKSLASH;
|
|
|
|
else if (strcmp(name, "LSGT") == 0) key = GLFW_KEY_WORLD_1;
|
|
|
|
else key = GLFW_KEY_UNKNOWN;
|
|
|
|
|
|
|
|
if ((scancode >= 0) && (scancode < 256))
|
2016-09-07 15:43:39 +02:00
|
|
|
_glfw.x11.keycodes[scancode] = key;
|
2014-04-24 07:10:58 +02:00
|
|
|
}
|
2013-01-07 18:08:07 +01:00
|
|
|
|
2015-08-14 17:54:24 +02:00
|
|
|
XkbFreeNames(desc, XkbKeyNamesMask, True);
|
2015-12-17 12:38:53 +01:00
|
|
|
XkbFreeKeyboard(desc, 0, True);
|
2014-04-24 07:10:58 +02:00
|
|
|
}
|
2011-01-04 23:07:34 +01:00
|
|
|
|
2014-03-30 16:23:22 +02:00
|
|
|
for (scancode = 0; scancode < 256; scancode++)
|
2011-01-04 23:07:34 +01:00
|
|
|
{
|
2015-07-02 14:24:50 +02:00
|
|
|
// Translate the un-translated key codes using traditional X11 KeySym
|
|
|
|
// lookups
|
2016-09-07 15:43:39 +02:00
|
|
|
if (_glfw.x11.keycodes[scancode] < 0)
|
|
|
|
_glfw.x11.keycodes[scancode] = translateKeyCode(scancode);
|
2015-07-02 14:24:50 +02:00
|
|
|
|
|
|
|
// Store the reverse translation for faster key name lookup
|
2016-09-07 15:43:39 +02:00
|
|
|
if (_glfw.x11.keycodes[scancode] > 0)
|
|
|
|
_glfw.x11.scancodes[_glfw.x11.keycodes[scancode]] = scancode;
|
2011-01-02 11:18:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-21 02:13:41 +02:00
|
|
|
// Check whether the IM has a usable style
|
|
|
|
//
|
2015-08-23 19:30:04 +02:00
|
|
|
static GLFWbool hasUsableInputMethodStyle(void)
|
2014-09-21 02:13:41 +02:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2015-08-23 19:30:04 +02:00
|
|
|
GLFWbool found = GLFW_FALSE;
|
2014-09-21 02:13:41 +02:00
|
|
|
XIMStyles* styles = NULL;
|
|
|
|
|
|
|
|
if (XGetIMValues(_glfw.x11.im, XNQueryInputStyle, &styles, NULL) != NULL)
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2014-09-21 02:13:41 +02:00
|
|
|
|
|
|
|
for (i = 0; i < styles->count_styles; i++)
|
|
|
|
{
|
|
|
|
if (styles->supported_styles[i] == (XIMPreeditNothing | XIMStatusNothing))
|
|
|
|
{
|
2015-08-23 19:30:04 +02:00
|
|
|
found = GLFW_TRUE;
|
2014-09-21 02:13:41 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(styles);
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2012-04-05 17:29:08 +02:00
|
|
|
// Check whether the specified atom is supported
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2012-04-05 17:29:08 +02:00
|
|
|
static Atom getSupportedAtom(Atom* supportedAtoms,
|
|
|
|
unsigned long atomCount,
|
|
|
|
const char* atomName)
|
|
|
|
{
|
2016-05-01 22:54:02 +02:00
|
|
|
unsigned long i;
|
|
|
|
const Atom atom = XInternAtom(_glfw.x11.display, atomName, False);
|
2012-04-05 17:29:08 +02:00
|
|
|
|
2016-05-01 22:54:02 +02:00
|
|
|
for (i = 0; i < atomCount; i++)
|
|
|
|
{
|
|
|
|
if (supportedAtoms[i] == atom)
|
|
|
|
return atom;
|
2012-04-05 17:29:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the running window manager is EWMH-compliant
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2013-01-04 07:11:30 +01:00
|
|
|
static void detectEWMH(void)
|
2012-04-05 17:29:08 +02:00
|
|
|
{
|
|
|
|
Window* windowFromRoot = NULL;
|
|
|
|
Window* windowFromChild = NULL;
|
|
|
|
|
2016-05-01 22:54:02 +02:00
|
|
|
// First we need a couple of atoms
|
|
|
|
const Atom supportingWmCheck =
|
|
|
|
XInternAtom(_glfw.x11.display, "_NET_SUPPORTING_WM_CHECK", False);
|
|
|
|
const Atom wmSupported =
|
|
|
|
XInternAtom(_glfw.x11.display, "_NET_SUPPORTED", False);
|
2012-04-05 17:29:08 +02:00
|
|
|
|
|
|
|
// Then we look for the _NET_SUPPORTING_WM_CHECK property of the root window
|
2017-01-16 01:36:14 +01:00
|
|
|
if (!_glfwGetWindowPropertyX11(_glfw.x11.root,
|
|
|
|
supportingWmCheck,
|
|
|
|
XA_WINDOW,
|
|
|
|
(unsigned char**) &windowFromRoot))
|
2012-04-05 17:29:08 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-03 18:16:46 +01:00
|
|
|
_glfwGrabErrorHandlerX11();
|
2014-02-11 15:46:54 +01:00
|
|
|
|
2012-04-05 17:29:08 +02:00
|
|
|
// It should be the ID of a child window (of the root)
|
|
|
|
// Then we look for the same property on the child window
|
2017-01-16 01:36:14 +01:00
|
|
|
if (!_glfwGetWindowPropertyX11(*windowFromRoot,
|
|
|
|
supportingWmCheck,
|
|
|
|
XA_WINDOW,
|
|
|
|
(unsigned char**) &windowFromChild))
|
2012-04-05 17:29:08 +02:00
|
|
|
{
|
|
|
|
XFree(windowFromRoot);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-03 18:16:46 +01:00
|
|
|
_glfwReleaseErrorHandlerX11();
|
2014-02-11 15:46:54 +01:00
|
|
|
|
2012-04-05 17:29:08 +02:00
|
|
|
// It should be the ID of that same child window
|
|
|
|
if (*windowFromRoot != *windowFromChild)
|
|
|
|
{
|
|
|
|
XFree(windowFromRoot);
|
|
|
|
XFree(windowFromChild);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(windowFromRoot);
|
|
|
|
XFree(windowFromChild);
|
|
|
|
|
|
|
|
// We are now fairly sure that an EWMH-compliant window manager is running
|
|
|
|
|
|
|
|
Atom* supportedAtoms;
|
|
|
|
unsigned long atomCount;
|
|
|
|
|
|
|
|
// Now we need to check the _NET_SUPPORTED property of the root window
|
|
|
|
// It should be a list of supported WM protocol and state atoms
|
2015-12-03 18:16:46 +01:00
|
|
|
atomCount = _glfwGetWindowPropertyX11(_glfw.x11.root,
|
|
|
|
wmSupported,
|
|
|
|
XA_ATOM,
|
|
|
|
(unsigned char**) &supportedAtoms);
|
2012-04-05 17:29:08 +02:00
|
|
|
|
|
|
|
// See which of the atoms we support that are supported by the WM
|
2013-01-21 18:03:47 +01:00
|
|
|
_glfw.x11.NET_WM_STATE =
|
2012-04-05 17:29:08 +02:00
|
|
|
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE");
|
2014-05-23 14:01:02 +02:00
|
|
|
_glfw.x11.NET_WM_STATE_ABOVE =
|
|
|
|
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_ABOVE");
|
2013-01-21 18:03:47 +01:00
|
|
|
_glfw.x11.NET_WM_STATE_FULLSCREEN =
|
2012-04-05 17:29:08 +02:00
|
|
|
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_FULLSCREEN");
|
2015-10-13 12:50:59 +02:00
|
|
|
_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");
|
2017-03-21 14:02:57 +01:00
|
|
|
_glfw.x11.NET_WM_STATE_DEMANDS_ATTENTION =
|
|
|
|
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_DEMANDS_ATTENTION");
|
2014-09-22 12:49:03 +02:00
|
|
|
_glfw.x11.NET_WM_FULLSCREEN_MONITORS =
|
|
|
|
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_FULLSCREEN_MONITORS");
|
2016-03-14 20:47:48 +01:00
|
|
|
_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");
|
2013-01-21 18:03:47 +01:00
|
|
|
_glfw.x11.NET_ACTIVE_WINDOW =
|
2012-04-05 17:29:08 +02:00
|
|
|
getSupportedAtom(supportedAtoms, atomCount, "_NET_ACTIVE_WINDOW");
|
2014-03-25 21:30:13 +01:00
|
|
|
_glfw.x11.NET_FRAME_EXTENTS =
|
|
|
|
getSupportedAtom(supportedAtoms, atomCount, "_NET_FRAME_EXTENTS");
|
2014-03-30 12:24:18 +02:00
|
|
|
_glfw.x11.NET_REQUEST_FRAME_EXTENTS =
|
|
|
|
getSupportedAtom(supportedAtoms, atomCount, "_NET_REQUEST_FRAME_EXTENTS");
|
2012-04-05 17:29:08 +02:00
|
|
|
|
2017-01-16 01:36:14 +01:00
|
|
|
if (supportedAtoms)
|
|
|
|
XFree(supportedAtoms);
|
2012-04-05 17:29:08 +02:00
|
|
|
}
|
|
|
|
|
2017-03-20 17:48:45 +01:00
|
|
|
// Look for and initialize supported X11 extensions
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2015-08-23 19:30:04 +02:00
|
|
|
static GLFWbool initExtensions(void)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2017-02-06 21:27:56 +01:00
|
|
|
_glfw.x11.vidmode.handle = dlopen("libXxf86vm.so.1", RTLD_LAZY | RTLD_GLOBAL);
|
2016-12-10 23:41:19 +01:00
|
|
|
if (_glfw.x11.vidmode.handle)
|
|
|
|
{
|
|
|
|
_glfw.x11.vidmode.QueryExtension = (PFN_XF86VidModeQueryExtension)
|
|
|
|
dlsym(_glfw.x11.vidmode.handle, "XF86VidModeQueryExtension");
|
|
|
|
_glfw.x11.vidmode.GetGammaRamp = (PFN_XF86VidModeGetGammaRamp)
|
|
|
|
dlsym(_glfw.x11.vidmode.handle, "XF86VidModeGetGammaRamp");
|
|
|
|
_glfw.x11.vidmode.SetGammaRamp = (PFN_XF86VidModeSetGammaRamp)
|
|
|
|
dlsym(_glfw.x11.vidmode.handle, "XF86VidModeSetGammaRamp");
|
|
|
|
_glfw.x11.vidmode.GetGammaRampSize = (PFN_XF86VidModeGetGammaRampSize)
|
|
|
|
dlsym(_glfw.x11.vidmode.handle, "XF86VidModeGetGammaRampSize");
|
|
|
|
|
|
|
|
_glfw.x11.vidmode.available =
|
|
|
|
XF86VidModeQueryExtension(_glfw.x11.display,
|
|
|
|
&_glfw.x11.vidmode.eventBase,
|
|
|
|
&_glfw.x11.vidmode.errorBase);
|
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2017-03-20 17:49:05 +01:00
|
|
|
_glfw.x11.xi.handle = dlopen("libXi.so.6", RTLD_LAZY | RTLD_GLOBAL);
|
2017-01-12 20:31:59 +01:00
|
|
|
if (_glfw.x11.xi.handle)
|
|
|
|
{
|
|
|
|
_glfw.x11.xi.QueryVersion = (PFN_XIQueryVersion)
|
|
|
|
dlsym(_glfw.x11.xi.handle, "XIQueryVersion");
|
|
|
|
_glfw.x11.xi.SelectEvents = (PFN_XISelectEvents)
|
|
|
|
dlsym(_glfw.x11.xi.handle, "XISelectEvents");
|
|
|
|
|
|
|
|
if (XQueryExtension(_glfw.x11.display,
|
|
|
|
"XInputExtension",
|
|
|
|
&_glfw.x11.xi.majorOpcode,
|
|
|
|
&_glfw.x11.xi.eventBase,
|
|
|
|
&_glfw.x11.xi.errorBase))
|
|
|
|
{
|
|
|
|
_glfw.x11.xi.major = 2;
|
|
|
|
_glfw.x11.xi.minor = 0;
|
|
|
|
|
|
|
|
if (XIQueryVersion(_glfw.x11.display,
|
|
|
|
&_glfw.x11.xi.major,
|
|
|
|
&_glfw.x11.xi.minor) == Success)
|
|
|
|
{
|
|
|
|
_glfw.x11.xi.available = GLFW_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 19:46:09 +02:00
|
|
|
_glfw.x11.randr.handle = dlopen("libXrandr.so.2", RTLD_LAZY | RTLD_GLOBAL);
|
|
|
|
if (_glfw.x11.randr.handle)
|
2010-10-13 04:04:43 +02:00
|
|
|
{
|
2017-08-16 19:46:09 +02:00
|
|
|
_glfw.x11.randr.AllocGamma = (PFN_XRRAllocGamma)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRAllocGamma");
|
|
|
|
_glfw.x11.randr.FreeGamma = (PFN_XRRFreeGamma)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRFreeGamma");
|
|
|
|
_glfw.x11.randr.FreeCrtcInfo = (PFN_XRRFreeCrtcInfo)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRFreeCrtcInfo");
|
|
|
|
_glfw.x11.randr.FreeGamma = (PFN_XRRFreeGamma)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRFreeGamma");
|
|
|
|
_glfw.x11.randr.FreeOutputInfo = (PFN_XRRFreeOutputInfo)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRFreeOutputInfo");
|
|
|
|
_glfw.x11.randr.FreeScreenResources = (PFN_XRRFreeScreenResources)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRFreeScreenResources");
|
|
|
|
_glfw.x11.randr.GetCrtcGamma = (PFN_XRRGetCrtcGamma)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRGetCrtcGamma");
|
|
|
|
_glfw.x11.randr.GetCrtcGammaSize = (PFN_XRRGetCrtcGammaSize)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRGetCrtcGammaSize");
|
|
|
|
_glfw.x11.randr.GetCrtcInfo = (PFN_XRRGetCrtcInfo)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRGetCrtcInfo");
|
|
|
|
_glfw.x11.randr.GetOutputInfo = (PFN_XRRGetOutputInfo)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRGetOutputInfo");
|
|
|
|
_glfw.x11.randr.GetOutputPrimary = (PFN_XRRGetOutputPrimary)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRGetOutputPrimary");
|
|
|
|
_glfw.x11.randr.GetScreenResourcesCurrent = (PFN_XRRGetScreenResourcesCurrent)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRGetScreenResourcesCurrent");
|
|
|
|
_glfw.x11.randr.QueryExtension = (PFN_XRRQueryExtension)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRQueryExtension");
|
|
|
|
_glfw.x11.randr.QueryVersion = (PFN_XRRQueryVersion)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRQueryVersion");
|
|
|
|
_glfw.x11.randr.SelectInput = (PFN_XRRSelectInput)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRSelectInput");
|
|
|
|
_glfw.x11.randr.SetCrtcConfig = (PFN_XRRSetCrtcConfig)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRSetCrtcConfig");
|
|
|
|
_glfw.x11.randr.SetCrtcGamma = (PFN_XRRSetCrtcGamma)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRSetCrtcGamma");
|
|
|
|
_glfw.x11.randr.UpdateConfiguration = (PFN_XRRUpdateConfiguration)
|
|
|
|
dlsym(_glfw.x11.randr.handle, "XRRUpdateConfiguration");
|
|
|
|
|
|
|
|
if (XRRQueryExtension(_glfw.x11.display,
|
|
|
|
&_glfw.x11.randr.eventBase,
|
|
|
|
&_glfw.x11.randr.errorBase))
|
2015-06-14 21:05:42 +02:00
|
|
|
{
|
2017-08-16 19:46:09 +02:00
|
|
|
if (XRRQueryVersion(_glfw.x11.display,
|
|
|
|
&_glfw.x11.randr.major,
|
|
|
|
&_glfw.x11.randr.minor))
|
|
|
|
{
|
|
|
|
// The GLFW RandR path requires at least version 1.3
|
|
|
|
if (_glfw.x11.randr.major > 1 || _glfw.x11.randr.minor >= 3)
|
|
|
|
_glfw.x11.randr.available = GLFW_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"X11: Failed to query RandR version");
|
|
|
|
}
|
2010-11-23 17:45:23 +01:00
|
|
|
}
|
2015-06-14 21:05:42 +02:00
|
|
|
}
|
2013-01-12 18:10:18 +01:00
|
|
|
|
2015-06-14 21:05:42 +02:00
|
|
|
if (_glfw.x11.randr.available)
|
|
|
|
{
|
2016-12-18 15:00:55 +01:00
|
|
|
XRRScreenResources* sr = XRRGetScreenResourcesCurrent(_glfw.x11.display,
|
|
|
|
_glfw.x11.root);
|
2014-08-18 12:58:02 +02:00
|
|
|
|
|
|
|
if (!sr->ncrtc || !XRRGetCrtcGammaSize(_glfw.x11.display, sr->crtcs[0]))
|
|
|
|
{
|
2017-03-19 05:30:27 +01:00
|
|
|
// This is likely an older Nvidia driver with broken gamma support
|
|
|
|
// Flag it as useless and fall back to xf86vm gamma, if available
|
2015-08-23 19:30:04 +02:00
|
|
|
_glfw.x11.randr.gammaBroken = GLFW_TRUE;
|
2014-08-18 12:58:02 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 05:30:27 +01:00
|
|
|
if (!sr->ncrtc)
|
2017-01-16 17:44:31 +01:00
|
|
|
{
|
2017-03-19 05:30:27 +01:00
|
|
|
// A system without CRTCs is likely a system with broken RandR
|
|
|
|
// Disable the RandR monitor path and fall back to core functions
|
2017-01-16 17:44:31 +01:00
|
|
|
_glfw.x11.randr.monitorBroken = GLFW_TRUE;
|
|
|
|
}
|
|
|
|
|
2014-08-18 12:58:02 +02:00
|
|
|
XRRFreeScreenResources(sr);
|
2017-03-19 05:30:27 +01:00
|
|
|
}
|
2015-06-14 21:05:42 +02:00
|
|
|
|
2017-03-19 05:30:27 +01:00
|
|
|
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
|
|
|
|
{
|
2015-06-14 21:05:42 +02:00
|
|
|
XRRSelectInput(_glfw.x11.display, _glfw.x11.root,
|
|
|
|
RROutputChangeNotifyMask);
|
2010-10-13 04:04:43 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2017-08-16 20:54:14 +02:00
|
|
|
_glfw.x11.xcursor.handle = dlopen("libXcursor.so.1", RTLD_LAZY | RTLD_GLOBAL);
|
|
|
|
if (_glfw.x11.xcursor.handle)
|
|
|
|
{
|
|
|
|
_glfw.x11.xcursor.ImageCreate = (PFN_XcursorImageCreate)
|
|
|
|
dlsym(_glfw.x11.xcursor.handle, "XcursorImageCreate");
|
|
|
|
_glfw.x11.xcursor.ImageDestroy = (PFN_XcursorImageDestroy)
|
|
|
|
dlsym(_glfw.x11.xcursor.handle, "XcursorImageDestroy");
|
|
|
|
_glfw.x11.xcursor.ImageLoadCursor = (PFN_XcursorImageLoadCursor)
|
|
|
|
dlsym(_glfw.x11.xcursor.handle, "XcursorImageLoadCursor");
|
|
|
|
}
|
|
|
|
|
2017-08-16 19:55:32 +02:00
|
|
|
_glfw.x11.xinerama.handle = dlopen("libXinerama.so.1", RTLD_LAZY | RTLD_GLOBAL);
|
|
|
|
if (_glfw.x11.xinerama.handle)
|
2014-09-22 12:49:03 +02:00
|
|
|
{
|
2017-08-16 19:55:32 +02:00
|
|
|
_glfw.x11.xinerama.IsActive = (PFN_XineramaIsActive)
|
|
|
|
dlsym(_glfw.x11.xinerama.handle, "XineramaIsActive");
|
|
|
|
_glfw.x11.xinerama.QueryExtension = (PFN_XineramaQueryExtension)
|
|
|
|
dlsym(_glfw.x11.xinerama.handle, "XineramaQueryExtension");
|
|
|
|
_glfw.x11.xinerama.QueryScreens = (PFN_XineramaQueryScreens)
|
|
|
|
dlsym(_glfw.x11.xinerama.handle, "XineramaQueryScreens");
|
|
|
|
|
|
|
|
if (XineramaQueryExtension(_glfw.x11.display,
|
|
|
|
&_glfw.x11.xinerama.major,
|
|
|
|
&_glfw.x11.xinerama.minor))
|
|
|
|
{
|
|
|
|
if (XineramaIsActive(_glfw.x11.display))
|
|
|
|
_glfw.x11.xinerama.available = GLFW_TRUE;
|
|
|
|
}
|
2014-09-22 12:49:03 +02:00
|
|
|
}
|
|
|
|
|
2015-05-27 14:35:31 +02:00
|
|
|
_glfw.x11.xkb.major = 1;
|
|
|
|
_glfw.x11.xkb.minor = 0;
|
2014-04-24 07:10:58 +02:00
|
|
|
_glfw.x11.xkb.available =
|
|
|
|
XkbQueryExtension(_glfw.x11.display,
|
|
|
|
&_glfw.x11.xkb.majorOpcode,
|
|
|
|
&_glfw.x11.xkb.eventBase,
|
|
|
|
&_glfw.x11.xkb.errorBase,
|
2015-05-27 14:35:31 +02:00
|
|
|
&_glfw.x11.xkb.major,
|
|
|
|
&_glfw.x11.xkb.minor);
|
2014-04-24 07:10:58 +02:00
|
|
|
|
2014-05-18 12:24:29 +02:00
|
|
|
if (_glfw.x11.xkb.available)
|
2013-01-12 17:06:35 +01:00
|
|
|
{
|
2014-05-18 12:24:29 +02:00
|
|
|
Bool supported;
|
2013-01-12 17:06:35 +01:00
|
|
|
|
2014-05-18 12:24:29 +02:00
|
|
|
if (XkbSetDetectableAutoRepeat(_glfw.x11.display, True, &supported))
|
2014-04-24 07:10:58 +02:00
|
|
|
{
|
2014-05-18 12:24:29 +02:00
|
|
|
if (supported)
|
2015-08-23 19:30:04 +02:00
|
|
|
_glfw.x11.xkb.detectable = GLFW_TRUE;
|
2014-04-24 07:10:58 +02:00
|
|
|
}
|
2013-01-12 21:01:44 +01:00
|
|
|
}
|
|
|
|
|
2017-02-06 21:27:56 +01:00
|
|
|
_glfw.x11.x11xcb.handle = dlopen("libX11-xcb.so.1", RTLD_LAZY | RTLD_GLOBAL);
|
2015-08-10 20:19:04 +02:00
|
|
|
if (_glfw.x11.x11xcb.handle)
|
|
|
|
{
|
2016-12-06 20:10:51 +01:00
|
|
|
_glfw.x11.x11xcb.XGetXCBConnection = (PFN_XGetXCBConnection)
|
2015-08-10 20:19:04 +02:00
|
|
|
dlsym(_glfw.x11.x11xcb.handle, "XGetXCBConnection");
|
|
|
|
}
|
|
|
|
|
2011-01-02 11:18:14 +01:00
|
|
|
// Update the key code LUT
|
|
|
|
// FIXME: We should listen to XkbMapNotify events to track changes to
|
|
|
|
// the keyboard mapping.
|
2014-03-30 16:23:22 +02:00
|
|
|
createKeyTables();
|
2011-01-02 11:18:14 +01:00
|
|
|
|
2013-01-04 07:11:30 +01:00
|
|
|
// Detect whether an EWMH-conformant window manager is running
|
|
|
|
detectEWMH();
|
|
|
|
|
2016-05-03 12:00:16 +02:00
|
|
|
// String format atoms
|
2015-01-28 00:04:59 +01:00
|
|
|
_glfw.x11.NULL_ = XInternAtom(_glfw.x11.display, "NULL", False);
|
2013-01-29 02:45:08 +01:00
|
|
|
_glfw.x11.UTF8_STRING =
|
|
|
|
XInternAtom(_glfw.x11.display, "UTF8_STRING", False);
|
|
|
|
_glfw.x11.COMPOUND_STRING =
|
|
|
|
XInternAtom(_glfw.x11.display, "COMPOUND_STRING", False);
|
2013-04-29 13:16:56 +02:00
|
|
|
_glfw.x11.ATOM_PAIR = XInternAtom(_glfw.x11.display, "ATOM_PAIR", False);
|
2013-01-29 02:45:08 +01:00
|
|
|
|
2016-05-03 12:00:16 +02:00
|
|
|
// Custom selection property atom
|
2013-04-29 12:45:18 +02:00
|
|
|
_glfw.x11.GLFW_SELECTION =
|
2013-01-02 01:40:42 +01:00
|
|
|
XInternAtom(_glfw.x11.display, "GLFW_SELECTION", False);
|
2012-04-11 23:32:50 +02:00
|
|
|
|
2016-05-03 12:00:16 +02:00
|
|
|
// ICCCM standard clipboard atoms
|
2013-01-29 02:45:08 +01:00
|
|
|
_glfw.x11.TARGETS = XInternAtom(_glfw.x11.display, "TARGETS", False);
|
2013-04-29 12:26:25 +02:00
|
|
|
_glfw.x11.MULTIPLE = XInternAtom(_glfw.x11.display, "MULTIPLE", False);
|
2017-08-02 16:10:13 +02:00
|
|
|
_glfw.x11.PRIMARY = XInternAtom(_glfw.x11.display, "PRIMARY", False);
|
2013-01-29 02:45:08 +01:00
|
|
|
_glfw.x11.CLIPBOARD = XInternAtom(_glfw.x11.display, "CLIPBOARD", False);
|
2011-09-22 13:03:45 +02:00
|
|
|
|
2016-05-03 12:00:16 +02:00
|
|
|
// Clipboard manager atoms
|
2013-04-29 13:16:56 +02:00
|
|
|
_glfw.x11.CLIPBOARD_MANAGER =
|
|
|
|
XInternAtom(_glfw.x11.display, "CLIPBOARD_MANAGER", False);
|
|
|
|
_glfw.x11.SAVE_TARGETS =
|
|
|
|
XInternAtom(_glfw.x11.display, "SAVE_TARGETS", False);
|
|
|
|
|
2016-05-03 12:00:16 +02:00
|
|
|
// Xdnd (drag and drop) atoms
|
2016-05-01 22:54:02 +02:00
|
|
|
_glfw.x11.XdndAware = XInternAtom(_glfw.x11.display, "XdndAware", False);
|
|
|
|
_glfw.x11.XdndEnter = XInternAtom(_glfw.x11.display, "XdndEnter", False);
|
|
|
|
_glfw.x11.XdndPosition = XInternAtom(_glfw.x11.display, "XdndPosition", False);
|
|
|
|
_glfw.x11.XdndStatus = XInternAtom(_glfw.x11.display, "XdndStatus", False);
|
|
|
|
_glfw.x11.XdndActionCopy = XInternAtom(_glfw.x11.display, "XdndActionCopy", False);
|
|
|
|
_glfw.x11.XdndDrop = XInternAtom(_glfw.x11.display, "XdndDrop", False);
|
|
|
|
_glfw.x11.XdndFinished = XInternAtom(_glfw.x11.display, "XdndFinished", False);
|
|
|
|
_glfw.x11.XdndSelection = XInternAtom(_glfw.x11.display, "XdndSelection", False);
|
2017-03-16 23:07:59 +01:00
|
|
|
_glfw.x11.XdndTypeList = XInternAtom(_glfw.x11.display, "XdndTypeList", False);
|
|
|
|
_glfw.x11.text_uri_list = XInternAtom(_glfw.x11.display, "text/uri-list", False);
|
2013-07-10 11:42:14 +02:00
|
|
|
|
2016-05-03 12:00:16 +02:00
|
|
|
// ICCCM, EWMH and Motif window property atoms
|
|
|
|
// These can be set safely even without WM support
|
|
|
|
// The EWMH atoms that require WM support are handled in detectEWMH
|
|
|
|
_glfw.x11.WM_PROTOCOLS =
|
|
|
|
XInternAtom(_glfw.x11.display, "WM_PROTOCOLS", False);
|
|
|
|
_glfw.x11.WM_STATE =
|
|
|
|
XInternAtom(_glfw.x11.display, "WM_STATE", False);
|
|
|
|
_glfw.x11.WM_DELETE_WINDOW =
|
|
|
|
XInternAtom(_glfw.x11.display, "WM_DELETE_WINDOW", False);
|
|
|
|
_glfw.x11.NET_WM_ICON =
|
|
|
|
XInternAtom(_glfw.x11.display, "_NET_WM_ICON", False);
|
|
|
|
_glfw.x11.NET_WM_PING =
|
|
|
|
XInternAtom(_glfw.x11.display, "_NET_WM_PING", False);
|
|
|
|
_glfw.x11.NET_WM_PID =
|
|
|
|
XInternAtom(_glfw.x11.display, "_NET_WM_PID", False);
|
|
|
|
_glfw.x11.NET_WM_NAME =
|
|
|
|
XInternAtom(_glfw.x11.display, "_NET_WM_NAME", False);
|
|
|
|
_glfw.x11.NET_WM_ICON_NAME =
|
|
|
|
XInternAtom(_glfw.x11.display, "_NET_WM_ICON_NAME", False);
|
|
|
|
_glfw.x11.NET_WM_BYPASS_COMPOSITOR =
|
|
|
|
XInternAtom(_glfw.x11.display, "_NET_WM_BYPASS_COMPOSITOR", False);
|
|
|
|
_glfw.x11.MOTIF_WM_HINTS =
|
|
|
|
XInternAtom(_glfw.x11.display, "_MOTIF_WM_HINTS", False);
|
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2014-06-22 13:13:53 +02:00
|
|
|
// Create a blank cursor for hidden and disabled cursor modes
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2016-02-22 12:29:52 +01:00
|
|
|
static Cursor createHiddenCursor(void)
|
2010-09-11 15:39:21 +02:00
|
|
|
{
|
2017-03-20 17:51:03 +01:00
|
|
|
unsigned char pixels[16 * 16 * 4] = { 0 };
|
2014-06-22 13:13:53 +02:00
|
|
|
GLFWimage image = { 16, 16, pixels };
|
2015-12-03 18:16:46 +01:00
|
|
|
return _glfwCreateCursorX11(&image, 0, 0);
|
2010-09-11 15:39:21 +02:00
|
|
|
}
|
|
|
|
|
2015-10-24 22:46:56 +02:00
|
|
|
// Create a helper window for IPC
|
|
|
|
//
|
|
|
|
static Window createHelperWindow(void)
|
|
|
|
{
|
|
|
|
XSetWindowAttributes wa;
|
|
|
|
wa.event_mask = PropertyChangeMask;
|
|
|
|
|
|
|
|
return XCreateWindow(_glfw.x11.display, _glfw.x11.root,
|
|
|
|
0, 0, 1, 1, 0, 0,
|
|
|
|
InputOnly,
|
|
|
|
DefaultVisual(_glfw.x11.display, _glfw.x11.screen),
|
|
|
|
CWEventMask, &wa);
|
|
|
|
}
|
|
|
|
|
2013-07-11 01:23:26 +02:00
|
|
|
// X error handler
|
|
|
|
//
|
|
|
|
static int errorHandler(Display *display, XErrorEvent* event)
|
|
|
|
{
|
|
|
|
_glfw.x11.errorCode = event->error_code;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-09-02 19:42:43 +02:00
|
|
|
// Sets the X error handler callback
|
2013-07-11 01:23:26 +02:00
|
|
|
//
|
2015-12-03 18:16:46 +01:00
|
|
|
void _glfwGrabErrorHandlerX11(void)
|
2013-07-11 01:23:26 +02:00
|
|
|
{
|
|
|
|
_glfw.x11.errorCode = Success;
|
|
|
|
XSetErrorHandler(errorHandler);
|
|
|
|
}
|
|
|
|
|
2014-09-02 19:42:43 +02:00
|
|
|
// Clears the X error handler callback
|
2013-07-11 01:23:26 +02:00
|
|
|
//
|
2015-12-03 18:16:46 +01:00
|
|
|
void _glfwReleaseErrorHandlerX11(void)
|
2013-07-11 01:23:26 +02:00
|
|
|
{
|
|
|
|
// Synchronize to make sure all commands are processed
|
|
|
|
XSync(_glfw.x11.display, False);
|
|
|
|
XSetErrorHandler(NULL);
|
|
|
|
}
|
|
|
|
|
2014-09-02 19:42:43 +02:00
|
|
|
// Reports the specified error, appending information about the last X error
|
2013-07-11 01:23:26 +02:00
|
|
|
//
|
2015-12-03 18:16:46 +01:00
|
|
|
void _glfwInputErrorX11(int error, const char* message)
|
2013-07-11 01:23:26 +02:00
|
|
|
{
|
|
|
|
char buffer[8192];
|
|
|
|
XGetErrorText(_glfw.x11.display, _glfw.x11.errorCode,
|
|
|
|
buffer, sizeof(buffer));
|
|
|
|
|
|
|
|
_glfwInputError(error, "%s: %s", message, buffer);
|
|
|
|
}
|
|
|
|
|
2014-09-02 19:42:43 +02:00
|
|
|
// Creates a native cursor object from the specified image and hotspot
|
2014-06-22 13:13:53 +02:00
|
|
|
//
|
2015-12-03 18:16:46 +01:00
|
|
|
Cursor _glfwCreateCursorX11(const GLFWimage* image, int xhot, int yhot)
|
2014-06-22 13:13:53 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Cursor cursor;
|
|
|
|
|
2017-08-16 20:54:14 +02:00
|
|
|
if (!_glfw.x11.xcursor.handle)
|
|
|
|
return None;
|
|
|
|
|
2014-06-22 13:13:53 +02:00
|
|
|
XcursorImage* native = XcursorImageCreate(image->width, image->height);
|
|
|
|
if (native == NULL)
|
|
|
|
return None;
|
|
|
|
|
|
|
|
native->xhot = xhot;
|
|
|
|
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)
|
|
|
|
{
|
2016-02-23 11:47:14 +01:00
|
|
|
unsigned int alpha = source[3];
|
2016-02-17 06:53:57 +01:00
|
|
|
|
|
|
|
*target = (alpha << 24) |
|
2016-02-23 11:47:14 +01:00
|
|
|
((unsigned char) ((source[0] * alpha) / 255) << 16) |
|
|
|
|
((unsigned char) ((source[1] * alpha) / 255) << 8) |
|
|
|
|
((unsigned char) ((source[2] * alpha) / 255) << 0);
|
2014-06-22 13:13:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cursor = XcursorImageLoadCursor(_glfw.x11.display, native);
|
|
|
|
XcursorImageDestroy(native);
|
|
|
|
|
|
|
|
return cursor;
|
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2010-09-15 16:44:43 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2010-09-08 15:51:25 +02:00
|
|
|
int _glfwPlatformInit(void)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2015-10-09 13:23:34 +02:00
|
|
|
#if !defined(X_HAVE_UTF8_STRING)
|
2017-01-11 19:54:00 +01:00
|
|
|
// HACK: If the current locale is "C" and the Xlib UTF-8 functions are
|
|
|
|
// unavailable, apply the environment's locale in the hope that it's
|
|
|
|
// both available and not "C"
|
|
|
|
// This is done because the "C" locale breaks wide character input,
|
|
|
|
// which is what we fall back on when UTF-8 support is missing
|
2014-12-18 02:52:06 +01:00
|
|
|
if (strcmp(setlocale(LC_CTYPE, NULL), "C") == 0)
|
|
|
|
setlocale(LC_CTYPE, "");
|
2015-10-09 13:23:34 +02:00
|
|
|
#endif
|
2014-12-18 02:52:06 +01:00
|
|
|
|
2012-08-12 15:57:52 +02:00
|
|
|
XInitThreads();
|
|
|
|
|
2013-06-24 14:38:00 +02:00
|
|
|
_glfw.x11.display = XOpenDisplay(NULL);
|
|
|
|
if (!_glfw.x11.display)
|
|
|
|
{
|
2015-07-06 14:38:00 +02:00
|
|
|
const char* display = getenv("DISPLAY");
|
|
|
|
if (display)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"X11: Failed to open display %s", display);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"X11: The DISPLAY environment variable is missing");
|
|
|
|
}
|
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2013-06-24 14:38:00 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2013-06-24 14:38:00 +02:00
|
|
|
_glfw.x11.screen = DefaultScreen(_glfw.x11.display);
|
|
|
|
_glfw.x11.root = RootWindow(_glfw.x11.display, _glfw.x11.screen);
|
|
|
|
_glfw.x11.context = XUniqueContext();
|
2015-10-24 22:46:56 +02:00
|
|
|
_glfw.x11.helperWindowHandle = createHelperWindow();
|
|
|
|
_glfw.x11.hiddenCursorHandle = createHiddenCursor();
|
2010-10-13 04:04:43 +02:00
|
|
|
|
2013-06-24 14:38:00 +02:00
|
|
|
if (!initExtensions())
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2012-04-23 13:00:49 +02:00
|
|
|
|
2014-09-21 02:13:41 +02:00
|
|
|
if (XSupportsLocale())
|
|
|
|
{
|
|
|
|
XSetLocaleModifiers("");
|
|
|
|
|
2015-06-09 14:41:07 +02:00
|
|
|
_glfw.x11.im = XOpenIM(_glfw.x11.display, 0, NULL, NULL);
|
2014-09-21 02:13:41 +02:00
|
|
|
if (_glfw.x11.im)
|
|
|
|
{
|
|
|
|
if (!hasUsableInputMethodStyle())
|
|
|
|
{
|
|
|
|
XCloseIM(_glfw.x11.im);
|
|
|
|
_glfw.x11.im = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-31 03:29:28 +01:00
|
|
|
#if defined(__linux__)
|
2015-12-03 18:16:46 +01:00
|
|
|
if (!_glfwInitJoysticksLinux())
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2017-01-31 03:29:28 +01:00
|
|
|
#endif
|
2013-10-16 17:24:37 +02:00
|
|
|
|
2015-12-03 18:16:46 +01:00
|
|
|
_glfwInitTimerPOSIX();
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2016-12-05 01:19:48 +01:00
|
|
|
_glfwPollMonitorsX11();
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2012-12-30 01:15:48 +01:00
|
|
|
void _glfwPlatformTerminate(void)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2015-08-10 20:19:04 +02:00
|
|
|
if (_glfw.x11.x11xcb.handle)
|
|
|
|
{
|
|
|
|
dlclose(_glfw.x11.x11xcb.handle);
|
|
|
|
_glfw.x11.x11xcb.handle = NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-16 19:46:09 +02:00
|
|
|
if (_glfw.x11.randr.handle)
|
|
|
|
{
|
|
|
|
dlclose(_glfw.x11.randr.handle);
|
|
|
|
_glfw.x11.randr.handle = NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-16 20:54:14 +02:00
|
|
|
if (_glfw.x11.xcursor.handle)
|
|
|
|
{
|
|
|
|
dlclose(_glfw.x11.xcursor.handle);
|
|
|
|
_glfw.x11.xcursor.handle = NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-16 19:55:32 +02:00
|
|
|
if (_glfw.x11.xinerama.handle)
|
|
|
|
{
|
|
|
|
dlclose(_glfw.x11.xinerama.handle);
|
|
|
|
_glfw.x11.xinerama.handle = NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-24 22:46:56 +02:00
|
|
|
if (_glfw.x11.helperWindowHandle)
|
|
|
|
{
|
2015-10-24 22:54:30 +02:00
|
|
|
if (XGetSelectionOwner(_glfw.x11.display, _glfw.x11.CLIPBOARD) ==
|
|
|
|
_glfw.x11.helperWindowHandle)
|
|
|
|
{
|
|
|
|
_glfwPushSelectionToManagerX11();
|
|
|
|
}
|
|
|
|
|
2015-10-24 22:46:56 +02:00
|
|
|
XDestroyWindow(_glfw.x11.display, _glfw.x11.helperWindowHandle);
|
|
|
|
_glfw.x11.helperWindowHandle = None;
|
|
|
|
}
|
|
|
|
|
2016-09-06 16:21:15 +02:00
|
|
|
if (_glfw.x11.hiddenCursorHandle)
|
2010-09-11 15:42:32 +02:00
|
|
|
{
|
2016-09-06 16:21:15 +02:00
|
|
|
XFreeCursor(_glfw.x11.display, _glfw.x11.hiddenCursorHandle);
|
|
|
|
_glfw.x11.hiddenCursorHandle = (Cursor) 0;
|
2010-09-11 15:42:32 +02:00
|
|
|
}
|
|
|
|
|
2017-08-02 16:10:13 +02:00
|
|
|
free(_glfw.x11.primarySelectionString);
|
2014-08-21 21:14:29 +02:00
|
|
|
free(_glfw.x11.clipboardString);
|
2013-06-24 14:08:50 +02:00
|
|
|
|
2013-10-06 21:19:38 +02:00
|
|
|
if (_glfw.x11.im)
|
|
|
|
{
|
|
|
|
XCloseIM(_glfw.x11.im);
|
|
|
|
_glfw.x11.im = NULL;
|
|
|
|
}
|
|
|
|
|
2015-12-03 18:16:46 +01:00
|
|
|
_glfwTerminateEGL();
|
|
|
|
|
2014-08-21 21:18:02 +02:00
|
|
|
if (_glfw.x11.display)
|
|
|
|
{
|
|
|
|
XCloseDisplay(_glfw.x11.display);
|
|
|
|
_glfw.x11.display = NULL;
|
|
|
|
}
|
2015-08-13 00:21:33 +02:00
|
|
|
|
|
|
|
// NOTE: This needs to be done after XCloseDisplay, as libGL registers
|
2015-10-14 12:36:57 +02:00
|
|
|
// cleanup callbacks that get called by it
|
2015-12-03 18:16:46 +01:00
|
|
|
_glfwTerminateGLX();
|
|
|
|
|
2017-01-31 03:29:28 +01:00
|
|
|
#if defined(__linux__)
|
2015-12-03 18:16:46 +01:00
|
|
|
_glfwTerminateJoysticksLinux();
|
2017-01-31 03:29:28 +01:00
|
|
|
#endif
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2010-09-13 18:05:59 +02:00
|
|
|
const char* _glfwPlatformGetVersionString(void)
|
|
|
|
{
|
2016-03-28 13:19:31 +02:00
|
|
|
return _GLFW_VERSION_NUMBER " X11 GLX EGL"
|
2011-09-20 00:55:20 +02:00
|
|
|
#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
|
|
|
|
" clock_gettime"
|
2015-06-01 19:15:55 +02:00
|
|
|
#else
|
|
|
|
" gettimeofday"
|
2011-09-20 00:55:20 +02:00
|
|
|
#endif
|
2012-11-05 16:19:11 +01:00
|
|
|
#if defined(__linux__)
|
2017-08-07 11:34:06 +02:00
|
|
|
" evdev"
|
2012-03-29 14:06:26 +02:00
|
|
|
#endif
|
|
|
|
#if defined(_GLFW_BUILD_DLL)
|
|
|
|
" shared"
|
2010-09-13 18:05:59 +02:00
|
|
|
#endif
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|