gnome-screensaver r1476 - in trunk: . src



Author: mccann
Date: Fri Aug  8 14:29:24 2008
New Revision: 1476
URL: http://svn.gnome.org/viewvc/gnome-screensaver?rev=1476&view=rev

Log:
2008-08-08  William Jon McCann  <jmccann redhat com>

	* src/gs-lock-plug.c (surface_from_pixbuf), (curved_rectangle),
	(image_set_from_pixbuf), (check_user_file), (set_face_image),
	(gs_lock_plug_show), (gs_lock_plug_init):
	Paint widget background color as face background color.



Modified:
   trunk/ChangeLog
   trunk/src/gs-lock-plug.c

Modified: trunk/src/gs-lock-plug.c
==============================================================================
--- trunk/src/gs-lock-plug.c	(original)
+++ trunk/src/gs-lock-plug.c	Fri Aug  8 14:29:24 2008
@@ -484,6 +484,237 @@
         return ri.response_id;
 }
 
+
+static cairo_surface_t *
+surface_from_pixbuf (GdkPixbuf *pixbuf)
+{
+        cairo_surface_t *surface;
+        cairo_t         *cr;
+
+        surface = cairo_image_surface_create (gdk_pixbuf_get_has_alpha (pixbuf) ?
+                                              CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24,
+                                              gdk_pixbuf_get_width (pixbuf),
+                                              gdk_pixbuf_get_height (pixbuf));
+        cr = cairo_create (surface);
+        gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
+        cairo_paint (cr);
+        cairo_destroy (cr);
+
+        return surface;
+}
+
+static void
+curved_rectangle (cairo_t *cr,
+                  double   x0,
+                  double   y0,
+                  double   width,
+                  double   height,
+                  double   radius)
+{
+        double x1;
+        double y1;
+
+        x1 = x0 + width;
+        y1 = y0 + height;
+
+        if (!width || !height) {
+                return;
+        }
+
+        if (width / 2 < radius) {
+                if (height / 2 < radius) {
+                        cairo_move_to  (cr, x0, (y0 + y1) / 2);
+                        cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1) / 2, y0);
+                        cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1) / 2);
+                        cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0) / 2, y1);
+                        cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1) / 2);
+                } else {
+                        cairo_move_to  (cr, x0, y0 + radius);
+                        cairo_curve_to (cr, x0, y0, x0, y0, (x0 + x1) / 2, y0);
+                        cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
+                        cairo_line_to (cr, x1, y1 - radius);
+                        cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0) / 2, y1);
+                        cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - radius);
+                }
+        } else {
+                if (height / 2 < radius) {
+                        cairo_move_to  (cr, x0, (y0 + y1) / 2);
+                        cairo_curve_to (cr, x0, y0, x0 , y0, x0 + radius, y0);
+                        cairo_line_to (cr, x1 - radius, y0);
+                        cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1) / 2);
+                        cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
+                        cairo_line_to (cr, x0 + radius, y1);
+                        cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1) / 2);
+                } else {
+                        cairo_move_to  (cr, x0, y0 + radius);
+                        cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
+                        cairo_line_to (cr, x1 - radius, y0);
+                        cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
+                        cairo_line_to (cr, x1, y1 - radius);
+                        cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
+                        cairo_line_to (cr, x0 + radius, y1);
+                        cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - radius);
+                }
+        }
+
+        cairo_close_path (cr);
+}
+
+static void
+image_set_from_pixbuf (GtkImage  *image,
+                       GdkPixbuf *source)
+{
+        cairo_t         *cr;
+        cairo_t         *cr_mask;
+        cairo_surface_t *surface;
+        GdkPixmap       *pixmap;
+        GdkPixmap       *bitmask;
+        int              w;
+        int              h;
+        int              frame_width;
+        double           radius;
+        GdkColor         color;
+        double           r;
+        double           g;
+        double           b;
+
+        frame_width = 5;
+
+        w = gdk_pixbuf_get_width (source) + frame_width * 2;
+        h = gdk_pixbuf_get_height (source) + frame_width * 2;
+
+        radius = w / 3.0;
+
+        pixmap = gdk_pixmap_new (GTK_WIDGET (image)->window, w, h, -1);
+        bitmask = gdk_pixmap_new (GTK_WIDGET (image)->window, w, h, 1);
+
+        cr = gdk_cairo_create (pixmap);
+        cr_mask = gdk_cairo_create (bitmask);
+
+        /* setup mask */
+        cairo_rectangle (cr_mask, 0, 0, w, h);
+        cairo_set_operator (cr_mask, CAIRO_OPERATOR_CLEAR);
+        cairo_fill (cr_mask);
+
+        curved_rectangle (cr_mask, 0, 0, w, h, radius);
+        cairo_set_operator (cr_mask, CAIRO_OPERATOR_OVER);
+        cairo_set_source_rgb (cr_mask, 1, 1, 1);
+        cairo_fill (cr_mask);
+
+        color = GTK_WIDGET (image)->style->bg [GTK_STATE_NORMAL];
+        r = (float)color.red / 65535.0;
+        g = (float)color.green / 65535.0;
+        b = (float)color.blue / 65535.0;
+
+        /* set up image */
+        cairo_rectangle (cr, 0, 0, w, h);
+        cairo_set_source_rgb (cr, r, g, b);
+        cairo_fill (cr);
+
+        curved_rectangle (cr, frame_width, frame_width,
+                          w - frame_width * 2, h - frame_width * 2,
+                          radius);
+        cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.3);
+        cairo_fill_preserve (cr);
+
+        surface = surface_from_pixbuf (source);
+        cairo_set_source_surface (cr, surface, frame_width, frame_width);
+        cairo_fill (cr);
+
+        gtk_image_set_from_pixmap (image, pixmap, bitmask);
+
+        cairo_surface_destroy (surface);
+
+        gdk_pixmap_unref (bitmask);
+        gdk_pixmap_unref (pixmap);
+
+        cairo_destroy (cr_mask);
+        cairo_destroy (cr);
+}
+
+
+static gboolean
+check_user_file (const gchar *filename,
+                 uid_t        user,
+                 gssize       max_file_size,
+                 gboolean     relax_group,
+                 gboolean     relax_other)
+{
+        struct stat fileinfo;
+
+        if (max_file_size < 0) {
+                max_file_size = G_MAXSIZE;
+        }
+
+        /* Exists/Readable? */
+        if (g_stat (filename, &fileinfo) < 0) {
+                return FALSE;
+        }
+
+        /* Is a regular file */
+        if (G_UNLIKELY (!S_ISREG (fileinfo.st_mode))) {
+                return FALSE;
+        }
+
+        /* Owned by user? */
+        if (G_UNLIKELY (fileinfo.st_uid != user)) {
+                return FALSE;
+        }
+
+        /* Group not writable or relax_group? */
+        if (G_UNLIKELY ((fileinfo.st_mode & S_IWGRP) == S_IWGRP && !relax_group)) {
+                return FALSE;
+        }
+
+        /* Other not writable or relax_other? */
+        if (G_UNLIKELY ((fileinfo.st_mode & S_IWOTH) == S_IWOTH && !relax_other)) {
+                return FALSE;
+        }
+
+        /* Size is kosher? */
+        if (G_UNLIKELY (fileinfo.st_size > max_file_size)) {
+                return FALSE;
+        }
+
+        return TRUE;
+}
+
+static gboolean
+set_face_image (GSLockPlug *plug)
+{
+        GdkPixbuf    *pixbuf;
+        const char   *homedir;
+        char         *path;
+        int           icon_size = 96;
+        gsize         user_max_file = 65536;
+        uid_t         uid;
+
+        homedir = g_get_home_dir ();
+        uid = getuid ();
+
+        path = g_build_filename (homedir, ".face", NULL);
+
+        pixbuf = NULL;
+        if (check_user_file (path, uid, user_max_file, 0, 0)) {
+                pixbuf = gdk_pixbuf_new_from_file_at_size (path,
+                                                           icon_size,
+                                                           icon_size,
+                                                           NULL);
+        }
+
+        g_free (path);
+
+        if (pixbuf == NULL) {
+                return FALSE;
+        }
+
+        image_set_from_pixbuf (GTK_IMAGE (plug->priv->auth_face_image), pixbuf);
+
+        g_object_unref (pixbuf);
+
+        return TRUE;
+}
+
 static void
 gs_lock_plug_show (GtkWidget *widget)
 {
@@ -498,6 +729,11 @@
 
         gs_profile_end ("parent");
 
+
+        if (plug->priv->auth_face_image) {
+                set_face_image (plug);
+        }
+
         capslock_update (plug, is_capslock_on ());
 
         restart_cancel_timeout (plug);
@@ -1101,230 +1337,6 @@
         return utf8_name;
 }
 
