user-accounts: render user's icons as surface with scale
This patch is needed for future hidpi support. https://bugzilla.gnome.org/show_bug.cgi?id=742395
This commit is contained in:
parent
33b599fdc1
commit
006b5970a6
3 changed files with 41 additions and 31 deletions
|
@ -34,6 +34,7 @@
|
||||||
#include <polkit/polkit.h>
|
#include <polkit/polkit.h>
|
||||||
#include <act/act.h>
|
#include <act/act.h>
|
||||||
#include <libgd/gd-notification.h>
|
#include <libgd/gd-notification.h>
|
||||||
|
#include <cairo-gobject.h>
|
||||||
|
|
||||||
#define GNOME_DESKTOP_USE_UNSTABLE_API
|
#define GNOME_DESKTOP_USE_UNSTABLE_API
|
||||||
#include <libgnome-desktop/gnome-languages.h>
|
#include <libgnome-desktop/gnome-languages.h>
|
||||||
|
@ -190,7 +191,7 @@ user_added (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
|
||||||
GtkListStore *store;
|
GtkListStore *store;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreeIter dummy;
|
GtkTreeIter dummy;
|
||||||
GdkPixbuf *pixbuf;
|
cairo_surface_t *surface;
|
||||||
gchar *text, *title;
|
gchar *text, *title;
|
||||||
GtkTreeSelection *selection;
|
GtkTreeSelection *selection;
|
||||||
gint sort_key;
|
gint sort_key;
|
||||||
|
@ -205,7 +206,7 @@ user_added (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
|
||||||
store = GTK_LIST_STORE (model);
|
store = GTK_LIST_STORE (model);
|
||||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
|
||||||
|
|
||||||
pixbuf = render_user_icon (user, UM_ICON_STYLE_FRAME | UM_ICON_STYLE_STATUS, 48);
|
surface = render_user_icon (user, UM_ICON_STYLE_FRAME | UM_ICON_STYLE_STATUS, 48, 1);
|
||||||
text = get_name_col_str (user);
|
text = get_name_col_str (user);
|
||||||
|
|
||||||
if (act_user_get_uid (user) == getuid ()) {
|
if (act_user_get_uid (user) == getuid ()) {
|
||||||
|
@ -219,14 +220,14 @@ user_added (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
|
||||||
|
|
||||||
gtk_list_store_set (store, &iter,
|
gtk_list_store_set (store, &iter,
|
||||||
USER_COL, user,
|
USER_COL, user,
|
||||||
FACE_COL, pixbuf,
|
FACE_COL, surface,
|
||||||
NAME_COL, text,
|
NAME_COL, text,
|
||||||
USER_ROW_COL, TRUE,
|
USER_ROW_COL, TRUE,
|
||||||
TITLE_COL, NULL,
|
TITLE_COL, NULL,
|
||||||
HEADING_ROW_COL, FALSE,
|
HEADING_ROW_COL, FALSE,
|
||||||
SORT_KEY_COL, sort_key,
|
SORT_KEY_COL, sort_key,
|
||||||
-1);
|
-1);
|
||||||
g_object_unref (pixbuf);
|
cairo_surface_destroy (surface);
|
||||||
g_free (text);
|
g_free (text);
|
||||||
|
|
||||||
if (sort_key == 1 &&
|
if (sort_key == 1 &&
|
||||||
|
@ -342,7 +343,7 @@ user_changed (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
ActUser *current;
|
ActUser *current;
|
||||||
GdkPixbuf *pixbuf;
|
cairo_surface_t *surface;
|
||||||
char *text;
|
char *text;
|
||||||
|
|
||||||
tv = (GtkTreeView *)get_widget (d, "list-treeview");
|
tv = (GtkTreeView *)get_widget (d, "list-treeview");
|
||||||
|
@ -353,15 +354,15 @@ user_changed (ActUserManager *um, ActUser *user, CcUserPanelPrivate *d)
|
||||||
do {
|
do {
|
||||||
gtk_tree_model_get (model, &iter, USER_COL, ¤t, -1);
|
gtk_tree_model_get (model, &iter, USER_COL, ¤t, -1);
|
||||||
if (current == user) {
|
if (current == user) {
|
||||||
pixbuf = render_user_icon (user, UM_ICON_STYLE_FRAME | UM_ICON_STYLE_STATUS, 48);
|
surface = render_user_icon (user, UM_ICON_STYLE_FRAME | UM_ICON_STYLE_STATUS, 48, 1);
|
||||||
text = get_name_col_str (user);
|
text = get_name_col_str (user);
|
||||||
|
|
||||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
||||||
USER_COL, user,
|
USER_COL, user,
|
||||||
FACE_COL, pixbuf,
|
FACE_COL, surface,
|
||||||
NAME_COL, text,
|
NAME_COL, text,
|
||||||
-1);
|
-1);
|
||||||
g_object_unref (pixbuf);
|
cairo_surface_destroy (surface);
|
||||||
g_free (text);
|
g_free (text);
|
||||||
g_object_unref (current);
|
g_object_unref (current);
|
||||||
|
|
||||||
|
@ -877,18 +878,18 @@ show_user (ActUser *user, CcUserPanelPrivate *d)
|
||||||
{
|
{
|
||||||
GtkWidget *image;
|
GtkWidget *image;
|
||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
GdkPixbuf *pixbuf;
|
cairo_surface_t *surface;
|
||||||
gchar *lang, *text, *name;
|
gchar *lang, *text, *name;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
gboolean show, enable;
|
gboolean show, enable;
|
||||||
ActUser *current;
|
ActUser *current;
|
||||||
|
|
||||||
pixbuf = render_user_icon (user, UM_ICON_STYLE_NONE, 48);
|
surface = render_user_icon (user, UM_ICON_STYLE_NONE, 48, 1);
|
||||||
image = get_widget (d, "user-icon-image");
|
image = get_widget (d, "user-icon-image");
|
||||||
gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
|
gtk_image_set_from_surface (GTK_IMAGE (image), surface);
|
||||||
image = get_widget (d, "user-icon-image2");
|
image = get_widget (d, "user-icon-image2");
|
||||||
gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
|
gtk_image_set_from_surface (GTK_IMAGE (image), surface);
|
||||||
g_object_unref (pixbuf);
|
cairo_surface_destroy (surface);
|
||||||
|
|
||||||
um_photo_dialog_set_user (d->photo_dialog, user);
|
um_photo_dialog_set_user (d->photo_dialog, user);
|
||||||
|
|
||||||
|
@ -1569,7 +1570,7 @@ setup_main_window (CcUserPanel *self)
|
||||||
userlist = get_widget (d, "list-treeview");
|
userlist = get_widget (d, "list-treeview");
|
||||||
store = gtk_list_store_new (NUM_USER_LIST_COLS,
|
store = gtk_list_store_new (NUM_USER_LIST_COLS,
|
||||||
ACT_TYPE_USER,
|
ACT_TYPE_USER,
|
||||||
GDK_TYPE_PIXBUF,
|
CAIRO_GOBJECT_TYPE_SURFACE,
|
||||||
G_TYPE_STRING,
|
G_TYPE_STRING,
|
||||||
G_TYPE_BOOLEAN,
|
G_TYPE_BOOLEAN,
|
||||||
G_TYPE_STRING,
|
G_TYPE_STRING,
|
||||||
|
@ -1602,7 +1603,7 @@ setup_main_window (CcUserPanel *self)
|
||||||
column = gtk_tree_view_column_new ();
|
column = gtk_tree_view_column_new ();
|
||||||
cell = gtk_cell_renderer_pixbuf_new ();
|
cell = gtk_cell_renderer_pixbuf_new ();
|
||||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), cell, FALSE);
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), cell, FALSE);
|
||||||
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "pixbuf", FACE_COL);
|
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "surface", FACE_COL);
|
||||||
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "visible", USER_ROW_COL);
|
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), cell, "visible", USER_ROW_COL);
|
||||||
cell = gtk_cell_renderer_text_new ();
|
cell = gtk_cell_renderer_text_new ();
|
||||||
g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
||||||
|
|
|
@ -867,7 +867,7 @@ check_user_file (const char *filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
static GdkPixbuf *
|
static GdkPixbuf *
|
||||||
frame_pixbuf (GdkPixbuf *source)
|
frame_pixbuf (GdkPixbuf *source, gint scale)
|
||||||
{
|
{
|
||||||
GdkPixbuf *dest;
|
GdkPixbuf *dest;
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
|
@ -877,7 +877,7 @@ frame_pixbuf (GdkPixbuf *source)
|
||||||
int frame_width;
|
int frame_width;
|
||||||
double radius;
|
double radius;
|
||||||
|
|
||||||
frame_width = 2;
|
frame_width = 2 * scale;
|
||||||
|
|
||||||
w = gdk_pixbuf_get_width (source) + frame_width * 2;
|
w = gdk_pixbuf_get_width (source) + frame_width * 2;
|
||||||
h = gdk_pixbuf_get_height (source) + frame_width * 2;
|
h = gdk_pixbuf_get_height (source) + frame_width * 2;
|
||||||
|
@ -908,7 +908,7 @@ frame_pixbuf (GdkPixbuf *source)
|
||||||
}
|
}
|
||||||
|
|
||||||
static GdkPixbuf *
|
static GdkPixbuf *
|
||||||
logged_in_pixbuf (GdkPixbuf *pixbuf)
|
logged_in_pixbuf (GdkPixbuf *pixbuf, gint scale)
|
||||||
{
|
{
|
||||||
cairo_format_t format;
|
cairo_format_t format;
|
||||||
cairo_surface_t *surface;
|
cairo_surface_t *surface;
|
||||||
|
@ -931,7 +931,8 @@ logged_in_pixbuf (GdkPixbuf *pixbuf)
|
||||||
|
|
||||||
/* Draw pattern */
|
/* Draw pattern */
|
||||||
cairo_rectangle (cr, 0, 0, width, height);
|
cairo_rectangle (cr, 0, 0, width, height);
|
||||||
pattern = cairo_pattern_create_radial (width - 9.5, height - 10, 0, width - 8.5, height - 7.5, 7.7);
|
pattern = cairo_pattern_create_radial (width - 9.5 * scale, height - 10 * scale, 0,
|
||||||
|
width - 8.5 * scale, height - 7.5 * scale, 7.7 * scale);
|
||||||
cairo_pattern_add_color_stop_rgb (pattern, 0, 0.4, 0.9, 0);
|
cairo_pattern_add_color_stop_rgb (pattern, 0, 0.4, 0.9, 0);
|
||||||
cairo_pattern_add_color_stop_rgb (pattern, 0.7, 0.3, 0.6, 0);
|
cairo_pattern_add_color_stop_rgb (pattern, 0.7, 0.3, 0.6, 0);
|
||||||
cairo_pattern_add_color_stop_rgb (pattern, 0.8, 0.4, 0.4, 0.4);
|
cairo_pattern_add_color_stop_rgb (pattern, 0.8, 0.4, 0.4, 0.4);
|
||||||
|
@ -940,8 +941,8 @@ logged_in_pixbuf (GdkPixbuf *pixbuf)
|
||||||
cairo_fill (cr);
|
cairo_fill (cr);
|
||||||
|
|
||||||
/* Draw border */
|
/* Draw border */
|
||||||
cairo_set_line_width (cr, 0.9);
|
cairo_set_line_width (cr, 0.9 * scale);
|
||||||
cairo_arc (cr, width - 8.5, height - 8.5, 6, 0, 2 * G_PI);
|
cairo_arc (cr, width - 8.5 * scale, height - 8.5 * scale, 6 * scale, 0, 2 * G_PI);
|
||||||
gdk_rgba_parse (&color, "#ffffff");
|
gdk_rgba_parse (&color, "#ffffff");
|
||||||
gdk_cairo_set_source_rgba (cr, &color);
|
gdk_cairo_set_source_rgba (cr, &color);
|
||||||
cairo_stroke (cr);
|
cairo_stroke (cr);
|
||||||
|
@ -956,16 +957,18 @@ logged_in_pixbuf (GdkPixbuf *pixbuf)
|
||||||
|
|
||||||
#define MAX_FILE_SIZE 65536
|
#define MAX_FILE_SIZE 65536
|
||||||
|
|
||||||
GdkPixbuf *
|
cairo_surface_t *
|
||||||
render_user_icon (ActUser *user,
|
render_user_icon (ActUser *user,
|
||||||
UmIconStyle style,
|
UmIconStyle style,
|
||||||
gint icon_size)
|
gint icon_size,
|
||||||
|
gint scale)
|
||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
GdkPixbuf *framed;
|
GdkPixbuf *framed;
|
||||||
gboolean res;
|
gboolean res;
|
||||||
GError *error;
|
GError *error;
|
||||||
const gchar *icon_file;
|
const gchar *icon_file;
|
||||||
|
cairo_surface_t *surface = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (ACT_IS_USER (user), NULL);
|
g_return_val_if_fail (ACT_IS_USER (user), NULL);
|
||||||
g_return_val_if_fail (icon_size > 12, NULL);
|
g_return_val_if_fail (icon_size > 12, NULL);
|
||||||
|
@ -976,8 +979,8 @@ render_user_icon (ActUser *user,
|
||||||
res = check_user_file (icon_file, MAX_FILE_SIZE);
|
res = check_user_file (icon_file, MAX_FILE_SIZE);
|
||||||
if (res) {
|
if (res) {
|
||||||
pixbuf = gdk_pixbuf_new_from_file_at_size (icon_file,
|
pixbuf = gdk_pixbuf_new_from_file_at_size (icon_file,
|
||||||
icon_size,
|
icon_size * scale,
|
||||||
icon_size,
|
icon_size * scale,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -993,7 +996,7 @@ render_user_icon (ActUser *user,
|
||||||
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
|
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
|
||||||
|
|
||||||
"avatar-default",
|
"avatar-default",
|
||||||
icon_size,
|
icon_size * scale,
|
||||||
GTK_ICON_LOOKUP_FORCE_SIZE,
|
GTK_ICON_LOOKUP_FORCE_SIZE,
|
||||||
&error);
|
&error);
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -1004,7 +1007,7 @@ render_user_icon (ActUser *user,
|
||||||
out:
|
out:
|
||||||
|
|
||||||
if (pixbuf != NULL && (style & UM_ICON_STYLE_FRAME)) {
|
if (pixbuf != NULL && (style & UM_ICON_STYLE_FRAME)) {
|
||||||
framed = frame_pixbuf (pixbuf);
|
framed = frame_pixbuf (pixbuf, scale);
|
||||||
if (framed != NULL) {
|
if (framed != NULL) {
|
||||||
g_object_unref (pixbuf);
|
g_object_unref (pixbuf);
|
||||||
pixbuf = framed;
|
pixbuf = framed;
|
||||||
|
@ -1012,14 +1015,19 @@ render_user_icon (ActUser *user,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pixbuf != NULL && (style & UM_ICON_STYLE_STATUS) && act_user_is_logged_in (user)) {
|
if (pixbuf != NULL && (style & UM_ICON_STYLE_STATUS) && act_user_is_logged_in (user)) {
|
||||||
framed = logged_in_pixbuf (pixbuf);
|
framed = logged_in_pixbuf (pixbuf, scale);
|
||||||
if (framed != NULL) {
|
if (framed != NULL) {
|
||||||
g_object_unref (pixbuf);
|
g_object_unref (pixbuf);
|
||||||
pixbuf = framed;
|
pixbuf = framed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pixbuf;
|
if (pixbuf != NULL) {
|
||||||
|
surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
|
||||||
|
g_object_unref (pixbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -75,9 +75,10 @@ void generate_username_choices (const gchar *name,
|
||||||
|
|
||||||
gchar * get_smart_date (GDateTime *date);
|
gchar * get_smart_date (GDateTime *date);
|
||||||
|
|
||||||
GdkPixbuf * render_user_icon (ActUser *user,
|
cairo_surface_t *render_user_icon (ActUser *user,
|
||||||
UmIconStyle style,
|
UmIconStyle style,
|
||||||
gint icon_size);
|
gint icon_size,
|
||||||
|
gint scale);
|
||||||
|
|
||||||
void set_user_icon_data (ActUser *user,
|
void set_user_icon_data (ActUser *user,
|
||||||
GdkPixbuf *pixbuf);
|
GdkPixbuf *pixbuf);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue