From 616d84c77003cdd169963249793d765f22eb5ffe Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Thu, 5 Aug 2021 11:21:12 -0300 Subject: Change the default user avatar creation prioritizing the GtkPixbuf. Add a unique return of the function, in order to be able to modify the user's personal photos and also the default images. Also add as fallback the stock_person icon. Used in older themes. --- src/lightdm-gtk-greeter.c | 81 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/lightdm-gtk-greeter.c b/src/lightdm-gtk-greeter.c index cefa348..9f988a8 100644 --- a/src/lightdm-gtk-greeter.c +++ b/src/lightdm-gtk-greeter.c @@ -794,6 +794,68 @@ set_message_label (LightDMMessageType type, const gchar *text) /* User image */ +static GdkPixbuf * +get_default_user_image (void) +{ + GtkIconTheme *icon_theme; + GdkPixbuf *image = NULL; + GError *error = NULL; + + if (default_user_pixbuf) + { + return default_user_pixbuf; + } + + icon_theme = gtk_icon_theme_get_default (); + + /* Use icon from settings */ + image = gtk_icon_theme_load_icon (icon_theme, + default_user_icon, + 80, + GTK_ICON_LOOKUP_FORCE_SIZE, + &error); + + if (!image) + { + g_warning ("Failed to load default user image from icon theme: %s", error->message); + g_clear_error (&error); + } + + /* Fallback to avatar-default icon from theme */ + if (!image) + { + image = gtk_icon_theme_load_icon (icon_theme, + "avatar-default", + 80, + GTK_ICON_LOOKUP_FORCE_SIZE, + &error); + + if (error != NULL) + { + g_warning ("Failed to load fallback user image: %s", error->message); + g_clear_error (&error); + } + } + + /* Fallback again to old stock_person icon from theme */ + if (!image) + { + image = gtk_icon_theme_load_icon (icon_theme, + "stock_person", + 80, + GTK_ICON_LOOKUP_FORCE_SIZE, + &error); + + if (error != NULL) + { + g_warning ("Failed to load old fallback user image: %s", error->message); + g_clear_error (&error); + } + } + + return image; +} + static void set_user_image (const gchar *username) { @@ -814,13 +876,7 @@ set_user_image (const gchar *username) if (path) { image = gdk_pixbuf_new_from_file_at_scale (path, 80, 80, FALSE, &error); - if (image) - { - gtk_image_set_from_pixbuf (GTK_IMAGE (user_image), image); - g_object_unref (image); - return; - } - else + if (!image) { g_debug ("Failed to load user image: %s", error->message); g_clear_error (&error); @@ -828,10 +884,13 @@ set_user_image (const gchar *username) } } - if (default_user_pixbuf) - gtk_image_set_from_pixbuf (GTK_IMAGE (user_image), default_user_pixbuf); - else - gtk_image_set_from_icon_name (GTK_IMAGE (user_image), default_user_icon, GTK_ICON_SIZE_DIALOG); + if (!image) + { + image = get_default_user_image (); + } + + gtk_image_set_from_pixbuf (GTK_IMAGE (user_image), image); + g_object_unref (image); } /* MenuCommand */ -- cgit v1.2.1 From a61131592abff3b7a992f3b91f18ff170a25dea6 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Thu, 5 Aug 2021 19:25:28 -0300 Subject: Refactor user image code. Move the code to its own file. Don't save the name of the icon, nor the pixbuf of the image by default. The advantage of saving them is minimal, and the avatar for each user are generated just when necessary, so we can do the same. --- src/Makefile.am | 2 + src/greeteruserimage.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++ src/greeteruserimage.h | 30 ++++++++++ src/lightdm-gtk-greeter.c | 106 +---------------------------------- 4 files changed, 171 insertions(+), 104 deletions(-) create mode 100644 src/greeteruserimage.c create mode 100644 src/greeteruserimage.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 5325a36..861b5d1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,6 +24,8 @@ lightdm_gtk_greeter_SOURCES = \ lightdm-gtk-greeter.c \ greeterbackground.c \ greeterbackground.h \ + greeteruserimage.c \ + greeteruserimage.h \ greeterconfiguration.c \ greeterconfiguration.h \ greetermenubar.c \ diff --git a/src/greeteruserimage.c b/src/greeteruserimage.c new file mode 100644 index 0000000..899b2bf --- /dev/null +++ b/src/greeteruserimage.c @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2010 - 2011, Robert Ancell + * Copyright (C) 2011, Gunnar Hjalmarsson + * Copyright (C) 2012 - 2013, Lionel Le Folgoc + * Copyright (C) 2012, Julien Lavergne + * Copyright (C) 2013 - 2015, Simon Steinbeiß + * Copyright (C) 2013 - 2020, Sean Davis + * Copyright (C) 2014, Andrew P. + * + * 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 the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. See http://www.gnu.org/copyleft/gpl.html the full text of the + * license. + */ + +#include + +#include "greeterconfiguration.h" +#include "greeteruserimage.h" + +static GdkPixbuf * +get_default_user_image_from_settings (void) +{ + GdkPixbuf *image = NULL; + gchar *value = NULL; + GError *error = NULL; + + value = config_get_string (NULL, CONFIG_KEY_DEFAULT_USER_IMAGE, NULL); + if (!value) + return NULL; + + if (value[0] == '/') + { + image = gdk_pixbuf_new_from_file_at_scale (value, + 80, 80, + FALSE, + &error); + + if (!image) + { + g_warning ("Failed to load default user image from path: %s", error->message); + g_clear_error (&error); + } + } + else if (value[0] == '#') + { + image = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), + value + 1, + 80, + GTK_ICON_LOOKUP_FORCE_SIZE, + &error); + + if (!image) + { + g_warning ("Failed to load default user image from icon theme: %s", error->message); + g_clear_error (&error); + } + } + + g_free (value); + + return image; +} + +GdkPixbuf * +get_default_user_image (void) +{ + GdkPixbuf *image = NULL; + GError *error = NULL; + + /* If a file is set by preferences, it must be prioritized. */ + image = get_default_user_image_from_settings (); + + /* Fallback to avatar-default icon from theme */ + if (!image) + { + image = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), + "avatar-default", + 80, + GTK_ICON_LOOKUP_FORCE_SIZE, + &error); + + if (error != NULL) + { + g_warning ("Failed to load fallback user image: %s", error->message); + g_clear_error (&error); + } + } + + /* Fallback again to old stock_person icon from theme */ + if (!image) + { + image = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), + "stock_person", + 80, + GTK_ICON_LOOKUP_FORCE_SIZE, + &error); + + if (error != NULL) + { + g_warning ("Failed to load old fallback user image: %s", error->message); + g_clear_error (&error); + } + } + + return image; +} + +GdkPixbuf * +get_user_image (const gchar *username) +{ + LightDMUser *user = NULL; + GdkPixbuf *image = NULL; + GError *error = NULL; + const gchar *path; + + user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), username); + if (user) + { + path = lightdm_user_get_image (user); + if (path) + { + image = gdk_pixbuf_new_from_file_at_scale (path, + 80, 80, + FALSE, + &error); + if (!image) + { + g_debug ("Failed to load user image: %s", error->message); + g_clear_error (&error); + } + } + } + return image; +} + diff --git a/src/greeteruserimage.h b/src/greeteruserimage.h new file mode 100644 index 0000000..57c70aa --- /dev/null +++ b/src/greeteruserimage.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2010 - 2011, Robert Ancell + * Copyright (C) 2011, Gunnar Hjalmarsson + * Copyright (C) 2012 - 2013, Lionel Le Folgoc + * Copyright (C) 2012, Julien Lavergne + * Copyright (C) 2013 - 2015, Simon Steinbeiß + * Copyright (C) 2013 - 2020, Sean Davis + * Copyright (C) 2014, Andrew P. + * + * 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 the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. See http://www.gnu.org/copyleft/gpl.html the full text of the + * license. + */ + +#ifndef GREETER_USER_IMAGE_H +#define GREETER_USER_IMAGE_H + +#include + +G_BEGIN_DECLS + +GdkPixbuf *get_default_user_image (void); + +GdkPixbuf *get_user_image (const gchar *username); + +G_END_DECLS + +#endif // GREETER_USER_IMAGE_H diff --git a/src/lightdm-gtk-greeter.c b/src/lightdm-gtk-greeter.c index 9f988a8..4628d8f 100644 --- a/src/lightdm-gtk-greeter.c +++ b/src/lightdm-gtk-greeter.c @@ -67,6 +67,7 @@ #include "src/greeterconfiguration.h" #include "src/greetermenubar.h" #include "src/greeterbackground.h" +#include "src/greeteruserimage.h" #include "src/lightdm-gtk-greeter-ui.h" #include "src/lightdm-gtk-greeter-css-fallback.h" #include "src/lightdm-gtk-greeter-css-application.h" @@ -162,8 +163,6 @@ static gboolean message_label_is_empty (void); static void set_message_label (LightDMMessageType type, const gchar *text); /* User image */ -static GdkPixbuf *default_user_pixbuf = NULL; -static gchar *default_user_icon = NULL; static void set_user_image (const gchar *username); /* External command (keyboard, reader) */ @@ -794,94 +793,17 @@ set_message_label (LightDMMessageType type, const gchar *text) /* User image */ -static GdkPixbuf * -get_default_user_image (void) -{ - GtkIconTheme *icon_theme; - GdkPixbuf *image = NULL; - GError *error = NULL; - - if (default_user_pixbuf) - { - return default_user_pixbuf; - } - - icon_theme = gtk_icon_theme_get_default (); - - /* Use icon from settings */ - image = gtk_icon_theme_load_icon (icon_theme, - default_user_icon, - 80, - GTK_ICON_LOOKUP_FORCE_SIZE, - &error); - - if (!image) - { - g_warning ("Failed to load default user image from icon theme: %s", error->message); - g_clear_error (&error); - } - - /* Fallback to avatar-default icon from theme */ - if (!image) - { - image = gtk_icon_theme_load_icon (icon_theme, - "avatar-default", - 80, - GTK_ICON_LOOKUP_FORCE_SIZE, - &error); - - if (error != NULL) - { - g_warning ("Failed to load fallback user image: %s", error->message); - g_clear_error (&error); - } - } - - /* Fallback again to old stock_person icon from theme */ - if (!image) - { - image = gtk_icon_theme_load_icon (icon_theme, - "stock_person", - 80, - GTK_ICON_LOOKUP_FORCE_SIZE, - &error); - - if (error != NULL) - { - g_warning ("Failed to load old fallback user image: %s", error->message); - g_clear_error (&error); - } - } - - return image; -} - static void set_user_image (const gchar *username) { - const gchar *path; - LightDMUser *user = NULL; GdkPixbuf *image = NULL; - GError *error = NULL; if (!gtk_widget_get_visible (GTK_WIDGET (user_image))) return; if (username) - user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), username); - - if (user) { - path = lightdm_user_get_image (user); - if (path) - { - image = gdk_pixbuf_new_from_file_at_scale (path, 80, 80, FALSE, &error); - if (!image) - { - g_debug ("Failed to load user image: %s", error->message); - g_clear_error (&error); - } - } + image = get_user_image (username); } if (!image) @@ -2958,8 +2880,6 @@ main (int argc, char **argv) g_unix_signal_add (SIGTERM, (GSourceFunc)sigterm_cb, /* is_callback */ GINT_TO_POINTER (TRUE)); - default_user_icon = g_strdup("avatar-default"); - config_init (); if (config_get_bool (NULL, CONFIG_KEY_DEBUGGING, FALSE)) @@ -3195,28 +3115,6 @@ main (int argc, char **argv) gtk_widget_hide (GTK_WIDGET (user_image)); /* Hide to mark image is disabled */ gtk_widget_set_size_request (GTK_WIDGET (user_combo), 250, -1); } - else - { - value = config_get_string (NULL, CONFIG_KEY_DEFAULT_USER_IMAGE, NULL); - if (value) - { - if (value[0] == '#') - { - g_free (default_user_icon); - default_user_icon = g_strdup (value + 1); - } - else - { - default_user_pixbuf = gdk_pixbuf_new_from_file_at_scale (value, 80, 80, FALSE, &error); - if (!default_user_pixbuf) - { - g_warning ("Failed to load default user image: %s", error->message); - g_clear_error (&error); - } - } - g_free (value); - } - } icon_theme = gtk_icon_theme_get_default (); -- cgit v1.2.1 From b6b100e345ab7d041e13ea915bb7e8aa8eb6c871 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Fri, 6 Aug 2021 08:53:43 -0300 Subject: Add option to round user avatars. This last code is based on the gnome-control-center user panel. --- src/greeterconfiguration.h | 1 + src/greeteruserimage.c | 52 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/greeterconfiguration.h b/src/greeterconfiguration.h index 587226d..fdc2453 100644 --- a/src/greeterconfiguration.h +++ b/src/greeterconfiguration.h @@ -29,6 +29,7 @@ #define CONFIG_KEY_RGBA "xft-rgba" #define CONFIG_KEY_HIDE_USER_IMAGE "hide-user-image" #define CONFIG_KEY_DEFAULT_USER_IMAGE "default-user-image" +#define CONFIG_KEY_ROUND_USER_IMAGE "round-user-image" #define CONFIG_KEY_KEYBOARD "keyboard" #define CONFIG_KEY_READER "reader" #define CONFIG_KEY_CLOCK_FORMAT "clock-format" diff --git a/src/greeteruserimage.c b/src/greeteruserimage.c index 899b2bf..64666b1 100644 --- a/src/greeteruserimage.c +++ b/src/greeteruserimage.c @@ -19,6 +19,33 @@ #include "greeterconfiguration.h" #include "greeteruserimage.h" +static GdkPixbuf * +round_image (GdkPixbuf *pixbuf) +{ + GdkPixbuf *dest = NULL; + cairo_surface_t *surface; + cairo_t *cr; + gint size; + + size = gdk_pixbuf_get_width (pixbuf); + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size, size); + cr = cairo_create (surface); + + /* Clip a circle */ + cairo_arc (cr, size/2, size/2, size/2, 0, 2 * G_PI); + cairo_clip (cr); + cairo_new_path (cr); + + gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); + cairo_paint (cr); + + dest = gdk_pixbuf_get_from_surface (surface, 0, 0, size, size); + cairo_surface_destroy (surface); + cairo_destroy (cr); + + return dest; +} + static GdkPixbuf * get_default_user_image_from_settings (void) { @@ -66,7 +93,7 @@ get_default_user_image_from_settings (void) GdkPixbuf * get_default_user_image (void) { - GdkPixbuf *image = NULL; + GdkPixbuf *temp_image = NULL, *image = NULL; GError *error = NULL; /* If a file is set by preferences, it must be prioritized. */ @@ -104,6 +131,16 @@ get_default_user_image (void) } } + if (image && config_get_bool (NULL, CONFIG_KEY_ROUND_USER_IMAGE, TRUE)) + { + temp_image = round_image (image); + if (temp_image != NULL) + { + g_object_unref (image); + image = temp_image; + } + } + return image; } @@ -111,7 +148,7 @@ GdkPixbuf * get_user_image (const gchar *username) { LightDMUser *user = NULL; - GdkPixbuf *image = NULL; + GdkPixbuf *temp_image = NULL, *image = NULL; GError *error = NULL; const gchar *path; @@ -132,6 +169,17 @@ get_user_image (const gchar *username) } } } + + if (image && config_get_bool (NULL, CONFIG_KEY_ROUND_USER_IMAGE, TRUE)) + { + temp_image = round_image (image); + if (temp_image != NULL) + { + g_object_unref (image); + image = temp_image; + } + } + return image; } -- cgit v1.2.1 From ff843ff6c16f552cb2a7d594bcd100490f7e45f1 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Fri, 6 Aug 2021 09:09:31 -0300 Subject: Change the hardcoded icon size around the code, to use a unique define. It allows to change it easier if necessary. It could probably be configurable, but it is outside of this PR. --- src/greeteruserimage.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/greeteruserimage.c b/src/greeteruserimage.c index 64666b1..5ce7ad4 100644 --- a/src/greeteruserimage.c +++ b/src/greeteruserimage.c @@ -19,6 +19,8 @@ #include "greeterconfiguration.h" #include "greeteruserimage.h" +#define USER_IMAGE_SIZE 80 + static GdkPixbuf * round_image (GdkPixbuf *pixbuf) { @@ -60,7 +62,8 @@ get_default_user_image_from_settings (void) if (value[0] == '/') { image = gdk_pixbuf_new_from_file_at_scale (value, - 80, 80, + USER_IMAGE_SIZE, + USER_IMAGE_SIZE, FALSE, &error); @@ -74,7 +77,7 @@ get_default_user_image_from_settings (void) { image = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), value + 1, - 80, + USER_IMAGE_SIZE, GTK_ICON_LOOKUP_FORCE_SIZE, &error); @@ -104,7 +107,7 @@ get_default_user_image (void) { image = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "avatar-default", - 80, + USER_IMAGE_SIZE, GTK_ICON_LOOKUP_FORCE_SIZE, &error); @@ -120,7 +123,7 @@ get_default_user_image (void) { image = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "stock_person", - 80, + USER_IMAGE_SIZE, GTK_ICON_LOOKUP_FORCE_SIZE, &error); @@ -159,7 +162,8 @@ get_user_image (const gchar *username) if (path) { image = gdk_pixbuf_new_from_file_at_scale (path, - 80, 80, + USER_IMAGE_SIZE, + USER_IMAGE_SIZE, FALSE, &error); if (!image) -- cgit v1.2.1 From fc6390c61edf16954a7e41f6fb96481323ade9e6 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Fri, 6 Aug 2021 09:31:27 -0300 Subject: Add a couple of macros to improve the readability of the code. When I just started this PR, I don't understand why these comparisons, and with this it is clearer. --- src/greeteruserimage.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/greeteruserimage.c b/src/greeteruserimage.c index 5ce7ad4..838707c 100644 --- a/src/greeteruserimage.c +++ b/src/greeteruserimage.c @@ -21,6 +21,13 @@ #define USER_IMAGE_SIZE 80 +#define VALUE_IS_ICON_PATH(v) (v[0] == '/') +#define VALUE_ICON_PATH(v) (v) + +#define VALUE_IS_ICON_NAME(v) (v[0] == '#') +#define VALUE_ICON_NAME(v) (v + 1) + + static GdkPixbuf * round_image (GdkPixbuf *pixbuf) { @@ -59,9 +66,9 @@ get_default_user_image_from_settings (void) if (!value) return NULL; - if (value[0] == '/') + if (VALUE_IS_ICON_PATH(value)) { - image = gdk_pixbuf_new_from_file_at_scale (value, + image = gdk_pixbuf_new_from_file_at_scale (VALUE_ICON_PATH(value), USER_IMAGE_SIZE, USER_IMAGE_SIZE, FALSE, @@ -73,10 +80,10 @@ get_default_user_image_from_settings (void) g_clear_error (&error); } } - else if (value[0] == '#') + else if (VALUE_IS_ICON_NAME(value)) { image = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), - value + 1, + VALUE_ICON_NAME(value), USER_IMAGE_SIZE, GTK_ICON_LOOKUP_FORCE_SIZE, &error); -- cgit v1.2.1 From a322634bac957bf68205740cc602031ef2a51710 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Tue, 12 Oct 2021 19:23:00 -0300 Subject: Add another option to highlight the logged in user. This adds an emblem to easily highlight the image of the user. it is very similar to what many dialogs use. --- src/greeterconfiguration.h | 1 + src/greeteruserimage.c | 82 ++++++++++++++++++++++++++++++++++++++-------- src/greeteruserimage.h | 4 +-- src/lightdm-gtk-greeter.c | 11 +------ 4 files changed, 72 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/greeterconfiguration.h b/src/greeterconfiguration.h index fdc2453..9e1b452 100644 --- a/src/greeterconfiguration.h +++ b/src/greeterconfiguration.h @@ -30,6 +30,7 @@ #define CONFIG_KEY_HIDE_USER_IMAGE "hide-user-image" #define CONFIG_KEY_DEFAULT_USER_IMAGE "default-user-image" #define CONFIG_KEY_ROUND_USER_IMAGE "round-user-image" +#define CONFIG_KEY_HIGHLIGHT_LOGGED_USER "highlight-logged-user" #define CONFIG_KEY_KEYBOARD "keyboard" #define CONFIG_KEY_READER "reader" #define CONFIG_KEY_CLOCK_FORMAT "clock-format" diff --git a/src/greeteruserimage.c b/src/greeteruserimage.c index 838707c..72674d5 100644 --- a/src/greeteruserimage.c +++ b/src/greeteruserimage.c @@ -21,6 +21,9 @@ #define USER_IMAGE_SIZE 80 +#define LOGGED_IN_EMBLEM_SIZE 20 +#define LOGGED_IN_EMBLEM_ICON "emblem-default" + #define VALUE_IS_ICON_PATH(v) (v[0] == '/') #define VALUE_ICON_PATH(v) (v) @@ -55,6 +58,48 @@ round_image (GdkPixbuf *pixbuf) return dest; } +static GdkPixbuf * +logged_in_pixbuf (GdkPixbuf *pixbuf) +{ + GdkPixbuf *composite = NULL, *emblem = NULL; + gint width, height; + GError *error = NULL; + + emblem = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), + LOGGED_IN_EMBLEM_ICON, + LOGGED_IN_EMBLEM_SIZE, + GTK_ICON_LOOKUP_FORCE_SIZE, + &error); + + if (!emblem) + { + g_warning ("Failed to load the logged icon: %s", error->message); + g_clear_error (&error); + return NULL; + } + + composite = gdk_pixbuf_copy (pixbuf); + + width = gdk_pixbuf_get_width (composite); + height = gdk_pixbuf_get_height (composite); + + gdk_pixbuf_composite (emblem, composite, + width - LOGGED_IN_EMBLEM_SIZE, + height - LOGGED_IN_EMBLEM_SIZE, + LOGGED_IN_EMBLEM_SIZE, + LOGGED_IN_EMBLEM_SIZE, + width - LOGGED_IN_EMBLEM_SIZE, + height - LOGGED_IN_EMBLEM_SIZE, + 1.0, + 1.0, + GDK_INTERP_BILINEAR, + 255); + + g_object_unref (emblem); + + return composite; +} + static GdkPixbuf * get_default_user_image_from_settings (void) { @@ -100,7 +145,7 @@ get_default_user_image_from_settings (void) return image; } -GdkPixbuf * +static GdkPixbuf * get_default_user_image (void) { GdkPixbuf *temp_image = NULL, *image = NULL; @@ -141,28 +186,22 @@ get_default_user_image (void) } } - if (image && config_get_bool (NULL, CONFIG_KEY_ROUND_USER_IMAGE, TRUE)) - { - temp_image = round_image (image); - if (temp_image != NULL) - { - g_object_unref (image); - image = temp_image; - } - } - return image; } GdkPixbuf * -get_user_image (const gchar *username) +greeter_get_user_image (const gchar *username) { LightDMUser *user = NULL; GdkPixbuf *temp_image = NULL, *image = NULL; GError *error = NULL; + gboolean logged_in = FALSE; const gchar *path; - user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), username); + if (username) { + user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), username); + } + if (user) { path = lightdm_user_get_image (user); @@ -179,6 +218,13 @@ get_user_image (const gchar *username) g_clear_error (&error); } } + logged_in = lightdm_user_get_logged_in (user); + } + + /* Fallback to default icon */ + if (!image) + { + image = get_default_user_image (); } if (image && config_get_bool (NULL, CONFIG_KEY_ROUND_USER_IMAGE, TRUE)) @@ -191,6 +237,16 @@ get_user_image (const gchar *username) } } + if (image && logged_in && config_get_bool (NULL, CONFIG_KEY_HIGHLIGHT_LOGGED_USER, TRUE)) + { + temp_image = logged_in_pixbuf (image); + if (temp_image != NULL) + { + g_object_unref (image); + image = temp_image; + } + } + return image; } diff --git a/src/greeteruserimage.h b/src/greeteruserimage.h index 57c70aa..9590874 100644 --- a/src/greeteruserimage.h +++ b/src/greeteruserimage.h @@ -21,9 +21,7 @@ G_BEGIN_DECLS -GdkPixbuf *get_default_user_image (void); - -GdkPixbuf *get_user_image (const gchar *username); +GdkPixbuf *greeter_get_user_image (const gchar *username); G_END_DECLS diff --git a/src/lightdm-gtk-greeter.c b/src/lightdm-gtk-greeter.c index 4628d8f..6d23bb2 100644 --- a/src/lightdm-gtk-greeter.c +++ b/src/lightdm-gtk-greeter.c @@ -801,16 +801,7 @@ set_user_image (const gchar *username) if (!gtk_widget_get_visible (GTK_WIDGET (user_image))) return; - if (username) - { - image = get_user_image (username); - } - - if (!image) - { - image = get_default_user_image (); - } - + image = greeter_get_user_image (username); gtk_image_set_from_pixbuf (GTK_IMAGE (user_image), image); g_object_unref (image); } -- cgit v1.2.1