[gtk/matthiasc/surface-state-rework: 71/80] x11/surface: Move the scattered compute-size calls to helper
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/surface-state-rework: 71/80] x11/surface: Move the scattered compute-size calls to helper
- Date: Sat, 5 Dec 2020 17:42:40 +0000 (UTC)
commit 51fe3d6b1923134abccfaaf08a8bb64f2c22d714
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Sat Dec 5 11:38:17 2020 +0100
x11/surface: Move the scattered compute-size calls to helper
This simplifies things, and fixes issue where we'd resize the wrong
time, and miss resizing other times.
gdk/x11/gdksurface-x11.c | 183 ++++++++++++++++++++---------------------------
1 file changed, 77 insertions(+), 106 deletions(-)
---
diff --git a/gdk/x11/gdksurface-x11.c b/gdk/x11/gdksurface-x11.c
index b5db385093..7f5983bcd8 100644
--- a/gdk/x11/gdksurface-x11.c
+++ b/gdk/x11/gdksurface-x11.c
@@ -115,6 +115,10 @@ static void gdk_x11_surface_toplevel_resize (GdkSurface *surface,
int width,
int height);
+static void gdk_x11_surface_set_geometry_hints (GdkSurface *surface,
+ const GdkGeometry *geometry,
+ GdkSurfaceHints geom_mask);
+
/* Return whether time1 is considered later than time2 as far as xserver
* time is concerned. Accounts for wraparound.
*/
@@ -233,25 +237,17 @@ update_shadow_size (GdkSurface *surface,
}
static gboolean
-compute_size_idle (gpointer user_data)
+compute_toplevel_size (GdkSurface *surface,
+ int *width,
+ int *height)
{
- GdkSurface *surface = user_data;
GdkX11Surface *impl = GDK_X11_SURFACE (surface);
GdkDisplay *display = gdk_surface_get_display (surface);
GdkMonitor *monitor;
GdkToplevelSize size;
int bounds_width, bounds_height;
- int width, height;
-
- impl->compute_size_source_id = 0;
-
- if (impl->next_layout.surface_geometry_dirty)
- return G_SOURCE_REMOVE;
-
- if (surface->state & (GDK_TOPLEVEL_STATE_MAXIMIZED &
- GDK_TOPLEVEL_STATE_FULLSCREEN &
- GDK_TOPLEVEL_STATE_TILED))
- return G_SOURCE_REMOVE;
+ GdkGeometry geometry;
+ GdkSurfaceHints mask;
monitor = gdk_display_get_monitor_at_surface (display, surface);
if (monitor)
@@ -271,10 +267,64 @@ compute_size_idle (gpointer user_data)
gdk_toplevel_size_init (&size, bounds_width, bounds_height);
gdk_toplevel_notify_compute_size (GDK_TOPLEVEL (surface), &size);
- width = size.width;
- height = size.height;
- if (width != impl->unscaled_width * impl->surface_scale ||
- height != impl->unscaled_height * impl->surface_scale)
+ if (size.shadow.is_valid)
+ {
+ update_shadow_size (surface,
+ size.shadow.left,
+ size.shadow.right,
+ size.shadow.top,
+ size.shadow.bottom);
+ }
+
+ if (gdk_toplevel_layout_get_resizable (impl->toplevel_layout))
+ {
+ geometry.min_width = size.min_width;
+ geometry.min_height = size.min_height;
+ mask = GDK_HINT_MIN_SIZE;
+ }
+ else
+ {
+ geometry.max_width = geometry.min_width = size.width;
+ geometry.max_height = geometry.min_height = size.height;
+ mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE;
+ }
+ gdk_x11_surface_set_geometry_hints (surface, &geometry, mask);
+
+ if (!(surface->state & (GDK_TOPLEVEL_STATE_FULLSCREEN |
+ GDK_TOPLEVEL_STATE_MAXIMIZED |
+ GDK_TOPLEVEL_STATE_TILED |
+ GDK_TOPLEVEL_STATE_TOP_TILED |
+ GDK_TOPLEVEL_STATE_RIGHT_TILED |
+ GDK_TOPLEVEL_STATE_BOTTOM_TILED |
+ GDK_TOPLEVEL_STATE_LEFT_TILED |
+ GDK_TOPLEVEL_STATE_MINIMIZED)) &&
+ (!impl->next_layout.configure_pending || surface->resize_count > 0))
+ {
+ gdk_surface_constrain_size (&geometry, mask,
+ size.width, size.height,
+ &size.width, &size.height);
+ if ((impl->next_layout.configured_width != size.width ||
+ impl->next_layout.configured_height != size.height))
+ {
+ *width = size.width;
+ *height = size.height;
+
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static gboolean
+compute_size_idle (gpointer user_data)
+{
+ GdkSurface *surface = user_data;
+ GdkX11Surface *impl = GDK_X11_SURFACE (surface);
+ int width, height;
+
+ impl->compute_size_source_id = 0;
+ if (compute_toplevel_size (surface, &width, &height))
gdk_x11_surface_toplevel_resize (surface, width, height);
return G_SOURCE_REMOVE;
@@ -302,44 +352,19 @@ gdk_x11_surface_compute_size (GdkSurface *surface)
if (GDK_IS_TOPLEVEL (surface))
{
- GdkDisplay *display = gdk_surface_get_display (surface);
- GdkMonitor *monitor;
- GdkToplevelSize size;
- int bounds_width, bounds_height;
+ int width, height;
- monitor = gdk_display_get_monitor_at_surface (display, surface);
- if (monitor)
- {
- GdkRectangle workarea;
+ if (compute_toplevel_size (surface, &width, &height))
+ gdk_x11_surface_toplevel_resize (surface, width, height);
- gdk_x11_monitor_get_workarea (monitor, &workarea);
- bounds_width = workarea.width;
- bounds_height = workarea.height;
- }
- else
+ if (surface->resize_count == 0)
{
- bounds_width = G_MAXINT;
- bounds_height = G_MAXINT;
+ surface->width = impl->next_layout.configured_width;
+ surface->height = impl->next_layout.configured_height;
+ _gdk_surface_update_size (surface);
+ _gdk_x11_surface_update_size (impl);
}
- gdk_toplevel_size_init (&size, bounds_width, bounds_height);
- gdk_toplevel_notify_compute_size (GDK_TOPLEVEL (surface), &size);
-
- if (size.shadow.is_valid)
- {
- update_shadow_size (surface,
- size.shadow.left,
- size.shadow.right,
- size.shadow.top,
- size.shadow.bottom);
- }
-
- surface->width = impl->next_layout.configured_width;
- surface->height = impl->next_layout.configured_height;
-
- _gdk_surface_update_size (surface);
- _gdk_x11_surface_update_size (impl);
-
impl->next_layout.surface_geometry_dirty = FALSE;
impl->next_layout.configure_pending = FALSE;
}
@@ -1926,10 +1951,6 @@ gdk_x11_surface_enter_leave_monitors (GdkSurface *surface)
}
}
-static void gdk_x11_surface_set_geometry_hints (GdkSurface *surface,
- const GdkGeometry *geometry,
- GdkSurfaceHints geom_mask);
-
void
_gdk_x11_surface_set_surface_scale (GdkSurface *surface,
int scale)
@@ -5039,13 +5060,7 @@ gdk_x11_toplevel_present (GdkToplevel *toplevel,
{
GdkSurface *surface = GDK_SURFACE (toplevel);
GdkX11Surface *impl = GDK_X11_SURFACE (surface);
- GdkDisplay *display = gdk_surface_get_display (surface);
- GdkMonitor *monitor;
- GdkToplevelSize size;
- int bounds_width, bounds_height;
int width, height;
- GdkGeometry geometry;
- GdkSurfaceHints mask;
gboolean was_mapped;
if (surface->destroyed)
@@ -5058,52 +5073,8 @@ gdk_x11_toplevel_present (GdkToplevel *toplevel,
g_clear_pointer (&impl->toplevel_layout, gdk_toplevel_layout_unref);
impl->toplevel_layout = gdk_toplevel_layout_copy (layout);
- monitor = gdk_display_get_monitor_at_surface (display, surface);
- if (monitor)
- {
- GdkRectangle workarea;
-
- gdk_x11_monitor_get_workarea (monitor, &workarea);
- bounds_width = workarea.width;
- bounds_height = workarea.height;
- }
- else
- {
- bounds_width = G_MAXINT;
- bounds_height = G_MAXINT;
- }
-
- gdk_toplevel_size_init (&size, bounds_width, bounds_height);
- gdk_toplevel_notify_compute_size (toplevel, &size);
- g_warn_if_fail (size.width > 0);
- g_warn_if_fail (size.height > 0);
- width = size.width;
- height = size.height;
-
- if (gdk_toplevel_layout_get_resizable (layout))
- {
- geometry.min_width = size.min_width;
- geometry.min_height = size.min_height;
- mask = GDK_HINT_MIN_SIZE;
- }
- else
- {
- geometry.max_width = geometry.min_width = width;
- geometry.max_height = geometry.min_height = height;
- mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE;
- }
- gdk_x11_surface_set_geometry_hints (surface, &geometry, mask);
- gdk_surface_constrain_size (&geometry, mask, width, height, &width, &height);
- gdk_x11_surface_toplevel_resize (surface, width, height);
-
- if (size.shadow.is_valid)
- {
- update_shadow_size (surface,
- size.shadow.left,
- size.shadow.right,
- size.shadow.top,
- size.shadow.bottom);
- }
+ if (compute_toplevel_size (surface, &width, &height))
+ gdk_x11_surface_toplevel_resize (surface, width, height);
if (gdk_toplevel_layout_get_maximized (layout))
gdk_x11_surface_maximize (surface);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]