[mutter/wip/gbsneto/edge-constraints: 17/19] wayland: Send edge constraints



commit 95f75472037eb54ecdf2f8acf39a389a6eac0b8b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Aug 17 00:49:36 2017 -0300

    wayland: Send edge constraints
    
    Following up the previous patch, this patch makes the
    Wayland backend send the edge constraints through a
    custom protocol extension internal to GTK.
    
    As it mature, we can think of upstreaming the protocol
    to Wayland itself.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751857

 src/wayland/meta-wayland-gtk-shell.c |   87 ++++++++++++++++++++++++++++++++-
 src/wayland/protocol/gtk-shell.xml   |   20 +++++++-
 2 files changed, 102 insertions(+), 5 deletions(-)
---
diff --git a/src/wayland/meta-wayland-gtk-shell.c b/src/wayland/meta-wayland-gtk-shell.c
index d6e249f..8c6e9e4 100644
--- a/src/wayland/meta-wayland-gtk-shell.c
+++ b/src/wayland/meta-wayland-gtk-shell.c
@@ -148,17 +148,84 @@ gtk_surface_surface_destroyed (MetaWaylandGtkSurface *gtk_surface)
 }
 
 static void
-fill_states (struct wl_array *states,
-             MetaWindow      *window)
+fill_edge_states (struct wl_array *states,
+                  MetaWindow      *window)
 {
   uint32_t *s;
 
+  /* Top */
+  if (window->edge_constraints[0] != META_EDGE_CONSTRAINT_MONITOR)
+    {
+      s = wl_array_add (states, sizeof *s);
+      *s = GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_TOP;
+    }
+
+  /* Right */
+  if (window->edge_constraints[1] != META_EDGE_CONSTRAINT_MONITOR)
+    {
+      s = wl_array_add (states, sizeof *s);
+      *s = GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_RIGHT;
+    }
+
+  /* Bottom */
+  if (window->edge_constraints[2] != META_EDGE_CONSTRAINT_MONITOR)
+    {
+      s = wl_array_add (states, sizeof *s);
+      *s = GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_BOTTOM;
+    }
+
+  /* Left */
+  if (window->edge_constraints[3] != META_EDGE_CONSTRAINT_MONITOR)
+    {
+      s = wl_array_add (states, sizeof *s);
+      *s = GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_LEFT;
+    }
+}
+
+static void
+fill_states (struct wl_array       *states,
+             MetaWindow            *window,
+             MetaWaylandGtkSurface *gtk_surface)
+{
+  struct wl_resource *resource;
+  uint32_t *s;
+
+  resource = gtk_surface->resource;
+
   if (window->tile_mode == META_TILE_LEFT ||
       window->tile_mode == META_TILE_RIGHT)
     {
       s = wl_array_add (states, sizeof *s);
       *s = GTK_SURFACE1_STATE_TILED;
     }
+
+  if (wl_resource_get_version (resource) >= GTK_SURFACE1_STATE_TILED_TOP_SINCE_VERSION &&
+      window->edge_constraints[0] != META_EDGE_CONSTRAINT_NONE)
+    {
+      s = wl_array_add (states, sizeof *s);
+      *s = GTK_SURFACE1_STATE_TILED_TOP;
+    }
+
+  if (wl_resource_get_version (resource) >= GTK_SURFACE1_STATE_TILED_RIGHT_SINCE_VERSION &&
+      window->edge_constraints[1] != META_EDGE_CONSTRAINT_NONE)
+    {
+      s = wl_array_add (states, sizeof *s);
+      *s = GTK_SURFACE1_STATE_TILED_RIGHT;
+    }
+
+  if (wl_resource_get_version (resource) >= GTK_SURFACE1_STATE_TILED_BOTTOM_SINCE_VERSION &&
+      window->edge_constraints[2] != META_EDGE_CONSTRAINT_NONE)
+    {
+      s = wl_array_add (states, sizeof *s);
+      *s = GTK_SURFACE1_STATE_TILED_BOTTOM;
+    }
+
+  if (wl_resource_get_version (resource) >= GTK_SURFACE1_STATE_TILED_LEFT_SINCE_VERSION &&
+      window->edge_constraints[3] != META_EDGE_CONSTRAINT_NONE)
+    {
+      s = wl_array_add (states, sizeof *s);
+      *s = GTK_SURFACE1_STATE_TILED_LEFT;
+    }
 }
 
 static void
@@ -167,8 +234,22 @@ on_configure (MetaWaylandSurface    *surface,
 {
   struct wl_array states;
 
+  /* Conditionally send the configure_edges event... */
+  if (wl_resource_get_version (gtk_surface->resource) >= GTK_SURFACE1_CONFIGURE_EDGES_SINCE_VERSION)
+    {
+      struct wl_array edge_states;
+
+      wl_array_init (&edge_states);
+      fill_edge_states (&edge_states, surface->window);
+
+      gtk_surface1_send_configure_edges (gtk_surface->resource, &edge_states);
+
+      wl_array_release (&edge_states);
+    }
+
+  /* ... but always send the configure event */
   wl_array_init (&states);
-  fill_states (&states, surface->window);
+  fill_states (&states, surface->window, gtk_surface);
 
   gtk_surface1_send_configure (gtk_surface->resource, &states);
 
diff --git a/src/wayland/protocol/gtk-shell.xml b/src/wayland/protocol/gtk-shell.xml
index 5cfdd42..0df1095 100644
--- a/src/wayland/protocol/gtk-shell.xml
+++ b/src/wayland/protocol/gtk-shell.xml
@@ -1,6 +1,6 @@
 <protocol name="gtk">
 
-  <interface name="gtk_shell1" version="1">
+  <interface name="gtk_shell1" version="2">
     <description summary="gtk specific extensions">
       gtk_shell is a protocol extension providing additional features for
       clients implementing it.
@@ -30,7 +30,7 @@
     </request>
   </interface>
 
-  <interface name="gtk_surface1" version="1">
+  <interface name="gtk_surface1" version="2">
     <request name="set_dbus_properties">
       <arg name="application_id" type="string" allow-null="true"/>
       <arg name="app_menu_path" type="string" allow-null="true"/>
@@ -51,11 +51,27 @@
 
     <enum name="state">
       <entry name="tiled" value="1"/>
+
+      <entry name="tiled_top" since="2" value="2"/>
+      <entry name="tiled_right" since="2" value="3"/>
+      <entry name="tiled_bottom" since="2" value="4"/>
+      <entry name="tiled_left" since="2" value="5" />
+    </enum>
+
+    <enum name="edge_constraint" since="2">
+      <entry name="resizable_top" value="1"/>
+      <entry name="resizable_right" value="2"/>
+      <entry name="resizable_bottom" value="3"/>
+      <entry name="resizable_left" value="4"/>
     </enum>
 
     <event name="configure">
       <arg name="states" type="array"/>
     </event>
+
+    <event name="configure_edges" since="2">
+      <arg name="constraints" type="array"/>
+    </event>
   </interface>
 
 </protocol>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]