[gtk+/wip/gbsneto/edge-constraints: 214/216] wayland: consider edge constraints in surface configuration



commit 3bae80dfc120287dff4202589db06d92ea50bc38
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Aug 17 00:35:52 2017 -0300

    wayland: consider edge constraints in surface configuration
    
    Now that GTK windows have the ability to properly handle
    per-edge tiling constraints, this patch extends GTK's
    internal Wayland protocol to have a proper enum with the
    relevant edge data.
    
    Once this approach is validated, we can think of upstreaming
    this work as an official Wayland protocol extension.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=783669

 gdk/wayland/gdkdisplay-wayland.c   |    4 ++-
 gdk/wayland/gdkwindow-wayland.c    |   54 +++++++++++++++++++++++++++++++++++-
 gdk/wayland/protocol/gtk-shell.xml |   20 ++++++++++++-
 3 files changed, 74 insertions(+), 4 deletions(-)
---
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index 380611c..3814157 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -82,6 +82,8 @@
 
 #define MIN_SYSTEM_BELL_DELAY_MS 20
 
+#define GTK_SHELL1_VERSION       2
+
 static void _gdk_wayland_display_load_cursor_theme (GdkWaylandDisplay *display_wayland);
 
 G_DEFINE_TYPE (GdkWaylandDisplay, gdk_wayland_display, GDK_TYPE_DISPLAY)
@@ -371,7 +373,7 @@ gdk_registry_handle_global (void               *data,
       display_wayland->gtk_shell =
         wl_registry_bind(display_wayland->wl_registry, id,
                          &gtk_shell1_interface,
-                         1);
+                         MIN (version, GTK_SHELL1_VERSION));
       _gdk_wayland_screen_set_has_gtk_shell (display_wayland->screen);
       display_wayland->gtk_shell_version = version;
     }
diff --git a/gdk/wayland/gdkwindow-wayland.c b/gdk/wayland/gdkwindow-wayland.c
index e25c782..77a6e97 100644
--- a/gdk/wayland/gdkwindow-wayland.c
+++ b/gdk/wayland/gdkwindow-wayland.c
@@ -2961,6 +2961,57 @@ gtk_surface_configure (void                *data,
         case GTK_SURFACE1_STATE_TILED:
           new_state |= GDK_WINDOW_STATE_TILED;
           break;
+
+        /* Since v2 */
+        case GTK_SURFACE1_STATE_TILED_TOP:
+          new_state |= GDK_WINDOW_STATE_TOP_TILED;
+          break;
+        case GTK_SURFACE1_STATE_TILED_RIGHT:
+          new_state |= GDK_WINDOW_STATE_RIGHT_TILED;
+          break;
+        case GTK_SURFACE1_STATE_TILED_BOTTOM:
+          new_state |= GDK_WINDOW_STATE_BOTTOM_TILED;
+          break;
+        case GTK_SURFACE1_STATE_TILED_LEFT:
+          new_state |= GDK_WINDOW_STATE_LEFT_TILED;
+          break;
+        default:
+          /* Unknown state */
+          break;
+        }
+    }
+
+  impl->pending.state |= new_state;
+}
+
+static void
+gtk_surface_configure_edges (void                *data,
+                             struct gtk_surface1 *gtk_surface,
+                             struct wl_array     *edge_constraints)
+{
+  GdkWindow *window = GDK_WINDOW (data);
+  GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
+  GdkWindowState new_state = 0;
+  uint32_t *p;
+
+  wl_array_for_each (p, edge_constraints)
+    {
+      uint32_t constraint = *p;
+
+      switch (constraint)
+        {
+        case GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_TOP:
+          new_state |= GDK_WINDOW_STATE_TOP_RESIZABLE;
+          break;
+        case GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_RIGHT:
+          new_state |= GDK_WINDOW_STATE_TOP_TILED;
+          break;
+        case GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_BOTTOM:
+          new_state |= GDK_WINDOW_STATE_BOTTOM_RESIZABLE;
+          break;
+        case GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_LEFT:
+          new_state |= GDK_WINDOW_STATE_LEFT_RESIZABLE;
+          break;
         default:
           /* Unknown state */
           break;
@@ -2971,7 +3022,8 @@ gtk_surface_configure (void                *data,
 }
 
 static const struct gtk_surface1_listener gtk_surface_listener = {
-  gtk_surface_configure
+  gtk_surface_configure,
+  gtk_surface_configure_edges
 };
 
 static void
diff --git a/gdk/wayland/protocol/gtk-shell.xml b/gdk/wayland/protocol/gtk-shell.xml
index 5cfdd42..8191fa9 100644
--- a/gdk/wayland/protocol/gtk-shell.xml
+++ b/gdk/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]