1 /* 2 * Copyright © 2014 David FORT <contact@hardening-consulting.com> 3 * 4 * Permission to use, copy, modify, distribute, and sell this software and its 5 * documentation for any purpose is hereby granted without fee, provided that 6 * the above copyright notice appear in all copies and that both that copyright 7 * notice and this permission notice appear in supporting documentation, and 8 * that the name of the copyright holders not be used in advertising or 9 * publicity pertaining to distribution of the software without specific, 10 * written prior permission. The copyright holders make no representations 11 * about the suitability of this software for any purpose. It is provided "as 12 * is" without express or implied warranty. 13 * 14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 20 * OF THIS SOFTWARE. 21 */ 22 23 #ifndef UWAC_PRIV_H_ 24 #define UWAC_PRIV_H_ 25 26 #include "config.h" 27 28 #include <stdbool.h> 29 #include <wayland-client.h> 30 #include "xdg-shell-client-protocol.h" 31 #include "keyboard-shortcuts-inhibit-unstable-v1-client-protocol.h" 32 #include "xdg-decoration-unstable-v1-client-protocol.h" 33 #include "server-decoration-client-protocol.h" 34 35 #ifdef BUILD_IVI 36 #include "ivi-application-client-protocol.h" 37 #endif 38 #ifdef BUILD_FULLSCREEN_SHELL 39 #include "fullscreen-shell-unstable-v1-client-protocol.h" 40 #endif 41 42 #ifdef HAVE_PIXMAN_REGION 43 #include <pixman-1/pixman.h> 44 #else 45 #include <freerdp/codec/region.h> 46 #endif 47 48 #include <xkbcommon/xkbcommon.h> 49 50 #include <uwac/uwac.h> 51 52 extern UwacErrorHandler uwacErrorHandler; 53 54 typedef struct uwac_task UwacTask; 55 56 /** @brief */ 57 struct uwac_task 58 { 59 void (*run)(UwacTask* task, uint32_t events); 60 struct wl_list link; 61 }; 62 63 /** @brief a global registry object */ 64 struct uwac_global 65 { 66 uint32_t name; 67 char* interface; 68 uint32_t version; 69 struct wl_list link; 70 }; 71 typedef struct uwac_global UwacGlobal; 72 73 struct uwac_event_list_item; 74 typedef struct uwac_event_list_item UwacEventListItem; 75 76 /** @brief */ 77 struct uwac_event_list_item 78 { 79 UwacEvent event; 80 UwacEventListItem *tail, *head; 81 }; 82 83 /** @brief main connection object to a wayland display */ 84 struct uwac_display 85 { 86 struct wl_list globals; 87 88 struct wl_display* display; 89 struct wl_registry* registry; 90 struct wl_compositor* compositor; 91 struct wl_subcompositor* subcompositor; 92 struct wl_shell* shell; 93 struct xdg_toplevel* xdg_toplevel; 94 struct xdg_wm_base* xdg_base; 95 struct wl_data_device_manager* devicemanager; 96 struct zwp_keyboard_shortcuts_inhibit_manager_v1* keyboard_inhibit_manager; 97 struct zxdg_decoration_manager_v1* deco_manager; 98 struct org_kde_kwin_server_decoration_manager* kde_deco_manager; 99 #ifdef BUILD_IVI 100 struct ivi_application* ivi_application; 101 #endif 102 #ifdef BUILD_FULLSCREEN_SHELL 103 struct zwp_fullscreen_shell_v1* fullscreen_shell; 104 #endif 105 106 struct wl_shm* shm; 107 enum wl_shm_format* shm_formats; 108 uint32_t shm_formats_nb; 109 bool has_rgb565; 110 111 struct wl_data_device_manager* data_device_manager; 112 struct text_cursor_position* text_cursor_position; 113 struct workspace_manager* workspace_manager; 114 115 struct wl_list seats; 116 117 int display_fd; 118 UwacReturnCode last_error; 119 uint32_t display_fd_events; 120 int epoll_fd; 121 bool running; 122 UwacTask dispatch_fd_task; 123 uint32_t serial; 124 125 struct wl_list windows; 126 127 struct wl_list outputs; 128 129 UwacEventListItem *push_queue, *pop_queue; 130 }; 131 132 /** @brief an output on a wayland display */ 133 struct uwac_output 134 { 135 UwacDisplay* display; 136 137 bool doneNeeded; 138 bool doneReceived; 139 140 UwacPosition position; 141 UwacSize resolution; 142 int transform; 143 int scale; 144 char* make; 145 char* model; 146 uint32_t server_output_id; 147 struct wl_output* output; 148 149 struct wl_list link; 150 }; 151 152 /** @brief a seat attached to a wayland display */ 153 struct uwac_seat 154 { 155 UwacDisplay* display; 156 char* name; 157 struct wl_seat* seat; 158 uint32_t seat_id; 159 uint32_t seat_version; 160 struct wl_data_device* data_device; 161 struct wl_data_source* data_source; 162 struct wl_pointer* pointer; 163 struct wl_surface* pointer_surface; 164 struct wl_cursor_image* pointer_image; 165 struct wl_cursor_theme* cursor_theme; 166 struct wl_cursor* default_cursor; 167 void* pointer_data; 168 size_t pointer_size; 169 int pointer_type; 170 struct wl_keyboard* keyboard; 171 struct wl_touch* touch; 172 struct wl_data_offer* offer; 173 struct xkb_context* xkb_context; 174 struct zwp_keyboard_shortcuts_inhibitor_v1* keyboard_inhibitor; 175 176 struct 177 { 178 struct xkb_keymap* keymap; 179 struct xkb_state* state; 180 xkb_mod_mask_t control_mask; 181 xkb_mod_mask_t alt_mask; 182 xkb_mod_mask_t shift_mask; 183 xkb_mod_mask_t caps_mask; 184 xkb_mod_mask_t num_mask; 185 } xkb; 186 uint32_t modifiers; 187 int32_t repeat_rate_sec, repeat_rate_nsec; 188 int32_t repeat_delay_sec, repeat_delay_nsec; 189 uint32_t repeat_sym, repeat_key, repeat_time; 190 191 struct wl_array pressed_keys; 192 193 UwacWindow* pointer_focus; 194 195 UwacWindow* keyboard_focus; 196 197 UwacWindow* touch_focus; 198 bool touch_frame_started; 199 200 int repeat_timer_fd; 201 UwacTask repeat_task; 202 float sx, sy; 203 struct wl_list link; 204 205 void* data_context; 206 UwacDataTransferHandler transfer_data; 207 UwacCancelDataTransferHandler cancel_data; 208 bool ignore_announcement; 209 }; 210 211 /** @brief a buffer used for drawing a surface frame */ 212 struct uwac_buffer 213 { 214 bool used; 215 bool dirty; 216 #ifdef HAVE_PIXMAN_REGION 217 pixman_region32_t damage; 218 #else 219 REGION16 damage; 220 #endif 221 struct wl_buffer* wayland_buffer; 222 void* data; 223 size_t size; 224 }; 225 typedef struct uwac_buffer UwacBuffer; 226 227 /** @brief a window */ 228 struct uwac_window 229 { 230 UwacDisplay* display; 231 int width, height, stride; 232 int surfaceStates; 233 enum wl_shm_format format; 234 235 int nbuffers; 236 UwacBuffer* buffers; 237 238 struct wl_region* opaque_region; 239 struct wl_region* input_region; 240 SSIZE_T drawingBufferIdx; 241 SSIZE_T pendingBufferIdx; 242 struct wl_surface* surface; 243 struct wl_shell_surface* shell_surface; 244 struct xdg_surface* xdg_surface; 245 struct xdg_toplevel* xdg_toplevel; 246 struct zxdg_toplevel_decoration_v1* deco; 247 struct org_kde_kwin_server_decoration* kde_deco; 248 #ifdef BUILD_IVI 249 struct ivi_surface* ivi_surface; 250 #endif 251 struct wl_list link; 252 253 uint32_t pointer_enter_serial; 254 uint32_t pointer_cursor_serial; 255 int pointer_current_cursor; 256 }; 257 258 /* in uwa-display.c */ 259 UwacEvent* UwacDisplayNewEvent(UwacDisplay* d, int type); 260 int UwacDisplayWatchFd(UwacDisplay* display, int fd, uint32_t events, UwacTask* task); 261 262 /* in uwac-input.c */ 263 UwacSeat* UwacSeatNew(UwacDisplay* d, uint32_t id, uint32_t version); 264 void UwacSeatDestroy(UwacSeat* s); 265 266 /* in uwac-output.c */ 267 UwacOutput* UwacCreateOutput(UwacDisplay* d, uint32_t id, uint32_t version); 268 int UwacDestroyOutput(UwacOutput* output); 269 270 UwacReturnCode UwacSeatRegisterClipboard(UwacSeat* s); 271 272 #endif /* UWAC_PRIV_H_ */ 273