[gnome-panel/desktop-background] Add desktop background drawing application
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/desktop-background] Add desktop background drawing application
- Date: Sun, 1 Jun 2014 16:10:36 +0000 (UTC)
commit 6a658fe6a00eb928acf7ca68051f342064d3ddba
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sun Jun 1 19:05:39 2014 +0300
Add desktop background drawing application
Makefile.am | 1 +
configure.ac | 7 +
data/gnome-flashback.session.desktop.in | 2 +-
desktop-background/Makefile.am | 5 +
desktop-background/data/Makefile.am | 10 ++
.../gnome-flashback-desktop-background.desktop.in | 5 +
desktop-background/src/Makefile.am | 15 ++
desktop-background/src/desktop-background.c | 155 ++++++++++++++++++++
desktop-background/src/desktop-background.h | 31 ++++
desktop-background/src/main.c | 30 ++++
10 files changed, 260 insertions(+), 1 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 23e1543..dc5ece8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,6 @@
SUBDIRS = \
gnome-panel \
+ desktop-background \
libpanel-applet \
applets \
doc \
diff --git a/configure.ac b/configure.ac
index bec78d4..e8fa11f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -99,6 +99,10 @@ PKG_CHECK_MODULES(PANEL, gmodule-2.0 >= $GLIB_REQUIRED
AC_SUBST(PANEL_CFLAGS)
AC_SUBST(PANEL_LIBS)
+PKG_CHECK_MODULES(DESKTOP_BACKGROUND, gtk+-3.0 >= $GTK_REQUIRED gnome-desktop-3.0 >=
$LIBGNOME_DESKTOP_REQUIRED dconf >= $DCONF_REQUIRED)
+AC_SUBST(DESKTOP_BACKGROUND_CFLAGS)
+AC_SUBST(DESKTOP_BACKGROUND_LIBS)
+
AC_ARG_ENABLE(telepathy_glib, AS_HELP_STRING([--enable-telepathy-glib],[Enable telepathy-glib support
(auto)]),enable_telepathy_glib=$enableval,enable_telepathy_glib=auto)
if test "x$enable_telepathy_glib" = "xno" ; then
HAVE_TELEPATHY_GLIB=no
@@ -311,6 +315,9 @@ esac
AC_CONFIG_FILES([
Makefile
+desktop-background/Makefile
+desktop-background/data/Makefile
+desktop-background/src/Makefile
data/Makefile
data/16x16/Makefile
data/22x22/Makefile
diff --git a/data/gnome-flashback.session.desktop.in b/data/gnome-flashback.session.desktop.in
index 5ba2d46..78f9729 100644
--- a/data/gnome-flashback.session.desktop.in
+++ b/data/gnome-flashback.session.desktop.in
@@ -1,3 +1,3 @@
[GNOME Session]
_Name=GNOME Flashback (Metacity)
-RequiredComponents=gnome-panel;gnome-settings-daemon;gnome-screensaver;metacity;
+RequiredComponents=gnome-panel;gnome-settings-daemon;gnome-screensaver;metacity;gnome-flashback-desktop-background;
diff --git a/desktop-background/Makefile.am b/desktop-background/Makefile.am
new file mode 100644
index 0000000..97a836c
--- /dev/null
+++ b/desktop-background/Makefile.am
@@ -0,0 +1,5 @@
+SUBDIRS = \
+ data \
+ src
+
+-include $(top_srcdir)/git.mk
diff --git a/desktop-background/data/Makefile.am b/desktop-background/data/Makefile.am
new file mode 100644
index 0000000..6c5bf3d
--- /dev/null
+++ b/desktop-background/data/Makefile.am
@@ -0,0 +1,10 @@
+desktopdir = $(datadir)/applications
+desktop_in_files = gnome-flashback-desktop-background.desktop.in
+desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
+
+ INTLTOOL_DESKTOP_RULE@
+
+EXTRA_DIST = $(desktop_in_files)
+CLEANFILES = $(desktop_DATA)
+
+-include $(top_srcdir)/git.mk
diff --git a/desktop-background/data/gnome-flashback-desktop-background.desktop.in
b/desktop-background/data/gnome-flashback-desktop-background.desktop.in
new file mode 100644
index 0000000..a3cbf6d
--- /dev/null
+++ b/desktop-background/data/gnome-flashback-desktop-background.desktop.in
@@ -0,0 +1,5 @@
+[Desktop Entry]
+Type=Application
+Name=GNOME Flashback Desktop Background
+Exec=gnome-flashback-desktop-background
+OnlyShowIn=GNOME;
diff --git a/desktop-background/src/Makefile.am b/desktop-background/src/Makefile.am
new file mode 100644
index 0000000..a75d27f
--- /dev/null
+++ b/desktop-background/src/Makefile.am
@@ -0,0 +1,15 @@
+bin_PROGRAMS = gnome-flashback-desktop-background
+
+AM_CPPFLAGS = \
+ -I$(top_builddir)/desktop-background \
+ $(DESKTOP_BACKGROUND_CFLAGS)
+
+gnome_flashback_desktop_background_SOURCES = \
+ main.c \
+ desktop-background.c \
+ desktop-background.h
+
+gnome_flashback_desktop_background_LDADD = \
+ $(DESKTOP_BACKGROUND_LIBS)
+
+-include $(top_srcdir)/git.mk
diff --git a/desktop-background/src/desktop-background.c b/desktop-background/src/desktop-background.c
new file mode 100644
index 0000000..f42fdf5
--- /dev/null
+++ b/desktop-background/src/desktop-background.c
@@ -0,0 +1,155 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define GNOME_DESKTOP_USE_UNSTABLE_API
+#include <libgnome-desktop/gnome-bg.h>
+#include <gdesktop-enums.h>
+
+#include <gtk/gtk.h>
+#include <string.h>
+
+#include "desktop-background.h"
+
+struct _DesktopBackgroundPrivate {
+ GnomeBG *bg;
+ GSettings *settings;
+
+ gulong screen_size_handler;
+ gulong screen_monitors_handler;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (DesktopBackground, desktop_background, G_TYPE_OBJECT);
+
+static void
+desktop_background_draw (DesktopBackground *desktop_background)
+{
+ GdkScreen *screen = gdk_screen_get_default ();
+ cairo_surface_t *surface = gnome_bg_create_surface (desktop_background->priv->bg,
+ gdk_screen_get_root_window (screen),
+ gdk_screen_get_width (screen),
+ gdk_screen_get_height (screen),
+ TRUE);
+ gnome_bg_set_surface_as_root (screen, surface);
+ cairo_surface_destroy (surface);
+}
+
+static void
+screen_size_changed (GdkScreen *screen,
+ DesktopBackground *desktop_background)
+{
+ desktop_background_draw (desktop_background);
+}
+
+static void
+desktop_background_changed (GnomeBG *bg,
+ DesktopBackground *desktop_background)
+{
+ desktop_background_draw (desktop_background);
+}
+
+static void
+desktop_background_transitioned (GnomeBG *bg,
+ DesktopBackground *desktop_background)
+{
+ desktop_background_draw (desktop_background);
+}
+
+static gboolean
+desktop_background_settings_change_event (GSettings *settings,
+ gpointer keys,
+ gint n_keys,
+ gpointer user_data)
+{
+ DesktopBackground *desktop_background = (DesktopBackground *) user_data;
+
+ gnome_bg_load_from_preferences (desktop_background->priv->bg,
+ desktop_background->priv->settings);
+
+ return FALSE;
+}
+
+static void
+desktop_background_constructed (GObject *object)
+{
+ DesktopBackground *desktop_background = DESKTOP_BACKGROUND (object);
+
+ if (G_OBJECT_CLASS (desktop_background_parent_class)->constructed != NULL)
+ G_OBJECT_CLASS (desktop_background_parent_class)->constructed (object);
+
+ gnome_bg_load_from_preferences (desktop_background->priv->bg,
+ desktop_background->priv->settings);
+
+ g_signal_connect (desktop_background->priv->settings,
+ "change-event",
+ G_CALLBACK (desktop_background_settings_change_event),
+ desktop_background);
+}
+
+static void
+desktop_background_finalize (GObject *object)
+{
+ DesktopBackground *desktop_background = DESKTOP_BACKGROUND (object);
+
+ if (desktop_background->priv->screen_size_handler > 0) {
+ g_signal_handler_disconnect (gdk_screen_get_default (),
+ desktop_background->priv->screen_size_handler);
+ desktop_background->priv->screen_size_handler = 0;
+ }
+
+ if (desktop_background->priv->screen_monitors_handler > 0) {
+ g_signal_handler_disconnect (gdk_screen_get_default (),
+ desktop_background->priv->screen_monitors_handler);
+ desktop_background->priv->screen_monitors_handler = 0;
+ }
+
+ g_signal_handlers_disconnect_by_func (desktop_background->priv->settings,
+ desktop_background_settings_change_event,
+ desktop_background);
+
+ g_clear_object (&desktop_background->priv->bg);
+
+ G_OBJECT_CLASS (desktop_background_parent_class)->finalize (object);
+}
+
+static void
+desktop_background_class_init (DesktopBackgroundClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->finalize = desktop_background_finalize;
+ object_class->constructed = desktop_background_constructed;
+}
+
+static void
+desktop_background_init (DesktopBackground *desktop_background)
+{
+ desktop_background->priv = DESKTOP_BACKGROUND_GET_PRIVATE (desktop_background);
+
+ desktop_background->priv->bg = gnome_bg_new ();
+ desktop_background->priv->settings = g_settings_new("org.gnome.desktop.background");
+
+ g_signal_connect (desktop_background->priv->bg,
+ "changed",
+ G_CALLBACK (desktop_background_changed),
+ desktop_background);
+ g_signal_connect (desktop_background->priv->bg,
+ "transitioned",
+ G_CALLBACK (desktop_background_transitioned),
+ desktop_background);
+
+ desktop_background->priv->screen_size_handler = g_signal_connect (gdk_screen_get_default (),
+ "size-changed",
+ G_CALLBACK (screen_size_changed),
+ desktop_background);
+ desktop_background->priv->screen_monitors_handler = g_signal_connect (gdk_screen_get_default (),
+ "monitors-changed",
+ G_CALLBACK
(screen_size_changed),
+ desktop_background);
+}
+
+DesktopBackground *
+desktop_background_new ()
+{
+ return g_object_new (DESKTOP_BACKGROUND_TYPE, NULL);
+}
diff --git a/desktop-background/src/desktop-background.h b/desktop-background/src/desktop-background.h
new file mode 100644
index 0000000..c45822c
--- /dev/null
+++ b/desktop-background/src/desktop-background.h
@@ -0,0 +1,31 @@
+#ifndef DESKTOP_BACKGROUND_H
+#define DESKTOP_BACKGROUND_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define DESKTOP_BACKGROUND_TYPE (desktop_background_get_type ())
+#define DESKTOP_BACKGROUND(object) (G_TYPE_CHECK_INSTANCE_CAST ((object),
DESKTOP_BACKGROUND_TYPE, DesktopBackground))
+#define DESKTOP_BACKGROUND_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class,
DESKTOP_BACKGROUND_TYPE, DesktopBackgroundClass))
+#define DESKTOP_BACKGROUND_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object),
DESKTOP_BACKGROUND_TYPE, DesktopBackgroundPrivate))
+
+typedef struct _DesktopBackground DesktopBackground;
+typedef struct _DesktopBackgroundClass DesktopBackgroundClass;
+typedef struct _DesktopBackgroundPrivate DesktopBackgroundPrivate;
+
+struct _DesktopBackground {
+ GObject parent;
+ DesktopBackgroundPrivate *priv;
+};
+
+struct _DesktopBackgroundClass {
+ GObjectClass parent_class;
+};
+
+GType desktop_background_get_type (void);
+DesktopBackground *desktop_background_new ();
+
+G_END_DECLS
+
+#endif
diff --git a/desktop-background/src/main.c b/desktop-background/src/main.c
new file mode 100644
index 0000000..8029697
--- /dev/null
+++ b/desktop-background/src/main.c
@@ -0,0 +1,30 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "desktop-background.h"
+
+#include <gtk/gtk.h>
+#include <gio/gdesktopappinfo.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int
+main (int argc, char *argv[])
+{
+ DesktopBackground *desktop_background;
+
+ gtk_init (&argc, &argv);
+
+ desktop_background = desktop_background_new ();
+
+ gtk_main ();
+
+ if (desktop_background) {
+ g_object_unref (desktop_background);
+ desktop_background = NULL;
+ }
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]