2011-06-30 23:55:03 +04:00
|
|
|
/**
|
2012-02-20 05:24:06 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Keyboard Localization
|
2011-06-30 23:55:03 +04:00
|
|
|
*
|
2012-02-20 05:24:06 +04:00
|
|
|
* Copyright 2009-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2011-06-30 23:55:03 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-06-30 23:55:03 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-11-22 06:22:06 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2012-02-19 07:04:28 +04:00
|
|
|
#include <freerdp/types.h>
|
|
|
|
#include <freerdp/locale/keyboard.h>
|
2012-03-24 04:57:09 +04:00
|
|
|
#include <freerdp/locale/locale.h>
|
2012-02-19 07:04:28 +04:00
|
|
|
|
|
|
|
#include "liblocale.h"
|
|
|
|
|
2012-02-19 07:54:44 +04:00
|
|
|
#ifdef WITH_X11
|
|
|
|
#include "keyboard_x11.h"
|
|
|
|
|
2012-03-24 04:57:09 +04:00
|
|
|
#ifdef WITH_XKBFILE
|
|
|
|
#include "keyboard_xkbfile.h"
|
2011-10-24 22:15:19 +04:00
|
|
|
#endif
|
|
|
|
|
2012-03-24 04:57:09 +04:00
|
|
|
#endif
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 RDP_SCANCODE_TO_X11_KEYCODE[256][2];
|
2012-02-20 05:24:06 +04:00
|
|
|
RDP_SCANCODE X11_KEYCODE_TO_RDP_SCANCODE[256];
|
2011-06-30 23:55:03 +04:00
|
|
|
|
2012-02-22 05:56:34 +04:00
|
|
|
extern const RDP_SCANCODE VIRTUAL_KEY_CODE_TO_DEFAULT_RDP_SCANCODE_TABLE[256];
|
2011-08-15 22:33:04 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 freerdp_detect_keyboard(UINT32 keyboardLayoutID)
|
2012-02-19 21:54:27 +04:00
|
|
|
{
|
|
|
|
if (keyboardLayoutID != 0)
|
|
|
|
DEBUG_KBD("keyboard layout configuration: %X", keyboardLayoutID);
|
|
|
|
|
|
|
|
if (keyboardLayoutID == 0)
|
|
|
|
{
|
2012-02-20 05:48:04 +04:00
|
|
|
keyboardLayoutID = freerdp_detect_keyboard_layout_from_system_locale();
|
2012-02-19 21:54:27 +04:00
|
|
|
DEBUG_KBD("detect_keyboard_layout_from_locale: %X", keyboardLayoutID);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keyboardLayoutID == 0)
|
|
|
|
{
|
|
|
|
keyboardLayoutID = 0x0409;
|
|
|
|
DEBUG_KBD("using default keyboard layout: %X", keyboardLayoutID);
|
|
|
|
}
|
|
|
|
|
|
|
|
return keyboardLayoutID;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 freerdp_keyboard_init(UINT32 keyboardLayoutId)
|
2012-02-19 21:54:27 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 keycode;
|
2012-03-24 04:57:10 +04:00
|
|
|
|
2012-03-24 04:57:09 +04:00
|
|
|
#ifdef WITH_X11
|
|
|
|
|
2012-03-24 04:57:09 +04:00
|
|
|
#ifdef WITH_XKBFILE
|
2012-03-24 04:57:10 +04:00
|
|
|
keyboardLayoutId = freerdp_keyboard_init_xkbfile(keyboardLayoutId, X11_KEYCODE_TO_RDP_SCANCODE);
|
2012-02-19 21:54:27 +04:00
|
|
|
#else
|
2012-03-24 04:57:10 +04:00
|
|
|
keyboardLayoutId = freerdp_keyboard_init_x11(keyboardLayoutId, X11_KEYCODE_TO_RDP_SCANCODE);
|
2012-02-19 21:54:27 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
2012-03-24 04:57:10 +04:00
|
|
|
keyboardLayoutId = freerdp_detect_keyboard(keyboardLayoutId);
|
2012-03-24 04:57:10 +04:00
|
|
|
|
|
|
|
memset(RDP_SCANCODE_TO_X11_KEYCODE, 0, sizeof(RDP_SCANCODE_TO_X11_KEYCODE));
|
2012-11-22 05:50:28 +04:00
|
|
|
for (keycode=0; keycode < ARRAYSIZE(RDP_SCANCODE_TO_X11_KEYCODE); keycode++)
|
2012-03-24 04:57:10 +04:00
|
|
|
RDP_SCANCODE_TO_X11_KEYCODE
|
2012-09-22 22:27:30 +04:00
|
|
|
[RDP_SCANCODE_CODE(X11_KEYCODE_TO_RDP_SCANCODE[keycode])]
|
|
|
|
[RDP_SCANCODE_EXTENDED(X11_KEYCODE_TO_RDP_SCANCODE[keycode]) ? 1 : 0] = keycode;
|
2012-03-24 04:57:10 +04:00
|
|
|
|
2012-02-19 21:54:27 +04:00
|
|
|
return keyboardLayoutId;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
RDP_SCANCODE freerdp_keyboard_get_rdp_scancode_from_x11_keycode(UINT32 keycode)
|
2012-02-19 07:04:28 +04:00
|
|
|
{
|
2012-02-22 02:22:03 +04:00
|
|
|
DEBUG_KBD("x11 keycode: %02X -> rdp code: %02X%s", keycode,
|
2012-09-22 22:27:30 +04:00
|
|
|
RDP_SCANCODE_CODE(X11_KEYCODE_TO_RDP_SCANCODE[keycode]),
|
|
|
|
RDP_SCANCODE_EXTENDED(X11_KEYCODE_TO_RDP_SCANCODE[keycode]) ? " extended" : "");
|
2012-02-24 03:42:54 +04:00
|
|
|
|
2012-03-29 03:12:35 +04:00
|
|
|
return X11_KEYCODE_TO_RDP_SCANCODE[keycode];
|
2012-02-19 07:04:28 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 freerdp_keyboard_get_x11_keycode_from_rdp_scancode(UINT32 scancode, BOOL extended)
|
2012-02-19 07:04:28 +04:00
|
|
|
{
|
|
|
|
if (extended)
|
2012-02-20 05:24:06 +04:00
|
|
|
return RDP_SCANCODE_TO_X11_KEYCODE[scancode][1];
|
2012-02-19 07:04:28 +04:00
|
|
|
else
|
2012-02-20 05:24:06 +04:00
|
|
|
return RDP_SCANCODE_TO_X11_KEYCODE[scancode][0];
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
RDP_SCANCODE freerdp_keyboard_get_rdp_scancode_from_virtual_key_code(UINT32 vkcode)
|
2012-02-20 05:24:06 +04:00
|
|
|
{
|
2012-03-29 03:12:35 +04:00
|
|
|
return VIRTUAL_KEY_CODE_TO_DEFAULT_RDP_SCANCODE_TABLE[vkcode];
|
2012-02-19 07:04:28 +04:00
|
|
|
}
|