[Xfce4-commits] <ristretto:master> Improve gnome-3 compatibility.
Stephan Arts
noreply at xfce.org
Mon Nov 28 19:44:01 CET 2011
Updating branch refs/heads/master
to f6f45c1e4abf8db82e5bb09a794152366aa05887 (commit)
from e984d0eedcc366fa04982ab65885784da071e563 (commit)
commit f6f45c1e4abf8db82e5bb09a794152366aa05887
Author: Stephan Arts <stephan at xfce.org>
Date: Thu Nov 24 19:52:22 2011 +0100
Improve gnome-3 compatibility.
src/gnome_wallpaper_manager.c | 348 +++++++++++++++++++++++++++++++++++++++--
src/main_window.c | 21 +--
2 files changed, 341 insertions(+), 28 deletions(-)
diff --git a/src/gnome_wallpaper_manager.c b/src/gnome_wallpaper_manager.c
index 25c4352..2db8e01 100644
--- a/src/gnome_wallpaper_manager.c
+++ b/src/gnome_wallpaper_manager.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) Stephan Arts 2009-2011 <stephan at gnome.org>
+ * Copyright (c) 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
@@ -24,6 +24,7 @@
#include <X11/Xlib.h>
#include <xfconf/xfconf.h>
#include <libxfce4util/libxfce4util.h>
+#include <libxfce4ui/libxfce4ui.h>
#include <gio/gio.h>
@@ -32,9 +33,28 @@
#include "util.h"
#include "file.h"
+#include "monitor_chooser.h"
#include "wallpaper_manager.h"
#include "gnome_wallpaper_manager.h"
+enum MonitorStyle
+{
+ MONITOR_STYLE_AUTOMATIC = 0,
+ MONITOR_STYLE_CENTERED,
+ MONITOR_STYLE_TILED,
+ MONITOR_STYLE_STRETCHED,
+ MONITOR_STYLE_SCALED,
+ MONITOR_STYLE_ZOOMED
+};
+
+enum ColorStyle
+{
+ COLOR_STYLE_SOLID = 0,
+ COLOR_STYLE_HORIZONTAL_GRADIENT,
+ COLOR_STYLE_VERTICAL_GRADIENT
+};
+
+
typedef struct {
gint16 r;
gint16 g;
@@ -42,9 +62,6 @@ typedef struct {
gint16 a;
} RsttoColor;
-#define IMAGE_PATH_PROP "/desktop/gnome/background/picture_filename"
-#define IMAGE_SHOW_PROP "/desktop/gnome/background/draw_background"
-
static void
rstto_gnome_wallpaper_manager_init (GObject *);
static void
@@ -55,13 +72,34 @@ rstto_gnome_wallpaper_manager_dispose (GObject *object);
static void
rstto_gnome_wallpaper_manager_finalize (GObject *object);
+static void
+cb_monitor_chooser_changed (
+ RsttoMonitorChooser *monitor_chooser,
+ RsttoGnomeWallpaperManager *manager);
+static void
+cb_style_combo_changed (
+ GtkComboBox *style_combo,
+ RsttoGnomeWallpaperManager *manager);
+
+static void
+configure_monitor_chooser_pixbuf (
+ RsttoGnomeWallpaperManager *manager );
+
static GObjectClass *parent_class = NULL;
-static RsttoWallpaperManager *gnome_wallpaper_manager_object;
+static RsttoWallpaperManager *gnome_wallpaper_manager_object = NULL;
struct _RsttoGnomeWallpaperManagerPriv
{
+ gint screen;
+ gint monitor;
+ enum MonitorStyle style;
+
RsttoFile *file;
+ GdkPixbuf *pixbuf;
+
+ GtkWidget *monitor_chooser;
+ GtkWidget *style_combo;
GtkWidget *dialog;
};
@@ -77,11 +115,33 @@ rstto_gnome_wallpaper_manager_configure_dialog_run (
RsttoWallpaperManager *self,
RsttoFile *file)
{
- //RsttoGnomeWallpaperManager *manager = RSTTO_GNOME_WALLPAPER_MANAGER (self);
+ RsttoGnomeWallpaperManager *manager = RSTTO_GNOME_WALLPAPER_MANAGER (self);
gint response = GTK_RESPONSE_OK;
+ manager->priv->file = file;
+
+ if (manager->priv->pixbuf)
+ {
+ g_object_unref (manager->priv->pixbuf);
+ }
+
+ manager->priv->pixbuf = gdk_pixbuf_new_from_file_at_size (
+ rstto_file_get_path(file),
+ 500,
+ 500,
+ NULL);
+
+ configure_monitor_chooser_pixbuf (manager);
+
+ response = gtk_dialog_run (GTK_DIALOG (manager->priv->dialog));
+ gtk_widget_hide (manager->priv->dialog);
+ if ((response == GTK_RESPONSE_OK) || (response == GTK_RESPONSE_APPLY))
+ {
+ manager->priv->style = gtk_combo_box_get_active (
+ GTK_COMBO_BOX (manager->priv->style_combo));
+ manager->priv->monitor = rstto_monitor_chooser_get_selected (
+ RSTTO_MONITOR_CHOOSER(manager->priv->monitor_chooser));
+ }
- //response = gtk_dialog_run (GTK_DIALOG(manager->priv->dialog));
- //gtk_widget_hide (manager->priv->dialog);
return response;
}
@@ -98,20 +158,23 @@ rstto_gnome_wallpaper_manager_set (
RsttoFile *file)
{
gchar *command = NULL;
- gchar *escaped_file_name = g_shell_quote (
- rstto_file_get_path (file));
command = g_strdup_printf (
- "gconftool-2 %s --set %s --type string",
- IMAGE_PATH_PROP,
- escaped_file_name);
+ "gsettings set org.gnome.desktop.background picture-uri %s",
+ rstto_file_get_uri (file));
+
+ g_spawn_command_line_async (command, NULL);
+ g_free (command);
+
+ command = g_strdup_printf (
+ "gsettings set org.gnome.desktop.background picture-options %s",
+ "scaled");
g_spawn_command_line_async (command, NULL);
g_free (command);
command = g_strdup_printf (
- "gconftool-2 %s --set true --type boolean",
- IMAGE_SHOW_PROP);
+ "gsettings set org.gnome.desktop.background primary-color '#000000000000'");
g_spawn_command_line_async (command, NULL);
g_free (command);
@@ -167,6 +230,14 @@ static void
rstto_gnome_wallpaper_manager_init (GObject *object)
{
RsttoGnomeWallpaperManager *manager = RSTTO_GNOME_WALLPAPER_MANAGER (object);
+ GtkWidget *image_prop_table = gtk_table_new (3, 2, FALSE);
+ GtkWidget *style_label = gtk_label_new( _("Style:"));
+ GtkWidget *vbox;
+
+ GdkScreen *screen = gdk_screen_get_default ();
+ gint n_monitors = gdk_screen_get_n_monitors (screen);
+ GdkRectangle monitor_geometry;
+ gint i;
manager->priv = g_new0 (RsttoGnomeWallpaperManagerPriv, 1);
@@ -181,6 +252,85 @@ rstto_gnome_wallpaper_manager_init (GObject *object)
GTK_STOCK_OK,
GTK_RESPONSE_OK,
NULL);
+
+ vbox = gtk_dialog_get_content_area ( GTK_DIALOG (manager->priv->dialog));
+
+ manager->priv->monitor_chooser = rstto_monitor_chooser_new ();
+ manager->priv->style_combo = gtk_combo_box_new_text();
+
+ gtk_table_set_row_spacing (GTK_TABLE(image_prop_table), 1, 4);
+
+ for (i = 0; i < n_monitors; ++i)
+ {
+ gdk_screen_get_monitor_geometry (
+ screen,
+ i,
+ &monitor_geometry);
+ rstto_monitor_chooser_add (
+ RSTTO_MONITOR_CHOOSER (manager->priv->monitor_chooser),
+ monitor_geometry.width,
+ monitor_geometry.height);
+ }
+ gtk_box_pack_start (
+ GTK_BOX (vbox),
+ manager->priv->monitor_chooser,
+ FALSE,
+ FALSE,
+ 0);
+ gtk_box_pack_start (
+ GTK_BOX (vbox),
+ image_prop_table,
+ FALSE,
+ FALSE,
+ 0);
+
+ gtk_table_attach (
+ GTK_TABLE (image_prop_table),
+ style_label,
+ 0,
+ 1,
+ 0,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0);
+ gtk_table_attach (
+ GTK_TABLE (image_prop_table),
+ manager->priv->style_combo,
+ 1,
+ 2,
+ 0,
+ 1,
+ GTK_EXPAND|GTK_FILL,
+ 0,
+ 0,
+ 0);
+
+ gtk_combo_box_append_text (
+ GTK_COMBO_BOX (manager->priv->style_combo),
+ _("Auto"));
+
+ gtk_combo_box_set_active (
+ GTK_COMBO_BOX (manager->priv->style_combo),
+ 0);
+
+ manager->priv->screen = gdk_screen_get_number (screen);
+
+ gtk_window_set_resizable (GTK_WINDOW (manager->priv->dialog), FALSE);
+
+ g_signal_connect (
+ G_OBJECT(manager->priv->monitor_chooser),
+ "changed",
+ G_CALLBACK (cb_monitor_chooser_changed),
+ manager);
+ g_signal_connect (
+ G_OBJECT(manager->priv->style_combo),
+ "changed",
+ G_CALLBACK (cb_style_combo_changed),
+ manager);
+
+ gtk_widget_show_all (vbox);
}
@@ -220,6 +370,10 @@ rstto_gnome_wallpaper_manager_dispose (GObject *object)
static void
rstto_gnome_wallpaper_manager_finalize (GObject *object)
{
+ if (gnome_wallpaper_manager_object)
+ {
+ gnome_wallpaper_manager_object = NULL;
+ }
}
@@ -245,3 +399,167 @@ rstto_gnome_wallpaper_manager_new (void)
return gnome_wallpaper_manager_object;
}
+
+static void
+cb_monitor_chooser_changed (
+ RsttoMonitorChooser *monitor_chooser,
+ RsttoGnomeWallpaperManager *manager)
+{
+ rstto_monitor_chooser_set_pixbuf (
+ monitor_chooser,
+ manager->priv->monitor,
+ NULL,
+ NULL);
+
+ manager->priv->monitor = rstto_monitor_chooser_get_selected (monitor_chooser);
+
+ configure_monitor_chooser_pixbuf (manager);
+}
+
+static void
+configure_monitor_chooser_pixbuf (
+ RsttoGnomeWallpaperManager *manager )
+{
+ GdkPixbuf *monitor_pixbuf = NULL;
+ GdkPixbuf *tmp_pixbuf = NULL;
+ gint monitor_width = 0;
+ gint monitor_height = 0;
+
+ gint pixbuf_width = 0;
+ gint pixbuf_height = 0;
+ gint dest_x = 0;
+ gint dest_y = 0;
+ gint dest_width = 0;
+ gint dest_height = 0;
+ gdouble x_scale = 0.0;
+ gdouble y_scale = 0.0;
+
+ if (manager->priv->pixbuf)
+ {
+ tmp_pixbuf = gdk_pixbuf_copy (manager->priv->pixbuf);
+ if ( NULL != tmp_pixbuf )
+ {
+ rstto_monitor_chooser_get_dimensions (
+ RSTTO_MONITOR_CHOOSER (manager->priv->monitor_chooser),
+ manager->priv->monitor,
+ &monitor_width,
+ &monitor_height);
+
+ pixbuf_width = monitor_width * 0.2;
+ pixbuf_height = monitor_height * 0.2;
+
+ monitor_pixbuf = gdk_pixbuf_new (
+ GDK_COLORSPACE_RGB, /* Colorspace */
+ FALSE, /* has-alpha */
+ 8, /* bits per sample */
+ pixbuf_width, /* width */
+ pixbuf_height); /* height */
+
+ switch (manager->priv->style)
+ {
+ case MONITOR_STYLE_ZOOMED:
+ dest_x = 0;
+ dest_y = 0;
+ dest_width = pixbuf_width;
+ dest_height = pixbuf_height;
+ x_scale = (gdouble)dest_width / (gdouble)gdk_pixbuf_get_width (tmp_pixbuf);
+ y_scale = (gdouble)dest_height / (gdouble)gdk_pixbuf_get_height (tmp_pixbuf);
+ if (x_scale > y_scale)
+ {
+ y_scale = x_scale;
+ }
+ else
+ {
+ x_scale = y_scale;
+ }
+ break;
+ case MONITOR_STYLE_AUTOMATIC:
+ case MONITOR_STYLE_SCALED:
+ x_scale = (gdouble)pixbuf_width / (gdouble)gdk_pixbuf_get_width (tmp_pixbuf);
+ y_scale = (gdouble)pixbuf_height / (gdouble)gdk_pixbuf_get_height (tmp_pixbuf);
+ if (x_scale > y_scale)
+ {
+ x_scale = y_scale;
+ }
+ else
+ {
+ y_scale = x_scale;
+ }
+ dest_width = x_scale * (gdouble)gdk_pixbuf_get_width (tmp_pixbuf);
+ dest_height = y_scale * (gdouble)gdk_pixbuf_get_height (tmp_pixbuf);
+ dest_x = (gdouble)(pixbuf_width - gdk_pixbuf_get_width (tmp_pixbuf)*x_scale) / 2;
+ dest_y = (gdouble)(pixbuf_height - gdk_pixbuf_get_height (tmp_pixbuf)*y_scale) / 2;
+ break;
+ case MONITOR_STYLE_STRETCHED:
+ dest_x = 0;
+ dest_y = 0;
+ dest_width = pixbuf_width;
+ dest_height = pixbuf_height;
+ x_scale = (gdouble)dest_width / (gdouble)gdk_pixbuf_get_width (tmp_pixbuf);
+ y_scale = (gdouble)dest_height / (gdouble)gdk_pixbuf_get_height (tmp_pixbuf);
+ break;
+ default:
+ x_scale = (gdouble)pixbuf_width / (gdouble)gdk_pixbuf_get_width (tmp_pixbuf);
+ y_scale = (gdouble)pixbuf_height / (gdouble)gdk_pixbuf_get_height (tmp_pixbuf);
+ if (x_scale > y_scale)
+ {
+ x_scale = y_scale;
+ }
+ else
+ {
+ y_scale = x_scale;
+ }
+ dest_width = x_scale * (gdouble)gdk_pixbuf_get_width (tmp_pixbuf);
+ dest_height = y_scale * (gdouble)gdk_pixbuf_get_height (tmp_pixbuf);
+ dest_x = (gdouble)(pixbuf_width - dest_width) / 2;
+ dest_y = (gdouble)(pixbuf_height - dest_height) / 2;
+ gdk_pixbuf_saturate_and_pixelate (
+ tmp_pixbuf,
+ tmp_pixbuf,
+ 0.0,
+ TRUE);
+ }
+
+ gdk_pixbuf_composite (
+ tmp_pixbuf,
+ monitor_pixbuf,
+ dest_x,
+ dest_y,
+ dest_width,
+ dest_height,
+ 0.0,
+ 0.0,
+ x_scale,
+ y_scale,
+ GDK_INTERP_BILINEAR,
+ 255);
+
+ g_object_unref (tmp_pixbuf);
+ }
+ }
+
+ rstto_monitor_chooser_set_pixbuf (
+ RSTTO_MONITOR_CHOOSER(manager->priv->monitor_chooser),
+ manager->priv->monitor,
+ monitor_pixbuf,
+ NULL);
+
+ if ( NULL != monitor_pixbuf )
+ {
+ g_object_unref (monitor_pixbuf);
+ }
+}
+
+static void
+cb_style_combo_changed (
+ GtkComboBox *style_combo,
+ RsttoGnomeWallpaperManager *manager)
+{
+
+ manager->priv->style = gtk_combo_box_get_active (style_combo);
+
+ manager->priv->monitor = rstto_monitor_chooser_get_selected (
+ RSTTO_MONITOR_CHOOSER (manager->priv->monitor_chooser));
+
+ configure_monitor_chooser_pixbuf (manager);
+}
diff --git a/src/main_window.c b/src/main_window.c
index 94b138a..2a25027 100644
--- a/src/main_window.c
+++ b/src/main_window.c
@@ -1843,10 +1843,7 @@ cb_rstto_main_window_set_as_wallpaper (GtkWidget *widget, RsttoMainWindow *windo
GTK_COMBO_BOX (choose_desktop_combo_box)))
{
case DESKTOP_TYPE_NONE:
- rstto_settings_set_string_property (
- window->priv->settings_manager,
- "desktop-type",
- "none");
+ desktop_type = g_strdup ("none");
if (NULL != window->priv->wallpaper_manager)
{
g_object_unref (window->priv->wallpaper_manager);
@@ -1854,10 +1851,7 @@ cb_rstto_main_window_set_as_wallpaper (GtkWidget *widget, RsttoMainWindow *windo
}
break;
case DESKTOP_TYPE_XFCE:
- rstto_settings_set_string_property (
- window->priv->settings_manager,
- "desktop-type",
- "xfce");
+ desktop_type = g_strdup ("xfce");
if (NULL != window->priv->wallpaper_manager)
{
g_object_unref (window->priv->wallpaper_manager);
@@ -1865,10 +1859,7 @@ cb_rstto_main_window_set_as_wallpaper (GtkWidget *widget, RsttoMainWindow *windo
window->priv->wallpaper_manager = rstto_xfce_wallpaper_manager_new ();
break;
case DESKTOP_TYPE_GNOME:
- rstto_settings_set_string_property (
- window->priv->settings_manager,
- "desktop-type",
- "gnome");
+ desktop_type = g_strdup ("gnome");
if (NULL != window->priv->wallpaper_manager)
{
g_object_unref (window->priv->wallpaper_manager);
@@ -1876,6 +1867,10 @@ cb_rstto_main_window_set_as_wallpaper (GtkWidget *widget, RsttoMainWindow *windo
window->priv->wallpaper_manager = rstto_gnome_wallpaper_manager_new ();
break;
}
+ rstto_settings_set_string_property (
+ window->priv->settings_manager,
+ "desktop-type",
+ desktop_type);
}
@@ -1884,7 +1879,7 @@ cb_rstto_main_window_set_as_wallpaper (GtkWidget *widget, RsttoMainWindow *windo
dialog = NULL;
}
- if (window->priv->wallpaper_manager)
+ if (NULL != desktop_type && NULL != window->priv->wallpaper_manager)
{
/* Set the response to GTK_RESPONSE_APPLY,
* so we at least do one run.
More information about the Xfce4-commits
mailing list