File lightdm-gtk-greeter-improve-background-scaling.patch of Package lightdm-gtk-greeter

Index: lightdm-gtk-greeter-1.3.1/src/lightdm-gtk-greeter.c
===================================================================
--- lightdm-gtk-greeter-1.3.1.orig/src/lightdm-gtk-greeter.c
+++ lightdm-gtk-greeter-1.3.1/src/lightdm-gtk-greeter.c
@@ -10,6 +10,7 @@
  */
 
 #include <stdlib.h>
+#include <math.h>
 #include <locale.h>
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
@@ -819,9 +820,41 @@ main (int argc, char **argv)
 
             if (background_pixbuf)
             {
-                GdkPixbuf *pixbuf = gdk_pixbuf_scale_simple (background_pixbuf, monitor_geometry.width, monitor_geometry.height, GDK_INTERP_BILINEAR);
+                GdkPixbuf *pixbuf;
+                GdkPixbuf *scaled_pixbuf = NULL;
+                gdouble ratio_horiz, ratio_vert;
+                gint image_width, image_height, width, height;
+                gint offset_x = 0;
+                gint offset_y = 0;
+
+                image_width = gdk_pixbuf_get_width(background_pixbuf);
+                image_height = gdk_pixbuf_get_height(background_pixbuf);
+
+                if (image_width == monitor_geometry.width && image_height == monitor_geometry.height)
+                {
+                    pixbuf = gdk_pixbuf_copy (background_pixbuf);
+                } else {
+                    ratio_horiz = (gdouble) monitor_geometry.width / image_width;
+                    ratio_vert = (gdouble) monitor_geometry.height / image_height;
+                    if (ratio_vert > ratio_horiz)
+                    {
+                        width = (gint) round (image_width * ratio_vert);
+                        height = (gint) round (image_height * ratio_vert);
+                        offset_x = (gint) round (fabs ((gdouble) (monitor_geometry.width - width) / 2));
+                    }
+                    else
+                    {
+                        width = (gint) round (image_width * ratio_horiz);
+                        height = (gint) round (image_height * ratio_horiz);
+                        offset_y = (gint) round (fabs ((gdouble) (monitor_geometry.height - height) / 2));
+                    }
+                    scaled_pixbuf = gdk_pixbuf_scale_simple (background_pixbuf, width, height, GDK_INTERP_BILINEAR);
+                    pixbuf = gdk_pixbuf_new_subpixbuf (scaled_pixbuf, offset_x, offset_y, monitor_geometry.width, monitor_geometry.height);
+                }
                 gdk_cairo_set_source_pixbuf (c, pixbuf, monitor_geometry.x, monitor_geometry.y);
                 g_object_unref (pixbuf);
+                if (scaled_pixbuf)
+                    g_object_unref (scaled_pixbuf);
             }
             else
                 gdk_cairo_set_source_rgba (c, &background_color);
Index: lightdm-gtk-greeter-1.3.1/configure.ac
===================================================================
--- lightdm-gtk-greeter-1.3.1.orig/configure.ac
+++ lightdm-gtk-greeter-1.3.1/configure.ac
@@ -17,6 +17,9 @@ dnl ####################################
 dnl Dependencies
 dnl ###########################################################################
 
+AC_CHECK_HEADERS([math.h])
+AC_CHECK_LIB([m],[round])
+
 PKG_CHECK_MODULES(GREETER, [
     gtk+-3.0
     x11