[gnome-flashback] root-background: initial version



commit 505f04c1482f262b3b098bbf6c84f7794253a452
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Fri Nov 22 22:41:52 2019 +0200

    root-background: initial version
    
    Disabling desktop module will disable also background handling. This
    module allows to re-enable background handling in case when user
    wants to use 3rd party application for desktop icons.

 configure.ac                                       |   6 +
 data/schemas/org.gnome.gnome-flashback.gschema.xml |   5 +
 gnome-flashback/Makefile.am                        |   2 +
 gnome-flashback/gf-application.c                   |   4 +
 gnome-flashback/libroot-background/Makefile.am     |  34 ++++
 .../libroot-background/gf-root-background.c        | 207 +++++++++++++++++++++
 .../libroot-background/gf-root-background.h        |  33 ++++
 7 files changed, 291 insertions(+)
---
diff --git a/configure.ac b/configure.ac
index ab71c41..5db5160 100644
--- a/configure.ac
+++ b/configure.ac
@@ -214,6 +214,11 @@ PKG_CHECK_MODULES([POWER_APPLET], [
   upower-glib
 ])
 
+PKG_CHECK_MODULES([ROOT_BACKGROUND], [
+  gtk+-3.0 >= $GTK_REQUIRED
+  gnome-desktop-3.0 >= $LIBGNOME_DESKTOP_REQUIRED
+])
+
 PKG_CHECK_MODULES([SCREENCAST], [
   gdk-pixbuf-2.0 >= $GDK_PIXBUF_REQUIRED
   gio-unix-2.0 >= $GLIB_REQUIRED
@@ -364,6 +369,7 @@ AC_CONFIG_FILES([
   gnome-flashback/libnotifications/Makefile
   gnome-flashback/libpolkit/Makefile
   gnome-flashback/libpower-applet/Makefile
+  gnome-flashback/libroot-background/Makefile
   gnome-flashback/libscreencast/Makefile
   gnome-flashback/libscreensaver/Makefile
   gnome-flashback/libscreenshot/Makefile
diff --git a/data/schemas/org.gnome.gnome-flashback.gschema.xml 
b/data/schemas/org.gnome.gnome-flashback.gschema.xml
index 3efd816..51c7f17 100644
--- a/data/schemas/org.gnome.gnome-flashback.gschema.xml
+++ b/data/schemas/org.gnome.gnome-flashback.gschema.xml
@@ -74,6 +74,11 @@
       <description>If set to true, then GNOME Flashback application will be used to show a power 
applet.</description>
     </key>
 
+    <key name="root-background" type="b">
+      <default>false</default>
+      <summary>Root background</summary>
+    </key>
+
     <key name="screencast" type="b">
       <default>true</default>
       <summary>Screencasts</summary>
diff --git a/gnome-flashback/Makefile.am b/gnome-flashback/Makefile.am
index f7b1f64..f6e142c 100644
--- a/gnome-flashback/Makefile.am
+++ b/gnome-flashback/Makefile.am
@@ -15,6 +15,7 @@ SUBDIRS = \
        libnotifications \
        libpolkit \
        libpower-applet \
+       libroot-background \
        libscreencast \
        libscreensaver \
        libscreenshot \
@@ -74,6 +75,7 @@ gnome_flashback_LDADD = \
        $(top_builddir)/gnome-flashback/libnotifications/libnotifications.la \
        $(top_builddir)/gnome-flashback/libpolkit/libpolkit.la \
        $(top_builddir)/gnome-flashback/libpower-applet/libpower-applet.la \
+       $(top_builddir)/gnome-flashback/libroot-background/libroot-background.la \
        $(top_builddir)/gnome-flashback/libscreencast/libscreencast.la \
        $(top_builddir)/gnome-flashback/libscreensaver/libscreensaver.la \
        $(top_builddir)/gnome-flashback/libscreenshot/libscreenshot.la \
diff --git a/gnome-flashback/gf-application.c b/gnome-flashback/gf-application.c
index ebbd71f..adce520 100644
--- a/gnome-flashback/gf-application.c
+++ b/gnome-flashback/gf-application.c
@@ -36,6 +36,7 @@
 #include "libnotifications/gf-notifications.h"
 #include "libpolkit/flashback-polkit.h"
 #include "libpower-applet/gf-power-applet.h"
+#include "libroot-background/gf-root-background.h"
 #include "libscreencast/gf-screencast.h"
 #include "libscreensaver/gf-screensaver.h"
 #include "libscreenshot/gf-screenshot.h"
@@ -69,6 +70,7 @@ struct _GfApplication
   GfInputSources          *input_sources;
   GfNotifications         *notifications;
   GfPowerApplet           *power;
+  GfRootBackground        *root_background;
   GfScreencast            *screencast;
   GfScreensaver           *screensaver;
   GfScreenshot            *screenshot;
@@ -169,6 +171,7 @@ settings_changed (GSettings   *settings,
   SETTING_CHANGED (input_sources, "input-sources", gf_input_sources_new)
   SETTING_CHANGED (notifications, "notifications", gf_notifications_new)
   SETTING_CHANGED (power, "power-applet", gf_power_applet_new)
+  SETTING_CHANGED (root_background, "root-background", gf_root_background_new)
   SETTING_CHANGED (screencast, "screencast", gf_screencast_new)
   SETTING_CHANGED (screensaver, "screensaver", gf_screensaver_new)
   SETTING_CHANGED (screenshot, "screenshot", gf_screenshot_new)
@@ -216,6 +219,7 @@ gf_application_dispose (GObject *object)
   g_clear_object (&application->input_sources);
   g_clear_object (&application->notifications);
   g_clear_object (&application->power);
+  g_clear_object (&application->root_background);
   g_clear_object (&application->screencast);
   g_clear_object (&application->screenshot);
   g_clear_object (&application->screensaver);
diff --git a/gnome-flashback/libroot-background/Makefile.am b/gnome-flashback/libroot-background/Makefile.am
new file mode 100644
index 0000000..cffe29b
--- /dev/null
+++ b/gnome-flashback/libroot-background/Makefile.am
@@ -0,0 +1,34 @@
+NULL =
+
+noinst_LTLIBRARIES = \
+       libroot-background.la \
+       $(NULL)
+
+libroot_background_la_CPPFLAGS = \
+       -DG_LOG_DOMAIN=\"root-background\" \
+       -DG_LOG_USE_STRUCTURED=1 \
+       $(NULL)
+
+libroot_background_la_CFLAGS = \
+       $(ROOT_BACKGROUND_CFLAGS) \
+       $(WARN_CFLAGS) \
+       $(AM_CFLAGS) \
+       -I$(top_builddir)/gnome-flashback/libroot-background \
+       -DGNOME_DESKTOP_USE_UNSTABLE_API \
+       $(NULL)
+
+libroot_background_la_SOURCES = \
+       gf-root-background.c \
+       gf-root-background.h \
+       $(NULL)
+
+libroot_background_la_LDFLAGS = \
+       $(WARN_LDFLAGS) \
+       $(AM_LDFLAGS) \
+       $(NULL)
+
+libroot_background_la_LIBADD = \
+       $(DROOT_BACKGROUND_LIBS) \
+       $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/gnome-flashback/libroot-background/gf-root-background.c 
b/gnome-flashback/libroot-background/gf-root-background.c
new file mode 100644
index 0000000..6504a49
--- /dev/null
+++ b/gnome-flashback/libroot-background/gf-root-background.c
@@ -0,0 +1,207 @@
+/*
+ * Copyright (C) 2019 Alberts Muktupāvels
+ *
+ * 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/>.
+ */
+
+#include "config.h"
+#include "gf-root-background.h"
+
+#include <gtk/gtk.h>
+#include <libgnome-desktop/gnome-bg.h>
+
+struct _GfRootBackground
+{
+  GObject    parent;
+
+  gulong     monitors_changed_id;
+  gulong     size_changed_id;
+  gulong     change_event_id;
+
+  guint      change_idle_id;
+
+  GnomeBG   *bg;
+
+  GSettings *settings;
+};
+
+G_DEFINE_TYPE (GfRootBackground, gf_root_background, G_TYPE_OBJECT)
+
+static void
+set_background (GfRootBackground *self)
+{
+  GdkScreen *screen;
+  GdkWindow *root;
+  gint width;
+  gint height;
+  cairo_surface_t *surface;
+
+  screen = gdk_screen_get_default ();
+  root = gdk_screen_get_root_window (screen);
+  width = gdk_window_get_width (root);
+  height = gdk_window_get_height (root);
+
+  surface = gnome_bg_create_surface (self->bg, root, width, height, TRUE);
+
+  gnome_bg_set_surface_as_root (screen, surface);
+  cairo_surface_destroy (surface);
+}
+
+static gboolean
+change_event_cb (GSettings        *settings,
+                 gpointer          keys,
+                 gint              n_keys,
+                 GfRootBackground *self)
+{
+  gnome_bg_load_from_preferences (self->bg, self->settings);
+
+  return TRUE;
+}
+
+static void
+changed_cb (GnomeBG          *bg,
+            GfRootBackground *self)
+{
+  set_background (self);
+}
+
+static void
+transitioned_cb (GnomeBG          *bg,
+                 GfRootBackground *self)
+{
+  set_background (self);
+}
+
+static gboolean
+change_cb (gpointer user_data)
+{
+  GfRootBackground *self;
+
+  self = GF_ROOT_BACKGROUND (user_data);
+
+  set_background (self);
+  self->change_idle_id = 0;
+
+  return G_SOURCE_REMOVE;
+}
+
+static void
+queue_change (GfRootBackground *self)
+{
+  if (self->change_idle_id != 0)
+    return;
+
+  self->change_idle_id = g_idle_add (change_cb, self);
+}
+
+static void
+monitors_changed_cb (GdkScreen        *screen,
+                     GfRootBackground *self)
+{
+  queue_change (self);
+}
+
+static void
+size_changed_cb (GdkScreen        *screen,
+                 GfRootBackground *self)
+{
+  queue_change (self);
+}
+
+static void
+gf_root_background_dispose (GObject *object)
+{
+  GfRootBackground *self;
+  GdkScreen *screen;
+
+  self = GF_ROOT_BACKGROUND (object);
+  screen = gdk_screen_get_default ();
+
+  if (self->monitors_changed_id != 0)
+    {
+      g_signal_handler_disconnect (screen, self->monitors_changed_id);
+      self->monitors_changed_id = 0;
+    }
+
+  if (self->size_changed_id != 0)
+    {
+      g_signal_handler_disconnect (screen, self->size_changed_id);
+      self->size_changed_id = 0;
+    }
+
+  if (self->change_event_id != 0)
+    {
+      g_signal_handler_disconnect (self->settings, self->change_event_id);
+      self->change_event_id = 0;
+    }
+
+  if (self->change_idle_id != 0)
+    {
+      g_source_remove (self->change_idle_id);
+      self->change_idle_id = 0;
+    }
+
+  g_clear_object (&self->bg);
+  g_clear_object (&self->settings);
+
+  G_OBJECT_CLASS (gf_root_background_parent_class)->dispose (object);
+}
+
+static void
+gf_root_background_class_init (GfRootBackgroundClass *self_class)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (self_class);
+
+  object_class->dispose = gf_root_background_dispose;
+}
+
+static void
+gf_root_background_init (GfRootBackground *self)
+{
+  GdkScreen *screen;
+
+  screen = gdk_screen_get_default ();
+
+  self->monitors_changed_id =
+    g_signal_connect (screen, "monitors-changed",
+                      G_CALLBACK (monitors_changed_cb), self);
+
+  self->size_changed_id =
+    g_signal_connect (screen, "size-changed",
+                      G_CALLBACK (size_changed_cb), self);
+
+  self->bg = gnome_bg_new ();
+
+  g_signal_connect (self->bg, "changed",
+                    G_CALLBACK (changed_cb), self);
+
+  g_signal_connect (self->bg, "transitioned",
+                    G_CALLBACK (transitioned_cb), self);
+
+  self->settings = g_settings_new ("org.gnome.desktop.background");
+
+  self->change_event_id =
+    g_signal_connect (self->settings, "change-event",
+                      G_CALLBACK (change_event_cb), self);
+
+  gnome_bg_load_from_preferences (self->bg, self->settings);
+}
+
+GfRootBackground *
+gf_root_background_new (void)
+{
+  return g_object_new (GF_TYPE_ROOT_BACKGROUND, NULL);
+}
diff --git a/gnome-flashback/libroot-background/gf-root-background.h 
b/gnome-flashback/libroot-background/gf-root-background.h
new file mode 100644
index 0000000..451739f
--- /dev/null
+++ b/gnome-flashback/libroot-background/gf-root-background.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2019 Alberts Muktupāvels
+ *
+ * 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/>.
+ */
+
+#ifndef GF_ROOT_BACKGROUND_H
+#define GF_ROOT_BACKGROUND_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GF_TYPE_ROOT_BACKGROUND (gf_root_background_get_type ())
+G_DECLARE_FINAL_TYPE (GfRootBackground, gf_root_background,
+                      GF, ROOT_BACKGROUND, GObject)
+
+GfRootBackground *gf_root_background_new (void);
+
+G_END_DECLS
+
+#endif


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