2 * FreeRDP: A Remote Desktop Protocol Implementation
5 * Copyright 2014 Manuel Bachmann <tarnyko@tarnyko.net>
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 <linux/input.h>
23 #include <freerdp/locale/keyboard.h>
25 #include "wlf_input.h"
27 static void wl_pointer_enter(void* data, struct wl_pointer* pointer, uint32_t serial, struct wl_surface* surface, wl_fixed_t sx_w, wl_fixed_t sy_w)
32 static void wl_pointer_leave(void* data, struct wl_pointer* pointer, uint32_t serial, struct wl_surface* surface)
37 static void wl_pointer_motion(void* data, struct wl_pointer* pointer, uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
39 wlfInput* input_w = data;
44 input = input_w->input;
46 x = (UINT16) wl_fixed_to_int(sx_w);
47 y = (UINT16) wl_fixed_to_int(sy_w);
49 input->MouseEvent(input, PTR_FLAGS_MOVE, x, y);
55 static void wl_pointer_button(void* data, struct wl_pointer* pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
57 wlfInput* input_w = data;
63 input = input_w->input;
65 if (state == WL_POINTER_BUTTON_STATE_PRESSED)
66 flags = PTR_FLAGS_DOWN;
73 flags |= PTR_FLAGS_BUTTON1;
76 flags |= PTR_FLAGS_BUTTON2;
79 flags |= PTR_FLAGS_BUTTON3;
88 input->MouseEvent(input, flags, x, y);
91 static void wl_pointer_axis(void* data, struct wl_pointer* pointer, uint32_t time, uint32_t axis, wl_fixed_t value)
93 wlfInput* input_w = data;
98 input = input_w->input;
100 flags = PTR_FLAGS_WHEEL;
102 if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
104 direction = wl_fixed_to_int(value);
108 flags |= PTR_FLAGS_WHEEL_NEGATIVE | 0x0088;
111 input->MouseEvent(input, flags, 0, 0);
114 static const struct wl_pointer_listener wl_pointer_listener =
123 static void wl_keyboard_keymap(void* data, struct wl_keyboard* keyboard, uint32_t format, int fd, uint32_t size)
128 static void wl_keyboard_enter(void* data, struct wl_keyboard* keyboard, uint32_t serial, struct wl_surface* surface, struct wl_array* keys)
130 wlfInput* input_w = data;
135 input = input_w->input;
140 input->FocusInEvent(input, 0);
141 input->MouseEvent(input, PTR_FLAGS_MOVE, x, y);
144 static void wl_keyboard_leave(void* data, struct wl_keyboard* keyboard, uint32_t serial, struct wl_surface* surface)
149 static void wl_keyboard_key(void* data, struct wl_keyboard* keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
151 wlfInput* input_w = data;
156 input = input_w->input;
158 if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
163 rdp_scancode = (DWORD) key;
165 if (rdp_scancode == RDP_SCANCODE_UNKNOWN)
168 freerdp_input_send_keyboard_event_ex(input, key_down, rdp_scancode);
171 static void wl_keyboard_modifiers(void* data, struct wl_keyboard* keyboard, uint32_t serial, uint32_t mods_depr, uint32_t mods_latch, uint32_t mods_lock, uint32_t group)
176 static const struct wl_keyboard_listener wl_keyboard_listener =
182 wl_keyboard_modifiers
185 static void wl_seat_handle_capabilities(void* data, struct wl_seat* seat, enum wl_seat_capability capabilities)
187 wlfInput* input = data;
188 struct wl_pointer* pointer;
189 struct wl_keyboard* keyboard;
191 if (capabilities & WL_SEAT_CAPABILITY_POINTER)
193 pointer = wl_seat_get_pointer(seat);
195 input->pointer = pointer;
196 wl_pointer_add_listener(pointer, &wl_pointer_listener, input);
199 if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD)
201 keyboard = wl_seat_get_keyboard(seat);
203 input->keyboard = keyboard;
204 wl_keyboard_add_listener(keyboard, &wl_keyboard_listener, input);
209 static const struct wl_seat_listener wl_seat_listener = {
210 wl_seat_handle_capabilities
214 wlfInput* wlf_CreateInput(wlfContext* wlfc)
217 struct wl_seat* seat;
221 if (!wlfc->display->seat)
223 seat = wlfc->display->seat;
225 input = (wlfInput*) calloc(1, sizeof(wlfInput));
229 input->input = wlfc->context.input;
233 wl_seat_add_listener(seat, &wl_seat_listener, input);
239 void wlf_DestroyInput(wlfContext* wlfc, wlfInput* input)
244 if (wlfc->input == input)
248 wl_pointer_release(input->pointer);
250 wl_keyboard_release(input->keyboard);