libfreerdp-locale: cleanup solaris code

This commit is contained in:
Marc-André Moreau
2013-03-06 12:50:25 -05:00
parent 1630b80bda
commit 75f80d0198
11 changed files with 50 additions and 89 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 */

View File

@@ -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))

View File

@@ -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]),

View File

@@ -25,6 +25,8 @@
#include <stdlib.h>
#include <string.h>
#include <winpr/crt.h>
#include "liblocale.h"
#include <freerdp/locale/keyboard.h>
@@ -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;
}
}
}

View File

@@ -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 */

View File

@@ -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

View File

@@ -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 */

View File

@@ -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))

View File

@@ -23,8 +23,8 @@
#include <freerdp/types.h>
#include <freerdp/locale/keyboard.h>
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 */