26 #include "../../SDL_internal.h" 28 #if SDL_VIDEO_DRIVER_MIR 30 #include "../../events/SDL_events_c.h" 31 #include "../../events/SDL_keyboard_c.h" 32 #include "../../events/SDL_touch_c.h" 33 #include "../../events/scancodes_xfree86.h" 38 #include <xkbcommon/xkbcommon.h> 48 size = MIR_xkb_keysym_to_utf8(key_code, text,
sizeof text);
61 if (sdl_window && keyboard_window != sdl_window)
73 xkb_keysym_t key_code;
78 MirKeyboardAction action = MIR_mir_keyboard_event_action(key_event);
81 key_code = MIR_mir_keyboard_event_key_code(key_event);
82 event_scancode = MIR_mir_keyboard_event_scan_code(key_event);
84 if (action == mir_keyboard_action_up)
87 CheckKeyboardFocus(window);
96 HandleKeyText(key_code);
103 MirPointerButton button_state = mir_pointer_button_primary;
105 static uint32_t old_button_states = 0;
106 uint32_t new_button_states = MIR_mir_pointer_event_buttons(pointer);
109 button_state = new_button_states ^ old_button_states;
111 switch (button_state) {
112 case mir_pointer_button_primary:
115 case mir_pointer_button_secondary:
118 case mir_pointer_button_tertiary:
121 case mir_pointer_button_forward:
124 case mir_pointer_button_back:
131 old_button_states = new_button_states;
143 HandleTouchPress(
int device_id,
int source_id,
SDL_bool down,
float x,
float y,
float pressure)
149 HandleTouchMotion(
int device_id,
int source_id,
float x,
float y,
float pressure)
155 HandleMouseScroll(
SDL_Window* sdl_window,
int hscroll,
int vscroll)
161 AddTouchDevice(
int device_id)
164 SDL_SetError(
"Error: can't add touch %s, %d", __FILE__, __LINE__);
168 HandleTouchEvent(MirTouchEvent
const* touch,
int device_id,
SDL_Window* sdl_window)
171 point_count = MIR_mir_touch_event_point_count(touch);
173 AddTouchDevice(device_id);
175 for (i = 0; i < point_count; i++) {
176 int id = MIR_mir_touch_event_id(touch, i);
178 int width = sdl_window->
w;
181 float x = MIR_mir_touch_event_axis_value(touch, i, mir_touch_axis_x);
182 float y = MIR_mir_touch_event_axis_value(touch, i, mir_touch_axis_y);
184 float n_x = x /
width;
187 float pressure = MIR_mir_touch_event_axis_value(touch, i, mir_touch_axis_pressure);
189 switch (MIR_mir_touch_event_action(touch, i)) {
190 case mir_touch_action_up:
191 HandleTouchPress(device_id,
id,
SDL_FALSE, n_x, n_y, pressure);
193 case mir_touch_action_down:
194 HandleTouchPress(device_id,
id,
SDL_TRUE, n_x, n_y, pressure);
196 case mir_touch_action_change:
197 HandleTouchMotion(device_id,
id, n_x, n_y, pressure);
204 HandleMouseEvent(MirPointerEvent
const* pointer,
SDL_Window* sdl_window)
208 switch (MIR_mir_pointer_event_action(pointer)) {
209 case mir_pointer_action_button_down:
210 HandleMouseButton(sdl_window,
SDL_PRESSED, pointer);
212 case mir_pointer_action_button_up:
215 case mir_pointer_action_motion: {
217 int hscroll, vscroll;
219 x = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_x);
220 y = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_y);
221 hscroll = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_hscroll);
222 vscroll = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_vscroll);
224 if (mouse && (mouse->
x != x || mouse->
y != y))
225 HandleMouseMotion(sdl_window, x, y);
226 if (vscroll != 0 || hscroll != 0)
227 HandleMouseScroll(sdl_window, hscroll, vscroll);
230 case mir_pointer_action_leave:
233 case mir_pointer_action_enter:
240 MIR_HandleInput(MirInputEvent
const* input_event,
SDL_Window* window)
242 switch (MIR_mir_input_event_get_type(input_event)) {
243 case (mir_input_event_type_key):
244 HandleKeyEvent(MIR_mir_input_event_get_keyboard_event(input_event), window);
246 case (mir_input_event_type_pointer):
247 HandleMouseEvent(MIR_mir_input_event_get_pointer_event(input_event), window);
249 case (mir_input_event_type_touch):
250 HandleTouchEvent(MIR_mir_input_event_get_touch_event(input_event),
251 MIR_mir_input_event_get_device_id(input_event),
260 MIR_HandleResize(MirResizeEvent
const* resize_event,
SDL_Window* window)
262 int new_w = MIR_mir_resize_event_get_width (resize_event);
263 int new_h = MIR_mir_resize_event_get_height(resize_event);
265 int old_w = window->
w;
266 int old_h = window->
h;
268 if (new_w != old_w || new_h != old_h)
273 MIR_HandleEvent(MirSurface* surface, MirEvent
const* ev,
void* context)
275 MirEventType event_type = MIR_mir_event_get_type(ev);
279 switch (event_type) {
280 case (mir_event_type_input):
281 MIR_HandleInput(MIR_mir_event_get_input_event(ev), window);
283 case (mir_event_type_resize):
284 MIR_HandleResize(MIR_mir_event_get_resize_event(ev), window);
SDL_Mouse * SDL_GetMouse(void)
void SDL_SetKeyboardFocus(SDL_Window *window)
GLint GLint GLsizei width
GLint GLint GLint GLint GLint x
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
static const SDL_Scancode xfree86_scancode_table2[]
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
void SDL_SetMouseFocus(SDL_Window *window)
#define SDL_GetKeyboardFocus
GLint GLint GLsizei GLsizei height
GLsizei const void * pointer
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
GLint GLint GLint GLint GLint GLint y
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
uint8_t Uint8
An unsigned 8-bit integer type.
int SDL_SendKeyboardText(const char *text)
#define SDL_BUTTON_MIDDLE
int SDL_AddTouch(SDL_TouchID touchID, const char *name)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
static char text[MAX_TEXT_LENGTH]
The type used to identify a window.
#define SDL_arraysize(array)
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction)
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
void MIR_HandleEvent(MirSurface *surface, MirEvent const *ev, void *context)