[gnome-flashback] common: add background utils



commit 029e079857f3edcce6e7bbaccd2873aa8cc17468
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Nov 25 01:00:21 2019 +0200

    common: add background utils

 configure.ac                                       |  1 +
 gnome-flashback/libcommon/Makefile.am              |  7 ++-
 gnome-flashback/libcommon/gf-background-utils.c    | 50 ++++++++++++++++++++++
 gnome-flashback/libcommon/gf-background-utils.h    | 38 ++++++++++++++++
 gnome-flashback/libdesktop/Makefile.am             |  5 +++
 gnome-flashback/libdesktop/gf-background.c         | 29 ++++++++-----
 gnome-flashback/libdesktop/gf-desktop-window.c     |  7 +--
 gnome-flashback/libroot-background/Makefile.am     |  7 ++-
 .../libroot-background/gf-root-background.c        | 13 ++++--
 9 files changed, 136 insertions(+), 21 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5db5160..ff80cce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,6 +147,7 @@ PKG_CHECK_MODULES([CLIPBOARD], [
 ])
 
 PKG_CHECK_MODULES([COMMON], [
+  gnome-desktop-3.0 >= $LIBGNOME_DESKTOP_REQUIRED
   gtk+-3.0 >= $GTK_REQUIRED
   x11
 ])
diff --git a/gnome-flashback/libcommon/Makefile.am b/gnome-flashback/libcommon/Makefile.am
index 0f00f8a..a75cd5a 100644
--- a/gnome-flashback/libcommon/Makefile.am
+++ b/gnome-flashback/libcommon/Makefile.am
@@ -7,17 +7,20 @@ noinst_LTLIBRARIES = \
 libcommon_la_CPPFLAGS = \
        -DG_LOG_DOMAIN=\"common\" \
        -DG_LOG_USE_STRUCTURED=1 \
+       -DGNOME_DESKTOP_USE_UNSTABLE_API \
+       -I$(top_builddir)/gnome-flashback/libcommon \
        $(NULL)
 
 libcommon_la_CFLAGS = \
        $(COMMON_CFLAGS) \
        $(WARN_CFLAGS) \
        $(AM_CFLAGS) \
-       -I$(top_builddir)/gnome-flashback/libcommon \
        $(NULL)
 
 libcommon_la_SOURCES = \
-  gf-keybindings.c \
+       gf-background-utils.c \
+       gf-background-utils.h \
+       gf-keybindings.c \
        gf-keybindings.h \
        gf-popup-window.c \
        gf-popup-window.h \
