2011-08-07 21:41:54 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-07 21:41:54 +04:00
|
|
|
* X11 Keyboard Handling
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* 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:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-07 21:41:54 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-11-22 06:22:06 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
2014-03-22 22:40:52 +04:00
|
|
|
#include <winpr/path.h>
|
|
|
|
#include <winpr/collections.h>
|
2012-11-22 06:22:06 +04:00
|
|
|
|
2011-08-07 21:41:54 +04:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
|
2012-11-29 10:33:19 +04:00
|
|
|
#include <freerdp/locale/keyboard.h>
|
|
|
|
|
2014-03-23 01:12:50 +04:00
|
|
|
#include "xf_event.h"
|
|
|
|
|
2011-08-07 21:41:54 +04:00
|
|
|
#include "xf_keyboard.h"
|
|
|
|
|
2014-03-22 22:40:52 +04:00
|
|
|
int xf_keyboard_action_script_init(xfContext* xfc)
|
|
|
|
{
|
|
|
|
int exitCode;
|
|
|
|
FILE* keyScript;
|
|
|
|
char* keyCombination;
|
|
|
|
char buffer[1024] = { 0 };
|
|
|
|
char command[1024] = { 0 };
|
|
|
|
|
|
|
|
if (xfc->actionScript)
|
|
|
|
{
|
|
|
|
free(xfc->actionScript);
|
|
|
|
xfc->actionScript = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PathFileExistsA("/usr/share/freerdp/action.sh"))
|
|
|
|
xfc->actionScript = _strdup("/usr/share/freerdp/action.sh");
|
|
|
|
|
|
|
|
if (!xfc->actionScript)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
xfc->keyCombinations = ArrayList_New(TRUE);
|
|
|
|
ArrayList_Object(xfc->keyCombinations)->fnObjectFree = free;
|
|
|
|
|
|
|
|
sprintf_s(command, sizeof(command), "%s key", xfc->actionScript);
|
|
|
|
|
|
|
|
keyScript = popen(command, "r");
|
|
|
|
|
|
|
|
if (keyScript < 0)
|
|
|
|
{
|
|
|
|
free(xfc->actionScript);
|
|
|
|
xfc->actionScript = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (fgets(buffer, sizeof(buffer), keyScript) != NULL)
|
|
|
|
{
|
|
|
|
strtok(buffer, "\n");
|
|
|
|
keyCombination = _strdup(buffer);
|
|
|
|
ArrayList_Add(xfc->keyCombinations, keyCombination);
|
|
|
|
}
|
|
|
|
|
|
|
|
exitCode = pclose(keyScript);
|
|
|
|
|
2014-03-23 01:12:50 +04:00
|
|
|
xf_event_action_script_init(xfc);
|
|
|
|
|
2014-03-22 22:40:52 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_keyboard_action_script_free(xfContext* xfc)
|
|
|
|
{
|
2014-03-23 01:12:50 +04:00
|
|
|
xf_event_action_script_free(xfc);
|
|
|
|
|
2014-03-22 22:40:52 +04:00
|
|
|
if (xfc->keyCombinations)
|
|
|
|
{
|
|
|
|
ArrayList_Free(xfc->keyCombinations);
|
|
|
|
xfc->keyCombinations = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xfc->actionScript)
|
|
|
|
{
|
|
|
|
free(xfc->actionScript);
|
|
|
|
xfc->actionScript = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
void xf_keyboard_init(xfContext* xfc)
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
2014-03-14 05:10:22 +04:00
|
|
|
xf_keyboard_clear(xfc);
|
2013-11-01 07:35:24 +04:00
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
xfc->KeyboardLayout = xfc->instance->settings->KeyboardLayout;
|
|
|
|
xfc->KeyboardLayout = freerdp_keyboard_init(xfc->KeyboardLayout);
|
|
|
|
xfc->instance->settings->KeyboardLayout = xfc->KeyboardLayout;
|
2013-11-01 07:35:24 +04:00
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
if (xfc->modifierMap)
|
|
|
|
XFreeModifiermap(xfc->modifierMap);
|
2013-11-01 07:35:24 +04:00
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
xfc->modifierMap = XGetModifierMapping(xfc->display);
|
2014-03-22 22:40:52 +04:00
|
|
|
|
|
|
|
xf_keyboard_action_script_init(xfc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_keyboard_free(xfContext* xfc)
|
|
|
|
{
|
|
|
|
if (xfc->modifierMap)
|
|
|
|
{
|
|
|
|
XFreeModifiermap(xfc->modifierMap);
|
|
|
|
xfc->modifierMap = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
xf_keyboard_action_script_free(xfc);
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
void xf_keyboard_clear(xfContext* xfc)
|
2012-08-03 00:45:03 +04:00
|
|
|
{
|
2014-03-14 05:10:22 +04:00
|
|
|
ZeroMemory(xfc->KeyboardState, 256 * sizeof(BOOL));
|
2012-08-03 00:45:03 +04:00
|
|
|
}
|
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
void xf_keyboard_key_press(xfContext* xfc, BYTE keycode, KeySym keysym)
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
2014-03-14 05:10:22 +04:00
|
|
|
if (keycode < 8)
|
2011-08-07 21:41:54 +04:00
|
|
|
return;
|
2014-03-14 05:10:22 +04:00
|
|
|
|
|
|
|
xfc->KeyboardState[keycode] = keysym;
|
2014-03-14 08:11:44 +04:00
|
|
|
|
|
|
|
if (xf_keyboard_handle_special_keys(xfc, keysym))
|
|
|
|
return;
|
|
|
|
|
|
|
|
xf_keyboard_send_key(xfc, TRUE, keycode);
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
void xf_keyboard_key_release(xfContext* xfc, BYTE keycode)
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
2014-03-14 05:10:22 +04:00
|
|
|
if (keycode < 8)
|
2011-08-07 21:41:54 +04:00
|
|
|
return;
|
2014-03-14 05:10:22 +04:00
|
|
|
|
|
|
|
xfc->KeyboardState[keycode] = NoSymbol;
|
2014-03-14 08:11:44 +04:00
|
|
|
|
|
|
|
xf_keyboard_send_key(xfc, FALSE, keycode);
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
void xf_keyboard_release_all_keypress(xfContext* xfc)
|
2012-04-11 08:37:47 +04:00
|
|
|
{
|
|
|
|
int keycode;
|
2013-03-06 21:50:25 +04:00
|
|
|
DWORD rdp_scancode;
|
2012-04-11 08:37:47 +04:00
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
for (keycode = 0; keycode < ARRAYSIZE(xfc->KeyboardState); keycode++)
|
2012-04-11 08:37:47 +04:00
|
|
|
{
|
2014-03-14 05:10:22 +04:00
|
|
|
if (xfc->KeyboardState[keycode] != NoSymbol)
|
2012-04-11 08:37:47 +04:00
|
|
|
{
|
|
|
|
rdp_scancode = freerdp_keyboard_get_rdp_scancode_from_x11_keycode(keycode);
|
2013-06-13 02:57:25 +04:00
|
|
|
freerdp_input_send_keyboard_event_ex(xfc->instance->input, FALSE, rdp_scancode);
|
2014-03-14 05:10:22 +04:00
|
|
|
xfc->KeyboardState[keycode] = NoSymbol;
|
2012-04-11 08:37:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
BOOL xf_keyboard_key_pressed(xfContext* xfc, KeySym keysym)
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
KeyCode keycode = XKeysymToKeycode(xfc->display, keysym);
|
2014-03-14 05:10:22 +04:00
|
|
|
return (xfc->KeyboardState[keycode] == keysym);
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
void xf_keyboard_send_key(xfContext* xfc, BOOL down, BYTE keycode)
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
2013-03-06 21:50:25 +04:00
|
|
|
DWORD rdp_scancode;
|
2011-08-07 21:41:54 +04:00
|
|
|
rdpInput* input;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
input = xfc->instance->input;
|
2012-03-29 03:12:35 +04:00
|
|
|
rdp_scancode = freerdp_keyboard_get_rdp_scancode_from_x11_keycode(keycode);
|
2011-08-07 21:41:54 +04:00
|
|
|
|
2012-03-29 03:12:48 +04:00
|
|
|
if (rdp_scancode == RDP_SCANCODE_UNKNOWN)
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Unknown key with X keycode 0x%02x\n", keycode);
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
2012-03-29 03:12:48 +04:00
|
|
|
else if (rdp_scancode == RDP_SCANCODE_PAUSE &&
|
2014-03-14 05:10:22 +04:00
|
|
|
!xf_keyboard_key_pressed(xfc, XK_Control_L) && !xf_keyboard_key_pressed(xfc, XK_Control_R))
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
|
|
|
/* Pause without Ctrl has to be sent as Ctrl + NumLock. */
|
|
|
|
if (down)
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
freerdp_input_send_keyboard_event_ex(input, TRUE, RDP_SCANCODE_LCONTROL);
|
|
|
|
freerdp_input_send_keyboard_event_ex(input, TRUE, RDP_SCANCODE_NUMLOCK);
|
|
|
|
freerdp_input_send_keyboard_event_ex(input, FALSE, RDP_SCANCODE_LCONTROL);
|
|
|
|
freerdp_input_send_keyboard_event_ex(input, FALSE, RDP_SCANCODE_NUMLOCK);
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-22 22:27:30 +04:00
|
|
|
freerdp_input_send_keyboard_event_ex(input, down, rdp_scancode);
|
2011-08-07 21:41:54 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
if ((rdp_scancode == RDP_SCANCODE_CAPSLOCK) && (down == FALSE))
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 syncFlags;
|
2014-03-14 05:10:22 +04:00
|
|
|
syncFlags = xf_keyboard_get_toggle_keys_state(xfc);
|
2011-08-07 21:41:54 +04:00
|
|
|
input->SynchronizeEvent(input, syncFlags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
int xf_keyboard_read_keyboard_state(xfContext* xfc)
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
|
|
|
int dummy;
|
|
|
|
Window wdummy;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 state = 0;
|
2011-08-07 21:41:54 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (!xfc->remote_app)
|
2011-08-18 09:16:49 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XQueryPointer(xfc->display, xfc->window->handle,
|
2011-08-07 21:41:54 +04:00
|
|
|
&wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state);
|
2011-08-18 09:16:49 +04:00
|
|
|
}
|
2012-02-28 03:04:11 +04:00
|
|
|
else
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XQueryPointer(xfc->display, DefaultRootWindow(xfc->display),
|
2012-02-28 03:04:11 +04:00
|
|
|
&wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state);
|
|
|
|
}
|
2014-03-14 05:10:22 +04:00
|
|
|
|
2011-08-07 21:41:54 +04:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
BOOL xf_keyboard_get_key_state(xfContext* xfc, int state, int keysym)
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
int modifierpos, key, keysymMask = 0;
|
2013-06-13 02:57:25 +04:00
|
|
|
KeyCode keycode = XKeysymToKeycode(xfc->display, keysym);
|
2011-08-07 21:41:54 +04:00
|
|
|
|
|
|
|
if (keycode == NoSymbol)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-07 21:41:54 +04:00
|
|
|
|
|
|
|
for (modifierpos = 0; modifierpos < 8; modifierpos++)
|
|
|
|
{
|
2014-03-14 05:10:22 +04:00
|
|
|
offset = xfc->modifierMap->max_keypermod * modifierpos;
|
2013-02-10 22:17:08 +04:00
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
for (key = 0; key < xfc->modifierMap->max_keypermod; key++)
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
2014-03-14 05:10:22 +04:00
|
|
|
if (xfc->modifierMap->modifiermap[offset + key] == keycode)
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
|
|
|
keysymMask |= 1 << modifierpos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return (state & keysymMask) ? TRUE : FALSE;
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
UINT32 xf_keyboard_get_toggle_keys_state(xfContext* xfc)
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
|
|
|
int state;
|
2014-03-14 05:10:22 +04:00
|
|
|
UINT32 toggleKeysState = 0;
|
2011-08-07 21:41:54 +04:00
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
state = xf_keyboard_read_keyboard_state(xfc);
|
2013-02-12 05:38:19 +04:00
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
if (xf_keyboard_get_key_state(xfc, state, XK_Scroll_Lock))
|
|
|
|
toggleKeysState |= KBD_SYNC_SCROLL_LOCK;
|
|
|
|
if (xf_keyboard_get_key_state(xfc, state, XK_Num_Lock))
|
|
|
|
toggleKeysState |= KBD_SYNC_NUM_LOCK;
|
|
|
|
if (xf_keyboard_get_key_state(xfc, state, XK_Caps_Lock))
|
|
|
|
toggleKeysState |= KBD_SYNC_CAPS_LOCK;
|
|
|
|
if (xf_keyboard_get_key_state(xfc, state, XK_Kana_Lock))
|
|
|
|
toggleKeysState |= KBD_SYNC_KANA_LOCK;
|
2011-08-07 21:41:54 +04:00
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
return toggleKeysState;
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
void xf_keyboard_focus_in(xfContext* xfc)
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
|
|
|
rdpInput* input;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 syncFlags;
|
2013-04-15 14:14:09 +04:00
|
|
|
int dummy, mouseX, mouseY;
|
|
|
|
Window wdummy;
|
|
|
|
UINT32 state = 0;
|
2011-08-07 21:41:54 +04:00
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
if (xfc->display && xfc->window)
|
|
|
|
{
|
|
|
|
input = xfc->instance->input;
|
|
|
|
syncFlags = xf_keyboard_get_toggle_keys_state(xfc);
|
|
|
|
XQueryPointer(xfc->display, xfc->window->handle, &wdummy, &wdummy, &mouseX, &mouseY, &dummy, &dummy, &state);
|
|
|
|
input->FocusInEvent(input, syncFlags, mouseX, mouseY);
|
2013-05-15 12:42:21 +04:00
|
|
|
}
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
|
|
|
|
2014-03-14 08:11:44 +04:00
|
|
|
int xf_keyboard_execute_action_script(xfContext* xfc, XF_MODIFIER_KEYS* mod, KeySym keysym)
|
|
|
|
{
|
2014-03-22 22:40:52 +04:00
|
|
|
int index;
|
|
|
|
int count;
|
2014-03-14 08:11:44 +04:00
|
|
|
int exitCode;
|
|
|
|
int status = 1;
|
|
|
|
FILE* keyScript;
|
|
|
|
const char* keyStr;
|
2014-03-22 22:40:52 +04:00
|
|
|
BOOL match = FALSE;
|
|
|
|
char* keyCombination;
|
|
|
|
char buffer[1024] = { 0 };
|
|
|
|
char command[1024] = { 0 };
|
|
|
|
char combination[1024] = { 0 };
|
|
|
|
|
|
|
|
if (!xfc->actionScript)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if ((keysym == XK_Shift_L) || (keysym == XK_Shift_R) ||
|
|
|
|
(keysym == XK_Alt_L) || (keysym == XK_Alt_R) ||
|
2014-03-25 20:27:06 +04:00
|
|
|
(keysym == XK_Control_L) || (keysym == XK_Control_R))
|
2014-03-22 22:40:52 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2014-03-14 08:11:44 +04:00
|
|
|
|
|
|
|
keyStr = XKeysymToString(keysym);
|
|
|
|
|
|
|
|
if (mod->Shift)
|
2014-03-22 22:40:52 +04:00
|
|
|
strcat(combination, "Shift+");
|
2014-03-14 08:11:44 +04:00
|
|
|
|
|
|
|
if (mod->Ctrl)
|
2014-03-22 22:40:52 +04:00
|
|
|
strcat(combination, "Ctrl+");
|
2014-03-14 08:11:44 +04:00
|
|
|
|
|
|
|
if (mod->Alt)
|
2014-03-22 22:40:52 +04:00
|
|
|
strcat(combination, "Alt+");
|
2014-03-14 08:11:44 +04:00
|
|
|
|
2014-03-22 22:40:52 +04:00
|
|
|
strcat(combination, keyStr);
|
|
|
|
|
|
|
|
count = ArrayList_Count(xfc->keyCombinations);
|
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
|
|
|
{
|
|
|
|
keyCombination = (char*) ArrayList_GetItem(xfc->keyCombinations, index);
|
|
|
|
|
|
|
|
if (_stricmp(keyCombination, combination) == 0)
|
|
|
|
{
|
|
|
|
match = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!match)
|
2014-03-23 01:12:50 +04:00
|
|
|
return 1;
|
2014-03-14 08:11:44 +04:00
|
|
|
|
2014-03-22 22:40:52 +04:00
|
|
|
sprintf_s(command, sizeof(command), "%s key %s",
|
|
|
|
xfc->actionScript, combination);
|
2014-03-14 08:11:44 +04:00
|
|
|
|
|
|
|
keyScript = popen(command, "r");
|
|
|
|
|
|
|
|
if (keyScript < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
while (fgets(buffer, sizeof(buffer), keyScript) != NULL)
|
|
|
|
{
|
|
|
|
strtok(buffer, "\n");
|
|
|
|
|
|
|
|
if (strcmp(buffer, "key-local") == 0)
|
|
|
|
status = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
exitCode = pclose(keyScript);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xk_keyboard_get_modifier_keys(xfContext* xfc, XF_MODIFIER_KEYS* mod)
|
|
|
|
{
|
|
|
|
mod->LeftShift = xf_keyboard_key_pressed(xfc, XK_Shift_L);
|
|
|
|
mod->RightShift = xf_keyboard_key_pressed(xfc, XK_Shift_R);
|
|
|
|
mod->Shift = mod->LeftShift || mod->RightShift;
|
|
|
|
|
|
|
|
mod->LeftAlt = xf_keyboard_key_pressed(xfc, XK_Alt_L);
|
|
|
|
mod->RightAlt = xf_keyboard_key_pressed(xfc, XK_Alt_R);
|
|
|
|
mod->Alt = mod->LeftAlt || mod->RightAlt;
|
|
|
|
|
|
|
|
mod->LeftCtrl = xf_keyboard_key_pressed(xfc, XK_Control_L);
|
|
|
|
mod->RightCtrl = xf_keyboard_key_pressed(xfc, XK_Control_R);
|
|
|
|
mod->Ctrl = mod->LeftCtrl || mod->RightCtrl;
|
|
|
|
|
|
|
|
mod->LeftSuper = xf_keyboard_key_pressed(xfc, XK_Super_L);
|
|
|
|
mod->RightSuper = xf_keyboard_key_pressed(xfc, XK_Super_R);
|
|
|
|
mod->Super = mod->LeftSuper || mod->RightSuper;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-14 05:10:22 +04:00
|
|
|
BOOL xf_keyboard_handle_special_keys(xfContext* xfc, KeySym keysym)
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
2014-03-14 08:11:44 +04:00
|
|
|
XF_MODIFIER_KEYS mod = { 0 };
|
|
|
|
|
|
|
|
xk_keyboard_get_modifier_keys(xfc, &mod);
|
|
|
|
|
|
|
|
if (!xf_keyboard_execute_action_script(xfc, &mod, keysym))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-08-07 21:41:54 +04:00
|
|
|
if (keysym == XK_Return)
|
|
|
|
{
|
2014-03-14 08:11:44 +04:00
|
|
|
if (mod.Ctrl && mod.Alt)
|
2011-08-07 21:41:54 +04:00
|
|
|
{
|
|
|
|
/* Ctrl-Alt-Enter: toggle full screen */
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_toggle_fullscreen(xfc);
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
|
|
|
}
|
2014-03-14 05:10:22 +04:00
|
|
|
|
2013-05-05 05:23:24 +04:00
|
|
|
if (keysym == XK_period)
|
|
|
|
{
|
2014-03-14 08:11:44 +04:00
|
|
|
if (mod.Ctrl && mod.Alt)
|
2013-05-30 17:27:20 +04:00
|
|
|
{
|
2014-03-14 05:10:22 +04:00
|
|
|
/* Zoom In (scale larger) */
|
|
|
|
|
2013-06-27 22:24:46 +04:00
|
|
|
double s = xfc->settings->ScalingFactor;
|
2014-03-14 05:10:22 +04:00
|
|
|
|
2013-05-30 17:27:20 +04:00
|
|
|
s += 0.1;
|
2014-03-14 05:10:22 +04:00
|
|
|
|
2013-05-30 17:27:20 +04:00
|
|
|
if (s > 2.0)
|
|
|
|
s = 2.0;
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 22:24:46 +04:00
|
|
|
xfc->settings->ScalingFactor = s;
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
xfc->currentWidth = xfc->originalWidth * s;
|
|
|
|
xfc->currentHeight = xfc->originalHeight * s;
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
xf_transform_window(xfc);
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
{
|
|
|
|
ResizeWindowEventArgs e;
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2013-06-27 22:24:46 +04:00
|
|
|
e.width = (int) xfc->originalWidth * xfc->settings->ScalingFactor;
|
|
|
|
e.height = (int) xfc->originalHeight * xfc->settings->ScalingFactor;
|
2013-06-27 03:16:28 +04:00
|
|
|
PubSub_OnResizeWindow(((rdpContext*) xfc)->pubSub, xfc, &e);
|
|
|
|
}
|
|
|
|
xf_draw_screen_scaled(xfc, 0, 0, 0, 0, FALSE);
|
2013-05-30 17:27:20 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2013-05-05 05:23:24 +04:00
|
|
|
}
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-05-05 05:23:24 +04:00
|
|
|
if (keysym == XK_comma)
|
|
|
|
{
|
2014-03-14 08:11:44 +04:00
|
|
|
if (mod.Ctrl && mod.Alt)
|
2013-05-30 17:27:20 +04:00
|
|
|
{
|
2014-03-14 05:10:22 +04:00
|
|
|
/* Zoom Out (scale smaller) */
|
|
|
|
|
2013-06-27 22:24:46 +04:00
|
|
|
double s = xfc->settings->ScalingFactor;
|
2014-03-14 05:10:22 +04:00
|
|
|
|
2013-05-30 17:27:20 +04:00
|
|
|
s -= 0.1;
|
2014-03-14 05:10:22 +04:00
|
|
|
|
2013-05-30 17:27:20 +04:00
|
|
|
if (s < 0.5)
|
|
|
|
s = 0.5;
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 22:24:46 +04:00
|
|
|
xfc->settings->ScalingFactor = s;
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
xfc->currentWidth = xfc->originalWidth * s;
|
|
|
|
xfc->currentHeight = xfc->originalHeight * s;
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
xf_transform_window(xfc);
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
{
|
|
|
|
ResizeWindowEventArgs e;
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2013-06-27 22:24:46 +04:00
|
|
|
e.width = (int) xfc->originalWidth * xfc->settings->ScalingFactor;
|
|
|
|
e.height = (int) xfc->originalHeight * xfc->settings->ScalingFactor;
|
2013-06-27 03:16:28 +04:00
|
|
|
PubSub_OnResizeWindow(((rdpContext*) xfc)->pubSub, xfc, &e);
|
|
|
|
}
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
xf_draw_screen_scaled(xfc, 0, 0, 0, 0, FALSE);
|
2013-05-30 17:27:20 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-05-14 02:29:55 +04:00
|
|
|
if (keysym == XK_KP_4)
|
2013-05-15 00:18:57 +04:00
|
|
|
{
|
2014-03-14 08:11:44 +04:00
|
|
|
if (mod.Ctrl && mod.Alt)
|
2013-05-30 17:27:20 +04:00
|
|
|
{
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
{
|
2013-06-27 11:59:49 +04:00
|
|
|
PanningChangeEventArgs e;
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2013-06-27 11:59:49 +04:00
|
|
|
e.XPan = -5;
|
|
|
|
e.YPan = 0;
|
|
|
|
PubSub_OnPanningChange(((rdpContext*) xfc)->pubSub, xfc, &e);
|
2013-06-27 03:16:28 +04:00
|
|
|
}
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-05-30 17:27:20 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2013-05-15 00:18:57 +04:00
|
|
|
}
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-05-14 02:29:55 +04:00
|
|
|
if (keysym == XK_KP_6)
|
2013-05-15 00:18:57 +04:00
|
|
|
{
|
2014-03-14 08:11:44 +04:00
|
|
|
if (mod.Ctrl && mod.Alt)
|
2013-05-30 17:27:20 +04:00
|
|
|
{
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
{
|
2013-06-27 11:59:49 +04:00
|
|
|
PanningChangeEventArgs e;
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2013-06-27 11:59:49 +04:00
|
|
|
e.XPan = 5;
|
|
|
|
e.YPan = 0;
|
|
|
|
PubSub_OnPanningChange(((rdpContext*) xfc)->pubSub, xfc, &e);
|
2013-06-27 03:16:28 +04:00
|
|
|
}
|
2013-05-30 17:27:20 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2013-05-15 00:18:57 +04:00
|
|
|
}
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-05-14 02:29:55 +04:00
|
|
|
if (keysym == XK_KP_8)
|
2013-05-15 00:18:57 +04:00
|
|
|
{
|
2014-03-14 08:11:44 +04:00
|
|
|
if (mod.Ctrl && mod.Alt)
|
2013-05-30 17:27:20 +04:00
|
|
|
{
|
2013-06-27 03:16:28 +04:00
|
|
|
{
|
2013-06-27 11:59:49 +04:00
|
|
|
PanningChangeEventArgs e;
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2013-06-27 11:59:49 +04:00
|
|
|
e.XPan = 0;
|
|
|
|
e.YPan = -5;
|
|
|
|
PubSub_OnPanningChange(((rdpContext*) xfc)->pubSub, xfc, &e);
|
2013-06-27 03:16:28 +04:00
|
|
|
}
|
2013-05-30 17:27:20 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2013-05-15 00:18:57 +04:00
|
|
|
}
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-05-14 02:29:55 +04:00
|
|
|
if (keysym == XK_KP_2)
|
2013-05-15 00:18:57 +04:00
|
|
|
{
|
2014-03-14 08:11:44 +04:00
|
|
|
if (mod.Ctrl && mod.Alt)
|
2013-05-30 17:27:20 +04:00
|
|
|
{
|
2013-06-27 03:16:28 +04:00
|
|
|
{
|
2013-06-27 11:59:49 +04:00
|
|
|
PanningChangeEventArgs e;
|
2013-07-23 22:47:40 +04:00
|
|
|
|
2013-06-27 03:16:28 +04:00
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2013-06-27 11:59:49 +04:00
|
|
|
e.XPan = 0;
|
|
|
|
e.YPan = 5;
|
|
|
|
PubSub_OnPanningChange(((rdpContext*) xfc)->pubSub, xfc, &e);
|
2013-06-27 03:16:28 +04:00
|
|
|
}
|
2013-05-30 17:27:20 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2013-05-15 00:18:57 +04:00
|
|
|
}
|
2013-06-11 03:52:16 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
|
|
|
|