[gtk/present-toplevel-2: 28/59] Add toplevel properties for sticky, above and below



commit f4940aeb83038f97a08149a9db8f187ce3e3076f
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Mar 3 02:24:20 2020 -0800

    Add toplevel properties for sticky, above and below

 gdk/gdksurface.c         | 40 ++++++++++++++++++++++++++++
 gdk/gdktoplevel.c        | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
 gdk/gdktoplevel.h        | 10 +++++++
 gdk/gdktoplevelprivate.h |  3 +++
 4 files changed, 122 insertions(+)
---
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index cf26304743..6008f4033e 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -661,12 +661,34 @@ gdk_surface_set_property (GObject      *object,
       g_object_notify_by_pspec (G_OBJECT (surface), pspec);
       break;
 
+    case LAST_PROP + GDK_POPUP_NUM_PROPERTIES + GDK_TOPLEVEL_PROP_STICKY:
+      if (g_value_get_boolean (value))
+        GDK_SURFACE_GET_CLASS (surface)->stick (surface);
+      else
+        GDK_SURFACE_GET_CLASS (surface)->unstick (surface);
+      g_object_notify_by_pspec (G_OBJECT (surface), pspec);
+      break;
+
+    case LAST_PROP + GDK_POPUP_NUM_PROPERTIES + GDK_TOPLEVEL_PROP_KEEP_ABOVE:
+      GDK_SURFACE_GET_CLASS (surface)->set_keep_above (surface, g_value_get_boolean (value));
+      g_object_notify_by_pspec (G_OBJECT (surface), pspec);
+      break;
+
+    case LAST_PROP + GDK_POPUP_NUM_PROPERTIES + GDK_TOPLEVEL_PROP_KEEP_BELOW:
+      GDK_SURFACE_GET_CLASS (surface)->set_keep_below (surface, g_value_get_boolean (value));
+      g_object_notify_by_pspec (G_OBJECT (surface), pspec);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
     }
 }
 
