Skip to content

Commit 50e8885

Browse files
authored
[Wayland] Add support for xdg_toplevel.configure_bounds() (#740)
This PR adds support for xdg_toplevel_configure_bounds(), which is aims to communicate the maximum size a surface should be created with, and loosely corresponds to the concept of "work area" in the X11 world. It was introduced in v4 of xdg-shell protocol, so also bump it's version. Adapted from Mutter: https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2167
1 parent e603d4a commit 50e8885

File tree

7 files changed

+170
-101
lines changed

7 files changed

+170
-101
lines changed

src/core/window-private.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,4 +908,8 @@ gboolean meta_window_shortcuts_inhibited (MetaWindow *window,
908908
ClutterInputDevice *source);
909909
gboolean meta_window_is_stackable (MetaWindow *window);
910910
gboolean meta_window_is_focus_async (MetaWindow *window);
911+
912+
gboolean meta_window_calculate_bounds (MetaWindow *window,
913+
int *bounds_width,
914+
int *bounds_height);
911915
#endif

src/core/window.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,7 @@ _meta_window_shared_new (MetaDisplay *display,
10471047
MetaCompEffect effect,
10481048
XWindowAttributes *attrs)
10491049
{
1050+
MetaBackend *backend = meta_get_backend ();
10501051
MetaWorkspaceManager *workspace_manager = display->workspace_manager;
10511052
MetaWindow *window;
10521053

@@ -1241,7 +1242,11 @@ _meta_window_shared_new (MetaDisplay *display,
12411242

12421243
window->compositor_private = NULL;
12431244

1244-
window->monitor = meta_window_calculate_main_logical_monitor (window);
1245+
if (window->rect.width > 0 && window->rect.height > 0)
1246+
window->monitor = meta_window_calculate_main_logical_monitor (window);
1247+
else
1248+
window->monitor = meta_backend_get_current_logical_monitor (backend);
1249+
12451250
if (window->monitor)
12461251
window->preferred_output_winsys_id = window->monitor->winsys_id;
12471252
else
@@ -9495,3 +9500,29 @@ meta_window_get_icon_name (MetaWindow *window)
94959500

94969501
return window->theme_icon_name;
94979502
}
9503+
9504+
gboolean
9505+
meta_window_calculate_bounds (MetaWindow *window,
9506+
int *bounds_width,
9507+
int *bounds_height)
9508+
{
9509+
MetaLogicalMonitor *main_monitor;
9510+
9511+
main_monitor = meta_window_get_main_logical_monitor (window);
9512+
if (main_monitor)
9513+
{
9514+
MetaRectangle work_area;
9515+
9516+
meta_window_get_work_area_for_logical_monitor (window,
9517+
main_monitor,
9518+
&work_area);
9519+
9520+
*bounds_width = work_area.width;
9521+
*bounds_height = work_area.height;
9522+
return TRUE;
9523+
}
9524+
else
9525+
{
9526+
return FALSE;
9527+
}
9528+
}

src/wayland/meta-wayland-versions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
/* Global/master objects (version exported by wl_registry and negotiated through bind) */
3838
#define META_WL_COMPOSITOR_VERSION 5
3939
#define META_WL_DATA_DEVICE_MANAGER_VERSION 3
40-
#define META_XDG_WM_BASE_VERSION 3
40+
#define META_XDG_WM_BASE_VERSION 4
4141
#define META_WL_SEAT_VERSION 5
4242
#define META_WL_OUTPUT_VERSION 4
4343
#define META_XSERVER_VERSION 1

src/wayland/meta-wayland-window-configuration.c

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,64 @@
2424

2525
static uint32_t global_serial_counter = 0;
2626

27+
static gboolean
28+
is_window_size_fixed (MetaWindow *window)
29+
{
30+
if (meta_window_is_fullscreen (window))
31+
return TRUE;
32+
33+
if (meta_window_get_maximized (window) |
34+
(META_MAXIMIZE_VERTICAL | META_MAXIMIZE_VERTICAL))
35+
return TRUE;
36+
37+
if (meta_window_get_tile_mode (window) != META_TILE_NONE)
38+
return TRUE;
39+
40+
return FALSE;
41+
}
42+
2743
MetaWaylandWindowConfiguration *
28-
meta_wayland_window_configuration_new (int x,
29-
int y,
30-
int width,
31-
int height,
32-
int scale,
33-
MetaMoveResizeFlags flags,
34-
MetaGravity gravity)
44+
meta_wayland_window_configuration_new (MetaWindow *window,
45+
MetaRectangle rect,
46+
int bounds_width,
47+
int bounds_height,
48+
int scale,
49+
MetaMoveResizeFlags flags,
50+
MetaGravity gravity)
3551
{
3652
MetaWaylandWindowConfiguration *configuration;
3753

3854
configuration = g_new0 (MetaWaylandWindowConfiguration, 1);
3955
*configuration = (MetaWaylandWindowConfiguration) {
4056
.serial = ++global_serial_counter,
4157

42-
.has_position = TRUE,
43-
.x = x,
44-
.y = y,
45-
46-
.has_size = TRUE,
47-
.width = width,
48-
.height = height,
58+
.bounds_height = bounds_height,
59+
.bounds_width = bounds_width,
4960

5061
.scale = scale,
5162
.gravity = gravity,
5263
.flags = flags,
5364
};
5465

66+
if (flags & META_MOVE_RESIZE_MOVE_ACTION ||
67+
window->rect.x != rect.x ||
68+
window->rect.y != rect.y)
69+
{
70+
configuration->has_position = TRUE;
71+
configuration->x = rect.x;
72+
configuration->y = rect.y;
73+
}
74+
75+
if (flags & META_MOVE_RESIZE_RESIZE_ACTION ||
76+
is_window_size_fixed (window) ||
77+
window->rect.width != rect.width ||
78+
window->rect.height != rect.height)
79+
{
80+
configuration->has_size = TRUE;
81+
configuration->width = rect.width;
82+
configuration->height = rect.height;
83+
}
84+
5585
return configuration;
5686
}
5787

@@ -83,14 +113,17 @@ meta_wayland_window_configuration_new_relative (int rel_x,
83113
}
84114

85115
MetaWaylandWindowConfiguration *
86-
meta_wayland_window_configuration_new_empty (void)
116+
meta_wayland_window_configuration_new_empty (int bounds_width,
117+
int bounds_height)
87118
{
88119
MetaWaylandWindowConfiguration *configuration;
89120

90121
configuration = g_new0 (MetaWaylandWindowConfiguration, 1);
91122
*configuration = (MetaWaylandWindowConfiguration) {
92123
.serial = ++global_serial_counter,
93124
.scale = 1,
125+
.bounds_width = bounds_width,
126+
.bounds_height = bounds_height,
94127
};
95128

96129
return configuration;

src/wayland/meta-wayland-window-configuration.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ struct _MetaWaylandWindowConfiguration
4646
int scale;
4747
MetaGravity gravity;
4848
MetaMoveResizeFlags flags;
49+
50+
int bounds_width;
51+
int bounds_height;
4952
};
5053

51-
MetaWaylandWindowConfiguration * meta_wayland_window_configuration_new (int x,
52-
int y,
53-
int width,
54-
int height,
54+
MetaWaylandWindowConfiguration * meta_wayland_window_configuration_new (MetaWindow *window,
55+
MetaRectangle rect,
56+
int max_width,
57+
int max_height,
5558
int scale,
5659
MetaMoveResizeFlags flags,
5760
MetaGravity gravity);
@@ -62,7 +65,8 @@ MetaWaylandWindowConfiguration * meta_wayland_window_configuration_new_relative
6265
int height,
6366
int scale);
6467

65-
MetaWaylandWindowConfiguration * meta_wayland_window_configuration_new_empty (void);
68+
MetaWaylandWindowConfiguration * meta_wayland_window_configuration_new_empty (int bounds_width,
69+
int bounds_height);
6670

6771
void meta_wayland_window_configuration_free (MetaWaylandWindowConfiguration *configuration);
6872

src/wayland/meta-wayland-xdg-shell.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,18 @@ meta_wayland_xdg_toplevel_send_configure (MetaWaylandXdgToplevel *xdg_to
697697
wl_array_init (&states);
698698
fill_states (xdg_toplevel, &states);
699699

700+
if (wl_resource_get_version (xdg_toplevel->resource) >=
701+
XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION &&
702+
configuration->bounds_width > 0 &&
703+
configuration->bounds_height > 0)
704+
{
705+
xdg_toplevel_send_configure_bounds (xdg_toplevel->resource,
706+
(configuration->bounds_width /
707+
configuration->scale),
708+
(configuration->bounds_height /
709+
configuration->scale));
710+
}
711+
700712
xdg_toplevel_send_configure (xdg_toplevel->resource,
701713
configuration->width / configuration->scale,
702714
configuration->height / configuration->scale,
@@ -774,8 +786,18 @@ meta_wayland_xdg_toplevel_apply_state (MetaWaylandSurfaceRole *surface_role,
774786
if (!xdg_surface_priv->configure_sent)
775787
{
776788
MetaWaylandWindowConfiguration *configuration;
789+
int bounds_width;
790+
int bounds_height;
791+
792+
if (!meta_window_calculate_bounds (window, &bounds_width, &bounds_height))
793+
{
794+
bounds_width = 0;
795+
bounds_height = 0;
796+
}
777797

778-
configuration = meta_wayland_window_configuration_new_empty ();
798+
configuration =
799+
meta_wayland_window_configuration_new_empty (bounds_width,
800+
bounds_height);
779801
meta_wayland_xdg_toplevel_send_configure (xdg_toplevel, configuration);
780802
meta_wayland_window_configuration_free (configuration);
781803
return;

0 commit comments

Comments
 (0)