[libadwaita/wip/exalm/dark: 2/7] application: Add style-manager property
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/dark: 2/7] application: Add style-manager property
- Date: Wed, 22 Sep 2021 15:32:41 +0000 (UTC)
commit 30fc24b585734123d2755c653f58d3d0daef8c49
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 | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/adw-application.h | 5 ++++
2 files changed, 69 insertions(+)
---
diff --git a/src/adw-application.c b/src/adw-application.c
index 4459dda3..c039faad 100644
--- a/src/adw-application.c
+++ b/src/adw-application.c
@@ -52,6 +52,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 +194,24 @@ 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)
+{
+ AdwApplication *self = ADW_APPLICATION (object);
+
+ switch (prop_id) {
+ case PROP_STYLE_MANAGER:
+ g_value_set_object (value, adw_application_get_style_manager (self));
+ 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_application_get_style_manager)
+ *
+ * The style manager for this application.
+ *
+ * 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
@@ -228,3 +274,21 @@ adw_application_new (const char *application_id,
"flags", flags,
NULL);
}
+
+/**
+ * adw_application_get_style_manager: (attributes org.gtk.Method.get_property=style-manager)
+ * @self: a `AdwApplication`
+ *
+ * Gets the style manager for @self.
+ *
+ * Returns: (transfer none): the style manager
+ *
+ * Since: 1.0
+ */
+AdwStyleManager *
+adw_application_get_style_manager (AdwApplication *self)
+{
+ g_return_val_if_fail (ADW_IS_APPLICATION (self), NULL);
+
+ return adw_style_manager_get_default ();
+}
diff --git a/src/adw-application.h b/src/adw-application.h
index 2c5d73de..28e5a3a4 100644
--- a/src/adw-application.h
+++ b/src/adw-application.h
@@ -14,6 +14,8 @@
#include <gtk/gtk.h>
+#include "adw-style-manager.h"
+
G_BEGIN_DECLS
#define ADW_TYPE_APPLICATION (adw_application_get_type())
@@ -37,4 +39,7 @@ ADW_AVAILABLE_IN_ALL
AdwApplication *adw_application_new (const char *application_id,
GApplicationFlags flags) G_GNUC_WARN_UNUSED_RESULT;
+ADW_AVAILABLE_IN_ALL
+AdwStyleManager *adw_application_get_style_manager (AdwApplication *self);
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]