PATCH: auto-fit for xfdesktop

Jasper Huijsmans jasper at moongroup.com
Sun Nov 30 20:07:37 CET 2003


Hi, 

I will have a look at it this next week. I reorganized the xfdesktop
code a bit, so I need to adapt the patch a little. 

Anyway, I believe what you call auto-fit is what is commonly known as a
'scaled' image and what we call scaled should in fact be called
'stretched'. Some native English speaker may correct me if I'm wrong.

I already added the STRETCHED style to CVS, but not the implementation
of the new scaled style. So, the end result should be:

TILED : image is tiled from top left to bottom right to fill the screen

CENTERED: image is centered on the screen, the free space is filled with
the background color.

STRETCHED: the image is stretched to fit the screen, without taking into
account the aspect ratio (what we currently call scaled).

SCALED: the image is scaled to fit the screen with the same aspect ratio
as the original. Any free space is filled with the background color.

AUTO: the image is tiled if it's smaller than 1/2 the screen width and
height, otherwise it's stretched.

Does that sound correct to you?

	Jasper

Op zo 30-11-2003, om 15:32 schreef Nagulan Selvakannu:
> 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"
> 
> ______________________________________________________________________
> _______________________________________________
> Xfce4-dev mailing list
> Xfce4-dev at xfce.org
> http://moongroup.com/mailman/listinfo/xfce4-dev




More information about the Xfce4-dev mailing list