+#define GDK_SURFACE_IS_STICKY(surface) (((surface)->state & GDK_SURFACE_STATE_STICKY))
+#define GDK_SURFACE_IS_ABOVE(surface) (((surface)->state & GDK_SURFACE_STATE_ABOVE))
+#define GDK_SURFACE_IS_BELOW(surface) (((surface)->state & GDK_SURFACE_STATE_BELOW))
+
 static void
 gdk_surface_get_property (GObject    *object,
                           guint       prop_id,
@@ -725,6 +747,18 @@ gdk_surface_get_property (GObject    *object,
       g_value_set_pointer (value, NULL); // FIXME
       break;
 
+    case LAST_PROP + GDK_POPUP_NUM_PROPERTIES + GDK_TOPLEVEL_PROP_STICKY:
+      g_value_set_boolean (value, GDK_SURFACE_IS_STICKY (surface));
+      break;
+
+    case LAST_PROP + GDK_POPUP_NUM_PROPERTIES + GDK_TOPLEVEL_PROP_KEEP_ABOVE:
+      g_value_set_boolean (value, GDK_SURFACE_IS_ABOVE (surface));
+      break;
+
+    case LAST_PROP + GDK_POPUP_NUM_PROPERTIES + GDK_TOPLEVEL_PROP_KEEP_BELOW:
+      g_value_set_boolean (value, GDK_SURFACE_IS_BELOW (surface));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -3395,6 +3429,7 @@ gdk_surface_set_state (GdkSurface      *surface,
                        GdkSurfaceState  new_state)
 {
   gboolean was_mapped, mapped;
+  gboolean was_sticky, sticky;
   g_return_if_fail (GDK_IS_SURFACE (surface));
 
   if (new_state == surface->state)
@@ -3406,10 +3441,12 @@ gdk_surface_set_state (GdkSurface      *surface,
    */
 
   was_mapped = GDK_SURFACE_IS_MAPPED (surface);
+  was_sticky = GDK_SURFACE_IS_STICKY (surface);
 
   surface->state = new_state;
 
   mapped = GDK_SURFACE_IS_MAPPED (surface);
+  sticky = GDK_SURFACE_IS_STICKY (surface);
 
   _gdk_surface_update_viewable (surface);
 
@@ -3417,6 +3454,9 @@ gdk_surface_set_state (GdkSurface      *surface,
 
   if (was_mapped != mapped)
     g_object_notify_by_pspec (G_OBJECT (surface), properties[PROP_MAPPED]);
+
+  if (was_sticky != sticky)
+    g_object_notify (G_OBJECT (surface), "sticky");
 }
 
 void
diff --git a/gdk/gdktoplevel.c b/gdk/gdktoplevel.c
index f859e88284..3417e4bba5 100644
--- a/gdk/gdktoplevel.c
+++ b/gdk/gdktoplevel.c
@@ -88,6 +88,24 @@ gdk_toplevel_default_init (GdkToplevelInterface *iface)
                             "Icon List",
                             "The list of icon textures",
                             G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY));
+  g_object_interface_install_property (iface,
+      g_param_spec_boolean ("sticky",
+                            "Sticky",
+                            "Whether the surface is on all workspaces",
+                            FALSE,
+                            G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY));
+  g_object_interface_install_property (iface,
+      g_param_spec_boolean ("keep-above",
+                            "Keep above",
+                            "Whether the surface is on above all other surfaces",
+                            FALSE,
+                            G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY));
+  g_object_interface_install_property (iface,
+      g_param_spec_boolean ("keep-below",
+                            "Keep below",
+                            "Whether the surface is below all other surfaces",
+                            FALSE,
+                            G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY));
 }
 
 guint
@@ -99,6 +117,9 @@ gdk_toplevel_install_properties (GObjectClass *object_class,
   g_object_class_override_property (object_class, first_prop + GDK_TOPLEVEL_PROP_STARTUP_ID, "startup-id");
   g_object_class_override_property (object_class, first_prop + GDK_TOPLEVEL_PROP_TRANSIENT_FOR, 
"transient-for");
   g_object_class_override_property (object_class, first_prop + GDK_TOPLEVEL_PROP_ICON_LIST, "icon-list");
+  g_object_class_override_property (object_class, first_prop + GDK_TOPLEVEL_PROP_STICKY, "sticky");
+  g_object_class_override_property (object_class, first_prop + GDK_TOPLEVEL_PROP_KEEP_ABOVE, "keep-above");
+  g_object_class_override_property (object_class, first_prop + GDK_TOPLEVEL_PROP_KEEP_BELOW, "keep-below");
 
   return GDK_TOPLEVEL_NUM_PROPERTIES;
 }
@@ -257,3 +278,51 @@ gdk_toplevel_show_window_menu (GdkToplevel *toplevel,
 
   return GDK_TOPLEVEL_GET_IFACE (toplevel)->show_window_menu (toplevel, event); 
 }
+
+/**
+ * gdk_toplevel_set_sticky:
+ * @toplevel: a #GdkToplevel
+ * @sticky: whether to make @toplevel show on all workspaces
+ *
+ * Set if @surface is sticky.
+ **/
+void
+gdk_toplevel_set_sticky (GdkToplevel *toplevel,
+                         gboolean     sticky)
+{
+  g_return_if_fail (GDK_IS_TOPLEVEL (toplevel));
+
+  g_object_set (toplevel, "sticky", sticky, NULL);
+}
+
+/**
+ * gdk_toplevel_set_keep_above:
+ * @toplevel: a #GdkToplevel
+ * @above: whether to keep @toplevel above other surfaces
+ *
+ * Set if @surface must be kept above other surfaces.
+ **/
+void
+gdk_toplevel_set_keep_above (GdkToplevel *toplevel,
+                             gboolean     above)
+{
+  g_return_if_fail (GDK_IS_TOPLEVEL (toplevel));
+
+  g_object_set (toplevel, "keep-above", above, NULL);
+}
+
+/**
+ * gdk_toplevel_set_keep_below:
+ * @toplevel: a #GdkToplevel
+ * @above: whether to keep @toplevel below other surfaces
+ *
+ * Set if @surface must be kept below other surfaces.
+ **/
+void
+gdk_toplevel_set_keep_below (GdkToplevel *toplevel,
+                             gboolean     below)
+{
+  g_return_if_fail (GDK_IS_TOPLEVEL (toplevel));
+
+  g_object_set (toplevel, "keep-below", below, NULL);
+}
diff --git a/gdk/gdktoplevel.h b/gdk/gdktoplevel.h
index 7ce4cb4cb5..9643947fe6 100644
--- a/gdk/gdktoplevel.h
+++ b/gdk/gdktoplevel.h
@@ -63,6 +63,16 @@ GDK_AVAILABLE_IN_ALL
 gboolean        gdk_toplevel_show_window_menu   (GdkToplevel       *toplevel,
                                                  GdkEvent          *event);
 
+GDK_AVAILABLE_IN_ALL
+void            gdk_toplevel_set_sticky         (GdkToplevel       *toplevel,
+                                                 gboolean           sticky);
+
+GDK_AVAILABLE_IN_ALL
+void            gdk_toplevel_set_keep_above     (GdkToplevel       *toplevel,
+                                                 gboolean           above);
+GDK_AVAILABLE_IN_ALL
+void            gdk_toplevel_set_keep_below     (GdkToplevel       *toplevel,
+                                                 gboolean           below);
 
 G_END_DECLS
 
diff --git a/gdk/gdktoplevelprivate.h b/gdk/gdktoplevelprivate.h
index ddd2e53034..aee7b971cd 100644
--- a/gdk/gdktoplevelprivate.h
+++ b/gdk/gdktoplevelprivate.h
@@ -25,6 +25,9 @@ typedef enum {
   GDK_TOPLEVEL_PROP_STARTUP_ID,
   GDK_TOPLEVEL_PROP_TRANSIENT_FOR,
   GDK_TOPLEVEL_PROP_ICON_LIST,
+  GDK_TOPLEVEL_PROP_STICKY,
+  GDK_TOPLEVEL_PROP_KEEP_ABOVE,
+  GDK_TOPLEVEL_PROP_KEEP_BELOW,
   GDK_TOPLEVEL_NUM_PROPERTIES
 } GdkToplevelProperties;
 


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