[Xfce4-commits] <ristretto:ristretto-0.0> Implement basic 'set as wallpaper' functionality for xfdesktop, simmilar to the 0.0.x versions (only set on screen0, monitor0)

Stephan Arts noreply at xfce.org
Sun Oct 23 19:20:26 CEST 2011


Updating branch refs/heads/ristretto-0.0
         to 6ec49be460af0d05d5d38573821aa3f34ba8f3da (commit)
       from 29e052d12745196ba251b64bb5f699275ec5cb60 (commit)

commit 6ec49be460af0d05d5d38573821aa3f34ba8f3da
Author: Stephan Arts <stephan at xfce.org>
Date:   Sat Sep 26 09:03:40 2009 +0200

    Implement basic 'set as wallpaper' functionality for xfdesktop, simmilar to the 0.0.x versions (only set on screen0, monitor0)

 src/Makefile.am              |    2 +
 src/image.h                  |    2 +
 src/main_window.c            |   29 ++++--
 src/wallpaper_manager.c      |   79 +++++++++++++++
 src/wallpaper_manager.h      |   49 ++++++++++
 src/xfce_wallpaper_manager.c |  217 ++++++++++++++++++++++++++++++++++++++++++
 src/xfce_wallpaper_manager.h |   65 +++++++++++++
 7 files changed, 435 insertions(+), 8 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 9a88f24..2467eba 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,6 +9,8 @@ ristretto_SOURCES = \
 	preferences_dialog.h preferences_dialog.c \
 	main_window_ui.h \
 	main_window.c main_window.h \
+    wallpaper_manager.c wallpaper_manager.h \
+    xfce_wallpaper_manager.c xfce_wallpaper_manager.h \
     app_menu_item.c app_menu_item.h \
 	thumbnail_bar.c thumbnail_bar.h \
 	thumbnail.c thumbnail.h \
