winewayland.drv: Prepare to handle different coordinate spaces.
[wine.git] / dlls / winewayland.drv / waylanddrv.h
blobb9346c1443edda8a671ea392cacf5439ce22ed93
1 /*
2 * Wayland driver
4 * Copyright 2020 Alexandros Frantzis for Collabora Ltd
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef __WINE_WAYLANDDRV_H
22 #define __WINE_WAYLANDDRV_H
24 #ifndef __WINE_CONFIG_H
25 # error You must include config.h to use this header
26 #endif
28 #include <pthread.h>
29 #include <wayland-client.h>
30 #include <xkbcommon/xkbcommon.h>
31 #include "xdg-output-unstable-v1-client-protocol.h"
32 #include "xdg-shell-client-protocol.h"
34 #include "windef.h"
35 #include "winbase.h"
36 #include "ntgdi.h"
37 #include "wine/gdi_driver.h"
38 #include "wine/rbtree.h"
40 #include "unixlib.h"
42 /* We only use 4 byte formats. */
43 #define WINEWAYLAND_BYTES_PER_PIXEL 4
45 /**********************************************************************
46 * Globals
49 extern struct wayland process_wayland DECLSPEC_HIDDEN;
51 /**********************************************************************
52 * Definitions for wayland types
55 enum wayland_window_message
57 WM_WAYLAND_INIT_DISPLAY_DEVICES = 0x80001000,
58 WM_WAYLAND_CONFIGURE = 0x80001001
61 enum wayland_surface_config_state
63 WAYLAND_SURFACE_CONFIG_STATE_MAXIMIZED = (1 << 0),
64 WAYLAND_SURFACE_CONFIG_STATE_RESIZING = (1 << 1),
65 WAYLAND_SURFACE_CONFIG_STATE_TILED = (1 << 2),
66 WAYLAND_SURFACE_CONFIG_STATE_FULLSCREEN = (1 << 3)
69 struct wayland_keyboard
71 struct wl_keyboard *wl_keyboard;
72 struct xkb_context *xkb_context;
73 HWND focused_hwnd;
74 pthread_mutex_t mutex;
77 struct wayland_cursor
79 struct wayland_shm_buffer *shm_buffer;
80 struct wl_surface *wl_surface;
81 int hotspot_x, hotspot_y;
84 struct wayland_pointer
86 struct wl_pointer *wl_pointer;
87 HWND focused_hwnd;
88 uint32_t enter_serial;
89 uint32_t button_serial;
90 struct wayland_cursor cursor;
91 pthread_mutex_t mutex;
94 struct wayland_seat
96 struct wl_seat *wl_seat;
97 uint32_t global_id;
98 pthread_mutex_t mutex;
101 struct wayland
103 BOOL initialized;
104 struct wl_display *wl_display;
105 struct wl_event_queue *wl_event_queue;
106 struct wl_registry *wl_registry;
107 struct zxdg_output_manager_v1 *zxdg_output_manager_v1;
108 struct wl_compositor *wl_compositor;
109 struct xdg_wm_base *xdg_wm_base;
110 struct wl_shm *wl_shm;
111 struct wayland_seat seat;
112 struct wayland_keyboard keyboard;
113 struct wayland_pointer pointer;
114 struct wl_list output_list;
115 /* Protects the output_list and the wayland_output.current states. */
116 pthread_mutex_t output_mutex;
119 struct wayland_output_mode
121 struct rb_entry entry;
122 int32_t width;
123 int32_t height;
124 int32_t refresh;
127 struct wayland_output_state
129 struct rb_tree modes;
130 struct wayland_output_mode *current_mode;
131 char *name;
132 int logical_x, logical_y;
133 int logical_w, logical_h;
136 struct wayland_output
138 struct wl_list link;
139 struct wl_output *wl_output;
140 struct zxdg_output_v1 *zxdg_output_v1;
141 uint32_t global_id;
142 unsigned int pending_flags;
143 struct wayland_output_state pending;
144 struct wayland_output_state current;
147 struct wayland_surface_config
149 int32_t width, height;
150 enum wayland_surface_config_state state;
151 uint32_t serial;
152 BOOL processed;
155 struct wayland_window_config
157 RECT rect;
158 enum wayland_surface_config_state state;
161 struct wayland_surface
163 HWND hwnd;
164 struct wl_surface *wl_surface;
165 struct xdg_surface *xdg_surface;
166 struct xdg_toplevel *xdg_toplevel;
167 pthread_mutex_t mutex;
168 struct wayland_surface_config pending, requested, processing, current;
169 struct wayland_shm_buffer *latest_window_buffer;
170 BOOL resizing;
171 struct wayland_window_config window;
174 struct wayland_shm_buffer
176 struct wl_list link;
177 struct wl_buffer *wl_buffer;
178 int width, height;
179 void *map_data;
180 size_t map_size;
181 BOOL busy;
182 LONG ref;
183 HRGN damage_region;
186 /**********************************************************************
187 * Wayland initialization
190 BOOL wayland_process_init(void) DECLSPEC_HIDDEN;
191 void wayland_init_display_devices(BOOL force) DECLSPEC_HIDDEN;
193 /**********************************************************************
194 * Wayland output
197 BOOL wayland_output_create(uint32_t id, uint32_t version) DECLSPEC_HIDDEN;
198 void wayland_output_destroy(struct wayland_output *output) DECLSPEC_HIDDEN;
199 void wayland_output_use_xdg_extension(struct wayland_output *output) DECLSPEC_HIDDEN;
201 /**********************************************************************
202 * Wayland surface
205 struct wayland_surface *wayland_surface_create(HWND hwnd) DECLSPEC_HIDDEN;
206 void wayland_surface_destroy(struct wayland_surface *surface) DECLSPEC_HIDDEN;
207 void wayland_surface_make_toplevel(struct wayland_surface *surface) DECLSPEC_HIDDEN;
208 void wayland_surface_clear_role(struct wayland_surface *surface) DECLSPEC_HIDDEN;
209 void wayland_surface_attach_shm(struct wayland_surface *surface,
210 struct wayland_shm_buffer *shm_buffer,
211 HRGN surface_damage_region) DECLSPEC_HIDDEN;
212 struct wayland_surface *wayland_surface_lock_hwnd(HWND hwnd) DECLSPEC_HIDDEN;
213 BOOL wayland_surface_reconfigure(struct wayland_surface *surface) DECLSPEC_HIDDEN;
214 BOOL wayland_surface_config_is_compatible(struct wayland_surface_config *conf,
215 int width, int height,
216 enum wayland_surface_config_state state) DECLSPEC_HIDDEN;
217 void wayland_surface_coords_from_window(struct wayland_surface *surface,
218 int window_x, int window_y,
219 int *surface_x, int *surface_y) DECLSPEC_HIDDEN;
220 void wayland_surface_coords_to_window(struct wayland_surface *surface,
221 double surface_x, double surface_y,
222 int *window_x, int *window_y) DECLSPEC_HIDDEN;
224 /**********************************************************************
225 * Wayland SHM buffer
228 struct wayland_shm_buffer *wayland_shm_buffer_create(int width, int height,
229 enum wl_shm_format format) DECLSPEC_HIDDEN;
230 void wayland_shm_buffer_ref(struct wayland_shm_buffer *shm_buffer) DECLSPEC_HIDDEN;
231 void wayland_shm_buffer_unref(struct wayland_shm_buffer *shm_buffer) DECLSPEC_HIDDEN;
233 /**********************************************************************
234 * Wayland window surface
237 struct window_surface *wayland_window_surface_create(HWND hwnd, const RECT *rect) DECLSPEC_HIDDEN;
238 void wayland_window_surface_update_wayland_surface(struct window_surface *surface,
239 struct wayland_surface *wayland_surface) DECLSPEC_HIDDEN;
240 void wayland_window_flush(HWND hwnd) DECLSPEC_HIDDEN;
242 /**********************************************************************
243 * Wayland Keyboard
246 void wayland_keyboard_init(struct wl_keyboard *wl_keyboard) DECLSPEC_HIDDEN;
247 void wayland_keyboard_deinit(void) DECLSPEC_HIDDEN;
249 /**********************************************************************
250 * Wayland pointer
253 void wayland_pointer_init(struct wl_pointer *wl_pointer) DECLSPEC_HIDDEN;
254 void wayland_pointer_deinit(void) DECLSPEC_HIDDEN;
256 /**********************************************************************
257 * Helpers
260 static inline BOOL intersect_rect(RECT *dst, const RECT *src1, const RECT *src2)
262 dst->left = max(src1->left, src2->left);
263 dst->top = max(src1->top, src2->top);
264 dst->right = min(src1->right, src2->right);
265 dst->bottom = min(src1->bottom, src2->bottom);
266 return !IsRectEmpty(dst);
269 static inline LRESULT send_message(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
271 return NtUserMessageCall(hwnd, msg, wparam, lparam, NULL, NtUserSendMessage, FALSE);
274 RGNDATA *get_region_data(HRGN region) DECLSPEC_HIDDEN;
276 /**********************************************************************
277 * USER driver functions
280 LRESULT WAYLAND_DesktopWindowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) DECLSPEC_HIDDEN;
281 void WAYLAND_DestroyWindow(HWND hwnd) DECLSPEC_HIDDEN;
282 void WAYLAND_SetCursor(HWND hwnd, HCURSOR hcursor) DECLSPEC_HIDDEN;
283 LRESULT WAYLAND_SysCommand(HWND hwnd, WPARAM wparam, LPARAM lparam) DECLSPEC_HIDDEN;
284 BOOL WAYLAND_UpdateDisplayDevices(const struct gdi_device_manager *device_manager,
285 BOOL force, void *param) DECLSPEC_HIDDEN;
286 LRESULT WAYLAND_WindowMessage(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) DECLSPEC_HIDDEN;
287 void WAYLAND_WindowPosChanged(HWND hwnd, HWND insert_after, UINT swp_flags,
288 const RECT *window_rect, const RECT *client_rect,
289 const RECT *visible_rect, const RECT *valid_rects,
290 struct window_surface *surface) DECLSPEC_HIDDEN;
291 BOOL WAYLAND_WindowPosChanging(HWND hwnd, HWND insert_after, UINT swp_flags,
292 const RECT *window_rect, const RECT *client_rect,
293 RECT *visible_rect, struct window_surface **surface) DECLSPEC_HIDDEN;
295 #endif /* __WINE_WAYLANDDRV_H */