2012-01-31 06:35:15 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2012-01-31 06:35:15 +04:00
|
|
|
* X11 Server Input
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2012-01-31 06:35:15 +04:00
|
|
|
#include <X11/Xlib.h>
|
2012-08-15 01:20:53 +04:00
|
|
|
|
2012-02-18 02:43:00 +04:00
|
|
|
#include <freerdp/locale/keyboard.h>
|
2012-01-31 06:35:15 +04:00
|
|
|
|
2013-05-02 09:34:54 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/input.h>
|
|
|
|
|
2013-02-17 20:59:29 +04:00
|
|
|
#include "xf_peer.h"
|
|
|
|
|
2012-01-31 06:35:15 +04:00
|
|
|
#include "xf_input.h"
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
void xf_input_synchronize_event(rdpInput* input, UINT32 flags)
|
2012-01-31 06:35:15 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Client sent a synchronize event (flags:0x%X)\n", flags);
|
2012-01-31 06:35:15 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void xf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
2012-01-31 06:35:15 +04:00
|
|
|
{
|
2012-03-29 03:10:58 +04:00
|
|
|
#ifdef WITH_XTEST
|
2013-05-02 09:34:54 +04:00
|
|
|
DWORD vkcode;
|
|
|
|
DWORD keycode;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL extended = FALSE;
|
2012-01-31 06:35:15 +04:00
|
|
|
xfPeerContext* xfp = (xfPeerContext*) input->context;
|
|
|
|
xfInfo* xfi = xfp->info;
|
|
|
|
|
|
|
|
if (flags & KBD_FLAGS_EXTENDED)
|
2012-10-09 10:31:28 +04:00
|
|
|
extended = TRUE;
|
2012-01-31 06:35:15 +04:00
|
|
|
|
2013-05-02 09:34:54 +04:00
|
|
|
if (extended)
|
|
|
|
code |= KBDEXT;
|
|
|
|
|
|
|
|
vkcode = GetVirtualKeyCodeFromVirtualScanCode(code, 4);
|
|
|
|
keycode = GetKeycodeFromVirtualKeyCode(vkcode, KEYCODE_TYPE_EVDEV);
|
2012-01-31 06:35:15 +04:00
|
|
|
|
|
|
|
if (keycode != 0)
|
|
|
|
{
|
2012-03-18 21:13:34 +04:00
|
|
|
XTestGrabControl(xfi->display, True);
|
|
|
|
|
2012-01-31 06:35:15 +04:00
|
|
|
if (flags & KBD_FLAGS_DOWN)
|
|
|
|
XTestFakeKeyEvent(xfi->display, keycode, True, 0);
|
|
|
|
else if (flags & KBD_FLAGS_RELEASE)
|
|
|
|
XTestFakeKeyEvent(xfi->display, keycode, False, 0);
|
|
|
|
|
2012-03-18 21:13:34 +04:00
|
|
|
XTestGrabControl(xfi->display, False);
|
2012-01-31 06:35:15 +04:00
|
|
|
}
|
2012-03-29 03:10:58 +04:00
|
|
|
#endif
|
2012-01-31 06:35:15 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void xf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
|
2012-01-31 06:35:15 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Client sent a unicode keyboard event (flags:0x%X code:0x%X)\n", flags, code);
|
2012-01-31 06:35:15 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void xf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
2012-01-31 06:35:15 +04:00
|
|
|
{
|
2012-03-29 03:10:58 +04:00
|
|
|
#ifdef WITH_XTEST
|
|
|
|
xfPeerContext* xfp = (xfPeerContext*) input->context;
|
2012-01-31 06:35:15 +04:00
|
|
|
int button = 0;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL down = FALSE;
|
2012-01-31 06:35:15 +04:00
|
|
|
xfInfo* xfi = xfp->info;
|
|
|
|
|
2012-03-18 21:13:34 +04:00
|
|
|
XTestGrabControl(xfi->display, True);
|
2012-01-31 06:35:15 +04:00
|
|
|
|
|
|
|
if (flags & PTR_FLAGS_WHEEL)
|
|
|
|
{
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL negative = FALSE;
|
2012-01-31 06:35:15 +04:00
|
|
|
|
|
|
|
if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
|
2012-10-09 10:31:28 +04:00
|
|
|
negative = TRUE;
|
2012-01-31 06:35:15 +04:00
|
|
|
|
|
|
|
button = (negative) ? 5 : 4;
|
|
|
|
|
|
|
|
XTestFakeButtonEvent(xfi->display, button, True, 0);
|
|
|
|
XTestFakeButtonEvent(xfi->display, button, False, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (flags & PTR_FLAGS_MOVE)
|
|
|
|
XTestFakeMotionEvent(xfi->display, 0, x, y, 0);
|
|
|
|
|
|
|
|
if (flags & PTR_FLAGS_BUTTON1)
|
|
|
|
button = 1;
|
|
|
|
else if (flags & PTR_FLAGS_BUTTON2)
|
|
|
|
button = 3;
|
|
|
|
else if (flags & PTR_FLAGS_BUTTON3)
|
|
|
|
button = 2;
|
|
|
|
|
|
|
|
if (flags & PTR_FLAGS_DOWN)
|
2012-10-09 10:31:28 +04:00
|
|
|
down = TRUE;
|
2012-01-31 06:35:15 +04:00
|
|
|
|
|
|
|
if (button != 0)
|
|
|
|
XTestFakeButtonEvent(xfi->display, button, down, 0);
|
|
|
|
}
|
2012-03-18 21:13:34 +04:00
|
|
|
|
|
|
|
XTestGrabControl(xfi->display, False);
|
2012-03-29 03:10:58 +04:00
|
|
|
#endif
|
2012-01-31 06:35:15 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void xf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
|
2012-01-31 06:35:15 +04:00
|
|
|
{
|
2012-03-29 03:10:58 +04:00
|
|
|
#ifdef WITH_XTEST
|
2012-01-31 06:35:15 +04:00
|
|
|
xfPeerContext* xfp = (xfPeerContext*) input->context;
|
|
|
|
xfInfo* xfi = xfp->info;
|
|
|
|
|
2012-03-18 21:13:34 +04:00
|
|
|
XTestGrabControl(xfi->display, True);
|
2012-01-31 06:35:15 +04:00
|
|
|
XTestFakeMotionEvent(xfi->display, 0, x, y, CurrentTime);
|
2012-03-18 21:13:34 +04:00
|
|
|
XTestGrabControl(xfi->display, False);
|
2012-03-29 03:10:58 +04:00
|
|
|
#endif
|
2012-01-31 06:35:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void xf_input_register_callbacks(rdpInput* input)
|
|
|
|
{
|
|
|
|
input->SynchronizeEvent = xf_input_synchronize_event;
|
|
|
|
input->KeyboardEvent = xf_input_keyboard_event;
|
|
|
|
input->UnicodeKeyboardEvent = xf_input_unicode_keyboard_event;
|
|
|
|
input->MouseEvent = xf_input_mouse_event;
|
|
|
|
input->ExtendedMouseEvent = xf_input_extended_mouse_event;
|
|
|
|
}
|