[mutter/wip/fmuellner/contraint-tiling: 9/10] wayland: Send edge constraints



commit 02e28fa1f0e1211eb7b027f26444e8efc09036e4
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 |  102 ++++++++++++++++++++++++++++++++--
 src/wayland/protocol/gtk-shell.xml   |   20 ++++++-
 2 files changed, 115 insertions(+), 7 deletions(-)
---
diff --git a/src/wayland/meta-wayland-gtk-shell.c b/src/wayland/meta-wayland-gtk-shell.c
index d6e249f..32ad2ca 100644
--- a/src/wayland/meta-wayland-gtk-shell.c
+++ b/src/wayland/meta-wayland-gtk-shell.c
@@ -148,27 +148,108 @@ 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
+send_configure_edges (MetaWaylandGtkSurface *gtk_surface,
+                      MetaWindow            *window)
+{
+  struct wl_array edge_states;
+
+  wl_array_init (&edge_states);
+  fill_edge_states (&edge_states, window);
+
+  gtk_surface1_send_configure_edges (gtk_surface->resource, &edge_states);
+
+  wl_array_release (&edge_states);
+}
+
+static void
+fill_states (struct wl_array    *states,
+             MetaWindow         *window,
+             struct wl_resource *resource)
+{
+  uint32_t *s;
+  guint version;
+
+  version = wl_resource_get_version (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 (version >= 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 (version >= 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 (version >= 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 (version >= 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
-on_configure (MetaWaylandSurface    *surface,
-              MetaWaylandGtkSurface *gtk_surface)
+send_configure (MetaWaylandGtkSurface *gtk_surface,
+                MetaWindow            *window)
 {
   struct wl_array states;
 
   wl_array_init (&states);
-  fill_states (&states, surface->window);
+  fill_states (&states, window, gtk_surface->resource);
 
   gtk_surface1_send_configure (gtk_surface->resource, &states);
 
@@ -176,6 +257,17 @@ on_configure (MetaWaylandSurface    *surface,
 }
 
 static void
+on_configure (MetaWaylandSurface    *surface,
+              MetaWaylandGtkSurface *gtk_surface)
+{
+
+  if (wl_resource_get_version (gtk_surface->resource) >= GTK_SURFACE1_CONFIGURE_EDGES_SINCE_VERSION)
+    send_configure_edges (gtk_surface, surface->window);
+
+  send_configure (gtk_surface, surface->window);
+}
+
+static void
 gtk_shell_get_gtk_surface (struct wl_client   *client,
                            struct wl_resource *resource,
                            guint32             id,
diff --git a/src/wayland/protocol/gtk-shell.xml b/src/wayland/protocol/gtk-shell.xml
index 5cfdd42..8191fa9 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" value="2" since="2" />
+      <entry name="tiled_right" value="3" since="2" />
+      <entry name="tiled_bottom" value="4" since="2" />
+      <entry name="tiled_left" value="5"  since="2" />
+    </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]