Skip to content

Commit dade92d

Browse files
vkarehraveit65
authored andcommitted
HiDPI: Convert Pixbufs to Cairo Surfaces
This allows icons in most places to scale up properly for HiDPI displays.
1 parent 556663a commit dade92d

21 files changed

+395
-276
lines changed

eel/eel-graphic-effects.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ eel_create_spotlight_pixbuf (GdkPixbuf* src)
108108
return dest;
109109
}
110110

111+
cairo_surface_t *
112+
eel_create_spotlight_surface (cairo_surface_t* src, int scale)
113+
{
114+
GdkPixbuf *pixbuf;
115+
cairo_surface_t *dest;
116+
117+
pixbuf = gdk_pixbuf_get_from_surface (src, 0, 0,
118+
cairo_image_surface_get_width (src),
119+
cairo_image_surface_get_height (src));
120+
dest = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
121+
g_object_unref (pixbuf);
122+
123+
return dest;
124+
}
111125

112126
/* the following routine was stolen from the panel to darken a pixbuf, by manipulating the saturation */
113127

eel/eel-graphic-effects.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
/* return a lightened pixbuf for pre-lighting */
3434
GdkPixbuf *eel_create_spotlight_pixbuf (GdkPixbuf *source_pixbuf);
35+
/* return a lightened surface for pre-lighting */
36+
cairo_surface_t *eel_create_spotlight_surface (cairo_surface_t *source_surface,
37+
int scale);
3538

3639
/* return a darkened pixbuf for selection hiliting */
3740
GdkPixbuf *eel_create_darkened_pixbuf (GdkPixbuf *source_pixbuf,

libcaja-private/caja-autorun.c

Lines changed: 69 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <gio/gdesktopappinfo.h>
3232
#include <X11/XKBlib.h>
3333
#include <gdk/gdkkeysyms.h>
34+
#include <cairo-gobject.h>
3435

3536
#include <eel/eel-glib-extensions.h>
3637

@@ -54,7 +55,7 @@ enum
5455
};
5556
enum
5657
{
57-
COLUMN_AUTORUN_PIXBUF,
58+
COLUMN_AUTORUN_SURFACE,
5859
COLUMN_AUTORUN_NAME,
5960
COLUMN_AUTORUN_APP_INFO,
6061
COLUMN_AUTORUN_X_CONTENT_TYPE,
@@ -467,7 +468,7 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
467468
GAppInfo *default_app_info;
468469
GtkListStore *list_store;
469470
GtkTreeIter iter;
470-
GdkPixbuf *pixbuf;
471+
cairo_surface_t *surface;
471472
int icon_size, icon_scale;
472473
int set_active;
473474
int n;
@@ -495,7 +496,7 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
495496
num_apps = g_list_length (app_info_list);
496497

497498
list_store = gtk_list_store_new (5,
498-
GDK_TYPE_PIXBUF,
499+
CAIRO_GOBJECT_TYPE_SURFACE,
499500
G_TYPE_STRING,
500501
G_TYPE_APP_INFO,
501502
G_TYPE_STRING,
@@ -505,76 +506,84 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
505506
if (num_apps == 0)
506507
{
507508
gtk_list_store_append (list_store, &iter);
508-
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
509-
"dialog-error",
510-
icon_size,
511-
0,
512-
NULL);
509+
surface = gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
510+
"dialog-error",
511+
icon_size,
512+
icon_scale,
513+
NULL,
514+
0,
515+
NULL);
513516

514517
/* TODO: integrate with PackageKit-mate to find applications */
515518

516519
gtk_list_store_set (list_store, &iter,
517-
COLUMN_AUTORUN_PIXBUF, pixbuf,
520+
COLUMN_AUTORUN_SURFACE, surface,
518521
COLUMN_AUTORUN_NAME, _("No applications found"),
519522
COLUMN_AUTORUN_APP_INFO, NULL,
520523
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
521524
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK,
522525
-1);
523-
g_object_unref (pixbuf);
526+
cairo_surface_destroy (surface);
524527
}
525528
else
526529
{
527530
if (include_ask)
528531
{
529532
gtk_list_store_append (list_store, &iter);
530-
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
531-
"dialog-question",
532-
icon_size,
533-
0,
534-
NULL);
533+
surface = gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
534+
"dialog-question",
535+
icon_size,
536+
icon_scale,
537+
NULL,
538+
0,
539+
NULL);
535540
gtk_list_store_set (list_store, &iter,
536-
COLUMN_AUTORUN_PIXBUF, pixbuf,
541+
COLUMN_AUTORUN_SURFACE, surface,
537542
COLUMN_AUTORUN_NAME, _("Ask what to do"),
538543
COLUMN_AUTORUN_APP_INFO, NULL,
539544
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
540545
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK,
541546
-1);
542-
g_object_unref (pixbuf);
547+
cairo_surface_destroy (surface);
543548
}
544549

