PATCH: auto-fit for xfdesktop

Nagulan Selvakannu fundabonka at yahoo.co.uk
Sun Nov 30 15:32:27 CET 2003


I added a few lines to xfdesktop to enable it to auto fit a picture to the background. This is my first time sending in a patch to an open source project, i hope i did do it the rigth way. Here's the diff command that i ran
 
 diff -urN xfdesktop-4.0.0/ xfdesktop-4.0.0-nagulan/ > /tmp/patch-xfdesktop-4.0.0
 
and here is the diff contents
 

diff -urN xfdesktop-4.0.0/common/backdrop.h xfdesktop-4.0.0-nagulan/common/backdrop.h

--- xfdesktop-4.0.0/common/backdrop.h 2003-03-15 00:46:07.000000000 +0800

+++ xfdesktop-4.0.0-nagulan/common/backdrop.h 2003-11-30 21:07:16.000000000 +0800

@@ -32,6 +32,7 @@

SCALED,

CENTERED,

AUTO,

+ AUTO_FIT,

NONE

};



diff -urN xfdesktop-4.0.0/settings/backdrop_settings.c xfdesktop-4.0.0-nagulan/settings/backdrop_settings.c

--- xfdesktop-4.0.0/settings/backdrop_settings.c 2003-09-20 04:47:05.000000000 +0800

+++ xfdesktop-4.0.0-nagulan/settings/backdrop_settings.c 2003-11-29 13:08:01.000000000 +0800

@@ -737,9 +737,9 @@

static void

add_style_options(GtkWidget *vbox, GtkSizeGroup *sg, BackdropDialog *bd)

{

- GtkWidget *hbox, *label, *rb_tiled, *rb_scaled, *rb_centered, *rb_auto;

+ GtkWidget *hbox, *label, *rb_tiled, *rb_scaled, *rb_auto_fit, *rb_centered, *rb_auto;

GtkWidget *menu, *omenu;

- 

+

hbox = gtk_hbox_new(FALSE, BORDER);

gtk_widget_show(hbox);

gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);

@@ -757,27 +757,34 @@

gtk_widget_show(rb_tiled);

gtk_menu_shell_append(GTK_MENU_SHELL(menu), rb_tiled);

g_signal_connect(rb_tiled, "activate", G_CALLBACK(set_style), bd);

- 

+

rb_scaled = gtk_menu_item_new_with_mnemonic(_("_Scaled"));

g_object_set_data(G_OBJECT(rb_scaled), "user-data",

GUINT_TO_POINTER(SCALED));

gtk_widget_show(rb_scaled);

gtk_menu_shell_append(GTK_MENU_SHELL(menu), rb_scaled);

g_signal_connect(rb_scaled, "activate", G_CALLBACK(set_style), bd);

- 

+

rb_centered = gtk_menu_item_new_with_mnemonic(_("_Centered"));

g_object_set_data(G_OBJECT(rb_centered), "user-data",

GUINT_TO_POINTER(CENTERED));

gtk_widget_show(rb_centered);

gtk_menu_shell_append(GTK_MENU_SHELL(menu), rb_centered);

g_signal_connect(rb_centered, "activate", G_CALLBACK(set_style), bd);

- 

+

rb_auto = gtk_menu_item_new_with_mnemonic(_("_Auto"));

g_object_set_data(G_OBJECT(rb_auto), "user-data", GUINT_TO_POINTER(AUTO));

gtk_widget_show(rb_auto);

gtk_menu_shell_append(GTK_MENU_SHELL(menu), rb_auto);

g_signal_connect(rb_auto, "activate", G_CALLBACK(set_style), bd);

- 

+

+ rb_auto_fit = gtk_menu_item_new_with_mnemonic(_("Auto _Fit"));

+ g_object_set_data(G_OBJECT(rb_auto_fit), "user-data",

+ GUINT_TO_POINTER(AUTO_FIT));

+ gtk_widget_show(rb_auto_fit);

+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), rb_auto_fit);

+ g_signal_connect(rb_auto_fit, "activate", G_CALLBACK(set_style), bd);

+

bd->style_om = omenu = gtk_option_menu_new();

gtk_option_menu_set_menu(GTK_OPTION_MENU(omenu), menu);

gtk_option_menu_set_history(GTK_OPTION_MENU(omenu), backdrop_style);

diff -urN xfdesktop-4.0.0/src/backdrop.c xfdesktop-4.0.0-nagulan/src/backdrop.c

--- xfdesktop-4.0.0/src/backdrop.c 2003-07-26 06:15:02.000000000 +0800

+++ xfdesktop-4.0.0-nagulan/src/backdrop.c 2003-11-30 21:28:58.000000000 +0800

@@ -64,6 +64,8 @@



#include <backdrop.h>



+#include <stdio.h>

+

#include "main.h"

#include "settings.h"



@@ -326,6 +328,7 @@

return files[(previndex = i)];

}



+

static GdkPixmap *

create_background_pixmap (GdkPixbuf * pixbuf, int style, GdkColor * color)

{

@@ -414,6 +417,71 @@

g_object_unref (new);

}

break;

+ /* Added by Nagulan Selvakannu 

+ * ---------------------------

+ * if picture is then

+ * use the screen width and scale the picture height

+ * else

+ * use the screen height and scale the picture width

+ * 

+ * That is what i basically added. I used some code from the CENTRE method above

+ * to center the resulting picture. I hope it works and now i can put a list of

+ * all those irregular sized pictures to the wallpaper list ;P 

+ */

+ case AUTO_FIT:

+ {

+

+ GdkPixbuf *new = pixbuf;

+

+ int pixbuf_width = gdk_pixbuf_get_width (pixbuf);

+ int pixbuf_height = gdk_pixbuf_get_height (pixbuf);

+ int scale_width = 0; int scale_height = 0;

+

+ /* A dirty hack to prevent division by zero later on in the scaling */

+ if (pixbuf_height == 0)

+ pixbuf_height = 1;

+

+ if (pixbuf_width == 0)

+ pixbuf_width = 1;

+

+

+ if (pixbuf_height >= pixbuf_width)

+ {

+ scale_height = screen_height;

+ scale_width = (float)pixbuf_width / (float)pixbuf_height * screen_height;

+ }

+ else

+ {

+ scale_width = screen_width;

+ scale_height = (float)pixbuf_height / (float)pixbuf_width * screen_width;

+ }

+

+ 

+ new =

+ gdk_pixbuf_scale_simple (pixbuf, scale_width,

+ scale_height,

+ GDK_INTERP_BILINEAR);

+

+ gint x = MAX ((screen_width - scale_width) / 2, 0);

+ gint y = MAX ((screen_height - scale_height) / 2, 0);

+ if (has_composite)

+ {

+ gdk_pixbuf_composite (new, solid, x, y,

+ MIN (screen_width, scale_width),

+ MIN (screen_height, scale_height), x,

+ y, 1.0, 1.0, GDK_INTERP_NEAREST,

+ 255);

+ }

+ else

+ {

+ gdk_pixbuf_copy_area (new, 0, 0,

+ MIN (screen_width, scale_width),

+ MIN (screen_height, scale_height),

+ solid, x, y);

+ }

+ g_object_unref (new);

+ }

+ break;

default:

case TILED:

{



---------------------------------
Download Yahoo! Messenger now for a chance to WIN Robbie Williams "Live At Knebworth DVD"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.xfce.org/pipermail/xfce4-dev/attachments/20031130/28389ab7/attachment.html>


More information about the Xfce4-dev mailing list