| 1 |
/* |
| 2 |
* Copyright © 2010 Intel Corporation |
| 3 |
* |
| 4 |
* This library is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU Lesser General Public License |
| 6 |
* as published by the Free Software Foundation; either version 2 of |
| 7 |
* the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This library is distributed in the hope that it will be useful, but |
| 10 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* Lesser General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU Lesser General Public |
| 15 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "config.h" |
| 19 |
|
| 20 |
#include <netinet/in.h> |
| 21 |
#include <unistd.h> |
| 22 |
|
| 23 |
#include "gdk.h" |
| 24 |
#include "gdkwayland.h" |
| 25 |
|
| 26 |
#include "gdkwindow.h" |
| 27 |
#include "gdkwindowimpl.h" |
| 28 |
#include "gdkdisplay-wayland.h" |
| 29 |
#include "gdkglcontext-wayland.h" |
| 30 |
#include "gdkframeclockprivate.h" |
| 31 |
#include "gdkprivate-wayland.h" |
| 32 |
#include "gdkprofilerprivate.h" |
| 33 |
#include "gdkinternals.h" |
| 34 |
#include "gdkdeviceprivate.h" |
| 35 |
#include "gdkprivate-wayland.h" |
| 36 |
#include "xdg-shell-unstable-v6-client-protocol.h" |
| 37 |
|
| 38 |
#include <stdlib.h> |
| 39 |
#include <stdio.h> |
| 40 |
#include <string.h> |
| 41 |
#include <errno.h> |
| 42 |
|
| 43 |
enum { |
| 44 |
COMMITTED, |
| 45 |
|
| 46 |
LAST_SIGNAL |
| 47 |
}; |
| 48 |
|
| 49 |
static guint signals[LAST_SIGNAL]; |
| 50 |
|
| 51 |
#define WINDOW_IS_TOPLEVEL_OR_FOREIGN(window) \ |
| 52 |
(GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \ |
| 53 |
GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN) |
| 54 |
|
| 55 |
#define WINDOW_IS_TOPLEVEL(window) \ |
| 56 |
(GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \ |
| 57 |
GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN && \ |
| 58 |
GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN) |
| 59 |
|
| 60 |
#define MAX_WL_BUFFER_SIZE (4083) /* 4096 minus header, string argument length and NUL byte */ |
| 61 |
|
| 62 |
typedef struct _GdkWaylandWindow GdkWaylandWindow; |
| 63 |
typedef struct _GdkWaylandWindowClass GdkWaylandWindowClass; |
| 64 |
|
| 65 |
struct _GdkWaylandWindow |
| 66 |
{ |
| 67 |
GdkWindow parent; |
| 68 |
}; |
| 69 |
|
| 70 |
struct _GdkWaylandWindowClass |
| 71 |
{ |
| 72 |
GdkWindowClass parent_class; |
| 73 |
}; |
| 74 |
|
| 75 |
G_DEFINE_TYPE (GdkWaylandWindow, gdk_wayland_window, GDK_TYPE_WINDOW) |
| 76 |
|
| 77 |
static void |
| 78 |
gdk_wayland_window_class_init (GdkWaylandWindowClass *wayland_window_class) |
| 79 |
{ |
| 80 |
} |
| 81 |
|
| 82 |
static void |
| 83 |
gdk_wayland_window_init (GdkWaylandWindow *wayland_window) |
| 84 |
{ |
| 85 |
} |
| 86 |
|
| 87 |
#define GDK_TYPE_WINDOW_IMPL_WAYLAND (_gdk_window_impl_wayland_get_type ()) |
| 88 |
#define GDK_WINDOW_IMPL_WAYLAND(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_WINDOW_IMPL_WAYLAND, GdkWindowImplWayland)) |
| 89 |
#define GDK_WINDOW_IMPL_WAYLAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_WINDOW_IMPL_WAYLAND, GdkWindowImplWaylandClass)) |
| 90 |
#define GDK_IS_WINDOW_IMPL_WAYLAND(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_WINDOW_IMPL_WAYLAND)) |
| 91 |
#define GDK_IS_WINDOW_IMPL_WAYLAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_WINDOW_IMPL_WAYLAND)) |
| 92 |
#define GDK_WINDOW_IMPL_WAYLAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_WINDOW_IMPL_WAYLAND, GdkWindowImplWaylandClass)) |
| 93 |
|
| 94 |
typedef struct _GdkWindowImplWayland GdkWindowImplWayland; |
| 95 |
typedef struct _GdkWindowImplWaylandClass GdkWindowImplWaylandClass; |
| 96 |
|
| 97 |
typedef enum _PositionMethod |
| 98 |
{ |
| 99 |
POSITION_METHOD_NONE, |
| 100 |
POSITION_METHOD_MOVE_RESIZE, |
| 101 |
POSITION_METHOD_MOVE_TO_RECT |
| 102 |
} PositionMethod; |
| 103 |
|
| 104 |
typedef struct _ExportedClosure |
| 105 |
{ |
| 106 |
GdkWaylandWindowExported callback; |
| 107 |
gpointer user_data; |
| 108 |
GDestroyNotify destroy_func; |
| 109 |
} ExportedClosure; |
| 110 |
|
| 111 |
struct _GdkWindowImplWayland |
| 112 |
{ |
| 113 |
GdkWindowImpl parent_instance; |
| 114 |
|
| 115 |
GdkWindow *wrapper; |
| 116 |
|
| 117 |
struct { |
| 118 |
/* The wl_outputs that this window currently touches */ |
| 119 |
GSList *outputs; |
| 120 |
|
| 121 |
struct wl_surface *wl_surface; |
| 122 |
|
| 123 |
struct xdg_surface *xdg_surface; |
| 124 |
struct xdg_toplevel *xdg_toplevel; |
| 125 |
struct xdg_popup *xdg_popup; |
| 126 |
|
| 127 |
/* Legacy xdg-shell unstable v6 fallback support */ |
| 128 |
struct zxdg_surface_v6 *zxdg_surface_v6; |
| 129 |
struct zxdg_toplevel_v6 *zxdg_toplevel_v6; |
| 130 |
struct zxdg_popup_v6 *zxdg_popup_v6; |
| 131 |
|
| 132 |
struct gtk_surface1 *gtk_surface; |
| 133 |
struct wl_subsurface *wl_subsurface; |
| 134 |
struct wl_egl_window *egl_window; |
| 135 |
struct wl_egl_window *dummy_egl_window; |
| 136 |
struct zxdg_exported_v1 *xdg_exported_v1; |
| 137 |
struct zxdg_exported_v2 *xdg_exported_v2; |
| 138 |
struct org_kde_kwin_server_decoration *server_decoration; |
| 139 |
} display_server; |
| 140 |
|
| 141 |
EGLSurface egl_surface; |
| 142 |
EGLSurface dummy_egl_surface; |
| 143 |
|
| 144 |
unsigned int initial_configure_received : 1; |
| 145 |
unsigned int configuring_popup : 1; |
| 146 |
unsigned int mapped : 1; |
| 147 |
unsigned int use_custom_surface : 1; |
| 148 |
unsigned int pending_buffer_attached : 1; |
| 149 |
unsigned int pending_commit : 1; |
| 150 |
unsigned int awaiting_frame : 1; |
| 151 |
unsigned int using_csd : 1; |
| 152 |
unsigned int suspended : 1; |
| 153 |
GdkWindowTypeHint hint; |
| 154 |
GdkWindow *transient_for; |
| 155 |
GdkWindow *popup_parent; |
| 156 |
PositionMethod position_method; |
| 157 |
|
| 158 |
cairo_surface_t *staging_cairo_surface; |
| 159 |
cairo_surface_t *committed_cairo_surface; |
| 160 |
cairo_surface_t *backfill_cairo_surface; |
| 161 |
|
| 162 |
int pending_buffer_offset_x; |
| 163 |
int pending_buffer_offset_y; |
| 164 |
|
| 165 |
int subsurface_x; |
| 166 |
int subsurface_y; |
| 167 |
|
| 168 |
gchar *title; |
| 169 |
|
| 170 |
struct { |
| 171 |
gboolean was_set; |
| 172 |
|
| 173 |
gchar *application_id; |
| 174 |
gchar *app_menu_path; |
| 175 |
gchar *menubar_path; |
| 176 |
gchar *window_object_path; |
| 177 |
gchar *application_object_path; |
| 178 |
gchar *unique_bus_name; |
| 179 |
} application; |
| 180 |
|
| 181 |
GdkGeometry geometry_hints; |
| 182 |
GdkWindowHints geometry_mask; |
| 183 |
|
| 184 |
GdkSeat *grab_input_seat; |
| 185 |
|
| 186 |
gint64 pending_frame_counter; |
| 187 |
guint32 scale; |
| 188 |
|
| 189 |
int margin_left; |
| 190 |
int margin_right; |
| 191 |
int margin_top; |
| 192 |
int margin_bottom; |
| 193 |
gboolean margin_dirty; |
| 194 |
|
| 195 |
int initial_fullscreen_monitor; |
| 196 |
|
| 197 |
cairo_region_t *opaque_region; |
| 198 |
gboolean opaque_region_dirty; |
| 199 |
|
| 200 |
cairo_region_t *input_region; |
| 201 |
gboolean input_region_dirty; |
| 202 |
|
| 203 |
cairo_region_t *staged_updates_region; |
| 204 |
|
| 205 |
int saved_width; |
| 206 |
int saved_height; |
| 207 |
gboolean saved_size_changed; |
| 208 |
|
| 209 |
int unconfigured_width; |
| 210 |
int unconfigured_height; |
| 211 |
|
| 212 |
int fixed_size_width; |
| 213 |
int fixed_size_height; |
| 214 |
|
| 215 |
gulong parent_surface_committed_handler; |
| 216 |
|
| 217 |
struct { |
| 218 |
GdkRectangle rect; |
| 219 |
GdkGravity rect_anchor; |
| 220 |
GdkGravity window_anchor; |
| 221 |
GdkAnchorHints anchor_hints; |
| 222 |
gint rect_anchor_dx; |
| 223 |
gint rect_anchor_dy; |
| 224 |
} pending_move_to_rect; |
| 225 |
|
| 226 |
struct { |
| 227 |
int width; |
| 228 |
int height; |
| 229 |
GdkWindowState state; |
| 230 |
gboolean suspended; |
| 231 |
} pending; |
| 232 |
|
| 233 |
struct { |
| 234 |
char *handle; |
| 235 |
int export_count; |
| 236 |
GList *closures; |
| 237 |
guint idle_source_id; |
| 238 |
} exported; |
| 239 |
|
| 240 |
struct zxdg_imported_v1 *imported_v1_transient_for; |
| 241 |
struct zxdg_imported_v2 *imported_v2_transient_for; |
| 242 |
GHashTable *shortcuts_inhibitors; |
| 243 |
|
| 244 |
struct wl_callback *surface_callback; |
| 245 |
GHashTable *frame_callback_surfaces; |
| 246 |
}; |
| 247 |
|
| 248 |
struct _GdkWindowImplWaylandClass |
| 249 |
{ |
| 250 |
GdkWindowImplClass parent_class; |
| 251 |
}; |
| 252 |
|
| 253 |
static void gdk_wayland_window_maybe_configure (GdkWindow *window, |
| 254 |
int width, |
| 255 |
int height, |
| 256 |
int scale); |
| 257 |
|
| 258 |
static void maybe_set_gtk_surface_dbus_properties (GdkWindow *window); |
| 259 |
static void maybe_set_gtk_surface_modal (GdkWindow *window); |
| 260 |
|
| 261 |
static void gdk_window_request_transient_parent_commit (GdkWindow *window); |
| 262 |
|
| 263 |
static void gdk_wayland_window_sync_margin (GdkWindow *window); |
| 264 |
static void gdk_wayland_window_sync_input_region (GdkWindow *window); |
| 265 |
static void gdk_wayland_window_sync_opaque_region (GdkWindow *window); |
| 266 |
|
| 267 |
static void unset_transient_for_exported (GdkWindow *window); |
| 268 |
|
| 269 |
static void calculate_moved_to_rect_result (GdkWindow *window, |
| 270 |
int x, |
| 271 |
int y, |
| 272 |
int width, |
| 273 |
int height, |
| 274 |
GdkRectangle *flipped_rect, |
| 275 |
GdkRectangle *final_rect, |
| 276 |
gboolean *flipped_x, |
| 277 |
gboolean *flipped_y); |
| 278 |
|
| 279 |
static gboolean gdk_wayland_window_is_exported (GdkWindow *window); |
| 280 |
static void gdk_wayland_window_unexport (GdkWindow *window); |
| 281 |
static void gdk_wayland_window_announce_decoration_mode (GdkWindow *window); |
| 282 |
|
| 283 |
static gboolean should_map_as_subsurface (GdkWindow *window); |
| 284 |
static gboolean should_map_as_popup (GdkWindow *window); |
| 285 |
|
| 286 |
GType _gdk_window_impl_wayland_get_type (void); |
| 287 |
|
| 288 |
G_DEFINE_TYPE (GdkWindowImplWayland, _gdk_window_impl_wayland, GDK_TYPE_WINDOW_IMPL) |
| 289 |
|
| 290 |
static void |
| 291 |
_gdk_window_impl_wayland_init (GdkWindowImplWayland *impl) |
| 292 |
{ |
| 293 |
impl->scale = 1; |
| 294 |
impl->initial_fullscreen_monitor = -1; |
| 295 |
impl->saved_width = -1; |
| 296 |
impl->saved_height = -1; |
| 297 |
impl->suspended = FALSE; |
| 298 |
} |
| 299 |
|
| 300 |
static void |
| 301 |
_gdk_wayland_screen_add_orphan_dialog (GdkWindow *window) |
| 302 |
{ |
| 303 |
GdkWaylandDisplay *display_wayland = |
| 304 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 305 |
|
| 306 |
if (!g_list_find (display_wayland->orphan_dialogs, window)) |
| 307 |
display_wayland->orphan_dialogs = |
| 308 |
g_list_prepend (display_wayland->orphan_dialogs, window); |
| 309 |
} |
| 310 |
|
| 311 |
static void |
| 312 |
drop_cairo_surfaces (GdkWindow *window) |
| 313 |
{ |
| 314 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 315 |
|
| 316 |
g_clear_pointer (&impl->staging_cairo_surface, cairo_surface_destroy); |
| 317 |
g_clear_pointer (&impl->backfill_cairo_surface, cairo_surface_destroy); |
| 318 |
|
| 319 |
/* We nullify this so if a buffer release comes in later, we won't |
| 320 |
* try to reuse that buffer since it's no longer suitable |
| 321 |
*/ |
| 322 |
impl->committed_cairo_surface = NULL; |
| 323 |
} |
| 324 |
|
| 325 |
static int |
| 326 |
calculate_width_without_margin (GdkWindow *window, |
| 327 |
int width) |
| 328 |
{ |
| 329 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 330 |
|
| 331 |
return width - (impl->margin_left + impl->margin_right); |
| 332 |
} |
| 333 |
|
| 334 |
static int |
| 335 |
calculate_height_without_margin (GdkWindow *window, |
| 336 |
int height) |
| 337 |
{ |
| 338 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 339 |
|
| 340 |
return height - (impl->margin_top + impl->margin_bottom); |
| 341 |
} |
| 342 |
|
| 343 |
static int |
| 344 |
calculate_width_with_margin (GdkWindow *window, |
| 345 |
int width) |
| 346 |
{ |
| 347 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 348 |
|
| 349 |
return width + impl->margin_left + impl->margin_right; |
| 350 |
} |
| 351 |
|
| 352 |
static int |
| 353 |
calculate_height_with_margin (GdkWindow *window, |
| 354 |
int height) |
| 355 |
{ |
| 356 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 357 |
|
| 358 |
return height + impl->margin_top + impl->margin_bottom; |
| 359 |
} |
| 360 |
|
| 361 |
static void |
| 362 |
_gdk_wayland_window_save_size (GdkWindow *window) |
| 363 |
{ |
| 364 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 365 |
|
| 366 |
if (window->state & (GDK_WINDOW_STATE_FULLSCREEN | |
| 367 |
GDK_WINDOW_STATE_MAXIMIZED | |
| 368 |
GDK_WINDOW_STATE_TILED)) |
| 369 |
return; |
| 370 |
|
| 371 |
impl->saved_width = calculate_width_without_margin (window, window->width); |
| 372 |
impl->saved_height = calculate_height_without_margin (window, window->height); |
| 373 |
} |
| 374 |
|
| 375 |
static void |
| 376 |
_gdk_wayland_window_clear_saved_size (GdkWindow *window) |
| 377 |
{ |
| 378 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 379 |
|
| 380 |
if (window->state & (GDK_WINDOW_STATE_FULLSCREEN | |
| 381 |
GDK_WINDOW_STATE_MAXIMIZED | |
| 382 |
GDK_WINDOW_STATE_TILED)) |
| 383 |
return; |
| 384 |
|
| 385 |
impl->saved_width = -1; |
| 386 |
impl->saved_height = -1; |
| 387 |
} |
| 388 |
|
| 389 |
/* |
| 390 |
* gdk_wayland_window_update_size: |
| 391 |
* @drawable: a #GdkDrawableImplWayland. |
| 392 |
* |
| 393 |
* Updates the state of the drawable (in particular the drawable's |
| 394 |
* cairo surface) when its size has changed. |
| 395 |
*/ |
| 396 |
static void |
| 397 |
gdk_wayland_window_update_size (GdkWindow *window, |
| 398 |
int32_t width, |
| 399 |
int32_t height, |
| 400 |
int scale) |
| 401 |
{ |
| 402 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 403 |
GdkRectangle area; |
| 404 |
cairo_region_t *region; |
| 405 |
|
| 406 |
if ((window->width == width) && |
| 407 |
(window->height == height) && |
| 408 |
(impl->scale == scale)) |
| 409 |
return; |
| 410 |
|
| 411 |
drop_cairo_surfaces (window); |
| 412 |
|
| 413 |
window->width = width; |
| 414 |
window->height = height; |
| 415 |
impl->scale = scale; |
| 416 |
|
| 417 |
if (impl->display_server.egl_window) |
| 418 |
wl_egl_window_resize (impl->display_server.egl_window, width * scale, height * scale, 0, 0); |
| 419 |
if (impl->display_server.wl_surface) |
| 420 |
wl_surface_set_buffer_scale (impl->display_server.wl_surface, scale); |
| 421 |
|
| 422 |
area.x = 0; |
| 423 |
area.y = 0; |
| 424 |
area.width = window->width; |
| 425 |
area.height = window->height; |
| 426 |
|
| 427 |
region = cairo_region_create_rectangle (&area); |
| 428 |
_gdk_window_invalidate_for_expose (window, region); |
| 429 |
cairo_region_destroy (region); |
| 430 |
} |
| 431 |
|
| 432 |
GdkWindow * |
| 433 |
_gdk_wayland_screen_create_root_window (GdkScreen *screen, |
| 434 |
int width, |
| 435 |
int height) |
| 436 |
{ |
| 437 |
GdkWaylandDisplay *display_wayland = |
| 438 |
GDK_WAYLAND_DISPLAY (gdk_screen_get_display (screen)); |
| 439 |
GdkWindow *window; |
| 440 |
GdkWindowImplWayland *impl; |
| 441 |
|
| 442 |
window = _gdk_display_create_window (GDK_DISPLAY (display_wayland)); |
| 443 |
window->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_WAYLAND, NULL); |
| 444 |
window->impl_window = window; |
| 445 |
window->visual = gdk_screen_get_system_visual (screen); |
| 446 |
|
| 447 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 448 |
|
| 449 |
impl->wrapper = GDK_WINDOW (window); |
| 450 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 451 |
if (display_wayland->compositor_version >= WL_SURFACE_HAS_BUFFER_SCALE && |
| 452 |
gdk_screen_get_n_monitors (screen) > 0) |
| 453 |
impl->scale = gdk_screen_get_monitor_scale_factor (screen, 0); |
| 454 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 455 |
|
| 456 |
impl->using_csd = TRUE; |
| 457 |
|
| 458 |
/* logical 1x1 fake buffer */ |
| 459 |
impl->staging_cairo_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, |
| 460 |
impl->scale, |
| 461 |
impl->scale); |
| 462 |
|
| 463 |
cairo_surface_set_device_scale (impl->staging_cairo_surface, impl->scale, impl->scale); |
| 464 |
|
| 465 |
window->window_type = GDK_WINDOW_ROOT; |
| 466 |
window->depth = 32; |
| 467 |
|
| 468 |
window->x = 0; |
| 469 |
window->y = 0; |
| 470 |
window->abs_x = 0; |
| 471 |
window->abs_y = 0; |
| 472 |
window->width = width; |
| 473 |
window->height = height; |
| 474 |
window->viewable = TRUE; |
| 475 |
|
| 476 |
/* see init_randr_support() in gdkscreen-wayland.c */ |
| 477 |
window->event_mask = GDK_STRUCTURE_MASK; |
| 478 |
|
| 479 |
return window; |
| 480 |
} |
| 481 |
|
| 482 |
static const gchar * |
| 483 |
get_default_title (void) |
| 484 |
{ |
| 485 |
const char *title; |
| 486 |
|
| 487 |
title = g_get_application_name (); |
| 488 |
if (!title) |
| 489 |
title = g_get_prgname (); |
| 490 |
if (!title) |
| 491 |
title = ""; |
| 492 |
|
| 493 |
return title; |
| 494 |
} |
| 495 |
|
| 496 |
static void |
| 497 |
fill_presentation_time_from_frame_time (GdkFrameTimings *timings, |
| 498 |
guint32 frame_time) |
| 499 |
{ |
| 500 |
/* The timestamp in a wayland frame is a msec time value that in some |
| 501 |
* way reflects the time at which the server started drawing the frame. |
| 502 |
* This is not useful from our perspective. |
| 503 |
* |
| 504 |
* However, for the DRM backend of Weston, on reasonably recent |
| 505 |
* Linux, we know that the time is the |
| 506 |
* clock_gettime (CLOCK_MONOTONIC) value at the vblank, and that |
| 507 |
* backend starts drawing immediately after receiving the vblank |
| 508 |
* notification. If we detect this, and make the assumption that the |
| 509 |
* compositor will finish drawing before the next vblank, we can |
| 510 |
* then determine the presentation time as the frame time we |
| 511 |
* received plus one refresh interval. |
| 512 |
* |
| 513 |
* If a backend is using clock_gettime(CLOCK_MONOTONIC), but not |
| 514 |
* picking values right at the vblank, then the presentation times |
| 515 |
* we compute won't be accurate, but not really worse than then |
| 516 |
* the alternative of not providing presentation times at all. |
| 517 |
* |
| 518 |
* The complexity here is dealing with the fact that we receive |
| 519 |
* only the low 32 bits of the CLOCK_MONOTONIC value in milliseconds. |
| 520 |
*/ |
| 521 |
gint64 now_monotonic = g_get_monotonic_time (); |
| 522 |
gint64 now_monotonic_msec = now_monotonic / 1000; |
| 523 |
uint32_t now_monotonic_low = (uint32_t)now_monotonic_msec; |
| 524 |
|
| 525 |
if (frame_time - now_monotonic_low < 1000 || |
| 526 |
frame_time - now_monotonic_low > (uint32_t)-1000) |
| 527 |
{ |
| 528 |
/* Timestamp we received is within one second of the current time. |
| 529 |
*/ |
| 530 |
gint64 last_frame_time = now_monotonic + (gint64)1000 * (gint32)(frame_time - now_monotonic_low); |
| 531 |
if ((gint32)now_monotonic_low < 0 && (gint32)frame_time > 0) |
| 532 |
last_frame_time += (gint64)1000 * G_GINT64_CONSTANT(0x100000000); |
| 533 |
else if ((gint32)now_monotonic_low > 0 && (gint32)frame_time < 0) |
| 534 |
last_frame_time -= (gint64)1000 * G_GINT64_CONSTANT(0x100000000); |
| 535 |
|
| 536 |
timings->presentation_time = last_frame_time + timings->refresh_interval; |
| 537 |
} |
| 538 |
} |
| 539 |
|
| 540 |
static void |
| 541 |
read_back_cairo_surface (GdkWindow *window) |
| 542 |
{ |
| 543 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 544 |
cairo_t *cr; |
| 545 |
cairo_region_t *paint_region = NULL; |
| 546 |
|
| 547 |
if (!impl->backfill_cairo_surface) |
| 548 |
goto out; |
| 549 |
|
| 550 |
paint_region = cairo_region_copy (window->clip_region); |
| 551 |
cairo_region_subtract (paint_region, impl->staged_updates_region); |
| 552 |
|
| 553 |
if (cairo_region_is_empty (paint_region)) |
| 554 |
goto out; |
| 555 |
|
| 556 |
cr = cairo_create (impl->staging_cairo_surface); |
| 557 |
cairo_set_source_surface (cr, impl->backfill_cairo_surface, 0, 0); |
| 558 |
gdk_cairo_region (cr, paint_region); |
| 559 |
cairo_clip (cr); |
| 560 |
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
| 561 |
cairo_paint (cr); |
| 562 |
cairo_destroy (cr); |
| 563 |
cairo_surface_flush (impl->staging_cairo_surface); |
| 564 |
|
| 565 |
out: |
| 566 |
g_clear_pointer (&paint_region, cairo_region_destroy); |
| 567 |
g_clear_pointer (&impl->staged_updates_region, cairo_region_destroy); |
| 568 |
g_clear_pointer (&impl->backfill_cairo_surface, cairo_surface_destroy); |
| 569 |
} |
| 570 |
|
| 571 |
static void |
| 572 |
frame_callback (void *data, |
| 573 |
struct wl_callback *callback, |
| 574 |
uint32_t time) |
| 575 |
{ |
| 576 |
GdkWindow *window = data; |
| 577 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 578 |
GdkWaylandDisplay *display_wayland = |
| 579 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 580 |
GdkFrameClock *clock = gdk_window_get_frame_clock (window); |
| 581 |
GdkFrameTimings *timings; |
| 582 |
|
| 583 |
if (callback == impl->surface_callback) |
| 584 |
{ |
| 585 |
impl->surface_callback = NULL; |
| 586 |
} |
| 587 |
else |
| 588 |
{ |
| 589 |
GHashTableIter iter; |
| 590 |
gpointer surface_callback; |
| 591 |
|
| 592 |
g_hash_table_iter_init (&iter, impl->frame_callback_surfaces); |
| 593 |
while (g_hash_table_iter_next (&iter, NULL, &surface_callback)) |
| 594 |
{ |
| 595 |
if (callback == surface_callback) |
| 596 |
{ |
| 597 |
g_hash_table_iter_replace (&iter, NULL); |
| 598 |
break; |
| 599 |
} |
| 600 |
} |
| 601 |
} |
| 602 |
wl_callback_destroy (callback); |
| 603 |
|
| 604 |
if (GDK_WINDOW_DESTROYED (window)) |
| 605 |
return; |
| 606 |
|
| 607 |
if (!impl->awaiting_frame) |
| 608 |
return; |
| 609 |
|
| 610 |
GDK_NOTE (EVENTS, |
| 611 |
g_message ("frame %p", window)); |
| 612 |
|
| 613 |
impl->awaiting_frame = FALSE; |
| 614 |
_gdk_frame_clock_thaw (clock); |
| 615 |
|
| 616 |
timings = gdk_frame_clock_get_timings (clock, impl->pending_frame_counter); |
| 617 |
impl->pending_frame_counter = 0; |
| 618 |
|
| 619 |
if (timings == NULL) |
| 620 |
return; |
| 621 |
|
| 622 |
timings->refresh_interval = 16667; /* default to 1/60th of a second */ |
| 623 |
if (impl->display_server.outputs) |
| 624 |
{ |
| 625 |
/* We pick a random output out of the outputs that the window touches |
| 626 |
* The rate here is in milli-hertz */ |
| 627 |
int refresh_rate = |
| 628 |
_gdk_wayland_screen_get_output_refresh_rate (display_wayland->screen, |
| 629 |
impl->display_server.outputs->data); |
| 630 |
if (refresh_rate != 0) |
| 631 |
timings->refresh_interval = G_GINT64_CONSTANT(1000000000) / refresh_rate; |
| 632 |
} |
| 633 |
|
| 634 |
fill_presentation_time_from_frame_time (timings, time); |
| 635 |
|
| 636 |
timings->complete = TRUE; |
| 637 |
|
| 638 |
#ifdef G_ENABLE_DEBUG |
| 639 |
if ((_gdk_debug_flags & GDK_DEBUG_FRAMES) != 0) |
| 640 |
_gdk_frame_clock_debug_print_timings (clock, timings); |
| 641 |
|
| 642 |
if (gdk_profiler_is_running ()) |
| 643 |
_gdk_frame_clock_add_timings_to_profiler (clock, timings); |
| 644 |
#endif |
| 645 |
} |
| 646 |
|
| 647 |
static const struct wl_callback_listener frame_listener = { |
| 648 |
frame_callback |
| 649 |
}; |
| 650 |
|
| 651 |
static void |
| 652 |
on_frame_clock_before_paint (GdkFrameClock *clock, |
| 653 |
GdkWindow *window) |
| 654 |
{ |
| 655 |
GdkFrameTimings *timings = gdk_frame_clock_get_current_timings (clock); |
| 656 |
gint64 presentation_time; |
| 657 |
gint64 refresh_interval; |
| 658 |
|
| 659 |
if (window->update_freeze_count > 0) |
| 660 |
return; |
| 661 |
|
| 662 |
gdk_frame_clock_get_refresh_info (clock, |
| 663 |
timings->frame_time, |
| 664 |
&refresh_interval, &presentation_time); |
| 665 |
|
| 666 |
if (presentation_time != 0) |
| 667 |
{ |
| 668 |
/* Assume the algorithm used by the DRM backend of Weston - it |
| 669 |
* starts drawing at the next vblank after receiving the commit |
| 670 |
* for this frame, and presentation occurs at the vblank |
| 671 |
* after that. |
| 672 |
*/ |
| 673 |
timings->predicted_presentation_time = presentation_time + refresh_interval; |
| 674 |
} |
| 675 |
else |
| 676 |
{ |
| 677 |
/* As above, but we don't actually know the phase of the vblank, |
| 678 |
* so just assume that we're half way through a refresh cycle. |
| 679 |
*/ |
| 680 |
timings->predicted_presentation_time = timings->frame_time + refresh_interval / 2 + refresh_interval; |
| 681 |
} |
| 682 |
} |
| 683 |
|
| 684 |
static void |
| 685 |
on_frame_clock_after_paint (GdkFrameClock *clock, |
| 686 |
GdkWindow *window) |
| 687 |
{ |
| 688 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 689 |
struct wl_callback *callback; |
| 690 |
GHashTableIter iter; |
| 691 |
gpointer surface, surface_callback; |
| 692 |
|
| 693 |
if (!impl->pending_commit) |
| 694 |
return; |
| 695 |
|
| 696 |
if (window->update_freeze_count > 0) |
| 697 |
return; |
| 698 |
|
| 699 |
_gdk_frame_clock_freeze (clock); |
| 700 |
|
| 701 |
/* Before we commit a new buffer, make sure we've backfilled |
| 702 |
* undrawn parts from any old committed buffer |
| 703 |
*/ |
| 704 |
if (impl->pending_buffer_attached) |
| 705 |
read_back_cairo_surface (window); |
| 706 |
|
| 707 |
if (impl->surface_callback == NULL) |
| 708 |
{ |
| 709 |
callback = wl_surface_frame (impl->display_server.wl_surface); |
| 710 |
wl_callback_add_listener (callback, &frame_listener, window); |
| 711 |
impl->surface_callback = callback; |
| 712 |
} |
| 713 |
|
| 714 |
g_hash_table_iter_init (&iter, impl->frame_callback_surfaces); |
| 715 |
while (g_hash_table_iter_next (&iter, &surface, &surface_callback)) |
| 716 |
{ |
| 717 |
if (surface_callback) |
| 718 |
continue; |
| 719 |
|
| 720 |
callback = wl_surface_frame (surface); |
| 721 |
wl_callback_add_listener (callback, &frame_listener, window); |
| 722 |
g_hash_table_iter_replace (&iter, callback); |
| 723 |
} |
| 724 |
|
| 725 |
/* From this commit forward, we can't write to the buffer, |
| 726 |
* it's "live". In the future, if we need to stage more changes |
| 727 |
* we have to allocate a new staging buffer and draw to it instead. |
| 728 |
* |
| 729 |
* Our one saving grace is if the compositor releases the buffer |
| 730 |
* before we need to stage any changes, then we can take it back and |
| 731 |
* use it again. |
| 732 |
*/ |
| 733 |
wl_surface_commit (impl->display_server.wl_surface); |
| 734 |
|
| 735 |
if (impl->pending_buffer_attached) |
| 736 |
impl->committed_cairo_surface = g_steal_pointer (&impl->staging_cairo_surface); |
| 737 |
|
| 738 |
impl->pending_buffer_attached = FALSE; |
| 739 |
impl->pending_commit = FALSE; |
| 740 |
impl->pending_frame_counter = gdk_frame_clock_get_frame_counter (clock); |
| 741 |
impl->awaiting_frame = TRUE; |
| 742 |
|
| 743 |
g_signal_emit (impl, signals[COMMITTED], 0); |
| 744 |
} |
| 745 |
|
| 746 |
static void |
| 747 |
window_update_scale (GdkWindow *window) |
| 748 |
{ |
| 749 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 750 |
GdkWaylandDisplay *display_wayland = |
| 751 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 752 |
guint32 scale; |
| 753 |
GSList *l; |
| 754 |
|
| 755 |
if (display_wayland->compositor_version < WL_SURFACE_HAS_BUFFER_SCALE) |
| 756 |
{ |
| 757 |
/* We can't set the scale on this surface */ |
| 758 |
return; |
| 759 |
} |
| 760 |
|
| 761 |
if (!impl->display_server.outputs) |
| 762 |
{ |
| 763 |
scale = impl->scale; |
| 764 |
} |
| 765 |
else |
| 766 |
{ |
| 767 |
scale = 1; |
| 768 |
for (l = impl->display_server.outputs; l != NULL; l = l->next) |
| 769 |
{ |
| 770 |
struct wl_output *output = l->data; |
| 771 |
uint32_t output_scale; |
| 772 |
|
| 773 |
output_scale = |
| 774 |
_gdk_wayland_screen_get_output_scale (display_wayland->screen, |
| 775 |
output); |
| 776 |
scale = MAX (scale, output_scale); |
| 777 |
} |
| 778 |
} |
| 779 |
|
| 780 |
/* Notify app that scale changed */ |
| 781 |
gdk_wayland_window_maybe_configure (window, window->width, window->height, scale); |
| 782 |
} |
| 783 |
|
| 784 |
static void |
| 785 |
on_monitors_changed (GdkScreen *screen, |
| 786 |
GdkWindow *window) |
| 787 |
{ |
| 788 |
window_update_scale (window); |
| 789 |
} |
| 790 |
|
| 791 |
|
| 792 |
static void gdk_wayland_window_create_surface (GdkWindow *window); |
| 793 |
|
| 794 |
void |
| 795 |
_gdk_wayland_display_create_window_impl (GdkDisplay *display, |
| 796 |
GdkWindow *window, |
| 797 |
GdkWindow *real_parent, |
| 798 |
GdkScreen *screen, |
| 799 |
GdkEventMask event_mask, |
| 800 |
GdkWindowAttr *attributes, |
| 801 |
gint attributes_mask) |
| 802 |
{ |
| 803 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display); |
| 804 |
GdkWindowImplWayland *impl; |
| 805 |
GdkFrameClock *frame_clock; |
| 806 |
const char *title; |
| 807 |
|
| 808 |
impl = g_object_new (GDK_TYPE_WINDOW_IMPL_WAYLAND, NULL); |
| 809 |
window->impl = GDK_WINDOW_IMPL (impl); |
| 810 |
impl->unconfigured_width = window->width; |
| 811 |
impl->unconfigured_height = window->height; |
| 812 |
impl->wrapper = GDK_WINDOW (window); |
| 813 |
impl->shortcuts_inhibitors = g_hash_table_new (NULL, NULL); |
| 814 |
impl->using_csd = TRUE; |
| 815 |
impl->surface_callback = NULL; |
| 816 |
impl->frame_callback_surfaces = g_hash_table_new (NULL, NULL); |
| 817 |
|
| 818 |
if (window->width > 65535) |
| 819 |
{ |
| 820 |
g_warning ("Native Windows wider than 65535 pixels are not supported"); |
| 821 |
window->width = 65535; |
| 822 |
} |
| 823 |
if (window->height > 65535) |
| 824 |
{ |
| 825 |
g_warning ("Native Windows taller than 65535 pixels are not supported"); |
| 826 |
window->height = 65535; |
| 827 |
} |
| 828 |
|
| 829 |
g_object_ref (window); |
| 830 |
|
| 831 |
/* More likely to be right than just assuming 1 */ |
| 832 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 833 |
if (display_wayland->compositor_version >= WL_SURFACE_HAS_BUFFER_SCALE && |
| 834 |
gdk_screen_get_n_monitors (screen) > 0) |
| 835 |
impl->scale = gdk_screen_get_monitor_scale_factor (screen, 0); |
| 836 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 837 |
|
| 838 |
impl->title = NULL; |
| 839 |
|
| 840 |
switch (GDK_WINDOW_TYPE (window)) |
| 841 |
{ |
| 842 |
case GDK_WINDOW_TOPLEVEL: |
| 843 |
case GDK_WINDOW_TEMP: |
| 844 |
if (attributes_mask & GDK_WA_TITLE) |
| 845 |
title = attributes->title; |
| 846 |
else |
| 847 |
title = get_default_title (); |
| 848 |
|
| 849 |
gdk_window_set_title (window, title); |
| 850 |
break; |
| 851 |
|
| 852 |
case GDK_WINDOW_CHILD: |
| 853 |
default: |
| 854 |
break; |
| 855 |
} |
| 856 |
|
| 857 |
gdk_wayland_window_create_surface (window); |
| 858 |
|
| 859 |
if (attributes_mask & GDK_WA_TYPE_HINT) |
| 860 |
gdk_window_set_type_hint (window, attributes->type_hint); |
| 861 |
|
| 862 |
frame_clock = gdk_window_get_frame_clock (window); |
| 863 |
|
| 864 |
g_signal_connect (frame_clock, "before-paint", |
| 865 |
G_CALLBACK (on_frame_clock_before_paint), window); |
| 866 |
g_signal_connect (frame_clock, "after-paint", |
| 867 |
G_CALLBACK (on_frame_clock_after_paint), window); |
| 868 |
|
| 869 |
g_signal_connect (screen, "monitors-changed", |
| 870 |
G_CALLBACK (on_monitors_changed), window); |
| 871 |
} |
| 872 |
|
| 873 |
static void |
| 874 |
gdk_wayland_window_attach_image (GdkWindow *window) |
| 875 |
{ |
| 876 |
GdkWaylandDisplay *display; |
| 877 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 878 |
|
| 879 |
if (GDK_WINDOW_DESTROYED (window)) |
| 880 |
return; |
| 881 |
|
| 882 |
g_assert (_gdk_wayland_is_shm_surface (impl->staging_cairo_surface)); |
| 883 |
|
| 884 |
/* Attach this new buffer to the surface */ |
| 885 |
wl_surface_attach (impl->display_server.wl_surface, |
| 886 |
_gdk_wayland_shm_surface_get_wl_buffer (impl->staging_cairo_surface), |
| 887 |
impl->pending_buffer_offset_x, |
| 888 |
impl->pending_buffer_offset_y); |
| 889 |
impl->pending_buffer_offset_x = 0; |
| 890 |
impl->pending_buffer_offset_y = 0; |
| 891 |
|
| 892 |
/* Only set the buffer scale if supported by the compositor */ |
| 893 |
display = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 894 |
if (display->compositor_version >= WL_SURFACE_HAS_BUFFER_SCALE) |
| 895 |
wl_surface_set_buffer_scale (impl->display_server.wl_surface, impl->scale); |
| 896 |
|
| 897 |
impl->pending_buffer_attached = TRUE; |
| 898 |
impl->pending_commit = TRUE; |
| 899 |
} |
| 900 |
|
| 901 |
static const cairo_user_data_key_t gdk_wayland_window_cairo_key; |
| 902 |
|
| 903 |
static void |
| 904 |
buffer_release_callback (void *_data, |
| 905 |
struct wl_buffer *wl_buffer) |
| 906 |
{ |
| 907 |
cairo_surface_t *cairo_surface = _data; |
| 908 |
GdkWindowImplWayland *impl = cairo_surface_get_user_data (cairo_surface, &gdk_wayland_window_cairo_key); |
| 909 |
|
| 910 |
g_return_if_fail (GDK_IS_WINDOW_IMPL_WAYLAND (impl)); |
| 911 |
|
| 912 |
/* The released buffer isn't the latest committed one, we have no further |
| 913 |
* use for it, so clean it up. |
| 914 |
*/ |
| 915 |
if (impl->committed_cairo_surface != cairo_surface) |
| 916 |
{ |
| 917 |
/* If this fails, then the surface buffer got reused before it was |
| 918 |
* released from the compositor |
| 919 |
*/ |
| 920 |
g_warn_if_fail (impl->staging_cairo_surface != cairo_surface); |
| 921 |
|
| 922 |
cairo_surface_destroy (cairo_surface); |
| 923 |
return; |
| 924 |
} |
| 925 |
|
| 926 |
if (impl->staged_updates_region != NULL) |
| 927 |
{ |
| 928 |
/* If this fails, then we're tracking staged updates on a staging surface |
| 929 |
* that doesn't exist. |
| 930 |
*/ |
| 931 |
g_warn_if_fail (impl->staging_cairo_surface != NULL); |
| 932 |
|
| 933 |
/* If we've staged updates into a new buffer before the release for this |
| 934 |
* buffer came in, then we can't reuse this buffer, so unref it. It may still |
| 935 |
* be alive as a readback buffer though (via impl->backfill_cairo_surface). |
| 936 |
* |
| 937 |
* It's possible a staging surface was allocated but no updates were staged. |
| 938 |
* If that happened, clean up that staging surface now, since the old commit |
| 939 |
* buffer is available again, and reusing the old commit buffer for future |
| 940 |
* updates will save having to do a read back later. |
| 941 |
*/ |
| 942 |
if (!cairo_region_is_empty (impl->staged_updates_region)) |
| 943 |
{ |
| 944 |
g_clear_pointer (&impl->committed_cairo_surface, cairo_surface_destroy); |
| 945 |
return; |
| 946 |
} |
| 947 |
else |
| 948 |
{ |
| 949 |
g_clear_pointer (&impl->staged_updates_region, cairo_region_destroy); |
| 950 |
g_clear_pointer (&impl->staging_cairo_surface, cairo_surface_destroy); |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
/* Release came in, we haven't done any interim updates, so we can just use |
| 955 |
* the old committed buffer again. |
| 956 |
*/ |
| 957 |
g_clear_pointer (&impl->staging_cairo_surface, cairo_surface_destroy); |
| 958 |
impl->staging_cairo_surface = g_steal_pointer (&impl->committed_cairo_surface); |
| 959 |
} |
| 960 |
|
| 961 |
static const struct wl_buffer_listener buffer_listener = { |
| 962 |
buffer_release_callback |
| 963 |
}; |
| 964 |
|
| 965 |
static void |
| 966 |
gdk_wayland_window_ensure_cairo_surface (GdkWindow *window) |
| 967 |
{ |
| 968 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 969 |
|
| 970 |
/* If we are drawing using OpenGL then we only need a logical 1x1 surface. */ |
| 971 |
if (impl->display_server.egl_window) |
| 972 |
{ |
| 973 |
if (impl->staging_cairo_surface && |
| 974 |
_gdk_wayland_is_shm_surface (impl->staging_cairo_surface)) |
| 975 |
g_clear_pointer (&impl->staging_cairo_surface, cairo_surface_destroy); |
| 976 |
|
| 977 |
if (!impl->staging_cairo_surface) |
| 978 |
{ |
| 979 |
impl->staging_cairo_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, |
| 980 |
impl->scale, |
| 981 |
impl->scale); |
| 982 |
cairo_surface_set_device_scale (impl->staging_cairo_surface, |
| 983 |
impl->scale, impl->scale); |
| 984 |
} |
| 985 |
} |
| 986 |
else if (!impl->staging_cairo_surface) |
| 987 |
{ |
| 988 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (gdk_window_get_display (impl->wrapper)); |
| 989 |
struct wl_buffer *buffer; |
| 990 |
|
| 991 |
impl->staging_cairo_surface = _gdk_wayland_display_create_shm_surface (display_wayland, |
| 992 |
impl->wrapper->width, |
| 993 |
impl->wrapper->height, |
| 994 |
impl->scale); |
| 995 |
cairo_surface_set_user_data (impl->staging_cairo_surface, |
| 996 |
&gdk_wayland_window_cairo_key, |
| 997 |
g_object_ref (impl), |
| 998 |
(cairo_destroy_func_t) |
| 999 |
g_object_unref); |
| 1000 |
buffer = _gdk_wayland_shm_surface_get_wl_buffer (impl->staging_cairo_surface); |
| 1001 |
wl_buffer_add_listener (buffer, &buffer_listener, impl->staging_cairo_surface); |
| 1002 |
} |
| 1003 |
} |
| 1004 |
|
| 1005 |
/* The cairo surface returned here uses a memory segment that's shared |
| 1006 |
* with the display server. This is not a temporary buffer that gets |
| 1007 |
* copied to the display server, but the actual buffer the display server |
| 1008 |
* will ultimately end up sending to the GPU. At the time this happens |
| 1009 |
* impl->committed_cairo_surface gets set to impl->staging_cairo_surface, and |
| 1010 |
* impl->staging_cairo_surface gets nullified. |
| 1011 |
*/ |
| 1012 |
static cairo_surface_t * |
| 1013 |
gdk_wayland_window_ref_cairo_surface (GdkWindow *window) |
| 1014 |
{ |
| 1015 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1016 |
|
| 1017 |
if (GDK_WINDOW_DESTROYED (impl->wrapper)) |
| 1018 |
return NULL; |
| 1019 |
|
| 1020 |
gdk_wayland_window_ensure_cairo_surface (window); |
| 1021 |
|
| 1022 |
cairo_surface_reference (impl->staging_cairo_surface); |
| 1023 |
|
| 1024 |
return impl->staging_cairo_surface; |
| 1025 |
} |
| 1026 |
|
| 1027 |
static cairo_surface_t * |
| 1028 |
gdk_wayland_window_create_similar_image_surface (GdkWindow * window, |
| 1029 |
cairo_format_t format, |
| 1030 |
int width, |
| 1031 |
int height) |
| 1032 |
{ |
| 1033 |
return cairo_image_surface_create (format, width, height); |
| 1034 |
} |
| 1035 |
|
| 1036 |
static gboolean |
| 1037 |
gdk_window_impl_wayland_begin_paint (GdkWindow *window) |
| 1038 |
{ |
| 1039 |
gdk_wayland_window_ensure_cairo_surface (window); |
| 1040 |
|
| 1041 |
return FALSE; |
| 1042 |
} |
| 1043 |
|
| 1044 |
static void |
| 1045 |
gdk_window_impl_wayland_end_paint (GdkWindow *window) |
| 1046 |
{ |
| 1047 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1048 |
cairo_rectangle_int_t rect; |
| 1049 |
int i, n; |
| 1050 |
|
| 1051 |
if (!GDK_WINDOW_IS_MAPPED (window)) |
| 1052 |
return; |
| 1053 |
|
| 1054 |
if (impl->staging_cairo_surface && |
| 1055 |
_gdk_wayland_is_shm_surface (impl->staging_cairo_surface) && |
| 1056 |
!window->current_paint.use_gl && |
| 1057 |
!cairo_region_is_empty (window->current_paint.region)) |
| 1058 |
{ |
| 1059 |
gdk_wayland_window_attach_image (window); |
| 1060 |
|
| 1061 |
/* If there's a committed buffer pending, then track which |
| 1062 |
* updates are staged until the next frame, so we can back |
| 1063 |
* fill the unstaged parts of the staging buffer with the |
| 1064 |
* last frame. |
| 1065 |
*/ |
| 1066 |
if (impl->committed_cairo_surface != NULL) |
| 1067 |
{ |
| 1068 |
if (impl->staged_updates_region == NULL) |
| 1069 |
{ |
| 1070 |
impl->staged_updates_region = cairo_region_copy (window->current_paint.region); |
| 1071 |
impl->backfill_cairo_surface = cairo_surface_reference (impl->committed_cairo_surface); |
| 1072 |
} |
| 1073 |
else |
| 1074 |
{ |
| 1075 |
cairo_region_union (impl->staged_updates_region, window->current_paint.region); |
| 1076 |
} |
| 1077 |
} |
| 1078 |
|
| 1079 |
n = cairo_region_num_rectangles (window->current_paint.region); |
| 1080 |
for (i = 0; i < n; i++) |
| 1081 |
{ |
| 1082 |
cairo_region_get_rectangle (window->current_paint.region, i, &rect); |
| 1083 |
wl_surface_damage (impl->display_server.wl_surface, rect.x, rect.y, rect.width, rect.height); |
| 1084 |
} |
| 1085 |
|
| 1086 |
impl->pending_commit = TRUE; |
| 1087 |
} |
| 1088 |
else if (window->current_paint.use_gl && |
| 1089 |
window->current_paint.surface_needs_composite && |
| 1090 |
impl->pending_commit) |
| 1091 |
{ |
| 1092 |
/* Discard issuing pending commit, as when we reach here, it means it'll |
| 1093 |
* be done implicitly by eglSwapBuffers(). */ |
| 1094 |
impl->pending_commit = FALSE; |
| 1095 |
} |
| 1096 |
|
| 1097 |
gdk_wayland_window_sync_margin (window); |
| 1098 |
gdk_wayland_window_sync_opaque_region (window); |
| 1099 |
gdk_wayland_window_sync_input_region (window); |
| 1100 |
} |
| 1101 |
|
| 1102 |
static gboolean |
| 1103 |
gdk_window_impl_wayland_beep (GdkWindow *window) |
| 1104 |
{ |
| 1105 |
gdk_wayland_display_system_bell (gdk_window_get_display (window), |
| 1106 |
window); |
| 1107 |
|
| 1108 |
return TRUE; |
| 1109 |
} |
| 1110 |
|
| 1111 |
static void |
| 1112 |
gdk_window_impl_wayland_finalize (GObject *object) |
| 1113 |
{ |
| 1114 |
GdkWindowImplWayland *impl; |
| 1115 |
|
| 1116 |
g_return_if_fail (GDK_IS_WINDOW_IMPL_WAYLAND (object)); |
| 1117 |
|
| 1118 |
impl = GDK_WINDOW_IMPL_WAYLAND (object); |
| 1119 |
|
| 1120 |
if (gdk_wayland_window_is_exported (impl->wrapper)) |
| 1121 |
gdk_wayland_window_unexport_handle (impl->wrapper); |
| 1122 |
|
| 1123 |
g_free (impl->title); |
| 1124 |
|
| 1125 |
g_free (impl->application.application_id); |
| 1126 |
g_free (impl->application.app_menu_path); |
| 1127 |
g_free (impl->application.menubar_path); |
| 1128 |
g_free (impl->application.window_object_path); |
| 1129 |
g_free (impl->application.application_object_path); |
| 1130 |
g_free (impl->application.unique_bus_name); |
| 1131 |
|
| 1132 |
g_clear_pointer (&impl->opaque_region, cairo_region_destroy); |
| 1133 |
g_clear_pointer (&impl->input_region, cairo_region_destroy); |
| 1134 |
g_clear_pointer (&impl->staged_updates_region, cairo_region_destroy); |
| 1135 |
|
| 1136 |
g_clear_pointer (&impl->shortcuts_inhibitors, g_hash_table_unref); |
| 1137 |
g_clear_pointer (&impl->frame_callback_surfaces, g_hash_table_unref); |
| 1138 |
|
| 1139 |
G_OBJECT_CLASS (_gdk_window_impl_wayland_parent_class)->finalize (object); |
| 1140 |
} |
| 1141 |
|
| 1142 |
static void |
| 1143 |
gdk_wayland_window_configure (GdkWindow *window, |
| 1144 |
int width, |
| 1145 |
int height, |
| 1146 |
int scale) |
| 1147 |
{ |
| 1148 |
GdkDisplay *display; |
| 1149 |
GdkEvent *event; |
| 1150 |
|
| 1151 |
g_return_if_fail (width > 0); |
| 1152 |
g_return_if_fail (height > 0); |
| 1153 |
|
| 1154 |
event = gdk_event_new (GDK_CONFIGURE); |
| 1155 |
event->configure.window = g_object_ref (window); |
| 1156 |
event->configure.send_event = FALSE; |
| 1157 |
event->configure.width = width; |
| 1158 |
event->configure.height = height; |
| 1159 |
|
| 1160 |
gdk_wayland_window_update_size (window, width, height, scale); |
| 1161 |
_gdk_window_update_size (window); |
| 1162 |
|
| 1163 |
display = gdk_window_get_display (window); |
| 1164 |
_gdk_wayland_display_deliver_event (display, event); |
| 1165 |
} |
| 1166 |
|
| 1167 |
static gboolean |
| 1168 |
is_realized_shell_surface (GdkWindow *window) |
| 1169 |
{ |
| 1170 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1171 |
|
| 1172 |
return (impl->display_server.xdg_surface || |
| 1173 |
impl->display_server.zxdg_surface_v6); |
| 1174 |
} |
| 1175 |
|
| 1176 |
static gboolean |
| 1177 |
is_realized_toplevel (GdkWindow *window) |
| 1178 |
{ |
| 1179 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1180 |
|
| 1181 |
return (impl->display_server.xdg_toplevel || |
| 1182 |
impl->display_server.zxdg_toplevel_v6); |
| 1183 |
} |
| 1184 |
|
| 1185 |
static gboolean |
| 1186 |
is_realized_popup (GdkWindow *window) |
| 1187 |
{ |
| 1188 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1189 |
|
| 1190 |
return (impl->display_server.xdg_popup || |
| 1191 |
impl->display_server.zxdg_popup_v6); |
| 1192 |
} |
| 1193 |
|
| 1194 |
static gboolean |
| 1195 |
should_inhibit_resize (GdkWindow *window) |
| 1196 |
{ |
| 1197 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1198 |
|
| 1199 |
if (impl->display_server.wl_subsurface) |
| 1200 |
return FALSE; |
| 1201 |
else if (impl->use_custom_surface) |
| 1202 |
return FALSE; |
| 1203 |
else if (impl->hint == GDK_WINDOW_TYPE_HINT_DND) |
| 1204 |
return FALSE; |
| 1205 |
else if (is_realized_popup (window)) |
| 1206 |
return FALSE; |
| 1207 |
else if (should_map_as_popup (window)) |
| 1208 |
return FALSE; |
| 1209 |
else if (should_map_as_subsurface (window)) |
| 1210 |
return FALSE; |
| 1211 |
|
| 1212 |
/* This should now either be, or eventually be, a toplevel window, |
| 1213 |
* and we should wait for the initial configure to really configure it. |
| 1214 |
*/ |
| 1215 |
return !impl->initial_configure_received; |
| 1216 |
} |
| 1217 |
|
| 1218 |
static void |
| 1219 |
gdk_wayland_window_maybe_configure (GdkWindow *window, |
| 1220 |
int width, |
| 1221 |
int height, |
| 1222 |
int scale) |
| 1223 |
{ |
| 1224 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1225 |
gboolean is_xdg_popup; |
| 1226 |
gboolean is_visible; |
| 1227 |
gboolean size_changed; |
| 1228 |
|
| 1229 |
impl->unconfigured_width = calculate_width_without_margin (window, width); |
| 1230 |
impl->unconfigured_height = calculate_height_without_margin (window, height); |
| 1231 |
|
| 1232 |
if (should_inhibit_resize (window)) |
| 1233 |
return; |
| 1234 |
|
| 1235 |
size_changed = (window->width != width || window->height != height); |
| 1236 |
if (!size_changed && impl->scale == scale) |
| 1237 |
return; |
| 1238 |
|
| 1239 |
/* For xdg_popup using an xdg_positioner, there is a race condition if |
| 1240 |
* the application tries to change the size after it's mapped, but before |
| 1241 |
* the initial configure is received, so hide and show the surface again |
| 1242 |
* force the new size onto the compositor. See bug #772505. |
| 1243 |
*/ |
| 1244 |
|
| 1245 |
is_xdg_popup = is_realized_popup (window); |
| 1246 |
is_visible = gdk_window_is_visible (window); |
| 1247 |
|
| 1248 |
if (is_xdg_popup && |
| 1249 |
is_visible && |
| 1250 |
size_changed && |
| 1251 |
!impl->initial_configure_received && |
| 1252 |
!impl->configuring_popup) |
| 1253 |
gdk_window_hide (window); |
| 1254 |
|
| 1255 |
gdk_wayland_window_configure (window, width, height, scale); |
| 1256 |
|
| 1257 |
if (is_xdg_popup && |
| 1258 |
is_visible && |
| 1259 |
size_changed && |
| 1260 |
!impl->initial_configure_received && |
| 1261 |
!impl->configuring_popup) |
| 1262 |
gdk_window_show (window); |
| 1263 |
} |
| 1264 |
|
| 1265 |
static void |
| 1266 |
gdk_wayland_window_sync_parent (GdkWindow *window, |
| 1267 |
GdkWindow *parent) |
| 1268 |
{ |
| 1269 |
GdkWaylandDisplay *display_wayland = |
| 1270 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 1271 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1272 |
GdkWindowImplWayland *impl_parent = NULL; |
| 1273 |
|
| 1274 |
g_assert (parent == NULL || |
| 1275 |
gdk_window_get_display (window) == gdk_window_get_display (parent)); |
| 1276 |
|
| 1277 |
if (!is_realized_toplevel (window)) |
| 1278 |
return; |
| 1279 |
|
| 1280 |
if (impl->transient_for) |
| 1281 |
impl_parent = GDK_WINDOW_IMPL_WAYLAND (impl->transient_for->impl); |
| 1282 |
else if (parent) |
| 1283 |
impl_parent = GDK_WINDOW_IMPL_WAYLAND (parent->impl); |
| 1284 |
|
| 1285 |
/* XXX: Is this correct? */ |
| 1286 |
if (impl_parent && !impl_parent->display_server.wl_surface) |
| 1287 |
return; |
| 1288 |
|
| 1289 |
switch (display_wayland->shell_variant) |
| 1290 |
{ |
| 1291 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 1292 |
{ |
| 1293 |
struct xdg_toplevel *parent_toplevel; |
| 1294 |
|
| 1295 |
if (impl_parent) |
| 1296 |
parent_toplevel = impl_parent->display_server.xdg_toplevel; |
| 1297 |
else |
| 1298 |
parent_toplevel = NULL; |
| 1299 |
|
| 1300 |
xdg_toplevel_set_parent (impl->display_server.xdg_toplevel, |
| 1301 |
parent_toplevel); |
| 1302 |
break; |
| 1303 |
} |
| 1304 |
break; |
| 1305 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 1306 |
{ |
| 1307 |
struct zxdg_toplevel_v6 *parent_toplevel; |
| 1308 |
|
| 1309 |
if (impl_parent) |
| 1310 |
parent_toplevel = impl_parent->display_server.zxdg_toplevel_v6; |
| 1311 |
else |
| 1312 |
parent_toplevel = NULL; |
| 1313 |
|
| 1314 |
zxdg_toplevel_v6_set_parent (impl->display_server.zxdg_toplevel_v6, |
| 1315 |
parent_toplevel); |
| 1316 |
break; |
| 1317 |
} |
| 1318 |
} |
| 1319 |
} |
| 1320 |
|
| 1321 |
static void |
| 1322 |
gdk_wayland_window_sync_parent_of_imported (GdkWindow *window) |
| 1323 |
{ |
| 1324 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1325 |
|
| 1326 |
if (!impl->display_server.wl_surface) |
| 1327 |
return; |
| 1328 |
|
| 1329 |
if (!is_realized_toplevel (window)) |
| 1330 |
return; |
| 1331 |
|
| 1332 |
if (impl->imported_v2_transient_for) |
| 1333 |
{ |
| 1334 |
zxdg_imported_v2_set_parent_of (impl->imported_v2_transient_for, |
| 1335 |
impl->display_server.wl_surface); |
| 1336 |
} |
| 1337 |
else if (impl->imported_v1_transient_for) |
| 1338 |
{ |
| 1339 |
zxdg_imported_v1_set_parent_of (impl->imported_v1_transient_for, |
| 1340 |
impl->display_server.wl_surface); |
| 1341 |
} |
| 1342 |
} |
| 1343 |
|
| 1344 |
static void |
| 1345 |
gdk_wayland_window_update_dialogs (GdkWindow *window) |
| 1346 |
{ |
| 1347 |
GdkWaylandDisplay *display_wayland = |
| 1348 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 1349 |
GList *l; |
| 1350 |
|
| 1351 |
if (!display_wayland->orphan_dialogs) |
| 1352 |
return; |
| 1353 |
|
| 1354 |
for (l = display_wayland->orphan_dialogs; l; l = l->next) |
| 1355 |
{ |
| 1356 |
GdkWindow *w = l->data; |
| 1357 |
GdkWindowImplWayland *impl; |
| 1358 |
|
| 1359 |
if (!GDK_IS_WINDOW_IMPL_WAYLAND(w->impl)) |
| 1360 |
continue; |
| 1361 |
|
| 1362 |
impl = GDK_WINDOW_IMPL_WAYLAND (w->impl); |
| 1363 |
if (w == window) |
| 1364 |
continue; |
| 1365 |
if (impl->hint != GDK_WINDOW_TYPE_HINT_DIALOG) |
| 1366 |
continue; |
| 1367 |
if (impl->transient_for) |
| 1368 |
continue; |
| 1369 |
|
| 1370 |
/* Update the parent relationship only for dialogs without transients */ |
| 1371 |
gdk_wayland_window_sync_parent (w, window); |
| 1372 |
} |
| 1373 |
} |
| 1374 |
|
| 1375 |
static void |
| 1376 |
gdk_wayland_window_sync_title (GdkWindow *window) |
| 1377 |
{ |
| 1378 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1379 |
GdkWaylandDisplay *display_wayland = |
| 1380 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 1381 |
|
| 1382 |
if (!is_realized_toplevel (window)) |
| 1383 |
return; |
| 1384 |
|
| 1385 |
if (!impl->title) |
| 1386 |
return; |
| 1387 |
|
| 1388 |
switch (display_wayland->shell_variant) |
| 1389 |
{ |
| 1390 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 1391 |
xdg_toplevel_set_title (impl->display_server.xdg_toplevel, |
| 1392 |
impl->title); |
| 1393 |
break; |
| 1394 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 1395 |
zxdg_toplevel_v6_set_title (impl->display_server.zxdg_toplevel_v6, |
| 1396 |
impl->title); |
| 1397 |
break; |
| 1398 |
} |
| 1399 |
} |
| 1400 |
|
| 1401 |
static void |
| 1402 |
gdk_wayland_window_get_window_geometry (GdkWindow *window, |
| 1403 |
GdkRectangle *geometry) |
| 1404 |
{ |
| 1405 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1406 |
|
| 1407 |
*geometry = (GdkRectangle) { |
| 1408 |
.x = impl->margin_left, |
| 1409 |
.y = impl->margin_top, |
| 1410 |
.width = calculate_width_without_margin (window, window->width), |
| 1411 |
.height = calculate_height_without_margin (window, window->height) |
| 1412 |
}; |
| 1413 |
} |
| 1414 |
|
| 1415 |
static void |
| 1416 |
gdk_wayland_window_sync_margin (GdkWindow *window) |
| 1417 |
{ |
| 1418 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1419 |
GdkWaylandDisplay *display_wayland = |
| 1420 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 1421 |
GdkRectangle geometry; |
| 1422 |
|
| 1423 |
if (!is_realized_shell_surface (window)) |
| 1424 |
return; |
| 1425 |
|
| 1426 |
gdk_wayland_window_get_window_geometry (window, &geometry); |
| 1427 |
|
| 1428 |
g_return_if_fail (geometry.width > 0 && geometry.height > 0); |
| 1429 |
|
| 1430 |
gdk_window_set_geometry_hints (window, |
| 1431 |
&impl->geometry_hints, |
| 1432 |
impl->geometry_mask); |
| 1433 |
|
| 1434 |
switch (display_wayland->shell_variant) |
| 1435 |
{ |
| 1436 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 1437 |
xdg_surface_set_window_geometry (impl->display_server.xdg_surface, |
| 1438 |
geometry.x, |
| 1439 |
geometry.y, |
| 1440 |
geometry.width, |
| 1441 |
geometry.height); |
| 1442 |
break; |
| 1443 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 1444 |
zxdg_surface_v6_set_window_geometry (impl->display_server.zxdg_surface_v6, |
| 1445 |
geometry.x, |
| 1446 |
geometry.y, |
| 1447 |
geometry.width, |
| 1448 |
geometry.height); |
| 1449 |
break; |
| 1450 |
} |
| 1451 |
} |
| 1452 |
|
| 1453 |
static struct wl_region * |
| 1454 |
wl_region_from_cairo_region (GdkWaylandDisplay *display, |
| 1455 |
cairo_region_t *region) |
| 1456 |
{ |
| 1457 |
struct wl_region *wl_region; |
| 1458 |
int i, n_rects; |
| 1459 |
|
| 1460 |
wl_region = wl_compositor_create_region (display->compositor); |
| 1461 |
if (wl_region == NULL) |
| 1462 |
return NULL; |
| 1463 |
|
| 1464 |
n_rects = cairo_region_num_rectangles (region); |
| 1465 |
for (i = 0; i < n_rects; i++) |
| 1466 |
{ |
| 1467 |
cairo_rectangle_int_t rect; |
| 1468 |
cairo_region_get_rectangle (region, i, &rect); |
| 1469 |
wl_region_add (wl_region, rect.x, rect.y, rect.width, rect.height); |
| 1470 |
} |
| 1471 |
|
| 1472 |
return wl_region; |
| 1473 |
} |
| 1474 |
|
| 1475 |
static void |
| 1476 |
gdk_wayland_window_sync_opaque_region (GdkWindow *window) |
| 1477 |
{ |
| 1478 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1479 |
struct wl_region *wl_region = NULL; |
| 1480 |
|
| 1481 |
if (!impl->display_server.wl_surface) |
| 1482 |
return; |
| 1483 |
|
| 1484 |
if (!impl->opaque_region_dirty) |
| 1485 |
return; |
| 1486 |
|
| 1487 |
if (impl->opaque_region != NULL) |
| 1488 |
wl_region = wl_region_from_cairo_region (GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)), |
| 1489 |
impl->opaque_region); |
| 1490 |
|
| 1491 |
wl_surface_set_opaque_region (impl->display_server.wl_surface, wl_region); |
| 1492 |
|
| 1493 |
if (wl_region != NULL) |
| 1494 |
wl_region_destroy (wl_region); |
| 1495 |
|
| 1496 |
impl->opaque_region_dirty = FALSE; |
| 1497 |
} |
| 1498 |
|
| 1499 |
static void |
| 1500 |
gdk_wayland_window_sync_input_region (GdkWindow *window) |
| 1501 |
{ |
| 1502 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1503 |
struct wl_region *wl_region = NULL; |
| 1504 |
|
| 1505 |
if (!impl->display_server.wl_surface) |
| 1506 |
return; |
| 1507 |
|
| 1508 |
if (!impl->input_region_dirty) |
| 1509 |
return; |
| 1510 |
|
| 1511 |
if (impl->input_region != NULL) |
| 1512 |
wl_region = wl_region_from_cairo_region (GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)), |
| 1513 |
impl->input_region); |
| 1514 |
|
| 1515 |
wl_surface_set_input_region (impl->display_server.wl_surface, wl_region); |
| 1516 |
|
| 1517 |
if (wl_region != NULL) |
| 1518 |
wl_region_destroy (wl_region); |
| 1519 |
|
| 1520 |
impl->input_region_dirty = FALSE; |
| 1521 |
} |
| 1522 |
|
| 1523 |
static void |
| 1524 |
gdk_wayland_set_input_region_if_empty (GdkWindow *window) |
| 1525 |
{ |
| 1526 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1527 |
GdkWaylandDisplay *display; |
| 1528 |
struct wl_region *empty; |
| 1529 |
|
| 1530 |
if (!impl->input_region_dirty) |
| 1531 |
return; |
| 1532 |
|
| 1533 |
if (impl->input_region == NULL) |
| 1534 |
return; |
| 1535 |
|
| 1536 |
if (!cairo_region_is_empty (impl->input_region)) |
| 1537 |
return; |
| 1538 |
|
| 1539 |
display = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 1540 |
empty = wl_compositor_create_region (display->compositor); |
| 1541 |
|
| 1542 |
wl_surface_set_input_region (impl->display_server.wl_surface, empty); |
| 1543 |
wl_region_destroy (empty); |
| 1544 |
|
| 1545 |
impl->input_region_dirty = FALSE; |
| 1546 |
} |
| 1547 |
|
| 1548 |
static void |
| 1549 |
surface_enter (void *data, |
| 1550 |
struct wl_surface *wl_surface, |
| 1551 |
struct wl_output *output) |
| 1552 |
{ |
| 1553 |
GdkWindow *window = GDK_WINDOW (data); |
| 1554 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1555 |
GdkWaylandDisplay *display_wayland = |
| 1556 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 1557 |
gboolean output_is_unmanaged; |
| 1558 |
|
| 1559 |
output_is_unmanaged = |
| 1560 |
_gdk_wayland_screen_get_output_scale (display_wayland->screen, output) == 0; |
| 1561 |
if (output_is_unmanaged) |
| 1562 |
return; |
| 1563 |
|
| 1564 |
GDK_NOTE (EVENTS, |
| 1565 |
g_message ("surface enter, window %p output %p", window, output)); |
| 1566 |
|
| 1567 |
impl->display_server.outputs = g_slist_prepend (impl->display_server.outputs, output); |
| 1568 |
|
| 1569 |
window_update_scale (window); |
| 1570 |
} |
| 1571 |
|
| 1572 |
static void |
| 1573 |
surface_leave (void *data, |
| 1574 |
struct wl_surface *wl_surface, |
| 1575 |
struct wl_output *output) |
| 1576 |
{ |
| 1577 |
GdkWindow *window = GDK_WINDOW (data); |
| 1578 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1579 |
|
| 1580 |
GDK_NOTE (EVENTS, |
| 1581 |
g_message ("surface leave, window %p output %p", window, output)); |
| 1582 |
|
| 1583 |
impl->display_server.outputs = g_slist_remove (impl->display_server.outputs, output); |
| 1584 |
|
| 1585 |
if (impl->display_server.outputs) |
| 1586 |
window_update_scale (window); |
| 1587 |
} |
| 1588 |
|
| 1589 |
static const struct wl_surface_listener surface_listener = { |
| 1590 |
surface_enter, |
| 1591 |
surface_leave |
| 1592 |
}; |
| 1593 |
|
| 1594 |
static void |
| 1595 |
on_parent_surface_committed (GdkWindowImplWayland *parent_impl, |
| 1596 |
GdkWindow *window) |
| 1597 |
{ |
| 1598 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1599 |
|
| 1600 |
g_signal_handler_disconnect (parent_impl, |
| 1601 |
impl->parent_surface_committed_handler); |
| 1602 |
impl->parent_surface_committed_handler = 0; |
| 1603 |
|
| 1604 |
wl_subsurface_set_desync (impl->display_server.wl_subsurface); |
| 1605 |
|
| 1606 |
/* Special case if the input region is empty, it won't change on resize */ |
| 1607 |
gdk_wayland_set_input_region_if_empty (window); |
| 1608 |
} |
| 1609 |
|
| 1610 |
static void |
| 1611 |
gdk_wayland_window_set_subsurface_position (GdkWindow *window, |
| 1612 |
int x, |
| 1613 |
int y) |
| 1614 |
{ |
| 1615 |
GdkWindowImplWayland *impl; |
| 1616 |
|
| 1617 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1618 |
|
| 1619 |
wl_subsurface_set_position (impl->display_server.wl_subsurface, x, y); |
| 1620 |
impl->subsurface_x = x; |
| 1621 |
impl->subsurface_y = y; |
| 1622 |
|
| 1623 |
gdk_window_request_transient_parent_commit (window); |
| 1624 |
} |
| 1625 |
|
| 1626 |
static void |
| 1627 |
gdk_wayland_window_create_subsurface (GdkWindow *window) |
| 1628 |
{ |
| 1629 |
GdkWindowImplWayland *impl, *parent_impl = NULL; |
| 1630 |
GdkWaylandDisplay *display_wayland; |
| 1631 |
|
| 1632 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1633 |
|
| 1634 |
if (!impl->display_server.wl_surface) |
| 1635 |
return; /* Bail out, surface and subsurface will be created later when shown */ |
| 1636 |
|
| 1637 |
if (impl->display_server.wl_subsurface) |
| 1638 |
return; |
| 1639 |
|
| 1640 |
if (impl->transient_for) |
| 1641 |
parent_impl = GDK_WINDOW_IMPL_WAYLAND (impl->transient_for->impl); |
| 1642 |
|
| 1643 |
if (parent_impl && parent_impl->display_server.wl_surface) |
| 1644 |
{ |
| 1645 |
display_wayland = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 1646 |
impl->display_server.wl_subsurface = |
| 1647 |
wl_subcompositor_get_subsurface (display_wayland->subcompositor, |
| 1648 |
impl->display_server.wl_surface, parent_impl->display_server.wl_surface); |
| 1649 |
|
| 1650 |
/* In order to synchronize the initial position with the initial frame |
| 1651 |
* content, wait with making the subsurface desynchronized until after |
| 1652 |
* the parent was committed. |
| 1653 |
*/ |
| 1654 |
impl->parent_surface_committed_handler = |
| 1655 |
g_signal_connect_object (parent_impl, "committed", |
| 1656 |
G_CALLBACK (on_parent_surface_committed), |
| 1657 |
window, 0); |
| 1658 |
|
| 1659 |
gdk_wayland_window_set_subsurface_position (window, |
| 1660 |
window->x + window->abs_x, |
| 1661 |
window->y + window->abs_y); |
| 1662 |
} |
| 1663 |
} |
| 1664 |
|
| 1665 |
static void |
| 1666 |
gdk_wayland_window_create_surface (GdkWindow *window) |
| 1667 |
{ |
| 1668 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1669 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 1670 |
|
| 1671 |
impl->display_server.wl_surface = wl_compositor_create_surface (display_wayland->compositor); |
| 1672 |
wl_surface_add_listener (impl->display_server.wl_surface, &surface_listener, window); |
| 1673 |
} |
| 1674 |
|
| 1675 |
static gboolean |
| 1676 |
should_use_fixed_size (GdkWindowState state) |
| 1677 |
{ |
| 1678 |
return state & (GDK_WINDOW_STATE_MAXIMIZED | |
| 1679 |
GDK_WINDOW_STATE_FULLSCREEN | |
| 1680 |
GDK_WINDOW_STATE_TILED); |
| 1681 |
} |
| 1682 |
|
| 1683 |
static gboolean |
| 1684 |
has_per_edge_tiling_info (GdkWindowState state) |
| 1685 |
{ |
| 1686 |
return state & (GDK_WINDOW_STATE_TOP_TILED | |
| 1687 |
GDK_WINDOW_STATE_RIGHT_TILED | |
| 1688 |
GDK_WINDOW_STATE_BOTTOM_TILED | |
| 1689 |
GDK_WINDOW_STATE_LEFT_TILED); |
| 1690 |
} |
| 1691 |
|
| 1692 |
static GdkWindowState |
| 1693 |
infer_edge_constraints (GdkWindowState state) |
| 1694 |
{ |
| 1695 |
if (state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)) |
| 1696 |
return state; |
| 1697 |
|
| 1698 |
if (!(state & GDK_WINDOW_STATE_TILED) || !has_per_edge_tiling_info (state)) |
| 1699 |
return state | |
| 1700 |
GDK_WINDOW_STATE_TOP_RESIZABLE | |
| 1701 |
GDK_WINDOW_STATE_RIGHT_RESIZABLE | |
| 1702 |
GDK_WINDOW_STATE_BOTTOM_RESIZABLE | |
| 1703 |
GDK_WINDOW_STATE_LEFT_RESIZABLE; |
| 1704 |
|
| 1705 |
if (!(state & GDK_WINDOW_STATE_TOP_TILED)) |
| 1706 |
state |= GDK_WINDOW_STATE_TOP_RESIZABLE; |
| 1707 |
if (!(state & GDK_WINDOW_STATE_RIGHT_TILED)) |
| 1708 |
state |= GDK_WINDOW_STATE_RIGHT_RESIZABLE; |
| 1709 |
if (!(state & GDK_WINDOW_STATE_BOTTOM_TILED)) |
| 1710 |
state |= GDK_WINDOW_STATE_BOTTOM_RESIZABLE; |
| 1711 |
if (!(state & GDK_WINDOW_STATE_LEFT_TILED)) |
| 1712 |
state |= GDK_WINDOW_STATE_LEFT_RESIZABLE; |
| 1713 |
|
| 1714 |
return state; |
| 1715 |
} |
| 1716 |
|
| 1717 |
static gboolean |
| 1718 |
supports_native_edge_constraints (GdkWindowImplWayland *impl) |
| 1719 |
{ |
| 1720 |
struct gtk_surface1 *gtk_surface = impl->display_server.gtk_surface; |
| 1721 |
if (!gtk_surface) |
| 1722 |
return FALSE; |
| 1723 |
return gtk_surface1_get_version (gtk_surface) >= GTK_SURFACE1_CONFIGURE_EDGES_SINCE_VERSION; |
| 1724 |
} |
| 1725 |
|
| 1726 |
static void |
| 1727 |
gdk_wayland_window_handle_configure (GdkWindow *window, |
| 1728 |
uint32_t serial) |
| 1729 |
{ |
| 1730 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1731 |
GdkWaylandDisplay *display_wayland = |
| 1732 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 1733 |
GdkFrameClock *frame_clock = gdk_window_get_frame_clock (window); |
| 1734 |
GdkWindowState new_state; |
| 1735 |
gboolean suspended; |
| 1736 |
int width = impl->pending.width; |
| 1737 |
int height = impl->pending.height; |
| 1738 |
gboolean fixed_size; |
| 1739 |
gboolean saved_size; |
| 1740 |
|
| 1741 |
if (!impl->initial_configure_received) |
| 1742 |
{ |
| 1743 |
gdk_window_thaw_updates (window); |
| 1744 |
impl->initial_configure_received = TRUE; |
| 1745 |
} |
| 1746 |
|
| 1747 |
if (impl->display_server.xdg_popup) |
| 1748 |
{ |
| 1749 |
xdg_surface_ack_configure (impl->display_server.xdg_surface, serial); |
| 1750 |
return; |
| 1751 |
} |
| 1752 |
else if (impl->display_server.zxdg_popup_v6) |
| 1753 |
{ |
| 1754 |
zxdg_surface_v6_ack_configure (impl->display_server.zxdg_surface_v6, |
| 1755 |
serial); |
| 1756 |
return; |
| 1757 |
} |
| 1758 |
|
| 1759 |
suspended = impl->pending.suspended; |
| 1760 |
impl->pending.suspended = FALSE; |
| 1761 |
|
| 1762 |
if (impl->suspended != suspended) |
| 1763 |
{ |
| 1764 |
GdkEvent* event; |
| 1765 |
|
| 1766 |
impl->suspended = suspended; |
| 1767 |
|
| 1768 |
event = _gdk_make_event (window, GDK_VISIBILITY_NOTIFY, NULL, FALSE); |
| 1769 |
event->visibility.state = suspended ? GDK_VISIBILITY_FULLY_OBSCURED : GDK_VISIBILITY_UNOBSCURED; |
| 1770 |
} |
| 1771 |
|
| 1772 |
new_state = impl->pending.state; |
| 1773 |
impl->pending.state = 0; |
| 1774 |
|
| 1775 |
if (!supports_native_edge_constraints (impl)) |
| 1776 |
new_state = infer_edge_constraints (new_state); |
| 1777 |
|
| 1778 |
fixed_size = should_use_fixed_size (new_state); |
| 1779 |
|
| 1780 |
saved_size = (width == 0 && height == 0); |
| 1781 |
/* According to xdg_shell, an xdg_surface.configure with size 0x0 |
| 1782 |
* should be interpreted as that it is up to the client to set a |
| 1783 |
* size. |
| 1784 |
* |
| 1785 |
* When transitioning from maximize or fullscreen state, this means |
| 1786 |
* the client should configure its size back to what it was before |
| 1787 |
* being maximize or fullscreen. |
| 1788 |
* Additionally, if we receive a manual resize request, we must prefer this |
| 1789 |
* new size instead of the compositor's size hints. |
| 1790 |
* In such a scenario, and without letting the compositor know about the new |
| 1791 |
* size, the client has to manage all dimensions and ignore any server hints. |
| 1792 |
*/ |
| 1793 |
if (!fixed_size && (saved_size || impl->saved_size_changed)) |
| 1794 |
{ |
| 1795 |
width = impl->saved_width; |
| 1796 |
height = impl->saved_height; |
| 1797 |
impl->saved_size_changed = FALSE; |
| 1798 |
} |
| 1799 |
|
| 1800 |
if (width > 0 && height > 0) |
| 1801 |
{ |
| 1802 |
GdkWindowHints geometry_mask = impl->geometry_mask; |
| 1803 |
int configure_width; |
| 1804 |
int configure_height; |
| 1805 |
|
| 1806 |
/* Ignore size increments for maximized/fullscreen windows */ |
| 1807 |
if (fixed_size) |
| 1808 |
geometry_mask &= ~GDK_HINT_RESIZE_INC; |
| 1809 |
if (!saved_size) |
| 1810 |
{ |
| 1811 |
/* Do not reapply contrains if we are restoring original size */ |
| 1812 |
gdk_window_constrain_size (&impl->geometry_hints, |
| 1813 |
geometry_mask, |
| 1814 |
calculate_width_with_margin (window, width), |
| 1815 |
calculate_height_with_margin (window, height), |
| 1816 |
&width, |
| 1817 |
&height); |
| 1818 |
|
| 1819 |
/* Save size for next time we get 0x0 */ |
| 1820 |
_gdk_wayland_window_save_size (window); |
| 1821 |
} |
| 1822 |
|
| 1823 |
if (saved_size) |
| 1824 |
{ |
| 1825 |
configure_width = calculate_width_with_margin (window, width); |
| 1826 |
configure_height = calculate_height_with_margin (window, height); |
| 1827 |
} |
| 1828 |
else |
| 1829 |
{ |
| 1830 |
configure_width = width; |
| 1831 |
configure_height = height; |
| 1832 |
} |
| 1833 |
gdk_wayland_window_configure (window, |
| 1834 |
configure_width, |
| 1835 |
configure_height, |
| 1836 |
impl->scale); |
| 1837 |
} |
| 1838 |
else |
| 1839 |
{ |
| 1840 |
int unconfigured_width; |
| 1841 |
int unconfigured_height; |
| 1842 |
|
| 1843 |
unconfigured_width = |
| 1844 |
calculate_width_with_margin (window, impl->unconfigured_width); |
| 1845 |
unconfigured_height = |
| 1846 |
calculate_height_with_margin (window, impl->unconfigured_height); |
| 1847 |
gdk_wayland_window_configure (window, |
| 1848 |
unconfigured_width, |
| 1849 |
unconfigured_height, |
| 1850 |
impl->scale); |
| 1851 |
} |
| 1852 |
|
| 1853 |
if (fixed_size) |
| 1854 |
{ |
| 1855 |
impl->fixed_size_width = width; |
| 1856 |
impl->fixed_size_height = height; |
| 1857 |
} |
| 1858 |
|
| 1859 |
GDK_NOTE (EVENTS, |
| 1860 |
g_message ("configure, window %p %dx%d,%s%s%s%s", |
| 1861 |
window, width, height, |
| 1862 |
(new_state & GDK_WINDOW_STATE_FULLSCREEN) ? " fullscreen" : "", |
| 1863 |
(new_state & GDK_WINDOW_STATE_MAXIMIZED) ? " maximized" : "", |
| 1864 |
(new_state & GDK_WINDOW_STATE_FOCUSED) ? " focused" : "", |
| 1865 |
(new_state & GDK_WINDOW_STATE_TILED) ? " tiled" : "")); |
| 1866 |
|
| 1867 |
_gdk_set_window_state (window, new_state); |
| 1868 |
|
| 1869 |
switch (display_wayland->shell_variant) |
| 1870 |
{ |
| 1871 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 1872 |
xdg_surface_ack_configure (impl->display_server.xdg_surface, serial); |
| 1873 |
break; |
| 1874 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 1875 |
zxdg_surface_v6_ack_configure (impl->display_server.zxdg_surface_v6, |
| 1876 |
serial); |
| 1877 |
break; |
| 1878 |
} |
| 1879 |
|
| 1880 |
if (impl->hint != GDK_WINDOW_TYPE_HINT_DIALOG && |
| 1881 |
new_state & GDK_WINDOW_STATE_FOCUSED) |
| 1882 |
gdk_wayland_window_update_dialogs (window); |
| 1883 |
|
| 1884 |
impl->pending_commit = TRUE; |
| 1885 |
gdk_frame_clock_request_phase (frame_clock, |
| 1886 |
GDK_FRAME_CLOCK_PHASE_AFTER_PAINT); |
| 1887 |
} |
| 1888 |
|
| 1889 |
static void |
| 1890 |
gdk_wayland_window_handle_configure_toplevel (GdkWindow *window, |
| 1891 |
int32_t width, |
| 1892 |
int32_t height, |
| 1893 |
GdkWindowState state, |
| 1894 |
gboolean suspended) |
| 1895 |
{ |
| 1896 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 1897 |
|
| 1898 |
impl->pending.state |= state; |
| 1899 |
impl->pending.suspended |= suspended; |
| 1900 |
impl->pending.width = width; |
| 1901 |
impl->pending.height = height; |
| 1902 |
} |
| 1903 |
|
| 1904 |
static void |
| 1905 |
gdk_wayland_window_handle_close (GdkWindow *window) |
| 1906 |
{ |
| 1907 |
GdkDisplay *display; |
| 1908 |
GdkEvent *event; |
| 1909 |
|
| 1910 |
GDK_NOTE (EVENTS, |
| 1911 |
g_message ("close %p", window)); |
| 1912 |
|
| 1913 |
event = gdk_event_new (GDK_DELETE); |
| 1914 |
event->any.window = g_object_ref (window); |
| 1915 |
event->any.send_event = TRUE; |
| 1916 |
|
| 1917 |
display = gdk_window_get_display (window); |
| 1918 |
_gdk_wayland_display_deliver_event (display, event); |
| 1919 |
} |
| 1920 |
|
| 1921 |
static void |
| 1922 |
xdg_surface_configure (void *data, |
| 1923 |
struct xdg_surface *xdg_surface, |
| 1924 |
uint32_t serial) |
| 1925 |
{ |
| 1926 |
GdkWindow *window = GDK_WINDOW (data); |
| 1927 |
|
| 1928 |
gdk_wayland_window_handle_configure (window, serial); |
| 1929 |
} |
| 1930 |
|
| 1931 |
static const struct xdg_surface_listener xdg_surface_listener = { |
| 1932 |
xdg_surface_configure, |
| 1933 |
}; |
| 1934 |
|
| 1935 |
static void |
| 1936 |
xdg_toplevel_configure (void *data, |
| 1937 |
struct xdg_toplevel *xdg_toplevel, |
| 1938 |
int32_t width, |
| 1939 |
int32_t height, |
| 1940 |
struct wl_array *states) |
| 1941 |
{ |
| 1942 |
GdkWindow *window = GDK_WINDOW (data); |
| 1943 |
uint32_t *p; |
| 1944 |
GdkWindowState pending_state = 0; |
| 1945 |
gboolean suspended = FALSE; |
| 1946 |
|
| 1947 |
wl_array_for_each (p, states) |
| 1948 |
{ |
| 1949 |
uint32_t state = *p; |
| 1950 |
|
| 1951 |
switch (state) |
| 1952 |
{ |
| 1953 |
case XDG_TOPLEVEL_STATE_FULLSCREEN: |
| 1954 |
pending_state |= GDK_WINDOW_STATE_FULLSCREEN; |
| 1955 |
break; |
| 1956 |
case XDG_TOPLEVEL_STATE_MAXIMIZED: |
| 1957 |
pending_state |= GDK_WINDOW_STATE_MAXIMIZED; |
| 1958 |
break; |
| 1959 |
case XDG_TOPLEVEL_STATE_ACTIVATED: |
| 1960 |
pending_state |= GDK_WINDOW_STATE_FOCUSED; |
| 1961 |
break; |
| 1962 |
case XDG_TOPLEVEL_STATE_RESIZING: |
| 1963 |
break; |
| 1964 |
case XDG_TOPLEVEL_STATE_TILED_TOP: |
| 1965 |
pending_state |= (GDK_WINDOW_STATE_TILED | GDK_WINDOW_STATE_TOP_TILED); |
| 1966 |
break; |
| 1967 |
case XDG_TOPLEVEL_STATE_TILED_RIGHT: |
| 1968 |
pending_state |= (GDK_WINDOW_STATE_TILED | GDK_WINDOW_STATE_RIGHT_TILED); |
| 1969 |
break; |
| 1970 |
case XDG_TOPLEVEL_STATE_TILED_BOTTOM: |
| 1971 |
pending_state |= (GDK_WINDOW_STATE_TILED | GDK_WINDOW_STATE_BOTTOM_TILED); |
| 1972 |
break; |
| 1973 |
case XDG_TOPLEVEL_STATE_TILED_LEFT: |
| 1974 |
pending_state |= (GDK_WINDOW_STATE_TILED | GDK_WINDOW_STATE_LEFT_TILED); |
| 1975 |
break; |
| 1976 |
#ifdef HAVE_TOPLEVEL_STATE_SUSPENDED |
| 1977 |
case XDG_TOPLEVEL_STATE_SUSPENDED: |
| 1978 |
suspended = TRUE; |
| 1979 |
break; |
| 1980 |
#endif |
| 1981 |
default: |
| 1982 |
/* Unknown state */ |
| 1983 |
break; |
| 1984 |
} |
| 1985 |
} |
| 1986 |
|
| 1987 |
gdk_wayland_window_handle_configure_toplevel (window, width, height, |
| 1988 |
pending_state, suspended); |
| 1989 |
} |
| 1990 |
|
| 1991 |
static void |
| 1992 |
xdg_toplevel_close (void *data, |
| 1993 |
struct xdg_toplevel *xdg_toplevel) |
| 1994 |
{ |
| 1995 |
GdkWindow *window = GDK_WINDOW (data); |
| 1996 |
|
| 1997 |
gdk_wayland_window_handle_close (window); |
| 1998 |
} |
| 1999 |
|
| 2000 |
static void |
| 2001 |
xdg_toplevel_configure_bounds (void *data, |
| 2002 |
struct xdg_toplevel *xdg_toplevel, |
| 2003 |
int32_t width, |
| 2004 |
int32_t height) |
| 2005 |
{ |
| 2006 |
} |
| 2007 |
|
| 2008 |
static void |
| 2009 |
xdg_toplevel_wm_capabilities (void *data, |
| 2010 |
struct xdg_toplevel *xdg_toplevel, |
| 2011 |
struct wl_array *capabilities) |
| 2012 |
{ |
| 2013 |
} |
| 2014 |
|
| 2015 |
static const struct xdg_toplevel_listener xdg_toplevel_listener = { |
| 2016 |
xdg_toplevel_configure, |
| 2017 |
xdg_toplevel_close, |
| 2018 |
xdg_toplevel_configure_bounds, |
| 2019 |
xdg_toplevel_wm_capabilities, |
| 2020 |
}; |
| 2021 |
|
| 2022 |
static void |
| 2023 |
create_xdg_toplevel_resources (GdkWindow *window) |
| 2024 |
{ |
| 2025 |
GdkWaylandDisplay *display_wayland = |
| 2026 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 2027 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 2028 |
|
| 2029 |
impl->display_server.xdg_surface = |
| 2030 |
xdg_wm_base_get_xdg_surface (display_wayland->xdg_wm_base, |
| 2031 |
impl->display_server.wl_surface); |
| 2032 |
xdg_surface_add_listener (impl->display_server.xdg_surface, |
| 2033 |
&xdg_surface_listener, |
| 2034 |
window); |
| 2035 |
|
| 2036 |
impl->display_server.xdg_toplevel = |
| 2037 |
xdg_surface_get_toplevel (impl->display_server.xdg_surface); |
| 2038 |
xdg_toplevel_add_listener (impl->display_server.xdg_toplevel, |
| 2039 |
&xdg_toplevel_listener, |
| 2040 |
window); |
| 2041 |
} |
| 2042 |
|
| 2043 |
static void |
| 2044 |
zxdg_surface_v6_configure (void *data, |
| 2045 |
struct zxdg_surface_v6 *xdg_surface, |
| 2046 |
uint32_t serial) |
| 2047 |
{ |
| 2048 |
GdkWindow *window = GDK_WINDOW (data); |
| 2049 |
|
| 2050 |
gdk_wayland_window_handle_configure (window, serial); |
| 2051 |
} |
| 2052 |
|
| 2053 |
static const struct zxdg_surface_v6_listener zxdg_surface_v6_listener = { |
| 2054 |
zxdg_surface_v6_configure, |
| 2055 |
}; |
| 2056 |
|
| 2057 |
static void |
| 2058 |
zxdg_toplevel_v6_configure (void *data, |
| 2059 |
struct zxdg_toplevel_v6 *xdg_toplevel, |
| 2060 |
int32_t width, |
| 2061 |
int32_t height, |
| 2062 |
struct wl_array *states) |
| 2063 |
{ |
| 2064 |
GdkWindow *window = GDK_WINDOW (data); |
| 2065 |
uint32_t *p; |
| 2066 |
GdkWindowState pending_state = 0; |
| 2067 |
|
| 2068 |
wl_array_for_each (p, states) |
| 2069 |
{ |
| 2070 |
uint32_t state = *p; |
| 2071 |
|
| 2072 |
switch (state) |
| 2073 |
{ |
| 2074 |
case ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN: |
| 2075 |
pending_state |= GDK_WINDOW_STATE_FULLSCREEN; |
| 2076 |
break; |
| 2077 |
case ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED: |
| 2078 |
pending_state |= GDK_WINDOW_STATE_MAXIMIZED; |
| 2079 |
break; |
| 2080 |
case ZXDG_TOPLEVEL_V6_STATE_ACTIVATED: |
| 2081 |
pending_state |= GDK_WINDOW_STATE_FOCUSED; |
| 2082 |
break; |
| 2083 |
case ZXDG_TOPLEVEL_V6_STATE_RESIZING: |
| 2084 |
break; |
| 2085 |
default: |
| 2086 |
/* Unknown state */ |
| 2087 |
break; |
| 2088 |
} |
| 2089 |
} |
| 2090 |
|
| 2091 |
gdk_wayland_window_handle_configure_toplevel (window, width, height, |
| 2092 |
pending_state, FALSE); |
| 2093 |
} |
| 2094 |
|
| 2095 |
static void |
| 2096 |
zxdg_toplevel_v6_close (void *data, |
| 2097 |
struct zxdg_toplevel_v6 *xdg_toplevel) |
| 2098 |
{ |
| 2099 |
GdkWindow *window = GDK_WINDOW (data); |
| 2100 |
|
| 2101 |
gdk_wayland_window_handle_close (window); |
| 2102 |
} |
| 2103 |
|
| 2104 |
static const struct zxdg_toplevel_v6_listener zxdg_toplevel_v6_listener = { |
| 2105 |
zxdg_toplevel_v6_configure, |
| 2106 |
zxdg_toplevel_v6_close, |
| 2107 |
}; |
| 2108 |
|
| 2109 |
static void |
| 2110 |
create_zxdg_toplevel_v6_resources (GdkWindow *window) |
| 2111 |
{ |
| 2112 |
GdkWaylandDisplay *display_wayland = |
| 2113 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 2114 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 2115 |
|
| 2116 |
impl->display_server.zxdg_surface_v6 = |
| 2117 |
zxdg_shell_v6_get_xdg_surface (display_wayland->zxdg_shell_v6, |
| 2118 |
impl->display_server.wl_surface); |
| 2119 |
zxdg_surface_v6_add_listener (impl->display_server.zxdg_surface_v6, |
| 2120 |
&zxdg_surface_v6_listener, |
| 2121 |
window); |
| 2122 |
|
| 2123 |
impl->display_server.zxdg_toplevel_v6 = |
| 2124 |
zxdg_surface_v6_get_toplevel (impl->display_server.zxdg_surface_v6); |
| 2125 |
zxdg_toplevel_v6_add_listener (impl->display_server.zxdg_toplevel_v6, |
| 2126 |
&zxdg_toplevel_v6_listener, |
| 2127 |
window); |
| 2128 |
} |
| 2129 |
|
| 2130 |
/** |
| 2131 |
* gdk_wayland_window_set_application_id: |
| 2132 |
* @window: |
| 2133 |
* @application_id: |
| 2134 |
* |
| 2135 |
* Since: 3.24.22 |
| 2136 |
*/ |
| 2137 |
void |
| 2138 |
gdk_wayland_window_set_application_id (GdkWindow *window, const char* application_id) |
| 2139 |
{ |
| 2140 |
GdkWindowImplWayland *impl; |
| 2141 |
GdkWaylandDisplay *display_wayland; |
| 2142 |
|
| 2143 |
g_return_if_fail (application_id != NULL); |
| 2144 |
|
| 2145 |
if (GDK_WINDOW_DESTROYED (window)) |
| 2146 |
return; |
| 2147 |
|
| 2148 |
if (!is_realized_toplevel (window)) |
| 2149 |
return; |
| 2150 |
|
| 2151 |
display_wayland = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 2152 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 2153 |
|
| 2154 |
switch (display_wayland->shell_variant) |
| 2155 |
{ |
| 2156 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 2157 |
xdg_toplevel_set_app_id (impl->display_server.xdg_toplevel, |
| 2158 |
application_id); |
| 2159 |
break; |
| 2160 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 2161 |
zxdg_toplevel_v6_set_app_id (impl->display_server.zxdg_toplevel_v6, |
| 2162 |
application_id); |
| 2163 |
break; |
| 2164 |
} |
| 2165 |
} |
| 2166 |
|
| 2167 |
static void |
| 2168 |
gdk_wayland_window_create_xdg_toplevel (GdkWindow *window) |
| 2169 |
{ |
| 2170 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 2171 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 2172 |
const gchar *app_id; |
| 2173 |
GdkScreen *screen = gdk_window_get_screen (window); |
| 2174 |
struct wl_output *fullscreen_output = NULL; |
| 2175 |
|
| 2176 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 2177 |
if (impl->initial_fullscreen_monitor >= 0 && |
| 2178 |
impl->initial_fullscreen_monitor < gdk_screen_get_n_monitors (screen)) |
| 2179 |
fullscreen_output = |
| 2180 |
_gdk_wayland_screen_get_wl_output (screen, |
| 2181 |
impl->initial_fullscreen_monitor); |
| 2182 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 2183 |
|
| 2184 |
gdk_window_freeze_updates (window); |
| 2185 |
|
| 2186 |
switch (display_wayland->shell_variant) |
| 2187 |
{ |
| 2188 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 2189 |
create_xdg_toplevel_resources (window); |
| 2190 |
break; |
| 2191 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 2192 |
create_zxdg_toplevel_v6_resources (window); |
| 2193 |
break; |
| 2194 |
} |
| 2195 |
|
| 2196 |
gdk_wayland_window_sync_parent (window, NULL); |
| 2197 |
gdk_wayland_window_sync_parent_of_imported (window); |
| 2198 |
gdk_wayland_window_sync_title (window); |
| 2199 |
|
| 2200 |
switch (display_wayland->shell_variant) |
| 2201 |
{ |
| 2202 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 2203 |
if (window->state & GDK_WINDOW_STATE_MAXIMIZED) |
| 2204 |
xdg_toplevel_set_maximized (impl->display_server.xdg_toplevel); |
| 2205 |
if (window->state & GDK_WINDOW_STATE_FULLSCREEN) |
| 2206 |
xdg_toplevel_set_fullscreen (impl->display_server.xdg_toplevel, |
| 2207 |
fullscreen_output); |
| 2208 |
break; |
| 2209 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 2210 |
if (window->state & GDK_WINDOW_STATE_MAXIMIZED) |
| 2211 |
zxdg_toplevel_v6_set_maximized (impl->display_server.zxdg_toplevel_v6); |
| 2212 |
if (window->state & GDK_WINDOW_STATE_FULLSCREEN) |
| 2213 |
zxdg_toplevel_v6_set_fullscreen (impl->display_server.zxdg_toplevel_v6, |
| 2214 |
fullscreen_output); |
| 2215 |
break; |
| 2216 |
} |
| 2217 |
|
| 2218 |
app_id = g_get_prgname (); |
| 2219 |
if (app_id == NULL) |
| 2220 |
app_id = gdk_get_program_class (); |
| 2221 |
|
| 2222 |
gdk_wayland_window_set_application_id (window, app_id); |
| 2223 |
|
| 2224 |
maybe_set_gtk_surface_dbus_properties (window); |
| 2225 |
maybe_set_gtk_surface_modal (window); |
| 2226 |
|
| 2227 |
if (impl->hint == GDK_WINDOW_TYPE_HINT_DIALOG) |
| 2228 |
_gdk_wayland_screen_add_orphan_dialog (window); |
| 2229 |
|
| 2230 |
wl_surface_commit (impl->display_server.wl_surface); |
| 2231 |
} |
| 2232 |
|
| 2233 |
static void |
| 2234 |
gdk_wayland_window_handle_configure_popup (GdkWindow *window, |
| 2235 |
int32_t x, |
| 2236 |
int32_t y, |
| 2237 |
int32_t width, |
| 2238 |
int32_t height) |
| 2239 |
{ |
| 2240 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 2241 |
GdkRectangle flipped_rect; |
| 2242 |
GdkRectangle final_rect; |
| 2243 |
gboolean flipped_x; |
| 2244 |
gboolean flipped_y; |
| 2245 |
|
| 2246 |
g_return_if_fail (impl->transient_for); |
| 2247 |
|
| 2248 |
if (impl->position_method != POSITION_METHOD_MOVE_TO_RECT) |
| 2249 |
return; |
| 2250 |
|
| 2251 |
calculate_moved_to_rect_result (window, x, y, width, height, |
| 2252 |
&flipped_rect, |
| 2253 |
&final_rect, |
| 2254 |
&flipped_x, |
| 2255 |
&flipped_y); |
| 2256 |
|
| 2257 |
impl->position_method = POSITION_METHOD_MOVE_TO_RECT; |
| 2258 |
|
| 2259 |
g_signal_emit_by_name (window, |
| 2260 |
"moved-to-rect", |
| 2261 |
&flipped_rect, |
| 2262 |
&final_rect, |
| 2263 |
flipped_x, |
| 2264 |
flipped_y); |
| 2265 |
} |
| 2266 |
|
| 2267 |
static void |
| 2268 |
xdg_popup_configure (void *data, |
| 2269 |
struct xdg_popup *xdg_popup, |
| 2270 |
int32_t x, |
| 2271 |
int32_t y, |
| 2272 |
int32_t width, |
| 2273 |
int32_t height) |
| 2274 |
{ |
| 2275 |
GdkWindow *window = GDK_WINDOW (data); |
| 2276 |
|
| 2277 |
gdk_wayland_window_handle_configure_popup (window, x, y, width, height); |
| 2278 |
} |
| 2279 |
|
| 2280 |
static void |
| 2281 |
xdg_popup_done (void *data, |
| 2282 |
struct xdg_popup *xdg_popup) |
| 2283 |
{ |
| 2284 |
GdkWindow *window = GDK_WINDOW (data); |
| 2285 |
|
| 2286 |
GDK_NOTE (EVENTS, |
| 2287 |
g_message ("done %p", window)); |
| 2288 |
|
| 2289 |
gdk_window_hide (window); |
| 2290 |
} |
| 2291 |
|
| 2292 |
static const struct xdg_popup_listener xdg_popup_listener = { |
| 2293 |
xdg_popup_configure, |
| 2294 |
xdg_popup_done, |
| 2295 |
}; |
| 2296 |
|
| 2297 |
static void |
| 2298 |
zxdg_popup_v6_configure (void *data, |
| 2299 |
struct zxdg_popup_v6 *xdg_popup, |
| 2300 |
int32_t x, |
| 2301 |
int32_t y, |
| 2302 |
int32_t width, |
| 2303 |
int32_t height) |
| 2304 |
{ |
| 2305 |
GdkWindow *window = GDK_WINDOW (data); |
| 2306 |
|
| 2307 |
gdk_wayland_window_handle_configure_popup (window, x, y, width, height); |
| 2308 |
} |
| 2309 |
|
| 2310 |
static void |
| 2311 |
zxdg_popup_v6_done (void *data, |
| 2312 |
struct zxdg_popup_v6 *xdg_popup) |
| 2313 |
{ |
| 2314 |
GdkWindow *window = GDK_WINDOW (data); |
| 2315 |
|
| 2316 |
GDK_NOTE (EVENTS, |
| 2317 |
g_message ("done %p", window)); |
| 2318 |
|
| 2319 |
gdk_window_hide (window); |
| 2320 |
} |
| 2321 |
|
| 2322 |
static const struct zxdg_popup_v6_listener zxdg_popup_v6_listener = { |
| 2323 |
zxdg_popup_v6_configure, |
| 2324 |
zxdg_popup_v6_done, |
| 2325 |
}; |
| 2326 |
|
| 2327 |
static enum xdg_positioner_anchor |
| 2328 |
rect_anchor_to_anchor (GdkGravity rect_anchor) |
| 2329 |
{ |
| 2330 |
switch (rect_anchor) |
| 2331 |
{ |
| 2332 |
case GDK_GRAVITY_NORTH_WEST: |
| 2333 |
case GDK_GRAVITY_STATIC: |
| 2334 |
return XDG_POSITIONER_ANCHOR_TOP_LEFT; |
| 2335 |
case GDK_GRAVITY_NORTH: |
| 2336 |
return XDG_POSITIONER_ANCHOR_TOP; |
| 2337 |
case GDK_GRAVITY_NORTH_EAST: |
| 2338 |
return XDG_POSITIONER_ANCHOR_TOP_RIGHT; |
| 2339 |
case GDK_GRAVITY_WEST: |
| 2340 |
return XDG_POSITIONER_ANCHOR_LEFT; |
| 2341 |
case GDK_GRAVITY_CENTER: |
| 2342 |
return XDG_POSITIONER_ANCHOR_NONE; |
| 2343 |
case GDK_GRAVITY_EAST: |
| 2344 |
return XDG_POSITIONER_ANCHOR_RIGHT; |
| 2345 |
case GDK_GRAVITY_SOUTH_WEST: |
| 2346 |
return XDG_POSITIONER_ANCHOR_BOTTOM_LEFT; |
| 2347 |
case GDK_GRAVITY_SOUTH: |
| 2348 |
return XDG_POSITIONER_ANCHOR_BOTTOM; |
| 2349 |
case GDK_GRAVITY_SOUTH_EAST: |
| 2350 |
return XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT; |
| 2351 |
default: |
| 2352 |
g_assert_not_reached (); |
| 2353 |
} |
| 2354 |
} |
| 2355 |
|
| 2356 |
static enum xdg_positioner_gravity |
| 2357 |
window_anchor_to_gravity (GdkGravity rect_anchor) |
| 2358 |
{ |
| 2359 |
switch (rect_anchor) |
| 2360 |
{ |
| 2361 |
case GDK_GRAVITY_NORTH_WEST: |
| 2362 |
case GDK_GRAVITY_STATIC: |
| 2363 |
return XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT; |
| 2364 |
case GDK_GRAVITY_NORTH: |
| 2365 |
return XDG_POSITIONER_GRAVITY_BOTTOM; |
| 2366 |
case GDK_GRAVITY_NORTH_EAST: |
| 2367 |
return XDG_POSITIONER_GRAVITY_BOTTOM_LEFT; |
| 2368 |
case GDK_GRAVITY_WEST: |
| 2369 |
return XDG_POSITIONER_GRAVITY_RIGHT; |
| 2370 |
case GDK_GRAVITY_CENTER: |
| 2371 |
return XDG_POSITIONER_GRAVITY_NONE; |
| 2372 |
case GDK_GRAVITY_EAST: |
| 2373 |
return XDG_POSITIONER_GRAVITY_LEFT; |
| 2374 |
case GDK_GRAVITY_SOUTH_WEST: |
| 2375 |
return XDG_POSITIONER_GRAVITY_TOP_RIGHT; |
| 2376 |
case GDK_GRAVITY_SOUTH: |
| 2377 |
return XDG_POSITIONER_GRAVITY_TOP; |
| 2378 |
case GDK_GRAVITY_SOUTH_EAST: |
| 2379 |
return XDG_POSITIONER_GRAVITY_TOP_LEFT; |
| 2380 |
default: |
| 2381 |
g_assert_not_reached (); |
| 2382 |
} |
| 2383 |
} |
| 2384 |
|
| 2385 |
static enum zxdg_positioner_v6_anchor |
| 2386 |
rect_anchor_to_anchor_legacy (GdkGravity rect_anchor) |
| 2387 |
{ |
| 2388 |
switch (rect_anchor) |
| 2389 |
{ |
| 2390 |
case GDK_GRAVITY_NORTH_WEST: |
| 2391 |
case GDK_GRAVITY_STATIC: |
| 2392 |
return (ZXDG_POSITIONER_V6_ANCHOR_TOP | |
| 2393 |
ZXDG_POSITIONER_V6_ANCHOR_LEFT); |
| 2394 |
case GDK_GRAVITY_NORTH: |
| 2395 |
return ZXDG_POSITIONER_V6_ANCHOR_TOP; |
| 2396 |
case GDK_GRAVITY_NORTH_EAST: |
| 2397 |
return (ZXDG_POSITIONER_V6_ANCHOR_TOP | |
| 2398 |
ZXDG_POSITIONER_V6_ANCHOR_RIGHT); |
| 2399 |
case GDK_GRAVITY_WEST: |
| 2400 |
return ZXDG_POSITIONER_V6_ANCHOR_LEFT; |
| 2401 |
case GDK_GRAVITY_CENTER: |
| 2402 |
return ZXDG_POSITIONER_V6_ANCHOR_NONE; |
| 2403 |
case GDK_GRAVITY_EAST: |
| 2404 |
return ZXDG_POSITIONER_V6_ANCHOR_RIGHT; |
| 2405 |
case GDK_GRAVITY_SOUTH_WEST: |
| 2406 |
return (ZXDG_POSITIONER_V6_ANCHOR_BOTTOM | |
| 2407 |
ZXDG_POSITIONER_V6_ANCHOR_LEFT); |
| 2408 |
case GDK_GRAVITY_SOUTH: |
| 2409 |
return ZXDG_POSITIONER_V6_ANCHOR_BOTTOM; |
| 2410 |
case GDK_GRAVITY_SOUTH_EAST: |
| 2411 |
return (ZXDG_POSITIONER_V6_ANCHOR_BOTTOM | |
| 2412 |
ZXDG_POSITIONER_V6_ANCHOR_RIGHT); |
| 2413 |
default: |
| 2414 |
g_assert_not_reached (); |
| 2415 |
} |
| 2416 |
} |
| 2417 |
|
| 2418 |
static enum zxdg_positioner_v6_gravity |
| 2419 |
window_anchor_to_gravity_legacy (GdkGravity rect_anchor) |
| 2420 |
{ |
| 2421 |
switch (rect_anchor) |
| 2422 |
{ |
| 2423 |
case GDK_GRAVITY_NORTH_WEST: |
| 2424 |
case GDK_GRAVITY_STATIC: |
| 2425 |
return (ZXDG_POSITIONER_V6_GRAVITY_BOTTOM | |
| 2426 |
ZXDG_POSITIONER_V6_GRAVITY_RIGHT); |
| 2427 |
case GDK_GRAVITY_NORTH: |
| 2428 |
return ZXDG_POSITIONER_V6_GRAVITY_BOTTOM; |
| 2429 |
case GDK_GRAVITY_NORTH_EAST: |
| 2430 |
return (ZXDG_POSITIONER_V6_GRAVITY_BOTTOM | |
| 2431 |
ZXDG_POSITIONER_V6_GRAVITY_LEFT); |
| 2432 |
case GDK_GRAVITY_WEST: |
| 2433 |
return ZXDG_POSITIONER_V6_GRAVITY_RIGHT; |
| 2434 |
case GDK_GRAVITY_CENTER: |
| 2435 |
return ZXDG_POSITIONER_V6_GRAVITY_NONE; |
| 2436 |
case GDK_GRAVITY_EAST: |
| 2437 |
return ZXDG_POSITIONER_V6_GRAVITY_LEFT; |
| 2438 |
case GDK_GRAVITY_SOUTH_WEST: |
| 2439 |
return (ZXDG_POSITIONER_V6_GRAVITY_TOP | |
| 2440 |
ZXDG_POSITIONER_V6_GRAVITY_RIGHT); |
| 2441 |
case GDK_GRAVITY_SOUTH: |
| 2442 |
return ZXDG_POSITIONER_V6_GRAVITY_TOP; |
| 2443 |
case GDK_GRAVITY_SOUTH_EAST: |
| 2444 |
return (ZXDG_POSITIONER_V6_GRAVITY_TOP | |
| 2445 |
ZXDG_POSITIONER_V6_GRAVITY_LEFT); |
| 2446 |
default: |
| 2447 |
g_assert_not_reached (); |
| 2448 |
} |
| 2449 |
} |
| 2450 |
|
| 2451 |
static void |
| 2452 |
kwin_server_decoration_mode_set (void *data, struct org_kde_kwin_server_decoration *org_kde_kwin_server_decoration, uint32_t mode) |
| 2453 |
{ |
| 2454 |
GdkWindow *window = GDK_WINDOW (data); |
| 2455 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 2456 |
|
| 2457 |
if ((mode == ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER && impl->using_csd) || |
| 2458 |
(mode == ORG_KDE_KWIN_SERVER_DECORATION_MODE_CLIENT && !impl->using_csd)) |
| 2459 |
gdk_wayland_window_announce_decoration_mode (window); |
| 2460 |
} |
| 2461 |
|
| 2462 |
static const struct org_kde_kwin_server_decoration_listener kwin_server_decoration_listener = { |
| 2463 |
kwin_server_decoration_mode_set |
| 2464 |
}; |
| 2465 |
|
| 2466 |
static void |
| 2467 |
gdk_wayland_window_announce_decoration_mode (GdkWindow *window) |
| 2468 |
{ |
| 2469 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 2470 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 2471 |
|
| 2472 |
if (!display_wayland->server_decoration_manager) |
| 2473 |
return; |
| 2474 |
if (!impl->display_server.server_decoration) |
| 2475 |
{ |
| 2476 |
impl->display_server.server_decoration = |
| 2477 |
org_kde_kwin_server_decoration_manager_create (display_wayland->server_decoration_manager, |
| 2478 |
impl->display_server.wl_surface); |
| 2479 |
org_kde_kwin_server_decoration_add_listener (impl->display_server.server_decoration, |
| 2480 |
&kwin_server_decoration_listener, |
| 2481 |
window); |
| 2482 |
} |
| 2483 |
|
| 2484 |
if (impl->display_server.server_decoration) |
| 2485 |
{ |
| 2486 |
if (impl->using_csd) |
| 2487 |
org_kde_kwin_server_decoration_request_mode (impl->display_server.server_decoration, |
| 2488 |
ORG_KDE_KWIN_SERVER_DECORATION_MODE_CLIENT); |
| 2489 |
else |
| 2490 |
org_kde_kwin_server_decoration_request_mode (impl->display_server.server_decoration, |
| 2491 |
ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER); |
| 2492 |
} |
| 2493 |
} |
| 2494 |
|
| 2495 |
void |
| 2496 |
gdk_wayland_window_announce_csd (GdkWindow *window) |
| 2497 |
{ |
| 2498 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 2499 |
|
| 2500 |
impl->using_csd = TRUE; |
| 2501 |
if (impl->mapped) |
| 2502 |
gdk_wayland_window_announce_decoration_mode (window); |
| 2503 |
} |
| 2504 |
|
| 2505 |
void |
| 2506 |
gdk_wayland_window_announce_ssd (GdkWindow *window) |
| 2507 |
{ |
| 2508 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 2509 |
|
| 2510 |
impl->using_csd = FALSE; |
| 2511 |
if (impl->mapped) |
| 2512 |
gdk_wayland_window_announce_decoration_mode (window); |
| 2513 |
} |
| 2514 |
|
| 2515 |
static GdkWindow * |
| 2516 |
get_real_parent_and_translate (GdkWindow *window, |
| 2517 |
gint *x, |
| 2518 |
gint *y) |
| 2519 |
{ |
| 2520 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 2521 |
GdkWindow *parent = impl->transient_for; |
| 2522 |
|
| 2523 |
while (parent) |
| 2524 |
{ |
| 2525 |
GdkWindowImplWayland *parent_impl = |
| 2526 |
GDK_WINDOW_IMPL_WAYLAND (parent->impl); |
| 2527 |
GdkWindow *effective_parent = gdk_window_get_effective_parent (parent); |
| 2528 |
|
| 2529 |
if (parent == NULL || (gdk_window_has_native (parent) && |
| 2530 |
!parent_impl->display_server.wl_subsurface) || |
| 2531 |
!effective_parent) |
| 2532 |
break; |
| 2533 |
|
| 2534 |
*x += parent->x; |
| 2535 |
*y += parent->y; |
| 2536 |
|
| 2537 |
if (gdk_window_has_native (parent) && |
| 2538 |
parent_impl->display_server.wl_subsurface) |
| 2539 |
parent = parent->transient_for; |
| 2540 |
else |
| 2541 |
parent = effective_parent; |
| 2542 |
} |
| 2543 |
|
| 2544 |
return parent; |
| 2545 |
} |
| 2546 |
|
| 2547 |
static void |
| 2548 |
translate_to_real_parent_window_geometry (GdkWindow *window, |
| 2549 |
gint *x, |
| 2550 |
gint *y) |
| 2551 |
{ |
| 2552 |
GdkWindow *parent; |
| 2553 |
|
| 2554 |
parent = get_real_parent_and_translate (window, x, y); |
| 2555 |
|
| 2556 |
if (parent != NULL) { |
| 2557 |
*x -= parent->shadow_left; |
| 2558 |
*y -= parent->shadow_top; |
| 2559 |
} |
| 2560 |
} |
| 2561 |
|
| 2562 |
static GdkWindow * |
| 2563 |
translate_from_real_parent_window_geometry (GdkWindow *window, |
| 2564 |
gint *x, |
| 2565 |
gint *y) |
| 2566 |
{ |
| 2567 |
GdkWindow *parent; |
| 2568 |
gint dx = 0; |
| 2569 |
gint dy = 0; |
| 2570 |
|
| 2571 |
parent = get_real_parent_and_translate (window, &dx, &dy); |
| 2572 |
|
| 2573 |
*x -= dx; |
| 2574 |
*y -= dy; |
| 2575 |
|
| 2576 |
if (parent != NULL) { |
| 2577 |
*x += parent->shadow_left; |
| 2578 |
*y += parent->shadow_top; |
| 2579 |
} |
| 2580 |
|
| 2581 |
return parent; |
| 2582 |
} |
| 2583 |
|
| 2584 |
static void |
| 2585 |
calculate_popup_rect (GdkWindow *window, |
| 2586 |
GdkGravity rect_anchor, |
| 2587 |
GdkGravity window_anchor, |
| 2588 |
GdkRectangle *out_rect) |
| 2589 |
{ |
| 2590 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 2591 |
GdkRectangle geometry; |
| 2592 |
GdkRectangle anchor_rect; |
| 2593 |
int x = 0, y = 0; |
| 2594 |
|
| 2595 |
gdk_wayland_window_get_window_geometry (window, &geometry); |
| 2596 |
|
| 2597 |
anchor_rect = (GdkRectangle) { |
| 2598 |
.x = (impl->pending_move_to_rect.rect.x + |
| 2599 |
impl->pending_move_to_rect.rect_anchor_dx), |
| 2600 |
.y = (impl->pending_move_to_rect.rect.y + |
| 2601 |
impl->pending_move_to_rect.rect_anchor_dy), |
| 2602 |
.width = impl->pending_move_to_rect.rect.width, |
| 2603 |
.height = impl->pending_move_to_rect.rect.height |
| 2604 |
}; |
| 2605 |
|
| 2606 |
switch (rect_anchor) |
| 2607 |
{ |
| 2608 |
case GDK_GRAVITY_STATIC: |
| 2609 |
case GDK_GRAVITY_NORTH_WEST: |
| 2610 |
x = anchor_rect.x; |
| 2611 |
y = anchor_rect.y; |
| 2612 |
break; |
| 2613 |
case GDK_GRAVITY_NORTH: |
| 2614 |
x = anchor_rect.x + (anchor_rect.width / 2); |
| 2615 |
y = anchor_rect.y; |
| 2616 |
break; |
| 2617 |
case GDK_GRAVITY_NORTH_EAST: |
| 2618 |
x = anchor_rect.x + anchor_rect.width; |
| 2619 |
y = anchor_rect.y; |
| 2620 |
break; |
| 2621 |
case GDK_GRAVITY_WEST: |
| 2622 |
x = anchor_rect.x; |
| 2623 |
y = anchor_rect.y + (anchor_rect.height / 2); |
| 2624 |
break; |
| 2625 |
case GDK_GRAVITY_CENTER: |
| 2626 |
x = anchor_rect.x + (anchor_rect.width / 2); |
| 2627 |
y = anchor_rect.y + (anchor_rect.height / 2); |
| 2628 |
break; |
| 2629 |
case GDK_GRAVITY_EAST: |
| 2630 |
x = anchor_rect.x + anchor_rect.width; |
| 2631 |
y = anchor_rect.y + (anchor_rect.height / 2); |
| 2632 |
break; |
| 2633 |
case GDK_GRAVITY_SOUTH_WEST: |
| 2634 |
x = anchor_rect.x; |
| 2635 |
y = anchor_rect.y + anchor_rect.height; |
| 2636 |
break; |
| 2637 |
case GDK_GRAVITY_SOUTH: |
| 2638 |
x = anchor_rect.x + (anchor_rect.width / 2); |
| 2639 |
y = anchor_rect.y + anchor_rect.height; |
| 2640 |
break; |
| 2641 |
case GDK_GRAVITY_SOUTH_EAST: |
| 2642 |
x = anchor_rect.x + anchor_rect.width; |
| 2643 |
y = anchor_rect.y + anchor_rect.height; |
| 2644 |
break; |
| 2645 |
} |
| 2646 |
|
| 2647 |
switch (window_anchor) |
| 2648 |
{ |
| 2649 |
case GDK_GRAVITY_STATIC: |
| 2650 |
case GDK_GRAVITY_NORTH_WEST: |
| 2651 |
break; |
| 2652 |
case GDK_GRAVITY_NORTH: |
| 2653 |
x -= geometry.width / 2; |
| 2654 |
break; |
| 2655 |
case GDK_GRAVITY_NORTH_EAST: |
| 2656 |
x -= geometry.width; |
| 2657 |
break; |
| 2658 |
case GDK_GRAVITY_WEST: |
| 2659 |
y -= geometry.height / 2; |
| 2660 |
break; |
| 2661 |
case GDK_GRAVITY_CENTER: |
| 2662 |
x -= geometry.width / 2; |
| 2663 |
y -= geometry.height / 2; |
| 2664 |
break; |
| 2665 |
case GDK_GRAVITY_EAST: |
| 2666 |
x -= geometry.width; |
| 2667 |
y -= geometry.height / 2; |
| 2668 |
break; |
| 2669 |
case GDK_GRAVITY_SOUTH_WEST: |
| 2670 |
y -= geometry.height; |
| 2671 |
break; |
| 2672 |
case GDK_GRAVITY_SOUTH: |
| 2673 |
x -= geometry.width / 2; |
| 2674 |
y -= geometry.height; |
| 2675 |
break; |
| 2676 |
case GDK_GRAVITY_SOUTH_EAST: |
| 2677 |
x -= geometry.width; |
| 2678 |
y -= geometry.height; |
| 2679 |
break; |
| 2680 |
} |
| 2681 |
|
| 2682 |
*out_rect = (GdkRectangle) { |
| 2683 |
.x = x, |
| 2684 |
.y = y, |
| 2685 |
.width = geometry.width, |
| 2686 |
.height = geometry.height |
| 2687 |
}; |
| 2688 |
} |
| 2689 |
|
| 2690 |
static GdkGravity |
| 2691 |
flip_anchor_horizontally (GdkGravity anchor) |
| 2692 |
{ |
| 2693 |
switch (anchor) |
| 2694 |
{ |
| 2695 |
case GDK_GRAVITY_STATIC: |
| 2696 |
case GDK_GRAVITY_NORTH_WEST: |
| 2697 |
return GDK_GRAVITY_NORTH_EAST; |
| 2698 |
case GDK_GRAVITY_NORTH: |
| 2699 |
return GDK_GRAVITY_NORTH; |
| 2700 |
case GDK_GRAVITY_NORTH_EAST: |
| 2701 |
return GDK_GRAVITY_NORTH_WEST; |
| 2702 |
case GDK_GRAVITY_WEST: |
| 2703 |
return GDK_GRAVITY_EAST; |
| 2704 |
case GDK_GRAVITY_CENTER: |
| 2705 |
return GDK_GRAVITY_CENTER; |
| 2706 |
case GDK_GRAVITY_EAST: |
| 2707 |
return GDK_GRAVITY_WEST; |
| 2708 |
case GDK_GRAVITY_SOUTH_WEST: |
| 2709 |
return GDK_GRAVITY_SOUTH_EAST; |
| 2710 |
case GDK_GRAVITY_SOUTH: |
| 2711 |
return GDK_GRAVITY_SOUTH; |
| 2712 |
case GDK_GRAVITY_SOUTH_EAST: |
| 2713 |
return GDK_GRAVITY_SOUTH_WEST; |
| 2714 |
} |
| 2715 |
|
| 2716 |
g_assert_not_reached (); |
| 2717 |
} |
| 2718 |
|
| 2719 |
static GdkGravity |
| 2720 |
flip_anchor_vertically (GdkGravity anchor) |
| 2721 |
{ |
| 2722 |
switch (anchor) |
| 2723 |
{ |
| 2724 |
case GDK_GRAVITY_STATIC: |
| 2725 |
case GDK_GRAVITY_NORTH_WEST: |
| 2726 |
return GDK_GRAVITY_SOUTH_WEST; |
| 2727 |
case GDK_GRAVITY_NORTH: |
| 2728 |
return GDK_GRAVITY_SOUTH; |
| 2729 |
case GDK_GRAVITY_NORTH_EAST: |
| 2730 |
return GDK_GRAVITY_SOUTH_EAST; |
| 2731 |
case GDK_GRAVITY_WEST: |
| 2732 |
return GDK_GRAVITY_WEST; |
| 2733 |
case GDK_GRAVITY_CENTER: |
| 2734 |
return GDK_GRAVITY_CENTER; |
| 2735 |
case GDK_GRAVITY_EAST: |
| 2736 |
return GDK_GRAVITY_EAST; |
| 2737 |
case GDK_GRAVITY_SOUTH_WEST: |
| 2738 |
return GDK_GRAVITY_NORTH_WEST; |
| 2739 |
case GDK_GRAVITY_SOUTH: |
| 2740 |
return GDK_GRAVITY_NORTH; |
| 2741 |
case GDK_GRAVITY_SOUTH_EAST: |
| 2742 |
return GDK_GRAVITY_NORTH_EAST; |
| 2743 |
} |
| 2744 |
|
| 2745 |
g_assert_not_reached (); |
| 2746 |
} |
| 2747 |
|
| 2748 |
static void |
| 2749 |
calculate_moved_to_rect_result (GdkWindow *window, |
| 2750 |
int x, |
| 2751 |
int y, |
| 2752 |
int width, |
| 2753 |
int height, |
| 2754 |
GdkRectangle *flipped_rect, |
| 2755 |
GdkRectangle *final_rect, |
| 2756 |
gboolean *flipped_x, |
| 2757 |
gboolean *flipped_y) |
| 2758 |
{ |
| 2759 |
GdkWindowImplWayland *impl; |
| 2760 |
GdkWindow *parent; |
| 2761 |
gint window_x, window_y; |
| 2762 |
gint window_width, window_height; |
| 2763 |
GdkRectangle best_rect; |
| 2764 |
|
| 2765 |
g_return_if_fail (GDK_IS_WAYLAND_WINDOW (window)); |
| 2766 |
g_return_if_fail (GDK_IS_WINDOW_IMPL_WAYLAND (window->impl)); |
| 2767 |
|
| 2768 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 2769 |
|
| 2770 |
parent = translate_from_real_parent_window_geometry (window, &x, &y); |
| 2771 |
*final_rect = (GdkRectangle) { |
| 2772 |
.x = x, |
| 2773 |
.y = y, |
| 2774 |
.width = width, |
| 2775 |
.height = height, |
| 2776 |
}; |
| 2777 |
|
| 2778 |
window_x = parent->x + x; |
| 2779 |
window_y = parent->y + y; |
| 2780 |
window_width = width + window->shadow_left + window->shadow_right; |
| 2781 |
window_height = height + window->shadow_top + window->shadow_bottom; |
| 2782 |
|
| 2783 |
impl->configuring_popup = TRUE; |
| 2784 |
gdk_window_move_resize (window, |
| 2785 |
window_x, window_y, |
| 2786 |
window_width, window_height); |
| 2787 |
impl->configuring_popup = FALSE; |
| 2788 |
|
| 2789 |
calculate_popup_rect (window, |
| 2790 |
impl->pending_move_to_rect.rect_anchor, |
| 2791 |
impl->pending_move_to_rect.window_anchor, |
| 2792 |
&best_rect); |
| 2793 |
|
| 2794 |
*flipped_rect = best_rect; |
| 2795 |
|
| 2796 |
if (x != best_rect.x && |
| 2797 |
impl->pending_move_to_rect.anchor_hints & GDK_ANCHOR_FLIP_X) |
| 2798 |
{ |
| 2799 |
GdkRectangle flipped_x_rect; |
| 2800 |
GdkGravity flipped_rect_anchor; |
| 2801 |
GdkGravity flipped_window_anchor; |
| 2802 |
|
| 2803 |
flipped_rect_anchor = |
| 2804 |
flip_anchor_horizontally (impl->pending_move_to_rect.rect_anchor); |
| 2805 |
flipped_window_anchor = |
| 2806 |
flip_anchor_horizontally (impl->pending_move_to_rect.window_anchor), |
| 2807 |
calculate_popup_rect (window, |
| 2808 |
flipped_rect_anchor, |
| 2809 |
flipped_window_anchor, |
| 2810 |
&flipped_x_rect); |
| 2811 |
|
| 2812 |
if (flipped_x_rect.x == x) |
| 2813 |
flipped_rect->x = x; |
| 2814 |
} |
| 2815 |
if (y != best_rect.y && |
| 2816 |
impl->pending_move_to_rect.anchor_hints & GDK_ANCHOR_FLIP_Y) |
| 2817 |
{ |
| 2818 |
GdkRectangle flipped_y_rect; |
| 2819 |
GdkGravity flipped_rect_anchor; |
| 2820 |
GdkGravity flipped_window_anchor; |
| 2821 |
|
| 2822 |
flipped_rect_anchor = |
| 2823 |
flip_anchor_vertically (impl->pending_move_to_rect.rect_anchor); |
| 2824 |
flipped_window_anchor = |
| 2825 |
flip_anchor_vertically (impl->pending_move_to_rect.window_anchor), |
| 2826 |
calculate_popup_rect (window, |
| 2827 |
flipped_rect_anchor, |
| 2828 |
flipped_window_anchor, |
| 2829 |
&flipped_y_rect); |
| 2830 |
|
| 2831 |
if (flipped_y_rect.y == y) |
| 2832 |
flipped_rect->y = y; |
| 2833 |
} |
| 2834 |
|
| 2835 |
*flipped_x = flipped_rect->x != best_rect.x; |
| 2836 |
*flipped_y = flipped_rect->y != best_rect.y; |
| 2837 |
} |
| 2838 |
|
| 2839 |
static gpointer |
| 2840 |
create_dynamic_positioner (GdkWindow *window) |
| 2841 |
{ |
| 2842 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 2843 |
GdkWaylandDisplay *display = |
| 2844 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 2845 |
GdkRectangle geometry; |
| 2846 |
uint32_t constraint_adjustment = ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_NONE; |
| 2847 |
gint real_anchor_rect_x, real_anchor_rect_y; |
| 2848 |
gint anchor_rect_width, anchor_rect_height; |
| 2849 |
|
| 2850 |
gdk_wayland_window_get_window_geometry (window, &geometry); |
| 2851 |
|
| 2852 |
real_anchor_rect_x = impl->pending_move_to_rect.rect.x; |
| 2853 |
real_anchor_rect_y = impl->pending_move_to_rect.rect.y; |
| 2854 |
translate_to_real_parent_window_geometry (window, |
| 2855 |
&real_anchor_rect_x, |
| 2856 |
&real_anchor_rect_y); |
| 2857 |
|
| 2858 |
anchor_rect_width = impl->pending_move_to_rect.rect.width; |
| 2859 |
anchor_rect_height = impl->pending_move_to_rect.rect.height; |
| 2860 |
|
| 2861 |
switch (display->shell_variant) |
| 2862 |
{ |
| 2863 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 2864 |
{ |
| 2865 |
struct xdg_positioner *positioner; |
| 2866 |
enum xdg_positioner_anchor anchor; |
| 2867 |
enum xdg_positioner_gravity gravity; |
| 2868 |
|
| 2869 |
positioner = xdg_wm_base_create_positioner (display->xdg_wm_base); |
| 2870 |
|
| 2871 |
xdg_positioner_set_size (positioner, geometry.width, geometry.height); |
| 2872 |
xdg_positioner_set_anchor_rect (positioner, |
| 2873 |
real_anchor_rect_x, |
| 2874 |
real_anchor_rect_y, |
| 2875 |
anchor_rect_width, |
| 2876 |
anchor_rect_height); |
| 2877 |
xdg_positioner_set_offset (positioner, |
| 2878 |
impl->pending_move_to_rect.rect_anchor_dx, |
| 2879 |
impl->pending_move_to_rect.rect_anchor_dy); |
| 2880 |
|
| 2881 |
anchor = rect_anchor_to_anchor (impl->pending_move_to_rect.rect_anchor); |
| 2882 |
xdg_positioner_set_anchor (positioner, anchor); |
| 2883 |
|
| 2884 |
gravity = window_anchor_to_gravity (impl->pending_move_to_rect.window_anchor); |
| 2885 |
xdg_positioner_set_gravity (positioner, gravity); |
| 2886 |
|
| 2887 |
if (impl->pending_move_to_rect.anchor_hints & GDK_ANCHOR_FLIP_X) |
| 2888 |
constraint_adjustment |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_X; |
| 2889 |
if (impl->pending_move_to_rect.anchor_hints & GDK_ANCHOR_FLIP_Y) |
| 2890 |
constraint_adjustment |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y; |
| 2891 |
if (impl->pending_move_to_rect.anchor_hints & GDK_ANCHOR_SLIDE_X) |
| 2892 |
constraint_adjustment |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X; |
| 2893 |
if (impl->pending_move_to_rect.anchor_hints & GDK_ANCHOR_SLIDE_Y) |
| 2894 |
constraint_adjustment |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_Y; |
| 2895 |
if (impl->pending_move_to_rect.anchor_hints & GDK_ANCHOR_RESIZE_X) |
| 2896 |
constraint_adjustment |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_X; |
| 2897 |
if (impl->pending_move_to_rect.anchor_hints & GDK_ANCHOR_RESIZE_Y) |
| 2898 |
constraint_adjustment |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_Y; |
| 2899 |
xdg_positioner_set_constraint_adjustment (positioner, |
| 2900 |
constraint_adjustment); |
| 2901 |
|
| 2902 |
return positioner; |
| 2903 |
} |
| 2904 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 2905 |
{ |
| 2906 |
struct zxdg_positioner_v6 *positioner; |
| 2907 |
enum zxdg_positioner_v6_anchor anchor; |
| 2908 |
enum zxdg_positioner_v6_gravity gravity; |
| 2909 |
|
| 2910 |
positioner = zxdg_shell_v6_create_positioner (display->zxdg_shell_v6); |
| 2911 |
|
| 2912 |
zxdg_positioner_v6_set_size (positioner, geometry.width, geometry.height); |
| 2913 |
zxdg_positioner_v6_set_anchor_rect (positioner, |
| 2914 |
real_anchor_rect_x, |
| 2915 |
real_anchor_rect_y, |
| 2916 |
anchor_rect_width, |
| 2917 |
anchor_rect_height); |
| 2918 |
zxdg_positioner_v6_set_offset (positioner, |
| 2919 |
impl->pending_move_to_rect.rect_anchor_dx, |
| 2920 |
impl->pending_move_to_rect.rect_anchor_dy); |
| 2921 |
|
| 2922 |
anchor = rect_anchor_to_anchor_legacy (impl->pending_move_to_rect.rect_anchor); |
| 2923 |
zxdg_positioner_v6_set_anchor (positioner, anchor); |
| 2924 |
|
| 2925 |
gravity = window_anchor_to_gravity_legacy (impl->pending_move_to_rect.window_anchor); |
| 2926 |
zxdg_positioner_v6_set_gravity (positioner, gravity); |
| 2927 |
|
| 2928 |
if (impl->pending_move_to_rect.anchor_hints & GDK_ANCHOR_FLIP_X) |
| 2929 |
constraint_adjustment |= ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_X; |
| 2930 |
if (impl->pending_move_to_rect.anchor_hints & GDK_ANCHOR_FLIP_Y) |
| 2931 |
constraint_adjustment |= ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_Y; |
| 2932 |
if (impl->pending_move_to_rect.anchor_hints & GDK_ANCHOR_SLIDE_X) |
| 2933 |
constraint_adjustment |= ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_X; |
| 2934 |
if (impl->pending_move_to_rect.anchor_hints & GDK_ANCHOR_SLIDE_Y) |
| 2935 |
constraint_adjustment |= ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_Y; |
| 2936 |
if (impl->pending_move_to_rect.anchor_hints & GDK_ANCHOR_RESIZE_X) |
| 2937 |
constraint_adjustment |= ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_X; |
| 2938 |
if (impl->pending_move_to_rect.anchor_hints & GDK_ANCHOR_RESIZE_Y) |
| 2939 |
constraint_adjustment |= ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_Y; |
| 2940 |
zxdg_positioner_v6_set_constraint_adjustment (positioner, |
| 2941 |
constraint_adjustment); |
| 2942 |
|
| 2943 |
return positioner; |
| 2944 |
} |
| 2945 |
} |
| 2946 |
|
| 2947 |
g_assert_not_reached (); |
| 2948 |
} |
| 2949 |
|
| 2950 |
static gpointer |
| 2951 |
create_simple_positioner (GdkWindow *window, |
| 2952 |
GdkWindow *parent) |
| 2953 |
{ |
| 2954 |
GdkWaylandDisplay *display = |
| 2955 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 2956 |
GdkRectangle geometry; |
| 2957 |
GdkRectangle parent_geometry; |
| 2958 |
int parent_x, parent_y; |
| 2959 |
|
| 2960 |
gdk_wayland_window_get_window_geometry (window, &geometry); |
| 2961 |
|
| 2962 |
parent_x = parent->x; |
| 2963 |
parent_y = parent->y; |
| 2964 |
|
| 2965 |
gdk_wayland_window_get_window_geometry (parent, &parent_geometry); |
| 2966 |
parent_x += parent_geometry.x; |
| 2967 |
parent_y += parent_geometry.y; |
| 2968 |
|
| 2969 |
switch (display->shell_variant) |
| 2970 |
{ |
| 2971 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 2972 |
{ |
| 2973 |
struct xdg_positioner *positioner; |
| 2974 |
|
| 2975 |
positioner = xdg_wm_base_create_positioner (display->xdg_wm_base); |
| 2976 |
xdg_positioner_set_size (positioner, geometry.width, geometry.height); |
| 2977 |
xdg_positioner_set_anchor_rect (positioner, |
| 2978 |
(window->x + geometry.x) - parent_x, |
| 2979 |
(window->y + geometry.y) - parent_y, |
| 2980 |
1, 1); |
| 2981 |
xdg_positioner_set_anchor (positioner, |
| 2982 |
XDG_POSITIONER_ANCHOR_TOP_LEFT); |
| 2983 |
xdg_positioner_set_gravity (positioner, |
| 2984 |
XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT); |
| 2985 |
|
| 2986 |
return positioner; |
| 2987 |
} |
| 2988 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 2989 |
{ |
| 2990 |
struct zxdg_positioner_v6 *positioner; |
| 2991 |
|
| 2992 |
positioner = zxdg_shell_v6_create_positioner (display->zxdg_shell_v6); |
| 2993 |
zxdg_positioner_v6_set_size (positioner, geometry.width, geometry.height); |
| 2994 |
zxdg_positioner_v6_set_anchor_rect (positioner, |
| 2995 |
(window->x + geometry.x) - parent_x, |
| 2996 |
(window->y + geometry.y) - parent_y, |
| 2997 |
1, 1); |
| 2998 |
zxdg_positioner_v6_set_anchor (positioner, |
| 2999 |
(ZXDG_POSITIONER_V6_ANCHOR_TOP | |
| 3000 |
ZXDG_POSITIONER_V6_ANCHOR_LEFT)); |
| 3001 |
zxdg_positioner_v6_set_gravity (positioner, |
| 3002 |
(ZXDG_POSITIONER_V6_GRAVITY_BOTTOM | |
| 3003 |
ZXDG_POSITIONER_V6_GRAVITY_RIGHT)); |
| 3004 |
|
| 3005 |
return positioner; |
| 3006 |
} |
| 3007 |
} |
| 3008 |
|
| 3009 |
g_assert_not_reached (); |
| 3010 |
} |
| 3011 |
|
| 3012 |
static void |
| 3013 |
gdk_wayland_window_create_xdg_popup (GdkWindow *window, |
| 3014 |
GdkWindow *parent, |
| 3015 |
struct wl_seat *seat) |
| 3016 |
{ |
| 3017 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 3018 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3019 |
GdkWindowImplWayland *parent_impl = GDK_WINDOW_IMPL_WAYLAND (parent->impl); |
| 3020 |
gpointer positioner; |
| 3021 |
GdkSeat *gdk_seat; |
| 3022 |
guint32 serial; |
| 3023 |
|
| 3024 |
if (!impl->display_server.wl_surface) |
| 3025 |
return; |
| 3026 |
|
| 3027 |
if (!is_realized_shell_surface (parent)) |
| 3028 |
return; |
| 3029 |
|
| 3030 |
if (is_realized_toplevel (window)) |
| 3031 |
{ |
| 3032 |
g_warning ("Can't map popup, already mapped as toplevel"); |
| 3033 |
return; |
| 3034 |
} |
| 3035 |
if (is_realized_popup (window)) |
| 3036 |
{ |
| 3037 |
g_warning ("Can't map popup, already mapped"); |
| 3038 |
return; |
| 3039 |
} |
| 3040 |
if ((display->current_popups && |
| 3041 |
g_list_last (display->current_popups)->data != parent) || |
| 3042 |
(!display->current_popups && |
| 3043 |
!is_realized_toplevel (parent))) |
| 3044 |
{ |
| 3045 |
g_warning ("Tried to map a popup with a non-top most parent"); |
| 3046 |
return; |
| 3047 |
} |
| 3048 |
|
| 3049 |
gdk_window_freeze_updates (window); |
| 3050 |
|
| 3051 |
if (impl->position_method == POSITION_METHOD_MOVE_TO_RECT) |
| 3052 |
positioner = create_dynamic_positioner (window); |
| 3053 |
else |
| 3054 |
positioner = create_simple_positioner (window, parent); |
| 3055 |
|
| 3056 |
switch (display->shell_variant) |
| 3057 |
{ |
| 3058 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 3059 |
impl->display_server.xdg_surface = |
| 3060 |
xdg_wm_base_get_xdg_surface (display->xdg_wm_base, |
| 3061 |
impl->display_server.wl_surface); |
| 3062 |
xdg_surface_add_listener (impl->display_server.xdg_surface, |
| 3063 |
&xdg_surface_listener, |
| 3064 |
window); |
| 3065 |
impl->display_server.xdg_popup = |
| 3066 |
xdg_surface_get_popup (impl->display_server.xdg_surface, |
| 3067 |
parent_impl->display_server.xdg_surface, |
| 3068 |
positioner); |
| 3069 |
xdg_popup_add_listener (impl->display_server.xdg_popup, |
| 3070 |
&xdg_popup_listener, |
| 3071 |
window); |
| 3072 |
xdg_positioner_destroy (positioner); |
| 3073 |
break; |
| 3074 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 3075 |
impl->display_server.zxdg_surface_v6 = |
| 3076 |
zxdg_shell_v6_get_xdg_surface (display->zxdg_shell_v6, |
| 3077 |
impl->display_server.wl_surface); |
| 3078 |
zxdg_surface_v6_add_listener (impl->display_server.zxdg_surface_v6, |
| 3079 |
&zxdg_surface_v6_listener, |
| 3080 |
window); |
| 3081 |
impl->display_server.zxdg_popup_v6 = |
| 3082 |
zxdg_surface_v6_get_popup (impl->display_server.zxdg_surface_v6, |
| 3083 |
parent_impl->display_server.zxdg_surface_v6, |
| 3084 |
positioner); |
| 3085 |
zxdg_popup_v6_add_listener (impl->display_server.zxdg_popup_v6, |
| 3086 |
&zxdg_popup_v6_listener, |
| 3087 |
window); |
| 3088 |
zxdg_positioner_v6_destroy (positioner); |
| 3089 |
break; |
| 3090 |
} |
| 3091 |
|
| 3092 |
if (seat) |
| 3093 |
{ |
| 3094 |
gdk_seat = gdk_display_get_default_seat (GDK_DISPLAY (display)); |
| 3095 |
serial = _gdk_wayland_seat_get_last_implicit_grab_serial (gdk_seat, NULL); |
| 3096 |
|
| 3097 |
switch (display->shell_variant) |
| 3098 |
{ |
| 3099 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 3100 |
xdg_popup_grab (impl->display_server.xdg_popup, seat, serial); |
| 3101 |
break; |
| 3102 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 3103 |
zxdg_popup_v6_grab (impl->display_server.zxdg_popup_v6, seat, serial); |
| 3104 |
break; |
| 3105 |
} |
| 3106 |
} |
| 3107 |
|
| 3108 |
wl_surface_commit (impl->display_server.wl_surface); |
| 3109 |
|
| 3110 |
impl->popup_parent = parent; |
| 3111 |
display->current_popups = g_list_append (display->current_popups, window); |
| 3112 |
} |
| 3113 |
|
| 3114 |
static struct wl_seat * |
| 3115 |
find_grab_input_seat (GdkWindow *window, GdkWindow *transient_for) |
| 3116 |
{ |
| 3117 |
GdkWindow *attached_grab_window; |
| 3118 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3119 |
GdkWindowImplWayland *tmp_impl; |
| 3120 |
|
| 3121 |
/* Use the device that was used for the grab as the device for |
| 3122 |
* the popup window setup - so this relies on GTK+ taking the |
| 3123 |
* grab before showing the popup window. |
| 3124 |
*/ |
| 3125 |
if (impl->grab_input_seat) |
| 3126 |
return gdk_wayland_seat_get_wl_seat (impl->grab_input_seat); |
| 3127 |
|
| 3128 |
/* HACK: GtkMenu grabs a special window known as the "grab transfer window" |
| 3129 |
* and then transfers the grab over to the correct window later. Look for |
| 3130 |
* this window when taking the grab to know it's correct. |
| 3131 |
* |
| 3132 |
* See: associate_menu_grab_transfer_window in gtkmenu.c |
| 3133 |
*/ |
| 3134 |
attached_grab_window = g_object_get_data (G_OBJECT (window), "gdk-attached-grab-window"); |
| 3135 |
if (attached_grab_window) |
| 3136 |
{ |
| 3137 |
tmp_impl = GDK_WINDOW_IMPL_WAYLAND (attached_grab_window->impl); |
| 3138 |
if (tmp_impl->grab_input_seat) |
| 3139 |
return gdk_wayland_seat_get_wl_seat (tmp_impl->grab_input_seat); |
| 3140 |
} |
| 3141 |
|
| 3142 |
while (transient_for) |
| 3143 |
{ |
| 3144 |
tmp_impl = GDK_WINDOW_IMPL_WAYLAND (transient_for->impl); |
| 3145 |
|
| 3146 |
if (tmp_impl->grab_input_seat) |
| 3147 |
return gdk_wayland_seat_get_wl_seat (tmp_impl->grab_input_seat); |
| 3148 |
|
| 3149 |
transient_for = tmp_impl->transient_for; |
| 3150 |
} |
| 3151 |
|
| 3152 |
return NULL; |
| 3153 |
} |
| 3154 |
|
| 3155 |
static gboolean |
| 3156 |
should_be_mapped (GdkWindow *window) |
| 3157 |
{ |
| 3158 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3159 |
|
| 3160 |
/* Don't map crazy temp that GTK+ uses for internal X11 shenanigans. */ |
| 3161 |
if (window->window_type == GDK_WINDOW_TEMP && window->x < 0 && window->y < 0) |
| 3162 |
return FALSE; |
| 3163 |
|
| 3164 |
if (impl->hint == GDK_WINDOW_TYPE_HINT_DND) |
| 3165 |
return FALSE; |
| 3166 |
|
| 3167 |
return TRUE; |
| 3168 |
} |
| 3169 |
|
| 3170 |
static gboolean |
| 3171 |
should_map_as_popup (GdkWindow *window) |
| 3172 |
{ |
| 3173 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3174 |
|
| 3175 |
/* Ideally, popup would be temp windows with a parent and grab */ |
| 3176 |
if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TEMP) |
| 3177 |
{ |
| 3178 |
/* If a temp window has a parent and a grab, we can use a popup */ |
| 3179 |
if (impl->transient_for) |
| 3180 |
{ |
| 3181 |
if (impl->grab_input_seat) |
| 3182 |
return TRUE; |
| 3183 |
} |
| 3184 |
} |
| 3185 |
|
| 3186 |
/* Yet we need to keep the window type hint tests for compatibility */ |
| 3187 |
switch (impl->hint) |
| 3188 |
{ |
| 3189 |
case GDK_WINDOW_TYPE_HINT_POPUP_MENU: |
| 3190 |
case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU: |
| 3191 |
case GDK_WINDOW_TYPE_HINT_COMBO: |
| 3192 |
return TRUE; |
| 3193 |
|
| 3194 |
default: |
| 3195 |
break; |
| 3196 |
} |
| 3197 |
|
| 3198 |
if (impl->position_method == POSITION_METHOD_MOVE_TO_RECT) |
| 3199 |
return TRUE; |
| 3200 |
|
| 3201 |
return FALSE; |
| 3202 |
} |
| 3203 |
|
| 3204 |
static gboolean |
| 3205 |
should_map_as_subsurface (GdkWindow *window) |
| 3206 |
{ |
| 3207 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3208 |
|
| 3209 |
if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_SUBSURFACE) |
| 3210 |
return TRUE; |
| 3211 |
|
| 3212 |
if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_TEMP) |
| 3213 |
return FALSE; |
| 3214 |
|
| 3215 |
/* if we want a popup, we do not want a subsurface */ |
| 3216 |
if (should_map_as_popup (window)) |
| 3217 |
return FALSE; |
| 3218 |
|
| 3219 |
if (impl->transient_for) |
| 3220 |
{ |
| 3221 |
GdkWindowImplWayland *impl_parent; |
| 3222 |
|
| 3223 |
impl_parent = GDK_WINDOW_IMPL_WAYLAND (impl->transient_for->impl); |
| 3224 |
/* subsurface require that the parent is mapped */ |
| 3225 |
if (impl_parent->mapped) |
| 3226 |
return TRUE; |
| 3227 |
else |
| 3228 |
g_warning ("Couldn't map window %p as subsurface because its parent is not mapped.", |
| 3229 |
window); |
| 3230 |
|
| 3231 |
} |
| 3232 |
|
| 3233 |
return FALSE; |
| 3234 |
} |
| 3235 |
|
| 3236 |
/* Get the window that can be used as a parent for a popup, i.e. a xdg_toplevel |
| 3237 |
* or xdg_popup. If the window is not, traverse up the transiency parents until |
| 3238 |
* we find one. |
| 3239 |
*/ |
| 3240 |
static GdkWindow * |
| 3241 |
get_popup_parent (GdkWindow *window) |
| 3242 |
{ |
| 3243 |
while (window) |
| 3244 |
{ |
| 3245 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3246 |
|
| 3247 |
if (is_realized_popup (window) || is_realized_toplevel (window)) |
| 3248 |
return window; |
| 3249 |
|
| 3250 |
window = impl->transient_for; |
| 3251 |
} |
| 3252 |
|
| 3253 |
return NULL; |
| 3254 |
} |
| 3255 |
|
| 3256 |
static void |
| 3257 |
gdk_wayland_window_map (GdkWindow *window) |
| 3258 |
{ |
| 3259 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3260 |
GdkWindow *transient_for = NULL; |
| 3261 |
|
| 3262 |
if (!should_be_mapped (window)) |
| 3263 |
return; |
| 3264 |
|
| 3265 |
if (impl->mapped || impl->use_custom_surface) |
| 3266 |
return; |
| 3267 |
|
| 3268 |
if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TEMP) |
| 3269 |
{ |
| 3270 |
if (!impl->transient_for) |
| 3271 |
{ |
| 3272 |
g_message ("Window %p is a temporary window without parent, " |
| 3273 |
"application will not be able to position it on screen.", |
| 3274 |
window); |
| 3275 |
} |
| 3276 |
} |
| 3277 |
|
| 3278 |
if (should_map_as_subsurface (window)) |
| 3279 |
{ |
| 3280 |
if (impl->transient_for) |
| 3281 |
gdk_wayland_window_create_subsurface (window); |
| 3282 |
else |
| 3283 |
g_warning ("Couldn't map window %p as susburface yet because it doesn't have a parent", |
| 3284 |
window); |
| 3285 |
} |
| 3286 |
else if (should_map_as_popup (window)) |
| 3287 |
{ |
| 3288 |
gboolean create_fallback = FALSE; |
| 3289 |
struct wl_seat *grab_input_seat; |
| 3290 |
|
| 3291 |
/* Popup menus can appear without a transient parent, which means they |
| 3292 |
* cannot be positioned properly on Wayland. This attempts to guess the |
| 3293 |
* surface they should be positioned with by finding the surface beneath |
| 3294 |
* the device that created the grab for the popup window. |
| 3295 |
*/ |
| 3296 |
if (!impl->transient_for && impl->hint == GDK_WINDOW_TYPE_HINT_POPUP_MENU) |
| 3297 |
{ |
| 3298 |
GdkDevice *grab_device = NULL; |
| 3299 |
|
| 3300 |
/* The popup menu window is not the grabbed window. This may mean |
| 3301 |
* that a "transfer window" (see gtkmenu.c) is used, and we need |
| 3302 |
* to find that window to get the grab device. If so is the case |
| 3303 |
* the "transfer window" can be retrieved via the |
| 3304 |
* "gdk-attached-grab-window" associated data field. |
| 3305 |
*/ |
| 3306 |
if (!impl->grab_input_seat) |
| 3307 |
{ |
| 3308 |
GdkWindow *attached_grab_window = |
| 3309 |
g_object_get_data (G_OBJECT (window), |
| 3310 |
"gdk-attached-grab-window"); |
| 3311 |
if (attached_grab_window) |
| 3312 |
{ |
| 3313 |
GdkWindowImplWayland *attached_impl = |
| 3314 |
GDK_WINDOW_IMPL_WAYLAND (attached_grab_window->impl); |
| 3315 |
grab_device = gdk_seat_get_pointer (attached_impl->grab_input_seat); |
| 3316 |
transient_for = |
| 3317 |
gdk_device_get_window_at_position (grab_device, |
| 3318 |
NULL, NULL); |
| 3319 |
} |
| 3320 |
} |
| 3321 |
else |
| 3322 |
{ |
| 3323 |
grab_device = gdk_seat_get_pointer (impl->grab_input_seat); |
| 3324 |
transient_for = |
| 3325 |
gdk_device_get_window_at_position (grab_device, NULL, NULL); |
| 3326 |
} |
| 3327 |
|
| 3328 |
if (transient_for) |
| 3329 |
transient_for = get_popup_parent (gdk_window_get_effective_toplevel (transient_for)); |
| 3330 |
|
| 3331 |
/* If the position was not explicitly set, start the popup at the |
| 3332 |
* position of the device that holds the grab. |
| 3333 |
*/ |
| 3334 |
if (impl->position_method == POSITION_METHOD_NONE && grab_device) |
| 3335 |
gdk_window_get_device_position (transient_for, grab_device, |
| 3336 |
&window->x, &window->y, NULL); |
| 3337 |
} |
| 3338 |
else |
| 3339 |
{ |
| 3340 |
transient_for = gdk_window_get_effective_toplevel (impl->transient_for); |
| 3341 |
transient_for = get_popup_parent (transient_for); |
| 3342 |
} |
| 3343 |
|
| 3344 |
if (!transient_for) |
| 3345 |
{ |
| 3346 |
g_warning ("Couldn't map as window %p as popup because it doesn't have a parent", |
| 3347 |
window); |
| 3348 |
|
| 3349 |
create_fallback = TRUE; |
| 3350 |
} |
| 3351 |
else |
| 3352 |
{ |
| 3353 |
grab_input_seat = find_grab_input_seat (window, transient_for); |
| 3354 |
} |
| 3355 |
|
| 3356 |
if (!create_fallback) |
| 3357 |
{ |
| 3358 |
gdk_wayland_window_create_xdg_popup (window, |
| 3359 |
transient_for, |
| 3360 |
grab_input_seat); |
| 3361 |
} |
| 3362 |
else |
| 3363 |
{ |
| 3364 |
gdk_wayland_window_create_xdg_toplevel (window); |
| 3365 |
gdk_wayland_window_announce_decoration_mode (window); |
| 3366 |
} |
| 3367 |
} |
| 3368 |
else |
| 3369 |
{ |
| 3370 |
gdk_wayland_window_create_xdg_toplevel (window); |
| 3371 |
gdk_wayland_window_announce_decoration_mode (window); |
| 3372 |
} |
| 3373 |
|
| 3374 |
impl->mapped = TRUE; |
| 3375 |
} |
| 3376 |
|
| 3377 |
static void |
| 3378 |
gdk_wayland_window_show (GdkWindow *window, |
| 3379 |
gboolean already_mapped) |
| 3380 |
{ |
| 3381 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3382 |
|
| 3383 |
if (!impl->display_server.wl_surface) |
| 3384 |
gdk_wayland_window_create_surface (window); |
| 3385 |
|
| 3386 |
gdk_wayland_window_map (window); |
| 3387 |
|
| 3388 |
_gdk_make_event (window, GDK_MAP, NULL, FALSE); |
| 3389 |
|
| 3390 |
if (impl->staging_cairo_surface && |
| 3391 |
_gdk_wayland_is_shm_surface (impl->staging_cairo_surface)) |
| 3392 |
gdk_wayland_window_attach_image (window); |
| 3393 |
} |
| 3394 |
|
| 3395 |
static void |
| 3396 |
unmap_subsurface (GdkWindow *window) |
| 3397 |
{ |
| 3398 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3399 |
GdkWindowImplWayland *parent_impl; |
| 3400 |
|
| 3401 |
g_return_if_fail (impl->display_server.wl_subsurface); |
| 3402 |
g_return_if_fail (impl->transient_for); |
| 3403 |
|
| 3404 |
parent_impl = GDK_WINDOW_IMPL_WAYLAND (impl->transient_for->impl); |
| 3405 |
wl_subsurface_destroy (impl->display_server.wl_subsurface); |
| 3406 |
if (impl->parent_surface_committed_handler) |
| 3407 |
{ |
| 3408 |
g_signal_handler_disconnect (parent_impl, |
| 3409 |
impl->parent_surface_committed_handler); |
| 3410 |
impl->parent_surface_committed_handler = 0; |
| 3411 |
} |
| 3412 |
impl->display_server.wl_subsurface = NULL; |
| 3413 |
} |
| 3414 |
|
| 3415 |
static void |
| 3416 |
unmap_popups_for_window (GdkWindow *window) |
| 3417 |
{ |
| 3418 |
GdkWaylandDisplay *display_wayland; |
| 3419 |
GList *l; |
| 3420 |
|
| 3421 |
display_wayland = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 3422 |
for (l = display_wayland->current_popups; l; l = l->next) |
| 3423 |
{ |
| 3424 |
GdkWindow *popup = l->data; |
| 3425 |
GdkWindowImplWayland *popup_impl = GDK_WINDOW_IMPL_WAYLAND (popup->impl); |
| 3426 |
|
| 3427 |
if (popup_impl->popup_parent == window) |
| 3428 |
{ |
| 3429 |
g_warning ("Tried to unmap the parent of a popup"); |
| 3430 |
gdk_window_hide (popup); |
| 3431 |
|
| 3432 |
return; |
| 3433 |
} |
| 3434 |
} |
| 3435 |
} |
| 3436 |
|
| 3437 |
static void |
| 3438 |
gdk_wayland_window_hide_surface (GdkWindow *window) |
| 3439 |
{ |
| 3440 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 3441 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3442 |
|
| 3443 |
unmap_popups_for_window (window); |
| 3444 |
|
| 3445 |
if (impl->display_server.wl_surface) |
| 3446 |
{ |
| 3447 |
if (impl->dummy_egl_surface) |
| 3448 |
{ |
| 3449 |
eglDestroySurface (display_wayland->egl_display, impl->dummy_egl_surface); |
| 3450 |
impl->dummy_egl_surface = NULL; |
| 3451 |
} |
| 3452 |
|
| 3453 |
if (impl->display_server.dummy_egl_window) |
| 3454 |
{ |
| 3455 |
wl_egl_window_destroy (impl->display_server.dummy_egl_window); |
| 3456 |
impl->display_server.dummy_egl_window = NULL; |
| 3457 |
} |
| 3458 |
|
| 3459 |
if (impl->egl_surface) |
| 3460 |
{ |
| 3461 |
eglDestroySurface (display_wayland->egl_display, impl->egl_surface); |
| 3462 |
impl->egl_surface = NULL; |
| 3463 |
} |
| 3464 |
|
| 3465 |
if (impl->display_server.egl_window) |
| 3466 |
{ |
| 3467 |
wl_egl_window_destroy (impl->display_server.egl_window); |
| 3468 |
impl->display_server.egl_window = NULL; |
| 3469 |
} |
| 3470 |
|
| 3471 |
if (impl->display_server.xdg_toplevel) |
| 3472 |
{ |
| 3473 |
xdg_toplevel_destroy (impl->display_server.xdg_toplevel); |
| 3474 |
impl->display_server.xdg_toplevel = NULL; |
| 3475 |
} |
| 3476 |
else if (impl->display_server.xdg_popup) |
| 3477 |
{ |
| 3478 |
xdg_popup_destroy (impl->display_server.xdg_popup); |
| 3479 |
impl->display_server.xdg_popup = NULL; |
| 3480 |
display_wayland->current_popups = |
| 3481 |
g_list_remove (display_wayland->current_popups, window); |
| 3482 |
|
| 3483 |
if (impl->position_method == POSITION_METHOD_MOVE_TO_RECT) |
| 3484 |
{ |
| 3485 |
window->x = 0; |
| 3486 |
window->y = 0; |
| 3487 |
} |
| 3488 |
} |
| 3489 |
if (impl->display_server.xdg_surface) |
| 3490 |
{ |
| 3491 |
xdg_surface_destroy (impl->display_server.xdg_surface); |
| 3492 |
impl->display_server.xdg_surface = NULL; |
| 3493 |
if (!impl->initial_configure_received) |
| 3494 |
gdk_window_thaw_updates (window); |
| 3495 |
else |
| 3496 |
impl->initial_configure_received = FALSE; |
| 3497 |
} |
| 3498 |
|
| 3499 |
if (impl->display_server.zxdg_toplevel_v6) |
| 3500 |
{ |
| 3501 |
zxdg_toplevel_v6_destroy (impl->display_server.zxdg_toplevel_v6); |
| 3502 |
impl->display_server.zxdg_toplevel_v6 = NULL; |
| 3503 |
} |
| 3504 |
else if (impl->display_server.zxdg_popup_v6) |
| 3505 |
{ |
| 3506 |
zxdg_popup_v6_destroy (impl->display_server.zxdg_popup_v6); |
| 3507 |
impl->display_server.zxdg_popup_v6 = NULL; |
| 3508 |
display_wayland->current_popups = |
| 3509 |
g_list_remove (display_wayland->current_popups, window); |
| 3510 |
|
| 3511 |
if (impl->position_method == POSITION_METHOD_MOVE_TO_RECT) |
| 3512 |
{ |
| 3513 |
window->x = 0; |
| 3514 |
window->y = 0; |
| 3515 |
} |
| 3516 |
} |
| 3517 |
if (impl->display_server.zxdg_surface_v6) |
| 3518 |
{ |
| 3519 |
zxdg_surface_v6_destroy (impl->display_server.zxdg_surface_v6); |
| 3520 |
impl->display_server.zxdg_surface_v6 = NULL; |
| 3521 |
if (!impl->initial_configure_received) |
| 3522 |
gdk_window_thaw_updates (window); |
| 3523 |
else |
| 3524 |
impl->initial_configure_received = FALSE; |
| 3525 |
} |
| 3526 |
|
| 3527 |
if (impl->display_server.wl_subsurface) |
| 3528 |
unmap_subsurface (window); |
| 3529 |
|
| 3530 |
if (impl->awaiting_frame) |
| 3531 |
{ |
| 3532 |
GdkFrameClock *frame_clock; |
| 3533 |
|
| 3534 |
impl->awaiting_frame = FALSE; |
| 3535 |
frame_clock = gdk_window_get_frame_clock (window); |
| 3536 |
if (frame_clock) |
| 3537 |
_gdk_frame_clock_thaw (frame_clock); |
| 3538 |
} |
| 3539 |
|
| 3540 |
if (impl->display_server.gtk_surface) |
| 3541 |
{ |
| 3542 |
if (display_wayland->gtk_shell_version >= |
| 3543 |
GTK_SURFACE1_RELEASE_SINCE_VERSION) |
| 3544 |
gtk_surface1_release (impl->display_server.gtk_surface); |
| 3545 |
else |
| 3546 |
gtk_surface1_destroy (impl->display_server.gtk_surface); |
| 3547 |
impl->display_server.gtk_surface = NULL; |
| 3548 |
impl->application.was_set = FALSE; |
| 3549 |
} |
| 3550 |
|
| 3551 |
if (impl->display_server.server_decoration) |
| 3552 |
{ |
| 3553 |
org_kde_kwin_server_decoration_release (impl->display_server.server_decoration); |
| 3554 |
impl->display_server.server_decoration = NULL; |
| 3555 |
} |
| 3556 |
|
| 3557 |
wl_surface_destroy (impl->display_server.wl_surface); |
| 3558 |
impl->display_server.wl_surface = NULL; |
| 3559 |
g_clear_pointer (&impl->surface_callback, wl_callback_destroy); |
| 3560 |
|
| 3561 |
g_slist_free (impl->display_server.outputs); |
| 3562 |
impl->display_server.outputs = NULL; |
| 3563 |
|
| 3564 |
if (impl->hint == GDK_WINDOW_TYPE_HINT_DIALOG && !impl->transient_for) |
| 3565 |
display_wayland->orphan_dialogs = |
| 3566 |
g_list_remove (display_wayland->orphan_dialogs, window); |
| 3567 |
} |
| 3568 |
|
| 3569 |
unset_transient_for_exported (window); |
| 3570 |
|
| 3571 |
_gdk_wayland_window_clear_saved_size (window); |
| 3572 |
drop_cairo_surfaces (window); |
| 3573 |
impl->pending_commit = FALSE; |
| 3574 |
impl->mapped = FALSE; |
| 3575 |
} |
| 3576 |
|
| 3577 |
static void |
| 3578 |
gdk_wayland_window_hide (GdkWindow *window) |
| 3579 |
{ |
| 3580 |
gdk_wayland_window_hide_surface (window); |
| 3581 |
_gdk_window_clear_update_area (window); |
| 3582 |
} |
| 3583 |
|
| 3584 |
static void |
| 3585 |
gdk_window_wayland_withdraw (GdkWindow *window) |
| 3586 |
{ |
| 3587 |
if (!window->destroyed) |
| 3588 |
{ |
| 3589 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 3590 |
gdk_synthesize_window_state (window, 0, GDK_WINDOW_STATE_WITHDRAWN); |
| 3591 |
|
| 3592 |
g_assert (!GDK_WINDOW_IS_MAPPED (window)); |
| 3593 |
|
| 3594 |
gdk_wayland_window_hide_surface (window); |
| 3595 |
} |
| 3596 |
} |
| 3597 |
|
| 3598 |
static void |
| 3599 |
gdk_window_wayland_set_events (GdkWindow *window, |
| 3600 |
GdkEventMask event_mask) |
| 3601 |
{ |
| 3602 |
GDK_WINDOW (window)->event_mask = event_mask; |
| 3603 |
} |
| 3604 |
|
| 3605 |
static GdkEventMask |
| 3606 |
gdk_window_wayland_get_events (GdkWindow *window) |
| 3607 |
{ |
| 3608 |
if (GDK_WINDOW_DESTROYED (window)) |
| 3609 |
return 0; |
| 3610 |
else |
| 3611 |
return GDK_WINDOW (window)->event_mask; |
| 3612 |
} |
| 3613 |
|
| 3614 |
static void |
| 3615 |
gdk_window_wayland_raise (GdkWindow *window) |
| 3616 |
{ |
| 3617 |
} |
| 3618 |
|
| 3619 |
static void |
| 3620 |
gdk_window_wayland_lower (GdkWindow *window) |
| 3621 |
{ |
| 3622 |
} |
| 3623 |
|
| 3624 |
static void |
| 3625 |
gdk_window_wayland_restack_under (GdkWindow *window, |
| 3626 |
GList *native_siblings) |
| 3627 |
{ |
| 3628 |
} |
| 3629 |
|
| 3630 |
static void |
| 3631 |
gdk_window_wayland_restack_toplevel (GdkWindow *window, |
| 3632 |
GdkWindow *sibling, |
| 3633 |
gboolean above) |
| 3634 |
{ |
| 3635 |
} |
| 3636 |
|
| 3637 |
static void |
| 3638 |
gdk_window_request_transient_parent_commit (GdkWindow *window) |
| 3639 |
{ |
| 3640 |
GdkWindowImplWayland *window_impl, *impl; |
| 3641 |
GdkFrameClock *frame_clock; |
| 3642 |
|
| 3643 |
window_impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3644 |
|
| 3645 |
if (!window_impl->transient_for) |
| 3646 |
return; |
| 3647 |
|
| 3648 |
impl = GDK_WINDOW_IMPL_WAYLAND (window_impl->transient_for->impl); |
| 3649 |
|
| 3650 |
if (!impl->display_server.wl_surface || impl->pending_commit) |
| 3651 |
return; |
| 3652 |
|
| 3653 |
frame_clock = gdk_window_get_frame_clock (window_impl->transient_for); |
| 3654 |
|
| 3655 |
if (!frame_clock) |
| 3656 |
return; |
| 3657 |
|
| 3658 |
impl->pending_commit = TRUE; |
| 3659 |
gdk_frame_clock_request_phase (frame_clock, |
| 3660 |
GDK_FRAME_CLOCK_PHASE_AFTER_PAINT); |
| 3661 |
} |
| 3662 |
|
| 3663 |
static void |
| 3664 |
gdk_window_wayland_move_resize (GdkWindow *window, |
| 3665 |
gboolean with_move, |
| 3666 |
gint x, |
| 3667 |
gint y, |
| 3668 |
gint width, |
| 3669 |
gint height) |
| 3670 |
{ |
| 3671 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3672 |
|
| 3673 |
if (with_move) |
| 3674 |
{ |
| 3675 |
/* Each toplevel has in its own "root" coordinate system */ |
| 3676 |
if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_TOPLEVEL) |
| 3677 |
{ |
| 3678 |
window->x = x; |
| 3679 |
window->y = y; |
| 3680 |
impl->position_method = POSITION_METHOD_MOVE_RESIZE; |
| 3681 |
|
| 3682 |
if (impl->display_server.wl_subsurface && |
| 3683 |
(x + window->abs_x != impl->subsurface_x || |
| 3684 |
y + window->abs_y != impl->subsurface_y)) |
| 3685 |
{ |
| 3686 |
gdk_wayland_window_set_subsurface_position (window, |
| 3687 |
x + window->abs_x, |
| 3688 |
y + window->abs_y); |
| 3689 |
} |
| 3690 |
} |
| 3691 |
} |
| 3692 |
|
| 3693 |
if (window->state & (GDK_WINDOW_STATE_FULLSCREEN | |
| 3694 |
GDK_WINDOW_STATE_MAXIMIZED | |
| 3695 |
GDK_WINDOW_STATE_TILED)) |
| 3696 |
{ |
| 3697 |
impl->saved_width = width; |
| 3698 |
impl->saved_height = height; |
| 3699 |
impl->saved_size_changed = (width > 0 && height > 0); |
| 3700 |
} |
| 3701 |
|
| 3702 |
/* If this function is called with width and height = -1 then that means |
| 3703 |
* just move the window - don't update its size |
| 3704 |
*/ |
| 3705 |
if (width > 0 && height > 0) |
| 3706 |
{ |
| 3707 |
if (!should_use_fixed_size (window->state) || |
| 3708 |
(width == impl->fixed_size_width && |
| 3709 |
height == impl->fixed_size_height)) |
| 3710 |
{ |
| 3711 |
gdk_wayland_window_maybe_configure (window, |
| 3712 |
width, |
| 3713 |
height, |
| 3714 |
impl->scale); |
| 3715 |
} |
| 3716 |
else if (!should_inhibit_resize (window)) |
| 3717 |
{ |
| 3718 |
gdk_wayland_window_configure (window, |
| 3719 |
window->width, |
| 3720 |
window->height, |
| 3721 |
impl->scale); |
| 3722 |
} |
| 3723 |
} |
| 3724 |
} |
| 3725 |
|
| 3726 |
/* Avoid zero width/height as this is a protocol error */ |
| 3727 |
static void |
| 3728 |
sanitize_anchor_rect (GdkWindow *window, |
| 3729 |
GdkRectangle *rect) |
| 3730 |
{ |
| 3731 |
gint original_width = rect->width; |
| 3732 |
gint original_height = rect->height; |
| 3733 |
|
| 3734 |
rect->width = MAX (1, rect->width); |
| 3735 |
rect->height = MAX (1, rect->height); |
| 3736 |
rect->x = MAX (rect->x + original_width - rect->width, 0); |
| 3737 |
rect->y = MAX (rect->y + original_height - rect->height, 0); |
| 3738 |
} |
| 3739 |
|
| 3740 |
static void |
| 3741 |
gdk_window_wayland_move_to_rect (GdkWindow *window, |
| 3742 |
const GdkRectangle *rect, |
| 3743 |
GdkGravity rect_anchor, |
| 3744 |
GdkGravity window_anchor, |
| 3745 |
GdkAnchorHints anchor_hints, |
| 3746 |
gint rect_anchor_dx, |
| 3747 |
gint rect_anchor_dy) |
| 3748 |
{ |
| 3749 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3750 |
|
| 3751 |
impl->pending_move_to_rect.rect = *rect; |
| 3752 |
sanitize_anchor_rect (window, &impl->pending_move_to_rect.rect); |
| 3753 |
|
| 3754 |
impl->pending_move_to_rect.rect_anchor = rect_anchor; |
| 3755 |
impl->pending_move_to_rect.window_anchor = window_anchor; |
| 3756 |
impl->pending_move_to_rect.anchor_hints = anchor_hints; |
| 3757 |
impl->pending_move_to_rect.rect_anchor_dx = rect_anchor_dx; |
| 3758 |
impl->pending_move_to_rect.rect_anchor_dy = rect_anchor_dy; |
| 3759 |
|
| 3760 |
impl->position_method = POSITION_METHOD_MOVE_TO_RECT; |
| 3761 |
} |
| 3762 |
|
| 3763 |
static void |
| 3764 |
gdk_window_wayland_set_background (GdkWindow *window, |
| 3765 |
cairo_pattern_t *pattern) |
| 3766 |
{ |
| 3767 |
} |
| 3768 |
|
| 3769 |
static gboolean |
| 3770 |
gdk_window_wayland_reparent (GdkWindow *window, |
| 3771 |
GdkWindow *new_parent, |
| 3772 |
gint x, |
| 3773 |
gint y) |
| 3774 |
{ |
| 3775 |
return FALSE; |
| 3776 |
} |
| 3777 |
|
| 3778 |
static void |
| 3779 |
gdk_window_wayland_set_device_cursor (GdkWindow *window, |
| 3780 |
GdkDevice *device, |
| 3781 |
GdkCursor *cursor) |
| 3782 |
{ |
| 3783 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 3784 |
g_return_if_fail (GDK_IS_DEVICE (device)); |
| 3785 |
|
| 3786 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 3787 |
GDK_DEVICE_GET_CLASS (device)->set_window_cursor (device, window, cursor); |
| 3788 |
} |
| 3789 |
|
| 3790 |
static void |
| 3791 |
gdk_window_wayland_get_geometry (GdkWindow *window, |
| 3792 |
gint *x, |
| 3793 |
gint *y, |
| 3794 |
gint *width, |
| 3795 |
gint *height) |
| 3796 |
{ |
| 3797 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 3798 |
{ |
| 3799 |
if (x) |
| 3800 |
*x = window->x; |
| 3801 |
if (y) |
| 3802 |
*y = window->y; |
| 3803 |
if (width) |
| 3804 |
*width = window->width; |
| 3805 |
if (height) |
| 3806 |
*height = window->height; |
| 3807 |
} |
| 3808 |
} |
| 3809 |
|
| 3810 |
static void |
| 3811 |
gdk_window_wayland_get_root_coords (GdkWindow *window, |
| 3812 |
gint x, |
| 3813 |
gint y, |
| 3814 |
gint *root_x, |
| 3815 |
gint *root_y) |
| 3816 |
{ |
| 3817 |
/* |
| 3818 |
* Wayland does not have a global coordinate space shared between surfaces. In |
| 3819 |
* fact, for regular toplevels, we have no idea where our surfaces are |
| 3820 |
* positioned, relatively. |
| 3821 |
* |
| 3822 |
* However, there are some cases like popups and subsurfaces where we do have |
| 3823 |
* some amount of control over the placement of our window, and we can |
| 3824 |
* semi-accurately control the x/y position of these windows, if they are |
| 3825 |
* relative to another surface. |
| 3826 |
* |
| 3827 |
* To pretend we have something called a root coordinate space, assume all |
| 3828 |
* parent-less windows are positioned in (0, 0), and all relative positioned |
| 3829 |
* popups and subsurfaces are placed within this fake root coordinate space. |
| 3830 |
* |
| 3831 |
* For example a 200x200 large toplevel window will have the position (0, 0). |
| 3832 |
* If a popup positioned in the middle of the toplevel will have the fake |
| 3833 |
* position (100,100). Furthermore, if a positioned is placed in the middle |
| 3834 |
* that popup, will have the fake position (150,150), even though it has the |
| 3835 |
* relative position (50,50). These three windows would make up one single |
| 3836 |
* fake root coordinate space. |
| 3837 |
*/ |
| 3838 |
|
| 3839 |
if (root_x) |
| 3840 |
*root_x = window->x + x; |
| 3841 |
|
| 3842 |
if (root_y) |
| 3843 |
*root_y = window->y + y; |
| 3844 |
} |
| 3845 |
|
| 3846 |
static gboolean |
| 3847 |
gdk_window_wayland_get_device_state (GdkWindow *window, |
| 3848 |
GdkDevice *device, |
| 3849 |
gdouble *x, |
| 3850 |
gdouble *y, |
| 3851 |
GdkModifierType *mask) |
| 3852 |
{ |
| 3853 |
gboolean return_val; |
| 3854 |
|
| 3855 |
g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE); |
| 3856 |
|
| 3857 |
return_val = TRUE; |
| 3858 |
|
| 3859 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 3860 |
{ |
| 3861 |
GdkWindow *child; |
| 3862 |
|
| 3863 |
GDK_DEVICE_GET_CLASS (device)->query_state (device, window, |
| 3864 |
NULL, &child, |
| 3865 |
NULL, NULL, |
| 3866 |
x, y, mask); |
| 3867 |
return_val = (child != NULL); |
| 3868 |
} |
| 3869 |
|
| 3870 |
return return_val; |
| 3871 |
} |
| 3872 |
|
| 3873 |
static void |
| 3874 |
gdk_window_wayland_shape_combine_region (GdkWindow *window, |
| 3875 |
const cairo_region_t *shape_region, |
| 3876 |
gint offset_x, |
| 3877 |
gint offset_y) |
| 3878 |
{ |
| 3879 |
} |
| 3880 |
|
| 3881 |
static void |
| 3882 |
gdk_window_wayland_input_shape_combine_region (GdkWindow *window, |
| 3883 |
const cairo_region_t *shape_region, |
| 3884 |
gint offset_x, |
| 3885 |
gint offset_y) |
| 3886 |
{ |
| 3887 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3888 |
|
| 3889 |
if (GDK_WINDOW_DESTROYED (window)) |
| 3890 |
return; |
| 3891 |
|
| 3892 |
g_clear_pointer (&impl->input_region, cairo_region_destroy); |
| 3893 |
|
| 3894 |
if (shape_region) |
| 3895 |
{ |
| 3896 |
impl->input_region = cairo_region_copy (shape_region); |
| 3897 |
cairo_region_translate (impl->input_region, offset_x, offset_y); |
| 3898 |
} |
| 3899 |
|
| 3900 |
impl->input_region_dirty = TRUE; |
| 3901 |
} |
| 3902 |
|
| 3903 |
static void |
| 3904 |
gdk_wayland_window_destroy (GdkWindow *window, |
| 3905 |
gboolean recursing, |
| 3906 |
gboolean foreign_destroy) |
| 3907 |
{ |
| 3908 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 3909 |
|
| 3910 |
/* Wayland windows can't be externally destroyed; we may possibly |
| 3911 |
* eventually want to use this path at display close-down |
| 3912 |
*/ |
| 3913 |
g_return_if_fail (!foreign_destroy); |
| 3914 |
|
| 3915 |
gdk_wayland_window_hide_surface (window); |
| 3916 |
} |
| 3917 |
|
| 3918 |
static void |
| 3919 |
gdk_window_wayland_destroy_foreign (GdkWindow *window) |
| 3920 |
{ |
| 3921 |
} |
| 3922 |
|
| 3923 |
static cairo_region_t * |
| 3924 |
gdk_wayland_window_get_shape (GdkWindow *window) |
| 3925 |
{ |
| 3926 |
return NULL; |
| 3927 |
} |
| 3928 |
|
| 3929 |
static cairo_region_t * |
| 3930 |
gdk_wayland_window_get_input_shape (GdkWindow *window) |
| 3931 |
{ |
| 3932 |
return NULL; |
| 3933 |
} |
| 3934 |
|
| 3935 |
#ifdef HAVE_XDG_ACTIVATION |
| 3936 |
static void |
| 3937 |
token_done (gpointer data, |
| 3938 |
struct xdg_activation_token_v1 *provider, |
| 3939 |
const char *token) |
| 3940 |
{ |
| 3941 |
char **token_out = data; |
| 3942 |
|
| 3943 |
*token_out = g_strdup (token); |
| 3944 |
} |
| 3945 |
|
| 3946 |
static const struct xdg_activation_token_v1_listener token_listener = { |
| 3947 |
token_done, |
| 3948 |
}; |
| 3949 |
#endif |
| 3950 |
|
| 3951 |
static void |
| 3952 |
gdk_wayland_window_focus (GdkWindow *window, |
| 3953 |
guint32 timestamp) |
| 3954 |
{ |
| 3955 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 3956 |
GdkDisplay *display = gdk_window_get_display (window); |
| 3957 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display); |
| 3958 |
gchar *startup_id = NULL; |
| 3959 |
|
| 3960 |
startup_id = g_steal_pointer (&display_wayland->startup_notification_id); |
| 3961 |
|
| 3962 |
#ifdef HAVE_XDG_ACTIVATION |
| 3963 |
if (display_wayland->xdg_activation) |
| 3964 |
{ |
| 3965 |
GdkSeat *seat = gdk_display_get_default_seat (display); |
| 3966 |
|
| 3967 |
/* If the focus request does not have a startup ID associated, get a |
| 3968 |
* new token to activate the window. |
| 3969 |
*/ |
| 3970 |
if (!startup_id) |
| 3971 |
{ |
| 3972 |
struct xdg_activation_token_v1 *token; |
| 3973 |
struct wl_event_queue *event_queue; |
| 3974 |
struct wl_surface *wl_surface = NULL; |
| 3975 |
GdkWindow *focus_window; |
| 3976 |
|
| 3977 |
event_queue = wl_display_create_queue (display_wayland->wl_display); |
| 3978 |
|
| 3979 |
token = xdg_activation_v1_get_activation_token (display_wayland->xdg_activation); |
| 3980 |
wl_proxy_set_queue ((struct wl_proxy *) token, event_queue); |
| 3981 |
|
| 3982 |
xdg_activation_token_v1_add_listener (token, |
| 3983 |
&token_listener, |
| 3984 |
&startup_id); |
| 3985 |
xdg_activation_token_v1_set_serial (token, |
| 3986 |
_gdk_wayland_seat_get_last_implicit_grab_serial (seat, NULL), |
| 3987 |
gdk_wayland_seat_get_wl_seat (seat)); |
| 3988 |
|
| 3989 |
focus_window = gdk_wayland_device_get_focus (gdk_seat_get_keyboard (seat)); |
| 3990 |
if (focus_window) |
| 3991 |
wl_surface = gdk_wayland_window_get_wl_surface (focus_window); |
| 3992 |
if (wl_surface) |
| 3993 |
xdg_activation_token_v1_set_surface (token, wl_surface); |
| 3994 |
|
| 3995 |
xdg_activation_token_v1_commit (token); |
| 3996 |
|
| 3997 |
while (startup_id == NULL) |
| 3998 |
wl_display_dispatch_queue (display_wayland->wl_display, event_queue); |
| 3999 |
|
| 4000 |
xdg_activation_token_v1_destroy (token); |
| 4001 |
wl_event_queue_destroy (event_queue); |
| 4002 |
} |
| 4003 |
|
| 4004 |
xdg_activation_v1_activate (display_wayland->xdg_activation, |
| 4005 |
startup_id, |
| 4006 |
impl->display_server.wl_surface); |
| 4007 |
} |
| 4008 |
else |
| 4009 |
#endif |
| 4010 |
if (impl->display_server.gtk_surface) |
| 4011 |
{ |
| 4012 |
if (timestamp != GDK_CURRENT_TIME) |
| 4013 |
gtk_surface1_present (impl->display_server.gtk_surface, timestamp); |
| 4014 |
else if (startup_id && display_wayland->gtk_shell_version >= 3) |
| 4015 |
gtk_surface1_request_focus (impl->display_server.gtk_surface, |
| 4016 |
startup_id); |
| 4017 |
} |
| 4018 |
|
| 4019 |
g_free (startup_id); |
| 4020 |
} |
| 4021 |
|
| 4022 |
static void |
| 4023 |
gdk_wayland_window_set_type_hint (GdkWindow *window, |
| 4024 |
GdkWindowTypeHint hint) |
| 4025 |
{ |
| 4026 |
GdkWindowImplWayland *impl; |
| 4027 |
|
| 4028 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4029 |
|
| 4030 |
if (GDK_WINDOW_DESTROYED (window)) |
| 4031 |
return; |
| 4032 |
|
| 4033 |
impl->hint = hint; |
| 4034 |
} |
| 4035 |
|
| 4036 |
static GdkWindowTypeHint |
| 4037 |
gdk_wayland_window_get_type_hint (GdkWindow *window) |
| 4038 |
{ |
| 4039 |
GdkWindowImplWayland *impl; |
| 4040 |
|
| 4041 |
if (GDK_WINDOW_DESTROYED (window)) |
| 4042 |
return GDK_WINDOW_TYPE_HINT_NORMAL; |
| 4043 |
|
| 4044 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4045 |
|
| 4046 |
return impl->hint; |
| 4047 |
} |
| 4048 |
|
| 4049 |
static void |
| 4050 |
gtk_surface_configure (void *data, |
| 4051 |
struct gtk_surface1 *gtk_surface, |
| 4052 |
struct wl_array *states) |
| 4053 |
{ |
| 4054 |
GdkWindow *window = GDK_WINDOW (data); |
| 4055 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4056 |
GdkWindowState new_state = 0; |
| 4057 |
uint32_t *p; |
| 4058 |
|
| 4059 |
wl_array_for_each (p, states) |
| 4060 |
{ |
| 4061 |
uint32_t state = *p; |
| 4062 |
|
| 4063 |
switch (state) |
| 4064 |
{ |
| 4065 |
case GTK_SURFACE1_STATE_TILED: |
| 4066 |
new_state |= GDK_WINDOW_STATE_TILED; |
| 4067 |
break; |
| 4068 |
|
| 4069 |
/* Since v2 */ |
| 4070 |
case GTK_SURFACE1_STATE_TILED_TOP: |
| 4071 |
new_state |= (GDK_WINDOW_STATE_TILED | GDK_WINDOW_STATE_TOP_TILED); |
| 4072 |
break; |
| 4073 |
case GTK_SURFACE1_STATE_TILED_RIGHT: |
| 4074 |
new_state |= (GDK_WINDOW_STATE_TILED | GDK_WINDOW_STATE_RIGHT_TILED); |
| 4075 |
break; |
| 4076 |
case GTK_SURFACE1_STATE_TILED_BOTTOM: |
| 4077 |
new_state |= (GDK_WINDOW_STATE_TILED | GDK_WINDOW_STATE_BOTTOM_TILED); |
| 4078 |
break; |
| 4079 |
case GTK_SURFACE1_STATE_TILED_LEFT: |
| 4080 |
new_state |= (GDK_WINDOW_STATE_TILED | GDK_WINDOW_STATE_LEFT_TILED); |
| 4081 |
break; |
| 4082 |
default: |
| 4083 |
/* Unknown state */ |
| 4084 |
break; |
| 4085 |
} |
| 4086 |
} |
| 4087 |
|
| 4088 |
impl->pending.state |= new_state; |
| 4089 |
} |
| 4090 |
|
| 4091 |
static void |
| 4092 |
gtk_surface_configure_edges (void *data, |
| 4093 |
struct gtk_surface1 *gtk_surface, |
| 4094 |
struct wl_array *edge_constraints) |
| 4095 |
{ |
| 4096 |
GdkWindow *window = GDK_WINDOW (data); |
| 4097 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4098 |
GdkWindowState new_state = 0; |
| 4099 |
uint32_t *p; |
| 4100 |
|
| 4101 |
wl_array_for_each (p, edge_constraints) |
| 4102 |
{ |
| 4103 |
uint32_t constraint = *p; |
| 4104 |
|
| 4105 |
switch (constraint) |
| 4106 |
{ |
| 4107 |
case GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_TOP: |
| 4108 |
new_state |= GDK_WINDOW_STATE_TOP_RESIZABLE; |
| 4109 |
break; |
| 4110 |
case GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_RIGHT: |
| 4111 |
new_state |= GDK_WINDOW_STATE_RIGHT_RESIZABLE; |
| 4112 |
break; |
| 4113 |
case GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_BOTTOM: |
| 4114 |
new_state |= GDK_WINDOW_STATE_BOTTOM_RESIZABLE; |
| 4115 |
break; |
| 4116 |
case GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_LEFT: |
| 4117 |
new_state |= GDK_WINDOW_STATE_LEFT_RESIZABLE; |
| 4118 |
break; |
| 4119 |
default: |
| 4120 |
/* Unknown state */ |
| 4121 |
break; |
| 4122 |
} |
| 4123 |
} |
| 4124 |
|
| 4125 |
impl->pending.state |= new_state; |
| 4126 |
} |
| 4127 |
|
| 4128 |
static const struct gtk_surface1_listener gtk_surface_listener = { |
| 4129 |
gtk_surface_configure, |
| 4130 |
gtk_surface_configure_edges |
| 4131 |
}; |
| 4132 |
|
| 4133 |
static void |
| 4134 |
gdk_wayland_window_init_gtk_surface (GdkWindow *window) |
| 4135 |
{ |
| 4136 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4137 |
GdkWaylandDisplay *display = |
| 4138 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 4139 |
|
| 4140 |
if (impl->display_server.gtk_surface != NULL) |
| 4141 |
return; |
| 4142 |
if (!is_realized_toplevel (window)) |
| 4143 |
return; |
| 4144 |
if (display->gtk_shell == NULL) |
| 4145 |
return; |
| 4146 |
|
| 4147 |
impl->display_server.gtk_surface = |
| 4148 |
gtk_shell1_get_gtk_surface (display->gtk_shell, |
| 4149 |
impl->display_server.wl_surface); |
| 4150 |
gdk_window_set_geometry_hints (window, |
| 4151 |
&impl->geometry_hints, |
| 4152 |
impl->geometry_mask); |
| 4153 |
gtk_surface1_add_listener (impl->display_server.gtk_surface, |
| 4154 |
>k_surface_listener, |
| 4155 |
window); |
| 4156 |
} |
| 4157 |
|
| 4158 |
static void |
| 4159 |
maybe_set_gtk_surface_modal (GdkWindow *window) |
| 4160 |
{ |
| 4161 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4162 |
|
| 4163 |
gdk_wayland_window_init_gtk_surface (window); |
| 4164 |
if (impl->display_server.gtk_surface == NULL) |
| 4165 |
return; |
| 4166 |
|
| 4167 |
if (window->modal_hint) |
| 4168 |
gtk_surface1_set_modal (impl->display_server.gtk_surface); |
| 4169 |
else |
| 4170 |
gtk_surface1_unset_modal (impl->display_server.gtk_surface); |
| 4171 |
|
| 4172 |
} |
| 4173 |
|
| 4174 |
static void |
| 4175 |
gdk_wayland_window_set_modal_hint (GdkWindow *window, |
| 4176 |
gboolean modal) |
| 4177 |
{ |
| 4178 |
window->modal_hint = modal; |
| 4179 |
maybe_set_gtk_surface_modal (window); |
| 4180 |
} |
| 4181 |
|
| 4182 |
static void |
| 4183 |
gdk_wayland_window_set_skip_taskbar_hint (GdkWindow *window, |
| 4184 |
gboolean skips_taskbar) |
| 4185 |
{ |
| 4186 |
} |
| 4187 |
|
| 4188 |
static void |
| 4189 |
gdk_wayland_window_set_skip_pager_hint (GdkWindow *window, |
| 4190 |
gboolean skips_pager) |
| 4191 |
{ |
| 4192 |
} |
| 4193 |
|
| 4194 |
static void |
| 4195 |
gdk_wayland_window_set_urgency_hint (GdkWindow *window, |
| 4196 |
gboolean urgent) |
| 4197 |
{ |
| 4198 |
} |
| 4199 |
|
| 4200 |
static void |
| 4201 |
gdk_wayland_window_set_geometry_hints (GdkWindow *window, |
| 4202 |
const GdkGeometry *geometry, |
| 4203 |
GdkWindowHints geom_mask) |
| 4204 |
{ |
| 4205 |
GdkWaylandDisplay *display_wayland; |
| 4206 |
GdkWindowImplWayland *impl; |
| 4207 |
int min_width = 0, min_height = 0, max_width = 0, max_height = 0; |
| 4208 |
|
| 4209 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4210 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4211 |
return; |
| 4212 |
|
| 4213 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4214 |
display_wayland = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 4215 |
|
| 4216 |
impl->geometry_hints = *geometry; |
| 4217 |
impl->geometry_mask = geom_mask; |
| 4218 |
|
| 4219 |
if (!is_realized_toplevel (window)) |
| 4220 |
return; |
| 4221 |
|
| 4222 |
if (geom_mask & GDK_HINT_MIN_SIZE) |
| 4223 |
{ |
| 4224 |
min_width = |
| 4225 |
MAX (0, calculate_width_without_margin (window, geometry->min_width)); |
| 4226 |
min_height = |
| 4227 |
MAX (0, calculate_height_without_margin (window, geometry->min_height)); |
| 4228 |
} |
| 4229 |
|
| 4230 |
if (geom_mask & GDK_HINT_MAX_SIZE) |
| 4231 |
{ |
| 4232 |
max_width = |
| 4233 |
MAX (0, calculate_width_without_margin (window, geometry->max_width)); |
| 4234 |
max_height = |
| 4235 |
MAX (0, calculate_height_without_margin (window, geometry->max_height)); |
| 4236 |
} |
| 4237 |
|
| 4238 |
switch (display_wayland->shell_variant) |
| 4239 |
{ |
| 4240 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 4241 |
xdg_toplevel_set_min_size (impl->display_server.xdg_toplevel, |
| 4242 |
min_width, min_height); |
| 4243 |
xdg_toplevel_set_max_size (impl->display_server.xdg_toplevel, |
| 4244 |
max_width, max_height); |
| 4245 |
break; |
| 4246 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 4247 |
zxdg_toplevel_v6_set_min_size (impl->display_server.zxdg_toplevel_v6, |
| 4248 |
min_width, min_height); |
| 4249 |
zxdg_toplevel_v6_set_max_size (impl->display_server.zxdg_toplevel_v6, |
| 4250 |
max_width, max_height); |
| 4251 |
break; |
| 4252 |
} |
| 4253 |
} |
| 4254 |
|
| 4255 |
static void |
| 4256 |
gdk_wayland_window_set_title (GdkWindow *window, |
| 4257 |
const gchar *title) |
| 4258 |
{ |
| 4259 |
GdkWindowImplWayland *impl; |
| 4260 |
const char *end; |
| 4261 |
gsize title_length; |
| 4262 |
|
| 4263 |
g_return_if_fail (title != NULL); |
| 4264 |
|
| 4265 |
if (GDK_WINDOW_DESTROYED (window)) |
| 4266 |
return; |
| 4267 |
|
| 4268 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4269 |
|
| 4270 |
if (g_strcmp0 (impl->title, title) == 0) |
| 4271 |
return; |
| 4272 |
|
| 4273 |
g_free (impl->title); |
| 4274 |
|
| 4275 |
title_length = MIN (strlen (title), MAX_WL_BUFFER_SIZE); |
| 4276 |
if (g_utf8_validate (title, title_length, &end)) |
| 4277 |
{ |
| 4278 |
impl->title = g_malloc (end - title + 1); |
| 4279 |
memcpy (impl->title, title, end - title); |
| 4280 |
impl->title[end - title] = '\0'; |
| 4281 |
} |
| 4282 |
else |
| 4283 |
{ |
| 4284 |
impl->title = g_utf8_make_valid (title, title_length); |
| 4285 |
g_warning ("Invalid utf8 passed to gdk_window_set_title: '%s'", title); |
| 4286 |
} |
| 4287 |
|
| 4288 |
gdk_wayland_window_sync_title (window); |
| 4289 |
} |
| 4290 |
|
| 4291 |
static void |
| 4292 |
gdk_wayland_window_set_role (GdkWindow *window, |
| 4293 |
const gchar *role) |
| 4294 |
{ |
| 4295 |
} |
| 4296 |
|
| 4297 |
static void |
| 4298 |
gdk_wayland_window_set_startup_id (GdkWindow *window, |
| 4299 |
const gchar *startup_id) |
| 4300 |
{ |
| 4301 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4302 |
GdkDisplay *display = gdk_window_get_display (window); |
| 4303 |
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display); |
| 4304 |
gchar *free_me = NULL; |
| 4305 |
|
| 4306 |
if (!startup_id) |
| 4307 |
{ |
| 4308 |
free_me = g_steal_pointer (&display_wayland->startup_notification_id); |
| 4309 |
startup_id = free_me; |
| 4310 |
} |
| 4311 |
|
| 4312 |
#ifdef HAVE_XDG_ACTIVATION |
| 4313 |
if (display_wayland->xdg_activation && startup_id) |
| 4314 |
{ |
| 4315 |
xdg_activation_v1_activate (display_wayland->xdg_activation, |
| 4316 |
startup_id, |
| 4317 |
impl->display_server.wl_surface); |
| 4318 |
} |
| 4319 |
#endif |
| 4320 |
|
| 4321 |
g_free (free_me); |
| 4322 |
} |
| 4323 |
|
| 4324 |
static gboolean |
| 4325 |
check_transient_for_loop (GdkWindow *window, |
| 4326 |
GdkWindow *parent) |
| 4327 |
{ |
| 4328 |
while (parent) |
| 4329 |
{ |
| 4330 |
GdkWindowImplWayland *impl; |
| 4331 |
|
| 4332 |
if (!GDK_IS_WINDOW_IMPL_WAYLAND(parent->impl)) |
| 4333 |
return FALSE; |
| 4334 |
|
| 4335 |
impl = GDK_WINDOW_IMPL_WAYLAND (parent->impl); |
| 4336 |
if (impl->transient_for == window) |
| 4337 |
return TRUE; |
| 4338 |
parent = impl->transient_for; |
| 4339 |
} |
| 4340 |
return FALSE; |
| 4341 |
} |
| 4342 |
|
| 4343 |
static void |
| 4344 |
gdk_wayland_window_set_transient_for (GdkWindow *window, |
| 4345 |
GdkWindow *parent) |
| 4346 |
{ |
| 4347 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4348 |
GdkWaylandDisplay *display_wayland = |
| 4349 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 4350 |
GdkWindow *previous_parent; |
| 4351 |
gboolean was_subsurface = FALSE; |
| 4352 |
|
| 4353 |
g_assert (parent == NULL || |
| 4354 |
gdk_window_get_display (window) == gdk_window_get_display (parent)); |
| 4355 |
|
| 4356 |
if (check_transient_for_loop (window, parent)) |
| 4357 |
{ |
| 4358 |
g_warning ("Setting %p transient for %p would create a loop", window, parent); |
| 4359 |
return; |
| 4360 |
} |
| 4361 |
|
| 4362 |
unset_transient_for_exported (window); |
| 4363 |
|
| 4364 |
if (impl->display_server.wl_subsurface) |
| 4365 |
{ |
| 4366 |
was_subsurface = TRUE; |
| 4367 |
unmap_subsurface (window); |
| 4368 |
} |
| 4369 |
|
| 4370 |
previous_parent = impl->transient_for; |
| 4371 |
impl->transient_for = parent; |
| 4372 |
|
| 4373 |
if (impl->hint == GDK_WINDOW_TYPE_HINT_DIALOG) |
| 4374 |
{ |
| 4375 |
if (!parent) |
| 4376 |
_gdk_wayland_screen_add_orphan_dialog (window); |
| 4377 |
else if (!previous_parent) |
| 4378 |
display_wayland->orphan_dialogs = |
| 4379 |
g_list_remove (display_wayland->orphan_dialogs, window); |
| 4380 |
} |
| 4381 |
|
| 4382 |
gdk_wayland_window_sync_parent (window, NULL); |
| 4383 |
|
| 4384 |
if (was_subsurface && parent) |
| 4385 |
gdk_wayland_window_create_subsurface (window); |
| 4386 |
} |
| 4387 |
|
| 4388 |
static void |
| 4389 |
gdk_wayland_window_get_frame_extents (GdkWindow *window, |
| 4390 |
GdkRectangle *rect) |
| 4391 |
{ |
| 4392 |
*rect = (GdkRectangle) { |
| 4393 |
.x = window->x, |
| 4394 |
.y = window->y, |
| 4395 |
.width = window->width, |
| 4396 |
.height = window->height |
| 4397 |
}; |
| 4398 |
} |
| 4399 |
|
| 4400 |
static void |
| 4401 |
gdk_wayland_window_set_override_redirect (GdkWindow *window, |
| 4402 |
gboolean override_redirect) |
| 4403 |
{ |
| 4404 |
} |
| 4405 |
|
| 4406 |
static void |
| 4407 |
gdk_wayland_window_set_accept_focus (GdkWindow *window, |
| 4408 |
gboolean accept_focus) |
| 4409 |
{ |
| 4410 |
} |
| 4411 |
|
| 4412 |
static void |
| 4413 |
gdk_wayland_window_set_focus_on_map (GdkWindow *window, |
| 4414 |
gboolean focus_on_map) |
| 4415 |
{ |
| 4416 |
} |
| 4417 |
|
| 4418 |
static void |
| 4419 |
gdk_wayland_window_set_icon_list (GdkWindow *window, |
| 4420 |
GList *pixbufs) |
| 4421 |
{ |
| 4422 |
} |
| 4423 |
|
| 4424 |
static void |
| 4425 |
gdk_wayland_window_set_icon_name (GdkWindow *window, |
| 4426 |
const gchar *name) |
| 4427 |
{ |
| 4428 |
if (GDK_WINDOW_DESTROYED (window)) |
| 4429 |
return; |
| 4430 |
} |
| 4431 |
|
| 4432 |
static void |
| 4433 |
gdk_wayland_window_iconify (GdkWindow *window) |
| 4434 |
{ |
| 4435 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4436 |
GdkWaylandDisplay *display_wayland; |
| 4437 |
|
| 4438 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4439 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4440 |
return; |
| 4441 |
|
| 4442 |
if (!is_realized_toplevel (window)) |
| 4443 |
return; |
| 4444 |
|
| 4445 |
display_wayland = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 4446 |
switch (display_wayland->shell_variant) |
| 4447 |
{ |
| 4448 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 4449 |
xdg_toplevel_set_minimized (impl->display_server.xdg_toplevel); |
| 4450 |
break; |
| 4451 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 4452 |
zxdg_toplevel_v6_set_minimized (impl->display_server.zxdg_toplevel_v6); |
| 4453 |
break; |
| 4454 |
} |
| 4455 |
} |
| 4456 |
|
| 4457 |
static void |
| 4458 |
gdk_wayland_window_deiconify (GdkWindow *window) |
| 4459 |
{ |
| 4460 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4461 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4462 |
return; |
| 4463 |
|
| 4464 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 4465 |
gdk_window_show (window); |
| 4466 |
else |
| 4467 |
/* Flip our client side flag, the real work happens on map. */ |
| 4468 |
gdk_synthesize_window_state (window, GDK_WINDOW_STATE_ICONIFIED, 0); |
| 4469 |
} |
| 4470 |
|
| 4471 |
static void |
| 4472 |
gdk_wayland_window_stick (GdkWindow *window) |
| 4473 |
{ |
| 4474 |
} |
| 4475 |
|
| 4476 |
static void |
| 4477 |
gdk_wayland_window_unstick (GdkWindow *window) |
| 4478 |
{ |
| 4479 |
} |
| 4480 |
|
| 4481 |
static void |
| 4482 |
gdk_wayland_window_maximize (GdkWindow *window) |
| 4483 |
{ |
| 4484 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4485 |
|
| 4486 |
if (GDK_WINDOW_DESTROYED (window)) |
| 4487 |
return; |
| 4488 |
|
| 4489 |
_gdk_wayland_window_save_size (window); |
| 4490 |
if (is_realized_toplevel (window)) |
| 4491 |
{ |
| 4492 |
GdkWaylandDisplay *display_wayland = |
| 4493 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 4494 |
|
| 4495 |
switch (display_wayland->shell_variant) |
| 4496 |
{ |
| 4497 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 4498 |
xdg_toplevel_set_maximized (impl->display_server.xdg_toplevel); |
| 4499 |
break; |
| 4500 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 4501 |
zxdg_toplevel_v6_set_maximized (impl->display_server.zxdg_toplevel_v6); |
| 4502 |
break; |
| 4503 |
} |
| 4504 |
} |
| 4505 |
else |
| 4506 |
{ |
| 4507 |
gdk_synthesize_window_state (window, 0, GDK_WINDOW_STATE_MAXIMIZED); |
| 4508 |
} |
| 4509 |
} |
| 4510 |
|
| 4511 |
static void |
| 4512 |
gdk_wayland_window_unmaximize (GdkWindow *window) |
| 4513 |
{ |
| 4514 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4515 |
|
| 4516 |
if (GDK_WINDOW_DESTROYED (window)) |
| 4517 |
return; |
| 4518 |
|
| 4519 |
if (is_realized_toplevel (window)) |
| 4520 |
{ |
| 4521 |
GdkWaylandDisplay *display_wayland = |
| 4522 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 4523 |
|
| 4524 |
switch (display_wayland->shell_variant) |
| 4525 |
{ |
| 4526 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 4527 |
xdg_toplevel_unset_maximized (impl->display_server.xdg_toplevel); |
| 4528 |
break; |
| 4529 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 4530 |
zxdg_toplevel_v6_unset_maximized (impl->display_server.zxdg_toplevel_v6); |
| 4531 |
break; |
| 4532 |
} |
| 4533 |
} |
| 4534 |
else |
| 4535 |
{ |
| 4536 |
gdk_synthesize_window_state (window, GDK_WINDOW_STATE_MAXIMIZED, 0); |
| 4537 |
} |
| 4538 |
} |
| 4539 |
|
| 4540 |
static void |
| 4541 |
gdk_wayland_window_fullscreen_on_monitor (GdkWindow *window, gint monitor) |
| 4542 |
{ |
| 4543 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4544 |
GdkScreen *screen = gdk_window_get_screen (window); |
| 4545 |
struct wl_output *fullscreen_output = |
| 4546 |
_gdk_wayland_screen_get_wl_output (screen, monitor); |
| 4547 |
|
| 4548 |
if (GDK_WINDOW_DESTROYED (window)) |
| 4549 |
return; |
| 4550 |
|
| 4551 |
_gdk_wayland_window_save_size (window); |
| 4552 |
if (is_realized_toplevel (window)) |
| 4553 |
{ |
| 4554 |
GdkWaylandDisplay *display_wayland = |
| 4555 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 4556 |
|
| 4557 |
switch (display_wayland->shell_variant) |
| 4558 |
{ |
| 4559 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 4560 |
xdg_toplevel_set_fullscreen (impl->display_server.xdg_toplevel, |
| 4561 |
fullscreen_output); |
| 4562 |
break; |
| 4563 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 4564 |
zxdg_toplevel_v6_set_fullscreen (impl->display_server.zxdg_toplevel_v6, |
| 4565 |
fullscreen_output); |
| 4566 |
break; |
| 4567 |
} |
| 4568 |
} |
| 4569 |
else |
| 4570 |
{ |
| 4571 |
gdk_synthesize_window_state (window, 0, GDK_WINDOW_STATE_FULLSCREEN); |
| 4572 |
impl->initial_fullscreen_monitor = monitor; |
| 4573 |
} |
| 4574 |
} |
| 4575 |
|
| 4576 |
static void |
| 4577 |
gdk_wayland_window_fullscreen (GdkWindow *window) |
| 4578 |
{ |
| 4579 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4580 |
|
| 4581 |
if (GDK_WINDOW_DESTROYED (window)) |
| 4582 |
return; |
| 4583 |
|
| 4584 |
impl->initial_fullscreen_monitor = -1; |
| 4585 |
|
| 4586 |
_gdk_wayland_window_save_size (window); |
| 4587 |
if (is_realized_toplevel (window)) |
| 4588 |
{ |
| 4589 |
GdkWaylandDisplay *display_wayland = |
| 4590 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 4591 |
|
| 4592 |
switch (display_wayland->shell_variant) |
| 4593 |
{ |
| 4594 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 4595 |
xdg_toplevel_set_fullscreen (impl->display_server.xdg_toplevel, |
| 4596 |
NULL); |
| 4597 |
break; |
| 4598 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 4599 |
zxdg_toplevel_v6_set_fullscreen (impl->display_server.zxdg_toplevel_v6, |
| 4600 |
NULL); |
| 4601 |
break; |
| 4602 |
} |
| 4603 |
} |
| 4604 |
else |
| 4605 |
{ |
| 4606 |
gdk_synthesize_window_state (window, 0, GDK_WINDOW_STATE_FULLSCREEN); |
| 4607 |
} |
| 4608 |
} |
| 4609 |
|
| 4610 |
static void |
| 4611 |
gdk_wayland_window_unfullscreen (GdkWindow *window) |
| 4612 |
{ |
| 4613 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4614 |
|
| 4615 |
if (GDK_WINDOW_DESTROYED (window)) |
| 4616 |
return; |
| 4617 |
|
| 4618 |
impl->initial_fullscreen_monitor = -1; |
| 4619 |
|
| 4620 |
if (is_realized_toplevel (window)) |
| 4621 |
{ |
| 4622 |
GdkWaylandDisplay *display_wayland = |
| 4623 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 4624 |
|
| 4625 |
switch (display_wayland->shell_variant) |
| 4626 |
{ |
| 4627 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 4628 |
xdg_toplevel_unset_fullscreen (impl->display_server.xdg_toplevel); |
| 4629 |
break; |
| 4630 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 4631 |
zxdg_toplevel_v6_unset_fullscreen (impl->display_server.zxdg_toplevel_v6); |
| 4632 |
break; |
| 4633 |
} |
| 4634 |
} |
| 4635 |
else |
| 4636 |
{ |
| 4637 |
gdk_synthesize_window_state (window, GDK_WINDOW_STATE_FULLSCREEN, 0); |
| 4638 |
} |
| 4639 |
} |
| 4640 |
|
| 4641 |
static void |
| 4642 |
gdk_wayland_window_set_keep_above (GdkWindow *window, gboolean setting) |
| 4643 |
{ |
| 4644 |
} |
| 4645 |
|
| 4646 |
static void |
| 4647 |
gdk_wayland_window_set_keep_below (GdkWindow *window, gboolean setting) |
| 4648 |
{ |
| 4649 |
} |
| 4650 |
|
| 4651 |
static GdkWindow * |
| 4652 |
gdk_wayland_window_get_group (GdkWindow *window) |
| 4653 |
{ |
| 4654 |
return NULL; |
| 4655 |
} |
| 4656 |
|
| 4657 |
static void |
| 4658 |
gdk_wayland_window_set_group (GdkWindow *window, |
| 4659 |
GdkWindow *leader) |
| 4660 |
{ |
| 4661 |
} |
| 4662 |
|
| 4663 |
static void |
| 4664 |
gdk_wayland_window_set_decorations (GdkWindow *window, |
| 4665 |
GdkWMDecoration decorations) |
| 4666 |
{ |
| 4667 |
} |
| 4668 |
|
| 4669 |
static gboolean |
| 4670 |
gdk_wayland_window_get_decorations (GdkWindow *window, |
| 4671 |
GdkWMDecoration *decorations) |
| 4672 |
{ |
| 4673 |
return FALSE; |
| 4674 |
} |
| 4675 |
|
| 4676 |
static void |
| 4677 |
gdk_wayland_window_set_functions (GdkWindow *window, |
| 4678 |
GdkWMFunction functions) |
| 4679 |
{ |
| 4680 |
} |
| 4681 |
|
| 4682 |
static void |
| 4683 |
gdk_wayland_window_begin_resize_drag (GdkWindow *window, |
| 4684 |
GdkWindowEdge edge, |
| 4685 |
GdkDevice *device, |
| 4686 |
gint button, |
| 4687 |
gint root_x, |
| 4688 |
gint root_y, |
| 4689 |
guint32 timestamp) |
| 4690 |
{ |
| 4691 |
GdkWindowImplWayland *impl; |
| 4692 |
GdkWaylandDisplay *display_wayland; |
| 4693 |
GdkEventSequence *sequence; |
| 4694 |
uint32_t resize_edges, serial; |
| 4695 |
|
| 4696 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4697 |
!WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) |
| 4698 |
return; |
| 4699 |
|
| 4700 |
switch (edge) |
| 4701 |
{ |
| 4702 |
case GDK_WINDOW_EDGE_NORTH_WEST: |
| 4703 |
resize_edges = ZXDG_TOPLEVEL_V6_RESIZE_EDGE_TOP_LEFT; |
| 4704 |
break; |
| 4705 |
|
| 4706 |
case GDK_WINDOW_EDGE_NORTH: |
| 4707 |
resize_edges = ZXDG_TOPLEVEL_V6_RESIZE_EDGE_TOP; |
| 4708 |
break; |
| 4709 |
|
| 4710 |
case GDK_WINDOW_EDGE_NORTH_EAST: |
| 4711 |
resize_edges = ZXDG_TOPLEVEL_V6_RESIZE_EDGE_TOP_RIGHT; |
| 4712 |
break; |
| 4713 |
|
| 4714 |
case GDK_WINDOW_EDGE_WEST: |
| 4715 |
resize_edges = ZXDG_TOPLEVEL_V6_RESIZE_EDGE_LEFT; |
| 4716 |
break; |
| 4717 |
|
| 4718 |
case GDK_WINDOW_EDGE_EAST: |
| 4719 |
resize_edges = ZXDG_TOPLEVEL_V6_RESIZE_EDGE_RIGHT; |
| 4720 |
break; |
| 4721 |
|
| 4722 |
case GDK_WINDOW_EDGE_SOUTH_WEST: |
| 4723 |
resize_edges = ZXDG_TOPLEVEL_V6_RESIZE_EDGE_BOTTOM_LEFT; |
| 4724 |
break; |
| 4725 |
|
| 4726 |
case GDK_WINDOW_EDGE_SOUTH: |
| 4727 |
resize_edges = ZXDG_TOPLEVEL_V6_RESIZE_EDGE_BOTTOM; |
| 4728 |
break; |
| 4729 |
|
| 4730 |
case GDK_WINDOW_EDGE_SOUTH_EAST: |
| 4731 |
resize_edges = ZXDG_TOPLEVEL_V6_RESIZE_EDGE_BOTTOM_RIGHT; |
| 4732 |
break; |
| 4733 |
|
| 4734 |
default: |
| 4735 |
g_warning ("gdk_window_begin_resize_drag: bad resize edge %d!", edge); |
| 4736 |
return; |
| 4737 |
} |
| 4738 |
|
| 4739 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4740 |
display_wayland = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 4741 |
|
| 4742 |
if (!is_realized_toplevel (window)) |
| 4743 |
return; |
| 4744 |
|
| 4745 |
serial = _gdk_wayland_seat_get_last_implicit_grab_serial (gdk_device_get_seat (device), |
| 4746 |
&sequence); |
| 4747 |
|
| 4748 |
switch (display_wayland->shell_variant) |
| 4749 |
{ |
| 4750 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 4751 |
xdg_toplevel_resize (impl->display_server.xdg_toplevel, |
| 4752 |
gdk_wayland_device_get_wl_seat (device), |
| 4753 |
serial, resize_edges); |
| 4754 |
break; |
| 4755 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 4756 |
zxdg_toplevel_v6_resize (impl->display_server.zxdg_toplevel_v6, |
| 4757 |
gdk_wayland_device_get_wl_seat (device), |
| 4758 |
serial, resize_edges); |
| 4759 |
break; |
| 4760 |
} |
| 4761 |
|
| 4762 |
if (sequence) |
| 4763 |
gdk_wayland_device_unset_touch_grab (device, sequence); |
| 4764 |
|
| 4765 |
/* This is needed since Wayland will absorb all the pointer events after the |
| 4766 |
* above function - FIXME: Is this always safe..? |
| 4767 |
*/ |
| 4768 |
gdk_seat_ungrab (gdk_device_get_seat (device)); |
| 4769 |
} |
| 4770 |
|
| 4771 |
static void |
| 4772 |
gdk_wayland_window_begin_move_drag (GdkWindow *window, |
| 4773 |
GdkDevice *device, |
| 4774 |
gint button, |
| 4775 |
gint root_x, |
| 4776 |
gint root_y, |
| 4777 |
guint32 timestamp) |
| 4778 |
{ |
| 4779 |
GdkWindowImplWayland *impl; |
| 4780 |
GdkWaylandDisplay *display_wayland; |
| 4781 |
GdkEventSequence *sequence; |
| 4782 |
uint32_t serial; |
| 4783 |
|
| 4784 |
if (GDK_WINDOW_DESTROYED (window) || |
| 4785 |
!WINDOW_IS_TOPLEVEL (window)) |
| 4786 |
return; |
| 4787 |
|
| 4788 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4789 |
display_wayland = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 4790 |
|
| 4791 |
if (!is_realized_toplevel (window)) |
| 4792 |
return; |
| 4793 |
|
| 4794 |
serial = _gdk_wayland_seat_get_last_implicit_grab_serial (gdk_device_get_seat (device), |
| 4795 |
&sequence); |
| 4796 |
switch (display_wayland->shell_variant) |
| 4797 |
{ |
| 4798 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 4799 |
xdg_toplevel_move (impl->display_server.xdg_toplevel, |
| 4800 |
gdk_wayland_device_get_wl_seat (device), |
| 4801 |
serial); |
| 4802 |
break; |
| 4803 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 4804 |
zxdg_toplevel_v6_move (impl->display_server.zxdg_toplevel_v6, |
| 4805 |
gdk_wayland_device_get_wl_seat (device), |
| 4806 |
serial); |
| 4807 |
break; |
| 4808 |
} |
| 4809 |
|
| 4810 |
if (sequence) |
| 4811 |
gdk_wayland_device_unset_touch_grab (device, sequence); |
| 4812 |
|
| 4813 |
/* This is needed since Wayland will absorb all the pointer events after the |
| 4814 |
* above function - FIXME: Is this always safe..? |
| 4815 |
*/ |
| 4816 |
gdk_seat_ungrab (gdk_device_get_seat (device)); |
| 4817 |
} |
| 4818 |
|
| 4819 |
static void |
| 4820 |
gdk_wayland_window_set_opacity (GdkWindow *window, |
| 4821 |
gdouble opacity) |
| 4822 |
{ |
| 4823 |
} |
| 4824 |
|
| 4825 |
static void |
| 4826 |
gdk_wayland_window_set_composited (GdkWindow *window, |
| 4827 |
gboolean composited) |
| 4828 |
{ |
| 4829 |
} |
| 4830 |
|
| 4831 |
static void |
| 4832 |
gdk_wayland_window_destroy_notify (GdkWindow *window) |
| 4833 |
{ |
| 4834 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 4835 |
{ |
| 4836 |
if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN) |
| 4837 |
g_warning ("GdkWindow %p unexpectedly destroyed", window); |
| 4838 |
|
| 4839 |
_gdk_window_destroy (window, TRUE); |
| 4840 |
} |
| 4841 |
|
| 4842 |
g_object_unref (window); |
| 4843 |
} |
| 4844 |
|
| 4845 |
static void |
| 4846 |
gdk_wayland_window_sync_rendering (GdkWindow *window) |
| 4847 |
{ |
| 4848 |
} |
| 4849 |
|
| 4850 |
static gboolean |
| 4851 |
gdk_wayland_window_simulate_key (GdkWindow *window, |
| 4852 |
gint x, |
| 4853 |
gint y, |
| 4854 |
guint keyval, |
| 4855 |
GdkModifierType modifiers, |
| 4856 |
GdkEventType key_pressrelease) |
| 4857 |
{ |
| 4858 |
return FALSE; |
| 4859 |
} |
| 4860 |
|
| 4861 |
static gboolean |
| 4862 |
gdk_wayland_window_simulate_button (GdkWindow *window, |
| 4863 |
gint x, |
| 4864 |
gint y, |
| 4865 |
guint button, |
| 4866 |
GdkModifierType modifiers, |
| 4867 |
GdkEventType button_pressrelease) |
| 4868 |
{ |
| 4869 |
return FALSE; |
| 4870 |
} |
| 4871 |
|
| 4872 |
static gboolean |
| 4873 |
gdk_wayland_window_get_property (GdkWindow *window, |
| 4874 |
GdkAtom property, |
| 4875 |
GdkAtom type, |
| 4876 |
gulong offset, |
| 4877 |
gulong length, |
| 4878 |
gint pdelete, |
| 4879 |
GdkAtom *actual_property_type, |
| 4880 |
gint *actual_format_type, |
| 4881 |
gint *actual_length, |
| 4882 |
guchar **data) |
| 4883 |
{ |
| 4884 |
return FALSE; |
| 4885 |
} |
| 4886 |
|
| 4887 |
static void |
| 4888 |
gdk_wayland_window_change_property (GdkWindow *window, |
| 4889 |
GdkAtom property, |
| 4890 |
GdkAtom type, |
| 4891 |
gint format, |
| 4892 |
GdkPropMode mode, |
| 4893 |
const guchar *data, |
| 4894 |
gint nelements) |
| 4895 |
{ |
| 4896 |
if (property == gdk_atom_intern_static_string ("GDK_SELECTION")) |
| 4897 |
gdk_wayland_selection_store (window, type, mode, data, nelements * (format / 8)); |
| 4898 |
} |
| 4899 |
|
| 4900 |
static void |
| 4901 |
gdk_wayland_window_delete_property (GdkWindow *window, |
| 4902 |
GdkAtom property) |
| 4903 |
{ |
| 4904 |
} |
| 4905 |
|
| 4906 |
static gint |
| 4907 |
gdk_wayland_window_get_scale_factor (GdkWindow *window) |
| 4908 |
{ |
| 4909 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4910 |
|
| 4911 |
if (GDK_WINDOW_DESTROYED (window)) |
| 4912 |
return 1; |
| 4913 |
|
| 4914 |
return impl->scale; |
| 4915 |
} |
| 4916 |
|
| 4917 |
static void |
| 4918 |
gdk_wayland_window_set_opaque_region (GdkWindow *window, |
| 4919 |
cairo_region_t *region) |
| 4920 |
{ |
| 4921 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4922 |
|
| 4923 |
if (GDK_WINDOW_DESTROYED (window)) |
| 4924 |
return; |
| 4925 |
|
| 4926 |
g_clear_pointer (&impl->opaque_region, cairo_region_destroy); |
| 4927 |
impl->opaque_region = cairo_region_reference (region); |
| 4928 |
impl->opaque_region_dirty = TRUE; |
| 4929 |
} |
| 4930 |
|
| 4931 |
static void |
| 4932 |
gdk_wayland_window_set_shadow_width (GdkWindow *window, |
| 4933 |
int left, |
| 4934 |
int right, |
| 4935 |
int top, |
| 4936 |
int bottom) |
| 4937 |
{ |
| 4938 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4939 |
gint new_width, new_height; |
| 4940 |
|
| 4941 |
if (GDK_WINDOW_DESTROYED (window)) |
| 4942 |
return; |
| 4943 |
|
| 4944 |
/* Reconfigure window to keep the same window geometry */ |
| 4945 |
new_width = (calculate_width_without_margin (window, window->width) + |
| 4946 |
(left + right)); |
| 4947 |
new_height = (calculate_height_without_margin (window, window->height) + |
| 4948 |
(top + bottom)); |
| 4949 |
gdk_wayland_window_maybe_configure (window, new_width, new_height, impl->scale); |
| 4950 |
|
| 4951 |
impl->margin_left = left; |
| 4952 |
impl->margin_right = right; |
| 4953 |
impl->margin_top = top; |
| 4954 |
impl->margin_bottom = bottom; |
| 4955 |
} |
| 4956 |
|
| 4957 |
static gboolean |
| 4958 |
gdk_wayland_window_show_window_menu (GdkWindow *window, |
| 4959 |
GdkEvent *event) |
| 4960 |
{ |
| 4961 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 4962 |
GdkWaylandDisplay *display_wayland = |
| 4963 |
GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 4964 |
struct wl_seat *seat; |
| 4965 |
GdkWaylandDevice *device; |
| 4966 |
GdkWindow *event_window; |
| 4967 |
double x, y; |
| 4968 |
uint32_t serial; |
| 4969 |
|
| 4970 |
switch (event->type) |
| 4971 |
{ |
| 4972 |
case GDK_BUTTON_PRESS: |
| 4973 |
case GDK_BUTTON_RELEASE: |
| 4974 |
case GDK_TOUCH_BEGIN: |
| 4975 |
case GDK_TOUCH_END: |
| 4976 |
break; |
| 4977 |
default: |
| 4978 |
return FALSE; |
| 4979 |
} |
| 4980 |
|
| 4981 |
if (!is_realized_toplevel (window)) |
| 4982 |
return FALSE; |
| 4983 |
|
| 4984 |
device = GDK_WAYLAND_DEVICE (gdk_event_get_device (event)); |
| 4985 |
seat = gdk_wayland_device_get_wl_seat (GDK_DEVICE (device)); |
| 4986 |
|
| 4987 |
gdk_event_get_coords (event, &x, &y); |
| 4988 |
event_window = gdk_event_get_window (event); |
| 4989 |
while (gdk_window_get_window_type (event_window) != GDK_WINDOW_TOPLEVEL) |
| 4990 |
{ |
| 4991 |
gdk_window_coords_to_parent (event_window, x, y, &x, &y); |
| 4992 |
event_window = gdk_window_get_effective_parent (event_window); |
| 4993 |
} |
| 4994 |
|
| 4995 |
serial = _gdk_wayland_device_get_implicit_grab_serial (device, event); |
| 4996 |
|
| 4997 |
switch (display_wayland->shell_variant) |
| 4998 |
{ |
| 4999 |
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL: |
| 5000 |
xdg_toplevel_show_window_menu (impl->display_server.xdg_toplevel, |
| 5001 |
seat, serial, x, y); |
| 5002 |
break; |
| 5003 |
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6: |
| 5004 |
zxdg_toplevel_v6_show_window_menu (impl->display_server.zxdg_toplevel_v6, |
| 5005 |
seat, serial, x, y); |
| 5006 |
break; |
| 5007 |
} |
| 5008 |
|
| 5009 |
return TRUE; |
| 5010 |
} |
| 5011 |
|
| 5012 |
static gboolean |
| 5013 |
translate_gesture (GdkTitlebarGesture gesture, |
| 5014 |
enum gtk_surface1_gesture *out_gesture) |
| 5015 |
{ |
| 5016 |
switch (gesture) |
| 5017 |
{ |
| 5018 |
case GDK_TITLEBAR_GESTURE_DOUBLE_CLICK: |
| 5019 |
*out_gesture = GTK_SURFACE1_GESTURE_DOUBLE_CLICK; |
| 5020 |
break; |
| 5021 |
|
| 5022 |
case GDK_TITLEBAR_GESTURE_RIGHT_CLICK: |
| 5023 |
*out_gesture = GTK_SURFACE1_GESTURE_RIGHT_CLICK; |
| 5024 |
break; |
| 5025 |
|
| 5026 |
case GDK_TITLEBAR_GESTURE_MIDDLE_CLICK: |
| 5027 |
*out_gesture = GTK_SURFACE1_GESTURE_MIDDLE_CLICK; |
| 5028 |
break; |
| 5029 |
|
| 5030 |
default: |
| 5031 |
g_warning ("Not handling unknown titlebar gesture %u", gesture); |
| 5032 |
return FALSE; |
| 5033 |
} |
| 5034 |
|
| 5035 |
return TRUE; |
| 5036 |
} |
| 5037 |
|
| 5038 |
static gboolean |
| 5039 |
gdk_wayland_window_titlebar_gesture (GdkWindow *window, |
| 5040 |
GdkTitlebarGesture gesture) |
| 5041 |
{ |
| 5042 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5043 |
struct gtk_surface1 *gtk_surface = impl->display_server.gtk_surface; |
| 5044 |
enum gtk_surface1_gesture gtk_gesture; |
| 5045 |
GdkSeat *seat; |
| 5046 |
struct wl_seat *wl_seat; |
| 5047 |
uint32_t serial; |
| 5048 |
|
| 5049 |
if (!gtk_surface) |
| 5050 |
return FALSE; |
| 5051 |
|
| 5052 |
if (gtk_surface1_get_version (gtk_surface) < GTK_SURFACE1_TITLEBAR_GESTURE_SINCE_VERSION) |
| 5053 |
return FALSE; |
| 5054 |
|
| 5055 |
if (!translate_gesture (gesture, >k_gesture)) |
| 5056 |
return FALSE; |
| 5057 |
|
| 5058 |
seat = gdk_display_get_default_seat (gdk_window_get_display (window)); |
| 5059 |
wl_seat = gdk_wayland_seat_get_wl_seat (seat); |
| 5060 |
|
| 5061 |
serial = _gdk_wayland_seat_get_last_implicit_grab_serial (seat, NULL); |
| 5062 |
|
| 5063 |
gtk_surface1_titlebar_gesture (impl->display_server.gtk_surface, |
| 5064 |
serial, |
| 5065 |
wl_seat, |
| 5066 |
gtk_gesture); |
| 5067 |
|
| 5068 |
return TRUE; |
| 5069 |
} |
| 5070 |
|
| 5071 |
static void |
| 5072 |
_gdk_window_impl_wayland_class_init (GdkWindowImplWaylandClass *klass) |
| 5073 |
{ |
| 5074 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 5075 |
GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_CLASS (klass); |
| 5076 |
|
| 5077 |
object_class->finalize = gdk_window_impl_wayland_finalize; |
| 5078 |
|
| 5079 |
impl_class->ref_cairo_surface = gdk_wayland_window_ref_cairo_surface; |
| 5080 |
impl_class->create_similar_image_surface = gdk_wayland_window_create_similar_image_surface; |
| 5081 |
impl_class->show = gdk_wayland_window_show; |
| 5082 |
impl_class->hide = gdk_wayland_window_hide; |
| 5083 |
impl_class->withdraw = gdk_window_wayland_withdraw; |
| 5084 |
impl_class->set_events = gdk_window_wayland_set_events; |
| 5085 |
impl_class->get_events = gdk_window_wayland_get_events; |
| 5086 |
impl_class->raise = gdk_window_wayland_raise; |
| 5087 |
impl_class->lower = gdk_window_wayland_lower; |
| 5088 |
impl_class->restack_under = gdk_window_wayland_restack_under; |
| 5089 |
impl_class->restack_toplevel = gdk_window_wayland_restack_toplevel; |
| 5090 |
impl_class->move_resize = gdk_window_wayland_move_resize; |
| 5091 |
impl_class->move_to_rect = gdk_window_wayland_move_to_rect; |
| 5092 |
impl_class->set_background = gdk_window_wayland_set_background; |
| 5093 |
impl_class->reparent = gdk_window_wayland_reparent; |
| 5094 |
impl_class->set_device_cursor = gdk_window_wayland_set_device_cursor; |
| 5095 |
impl_class->get_geometry = gdk_window_wayland_get_geometry; |
| 5096 |
impl_class->get_root_coords = gdk_window_wayland_get_root_coords; |
| 5097 |
impl_class->get_device_state = gdk_window_wayland_get_device_state; |
| 5098 |
impl_class->shape_combine_region = gdk_window_wayland_shape_combine_region; |
| 5099 |
impl_class->input_shape_combine_region = gdk_window_wayland_input_shape_combine_region; |
| 5100 |
impl_class->destroy = gdk_wayland_window_destroy; |
| 5101 |
impl_class->destroy_foreign = gdk_window_wayland_destroy_foreign; |
| 5102 |
impl_class->get_shape = gdk_wayland_window_get_shape; |
| 5103 |
impl_class->get_input_shape = gdk_wayland_window_get_input_shape; |
| 5104 |
impl_class->begin_paint = gdk_window_impl_wayland_begin_paint; |
| 5105 |
impl_class->end_paint = gdk_window_impl_wayland_end_paint; |
| 5106 |
impl_class->beep = gdk_window_impl_wayland_beep; |
| 5107 |
|
| 5108 |
impl_class->focus = gdk_wayland_window_focus; |
| 5109 |
impl_class->set_type_hint = gdk_wayland_window_set_type_hint; |
| 5110 |
impl_class->get_type_hint = gdk_wayland_window_get_type_hint; |
| 5111 |
impl_class->set_modal_hint = gdk_wayland_window_set_modal_hint; |
| 5112 |
impl_class->set_skip_taskbar_hint = gdk_wayland_window_set_skip_taskbar_hint; |
| 5113 |
impl_class->set_skip_pager_hint = gdk_wayland_window_set_skip_pager_hint; |
| 5114 |
impl_class->set_urgency_hint = gdk_wayland_window_set_urgency_hint; |
| 5115 |
impl_class->set_geometry_hints = gdk_wayland_window_set_geometry_hints; |
| 5116 |
impl_class->set_title = gdk_wayland_window_set_title; |
| 5117 |
impl_class->set_role = gdk_wayland_window_set_role; |
| 5118 |
impl_class->set_startup_id = gdk_wayland_window_set_startup_id; |
| 5119 |
impl_class->set_transient_for = gdk_wayland_window_set_transient_for; |
| 5120 |
impl_class->get_frame_extents = gdk_wayland_window_get_frame_extents; |
| 5121 |
impl_class->set_override_redirect = gdk_wayland_window_set_override_redirect; |
| 5122 |
impl_class->set_accept_focus = gdk_wayland_window_set_accept_focus; |
| 5123 |
impl_class->set_focus_on_map = gdk_wayland_window_set_focus_on_map; |
| 5124 |
impl_class->set_icon_list = gdk_wayland_window_set_icon_list; |
| 5125 |
impl_class->set_icon_name = gdk_wayland_window_set_icon_name; |
| 5126 |
impl_class->iconify = gdk_wayland_window_iconify; |
| 5127 |
impl_class->deiconify = gdk_wayland_window_deiconify; |
| 5128 |
impl_class->stick = gdk_wayland_window_stick; |
| 5129 |
impl_class->unstick = gdk_wayland_window_unstick; |
| 5130 |
impl_class->maximize = gdk_wayland_window_maximize; |
| 5131 |
impl_class->unmaximize = gdk_wayland_window_unmaximize; |
| 5132 |
impl_class->fullscreen = gdk_wayland_window_fullscreen; |
| 5133 |
impl_class->fullscreen_on_monitor = gdk_wayland_window_fullscreen_on_monitor; |
| 5134 |
impl_class->unfullscreen = gdk_wayland_window_unfullscreen; |
| 5135 |
impl_class->set_keep_above = gdk_wayland_window_set_keep_above; |
| 5136 |
impl_class->set_keep_below = gdk_wayland_window_set_keep_below; |
| 5137 |
impl_class->get_group = gdk_wayland_window_get_group; |
| 5138 |
impl_class->set_group = gdk_wayland_window_set_group; |
| 5139 |
impl_class->set_decorations = gdk_wayland_window_set_decorations; |
| 5140 |
impl_class->get_decorations = gdk_wayland_window_get_decorations; |
| 5141 |
impl_class->set_functions = gdk_wayland_window_set_functions; |
| 5142 |
impl_class->begin_resize_drag = gdk_wayland_window_begin_resize_drag; |
| 5143 |
impl_class->begin_move_drag = gdk_wayland_window_begin_move_drag; |
| 5144 |
impl_class->set_opacity = gdk_wayland_window_set_opacity; |
| 5145 |
impl_class->set_composited = gdk_wayland_window_set_composited; |
| 5146 |
impl_class->destroy_notify = gdk_wayland_window_destroy_notify; |
| 5147 |
impl_class->get_drag_protocol = _gdk_wayland_window_get_drag_protocol; |
| 5148 |
impl_class->register_dnd = _gdk_wayland_window_register_dnd; |
| 5149 |
impl_class->drag_begin = _gdk_wayland_window_drag_begin; |
| 5150 |
impl_class->sync_rendering = gdk_wayland_window_sync_rendering; |
| 5151 |
impl_class->simulate_key = gdk_wayland_window_simulate_key; |
| 5152 |
impl_class->simulate_button = gdk_wayland_window_simulate_button; |
| 5153 |
impl_class->get_property = gdk_wayland_window_get_property; |
| 5154 |
impl_class->change_property = gdk_wayland_window_change_property; |
| 5155 |
impl_class->delete_property = gdk_wayland_window_delete_property; |
| 5156 |
impl_class->get_scale_factor = gdk_wayland_window_get_scale_factor; |
| 5157 |
impl_class->set_opaque_region = gdk_wayland_window_set_opaque_region; |
| 5158 |
impl_class->set_shadow_width = gdk_wayland_window_set_shadow_width; |
| 5159 |
impl_class->show_window_menu = gdk_wayland_window_show_window_menu; |
| 5160 |
impl_class->create_gl_context = gdk_wayland_window_create_gl_context; |
| 5161 |
impl_class->invalidate_for_new_frame = gdk_wayland_window_invalidate_for_new_frame; |
| 5162 |
impl_class->titlebar_gesture = gdk_wayland_window_titlebar_gesture; |
| 5163 |
|
| 5164 |
signals[COMMITTED] = g_signal_new ("committed", |
| 5165 |
G_TYPE_FROM_CLASS (object_class), |
| 5166 |
G_SIGNAL_RUN_LAST, |
| 5167 |
0, |
| 5168 |
NULL, NULL, NULL, |
| 5169 |
G_TYPE_NONE, 0); |
| 5170 |
} |
| 5171 |
|
| 5172 |
void |
| 5173 |
_gdk_wayland_window_set_grab_seat (GdkWindow *window, |
| 5174 |
GdkSeat *seat) |
| 5175 |
{ |
| 5176 |
GdkWindowImplWayland *impl; |
| 5177 |
|
| 5178 |
g_return_if_fail (window != NULL); |
| 5179 |
|
| 5180 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5181 |
impl->grab_input_seat = seat; |
| 5182 |
} |
| 5183 |
|
| 5184 |
/** |
| 5185 |
* gdk_wayland_window_get_wl_surface: |
| 5186 |
* @window: (type GdkWaylandWindow): a #GdkWindow |
| 5187 |
* |
| 5188 |
* Returns the Wayland surface of a #GdkWindow. |
| 5189 |
* |
| 5190 |
* Returns: (transfer none): a Wayland wl_surface |
| 5191 |
* |
| 5192 |
* Since: 3.8 |
| 5193 |
*/ |
| 5194 |
struct wl_surface * |
| 5195 |
gdk_wayland_window_get_wl_surface (GdkWindow *window) |
| 5196 |
{ |
| 5197 |
g_return_val_if_fail (GDK_IS_WAYLAND_WINDOW (window), NULL); |
| 5198 |
|
| 5199 |
return GDK_WINDOW_IMPL_WAYLAND (window->impl)->display_server.wl_surface; |
| 5200 |
} |
| 5201 |
|
| 5202 |
struct wl_output * |
| 5203 |
gdk_wayland_window_get_wl_output (GdkWindow *window) |
| 5204 |
{ |
| 5205 |
GdkWindowImplWayland *impl; |
| 5206 |
|
| 5207 |
g_return_val_if_fail (GDK_IS_WAYLAND_WINDOW (window), NULL); |
| 5208 |
|
| 5209 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5210 |
/* We pick the head of the list as this is the last entered output */ |
| 5211 |
if (impl->display_server.outputs) |
| 5212 |
return (struct wl_output *) impl->display_server.outputs->data; |
| 5213 |
|
| 5214 |
return NULL; |
| 5215 |
} |
| 5216 |
|
| 5217 |
static struct wl_egl_window * |
| 5218 |
gdk_wayland_window_get_wl_egl_window (GdkWindow *window) |
| 5219 |
{ |
| 5220 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5221 |
|
| 5222 |
if (impl->display_server.egl_window == NULL) |
| 5223 |
{ |
| 5224 |
impl->display_server.egl_window = |
| 5225 |
wl_egl_window_create (impl->display_server.wl_surface, |
| 5226 |
impl->wrapper->width * impl->scale, |
| 5227 |
impl->wrapper->height * impl->scale); |
| 5228 |
wl_surface_set_buffer_scale (impl->display_server.wl_surface, impl->scale); |
| 5229 |
} |
| 5230 |
|
| 5231 |
return impl->display_server.egl_window; |
| 5232 |
} |
| 5233 |
|
| 5234 |
EGLSurface |
| 5235 |
gdk_wayland_window_get_egl_surface (GdkWindow *window, |
| 5236 |
EGLConfig config) |
| 5237 |
{ |
| 5238 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 5239 |
GdkWindowImplWayland *impl; |
| 5240 |
struct wl_egl_window *egl_window; |
| 5241 |
|
| 5242 |
g_return_val_if_fail (GDK_IS_WAYLAND_WINDOW (window), NULL); |
| 5243 |
|
| 5244 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5245 |
|
| 5246 |
if (impl->egl_surface == NULL) |
| 5247 |
{ |
| 5248 |
egl_window = gdk_wayland_window_get_wl_egl_window (window); |
| 5249 |
|
| 5250 |
impl->egl_surface = |
| 5251 |
eglCreateWindowSurface (display->egl_display, config, egl_window, NULL); |
| 5252 |
} |
| 5253 |
|
| 5254 |
return impl->egl_surface; |
| 5255 |
} |
| 5256 |
|
| 5257 |
EGLSurface |
| 5258 |
gdk_wayland_window_get_dummy_egl_surface (GdkWindow *window, |
| 5259 |
EGLConfig config) |
| 5260 |
{ |
| 5261 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 5262 |
GdkWindowImplWayland *impl; |
| 5263 |
|
| 5264 |
g_return_val_if_fail (GDK_IS_WAYLAND_WINDOW (window), NULL); |
| 5265 |
|
| 5266 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5267 |
|
| 5268 |
if (impl->dummy_egl_surface == NULL) |
| 5269 |
{ |
| 5270 |
impl->display_server.dummy_egl_window = |
| 5271 |
wl_egl_window_create (impl->display_server.wl_surface, 1, 1); |
| 5272 |
|
| 5273 |
impl->dummy_egl_surface = |
| 5274 |
eglCreateWindowSurface (display->egl_display, config, impl->display_server.dummy_egl_window, NULL); |
| 5275 |
} |
| 5276 |
|
| 5277 |
return impl->dummy_egl_surface; |
| 5278 |
} |
| 5279 |
|
| 5280 |
struct gtk_surface1 * |
| 5281 |
gdk_wayland_window_get_gtk_surface (GdkWindow *window) |
| 5282 |
{ |
| 5283 |
g_return_val_if_fail (GDK_IS_WAYLAND_WINDOW (window), NULL); |
| 5284 |
|
| 5285 |
return GDK_WINDOW_IMPL_WAYLAND (window->impl)->display_server.gtk_surface; |
| 5286 |
} |
| 5287 |
|
| 5288 |
/** |
| 5289 |
* gdk_wayland_window_set_use_custom_surface: |
| 5290 |
* @window: (type GdkWaylandWindow): a #GdkWindow |
| 5291 |
* |
| 5292 |
* Marks a #GdkWindow as a custom Wayland surface. The application is |
| 5293 |
* expected to register the surface as some type of surface using |
| 5294 |
* some Wayland interface. |
| 5295 |
* |
| 5296 |
* A good example would be writing a panel or on-screen-keyboard as an |
| 5297 |
* out-of-process helper - as opposed to having those in the compositor |
| 5298 |
* process. In this case the underlying surface isn’t an xdg_shell |
| 5299 |
* surface and the panel or OSK client need to identify the wl_surface |
| 5300 |
* as a panel or OSK to the compositor. The assumption is that the |
| 5301 |
* compositor will expose a private interface to the special client |
| 5302 |
* that lets the client identify the wl_surface as a panel or such. |
| 5303 |
* |
| 5304 |
* This function should be called before a #GdkWindow is shown. This is |
| 5305 |
* best done by connecting to the #GtkWidget::realize signal: |
| 5306 |
* |
| 5307 |
* |[<!-- language="C" --> |
| 5308 |
* static void |
| 5309 |
* widget_realize_cb (GtkWidget *widget) |
| 5310 |
* { |
| 5311 |
* GdkWindow *window; |
| 5312 |
* struct wl_surface *surface; |
| 5313 |
* struct input_panel_surface *ip_surface; |
| 5314 |
* |
| 5315 |
* window = gtk_widget_get_window (widget); |
| 5316 |
* gdk_wayland_window_set_custom_surface (window); |
| 5317 |
* |
| 5318 |
* surface = gdk_wayland_window_get_wl_surface (window); |
| 5319 |
* ip_surface = input_panel_get_input_panel_surface (input_panel, surface); |
| 5320 |
* input_panel_surface_set_panel (ip_surface); |
| 5321 |
* } |
| 5322 |
* |
| 5323 |
* static void |
| 5324 |
* setup_window (GtkWindow *window) |
| 5325 |
* { |
| 5326 |
* g_signal_connect (window, "realize", G_CALLBACK (widget_realize_cb), NULL); |
| 5327 |
* } |
| 5328 |
* ]| |
| 5329 |
* |
| 5330 |
* Since: 3.10 |
| 5331 |
*/ |
| 5332 |
void |
| 5333 |
gdk_wayland_window_set_use_custom_surface (GdkWindow *window) |
| 5334 |
{ |
| 5335 |
GdkWindowImplWayland *impl; |
| 5336 |
|
| 5337 |
g_return_if_fail (GDK_IS_WAYLAND_WINDOW (window)); |
| 5338 |
|
| 5339 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5340 |
|
| 5341 |
if (!impl->display_server.wl_surface) |
| 5342 |
gdk_wayland_window_create_surface (window); |
| 5343 |
|
| 5344 |
impl->use_custom_surface = TRUE; |
| 5345 |
} |
| 5346 |
|
| 5347 |
static void |
| 5348 |
maybe_set_gtk_surface_dbus_properties (GdkWindow *window) |
| 5349 |
{ |
| 5350 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5351 |
|
| 5352 |
if (impl->application.was_set) |
| 5353 |
return; |
| 5354 |
|
| 5355 |
if (impl->application.application_id == NULL && |
| 5356 |
impl->application.app_menu_path == NULL && |
| 5357 |
impl->application.menubar_path == NULL && |
| 5358 |
impl->application.window_object_path == NULL && |
| 5359 |
impl->application.application_object_path == NULL && |
| 5360 |
impl->application.unique_bus_name == NULL) |
| 5361 |
return; |
| 5362 |
|
| 5363 |
gdk_wayland_window_init_gtk_surface (window); |
| 5364 |
if (impl->display_server.gtk_surface == NULL) |
| 5365 |
return; |
| 5366 |
|
| 5367 |
gtk_surface1_set_dbus_properties (impl->display_server.gtk_surface, |
| 5368 |
impl->application.application_id, |
| 5369 |
impl->application.app_menu_path, |
| 5370 |
impl->application.menubar_path, |
| 5371 |
impl->application.window_object_path, |
| 5372 |
impl->application.application_object_path, |
| 5373 |
impl->application.unique_bus_name); |
| 5374 |
impl->application.was_set = TRUE; |
| 5375 |
} |
| 5376 |
|
| 5377 |
void |
| 5378 |
gdk_wayland_window_set_dbus_properties_libgtk_only (GdkWindow *window, |
| 5379 |
const char *application_id, |
| 5380 |
const char *app_menu_path, |
| 5381 |
const char *menubar_path, |
| 5382 |
const char *window_object_path, |
| 5383 |
const char *application_object_path, |
| 5384 |
const char *unique_bus_name) |
| 5385 |
{ |
| 5386 |
GdkWindowImplWayland *impl; |
| 5387 |
|
| 5388 |
g_return_if_fail (GDK_IS_WAYLAND_WINDOW (window)); |
| 5389 |
|
| 5390 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5391 |
|
| 5392 |
impl->application.application_id = g_strdup (application_id); |
| 5393 |
impl->application.app_menu_path = g_strdup (app_menu_path); |
| 5394 |
impl->application.menubar_path = g_strdup (menubar_path); |
| 5395 |
impl->application.window_object_path = g_strdup (window_object_path); |
| 5396 |
impl->application.application_object_path = |
| 5397 |
g_strdup (application_object_path); |
| 5398 |
impl->application.unique_bus_name = g_strdup (unique_bus_name); |
| 5399 |
|
| 5400 |
maybe_set_gtk_surface_dbus_properties (window); |
| 5401 |
} |
| 5402 |
|
| 5403 |
void |
| 5404 |
_gdk_wayland_window_offset_next_wl_buffer (GdkWindow *window, |
| 5405 |
int x, |
| 5406 |
int y) |
| 5407 |
{ |
| 5408 |
GdkWindowImplWayland *impl; |
| 5409 |
|
| 5410 |
g_return_if_fail (GDK_IS_WAYLAND_WINDOW (window)); |
| 5411 |
|
| 5412 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5413 |
|
| 5414 |
impl->pending_buffer_offset_x = x; |
| 5415 |
impl->pending_buffer_offset_y = y; |
| 5416 |
} |
| 5417 |
|
| 5418 |
static void |
| 5419 |
invoke_exported_closures (GdkWindow *window) |
| 5420 |
{ |
| 5421 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5422 |
GList *l; |
| 5423 |
|
| 5424 |
if (gdk_window_is_destroyed (window)) |
| 5425 |
g_warning ("gdk_wayland_window_export_handle() callback called on destroyed window. " |
| 5426 |
"Make sure you called gdk_wayland_window_unexport_handle()."); |
| 5427 |
|
| 5428 |
for (l = impl->exported.closures; l; l = l->next) |
| 5429 |
{ |
| 5430 |
ExportedClosure *closure = l->data; |
| 5431 |
|
| 5432 |
if (! gdk_window_is_destroyed (window)) |
| 5433 |
closure->callback (window, impl->exported.handle, closure->user_data); |
| 5434 |
|
| 5435 |
if (closure->destroy_func) |
| 5436 |
closure->destroy_func (closure->user_data); |
| 5437 |
} |
| 5438 |
|
| 5439 |
g_list_free_full (impl->exported.closures, g_free); |
| 5440 |
impl->exported.closures = NULL; |
| 5441 |
} |
| 5442 |
|
| 5443 |
static void |
| 5444 |
xdg_exported_v1_handle (void *data, |
| 5445 |
struct zxdg_exported_v1 *zxdg_exported_v1, |
| 5446 |
const char *handle) |
| 5447 |
{ |
| 5448 |
GdkWindow *window = data; |
| 5449 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5450 |
|
| 5451 |
impl->exported.handle = g_strdup (handle); |
| 5452 |
|
| 5453 |
invoke_exported_closures (window); |
| 5454 |
} |
| 5455 |
|
| 5456 |
static const struct zxdg_exported_v1_listener xdg_exported_v1_listener = { |
| 5457 |
xdg_exported_v1_handle |
| 5458 |
}; |
| 5459 |
|
| 5460 |
static void |
| 5461 |
xdg_exported_v2_handle (void *data, |
| 5462 |
struct zxdg_exported_v2 *zxdg_exported_v2, |
| 5463 |
const char *handle) |
| 5464 |
{ |
| 5465 |
xdg_exported_v1_handle(data, NULL, handle); |
| 5466 |
} |
| 5467 |
|
| 5468 |
static const struct zxdg_exported_v2_listener xdg_exported_v2_listener = { |
| 5469 |
xdg_exported_v2_handle |
| 5470 |
}; |
| 5471 |
|
| 5472 |
/** |
| 5473 |
* GdkWaylandWindowExported: |
| 5474 |
* @window: the #GdkWindow that is exported |
| 5475 |
* @handle: the handle |
| 5476 |
* @user_data: user data that was passed to gdk_wayland_window_export_handle() |
| 5477 |
* |
| 5478 |
* Callback that gets called when the handle for a window has been |
| 5479 |
* obtained from the Wayland compositor. The handle can be passed |
| 5480 |
* to other processes, for the purpose of marking windows as transient |
| 5481 |
* for out-of-process surfaces. |
| 5482 |
* |
| 5483 |
* Since: 3.22 |
| 5484 |
*/ |
| 5485 |
|
| 5486 |
static gboolean |
| 5487 |
gdk_wayland_window_is_exported (GdkWindow *window) |
| 5488 |
{ |
| 5489 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5490 |
|
| 5491 |
return impl->display_server.xdg_exported_v2 || impl->display_server.xdg_exported_v1; |
| 5492 |
} |
| 5493 |
|
| 5494 |
static gboolean |
| 5495 |
exported_idle (gpointer user_data) |
| 5496 |
{ |
| 5497 |
GdkWindow *window = user_data; |
| 5498 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5499 |
|
| 5500 |
invoke_exported_closures (window); |
| 5501 |
|
| 5502 |
impl->exported.idle_source_id = 0; |
| 5503 |
|
| 5504 |
return G_SOURCE_REMOVE; |
| 5505 |
} |
| 5506 |
|
| 5507 |
/** |
| 5508 |
* gdk_wayland_window_export_handle: |
| 5509 |
* @window: the #GdkWindow to obtain a handle for |
| 5510 |
* @callback: callback to call with the handle |
| 5511 |
* @user_data: user data for @callback |
| 5512 |
* @destroy_func: destroy notify for @user_data |
| 5513 |
* |
| 5514 |
* Asynchronously obtains a handle for a surface that can be passed |
| 5515 |
* to other processes. When the handle has been obtained, @callback |
| 5516 |
* will be called. |
| 5517 |
* |
| 5518 |
* Up until 3.22.15 it was an error to call this function on a window that is |
| 5519 |
* already exported. When the handle is no longer needed, |
| 5520 |
* gdk_wayland_window_unexport_handle() should be called to clean up resources. |
| 5521 |
* |
| 5522 |
* Starting with 3.22.16, calling this function on an already exported window |
| 5523 |
* will cause the callback to be invoked with the same handle as was already |
| 5524 |
* invoked, from an idle callback. To unexport the window, |
| 5525 |
* gdk_wayland_window_unexport_handle() must be called the same number of times |
| 5526 |
* as gdk_wayland_window_export_handle() was called. Any 'exported' callback |
| 5527 |
* may still be invoked until the window is unexported or destroyed. |
| 5528 |
* |
| 5529 |
* The main purpose for obtaining a handle is to mark a surface |
| 5530 |
* from another window as transient for this one, see |
| 5531 |
* gdk_wayland_window_set_transient_for_exported(). |
| 5532 |
* |
| 5533 |
* Note that this API depends on an unstable Wayland protocol, |
| 5534 |
* and thus may require changes in the future. |
| 5535 |
* |
| 5536 |
* Return value: %TRUE if the handle has been requested, %FALSE if |
| 5537 |
* an error occurred. |
| 5538 |
* |
| 5539 |
* Since: 3.22 |
| 5540 |
*/ |
| 5541 |
gboolean |
| 5542 |
gdk_wayland_window_export_handle (GdkWindow *window, |
| 5543 |
GdkWaylandWindowExported callback, |
| 5544 |
gpointer user_data, |
| 5545 |
GDestroyNotify destroy_func) |
| 5546 |
{ |
| 5547 |
GdkWindowImplWayland *impl; |
| 5548 |
GdkWaylandDisplay *display_wayland; |
| 5549 |
GdkDisplay *display = gdk_window_get_display (window); |
| 5550 |
ExportedClosure *closure; |
| 5551 |
|
| 5552 |
g_return_val_if_fail (GDK_IS_WAYLAND_WINDOW (window), FALSE); |
| 5553 |
g_return_val_if_fail (GDK_IS_WAYLAND_DISPLAY (display), FALSE); |
| 5554 |
|
| 5555 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5556 |
display_wayland = GDK_WAYLAND_DISPLAY (display); |
| 5557 |
|
| 5558 |
if (display_wayland->xdg_exporter_v2) |
| 5559 |
{ |
| 5560 |
if (!impl->display_server.xdg_exported_v2) |
| 5561 |
{ |
| 5562 |
struct zxdg_exported_v2 *xdg_exported_v2; |
| 5563 |
|
| 5564 |
xdg_exported_v2 = |
| 5565 |
zxdg_exporter_v2_export_toplevel (display_wayland->xdg_exporter_v2, |
| 5566 |
impl->display_server.wl_surface); |
| 5567 |
zxdg_exported_v2_add_listener (xdg_exported_v2, |
| 5568 |
&xdg_exported_v2_listener, |
| 5569 |
window); |
| 5570 |
|
| 5571 |
impl->display_server.xdg_exported_v2 = xdg_exported_v2; |
| 5572 |
} |
| 5573 |
} |
| 5574 |
else if (display_wayland->xdg_exporter_v1) |
| 5575 |
{ |
| 5576 |
if (!impl->display_server.xdg_exported_v1) |
| 5577 |
{ |
| 5578 |
struct zxdg_exported_v1 *xdg_exported_v1; |
| 5579 |
|
| 5580 |
xdg_exported_v1 = |
| 5581 |
zxdg_exporter_v1_export (display_wayland->xdg_exporter_v1, |
| 5582 |
impl->display_server.wl_surface); |
| 5583 |
zxdg_exported_v1_add_listener (xdg_exported_v1, |
| 5584 |
&xdg_exported_v1_listener, |
| 5585 |
window); |
| 5586 |
|
| 5587 |
impl->display_server.xdg_exported_v1 = xdg_exported_v1; |
| 5588 |
} |
| 5589 |
} |
| 5590 |
else |
| 5591 |
{ |
| 5592 |
g_warning ("Server is missing xdg_foreign support"); |
| 5593 |
return FALSE; |
| 5594 |
} |
| 5595 |
|
| 5596 |
|
| 5597 |
closure = g_new0 (ExportedClosure, 1); |
| 5598 |
closure->callback = callback; |
| 5599 |
closure->user_data = user_data; |
| 5600 |
closure->destroy_func = destroy_func; |
| 5601 |
|
| 5602 |
impl->exported.closures = g_list_append (impl->exported.closures, closure); |
| 5603 |
impl->exported.export_count++; |
| 5604 |
|
| 5605 |
if (impl->exported.handle && !impl->exported.idle_source_id) |
| 5606 |
impl->exported.idle_source_id = g_idle_add (exported_idle, window); |
| 5607 |
|
| 5608 |
return TRUE; |
| 5609 |
} |
| 5610 |
|
| 5611 |
static void |
| 5612 |
gdk_wayland_window_unexport (GdkWindow *window) |
| 5613 |
{ |
| 5614 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5615 |
GList *l; |
| 5616 |
|
| 5617 |
if (impl->display_server.xdg_exported_v2) |
| 5618 |
{ |
| 5619 |
g_clear_pointer (&impl->display_server.xdg_exported_v2, |
| 5620 |
zxdg_exported_v2_destroy); |
| 5621 |
} |
| 5622 |
else if (impl->display_server.xdg_exported_v1) |
| 5623 |
{ |
| 5624 |
g_clear_pointer (&impl->display_server.xdg_exported_v1, |
| 5625 |
zxdg_exported_v1_destroy); |
| 5626 |
} |
| 5627 |
|
| 5628 |
for (l = impl->exported.closures; l; l = l->next) |
| 5629 |
{ |
| 5630 |
ExportedClosure *closure = l->data; |
| 5631 |
|
| 5632 |
if (closure->destroy_func) |
| 5633 |
closure->destroy_func (closure->user_data); |
| 5634 |
} |
| 5635 |
|
| 5636 |
g_list_free_full (impl->exported.closures, g_free); |
| 5637 |
impl->exported.closures = NULL; |
| 5638 |
g_clear_pointer (&impl->exported.handle, g_free); |
| 5639 |
|
| 5640 |
if (impl->exported.idle_source_id) |
| 5641 |
{ |
| 5642 |
g_source_remove (impl->exported.idle_source_id); |
| 5643 |
impl->exported.idle_source_id = 0; |
| 5644 |
} |
| 5645 |
} |
| 5646 |
|
| 5647 |
/** |
| 5648 |
* gdk_wayland_window_unexport_handle: |
| 5649 |
* @window: the #GdkWindow to unexport |
| 5650 |
* |
| 5651 |
* Destroys the handle that was obtained with |
| 5652 |
* gdk_wayland_window_export_handle(). |
| 5653 |
* |
| 5654 |
* It is an error to call this function on a window that |
| 5655 |
* does not have a handle. |
| 5656 |
* |
| 5657 |
* Note that this API depends on an unstable Wayland protocol, |
| 5658 |
* and thus may require changes in the future. |
| 5659 |
* |
| 5660 |
* Since: 3.22 |
| 5661 |
*/ |
| 5662 |
void |
| 5663 |
gdk_wayland_window_unexport_handle (GdkWindow *window) |
| 5664 |
{ |
| 5665 |
GdkWindowImplWayland *impl; |
| 5666 |
|
| 5667 |
g_return_if_fail (GDK_IS_WAYLAND_WINDOW (window)); |
| 5668 |
|
| 5669 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5670 |
|
| 5671 |
g_return_if_fail (impl->display_server.xdg_exported_v2 || |
| 5672 |
impl->display_server.xdg_exported_v1); |
| 5673 |
|
| 5674 |
impl->exported.export_count--; |
| 5675 |
if (impl->exported.export_count == 0) |
| 5676 |
gdk_wayland_window_unexport (window); |
| 5677 |
} |
| 5678 |
|
| 5679 |
static void |
| 5680 |
unset_transient_for_exported (GdkWindow *window) |
| 5681 |
{ |
| 5682 |
GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5683 |
|
| 5684 |
if (impl->imported_v2_transient_for) |
| 5685 |
{ |
| 5686 |
g_clear_pointer (&impl->imported_v2_transient_for, |
| 5687 |
zxdg_imported_v2_destroy); |
| 5688 |
} |
| 5689 |
else if (impl->imported_v1_transient_for) |
| 5690 |
{ |
| 5691 |
g_clear_pointer (&impl->imported_v1_transient_for, |
| 5692 |
zxdg_imported_v1_destroy); |
| 5693 |
} |
| 5694 |
} |
| 5695 |
|
| 5696 |
static void |
| 5697 |
xdg_imported_v1_destroyed (void *data, |
| 5698 |
struct zxdg_imported_v1 *zxdg_imported_v1) |
| 5699 |
{ |
| 5700 |
GdkWindow *window = data; |
| 5701 |
|
| 5702 |
unset_transient_for_exported (window); |
| 5703 |
} |
| 5704 |
|
| 5705 |
static const struct zxdg_imported_v1_listener xdg_imported_v1_listener = { |
| 5706 |
xdg_imported_v1_destroyed, |
| 5707 |
}; |
| 5708 |
|
| 5709 |
static void |
| 5710 |
xdg_imported_v2_destroyed (void *data, |
| 5711 |
struct zxdg_imported_v2 *zxdg_imported_v2) |
| 5712 |
{ |
| 5713 |
xdg_imported_v1_destroyed (data, NULL); |
| 5714 |
} |
| 5715 |
|
| 5716 |
static const struct zxdg_imported_v2_listener xdg_imported_v2_listener = { |
| 5717 |
xdg_imported_v2_destroyed, |
| 5718 |
}; |
| 5719 |
|
| 5720 |
/** |
| 5721 |
* gdk_wayland_window_set_transient_for_exported: |
| 5722 |
* @window: the #GdkWindow to make as transient |
| 5723 |
* @parent_handle_str: an exported handle for a surface |
| 5724 |
* |
| 5725 |
* Marks @window as transient for the surface to which the given |
| 5726 |
* @parent_handle_str refers. Typically, the handle will originate |
| 5727 |
* from a gdk_wayland_window_export_handle() call in another process. |
| 5728 |
* |
| 5729 |
* Note that this API depends on an unstable Wayland protocol, |
| 5730 |
* and thus may require changes in the future. |
| 5731 |
* |
| 5732 |
* Return value: %TRUE if the window has been marked as transient, |
| 5733 |
* %FALSE if an error occurred. |
| 5734 |
* |
| 5735 |
* Since: 3.22 |
| 5736 |
*/ |
| 5737 |
gboolean |
| 5738 |
gdk_wayland_window_set_transient_for_exported (GdkWindow *window, |
| 5739 |
char *parent_handle_str) |
| 5740 |
{ |
| 5741 |
GdkWindowImplWayland *impl; |
| 5742 |
GdkWaylandDisplay *display_wayland; |
| 5743 |
GdkDisplay *display = gdk_window_get_display (window); |
| 5744 |
|
| 5745 |
g_return_val_if_fail (GDK_IS_WAYLAND_WINDOW (window), FALSE); |
| 5746 |
g_return_val_if_fail (GDK_IS_WAYLAND_DISPLAY (display), FALSE); |
| 5747 |
g_return_val_if_fail (!should_map_as_subsurface (window) && |
| 5748 |
!should_map_as_popup (window), FALSE); |
| 5749 |
|
| 5750 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5751 |
display_wayland = GDK_WAYLAND_DISPLAY (display); |
| 5752 |
|
| 5753 |
if (display_wayland->xdg_importer_v2) |
| 5754 |
{ |
| 5755 |
gdk_window_set_transient_for (window, NULL); |
| 5756 |
|
| 5757 |
impl->imported_v2_transient_for = |
| 5758 |
zxdg_importer_v2_import_toplevel (display_wayland->xdg_importer_v2, |
| 5759 |
parent_handle_str); |
| 5760 |
zxdg_imported_v2_add_listener (impl->imported_v2_transient_for, |
| 5761 |
&xdg_imported_v2_listener, |
| 5762 |
window); |
| 5763 |
} |
| 5764 |
else if (display_wayland->xdg_importer_v1) |
| 5765 |
{ |
| 5766 |
gdk_window_set_transient_for (window, NULL); |
| 5767 |
|
| 5768 |
impl->imported_v1_transient_for = |
| 5769 |
zxdg_importer_v1_import (display_wayland->xdg_importer_v1, |
| 5770 |
parent_handle_str); |
| 5771 |
zxdg_imported_v1_add_listener (impl->imported_v1_transient_for, |
| 5772 |
&xdg_imported_v1_listener, |
| 5773 |
window); |
| 5774 |
} |
| 5775 |
else |
| 5776 |
{ |
| 5777 |
g_warning ("Server is missing xdg_foreign support"); |
| 5778 |
return FALSE; |
| 5779 |
} |
| 5780 |
|
| 5781 |
gdk_wayland_window_sync_parent_of_imported (window); |
| 5782 |
|
| 5783 |
return TRUE; |
| 5784 |
} |
| 5785 |
|
| 5786 |
static struct zwp_keyboard_shortcuts_inhibitor_v1 * |
| 5787 |
gdk_wayland_window_get_inhibitor (GdkWindowImplWayland *impl, |
| 5788 |
struct wl_seat *seat) |
| 5789 |
{ |
| 5790 |
return g_hash_table_lookup (impl->shortcuts_inhibitors, seat); |
| 5791 |
} |
| 5792 |
|
| 5793 |
void |
| 5794 |
gdk_wayland_window_inhibit_shortcuts (GdkWindow *window, |
| 5795 |
GdkSeat *gdk_seat) |
| 5796 |
{ |
| 5797 |
GdkWindowImplWayland *impl= GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5798 |
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (gdk_window_get_display (window)); |
| 5799 |
struct wl_surface *surface = impl->display_server.wl_surface; |
| 5800 |
struct wl_seat *seat = gdk_wayland_seat_get_wl_seat (gdk_seat); |
| 5801 |
struct zwp_keyboard_shortcuts_inhibitor_v1 *inhibitor; |
| 5802 |
|
| 5803 |
if (display->keyboard_shortcuts_inhibit == NULL) |
| 5804 |
return; |
| 5805 |
|
| 5806 |
if (gdk_wayland_window_get_inhibitor (impl, seat)) |
| 5807 |
return; /* Already inhibitted */ |
| 5808 |
|
| 5809 |
inhibitor = |
| 5810 |
zwp_keyboard_shortcuts_inhibit_manager_v1_inhibit_shortcuts ( |
| 5811 |
display->keyboard_shortcuts_inhibit, surface, seat); |
| 5812 |
|
| 5813 |
g_hash_table_insert (impl->shortcuts_inhibitors, seat, inhibitor); |
| 5814 |
} |
| 5815 |
|
| 5816 |
void |
| 5817 |
gdk_wayland_window_restore_shortcuts (GdkWindow *window, |
| 5818 |
GdkSeat *gdk_seat) |
| 5819 |
{ |
| 5820 |
GdkWindowImplWayland *impl; |
| 5821 |
struct wl_seat *seat; |
| 5822 |
struct zwp_keyboard_shortcuts_inhibitor_v1 *inhibitor; |
| 5823 |
|
| 5824 |
g_return_if_fail (GDK_IS_WAYLAND_WINDOW (window)); |
| 5825 |
g_return_if_fail (GDK_IS_WINDOW_IMPL_WAYLAND (window->impl)); |
| 5826 |
|
| 5827 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5828 |
seat = gdk_wayland_seat_get_wl_seat (gdk_seat); |
| 5829 |
|
| 5830 |
inhibitor = gdk_wayland_window_get_inhibitor (impl, seat); |
| 5831 |
if (inhibitor == NULL) |
| 5832 |
return; /* Not inhibitted */ |
| 5833 |
|
| 5834 |
zwp_keyboard_shortcuts_inhibitor_v1_destroy (inhibitor); |
| 5835 |
g_hash_table_remove (impl->shortcuts_inhibitors, seat); |
| 5836 |
} |
| 5837 |
|
| 5838 |
/** |
| 5839 |
* gdk_wayland_window_add_frame_callback_surface: |
| 5840 |
* @window: the #GdkWindow requesting callbacks |
| 5841 |
* @surface: the wl_surface to add |
| 5842 |
* |
| 5843 |
* Add @surface to a list of surfaces for which frame callback |
| 5844 |
* listeners will get set up, additionally to the one of @window. |
| 5845 |
* |
| 5846 |
* This is useful when clients use subsurfaces independently of GDK. |
| 5847 |
* For example if a client creates a subsurface that covers @window |
| 5848 |
* entirely. If this subsurface is opaque, Wayland compositors may not |
| 5849 |
* emit callbacks for the surface of @window any more. |
| 5850 |
* Adding the covering subsurface via this function ensures the |
| 5851 |
* @window will continue to update. |
| 5852 |
* |
| 5853 |
* A single callback is sufficient to trigger the next update. If more |
| 5854 |
* than one are triggered, the later ones will get ignored. |
| 5855 |
* |
| 5856 |
* Before @surface gets destroyed it must get removed again using |
| 5857 |
* gdk_wayland_window_remove_frame_callback_surface(). |
| 5858 |
* |
| 5859 |
* Note that the client is responsible to commit the @surface. |
| 5860 |
* One way to archive this is to always commit after the |
| 5861 |
* #GdkSurface::after-paint signal was triggered. |
| 5862 |
* |
| 5863 |
* Since: 3.24.25 |
| 5864 |
*/ |
| 5865 |
void |
| 5866 |
gdk_wayland_window_add_frame_callback_surface (GdkWindow *window, |
| 5867 |
struct wl_surface *surface) |
| 5868 |
{ |
| 5869 |
GdkWindowImplWayland *impl; |
| 5870 |
|
| 5871 |
g_return_if_fail (GDK_IS_WAYLAND_WINDOW (window)); |
| 5872 |
g_return_if_fail (GDK_IS_WINDOW_IMPL_WAYLAND (window->impl)); |
| 5873 |
g_return_if_fail (surface != NULL); |
| 5874 |
|
| 5875 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5876 |
|
| 5877 |
g_hash_table_insert (impl->frame_callback_surfaces, surface, NULL); |
| 5878 |
} |
| 5879 |
|
| 5880 |
/** |
| 5881 |
* gdk_wayland_window_remove_frame_callback_surface: |
| 5882 |
* @window: the #GdkWindow requesting callbacks |
| 5883 |
* @surface: the surface to remove |
| 5884 |
* |
| 5885 |
* Remove @surface from the list of surfaces again that got added via |
| 5886 |
* gdk_wayland_window_add_frame_callback_surface(). |
| 5887 |
* |
| 5888 |
* This function must be called before @surface gets destroyed. |
| 5889 |
* |
| 5890 |
* Since: 3.24.25 |
| 5891 |
*/ |
| 5892 |
void |
| 5893 |
gdk_wayland_window_remove_frame_callback_surface (GdkWindow *window, |
| 5894 |
struct wl_surface *surface) |
| 5895 |
{ |
| 5896 |
GdkWindowImplWayland *impl; |
| 5897 |
|
| 5898 |
g_return_if_fail (GDK_IS_WAYLAND_WINDOW (window)); |
| 5899 |
g_return_if_fail (GDK_IS_WINDOW_IMPL_WAYLAND (window->impl)); |
| 5900 |
g_return_if_fail (surface != NULL); |
| 5901 |
|
| 5902 |
impl = GDK_WINDOW_IMPL_WAYLAND (window->impl); |
| 5903 |
|
| 5904 |
g_hash_table_remove (impl->frame_callback_surfaces, surface); |
| 5905 |
} |