545550
gtk_list_store_append (list_store, &iter);
546-
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
547-
"window-close",
548-
icon_size,
549-
0,
550-
NULL);
551+
surface = gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
552+
"window-close",
553+
icon_size,
554+
icon_scale,
555+
NULL,
556+
0,
557+
NULL);
551558
gtk_list_store_set (list_store, &iter,
552-
COLUMN_AUTORUN_PIXBUF, pixbuf,
559+
COLUMN_AUTORUN_SURFACE, surface,
553560
COLUMN_AUTORUN_NAME, _("Do Nothing"),
554561
COLUMN_AUTORUN_APP_INFO, NULL,
555562
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
556563
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_IGNORE,
557564
-1);
558-
g_object_unref (pixbuf);
565+
cairo_surface_destroy (surface);
559566

560567
gtk_list_store_append (list_store, &iter);
561-
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
562-
"folder-open",
563-
icon_size,
564-
0,
565-
NULL);
568+
surface = gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
569+
"folder-open",
570+
icon_size,
571+
icon_scale,
572+
NULL,
573+
0,
574+
NULL);
566575
gtk_list_store_set (list_store, &iter,
567-
COLUMN_AUTORUN_PIXBUF, pixbuf,
576+
COLUMN_AUTORUN_SURFACE, surface,
568577
COLUMN_AUTORUN_NAME, _("Open Folder"),
569578
COLUMN_AUTORUN_APP_INFO, NULL,
570579
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
571580
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OPEN_FOLDER,
572581
-1);
573-
g_object_unref (pixbuf);
582+
cairo_surface_destroy (surface);
574583

575584
gtk_list_store_append (list_store, &iter);
576585
gtk_list_store_set (list_store, &iter,
577-
COLUMN_AUTORUN_PIXBUF, NULL,
586+
COLUMN_AUTORUN_SURFACE, NULL,
578587
COLUMN_AUTORUN_NAME, NULL,
579588
COLUMN_AUTORUN_APP_INFO, NULL,
580589
COLUMN_AUTORUN_X_CONTENT_TYPE, NULL,
@@ -595,22 +604,22 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
595604

596605
icon = g_app_info_get_icon (app_info);
597606
icon_info = caja_icon_info_lookup (icon, icon_size, icon_scale);
598-
pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
607+
surface = caja_icon_info_get_surface_at_size (icon_info, icon_size);
599608
g_object_unref (icon_info);
600609

601610
open_string = g_strdup_printf (_("Open %s"), g_app_info_get_display_name (app_info));
602611

603612
gtk_list_store_append (list_store, &iter);
604613
gtk_list_store_set (list_store, &iter,
605-
COLUMN_AUTORUN_PIXBUF, pixbuf,
614+
COLUMN_AUTORUN_SURFACE, surface,
606615
COLUMN_AUTORUN_NAME, open_string,
607616
COLUMN_AUTORUN_APP_INFO, app_info,
608617
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
609618
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_APP,
610619
-1);
611-
if (pixbuf != NULL)
620+
if (surface != NULL)
612621
{
613-
g_object_unref (pixbuf);
622+
cairo_surface_destroy (surface);
614623
}
615624
g_free (open_string);
616625

@@ -625,27 +634,29 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
625634
{
626635
gtk_list_store_append (list_store, &iter);
627636
gtk_list_store_set (list_store, &iter,
628-
COLUMN_AUTORUN_PIXBUF, NULL,
637+
COLUMN_AUTORUN_SURFACE, NULL,
629638
COLUMN_AUTORUN_NAME, NULL,
630639
COLUMN_AUTORUN_APP_INFO, NULL,
631640
COLUMN_AUTORUN_X_CONTENT_TYPE, NULL,
632641
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_SEP,
633642
-1);
634643

635644
gtk_list_store_append (list_store, &iter);
636-
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
637-
"application-x-executable",
638-
icon_size,
639-
0,
640-
NULL);
645+
surface = gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
646+
"application-x-executable",
647+
icon_size,
648+
icon_scale,
649+
NULL,
650+
0,
651+
NULL);
641652
gtk_list_store_set (list_store, &iter,
642-
COLUMN_AUTORUN_PIXBUF, pixbuf,
653+
COLUMN_AUTORUN_SURFACE, surface,
643654
COLUMN_AUTORUN_NAME, _("Open with other Application..."),
644655
COLUMN_AUTORUN_APP_INFO, NULL,
645656
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
646657
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OTHER_APP,
647658
-1);
648-
g_object_unref (pixbuf);
659+
cairo_surface_destroy (surface);
649660
}
650661

