2
* FreeRDP: A Remote Desktop Protocol Client
5
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7
* Licensed under the Apache License, Version 2.0 (the "License");
8
* you may not use this file except in compliance with the License.
9
* You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
21
#include <freerdp/kbd/kbd.h>
25
void xf_input_synchronize_event(rdpInput* input, uint32 flags)
27
printf("Client sent a synchronize event (flags:0x%X)\n", flags);
30
void xf_input_keyboard_event(rdpInput* input, uint16 flags, uint16 code)
33
boolean extended = false;
34
xfPeerContext* xfp = (xfPeerContext*) input->context;
35
xfInfo* xfi = xfp->info;
37
if (flags & KBD_FLAGS_EXTENDED)
40
keycode = freerdp_kbd_get_keycode_by_scancode(code, extended);
45
pthread_mutex_lock(&(xfp->mutex));
47
if (flags & KBD_FLAGS_DOWN)
48
XTestFakeKeyEvent(xfi->display, keycode, True, 0);
49
else if (flags & KBD_FLAGS_RELEASE)
50
XTestFakeKeyEvent(xfi->display, keycode, False, 0);
52
pthread_mutex_unlock(&(xfp->mutex));
57
void xf_input_unicode_keyboard_event(rdpInput* input, uint16 flags, uint16 code)
59
printf("Client sent a unicode keyboard event (flags:0x%X code:0x%X)\n", flags, code);
62
void xf_input_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
66
xfPeerContext* xfp = (xfPeerContext*) input->context;
67
xfInfo* xfi = xfp->info;
69
pthread_mutex_lock(&(xfp->mutex));
72
if (flags & PTR_FLAGS_WHEEL)
74
boolean negative = false;
76
if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
79
button = (negative) ? 5 : 4;
81
XTestFakeButtonEvent(xfi->display, button, True, 0);
82
XTestFakeButtonEvent(xfi->display, button, False, 0);
86
if (flags & PTR_FLAGS_MOVE)
87
XTestFakeMotionEvent(xfi->display, 0, x, y, 0);
89
if (flags & PTR_FLAGS_BUTTON1)
91
else if (flags & PTR_FLAGS_BUTTON2)
93
else if (flags & PTR_FLAGS_BUTTON3)
96
if (flags & PTR_FLAGS_DOWN)
100
XTestFakeButtonEvent(xfi->display, button, down, 0);
103
pthread_mutex_unlock(&(xfp->mutex));
106
void xf_input_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
108
xfPeerContext* xfp = (xfPeerContext*) input->context;
109
xfInfo* xfi = xfp->info;
111
pthread_mutex_lock(&(xfp->mutex));
113
XTestFakeMotionEvent(xfi->display, 0, x, y, CurrentTime);
115
pthread_mutex_unlock(&(xfp->mutex));
118
void xf_input_register_callbacks(rdpInput* input)
120
input->SynchronizeEvent = xf_input_synchronize_event;
121
input->KeyboardEvent = xf_input_keyboard_event;
122
input->UnicodeKeyboardEvent = xf_input_unicode_keyboard_event;
123
input->MouseEvent = xf_input_mouse_event;
124
input->ExtendedMouseEvent = xf_input_extended_mouse_event;