From 75f80d019892fdef224ef530055c2ba52c99e58b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Wed, 6 Mar 2013 12:50:25 -0500 Subject: [PATCH] libfreerdp-locale: cleanup solaris code --- client/Windows/wf_event.c | 2 +- client/X11/xf_keyboard.c | 4 +-- include/freerdp/locale/keyboard.h | 2 +- include/freerdp/scancode.h | 1 - libfreerdp/locale/keyboard.c | 4 +-- libfreerdp/locale/keyboard_sun.c | 35 ++++++++++++++--------- libfreerdp/locale/keyboard_sun.h | 8 +++--- libfreerdp/locale/keyboard_x11.c | 33 ++++------------------ libfreerdp/locale/keyboard_x11.h | 2 +- libfreerdp/locale/keyboard_xkbfile.c | 42 ++++++---------------------- libfreerdp/locale/keyboard_xkbfile.h | 6 ++-- 11 files changed, 50 insertions(+), 89 deletions(-) diff --git a/client/Windows/wf_event.c b/client/Windows/wf_event.c index b837d19c0..0c7fd8bd3 100644 --- a/client/Windows/wf_event.c +++ b/client/Windows/wf_event.c @@ -41,7 +41,7 @@ extern HCURSOR g_default_cursor; LRESULT CALLBACK wf_ll_kbd_proc(int nCode, WPARAM wParam, LPARAM lParam) { wfInfo* wfi; - RDP_SCANCODE rdp_scancode; + DWORD rdp_scancode; rdpInput* input; PKBDLLHOOKSTRUCT p; diff --git a/client/X11/xf_keyboard.c b/client/X11/xf_keyboard.c index 3640ed54d..7f4849d1f 100644 --- a/client/X11/xf_keyboard.c +++ b/client/X11/xf_keyboard.c @@ -68,7 +68,7 @@ void xf_kbd_unset_keypress(xfInfo* xfi, BYTE keycode) void xf_kbd_release_all_keypress(xfInfo* xfi) { int keycode; - RDP_SCANCODE rdp_scancode; + DWORD rdp_scancode; for (keycode = 0; keycode < ARRAYSIZE(xfi->pressed_keys); keycode++) { @@ -89,7 +89,7 @@ BOOL xf_kbd_key_pressed(xfInfo* xfi, KeySym keysym) void xf_kbd_send_key(xfInfo* xfi, BOOL down, BYTE keycode) { - RDP_SCANCODE rdp_scancode; + DWORD rdp_scancode; rdpInput* input; input = xfi->instance->input; diff --git a/include/freerdp/locale/keyboard.h b/include/freerdp/locale/keyboard.h index 1ba6e2158..08b5eab07 100644 --- a/include/freerdp/locale/keyboard.h +++ b/include/freerdp/locale/keyboard.h @@ -202,7 +202,7 @@ typedef struct _RDP_KEYBOARD_LAYOUT RDP_KEYBOARD_LAYOUT; 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 RDP_SCANCODE freerdp_keyboard_get_rdp_scancode_from_x11_keycode(UINT32 keycode); +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); #endif /* FREERDP_LOCALE_KEYBOARD_H */ diff --git a/include/freerdp/scancode.h b/include/freerdp/scancode.h index 88f893a0b..f0bc3286b 100644 --- a/include/freerdp/scancode.h +++ b/include/freerdp/scancode.h @@ -29,7 +29,6 @@ * The extended flag is for all practical an important 9th bit with a strange encoding - not just a modifier. */ -typedef UINT32 RDP_SCANCODE; /* Our own representation of a RDP protocol scancode */ #define RDP_SCANCODE_CODE(_rdp_scancode) ((BYTE)(_rdp_scancode & 0xFF)) #define RDP_SCANCODE_EXTENDED(_rdp_scancode) (((_rdp_scancode) & KBDEXT) ? TRUE : FALSE) #define MAKE_RDP_SCANCODE(_code, _extended) (((_code) & 0xFF) | ((_extended) ? KBDEXT : 0)) diff --git a/libfreerdp/locale/keyboard.c b/libfreerdp/locale/keyboard.c index aca2666fc..9bec2a9b3 100644 --- a/libfreerdp/locale/keyboard.c +++ b/libfreerdp/locale/keyboard.c @@ -42,7 +42,7 @@ #endif UINT32 RDP_SCANCODE_TO_X11_KEYCODE[256][2]; -RDP_SCANCODE X11_KEYCODE_TO_RDP_SCANCODE[256]; +DWORD X11_KEYCODE_TO_RDP_SCANCODE[256]; UINT32 freerdp_detect_keyboard(UINT32 keyboardLayoutID) { @@ -91,7 +91,7 @@ UINT32 freerdp_keyboard_init(UINT32 keyboardLayoutId) return keyboardLayoutId; } -RDP_SCANCODE freerdp_keyboard_get_rdp_scancode_from_x11_keycode(UINT32 keycode) +DWORD freerdp_keyboard_get_rdp_scancode_from_x11_keycode(UINT32 keycode) { DEBUG_KBD("x11 keycode: %02X -> rdp code: %02X%s", keycode, RDP_SCANCODE_CODE(X11_KEYCODE_TO_RDP_SCANCODE[keycode]), diff --git a/libfreerdp/locale/keyboard_sun.c b/libfreerdp/locale/keyboard_sun.c index d0b7f7234..5f8b62e17 100644 --- a/libfreerdp/locale/keyboard_sun.c +++ b/libfreerdp/locale/keyboard_sun.c @@ -25,6 +25,8 @@ #include #include +#include + #include "liblocale.h" #include @@ -202,18 +204,12 @@ static const SOLARIS_KEYBOARD SOLARIS_KEYBOARD_TABLE[] = { 6, 272, "sun(type6)", KBD_PORTUGUESE_BRAZILIAN_ABNT } /* Brazil6_usb */ }; -UINT32 freerdp_detect_keyboard_type_and_layout_solaris(char* keyboard_type, int length) +int freerdp_get_solaris_keyboard_layout_and_type(int* type, int* layout) { FILE* kbd; - - int i; - int type = 0; - int layout = 0; - char* pch; char* beg; char* end; - char buffer[1024]; /* @@ -226,10 +222,13 @@ UINT32 freerdp_detect_keyboard_type_and_layout_solaris(char* keyboard_type, int rate(ms)=40 */ + *type = 0; + *layout = 0; + kbd = popen("kbd -t -l", "r"); if (kbd < 0) - return 0; + return -1; while (fgets(buffer, sizeof(buffer), kbd) != NULL) { @@ -238,27 +237,37 @@ UINT32 freerdp_detect_keyboard_type_and_layout_solaris(char* keyboard_type, int beg = pch + sizeof("type=") - 1; end = strchr(beg, '\n'); end[0] = '\0'; - type = atoi(beg); + *type = atoi(beg); } else if ((pch = strstr(buffer, "layout=")) != NULL) { beg = pch + sizeof("layout=") - 1; end = strchr(beg, ' '); end[0] = '\0'; - layout = atoi(beg); + *layout = atoi(beg); } } + pclose(kbd); + return 0; +} + +DWORD freerdp_detect_solaris_keyboard_layout() +{ + int i; + int type; + int layout; + + if (freerdp_get_solaris_keyboard_layout_and_type(&type, &layout) < 0) + return 0; + for (i = 0; i < ARRAYSIZE(SOLARIS_KEYBOARD_TABLE); i++) { if (SOLARIS_KEYBOARD_TABLE[i].type == type) { if (SOLARIS_KEYBOARD_TABLE[i].layout == layout) - { - strncpy(keyboard_type, SOLARIS_KEYBOARD_TABLE[i].xkbType, length); return SOLARIS_KEYBOARD_TABLE[i].keyboardLayoutId; - } } } diff --git a/libfreerdp/locale/keyboard_sun.h b/libfreerdp/locale/keyboard_sun.h index 985e1e3ac..b7dd5a80d 100644 --- a/libfreerdp/locale/keyboard_sun.h +++ b/libfreerdp/locale/keyboard_sun.h @@ -17,9 +17,9 @@ * limitations under the License. */ -#ifndef __LOCALE_KEYBOARD_SUN_H -#define __LOCALE_KEYBOARD_SUN_H +#ifndef FREERDP_LOCALE_KEYBOARD_SUN_H +#define FREERDP_LOCALE_KEYBOARD_SUN_H -UINT32 freerdp_detect_keyboard_type_and_layout_solaris(char* keyboard_type, int length); +DWORD freerdp_detect_solaris_keyboard_layout(); -#endif /* __LOCALE_KEYBOARD_SUN_H */ +#endif /* FREERDP_LOCALE_KEYBOARD_SUN_H */ diff --git a/libfreerdp/locale/keyboard_x11.c b/libfreerdp/locale/keyboard_x11.c index 5376ca915..b78922516 100644 --- a/libfreerdp/locale/keyboard_x11.c +++ b/libfreerdp/locale/keyboard_x11.c @@ -36,10 +36,6 @@ #include "keyboard_x11.h" #include "xkb_layout_ids.h" -#ifdef WITH_SUN -#include "keyboard_sun.h" -#endif - UINT32 freerdp_detect_keyboard_layout_from_xkb(char** xkb_layout, char** xkb_variant) { char* pch; @@ -69,7 +65,7 @@ UINT32 freerdp_detect_keyboard_layout_from_xkb(char** xkb_layout, char** xkb_var if ((pch = strstr(buffer, "_XKB_RULES_NAMES_BACKUP(STRING) = ")) != NULL) { /* "rules" */ - pch = strchr(&buffer[34], ','); // We assume it is xorg + pch = strchr(&buffer[34], ','); /* We assume it is xorg */ pch += 1; /* "type" */ @@ -140,6 +136,7 @@ UINT32 freerdp_detect_keyboard_layout_from_xkb(char** xkb_layout, char** xkb_var variant = beg; } } + pclose(xprop); DEBUG_KBD("_XKB_RULES_NAMES layout: %s, variant: %s", layout, variant); @@ -206,34 +203,24 @@ char* freerdp_detect_keymap_from_xkb() return keymap; } -UINT32 freerdp_keyboard_init_x11(UINT32 keyboardLayoutId, RDP_SCANCODE x11_keycode_to_rdp_scancode[256]) +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(RDP_SCANCODE) * 256); + 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); } - -#elif defined(WITH_SUN) - { - char sunkeymap[32]; - - freerdp_detect_keyboard_type_and_layout_solaris(sunkeymap, sizeof(sunkeymap)); - freerdp_keyboard_load_map(keycode_to_vkcode, sunkeymap); - } #else { - char* keymap; - char* xkb_layout = 0; - char* xkb_variant = 0; + char* xkb_layout = NULL; + char* xkb_variant = NULL; if (keyboardLayoutId == 0) { @@ -245,14 +232,6 @@ UINT32 freerdp_keyboard_init_x11(UINT32 keyboardLayoutId, RDP_SCANCODE x11_keyco if (xkb_variant) free(xkb_variant); } - - keymap = freerdp_detect_keymap_from_xkb(); - - if (keymap) - { - freerdp_keyboard_load_maps(keycode_to_vkcode, keymap); - free(keymap); - } } #endif diff --git a/libfreerdp/locale/keyboard_x11.h b/libfreerdp/locale/keyboard_x11.h index 77dece1c9..b9c81d06d 100644 --- a/libfreerdp/locale/keyboard_x11.h +++ b/libfreerdp/locale/keyboard_x11.h @@ -20,6 +20,6 @@ #ifndef __LOCALE_KEYBOARD_X11_H #define __LOCALE_KEYBOARD_X11_H -UINT32 freerdp_keyboard_init_x11(UINT32 keyboardLayoutId, RDP_SCANCODE x11_keycode_to_rdp_scancode[256]); +UINT32 freerdp_keyboard_init_x11(UINT32 keyboardLayoutId, DWORD x11_keycode_to_rdp_scancode[256]); #endif /* __LOCALE_KEYBOARD_X11_H */ diff --git a/libfreerdp/locale/keyboard_xkbfile.c b/libfreerdp/locale/keyboard_xkbfile.c index 1113a6141..1a44d7c19 100644 --- a/libfreerdp/locale/keyboard_xkbfile.c +++ b/libfreerdp/locale/keyboard_xkbfile.c @@ -44,7 +44,7 @@ struct _XKB_KEY_NAME_SCANCODE { const char* xkb_keyname; /* XKB keyname */ - RDP_SCANCODE rdp_scancode; + DWORD rdp_scancode; }; typedef struct _XKB_KEY_NAME_SCANCODE XKB_KEY_NAME_SCANCODE; @@ -170,7 +170,7 @@ void* freerdp_keyboard_xkb_init() Display* display = XOpenDisplay(NULL); - if (display == NULL) + if (!display) return NULL; status = XkbQueryExtension(display, NULL, NULL, NULL, NULL, NULL); @@ -181,11 +181,11 @@ void* freerdp_keyboard_xkb_init() return (void*) display; } -UINT32 freerdp_keyboard_init_xkbfile(UINT32 keyboardLayoutId, RDP_SCANCODE x11_keycode_to_rdp_scancode[256]) +DWORD freerdp_keyboard_init_xkbfile(DWORD keyboardLayoutId, DWORD x11_keycode_to_rdp_scancode[256]) { void* display; - ZeroMemory(x11_keycode_to_rdp_scancode, sizeof(RDP_SCANCODE) * 256); + ZeroMemory(x11_keycode_to_rdp_scancode, sizeof(DWORD) * 256); display = freerdp_keyboard_xkb_init(); @@ -203,30 +203,6 @@ UINT32 freerdp_keyboard_init_xkbfile(UINT32 keyboardLayoutId, RDP_SCANCODE x11_k freerdp_keyboard_load_map_from_xkbfile(display, x11_keycode_to_rdp_scancode); -#if 1 - //ZeroMemory(x11_keycode_to_rdp_scancode, sizeof(RDP_SCANCODE) * 256); - - { - DWORD keycode; - DWORD vkcode; - DWORD scancode; - - for (keycode = 0; keycode < 256; keycode++) - { - vkcode = GetVirtualKeyCodeFromKeycode(keycode, KEYCODE_TYPE_EVDEV); - scancode = GetVirtualScanCodeFromVirtualKeyCode(vkcode, 4); - - if (x11_keycode_to_rdp_scancode[keycode] != scancode) - { - printf("mismatch keycode 0x%04X (%d) -> vkcode 0x%04X (%s) -> scancode 0x%04X, expected: 0x%04X\n", - keycode, keycode, vkcode, GetVirtualKeyName(vkcode & 0xFF), scancode, x11_keycode_to_rdp_scancode[keycode]); - } - - x11_keycode_to_rdp_scancode[keycode] = scancode; - } - } -#endif - XCloseDisplay(display); return keyboardLayoutId; @@ -254,12 +230,12 @@ static char* comma_substring(char* s, int n) return s; } -UINT32 detect_keyboard_layout_from_xkbfile(void* display) +DWORD detect_keyboard_layout_from_xkbfile(void* display) { char* layout; char* variant; - UINT32 group = 0; - UINT32 keyboard_layout = 0; + DWORD group = 0; + DWORD keyboard_layout = 0; XkbRF_VarDefsRec rules_names; XKeyboardState coreKbdState; XkbStateRec state; @@ -295,7 +271,7 @@ UINT32 detect_keyboard_layout_from_xkbfile(void* display) return keyboard_layout; } -int freerdp_keyboard_load_map_from_xkbfile(void* display, RDP_SCANCODE x11_keycode_to_rdp_scancode[256]) +int freerdp_keyboard_load_map_from_xkbfile(void* display, DWORD x11_keycode_to_rdp_scancode[256]) { int i, j; BOOL found; @@ -316,8 +292,6 @@ int freerdp_keyboard_load_map_from_xkbfile(void* display, RDP_SCANCODE x11_keyco if (strlen(xkb_keyname) < 1) continue; - printf("XKB KeyName: %s\n", xkb_keyname); - for (j = 0; j < ARRAYSIZE(XKB_KEY_NAME_SCANCODE_TABLE); j++) { if (!strcmp(xkb_keyname, XKB_KEY_NAME_SCANCODE_TABLE[j].xkb_keyname)) diff --git a/libfreerdp/locale/keyboard_xkbfile.h b/libfreerdp/locale/keyboard_xkbfile.h index 9205bd13d..06bdb9682 100644 --- a/libfreerdp/locale/keyboard_xkbfile.h +++ b/libfreerdp/locale/keyboard_xkbfile.h @@ -23,8 +23,8 @@ #include #include -UINT32 freerdp_keyboard_init_xkbfile(UINT32 keyboardLayoutId, RDP_SCANCODE x11_keycode_to_rdp_scancode[256]); -UINT32 detect_keyboard_layout_from_xkbfile(void* display); -int freerdp_keyboard_load_map_from_xkbfile(void* display, RDP_SCANCODE x11_keycode_to_rdp_scancode[256]); +DWORD 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]); #endif /* __LOCALE_KEYBOARD_XKB_H */