651662
if (default_app_info != NULL)
@@ -662,7 +673,7 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
662673
renderer = gtk_cell_renderer_pixbuf_new ();
663674
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE);
664675
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
665-
"pixbuf", COLUMN_AUTORUN_PIXBUF,
676+
"surface", COLUMN_AUTORUN_SURFACE,
666677
NULL);
667678
renderer = gtk_cell_renderer_text_new ();
668679
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
@@ -934,6 +945,7 @@ do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAuto
934945
char *mount_name;
935946
GIcon *icon;
936947
GdkPixbuf *pixbuf;
948+
cairo_surface_t *surface;
937949
CajaIconInfo *icon_info;
938950
int icon_size, icon_scale;
939951
gboolean user_forced_dialog;
@@ -1002,9 +1014,10 @@ do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAuto
10021014
icon_scale = gtk_widget_get_scale_factor (dialog);
10031015
icon_info = caja_icon_info_lookup (icon, icon_size, icon_scale);
10041016
pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
1017+
surface = caja_icon_info_get_surface_at_size (icon_info, icon_size);
10051018
g_object_unref (icon_info);
10061019
g_object_unref (icon);
1007-
image = gtk_image_new_from_pixbuf (pixbuf);
1020+
image = gtk_image_new_from_surface (surface);
10081021
gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
10091022
gtk_widget_set_valign (image, GTK_ALIGN_START);
10101023
gtk_box_pack_start (GTK_BOX (hbox), image, TRUE, TRUE, 0);
@@ -1013,6 +1026,7 @@ do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAuto
10131026
gtk_window_set_icon (GTK_WINDOW (dialog), pixbuf);
10141027
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
10151028
g_object_unref (pixbuf);
1029+
cairo_surface_destroy (surface);
10161030

10171031
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
10181032
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
@@ -1138,13 +1152,15 @@ do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAuto
11381152
{
11391153
GtkWidget *eject_image;
11401154
eject_button = gtk_button_new_with_mnemonic (_("_Eject"));
1141-
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1142-
"media-eject",
1143-
caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON),
1144-
0,
1145-
NULL);
1146-
eject_image = gtk_image_new_from_pixbuf (pixbuf);
1147-
g_object_unref (pixbuf);
1155+
surface = gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
1156+
"media-eject",
1157+
caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON),
1158+
icon_scale,
1159+
NULL,
1160+
0,
1161+
NULL);
1162+
eject_image = gtk_image_new_from_surface (surface);
1163+
cairo_surface_destroy (surface);
11481164
gtk_button_set_image (GTK_BUTTON (eject_button), eject_image);
11491165
data->should_eject = TRUE;
11501166
}

libcaja-private/caja-bookmark.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,15 @@ caja_bookmark_get_has_custom_name (CajaBookmark *bookmark)
212212
return (bookmark->details->has_custom_name);
213213
}
214214

