[gnome-flashback] desktop: add GfBackground



commit 1525c3e9909f3bdac55c93a9c462038a0dfbf15e
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Oct 29 00:28:53 2019 +0200

    desktop: add GfBackground

 gnome-flashback/libdesktop/Makefile.am         |   2 +
 gnome-flashback/libdesktop/gf-background.c     | 102 +++++++++++++++++++++++++
 gnome-flashback/libdesktop/gf-background.h     |  32 ++++++++
 gnome-flashback/libdesktop/gf-desktop-window.c |  32 +++++++-
 4 files changed, 164 insertions(+), 4 deletions(-)
---
diff --git a/gnome-flashback/libdesktop/Makefile.am b/gnome-flashback/libdesktop/Makefile.am
index a8110f8..73041c2 100644
--- a/gnome-flashback/libdesktop/Makefile.am
+++ b/gnome-flashback/libdesktop/Makefile.am
@@ -15,6 +15,8 @@ libdesktop_la_CFLAGS = \
        $(NULL)
 
 libdesktop_la_SOURCES = \
+       gf-background.c \
+       gf-background.h \
        gf-desktop-window.c \
        gf-desktop-window.h \
        gf-desktop.c \
diff --git a/gnome-flashback/libdesktop/gf-background.c b/gnome-flashback/libdesktop/gf-background.c
new file mode 100644
index 0000000..4e19853
--- /dev/null
+++ b/gnome-flashback/libdesktop/gf-background.c
@@ -0,0 +1,102 @@
+/*
+ * 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-background.h"
+
+struct _GfBackground
+{
+  GObject    parent;
+
+  GtkWidget *window;
+};
+
+enum
+{
+  PROP_0,
+
+  PROP_WINDOW,
+
+  LAST_PROP
+};
+
+static GParamSpec *background_properties[LAST_PROP] = { NULL };
+
+G_DEFINE_TYPE (GfBackground, gf_background, G_TYPE_OBJECT)
+
+static void
+gf_background_set_property (GObject      *object,
+                            guint         property_id,
+                            const GValue *value,
+                            GParamSpec   *pspec)
+{
+  GfBackground *self;
+
+  self = GF_BACKGROUND (object);
+
+  switch (property_id)
+    {
+      case PROP_WINDOW:
+        g_assert (self->window == NULL);
+        self->window = g_value_get_object (value);
+        break;
+
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        break;
+    }
+}
+
+static void
+install_properties (GObjectClass *object_class)
+{
+  background_properties[PROP_WINDOW] =
+    g_param_spec_object ("window",
+                         "window",
+                         "window",
+                         GTK_TYPE_WIDGET,
+                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE |
+                         G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, LAST_PROP,
+                                     background_properties);
+}
+
+static void
+gf_background_class_init (GfBackgroundClass *self_class)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (self_class);
+
+  object_class->set_property = gf_background_set_property;
+
+  install_properties (object_class);
+}
+
+static void
+gf_background_init (GfBackground *self)
+{
+}
+
+GfBackground *
+gf_background_new (GtkWidget *window)
+{
+  return g_object_new (GF_TYPE_BACKGROUND,
+                       "window", window,
+                       NULL);
+}
diff --git a/gnome-flashback/libdesktop/gf-background.h b/gnome-flashback/libdesktop/gf-background.h
new file mode 100644
index 0000000..a83593c
--- /dev/null
+++ b/gnome-flashback/libdesktop/gf-background.h
@@ -0,0 +1,32 @@
+/*
+ * 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_BACKGROUND_H
+#define GF_BACKGROUND_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GF_TYPE_BACKGROUND (gf_background_get_type ())
+G_DECLARE_FINAL_TYPE (GfBackground, gf_background, GF, BACKGROUND, GObject)
+
+GfBackground *gf_background_new (GtkWidget *window);
+
+G_END_DECLS
+
+#endif
diff --git a/gnome-flashback/libdesktop/gf-desktop-window.c b/gnome-flashback/libdesktop/gf-desktop-window.c
index b1de2c9..1bd2e40 100644
--- a/gnome-flashback/libdesktop/gf-desktop-window.c
+++ b/gnome-flashback/libdesktop/gf-desktop-window.c
@@ -18,16 +18,18 @@
 #include "config.h"
 #include "gf-desktop-window.h"
 
+#include "gf-background.h"
 #include "gf-icon-view.h"
 
 struct _GfDesktopWindow
 {
-  GtkWindow  parent;
+  GtkWindow     parent;
 
-  gboolean   draw_background;
+  gboolean      draw_background;
+  GfBackground *background;
 
-  gboolean   show_icons;
-  GtkWidget *icon_view;
+  gboolean      show_icons;
+  GtkWidget    *icon_view;
 };
 
 enum
@@ -47,6 +49,15 @@ G_DEFINE_TYPE (GfDesktopWindow, gf_desktop_window, GTK_TYPE_WINDOW)
 static void
 draw_background_changed (GfDesktopWindow *self)
 {
+  if (self->draw_background)
+    {
+      g_assert (self->background == NULL);
+      self->background = gf_background_new (GTK_WIDGET (self));
+    }
+  else
+    {
+      g_clear_object (&self->background);
+    }
 }
 
 static void
@@ -108,6 +119,18 @@ gf_desktop_window_constructed (GObject *object)
     show_icons_changed (self);
 }
 
+static void
+gf_desktop_window_dispose (GObject *object)
+{
+  GfDesktopWindow *self;
+
+  self = GF_DESKTOP_WINDOW (object);
+
+  g_clear_object (&self->background);
+
+  G_OBJECT_CLASS (gf_desktop_window_parent_class)->dispose (object);
+}
+
 static void
 gf_desktop_window_set_property (GObject      *object,
                                 guint         property_id,
@@ -166,6 +189,7 @@ gf_desktop_window_class_init (GfDesktopWindowClass *self_class)
   object_class = G_OBJECT_CLASS (self_class);
 
   object_class->constructed = gf_desktop_window_constructed;
+  object_class->dispose = gf_desktop_window_dispose;
   object_class->set_property = gf_desktop_window_set_property;
 
   install_properties (object_class);


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