-static gboolean
-check_user_file (const gchar *filename,
-                 uid_t        user,
-                 gssize       max_file_size,
-                 gboolean     relax_group,
-                 gboolean     relax_other)
-{
-        struct stat fileinfo;
-
-        if (max_file_size < 0) {
-                max_file_size = G_MAXSIZE;
-        }
-
-        /* Exists/Readable? */
-        if (g_stat (filename, &fileinfo) < 0) {
-                return FALSE;
-        }
-
-        /* Is a regular file */
-        if (G_UNLIKELY (!S_ISREG (fileinfo.st_mode))) {
-                return FALSE;
-        }
-
-        /* Owned by user? */
-        if (G_UNLIKELY (fileinfo.st_uid != user)) {
-                return FALSE;
-        }
-
-        /* Group not writable or relax_group? */
-        if (G_UNLIKELY ((fileinfo.st_mode & S_IWGRP) == S_IWGRP && !relax_group)) {
-                return FALSE;
-        }
-
-        /* Other not writable or relax_other? */
-        if (G_UNLIKELY ((fileinfo.st_mode & S_IWOTH) == S_IWOTH && !relax_other)) {
-                return FALSE;
-        }
-
-        /* Size is kosher? */
-        if (G_UNLIKELY (fileinfo.st_size > max_file_size)) {
-                return FALSE;
-        }
-
-        return TRUE;
-}
-
-static cairo_surface_t *
-surface_from_pixbuf (GdkPixbuf *pixbuf)
-{
-        cairo_surface_t *surface;
-        cairo_t         *cr;
-
-        surface = cairo_image_surface_create (gdk_pixbuf_get_has_alpha (pixbuf) ?
-                                              CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24,
-                                              gdk_pixbuf_get_width (pixbuf),
-                                              gdk_pixbuf_get_height (pixbuf));
-        cr = cairo_create (surface);
-        gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
-        cairo_paint (cr);
-        cairo_destroy (cr);
-
-        return surface;
-}
-
-static void
-curved_rectangle (cairo_t *cr,
-                  double   x0,
-                  double   y0,
-                  double   width,
-                  double   height,
-                  double   radius)
-{
-        double x1;
-        double y1;
-
-        x1 = x0 + width;
-        y1 = y0 + height;
-
-        if (!width || !height) {
-                return;
-        }
-
-        if (width / 2 < radius) {
-                if (height / 2 < radius) {
-                        cairo_move_to  (cr, x0, (y0 + y1) / 2);
-                        cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1) / 2, y0);
-                        cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1) / 2);
-                        cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0) / 2, y1);
-                        cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1) / 2);
-                } else {
-                        cairo_move_to  (cr, x0, y0 + radius);
-                        cairo_curve_to (cr, x0, y0, x0, y0, (x0 + x1) / 2, y0);
-                        cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
-                        cairo_line_to (cr, x1, y1 - radius);
-                        cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0) / 2, y1);
-                        cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - radius);
-                }
-        } else {
-                if (height / 2 < radius) {
-                        cairo_move_to  (cr, x0, (y0 + y1) / 2);
-                        cairo_curve_to (cr, x0, y0, x0 , y0, x0 + radius, y0);
-                        cairo_line_to (cr, x1 - radius, y0);
-                        cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1) / 2);
-                        cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
-                        cairo_line_to (cr, x0 + radius, y1);
-                        cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1) / 2);
-                } else {
-                        cairo_move_to  (cr, x0, y0 + radius);
-                        cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
-                        cairo_line_to (cr, x1 - radius, y0);
-                        cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
-                        cairo_line_to (cr, x1, y1 - radius);
-                        cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
-                        cairo_line_to (cr, x0 + radius, y1);
-                        cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - radius);
-                }
-        }
-
-        cairo_close_path (cr);
-}
-
-static void
-image_set_from_pixbuf (GtkImage  *image,
-                       GdkPixbuf *source)
-{
-        cairo_t         *cr;
-        cairo_t         *cr_mask;
-        cairo_surface_t *surface;
-        GdkPixmap       *pixmap;
-        GdkPixmap       *bitmask;
-        int              w;
-        int              h;
-        int              depth;
-        int              frame_width;
-        double           radius;
-
-        frame_width = 5;
-
-        w = gdk_pixbuf_get_width (source) + frame_width * 2;
-        h = gdk_pixbuf_get_height (source) + frame_width * 2;
-        depth = gdk_visual_get_system ()->depth;
-
-        radius = w / 3.0;
-
-        gs_debug ("creating pixmap w:%d h:%d d:%d", w, h, depth);
-        pixmap = gdk_pixmap_new (GTK_WIDGET (image)->window, w, h, depth);
-        bitmask = gdk_pixmap_new (GTK_WIDGET (image)->window, w, h, 1);
-
-        cr = gdk_cairo_create (pixmap);
-        cr_mask = gdk_cairo_create (bitmask);
-
-        /* setup mask */
-        cairo_rectangle (cr_mask, 0, 0, w, h);
-        cairo_set_operator (cr_mask, CAIRO_OPERATOR_CLEAR);
-        cairo_fill (cr_mask);
-
-        curved_rectangle (cr_mask, 0, 0, w, h, radius);
-        cairo_set_operator (cr_mask, CAIRO_OPERATOR_OVER);
-        cairo_set_source_rgb (cr_mask, 1, 1, 1);
-        cairo_fill (cr_mask);
-
-        /* set up image */
-        cairo_rectangle (cr, 0, 0, w, h);
-        cairo_set_source_rgb (cr, 0.8, 0.8, 0.8);
-        cairo_fill (cr);
-
-        curved_rectangle (cr, frame_width, frame_width,
-                          w - frame_width * 2, h - frame_width * 2,
-                          radius);
-        cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
-        cairo_fill_preserve (cr);
-
-        surface = surface_from_pixbuf (source);
-        cairo_set_source_surface (cr, surface, frame_width, frame_width);
-        cairo_fill (cr);
-
-        gtk_image_set_from_pixmap (image, pixmap, bitmask);
-
-        cairo_surface_destroy (surface);
-
-        gdk_pixmap_unref (bitmask);
-        gdk_pixmap_unref (pixmap);
-
-        cairo_destroy (cr_mask);
-        cairo_destroy (cr);
-}
-
-
-static gboolean
-set_face_image (GSLockPlug *plug)
-{
-        GdkPixbuf    *pixbuf;
-        const char   *homedir;
-        char         *path;
-        int           icon_size = 96;
-        gsize         user_max_file = 65536;
-        uid_t         uid;
-
-        homedir = g_get_home_dir ();
-        uid = getuid ();
-
-        path = g_build_filename (homedir, ".face", NULL);
-
-        pixbuf = NULL;
-        if (check_user_file (path, uid, user_max_file, 0, 0)) {
-                pixbuf = gdk_pixbuf_new_from_file_at_size (path,
-                                                           icon_size,
-                                                           icon_size,
-                                                           NULL);
-        }
-
-        g_free (path);
-
-        if (pixbuf == NULL) {
-                return FALSE;
-        }
-
-        image_set_from_pixbuf (GTK_IMAGE (plug->priv->auth_face_image), pixbuf);
-
-        g_object_unref (pixbuf);
-
-        return TRUE;
-}
-
 static void
 create_page_one_buttons (GSLockPlug *plug)
 {
@@ -1898,10 +1910,6 @@
                                   G_CALLBACK (logout_button_clicked), plug);
         }
 
-        if (plug->priv->auth_face_image) {
-                set_face_image (plug);
-        }
-
         g_signal_connect (plug, "delete_event", G_CALLBACK (delete_handler), NULL);
 
         gs_profile_end (NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]