215-
216-
GdkPixbuf *
217-
caja_bookmark_get_pixbuf (CajaBookmark *bookmark,
218-
GtkIconSize stock_size)
215+
cairo_surface_t *
216+
caja_bookmark_get_surface (CajaBookmark *bookmark,
217+
GtkIconSize stock_size)
219218
{
220-
GdkPixbuf *result;
219+
cairo_surface_t *result;
221220
GIcon *icon;
222221
CajaIconInfo *info;
223222
int pixel_size, pixel_scale;
224223

225-
226224
g_return_val_if_fail (CAJA_IS_BOOKMARK (bookmark), NULL);
227225

228226
icon = caja_bookmark_get_icon (bookmark);
@@ -234,7 +232,7 @@ caja_bookmark_get_pixbuf (CajaBookmark *bookmark,
234232
pixel_size = caja_get_icon_size_for_stock_size (stock_size);
235233
pixel_scale = gdk_window_get_scale_factor (gdk_get_default_root_window ());
236234
info = caja_icon_info_lookup (icon, pixel_size, pixel_scale);
237-
result = caja_icon_info_get_pixbuf_at_size (info, pixel_size);
235+
result = caja_icon_info_get_surface_at_size (info, pixel_size);
238236
g_object_unref (info);
239237

240238
g_object_unref (icon);
@@ -590,18 +588,18 @@ caja_bookmark_new (GFile *location, const char *name, gboolean has_custom_name,
590588
static GtkWidget *
591589
create_image_widget_for_bookmark (CajaBookmark *bookmark)
592590
{
593-
GdkPixbuf *pixbuf;
591+
cairo_surface_t *surface;
594592
GtkWidget *widget;
595593

596-
pixbuf = caja_bookmark_get_pixbuf (bookmark, GTK_ICON_SIZE_MENU);
597-
if (pixbuf == NULL)
594+
surface = caja_bookmark_get_surface (bookmark, GTK_ICON_SIZE_MENU);
595+
if (surface == NULL)
598596
{
599597
return NULL;
600598
}
601599

602-
widget = gtk_image_new_from_pixbuf (pixbuf);
600+
widget = gtk_image_new_from_surface (surface);
603601

604-
g_object_unref (pixbuf);
602+
cairo_surface_destroy (surface);
605603
return widget;
606604
}
607605

libcaja-private/caja-bookmark.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ char * caja_bookmark_get_scroll_pos (CajaBookmark *b
9393

9494

9595
/* Helper functions for displaying bookmarks */
96-
GdkPixbuf * caja_bookmark_get_pixbuf (CajaBookmark *bookmark,
96+
cairo_surface_t * caja_bookmark_get_surface (CajaBookmark *bookmark,
9797
GtkIconSize icon_size);
9898
GtkWidget * caja_bookmark_menu_item_new (CajaBookmark *bookmark);
9999

libcaja-private/caja-icon-canvas-item.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ caja_icon_canvas_item_get_drag_surface (CajaIconCanvasItem *item)
525525
cairo_surface_t *surface;
526526

527527
EelCanvas *canvas;
528-
GdkScreen *screen;
529528
int width, height;
530529
int pix_width, pix_height;
531530
int item_offset_x, item_offset_y;
@@ -542,7 +541,6 @@ caja_icon_canvas_item_get_drag_surface (CajaIconCanvasItem *item)
542541
g_return_val_if_fail (CAJA_IS_ICON_CANVAS_ITEM (item), NULL);
543542

544543
canvas = EEL_CANVAS_ITEM (item)->canvas;
545-
screen = gtk_widget_get_screen (GTK_WIDGET (canvas));
546544
context = gtk_widget_get_style_context (GTK_WIDGET (canvas));
547545

548546
gtk_style_context_save (context);
@@ -2462,7 +2460,7 @@ caja_icon_canvas_item_get_icon_rectangle (const CajaIconCanvasItem *item)
24622460
rectangle.y0 = item->details->y;
24632461

24642462
pixels_per_unit = EEL_CANVAS_ITEM (item)->canvas->pixels_per_unit;
2465-
get_scaled_icon_size (EEL_CANVAS_ITEM (item), &width, &height);
2463+
get_scaled_icon_size (CAJA_ICON_CANVAS_ITEM (item), &width, &height);
24662464
rectangle.x1 = rectangle.x0 + width / pixels_per_unit;
24672465
rectangle.y1 = rectangle.y0 + height / pixels_per_unit;
24682466

0 commit comments

Comments
 (0)