[libadwaita/wip/exalm/dark: 4/9] application: Add style-manager property




commit 37dfd8d8d8814e8332e26c5c0a2c5cc9caac78d7
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Thu Aug 26 14:22:13 2021 +0500

    application: Add style-manager property
    
    This is useful as a shortcut, allowing to use AdwStyleManager with property
    bindings or expressions without introducing your own property. It also
    allows to inspect AdwStyleManager in GtkInspector, and enables libraries
    like WebKit to support AdwStyleManager without a hard libadwaita
    dependency.

 src/adw-application.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
---
diff --git a/src/adw-application.c b/src/adw-application.c
index 4459dda3..ca1fea84 100644
--- a/src/adw-application.c
+++ b/src/adw-application.c
@@ -6,7 +6,9 @@
 
 #include "config.h"
 #include "adw-application.h"
+
 #include "adw-main-private.h"
+#include "adw-style-manager.h"
 
 /**
  * AdwApplication:
@@ -52,6 +54,14 @@ typedef struct
 
 G_DEFINE_TYPE_WITH_PRIVATE (AdwApplication, adw_application, GTK_TYPE_APPLICATION)
 
+enum {
+  PROP_0,
+  PROP_STYLE_MANAGER,
+  LAST_PROP,
+};
+
+static GParamSpec *props[LAST_PROP];
+
 static inline void
 style_provider_set_enabled (GtkStyleProvider *provider,
                             gboolean          enabled)
@@ -186,6 +196,22 @@ adw_application_dispose (GObject *object)
   G_OBJECT_CLASS (adw_application_parent_class)->dispose (object);
 }
 
+static void
+adw_application_get_property (GObject    *object,
+                              guint       prop_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+  switch (prop_id) {
+  case PROP_STYLE_MANAGER:
+    g_value_set_object (value, adw_style_manager_get_default ());
+    break;
+
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+  }
+}
+
 static void
 adw_application_class_init (AdwApplicationClass *klass)
 {
@@ -193,8 +219,28 @@ adw_application_class_init (AdwApplicationClass *klass)
   GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
 
   object_class->dispose = adw_application_dispose;
+  object_class->get_property = adw_application_get_property;
 
   application_class->startup = adw_application_startup;
+
+  /**
+   * AdwApplication:style-manager: (attributes org.gtk.Property.get=adw_style_manager_get_default)
+   *
+   * The default style manager.
+   *
+   * This is a convenience property allowing to access `AdwStyleManager` through
+   * property bindings or expressions.
+   *
+   * Since: 1.0
+   */
+  props[PROP_STYLE_MANAGER] =
+    g_param_spec_object ("style-manager",
+                         "Style Manager",
+                         "The default style manager",
+                         ADW_TYPE_STYLE_MANAGER,
+                         G_PARAM_READABLE);
+
+  g_object_class_install_properties (object_class, LAST_PROP, props);
 }
 
 static void


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