1 /* RetroArch - A frontend for libretro. 2 * Copyright (C) 2011-2017 - Daniel De Matteis 3 * 4 * RetroArch is free software: you can redistribute it and/or modify it under the terms 5 * of the GNU General Public License as published by the Free Software Found- 6 * ation, either version 3 of the License, or (at your option) any later version. 7 * 8 * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 10 * PURPOSE. See the GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License along with RetroArch. 13 * If not, see <http://www.gnu.org/licenses/>. 14 */ 15 16 #ifndef WAYLAND_INPUT_COMMON_H__ 17 #define WAYLAND_INPUT_COMMON_H__ 18 19 #include <stdint.h> 20 #include <boolean.h> 21 22 #include <linux/input.h> 23 #include <wayland-client.h> 24 #include <wayland-cursor.h> 25 26 #include "../input_driver.h" 27 28 #ifdef HAVE_EGL 29 #include "../../gfx/common/egl_common.h" 30 #endif 31 32 #ifdef HAVE_VULKAN 33 #include "../../gfx/common/vulkan_common.h" 34 #endif 35 36 /* Generated from idle-inhibit-unstable-v1.xml */ 37 #include "../../gfx/common/wayland/idle-inhibit-unstable-v1.h" 38 39 /* Generated from xdg-shell-unstable-v6.xml */ 40 #include "../../gfx/common/wayland/xdg-shell-unstable-v6.h" 41 42 /* Generated from xdg-shell.xml */ 43 #include "../../gfx/common/wayland/xdg-shell.h" 44 45 /* Generated from xdg-decoration-unstable-v1.h */ 46 #include "../../gfx/common/wayland/xdg-decoration-unstable-v1.h" 47 48 #define UDEV_KEY_MAX 0x2ff 49 #define UDEV_MAX_KEYS (UDEV_KEY_MAX + 7) / 8 50 51 #define MAX_TOUCHES 16 52 53 #define WL_ARRAY_FOR_EACH(pos, array, type) \ 54 for (pos = (type)(array)->data; \ 55 (const char *) pos < ((const char *) (array)->data + (array)->size); \ 56 (pos)++) 57 58 typedef struct 59 { 60 int16_t x; 61 int16_t y; 62 bool active; 63 } wayland_touch_data_t; 64 65 typedef struct touch_pos 66 { 67 int32_t id; 68 unsigned x; 69 unsigned y; 70 bool active; 71 } touch_pos_t; 72 73 typedef struct output_info 74 { 75 struct wl_output *output; 76 int refresh_rate; 77 uint32_t global_id; 78 unsigned width; 79 unsigned height; 80 unsigned physical_width; 81 unsigned physical_height; 82 unsigned scale; 83 struct wl_list link; /* wl->all_outputs */ 84 } output_info_t; 85 86 typedef struct gfx_ctx_wayland_data gfx_ctx_wayland_data_t; 87 88 typedef struct input_ctx_wayland_data 89 { 90 struct wl_display *dpy; 91 const input_device_driver_t *joypad; 92 gfx_ctx_wayland_data_t *gfx; 93 94 int fd; 95 96 wayland_touch_data_t touches[MAX_TOUCHES]; /* int16_t alignment */ 97 /* Wayland uses Linux keysyms. */ 98 uint8_t key_state[UDEV_MAX_KEYS]; 99 100 struct 101 { 102 int last_x, last_y; 103 int x, y; 104 int delta_x, delta_y; 105 bool last_valid; 106 bool focus; 107 bool left, right, middle; 108 } mouse; 109 110 bool keyboard_focus; 111 bool blocked; 112 } input_ctx_wayland_data_t; 113 114 typedef struct gfx_ctx_wayland_data 115 { 116 #ifdef HAVE_EGL 117 egl_ctx_data_t egl; 118 struct wl_egl_window *win; 119 #endif 120 struct wl_registry *registry; 121 struct wl_compositor *compositor; 122 struct wl_surface *surface; 123 struct zxdg_surface_v6 *zxdg_surface; 124 struct zxdg_shell_v6 *zxdg_shell; 125 struct zxdg_toplevel_v6 *zxdg_toplevel; 126 struct xdg_surface *xdg_surface; 127 struct xdg_wm_base *xdg_shell; 128 struct xdg_toplevel *xdg_toplevel; 129 struct wl_keyboard *wl_keyboard; 130 struct wl_pointer *wl_pointer; 131 struct wl_touch *wl_touch; 132 struct wl_seat *seat; 133 struct wl_shm *shm; 134 struct zxdg_decoration_manager_v1 *deco_manager; 135 struct zxdg_toplevel_decoration_v1 *deco; 136 struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager; 137 struct zwp_idle_inhibitor_v1 *idle_inhibitor; 138 output_info_t *current_output; 139 #ifdef HAVE_VULKAN 140 gfx_ctx_vulkan_data_t vk; 141 #endif 142 input_ctx_wayland_data_t input; /* ptr alignment */ 143 struct wl_list all_outputs; 144 145 struct 146 { 147 struct wl_cursor *default_cursor; 148 struct wl_cursor_theme *theme; 149 struct wl_surface *surface; 150 uint32_t serial; 151 bool visible; 152 } cursor; 153 154 int num_active_touches; 155 int swap_interval; 156 touch_pos_t active_touch_positions[MAX_TOUCHES]; /* int32_t alignment */ 157 unsigned prev_width; 158 unsigned prev_height; 159 unsigned width; 160 unsigned height; 161 unsigned last_buffer_scale; 162 unsigned buffer_scale; 163 164 bool core_hw_context_enable; 165 bool fullscreen; 166 bool maximized; 167 bool resize; 168 bool configured; 169 bool activated; 170 } gfx_ctx_wayland_data_t; 171 172 #ifdef HAVE_XKBCOMMON 173 /* FIXME: Move this into a header? */ 174 int init_xkb(int fd, size_t size); 175 int handle_xkb(int code, int value); 176 void handle_xkb_state_mask(uint32_t depressed, 177 uint32_t latched, uint32_t locked, uint32_t group); 178 void free_xkb(void); 179 #endif 180 181 void gfx_ctx_wl_show_mouse(void *data, bool state); 182 183 void handle_toplevel_close(void *data, 184 struct xdg_toplevel *xdg_toplevel); 185 186 void handle_zxdg_toplevel_close(void *data, 187 struct zxdg_toplevel_v6 *zxdg_toplevel); 188 189 void flush_wayland_fd(void *data); 190 191 extern const struct wl_keyboard_listener keyboard_listener; 192 193 extern const struct wl_pointer_listener pointer_listener; 194 195 extern const struct wl_touch_listener touch_listener; 196 197 extern const struct wl_seat_listener seat_listener; 198 199 extern const struct wl_surface_listener wl_surface_listener; 200 201 extern const struct xdg_wm_base_listener xdg_shell_listener; 202 203 extern const struct xdg_surface_listener xdg_surface_listener; 204 205 extern const struct zxdg_shell_v6_listener zxdg_shell_v6_listener; 206 207 extern const struct zxdg_surface_v6_listener zxdg_surface_v6_listener; 208 209 extern const struct wl_output_listener output_listener; 210 211 extern const struct wl_registry_listener registry_listener; 212 213 #endif 214