[gtk+/wip/gbsneto/edge-constraints-gtk4: 6/6] window: Improve detection of edge constraint support
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/gbsneto/edge-constraints-gtk4: 6/6] window: Improve detection of edge constraint support
- Date: Mon, 18 Sep 2017 02:15:31 +0000 (UTC)
commit 20d2d1674dadf408665cbbee58bd6a514167a0ee
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Sep 17 23:09:10 2017 -0300
window: Improve detection of edge constraint support
Instead of relying on special values of edge constraints, this
patch adds an internal-only gdk_window_supports_edge_constraints()
function that by default returns FALSE, and is implemented by
GdkWindowWayland and GdkWindowX11.
This way, we can properly detect server-side support for this
feature and adapt accordingly.
https://bugzilla.gnome.org/show_bug.cgi?id=783669
gdk/gdk-private.h | 2 ++
gdk/gdkwindow.c | 16 ++++++++++++++++
gdk/gdkwindowimpl.h | 1 +
gdk/wayland/gdkwindow-wayland.c | 9 +++++++++
gdk/x11/gdkdisplay-x11.c | 4 +---
gdk/x11/gdkwindow-x11.c | 8 ++++++++
gtk/gtkwindow.c | 24 +++++++++++++++++++-----
7 files changed, 56 insertions(+), 8 deletions(-)
---
diff --git a/gdk/gdk-private.h b/gdk/gdk-private.h
index 33090ee..7f5daec 100644
--- a/gdk/gdk-private.h
+++ b/gdk/gdk-private.h
@@ -21,6 +21,8 @@ void gdk_gl_set_flags (GdkGLFlags flags);
void gdk_window_freeze_toplevel_updates (GdkWindow *window);
void gdk_window_thaw_toplevel_updates (GdkWindow *window);
+gboolean gdk_window_supports_edge_constraints (GdkWindow *window);
+
GdkRenderingMode gdk_display_get_rendering_mode (GdkDisplay *display);
void gdk_display_set_rendering_mode (GdkDisplay *display,
GdkRenderingMode mode);
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 09d136c..813a237 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -8234,3 +8234,19 @@ gdk_window_show_window_menu (GdkWindow *window,
else
return FALSE;
}
+
+gboolean
+gdk_window_supports_edge_constraints (GdkWindow *window)
+{
+ GdkWindowImplClass *impl_class;
+
+ g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
+ g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), FALSE);
+
+ impl_class = GDK_WINDOW_IMPL_GET_CLASS (window->impl);
+
+ if (impl_class->supports_edge_constraints)
+ return impl_class->supports_edge_constraints (window);
+ else
+ return FALSE;
+}
diff --git a/gdk/gdkwindowimpl.h b/gdk/gdkwindowimpl.h
index 6d76379..4f24316 100644
--- a/gdk/gdkwindowimpl.h
+++ b/gdk/gdkwindowimpl.h
@@ -269,6 +269,7 @@ struct _GdkWindowImplClass
gboolean attached,
GdkGLContext *share,
GError **error);
+ gboolean (* supports_edge_constraints)(GdkWindow *window);
};
/* Interface Functions */
diff --git a/gdk/wayland/gdkwindow-wayland.c b/gdk/wayland/gdkwindow-wayland.c
index bca70be..5395e84 100644
--- a/gdk/wayland/gdkwindow-wayland.c
+++ b/gdk/wayland/gdkwindow-wayland.c
@@ -3637,6 +3637,14 @@ gdk_wayland_window_show_window_menu (GdkWindow *window,
return TRUE;
}
+static gboolean
+gdk_wayland_window_supports_edge_constraints (GdkWindow *window)
+{
+ GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
+
+ return gtk_surface1_get_version (impl->display_server.gtk_surface) >
GTK_SURFACE1_CONFIGURE_EDGES_SINCE_VERSION;
+}
+
static void
_gdk_window_impl_wayland_class_init (GdkWindowImplWaylandClass *klass)
{
@@ -3716,6 +3724,7 @@ _gdk_window_impl_wayland_class_init (GdkWindowImplWaylandClass *klass)
impl_class->set_shadow_width = gdk_wayland_window_set_shadow_width;
impl_class->show_window_menu = gdk_wayland_window_show_window_menu;
impl_class->create_gl_context = gdk_wayland_window_create_gl_context;
+ impl_class->supports_edge_constraints = gdk_wayland_window_supports_edge_constraints;
signals[COMMITTED] = g_signal_new ("committed",
G_TYPE_FROM_CLASS (object_class),
diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c
index be57485..0c42e7c 100644
--- a/gdk/x11/gdkdisplay-x11.c
+++ b/gdk/x11/gdkdisplay-x11.c
@@ -199,7 +199,6 @@ do_edge_constraint_state_check (GdkWindow *window,
{
GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
GdkWindowState local_set, local_unset;
- GdkScreen *screen = GDK_WINDOW_SCREEN (window);
guint edge_constraints;
local_set = *set;
@@ -210,8 +209,7 @@ do_edge_constraint_state_check (GdkWindow *window,
* implementation. If it supports _GTK_EDGE_CONSTRAINTS, however, remove
* the GDK_WINDOW_STATE_TILED flag explicitly.
*/
- if (!gdk_x11_screen_supports_net_wm_hint (screen,
- gdk_atom_intern_static_string ("_GTK_EDGE_CONSTRAINTS")))
+ if (!gdk_window_supports_edge_constraints (window))
{
/* FIXME: we rely on implementation details of mutter here:
* mutter only tiles horizontally, and sets maxvert when it does
diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c
index 7d36907..3bcff7d 100644
--- a/gdk/x11/gdkwindow-x11.c
+++ b/gdk/x11/gdkwindow-x11.c
@@ -210,6 +210,13 @@ gdk_x11_window_get_unscaled_size (GdkWindow *window,
*unscaled_height = impl->unscaled_height;
}
+static gboolean
+gdk_x11_window_supports_edge_constraints (GdkWindow *window)
+{
+ return gdk_x11_screen_supports_net_wm_hint (GDK_WINDOW_SCREEN (window),
+ gdk_atom_intern_static_string ("_GTK_EDGE_CONSTRAINTS"));
+}
+
static void
set_sync_counter(Display *display,
XSyncCounter counter,
@@ -5071,4 +5078,5 @@ gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
impl_class->show_window_menu = gdk_x11_window_show_window_menu;
impl_class->create_gl_context = gdk_x11_window_create_gl_context;
impl_class->get_unscaled_size = gdk_x11_window_get_unscaled_size;
+ impl_class->supports_edge_constraints = gdk_x11_window_supports_edge_constraints;
}
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 139a5b3..0e98e9e 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -1699,6 +1699,7 @@ edge_under_coordinates (GtkWindow *window,
GtkStyleContext *context;
gint handle_v, handle_h;
GtkBorder border;
+ gboolean supports_edge_constraints;
if (priv->type != GTK_WINDOW_TOPLEVEL ||
!priv->client_decorated ||
@@ -1707,7 +1708,16 @@ edge_under_coordinates (GtkWindow *window,
priv->maximized)
return FALSE;
- if (priv->tiled && !priv->edge_constraints)
+ supports_edge_constraints = gdk_window_supports_edge_constraints (_gtk_widget_get_window (GTK_WIDGET
(window)));
+
+ if (!supports_edge_constraints && priv->tiled)
+ return FALSE;
+
+ if (supports_edge_constraints &&
+ !(priv->edge_constraints & GDK_WINDOW_STATE_TOP_RESIZABLE) &&
+ !(priv->edge_constraints & GDK_WINDOW_STATE_RIGHT_RESIZABLE) &&
+ !(priv->edge_constraints & GDK_WINDOW_STATE_BOTTOM_RESIZABLE) &&
+ !(priv->edge_constraints & GDK_WINDOW_STATE_LEFT_RESIZABLE))
return FALSE;
_gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
@@ -1744,7 +1754,8 @@ edge_under_coordinates (GtkWindow *window,
edge != GDK_WINDOW_EDGE_SOUTH_WEST)
return FALSE;
- if (!(priv->edge_constraints & GDK_WINDOW_STATE_LEFT_RESIZABLE))
+ if (supports_edge_constraints &&
+ !(priv->edge_constraints & GDK_WINDOW_STATE_LEFT_RESIZABLE))
return FALSE;
}
else if (x >= allocation.x + allocation.width - border.right - handle_h)
@@ -1754,7 +1765,8 @@ edge_under_coordinates (GtkWindow *window,
edge != GDK_WINDOW_EDGE_SOUTH_EAST)
return FALSE;
- if (!(priv->edge_constraints & GDK_WINDOW_STATE_RIGHT_RESIZABLE))
+ if (supports_edge_constraints &&
+ !(priv->edge_constraints & GDK_WINDOW_STATE_RIGHT_RESIZABLE))
return FALSE;
}
else if (edge != GDK_WINDOW_EDGE_NORTH &&
@@ -1769,7 +1781,8 @@ edge_under_coordinates (GtkWindow *window,
edge != GDK_WINDOW_EDGE_NORTH_EAST)
return FALSE;
- if (!(priv->edge_constraints & GDK_WINDOW_STATE_TOP_RESIZABLE))
+ if (supports_edge_constraints &&
+ !(priv->edge_constraints & GDK_WINDOW_STATE_TOP_RESIZABLE))
return FALSE;
}
else if (y > allocation.y + allocation.height - border.bottom - handle_v)
@@ -1779,7 +1792,8 @@ edge_under_coordinates (GtkWindow *window,
edge != GDK_WINDOW_EDGE_SOUTH_EAST)
return FALSE;
- if (!(priv->edge_constraints & GDK_WINDOW_STATE_BOTTOM_RESIZABLE))
+ if (supports_edge_constraints &&
+ !(priv->edge_constraints & GDK_WINDOW_STATE_BOTTOM_RESIZABLE))
return FALSE;
}
else if (edge != GDK_WINDOW_EDGE_WEST &&
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]