diff --git a/src/image.h b/src/image.h
index 8b483b5..50e91d0 100644
--- a/src/image.h
+++ b/src/image.h
@@ -1,4 +1,6 @@
 /*
+ *  Copyright (C) Stephan Arts 2006-2009 <stephan at xfce.org>
+ *
  *  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 2 of the License, or
diff --git a/src/main_window.c b/src/main_window.c
index 97931a5..a1615e5 100644
--- a/src/main_window.c
+++ b/src/main_window.c
@@ -38,6 +38,8 @@
 #include "main_window.h"
 #include "main_window_ui.h"
 #include "thumbnail_bar.h"
+#include "wallpaper_manager.h"
+#include "xfce_wallpaper_manager.h"
 
 #include "preferences_dialog.h"
 #include "app_menu_item.h"
@@ -71,6 +73,7 @@ struct _RsttoMainWindowPriv
     GtkUIManager     *ui_manager;
     GtkRecentManager *recent_manager;
     RsttoSettings    *settings_manager;
+    RsttoWallpaperManager *wallpaper_manager;
 
     GtkWidget *menubar;
     GtkWidget *toolbar;
@@ -385,6 +388,7 @@ rstto_main_window_init (RsttoMainWindow *window)
     gtk_window_set_title (GTK_WINDOW (window), RISTRETTO_APP_TITLE);
 
     window->priv = g_new0(RsttoMainWindowPriv, 1);
+    window->priv->wallpaper_manager = RSTTO_WALLPAPER_MANAGER (rstto_xfce_wallpaper_manager_new());
 
     window->priv->iter = NULL;
 
@@ -710,8 +714,8 @@ rstto_main_window_image_list_iter_changed (RsttoMainWindow *window)
     const gchar *content_type;
     GtkWidget *open_with_menu = gtk_menu_new();
     GtkWidget *open_with_window_menu = gtk_menu_new();
-    gtk_menu_item_set_submenu (gtk_ui_manager_get_widget ( window->priv->ui_manager, "/image-viewer-menu/open-with-menu"), open_with_menu);
-    gtk_menu_item_set_submenu (gtk_ui_manager_get_widget ( window->priv->ui_manager, "/main-menu/edit-menu/open-with-menu"), open_with_window_menu);
+    gtk_menu_item_set_submenu (GTK_MENU_ITEM (gtk_ui_manager_get_widget ( window->priv->ui_manager, "/image-viewer-menu/open-with-menu")), open_with_menu);
+    gtk_menu_item_set_submenu (GTK_MENU_ITEM (gtk_ui_manager_get_widget ( window->priv->ui_manager, "/main-menu/edit-menu/open-with-menu")), open_with_window_menu);
 
     if (window->priv->props.image_list)
     {
@@ -1209,7 +1213,18 @@ cb_rstto_main_window_navigationtoolbar_position_changed (GtkRadioAction *action,
 static void
 cb_rstto_main_window_set_as_wallpaper (GtkWidget *widget, RsttoMainWindow *window)
 {
-    
+    RsttoImage *image = NULL;
+    if (window->priv->iter)
+        image = rstto_image_list_iter_get_image (window->priv->iter);
+    g_return_if_fail (image);
+
+    if (rstto_wallpaper_manager_check_running (window->priv->wallpaper_manager))
+    {
+        if (rstto_wallpaper_manager_configure_dialog_run (window->priv->wallpaper_manager, image) == GTK_RESPONSE_OK)
+        {
+            rstto_wallpaper_manager_set (window->priv->wallpaper_manager, image);
+        }
+    }
 }
 
 static void
@@ -1243,8 +1258,6 @@ cb_rstto_main_window_state_event(GtkWidget *widget, GdkEventWindowState *event,
                 gtk_widget_hide (window->priv->thumbnailbar);
             }
 
-            /*rstto_picture_viewer_zoom_fit (RSTTO_PICTURE_VIEWER (window->priv->picture_viewer));*/
-
             gtk_ui_manager_add_ui (window->priv->ui_manager,
                                    window->priv->toolbar_unfullscreen_merge_id,
                                    "/navigation-toolbar/placeholder-fullscreen",
@@ -1303,9 +1316,9 @@ cb_rstto_main_window_motion_notify_event (RsttoMainWindow *window,
     gint width, height;
     if(gdk_window_get_state(GTK_WIDGET(window)->window) & GDK_WINDOW_STATE_FULLSCREEN)
     {
-	gdk_drawable_get_size (GDK_DRAWABLE(GTK_WIDGET(window)->window), &width, &height);
-        //if ((event->state == 0) && (event->window == event->subwindow))
-	if ((event->x_root == 0) || (event->y_root == 0) || (((gint)event->x_root) == (width-1)) || (((gint)event->y_root) == (height-1)))
+        gdk_drawable_get_size (GDK_DRAWABLE(GTK_WIDGET(window)->window), &width, &height);
+
+        if ((event->x_root == 0) || (event->y_root == 0) || (((gint)event->x_root) == (width-1)) || (((gint)event->y_root) == (height-1)))
         {
             gtk_widget_show (window->priv->image_list_toolbar);
             window->priv->fs_toolbar_sticky = TRUE;
diff --git a/src/wallpaper_manager.c b/src/wallpaper_manager.c
new file mode 100644
index 0000000..4ac5997
--- /dev/null
+++ b/src/wallpaper_manager.c
@@ -0,0 +1,79 @@
+/*
+ *  Copyright (C) Stephan Arts 2009 <stephan at xfce.org>
+ *
+ *  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 2 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 Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <string.h>
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gtk/gtk.h>
+#include <gio/gio.h>
+
+
+
+#include "image.h"
+
+#include "wallpaper_manager.h"
+
+gint 
+rstto_wallpaper_manager_configure_dialog_run (RsttoWallpaperManager *self, RsttoImage *image)
+{
+    RSTTO_WALLPAPER_MANAGER_GET_IFACE (self)->configure_dialog_run(self, image);
+}
+
+gboolean 
+rstto_wallpaper_manager_check_running (RsttoWallpaperManager *self)
+{
+    RSTTO_WALLPAPER_MANAGER_GET_IFACE (self)->check_running (self);
+}
+
+gboolean
+rstto_wallpaper_manager_set (RsttoWallpaperManager *self, RsttoImage *image)
+{
+    RSTTO_WALLPAPER_MANAGER_GET_IFACE (self)->set (self, image);
+}
+
+
+static void
+rstto_wallpaper_manager_iface_init (gpointer         g_iface,
+                                    gpointer         iface_data)
+{
+    RsttoWallpaperManagerIface *iface = (RsttoWallpaperManagerIface *)g_iface;
+    iface->configure_dialog_run = rstto_wallpaper_manager_configure_dialog_run;
+}
+
+
+GType 
+rstto_wallpaper_manager_get_type (void)
+{
+    static GType iface_type = 0;
+    if (iface_type == 0)
+    {
+        static const GTypeInfo info = {
+            sizeof (RsttoWallpaperManagerIface),
+            rstto_wallpaper_manager_iface_init,   /* base_init */
+            NULL,   /* base_finalize */
+        };
+
+        iface_type = g_type_register_static (G_TYPE_INTERFACE, "RsttoWallpaperManagerIface",
+                               &info, 0);
+    }
+
+    return iface_type;
+
+}
diff --git a/src/wallpaper_manager.h b/src/wallpaper_manager.h
new file mode 100644
index 0000000..69316d1
--- /dev/null
+++ b/src/wallpaper_manager.h
@@ -0,0 +1,49 @@
+/*
+ *  Copyright (C) Stephan Arts 2009 <stephan at xfce.org>
+ *
+ *  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 2 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 Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __RISTRETTO_WALLPAPER_MANAGER_IFACE__
+#define __RISTRETTO_WALLPAPER_MANAGER_IFACE__
+
+G_BEGIN_DECLS
+
+#define RSTTO_WALLPAPER_MANAGER_TYPE    rstto_wallpaper_manager_get_type ()
+#define RSTTO_WALLPAPER_MANAGER(obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), RSTTO_WALLPAPER_MANAGER_TYPE, RsttoWallpaperManager))
+#define RSTTO_IS_WALLPAPER_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RSTTO_WALLPAPER_MANAGER_TYPE))
+#define RSTTO_WALLPAPER_MANAGER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), RSTTO_WALLPAPER_MANAGER_TYPE, RsttoWallpaperManagerIface))
+
+typedef struct _RsttoWallpaperManager RsttoWallpaperManager; /* dummy object */
+typedef struct _RsttoWallpaperManagerIface RsttoWallpaperManagerIface;
+
+struct _RsttoWallpaperManagerIface {
+    GTypeInterface parent;
+
+    gint (*configure_dialog_run) (RsttoWallpaperManager *self, RsttoImage *image);
+    gboolean (*set) (RsttoWallpaperManager *self, RsttoImage *image);
+    gboolean (*check_running) (RsttoWallpaperManager *self);
+};
+
+GType rstto_wallpaper_manager_get_type (void);
+
+gboolean rstto_wallpaper_manager_check_running (RsttoWallpaperManager *self);
+
+gint rstto_wallpaper_manager_configure_dialog_run (RsttoWallpaperManager *self, RsttoImage *image);
+gboolean rstto_wallpaper_manager_set (RsttoWallpaperManager *self, RsttoImage *image);
+
+G_END_DECLS
+
+#endif /* __RISTRETTO_WALLPAPER_MANAGER_IFACE__ */
diff --git a/src/xfce_wallpaper_manager.c b/src/xfce_wallpaper_manager.c
new file mode 100644
index 0000000..f69e944
--- /dev/null
+++ b/src/xfce_wallpaper_manager.c
@@ -0,0 +1,217 @@
+/*
+ *  Copyright (c) 2009 Stephan Arts <stephan at xfce.org>
+ *
+ *  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 2 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 Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+#include <X11/Xlib.h>
+#include <xfconf/xfconf.h>
+#include <libxfce4util/libxfce4util.h>
+#include <gio/gio.h>
+
+#include "image.h"
+
+#include "wallpaper_manager.h"
+#include "xfce_wallpaper_manager.h"
+
+#define XFDESKTOP_SELECTION_FMT "XFDESKTOP_SELECTION_%d"
+
+static void
+rstto_xfce_wallpaper_manager_init (GObject *);
+static void
+rstto_xfce_wallpaper_manager_class_init (GObjectClass *);
+
+static void
+rstto_xfce_wallpaper_manager_dispose (GObject *object);
+static void
+rstto_xfce_wallpaper_manager_finalize (GObject *object);
+
+static GObjectClass *parent_class = NULL;
+
+static RsttoXfceWallpaperManager *xfce_wallpaper_manager_object;
+
+struct _RsttoXfceWallpaperManagerPriv
+{
+    XfconfChannel *channel;
+};
+
+
+enum
+{
+    PROP_0,
+};
+
+static gint 
+rstto_xfce_wallpaper_manager_configure_dialog_run (RsttoWallpaperManager *self, RsttoImage *image)
+{
+    return GTK_RESPONSE_OK;
+}
+
+static gboolean
+rstto_xfce_wallpaper_manager_check_running (RsttoWallpaperManager *self)
+{
+    gchar selection_name[100];
+
+    GdkScreen *gdk_screen = gdk_screen_get_default();
+    gint xscreen = gdk_screen_get_number(gdk_screen);
+
+    g_snprintf(selection_name, 100, XFDESKTOP_SELECTION_FMT, xscreen);
+
+    Atom xfce_selection_atom = XInternAtom (gdk_display, selection_name, False);
+    if((XGetSelectionOwner(GDK_DISPLAY(), xfce_selection_atom)))
+    {
+        return TRUE;
+    }
+    return FALSE;
+}
+
+static gboolean
+rstto_xfce_wallpaper_manager_set (RsttoWallpaperManager *self, RsttoImage *image)
+{
+    RsttoXfceWallpaperManager *manager = RSTTO_XFCE_WALLPAPER_MANAGER (self);
+    GFile *file = rstto_image_get_file (image);
+    gchar *uri = g_file_get_path (file);
+
+    xfconf_channel_set_string (manager->priv->channel, "/backdrop/screen0/monitor0/image-path", uri);
+    xfconf_channel_set_bool   (manager->priv->channel, "/backdrop/screen0/monitor0/image-show", TRUE);
+    xfconf_channel_set_int    (manager->priv->channel, "/backdrop/screen0/monitor0/image-style", 4);
+
+    return FALSE;
+}
+
+static void
+rstto_xfce_wallpaper_manager_iface_init (RsttoWallpaperManagerIface *iface)
+{
+    iface->configure_dialog_run = rstto_xfce_wallpaper_manager_configure_dialog_run;
+    iface->check_running = rstto_xfce_wallpaper_manager_check_running;
+    iface->set = rstto_xfce_wallpaper_manager_set;
+}
+
+GType
+rstto_xfce_wallpaper_manager_get_type (void)
+{
+    static GType rstto_xfce_wallpaper_manager_type = 0;
+
+    if (!rstto_xfce_wallpaper_manager_type)
+    {
+        static const GTypeInfo rstto_xfce_wallpaper_manager_info = 
+        {
+            sizeof (RsttoXfceWallpaperManagerClass),
+            (GBaseInitFunc) NULL,
+            (GBaseFinalizeFunc) NULL,
+            (GClassInitFunc) rstto_xfce_wallpaper_manager_class_init,
+            (GClassFinalizeFunc) NULL,
+            NULL,
+            sizeof (RsttoXfceWallpaperManager),
+            0,
+            (GInstanceInitFunc) rstto_xfce_wallpaper_manager_init,
+            NULL
+        };
+
+        rstto_xfce_wallpaper_manager_type = g_type_register_static (G_TYPE_OBJECT, "RsttoXfceWallpaperManager", &rstto_xfce_wallpaper_manager_info, 0);
+
+        static const GInterfaceInfo wallpaper_manager_iface_info = 
+        {
+            (GInstanceInitFunc) rstto_xfce_wallpaper_manager_iface_init,
+            NULL,
+            NULL
+        };
+
+        g_type_add_interface_static (rstto_xfce_wallpaper_manager_type, RSTTO_WALLPAPER_MANAGER_TYPE,  &wallpaper_manager_iface_info);
+
+    }
+    return rstto_xfce_wallpaper_manager_type;
+}
+
+
+static void
+rstto_xfce_wallpaper_manager_init (GObject *object)
+{
+    gchar *accelmap_path = NULL;
+
+    RsttoXfceWallpaperManager *xfce_wallpaper_manager = RSTTO_XFCE_WALLPAPER_MANAGER (object);
+
+    xfce_wallpaper_manager->priv = g_new0 (RsttoXfceWallpaperManagerPriv, 1);
+    xfce_wallpaper_manager->priv->channel = xfconf_channel_new ("xfce4-desktop");
+}
+
+
+static void
+rstto_xfce_wallpaper_manager_class_init (GObjectClass *object_class)
+{
+    GParamSpec *pspec;
+
+    RsttoXfceWallpaperManagerClass *xfce_wallpaper_manager_class = RSTTO_XFCE_WALLPAPER_MANAGER_CLASS (object_class);
+
+    parent_class = g_type_class_peek_parent (xfce_wallpaper_manager_class);
+
+    object_class->dispose = rstto_xfce_wallpaper_manager_dispose;
+    object_class->finalize = rstto_xfce_wallpaper_manager_finalize;
+}
+
+/**
+ * rstto_xfce_wallpaper_manager_dispose:
+ * @object:
+ *
+ */
+static void
+rstto_xfce_wallpaper_manager_dispose (GObject *object)
+{
+    RsttoXfceWallpaperManager *xfce_wallpaper_manager = RSTTO_XFCE_WALLPAPER_MANAGER (object);
+
+    if (xfce_wallpaper_manager->priv)
+    {
+        g_free (xfce_wallpaper_manager->priv);
+        xfce_wallpaper_manager->priv = NULL;
+    }
+}
+
+/**
+ * rstto_xfce_wallpaper_manager_finalize:
+ * @object:
+ *
+ */
+static void
+rstto_xfce_wallpaper_manager_finalize (GObject *object)
+{
+}
+
+
+
+/**
+ * rstto_xfce_wallpaper_manager_new:
+ *
+ *
+ * Singleton
+ */
+RsttoXfceWallpaperManager *
+rstto_xfce_wallpaper_manager_new (void)
+{
+    if (xfce_wallpaper_manager_object == NULL)
+    {
+        xfce_wallpaper_manager_object = g_object_new (RSTTO_TYPE_XFCE_WALLPAPER_MANAGER, NULL);
+    }
+    else
+    {
+        g_object_ref (xfce_wallpaper_manager_object);
+    }
+
+    return xfce_wallpaper_manager_object;
+}
diff --git a/src/xfce_wallpaper_manager.h b/src/xfce_wallpaper_manager.h
new file mode 100644
index 0000000..76f9d9f
--- /dev/null
+++ b/src/xfce_wallpaper_manager.h
@@ -0,0 +1,65 @@
+/*
+ *  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 2 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 Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __RISTRETTO_XFCE_WALLPAPER_MANAGER_H__
+#define __RISTRETTO_XFCE_WALLPAPER_MANAGER_H__
+
+G_BEGIN_DECLS
+
+#define RSTTO_TYPE_XFCE_WALLPAPER_MANAGER rstto_xfce_wallpaper_manager_get_type()
+
+#define RSTTO_XFCE_WALLPAPER_MANAGER(obj)( \
+        G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                RSTTO_TYPE_XFCE_WALLPAPER_MANAGER, \
+                RsttoXfceWallpaperManager))
+
+#define RSTTO_IS_XFCE_WALLPAPER_MANAGER(obj)( \
+        G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+                RSTTO_TYPE_XFCE_WALLPAPER_MANAGER))
+
+#define RSTTO_XFCE_WALLPAPER_MANAGER_CLASS(klass)( \
+        G_TYPE_CHECK_CLASS_CAST ((klass), \
+                RSTTO_TYPE_XFCE_WALLPAPER_MANAGER, \
+                RsttoXfceWallpaperManagerClass))
+
+#define RSTTO_IS_XFCE_WALLPAPER_MANAGER_CLASS(klass)( \
+        G_TYPE_CHECK_CLASS_TYPE ((klass), \
+                RSTTO_TYPE_XFCE_WALLPAPER_MANAGER()))
+
+
+typedef struct _RsttoXfceWallpaperManager RsttoXfceWallpaperManager;
+typedef struct _RsttoXfceWallpaperManagerPriv RsttoXfceWallpaperManagerPriv;
+
+struct _RsttoXfceWallpaperManager
+{
+    GObject parent;
+
+    RsttoXfceWallpaperManagerPriv *priv;
+};
+
+typedef struct _RsttoXfceWallpaperManagerClass RsttoXfceWallpaperManagerClass;
+
+struct _RsttoXfceWallpaperManagerClass
+{
+    GObjectClass parent_class;
+};
+
+RsttoXfceWallpaperManager *rstto_xfce_wallpaper_manager_new (void);
+GType          rstto_xfce_wallpaper_manager_get_type (void);
+
+G_END_DECLS
+
+#endif /* __RISTRETTO_XFCE_WALLPAPER_MANAGER_H__ */


More information about the Xfce4-commits mailing list