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
This commit is contained in:
Georges Basile Stavracas Neto 2017-09-17 23:09:10 -03:00
parent b1c4e9afef
commit 0bdaebef1e
7 changed files with 56 additions and 8 deletions

View File

@ -21,6 +21,8 @@ void gdk_gl_set_flags (GdkGLFlags flags);
void gdk_window_freeze_toplevel_updates (GdkWindow *window); void gdk_window_freeze_toplevel_updates (GdkWindow *window);
void gdk_window_thaw_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); GdkRenderingMode gdk_display_get_rendering_mode (GdkDisplay *display);
void gdk_display_set_rendering_mode (GdkDisplay *display, void gdk_display_set_rendering_mode (GdkDisplay *display,
GdkRenderingMode mode); GdkRenderingMode mode);

View File

@ -8234,3 +8234,19 @@ gdk_window_show_window_menu (GdkWindow *window,
else else
return FALSE; 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;
}

View File

@ -269,6 +269,7 @@ struct _GdkWindowImplClass
gboolean attached, gboolean attached,
GdkGLContext *share, GdkGLContext *share,
GError **error); GError **error);
gboolean (* supports_edge_constraints)(GdkWindow *window);
}; };
/* Interface Functions */ /* Interface Functions */

View File

@ -3637,6 +3637,14 @@ gdk_wayland_window_show_window_menu (GdkWindow *window,
return TRUE; 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 static void
_gdk_window_impl_wayland_class_init (GdkWindowImplWaylandClass *klass) _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->set_shadow_width = gdk_wayland_window_set_shadow_width;
impl_class->show_window_menu = gdk_wayland_window_show_window_menu; impl_class->show_window_menu = gdk_wayland_window_show_window_menu;
impl_class->create_gl_context = gdk_wayland_window_create_gl_context; 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", signals[COMMITTED] = g_signal_new ("committed",
G_TYPE_FROM_CLASS (object_class), G_TYPE_FROM_CLASS (object_class),

View File

@ -199,7 +199,6 @@ do_edge_constraint_state_check (GdkWindow *window,
{ {
GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window); GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
GdkWindowState local_set, local_unset; GdkWindowState local_set, local_unset;
GdkScreen *screen = GDK_WINDOW_SCREEN (window);
guint edge_constraints; guint edge_constraints;
local_set = *set; local_set = *set;
@ -210,8 +209,7 @@ do_edge_constraint_state_check (GdkWindow *window,
* implementation. If it supports _GTK_EDGE_CONSTRAINTS, however, remove * implementation. If it supports _GTK_EDGE_CONSTRAINTS, however, remove
* the GDK_WINDOW_STATE_TILED flag explicitly. * the GDK_WINDOW_STATE_TILED flag explicitly.
*/ */
if (!gdk_x11_screen_supports_net_wm_hint (screen, if (!gdk_window_supports_edge_constraints (window))
gdk_atom_intern_static_string ("_GTK_EDGE_CONSTRAINTS")))
{ {
/* FIXME: we rely on implementation details of mutter here: /* FIXME: we rely on implementation details of mutter here:
* mutter only tiles horizontally, and sets maxvert when it does * mutter only tiles horizontally, and sets maxvert when it does

View File

@ -210,6 +210,13 @@ gdk_x11_window_get_unscaled_size (GdkWindow *window,
*unscaled_height = impl->unscaled_height; *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 static void
set_sync_counter(Display *display, set_sync_counter(Display *display,
XSyncCounter counter, 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->show_window_menu = gdk_x11_window_show_window_menu;
impl_class->create_gl_context = gdk_x11_window_create_gl_context; impl_class->create_gl_context = gdk_x11_window_create_gl_context;
impl_class->get_unscaled_size = gdk_x11_window_get_unscaled_size; impl_class->get_unscaled_size = gdk_x11_window_get_unscaled_size;
impl_class->supports_edge_constraints = gdk_x11_window_supports_edge_constraints;
} }

View File

@ -1699,6 +1699,7 @@ edge_under_coordinates (GtkWindow *window,
GtkStyleContext *context; GtkStyleContext *context;
gint handle_v, handle_h; gint handle_v, handle_h;
GtkBorder border; GtkBorder border;
gboolean supports_edge_constraints;
if (priv->type != GTK_WINDOW_TOPLEVEL || if (priv->type != GTK_WINDOW_TOPLEVEL ||
!priv->client_decorated || !priv->client_decorated ||
@ -1707,7 +1708,16 @@ edge_under_coordinates (GtkWindow *window,
priv->maximized) priv->maximized)
return FALSE; 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; return FALSE;
_gtk_widget_get_allocation (GTK_WIDGET (window), &allocation); _gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
@ -1744,7 +1754,8 @@ edge_under_coordinates (GtkWindow *window,
edge != GDK_WINDOW_EDGE_SOUTH_WEST) edge != GDK_WINDOW_EDGE_SOUTH_WEST)
return FALSE; 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; return FALSE;
} }
else if (x >= allocation.x + allocation.width - border.right - handle_h) 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) edge != GDK_WINDOW_EDGE_SOUTH_EAST)
return FALSE; 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; return FALSE;
} }
else if (edge != GDK_WINDOW_EDGE_NORTH && else if (edge != GDK_WINDOW_EDGE_NORTH &&
@ -1769,7 +1781,8 @@ edge_under_coordinates (GtkWindow *window,
edge != GDK_WINDOW_EDGE_NORTH_EAST) edge != GDK_WINDOW_EDGE_NORTH_EAST)
return FALSE; 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; return FALSE;
} }
else if (y > allocation.y + allocation.height - border.bottom - handle_v) 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) edge != GDK_WINDOW_EDGE_SOUTH_EAST)
return FALSE; 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; return FALSE;
} }
else if (edge != GDK_WINDOW_EDGE_WEST && else if (edge != GDK_WINDOW_EDGE_WEST &&