struct _RDP_KEYBOARD_LAYOUT
{
- UINT32 code; /* Keyboard layout code */
+ DWORD code; /* Keyboard layout code */
char* name; /* Keyboard layout name */
};
typedef struct _RDP_KEYBOARD_LAYOUT RDP_KEYBOARD_LAYOUT;
#define KBD_TYPE_NOKIA_9140 0x00000006 /* Nokia 9140 and similar keyboards */
#define KBD_TYPE_JAPANESE 0x00000007 /* Japanese keyboard */
-FREERDP_API UINT32 freerdp_keyboard_init(UINT32 keyboardLayoutId);
-FREERDP_API RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(UINT32 types);
-FREERDP_API const char* freerdp_keyboard_get_layout_name_from_id(UINT32 keyboardLayoutId);
-FREERDP_API DWORD freerdp_keyboard_get_rdp_scancode_from_x11_keycode(UINT32 keycode);
-FREERDP_API UINT32 freerdp_keyboard_get_x11_keycode_from_rdp_scancode(UINT32 scancode, BOOL extended);
+FREERDP_API DWORD freerdp_keyboard_init(DWORD keyboardLayoutId);
+FREERDP_API RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(DWORD types);
+FREERDP_API const char* freerdp_keyboard_get_layout_name_from_id(DWORD keyboardLayoutId);
+FREERDP_API DWORD freerdp_keyboard_get_rdp_scancode_from_x11_keycode(DWORD keycode);
+FREERDP_API DWORD freerdp_keyboard_get_x11_keycode_from_rdp_scancode(DWORD scancode, BOOL extended);
#endif /* FREERDP_LOCALE_KEYBOARD_H */
#define YORUBA 0x046A
#define ZULU 0x0435
-FREERDP_API UINT32 freerdp_get_system_locale_id(void);
-FREERDP_API UINT32 freerdp_detect_keyboard_layout_from_system_locale(void);
-FREERDP_API const char* freerdp_get_system_locale_name_from_id(UINT32 localeId);
+FREERDP_API DWORD freerdp_get_system_locale_id(void);
+FREERDP_API DWORD freerdp_detect_keyboard_layout_from_system_locale(void);
+FREERDP_API const char* freerdp_get_system_locale_name_from_id(DWORD localeId);
#endif /* FREERDP_LOCALE_H */
liblocale.h)
set(${MODULE_PREFIX}_X11_SRCS
+ keyboard_x11.c
+ keyboard_x11.h
xkb_layout_ids.c
xkb_layout_ids.h)
-set(${MODULE_PREFIX}_X11_KEYMAP_SRCS
- keyboard_x11.c
- keyboard_x11.h)
-
set(${MODULE_PREFIX}_XKBFILE_SRCS
keyboard_xkbfile.c
keyboard_xkbfile.h)
#include "liblocale.h"
#ifdef WITH_X11
+
#include "keyboard_x11.h"
#ifdef WITH_XKBFILE
#endif
-UINT32 RDP_SCANCODE_TO_X11_KEYCODE[256][2];
+DWORD RDP_SCANCODE_TO_X11_KEYCODE[256][2];
DWORD X11_KEYCODE_TO_RDP_SCANCODE[256];
-UINT32 freerdp_detect_keyboard(UINT32 keyboardLayoutID)
+int freerdp_detect_keyboard(DWORD* keyboardLayoutId)
{
- if (keyboardLayoutID != 0)
- DEBUG_KBD("keyboard layout configuration: %X", keyboardLayoutID);
+ if (*keyboardLayoutId == 0)
+ freerdp_detect_keyboard_layout_from_xkb(keyboardLayoutId);
+
+ if (*keyboardLayoutId == 0)
+ *keyboardLayoutId = freerdp_detect_keyboard_layout_from_system_locale();
+
+ if (*keyboardLayoutId == 0)
+ *keyboardLayoutId = 0x0409;
+
+ return 0;
+}
- if (keyboardLayoutID == 0)
+int freerdp_keyboard_init_apple(DWORD* keyboardLayoutId, DWORD x11_keycode_to_rdp_scancode[256])
+{
+ DWORD vkcode;
+ DWORD keycode;
+ DWORD keycode_to_vkcode[256];
+
+ ZeroMemory(keycode_to_vkcode, sizeof(keycode_to_vkcode));
+
+ for (keycode = 0; keycode < 256; keycode++)
{
- keyboardLayoutID = freerdp_detect_keyboard_layout_from_system_locale();
- DEBUG_KBD("detect_keyboard_layout_from_locale: %X", keyboardLayoutID);
+ vkcode = keycode_to_vkcode[keycode] = GetVirtualKeyCodeFromKeycode(keycode, KEYCODE_TYPE_APPLE);
+ x11_keycode_to_rdp_scancode[keycode] = GetVirtualScanCodeFromVirtualKeyCode(vkcode, 4);
}
- if (keyboardLayoutID == 0)
+ return 0;
+}
+
+int freerdp_keyboard_init_x11_evdev(DWORD* keyboardLayoutId, DWORD x11_keycode_to_rdp_scancode[256])
+{
+ DWORD vkcode;
+ DWORD keycode;
+ DWORD keycode_to_vkcode[256];
+
+ ZeroMemory(keycode_to_vkcode, sizeof(keycode_to_vkcode));
+
+ for (keycode = 0; keycode < 256; keycode++)
{
- keyboardLayoutID = 0x0409;
- DEBUG_KBD("using default keyboard layout: %X", keyboardLayoutID);
+ vkcode = keycode_to_vkcode[keycode] = GetVirtualKeyCodeFromKeycode(keycode, KEYCODE_TYPE_EVDEV);
+ x11_keycode_to_rdp_scancode[keycode] = GetVirtualScanCodeFromVirtualKeyCode(vkcode, 4);
}
- return keyboardLayoutID;
+ return 0;
}
-UINT32 freerdp_keyboard_init(UINT32 keyboardLayoutId)
+DWORD freerdp_keyboard_init(DWORD keyboardLayoutId)
{
- UINT32 keycode;
+ DWORD keycode;
+ int status = -1;
+
+#ifdef __APPLE__
+ if (status < 0)
+ status = freerdp_keyboard_init_apple(&keyboardLayoutId, X11_KEYCODE_TO_RDP_SCANCODE);
+#endif
#ifdef WITH_X11
#ifdef WITH_XKBFILE
- keyboardLayoutId = freerdp_keyboard_init_xkbfile(keyboardLayoutId, X11_KEYCODE_TO_RDP_SCANCODE);
-#else
- keyboardLayoutId = freerdp_keyboard_init_x11(keyboardLayoutId, X11_KEYCODE_TO_RDP_SCANCODE);
+ if (status < 0)
+ status = freerdp_keyboard_init_xkbfile(&keyboardLayoutId, X11_KEYCODE_TO_RDP_SCANCODE);
#endif
+ if (status < 0)
+ status = freerdp_keyboard_init_x11_evdev(&keyboardLayoutId, X11_KEYCODE_TO_RDP_SCANCODE);
+
#endif
- keyboardLayoutId = freerdp_detect_keyboard(keyboardLayoutId);
+
+ freerdp_detect_keyboard(&keyboardLayoutId);
ZeroMemory(RDP_SCANCODE_TO_X11_KEYCODE, sizeof(RDP_SCANCODE_TO_X11_KEYCODE));
return keyboardLayoutId;
}
-DWORD freerdp_keyboard_get_rdp_scancode_from_x11_keycode(UINT32 keycode)
+DWORD freerdp_keyboard_get_rdp_scancode_from_x11_keycode(DWORD keycode)
{
DEBUG_KBD("x11 keycode: %02X -> rdp code: %02X%s", keycode,
RDP_SCANCODE_CODE(X11_KEYCODE_TO_RDP_SCANCODE[keycode]),
return X11_KEYCODE_TO_RDP_SCANCODE[keycode];
}
-UINT32 freerdp_keyboard_get_x11_keycode_from_rdp_scancode(UINT32 scancode, BOOL extended)
+DWORD freerdp_keyboard_get_x11_keycode_from_rdp_scancode(DWORD scancode, BOOL extended)
{
if (extended)
return RDP_SCANCODE_TO_X11_KEYCODE[scancode][1];
struct _RDP_KEYBOARD_LAYOUT_VARIANT
{
- UINT32 code; /* Keyboard layout code */
- UINT32 id; /* Keyboard variant ID */
+ DWORD code; /* Keyboard layout code */
+ DWORD id; /* Keyboard variant ID */
const char* name; /* Keyboard layout variant name */
};
typedef struct _RDP_KEYBOARD_LAYOUT_VARIANT RDP_KEYBOARD_LAYOUT_VARIANT;
struct _RDP_KEYBOARD_IME
{
- UINT32 code; /* Keyboard layout code */
+ DWORD code; /* Keyboard layout code */
const char* file; /* IME file */
const char* name; /* Keyboard layout name */
};
{ KBD_CHINESE_TRADITIONAL_ALPHANUMERIC, "romanime.ime", "Chinese (Traditional) - Alphanumeric" }
};
-RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(UINT32 types)
+RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(DWORD types)
{
int num, length, i;
RDP_KEYBOARD_LAYOUT* layouts;
}
}
- memset(&layouts[num], 0, sizeof(RDP_KEYBOARD_LAYOUT));
+ ZeroMemory(&layouts[num], sizeof(RDP_KEYBOARD_LAYOUT));
return layouts;
}
-const char* freerdp_keyboard_get_layout_name_from_id(UINT32 keyboardLayoutID)
+const char* freerdp_keyboard_get_layout_name_from_id(DWORD keyboardLayoutID)
{
int i;
#include "keyboard_x11.h"
#include "xkb_layout_ids.h"
-UINT32 freerdp_detect_keyboard_layout_from_xkb(char** xkb_layout, char** xkb_variant)
+int freerdp_detect_keyboard_layout_from_xkb(DWORD* keyboardLayoutId)
{
char* pch;
char* beg;
char buffer[1024];
char* layout = NULL;
char* variant = NULL;
- UINT32 keyboardLayoutId = 0;
/* We start by looking for _XKB_RULES_NAMES_BACKUP which appears to be used by libxklavier */
variant = beg;
}
}
+
pclose(xprop);
DEBUG_KBD("_XKB_RULES_NAMES_BACKUP layout: %s, variant: %s", layout, variant);
- keyboardLayoutId = find_keyboard_layout_in_xorg_rules(layout, variant);
+ *keyboardLayoutId = find_keyboard_layout_in_xorg_rules(layout, variant);
- if (keyboardLayoutId > 0)
- {
- *xkb_layout = _strdup(layout);
- *xkb_variant = _strdup(variant);
- return keyboardLayoutId;
- }
+ if (*keyboardLayoutId > 0)
+ return 0;
/* Check _XKB_RULES_NAMES if _XKB_RULES_NAMES_BACKUP fails */
pclose(xprop);
DEBUG_KBD("_XKB_RULES_NAMES layout: %s, variant: %s", layout, variant);
- keyboardLayoutId = find_keyboard_layout_in_xorg_rules(layout, variant);
+ *keyboardLayoutId = find_keyboard_layout_in_xorg_rules(layout, variant);
- if (keyboardLayoutId > 0)
- {
- *xkb_layout = _strdup(layout);
- *xkb_variant = _strdup(variant);
- return keyboardLayoutId;
- }
+ if (*keyboardLayoutId > 0)
+ return *keyboardLayoutId;
return 0;
}
return keymap;
}
-
-UINT32 freerdp_keyboard_init_x11(UINT32 keyboardLayoutId, DWORD x11_keycode_to_rdp_scancode[256])
-{
- DWORD vkcode;
- DWORD keycode;
- DWORD keycode_to_vkcode[256];
-
- ZeroMemory(keycode_to_vkcode, sizeof(keycode_to_vkcode));
- ZeroMemory(x11_keycode_to_rdp_scancode, sizeof(DWORD) * 256);
-
-#ifdef __APPLE__
- for (keycode = 0; keycode < 256; keycode++)
- {
- keycode_to_vkcode[keycode] = GetVirtualKeyCodeFromKeycode(keycode, KEYCODE_TYPE_APPLE);
- }
-#else
- {
- char* xkb_layout = NULL;
- char* xkb_variant = NULL;
-
- if (keyboardLayoutId == 0)
- {
- keyboardLayoutId = freerdp_detect_keyboard_layout_from_xkb(&xkb_layout, &xkb_variant);
-
- if (xkb_layout)
- free(xkb_layout);
-
- if (xkb_variant)
- free(xkb_variant);
- }
- }
-#endif
-
- for (keycode = 0; keycode < 256; keycode++)
- {
- vkcode = keycode_to_vkcode[keycode];
-
- if (vkcode >= 0xFF)
- continue;
-
- x11_keycode_to_rdp_scancode[keycode] = GetVirtualScanCodeFromVirtualKeyCode(vkcode, 4);
- }
-
- return keyboardLayoutId;
-}
* limitations under the License.
*/
-#ifndef __LOCALE_KEYBOARD_X11_H
-#define __LOCALE_KEYBOARD_X11_H
+#ifndef FREERDP_LOCALE_KEYBOARD_X11_H
+#define FREERDP_LOCALE_KEYBOARD_X11_H
-UINT32 freerdp_keyboard_init_x11(UINT32 keyboardLayoutId, DWORD x11_keycode_to_rdp_scancode[256]);
+int freerdp_detect_keyboard_layout_from_xkb(DWORD* keyboardLayoutId);
-#endif /* __LOCALE_KEYBOARD_X11_H */
+#endif /* FREERDP_LOCALE_KEYBOARD_X11_H */
return (void*) display;
}
-DWORD freerdp_keyboard_init_xkbfile(DWORD keyboardLayoutId, DWORD x11_keycode_to_rdp_scancode[256])
+int freerdp_keyboard_init_xkbfile(DWORD* keyboardLayoutId, DWORD x11_keycode_to_rdp_scancode[256])
{
void* display;
if (!display)
{
DEBUG_KBD("Error initializing xkb");
- return 0;
+ return -1;
}
- if (keyboardLayoutId == 0)
+ if (*keyboardLayoutId == 0)
{
- keyboardLayoutId = detect_keyboard_layout_from_xkbfile(display);
+ *keyboardLayoutId = detect_keyboard_layout_from_xkbfile(display);
DEBUG_KBD("detect_keyboard_layout_from_xkb: %X", keyboardLayoutId);
}
XCloseDisplay(display);
- return keyboardLayoutId;
+ return 0;
}
/* return substring starting after nth comma, ending at following comma */
#include <freerdp/types.h>
#include <freerdp/locale/keyboard.h>
-DWORD freerdp_keyboard_init_xkbfile(DWORD keyboardLayoutId, DWORD x11_keycode_to_rdp_scancode[256]);
+int freerdp_keyboard_init_xkbfile(DWORD* keyboardLayoutId, DWORD x11_keycode_to_rdp_scancode[256]);
+
DWORD detect_keyboard_layout_from_xkbfile(void* display);
int freerdp_keyboard_load_map_from_xkbfile(void* display, DWORD x11_keycode_to_rdp_scancode[256]);
{
char language[4]; /* Two or three letter language code */
char country[10]; /* Two or three letter country code (Sometimes with Cyrl_ prefix) */
- UINT32 code; /* 32-bit unsigned integer corresponding to the locale */
+ DWORD code; /* 32-bit unsigned integer corresponding to the locale */
};
typedef struct _SYSTEM_LOCALE SYSTEM_LOCALE;
struct _LOCALE_NAME
{
- UINT32 localeId;
+ DWORD localeId;
const char* name;
};
typedef struct _LOCALE_NAME LOCALE_NAME;
struct _LOCALE_KEYBOARD_LAYOUTS
{
- UINT32 locale; /* Locale ID */
- UINT32 keyboardLayouts[5]; /* array of associated keyboard layouts */
+ DWORD locale; /* Locale ID */
+ DWORD keyboardLayouts[5]; /* array of associated keyboard layouts */
};
typedef struct _LOCALE_KEYBOARD_LAYOUTS LOCALE_KEYBOARD_LAYOUTS;
return locale;
}
-UINT32 freerdp_get_system_locale_id()
+DWORD freerdp_get_system_locale_id()
{
SYSTEM_LOCALE* locale;
return 0;
}
-const char* freerdp_get_system_locale_name_from_id(UINT32 localeId)
+const char* freerdp_get_system_locale_name_from_id(DWORD localeId)
{
int index;
return NULL;
}
-UINT32 freerdp_detect_keyboard_layout_from_system_locale()
+DWORD freerdp_detect_keyboard_layout_from_system_locale()
{
int i, j;
char language[4];