Skip to content

Commit 554a036

Browse files
vkarehlukefromdc
authored andcommitted
HiDPI: Convert Pixbufs to Cairo Surfaces
This allows icons in most places to scale up properly for HiDPI displays.
1 parent 280ef82 commit 554a036

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
#include <eel/eel-stock-dialogs.h>
@@ -55,7 +56,7 @@ enum
5556
};
5657
enum
5758
{
58-
COLUMN_AUTORUN_PIXBUF,
59+
COLUMN_AUTORUN_SURFACE,
5960
COLUMN_AUTORUN_NAME,
6061
COLUMN_AUTORUN_APP_INFO,
6162
COLUMN_AUTORUN_X_CONTENT_TYPE,
@@ -468,7 +469,7 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
468469
GAppInfo *default_app_info;
469470
GtkListStore *list_store;
470471
GtkTreeIter iter;
471-
GdkPixbuf *pixbuf;
472+
cairo_surface_t *surface;
472473
int icon_size, icon_scale;
473474
int set_active;
474475
int n;
@@ -496,7 +497,7 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
496497
num_apps = g_list_length (app_info_list);
497498

498499
list_store = gtk_list_store_new (5,
499-
GDK_TYPE_PIXBUF,
500+
CAIRO_GOBJECT_TYPE_SURFACE,
500501
G_TYPE_STRING,
501502
G_TYPE_APP_INFO,
502503
G_TYPE_STRING,
@@ -506,76 +507,84 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
506507
if (num_apps == 0)
507508
{
508509
gtk_list_store_append (list_store, &iter);
509-
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
510-
"dialog-error",
511-
icon_size,
512-
0,
513-
NULL);
510+
surface = gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
511+
"dialog-error",
512+
icon_size,
513+
icon_scale,
514+
NULL,
515+
0,
516+
NULL);
514517

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

517520
gtk_list_store_set (list_store, &iter,
518-
COLUMN_AUTORUN_PIXBUF, pixbuf,
521+
COLUMN_AUTORUN_SURFACE, surface,
519522
COLUMN_AUTORUN_NAME, _("No applications found"),
520523
COLUMN_AUTORUN_APP_INFO, NULL,
521524
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
522525
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK,
523526
-1);
524-
g_object_unref (pixbuf);
527+
cairo_surface_destroy (surface);
525528
}
526529
else
527530
{
528531
if (include_ask)
529532
{
530533
gtk_list_store_append (list_store, &iter);
531-
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
532-
"dialog-question",
533-
icon_size,
534-
0,
535-
NULL);
534+
surface = gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
535+
"dialog-question",
536+
icon_size,
537+
icon_scale,
538+
NULL,
539+
0,
540+
NULL);
536541
gtk_list_store_set (list_store, &iter,
537-
COLUMN_AUTORUN_PIXBUF, pixbuf,
542+
COLUMN_AUTORUN_SURFACE, surface,
538543
COLUMN_AUTORUN_NAME, _("Ask what to do"),
539544
COLUMN_AUTORUN_APP_INFO, NULL,
540545
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
541546
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK,
542547
-1);
543-
g_object_unref (pixbuf);
548+
cairo_surface_destroy (surface);
544549
}
545550

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

561568
gtk_list_store_append (list_store, &iter);
562-
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
563-
"folder-open",
564-
icon_size,
565-
0,
566-
NULL);
569+
surface = gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
570+
"folder-open",
571+
icon_size,
572+
icon_scale,
573+
NULL,
574+
0,
575+
NULL);
567576
gtk_list_store_set (list_store, &iter,
568-
COLUMN_AUTORUN_PIXBUF, pixbuf,
577+
COLUMN_AUTORUN_SURFACE, surface,
569578
COLUMN_AUTORUN_NAME, _("Open Folder"),
570579
COLUMN_AUTORUN_APP_INFO, NULL,
571580
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
572581
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OPEN_FOLDER,
573582
-1);
574-
g_object_unref (pixbuf);
583+
cairo_surface_destroy (surface);
575584

