summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSean Davis <bluesabre@users.noreply.github.com>2021-11-15 22:44:45 -0500
committerGitHub <noreply@github.com>2021-11-15 22:44:45 -0500
commit8008a9c290c87a70bd53b5a0ba43caf187581a6e (patch)
tree808d4d5f4b656b06006b60940dcd1bf0546e91b5 /src
parentad88d75b398a875d7e8392cddfa40511e6e16d5e (diff)
parenta322634bac957bf68205740cc602031ef2a51710 (diff)
downloadlightdm-gtk-greeter-git-8008a9c290c87a70bd53b5a0ba43caf187581a6e.tar.gz
Merge pull request #103 from matiasdelellis/master
Add option to round faces.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/greeterconfiguration.h2
-rw-r--r--src/greeteruserimage.c252
-rw-r--r--src/greeteruserimage.h28
-rw-r--r--src/lightdm-gtk-greeter.c60
5 files changed, 288 insertions, 56 deletions
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/greeterconfiguration.h b/src/greeterconfiguration.h
index 587226d..9e1b452 100644
--- a/src/greeterconfiguration.h
+++ b/src/greeterconfiguration.h
@@ -29,6 +29,8 @@
#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_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
new file mode 100644
index 0000000..72674d5
--- /dev/null
+++ b/src/greeteruserimage.c
@@ -0,0 +1,252 @@
+/*
+ * Copyright (C) 2010 - 2011, Robert Ancell <robert.ancell@canonical.com>
+ * Copyright (C) 2011, Gunnar Hjalmarsson <ubuntu@gunnar.cc>
+ * Copyright (C) 2012 - 2013, Lionel Le Folgoc <mrpouit@ubuntu.com>
+ * Copyright (C) 2012, Julien Lavergne <gilir@ubuntu.com>
+ * Copyright (C) 2013 - 2015, Simon Steinbeiß <ochosi@shimmerproject.org>
+ * Copyright (C) 2013 - 2020, Sean Davis <sean@bluesabre.org>
+ * Copyright (C) 2014, Andrew P. <pan.pav.7c5@gmail.com>
+ *
+ * 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 <lightdm.h>
+
+#include "greeterconfiguration.h"
+#include "greeteruserimage.h"
+
+#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)
+
+#define VALUE_IS_ICON_NAME(v) (v[0] == '#')
+#define VALUE_ICON_NAME(v) (v + 1)
+
+
+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 *
+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)
+{
+ 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_IS_ICON_PATH(value))
+ {
+ image = gdk_pixbuf_new_from_file_at_scale (VALUE_ICON_PATH(value),
+ USER_IMAGE_SIZE,
+ USER_IMAGE_SIZE,
+ FALSE,
+ &error);
+
+ if (!image)
+ {
+ g_warning ("Failed to load default user image from path: %s", error->message);
+ g_clear_error (&error);
+ }
+ }
+ else if (VALUE_IS_ICON_NAME(value))
+ {
+ image = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ VALUE_ICON_NAME(value),
+ USER_IMAGE_SIZE,
+ 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;
+}
+
+static GdkPixbuf *
+get_default_user_image (void)
+{
+ GdkPixbuf *temp_image = NULL, *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",
+ USER_IMAGE_SIZE,
+ 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",
+ USER_IMAGE_SIZE,
+ 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 *
+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;
+
+ 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,
+ USER_IMAGE_SIZE,
+ USER_IMAGE_SIZE,
+ FALSE,
+ &error);
+ if (!image)
+ {
+ g_debug ("Failed to load user image: %s", error->message);
+ 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))
+ {
+ temp_image = round_image (image);
+ if (temp_image != NULL)
+ {
+ g_object_unref (image);
+ image = temp_image;
+ }
+ }
+
+ 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
new file mode 100644
index 0000000..9590874
--- /dev/null
+++ b/src/greeteruserimage.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2010 - 2011, Robert Ancell <robert.ancell@canonical.com>
+ * Copyright (C) 2011, Gunnar Hjalmarsson <ubuntu@gunnar.cc>
+ * Copyright (C) 2012 - 2013, Lionel Le Folgoc <mrpouit@ubuntu.com>
+ * Copyright (C) 2012, Julien Lavergne <gilir@ubuntu.com>
+ * Copyright (C) 2013 - 2015, Simon Steinbeiß <ochosi@shimmerproject.org>
+ * Copyright (C) 2013 - 2020, Sean Davis <sean@bluesabre.org>
+ * Copyright (C) 2014, Andrew P. <pan.pav.7c5@gmail.com>
+ *
+ * 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 <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+GdkPixbuf *greeter_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 0e594d1..0504ea0 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) */
@@ -797,41 +796,14 @@ set_message_label (LightDMMessageType type, const gchar *text)
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)
- {
- gtk_image_set_from_pixbuf (GTK_IMAGE (user_image), image);
- g_object_unref (image);
- return;
- }
- else
- {
- g_debug ("Failed to load user image: %s", error->message);
- g_clear_error (&error);
- }
- }
- }
-
- 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);
+ image = greeter_get_user_image (username);
+ gtk_image_set_from_pixbuf (GTK_IMAGE (user_image), image);
+ g_object_unref (image);
}
/* MenuCommand */
@@ -2907,8 +2879,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))
@@ -3145,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 ();