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);
63 xkb_keysym_t key_code;
68 MirKeyboardAction action = MIR_mir_keyboard_event_action(key_event);
71 key_code = MIR_mir_keyboard_event_key_code(key_event);
72 event_scancode = MIR_mir_keyboard_event_scan_code(key_event);
74 if (action == mir_keyboard_action_up)
84 HandleKeyText(key_code);
91 MirPointerButton button_state = mir_pointer_button_primary;
93 static uint32_t old_button_states = 0;
94 uint32_t new_button_states = MIR_mir_pointer_event_buttons(pointer);
97 button_state = new_button_states ^ old_button_states;
99 switch (button_state) {
100 case mir_pointer_button_primary:
103 case mir_pointer_button_secondary:
106 case mir_pointer_button_tertiary:
109 case mir_pointer_button_forward:
112 case mir_pointer_button_back:
119 old_button_states = new_button_states;
132 HandleTouchPress(
int device_id,
int source_id,
SDL_bool down,
float x,
float y,
float pressure)
138 HandleTouchMotion(
int device_id,
int source_id,
float x,
float y,
float pressure)
144 HandleMouseScroll(
SDL_Window* sdl_window,
float hscroll,
float vscroll)
150 AddTouchDevice(
int device_id)
153 SDL_SetError(
"Error: can't add touch %s, %d", __FILE__, __LINE__);
157 HandleTouchEvent(MirTouchEvent
const* touch,
int device_id,
SDL_Window* sdl_window)
160 point_count = MIR_mir_touch_event_point_count(touch);
162 AddTouchDevice(device_id);
164 for (i = 0; i < point_count; i++) {
165 int id = MIR_mir_touch_event_id(touch, i);
167 int width = sdl_window->
w;
170 float x = MIR_mir_touch_event_axis_value(touch, i, mir_touch_axis_x);
171 float y = MIR_mir_touch_event_axis_value(touch, i, mir_touch_axis_y);
173 float n_x = x /
width;
176 float pressure = MIR_mir_touch_event_axis_value(touch, i, mir_touch_axis_pressure);
178 switch (MIR_mir_touch_event_action(touch, i)) {
179 case mir_touch_action_up:
180 HandleTouchPress(device_id,
id,
SDL_FALSE, n_x, n_y, pressure);
182 case mir_touch_action_down:
183 HandleTouchPress(device_id,
id,
SDL_TRUE, n_x, n_y, pressure);
185 case mir_touch_action_change:
186 HandleTouchMotion(device_id,
id, n_x, n_y, pressure);
188 case mir_touch_actions:
195 HandleMouseEvent(MirPointerEvent
const* pointer,
SDL_Window* sdl_window)
199 switch (MIR_mir_pointer_event_action(pointer)) {
200 case mir_pointer_action_button_down:
201 HandleMouseButton(sdl_window,
SDL_PRESSED, pointer);
203 case mir_pointer_action_button_up:
206 case mir_pointer_action_motion: {
208 float hscroll, vscroll;
210 x = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_x);
211 y = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_y);
215 int relative_x = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_relative_x);
216 int relative_y = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_relative_y);
217 HandleMouseMotion(sdl_window, relative_x, relative_y);
219 else if (mouse->
x != x || mouse->
y != y) {
220 HandleMouseMotion(sdl_window, x, y);
224 hscroll = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_hscroll);
225 vscroll = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_vscroll);
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 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 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)
275 MirWindowAttrib attrib = MIR_mir_window_event_get_attribute(event);
276 int value = MIR_mir_window_event_get_attribute_value(event);
278 if (attrib == mir_window_attrib_focus) {
279 if (value == mir_window_focus_state_focused) {
282 else if (value == mir_window_focus_state_unfocused) {
296 MirEventType event_type = MIR_mir_event_get_type(ev);
300 switch (event_type) {
301 case (mir_event_type_input):
302 HandleInput(MIR_mir_event_get_input_event(ev), window);
304 case (mir_event_type_resize):
305 HandleResize(MIR_mir_event_get_resize_event(ev), window);
307 case (mir_event_type_window):
308 HandleWindow(MIR_mir_event_get_window_event(ev), window);
310 case (mir_event_type_close_window):
311 MIR_HandleClose(window);
SDL_Mouse * SDL_GetMouse(void)
void SDL_SetKeyboardFocus(SDL_Window *window)
GLint GLint GLint GLint GLint x
static screen_context_t context
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)
void MIR_HandleEvent(MirWindow *, MirEvent const *ev, void *context)
GLint GLint GLsizei width
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
int SDL_SendKeyboardText(const char *text)
GLsizei const GLfloat * value
#define SDL_BUTTON_MIDDLE
GLint GLint GLint GLint GLint GLint y
GLsizei const void * pointer
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)
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
static char text[MAX_TEXT_LENGTH]
GLint GLint GLsizei GLsizei height
EGLSurface EGLNativeWindowType * window
The type used to identify a window.
#define SDL_arraysize(array)
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)