576585
gtk_list_store_append (list_store, &iter);
577586
gtk_list_store_set (list_store, &iter,
578-
COLUMN_AUTORUN_PIXBUF, NULL,
587+
COLUMN_AUTORUN_SURFACE, NULL,
579588
COLUMN_AUTORUN_NAME, NULL,
580589
COLUMN_AUTORUN_APP_INFO, NULL,
581590
COLUMN_AUTORUN_X_CONTENT_TYPE, NULL,
@@ -596,22 +605,22 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
596605

597606
icon = g_app_info_get_icon (app_info);
598607
icon_info = caja_icon_info_lookup (icon, icon_size, icon_scale);
599-
pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
608+
surface = caja_icon_info_get_surface_at_size (icon_info, icon_size);
600609
g_object_unref (icon_info);
601610

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

604613
gtk_list_store_append (list_store, &iter);
605614
gtk_list_store_set (list_store, &iter,
606-
COLUMN_AUTORUN_PIXBUF, pixbuf,
615+
COLUMN_AUTORUN_SURFACE, surface,
607616
COLUMN_AUTORUN_NAME, open_string,
608617
COLUMN_AUTORUN_APP_INFO, app_info,
609618
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
610619
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_APP,
611620
-1);
612-
if (pixbuf != NULL)
621+
if (surface != NULL)
613622
{
614-
g_object_unref (pixbuf);
623+
cairo_surface_destroy (surface);
615624
}
616625
g_free (open_string);
617626

@@ -626,27 +635,29 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
626635
{
627636
gtk_list_store_append (list_store, &iter);
628637
gtk_list_store_set (list_store, &iter,
629-
COLUMN_AUTORUN_PIXBUF, NULL,
638+
COLUMN_AUTORUN_SURFACE, NULL,
630639
COLUMN_AUTORUN_NAME, NULL,
631640
COLUMN_AUTORUN_APP_INFO, NULL,
632641
COLUMN_AUTORUN_X_CONTENT_TYPE, NULL,
633642
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_SEP,
634643
-1);
635644

636645
gtk_list_store_append (list_store, &iter);
637-
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
638-
"application-x-executable",
639-
icon_size,
640-
0,
641-
NULL);
646+
surface = gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
647+
"application-x-executable",
648+
icon_size,
649+
icon_scale,
650+
NULL,
651+
0,
652+
NULL);
642653
gtk_list_store_set (list_store, &iter,
643-
COLUMN_AUTORUN_PIXBUF, pixbuf,
654+
COLUMN_AUTORUN_SURFACE, surface,
644655
COLUMN_AUTORUN_NAME, _("Open with other Application..."),
645656
COLUMN_AUTORUN_APP_INFO, NULL,
646657
COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
647658
COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OTHER_APP,
648659
-1);
649-
g_object_unref (pixbuf);
660+
cairo_surface_destroy (surface);
650661
}
651662

652663
if (default_app_info != NULL)
@@ -663,7 +674,7 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
663674
renderer = gtk_cell_renderer_pixbuf_new ();
664675
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE);
665676
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
666-
"pixbuf", COLUMN_AUTORUN_PIXBUF,
677+
"surface", COLUMN_AUTORUN_SURFACE,
667678
NULL);
668679
renderer = gtk_cell_renderer_text_new ();
669680
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
@@ -935,6 +946,7 @@ do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAuto
935946
char *mount_name;
936947
GIcon *icon;
937948
GdkPixbuf *pixbuf;
949+
cairo_surface_t *surface;
938950
CajaIconInfo *icon_info;
939951
int icon_size, icon_scale;
940952
gboolean user_forced_dialog;
@@ -1003,9 +1015,10 @@ do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAuto
10031015
icon_scale = gtk_widget_get_scale_factor (dialog);
10041016
icon_info = caja_icon_info_lookup (icon, icon_size, icon_scale);
10051017
pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
1018+
surface = caja_icon_info_get_surface_at_size (icon_info, icon_size);
10061019
g_object_unref (icon_info);
10071020
g_object_unref (icon);
1008-
image = gtk_image_new_from_pixbuf (pixbuf);
1021+
image = gtk_image_new_from_surface (surface);
10091022
gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
10101023
gtk_widget_set_valign (image, GTK_ALIGN_START);
10111024
gtk_box_pack_start (GTK_BOX (hbox), image, TRUE, TRUE, 0);
@@ -1014,6 +1027,7 @@ do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAuto
10141027
gtk_window_set_icon (GTK_WINDOW (dialog), pixbuf);
10151028
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
10161029
g_object_unref (pixbuf);
1030+
cairo_surface_destroy (surface);
10171031

10181032
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
10191033
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
@@ -1145,13 +1159,15 @@ do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAuto
11451159
{
11461160
GtkWidget *eject_image;
11471161
eject_button = gtk_button_new_with_mnemonic (_("_Eject"));
1148-
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1149-
"media-eject",
1150-
caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON),
1151-
0,
1152-
NULL);
1153-
eject_image = gtk_image_new_from_pixbuf (pixbuf);
1154-
g_object_unref (pixbuf);
1162+
surface = gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
1163+
"media-eject",
1164+
caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON),
1165+
icon_scale,
1166+
NULL,
1167+
0,
1168+
NULL);
1169+
eject_image = gtk_image_new_from_surface (surface);
1170+
cairo_surface_destroy (surface);
11551171
gtk_button_set_image (GTK_BUTTON (eject_button), eject_image);
11561172
data->should_eject = TRUE;
11571173
}

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)