[gnome-flashback] backends: add GfSettings
- From: Alberts MuktupÄvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] backends: add GfSettings
- Date: Sat, 9 Sep 2017 22:18:16 +0000 (UTC)
commit b3027e16c7937d5ffc5432f7ec364fc6196571f5
Author: Alberts MuktupÄvels <alberts muktupavels gmail com>
Date: Sat Sep 9 21:34:23 2017 +0300
backends: add GfSettings
backends/Makefile.am | 2 +
backends/gf-backend.c | 34 ++++++
backends/gf-settings-private.h | 40 +++++++
backends/gf-settings.c | 220 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 296 insertions(+), 0 deletions(-)
---
diff --git a/backends/Makefile.am b/backends/Makefile.am
index 9f65c15..01801ee 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -29,6 +29,8 @@ libbackends_la_SOURCES = \
gf-backend-x11.c \
gf-backend.c \
gf-backend.h \
+ gf-settings-private.h \
+ gf-settings.c \
$(BUILT_SOURCES) \
$(NULL)
diff --git a/backends/gf-backend.c b/backends/gf-backend.c
index 9e6d5b3..a4ba4eb 100644
--- a/backends/gf-backend.c
+++ b/backends/gf-backend.c
@@ -30,11 +30,18 @@
#include "gf-backend-native-private.h"
#include "gf-backend-x11-cm-private.h"
#include "gf-backend-x11-nested-private.h"
+#include "gf-settings-private.h"
+
+typedef struct
+{
+ GfSettings *settings;
+} GfBackendPrivate;
static void
initable_iface_init (GInitableIface *initable_iface);
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GfBackend, gf_backend, G_TYPE_OBJECT,
+ G_ADD_PRIVATE (GfBackend)
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
initable_iface_init))
@@ -43,6 +50,14 @@ gf_backend_initable_init (GInitable *initable,
GCancellable *cancellable,
GError **error)
{
+ GfBackend *backend;
+ GfBackendPrivate *priv;
+
+ backend = GF_BACKEND (initable);
+ priv = gf_backend_get_instance_private (backend);
+
+ priv->settings = gf_settings_new (backend);
+
return TRUE;
}
@@ -53,8 +68,27 @@ initable_iface_init (GInitableIface *initable_iface)
}
static void
+gf_backend_dispose (GObject *object)
+{
+ GfBackend *backend;
+ GfBackendPrivate *priv;
+
+ backend = GF_BACKEND (object);
+ priv = gf_backend_get_instance_private (backend);
+
+ g_clear_object (&priv->settings);
+
+ G_OBJECT_CLASS (gf_backend_parent_class)->dispose (object);
+}
+
+static void
gf_backend_class_init (GfBackendClass *backend_class)
{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (backend_class);
+
+ object_class->dispose = gf_backend_dispose;
}
static void
diff --git a/backends/gf-settings-private.h b/backends/gf-settings-private.h
new file mode 100644
index 0000000..97fa87a
--- /dev/null
+++ b/backends/gf-settings-private.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 Alberts MuktupÄvels
+ * Copyright (C) 2017 Red Hat
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Adapted from mutter:
+ * - src/backends/meta-settings-private.h
+ * - src/meta/meta-settings.h
+ */
+
+#ifndef GF_SETTINGS_PRIVATE_H
+#define GF_SETTINGS_PRIVATE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GF_TYPE_SETTINGS (gf_settings_get_type ())
+G_DECLARE_FINAL_TYPE (GfSettings, gf_settings, GF, SETTINGS, GObject)
+
+GfSettings *gf_settings_new (GfBackend *backend);
+
+gboolean gf_settings_get_global_scaling_factor (GfSettings *settings,
+ gint *global_scaling_factor);
+
+G_END_DECLS
+
+#endif
diff --git a/backends/gf-settings.c b/backends/gf-settings.c
new file mode 100644
index 0000000..9fbaf85
--- /dev/null
+++ b/backends/gf-settings.c
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2017 Alberts MuktupÄvels
+ * Copyright (C) 2017 Red Hat
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Adapted from mutter:
+ * - src/backends/meta-settings.c
+ */
+
+#include "config.h"
+
+#include <gio/gio.h>
+
+#include "gf-backend-private.h"
+#include "gf-settings-private.h"
+
+struct _GfSettings
+{
+ GObject parent;
+
+ GfBackend *backend;
+
+ GSettings *interface;
+
+ gint global_scaling_factor;
+};
+
+enum
+{
+ PROP_0,
+
+ PROP_BACKEND,
+
+ LAST_PROP
+};
+
+static GParamSpec *settings_properties[LAST_PROP] = { NULL };
+
+enum
+{
+ GLOBAL_SCALING_FACTOR_CHANGED,
+
+ LAST_SIGNAL
+};
+
+static guint settings_signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (GfSettings, gf_settings, G_TYPE_OBJECT)
+
+static gboolean
+update_global_scaling_factor (GfSettings *settings)
+{
+ gint scale;
+
+ scale = (gint) g_settings_get_uint (settings->interface, "scaling-factor");
+
+ if (settings->global_scaling_factor != scale)
+ {
+ settings->global_scaling_factor = scale;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+interface_changed_cb (GSettings *interface,
+ const gchar *key,
+ GfSettings *settings)
+{
+ if (g_str_equal (key, "scaling-factor"))
+ {
+ if (update_global_scaling_factor (settings))
+ g_signal_emit (settings, settings_signals[GLOBAL_SCALING_FACTOR_CHANGED], 0);
+ }
+}
+
+static void
+gf_settings_dispose (GObject *object)
+{
+ GfSettings *settings;
+
+ settings = GF_SETTINGS (object);
+
+ g_clear_object (&settings->interface);
+ settings->backend = NULL;
+
+ G_OBJECT_CLASS (gf_settings_parent_class)->dispose (object);
+}
+
+static void
+gf_settings_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GfSettings *settings;
+
+ settings = GF_SETTINGS (object);
+
+ switch (property_id)
+ {
+ case PROP_BACKEND:
+ g_value_set_object (value, settings->backend);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gf_settings_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GfSettings *settings;
+
+ settings = GF_SETTINGS (object);
+
+ switch (property_id)
+ {
+ case PROP_BACKEND:
+ settings->backend = g_value_get_object (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gf_settings_install_properties (GObjectClass *object_class)
+{
+ settings_properties[PROP_BACKEND] =
+ g_param_spec_object ("backend",
+ "GfBackend",
+ "GfBackend",
+ GF_TYPE_BACKEND,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, LAST_PROP,
+ settings_properties);
+}
+
+static void
+gf_settings_install_signals (GObjectClass *object_class)
+{
+ settings_signals[GLOBAL_SCALING_FACTOR_CHANGED] =
+ g_signal_new ("global-scaling-factor-changed",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
+}
+
+static void
+gf_settings_class_init (GfSettingsClass *settings_class)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (settings_class);
+
+ object_class->dispose = gf_settings_dispose;
+ object_class->get_property = gf_settings_get_property;
+ object_class->set_property = gf_settings_set_property;
+
+ gf_settings_install_properties (object_class);
+ gf_settings_install_signals (object_class);
+}
+
+static void
+gf_settings_init (GfSettings *settings)
+{
+ settings->interface = g_settings_new ("org.gnome.desktop.interface");
+
+ g_signal_connect (settings->interface, "changed",
+ G_CALLBACK (interface_changed_cb), settings);
+
+ update_global_scaling_factor (settings);
+}
+
+GfSettings *
+gf_settings_new (GfBackend *backend)
+{
+ GfSettings *settings;
+
+ settings = g_object_new (GF_TYPE_SETTINGS,
+ "backend", backend,
+ NULL);
+
+ return settings;
+}
+
+gboolean
+gf_settings_get_global_scaling_factor (GfSettings *settings,
+ gint *global_scaling_factor)
+{
+ if (settings->global_scaling_factor == 0)
+ return FALSE;
+
+ *global_scaling_factor = settings->global_scaling_factor;
+
+ return TRUE;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]