diff --git a/gnome-flashback/libcommon/gf-background-utils.c b/gnome-flashback/libcommon/gf-background-utils.c
new file mode 100644
index 0000000..fe5c0b3
--- /dev/null
+++ b/gnome-flashback/libcommon/gf-background-utils.c
@@ -0,0 +1,50 @@
+/*
+ * 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-utils.h"
+
+cairo_surface_t *
+gf_background_surface_create (GdkDisplay *display,
+                              GnomeBG    *bg,
+                              GdkWindow  *window,
+                              int         width,
+                              int         height)
+{
+  return gnome_bg_create_surface (bg, window, width, height, TRUE);
+}
+
+cairo_surface_t *
+gf_background_surface_get_from_root (GdkDisplay *display)
+{
+  GdkScreen *screen;
+
+  screen = gdk_display_get_default_screen (display);
+
+  return gnome_bg_get_surface_from_root (screen);
+}
+
+void
+gf_background_surface_set_as_root (GdkDisplay      *display,
+                                   cairo_surface_t *surface)
+{
+  GdkScreen *screen;
+
+  screen = gdk_display_get_default_screen (display);
+
+  gnome_bg_set_surface_as_root (screen, surface);
+}
diff --git a/gnome-flashback/libcommon/gf-background-utils.h b/gnome-flashback/libcommon/gf-background-utils.h
new file mode 100644
index 0000000..95b908c
--- /dev/null
+++ b/gnome-flashback/libcommon/gf-background-utils.h
@@ -0,0 +1,38 @@
+/*
+ * 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_UTILS_H
+#define GF_BACKGROUND_UTILS_H
+
+#include <libgnome-desktop/gnome-bg.h>
+
+G_BEGIN_DECLS
+
+cairo_surface_t *gf_background_surface_create        (GdkDisplay      *display,
+                                                      GnomeBG         *bg,
+                                                      GdkWindow       *window,
+                                                      int              width,
+                                                      int              height);
+
+cairo_surface_t *gf_background_surface_get_from_root (GdkDisplay      *display);
+
+void             gf_background_surface_set_as_root   (GdkDisplay      *display,
+                                                      cairo_surface_t *surface);
+
+G_END_DECLS
+
+#endif
diff --git a/gnome-flashback/libdesktop/Makefile.am b/gnome-flashback/libdesktop/Makefile.am
index 224f911..f7bcdd7 100644
--- a/gnome-flashback/libdesktop/Makefile.am
+++ b/gnome-flashback/libdesktop/Makefile.am
@@ -5,8 +5,12 @@ noinst_LTLIBRARIES = \
        $(NULL)
 
 libdesktop_la_CPPFLAGS = \
+       -DG_LOG_DOMAIN=\"desktop\" \
+       -DG_LOG_USE_STRUCTURED=1 \
        -DGNOME_DESKTOP_USE_UNSTABLE_API \
+       -I$(top_builddir)/gnome-flashback/libcommon \
        -I$(top_builddir)/gnome-flashback/libdesktop \
+       -I$(top_srcdir)/gnome-flashback \
        $(NULL)
 
 libdesktop_la_CFLAGS = \
@@ -52,6 +56,7 @@ libdesktop_la_LDFLAGS = \
        $(NULL)
 
 libdesktop_la_LIBADD = \
+       $(top_builddir)/gnome-flashback/libcommon/libcommon.la \
        $(DESKTOP_LIBS) \
        $(NULL)
 
diff --git a/gnome-flashback/libdesktop/gf-background.c b/gnome-flashback/libdesktop/gf-background.c
index 10d1334..2d2d69c 100644
--- a/gnome-flashback/libdesktop/gf-background.c
+++ b/gnome-flashback/libdesktop/gf-background.c
@@ -18,6 +18,7 @@
 #include "config.h"
 #include "gf-background.h"
 
+#include <libcommon/gf-background-utils.h>
 #include <libgnome-desktop/gnome-bg.h>
 
 #include "gf-desktop-window.h"
@@ -96,7 +97,7 @@ fade_cb (gpointer user_data)
   FadeData *fade;
   double current_time;
   double percent_done;
-  GdkScreen *screen;
+  GdkDisplay *display;
 
   self = GF_BACKGROUND (user_data);
   fade = self->fade_data;
@@ -128,8 +129,8 @@ fade_cb (gpointer user_data)
 
   g_clear_pointer (&self->fade_data, free_fade_data);
 
-  screen = gtk_widget_get_screen (self->window);
-  gnome_bg_set_surface_as_root (screen, self->surface);
+  display = gtk_widget_get_display (self->window);
+  gf_background_surface_set_as_root (display, self->surface);
 
   g_signal_emit (self, background_signals[CHANGED], 0);
 
@@ -140,11 +141,13 @@ static void
 change (GfBackground *self,
         gboolean      fade)
 {
+  GdkDisplay *display;
   GdkScreen *screen;
   GdkWindow *root;
   int width;
   int height;
 
+  display = gtk_widget_get_display (self->window);
   screen = gtk_widget_get_screen (self->window);
   root = gdk_screen_get_root_window (screen);
 
@@ -163,9 +166,13 @@ change (GfBackground *self,
       if (self->surface != NULL)
         data->start = cairo_surface_reference (self->surface);
       else
-        data->start = gnome_bg_get_surface_from_root (screen);
+        data->start = gf_background_surface_get_from_root (display);
 
-      data->end = gnome_bg_create_surface (self->bg, root, width, height, TRUE);
+      data->end = gf_background_surface_create (display,
+                                                self->bg,
+                                                root,
+                                                width,
+                                                height);
 
       data->start_time = g_get_real_time () / (double) G_USEC_PER_SEC;
       data->total_duration = .75;
@@ -177,13 +184,13 @@ change (GfBackground *self,
   else
     {
       g_clear_pointer (&self->surface, cairo_surface_destroy);
-      self->surface = gnome_bg_create_surface (self->bg,
-                                               root,
-                                               width,
-                                               height,
-                                               TRUE);
+      self->surface = gf_background_surface_create (display,
+                                                    self->bg,
+                                                    root,
+                                                    width,
+                                                    height);
 
-      gnome_bg_set_surface_as_root (screen, self->surface);
+      gf_background_surface_set_as_root (display, self->surface);
 
       g_signal_emit (self, background_signals[CHANGED], 0);
     }
diff --git a/gnome-flashback/libdesktop/gf-desktop-window.c b/gnome-flashback/libdesktop/gf-desktop-window.c
index 52cabd1..784bd39 100644
--- a/gnome-flashback/libdesktop/gf-desktop-window.c
+++ b/gnome-flashback/libdesktop/gf-desktop-window.c
@@ -19,6 +19,7 @@
 #include "gf-desktop-window.h"
 
 #include <gdk/gdkx.h>
+#include <libcommon/gf-background-utils.h>
 #include <libgnome-desktop/gnome-bg.h>
 #include <glib/gi18n.h>
 #include <X11/Xatom.h>
@@ -167,13 +168,13 @@ static void
 ensure_surface (GfDesktopWindow *self)
 {
   GtkWidget *widget;
-  GdkScreen *screen;
+  GdkDisplay *display;
 
   widget = GTK_WIDGET (self);
 
-  screen = gtk_widget_get_screen (widget);
+  display = gtk_widget_get_display (widget);
 
-  self->surface = gnome_bg_get_surface_from_root (screen);
+  self->surface = gf_background_surface_get_from_root (display);
   gtk_widget_queue_draw (widget);
   update_css_class (self);
 }
diff --git a/gnome-flashback/libroot-background/Makefile.am b/gnome-flashback/libroot-background/Makefile.am
index cffe29b..144a415 100644
--- a/gnome-flashback/libroot-background/Makefile.am
+++ b/gnome-flashback/libroot-background/Makefile.am
@@ -7,14 +7,16 @@ noinst_LTLIBRARIES = \
 libroot_background_la_CPPFLAGS = \
        -DG_LOG_DOMAIN=\"root-background\" \
        -DG_LOG_USE_STRUCTURED=1 \
+       -DGNOME_DESKTOP_USE_UNSTABLE_API \
+       -I$(top_builddir)/gnome-flashback/libcommon \
+       -I$(top_builddir)/gnome-flashback/libroot-background \
+       -I$(top_srcdir)/gnome-flashback \
        $(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 = \
@@ -28,6 +30,7 @@ libroot_background_la_LDFLAGS = \
        $(NULL)
 
 libroot_background_la_LIBADD = \
+       $(top_builddir)/gnome-flashback/libcommon/libcommon.la \
        $(DROOT_BACKGROUND_LIBS) \
        $(NULL)
 
diff --git a/gnome-flashback/libroot-background/gf-root-background.c 
b/gnome-flashback/libroot-background/gf-root-background.c
index 6504a49..5856fc8 100644
--- a/gnome-flashback/libroot-background/gf-root-background.c
+++ b/gnome-flashback/libroot-background/gf-root-background.c
@@ -19,6 +19,7 @@
 #include "gf-root-background.h"
 
 #include <gtk/gtk.h>
+#include <libcommon/gf-background-utils.h>
 #include <libgnome-desktop/gnome-bg.h>
 
 struct _GfRootBackground
@@ -41,20 +42,26 @@ G_DEFINE_TYPE (GfRootBackground, gf_root_background, G_TYPE_OBJECT)
 static void
 set_background (GfRootBackground *self)
 {
+  GdkDisplay *display;
   GdkScreen *screen;
   GdkWindow *root;
   gint width;
   gint height;
   cairo_surface_t *surface;
 
-  screen = gdk_screen_get_default ();
+  display = gdk_display_get_default ();
+  screen = gdk_display_get_default_screen (display);
   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);
+  surface = gf_background_surface_create (display,
+                                          self->bg,
+                                          root,
+                                          width,
+                                          height);
 
-  gnome_bg_set_surface_as_root (screen, surface);
+  gf_background_surface_set_as_root (display, surface);
   cairo_surface_destroy (surface);
 }
 


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