summaryrefslogtreecommitdiff
path: root/libcaja-private
diff options
context:
space:
mode:
authorCosimo Cecchi <[email protected]>2013-08-02 14:37:13 +0200
committerraveit65 <[email protected]>2018-04-05 09:07:22 +0200
commit4bf67ac8fff8555bf784d8cd7e1611829a9fca44 (patch)
tree343275a74d64866035b0850d5583c83eb20fe486 /libcaja-private
parent35c4dc6021f36a5fc7df94b0332c7e5d6fa00d0a (diff)
downloadcaja-4bf67ac8fff8555bf784d8cd7e1611829a9fca44.tar.bz2
caja-4bf67ac8fff8555bf784d8cd7e1611829a9fca44.tar.xz
Support HiDpi icons
Port the rendering of icons to cairo surfaces, so that we can apply the GDK scale factor when rendering icons. origin commit: https://gitlab.gnome.org/GNOME/nautilus/commit/0d4555d7
Diffstat (limited to 'libcaja-private')
-rw-r--r--libcaja-private/caja-autorun.c10
-rw-r--r--libcaja-private/caja-bookmark.c5
-rw-r--r--libcaja-private/caja-file-conflict-dialog.c4
-rw-r--r--libcaja-private/caja-file.c32
-rw-r--r--libcaja-private/caja-file.h2
-rw-r--r--libcaja-private/caja-icon-canvas-item.c150
-rw-r--r--libcaja-private/caja-icon-info.c54
-rw-r--r--libcaja-private/caja-icon-info.h12
-rw-r--r--libcaja-private/caja-program-choosing.c4
-rw-r--r--libcaja-private/caja-ui-utilities.c22
-rw-r--r--libcaja-private/caja-ui-utilities.h4
11 files changed, 177 insertions, 122 deletions
diff --git a/libcaja-private/caja-autorun.c b/libcaja-private/caja-autorun.c
index 22ed18df..f0a36b4d 100644
--- a/libcaja-private/caja-autorun.c
+++ b/libcaja-private/caja-autorun.c
@@ -468,7 +468,7 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
GtkListStore *list_store;
GtkTreeIter iter;
GdkPixbuf *pixbuf;
- int icon_size;
+ int icon_size, icon_scale;
int set_active;
int n;
int num_apps;
@@ -484,6 +484,7 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder;
icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);
+ icon_scale = gtk_widget_get_scale_factor (combo_box);
set_active = -1;
data = NULL;
@@ -593,7 +594,7 @@ caja_autorun_prepare_combo_box (GtkWidget *combo_box,
*/
icon = g_app_info_get_icon (app_info);
- icon_info = caja_icon_info_lookup (icon, icon_size);
+ icon_info = caja_icon_info_lookup (icon, icon_size, icon_scale);
pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
g_object_unref (icon_info);
@@ -934,7 +935,7 @@ do_autorun_for_content_type (GMount *mount, const char *x_content_type, CajaAuto
GIcon *icon;
GdkPixbuf *pixbuf;
CajaIconInfo *icon_info;
- int icon_size;
+ int icon_size, icon_scale;
gboolean user_forced_dialog;
gboolean pref_ask;
gboolean pref_start_app;
@@ -998,7 +999,8 @@ show_dialog:
icon = g_mount_get_icon (mount);
icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_DIALOG);
- icon_info = caja_icon_info_lookup (icon, icon_size);
+ icon_scale = gtk_widget_get_scale_factor (dialog);
+ icon_info = caja_icon_info_lookup (icon, icon_size, icon_scale);
pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
g_object_unref (icon_info);
g_object_unref (icon);
diff --git a/libcaja-private/caja-bookmark.c b/libcaja-private/caja-bookmark.c
index 040f0834..d4c25939 100644
--- a/libcaja-private/caja-bookmark.c
+++ b/libcaja-private/caja-bookmark.c
@@ -220,7 +220,7 @@ caja_bookmark_get_pixbuf (CajaBookmark *bookmark,
GdkPixbuf *result;
GIcon *icon;
CajaIconInfo *info;
- int pixel_size;
+ int pixel_size, pixel_scale;
g_return_val_if_fail (CAJA_IS_BOOKMARK (bookmark), NULL);
@@ -232,7 +232,8 @@ caja_bookmark_get_pixbuf (CajaBookmark *bookmark,
}
pixel_size = caja_get_icon_size_for_stock_size (stock_size);
- info = caja_icon_info_lookup (icon, pixel_size);
+ pixel_scale = gdk_window_get_scale_factor (gdk_get_default_root_window ());
+ info = caja_icon_info_lookup (icon, pixel_size, pixel_scale);
result = caja_icon_info_get_pixbuf_at_size (info, pixel_size);
g_object_unref (info);
diff --git a/libcaja-private/caja-file-conflict-dialog.c b/libcaja-private/caja-file-conflict-dialog.c
index 003bcf76..69e1b476 100644
--- a/libcaja-private/caja-file-conflict-dialog.c
+++ b/libcaja-private/caja-file-conflict-dialog.c
@@ -79,6 +79,7 @@ file_icons_changed (CajaFile *file,
pixbuf = caja_file_get_icon_pixbuf (fcd->details->destination,
CAJA_ICON_SIZE_LARGE,
TRUE,
+ gtk_widget_get_scale_factor (fcd->details->dest_image),
CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS);
gtk_image_set_from_pixbuf (GTK_IMAGE (fcd->details->dest_image), pixbuf);
@@ -87,6 +88,7 @@ file_icons_changed (CajaFile *file,
pixbuf = caja_file_get_icon_pixbuf (fcd->details->source,
CAJA_ICON_SIZE_LARGE,
TRUE,
+ gtk_widget_get_scale_factor (fcd->details->src_image),
CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS);
gtk_image_set_from_pixbuf (GTK_IMAGE (fcd->details->src_image), pixbuf);
@@ -238,6 +240,7 @@ file_list_ready_cb (GList *files,
pixbuf = caja_file_get_icon_pixbuf (dest,
CAJA_ICON_SIZE_LARGE,
TRUE,
+ gtk_widget_get_scale_factor (fcd->details->titles_vbox),
CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS);
details->dest_image = gtk_image_new_from_pixbuf (pixbuf);
gtk_box_pack_start (GTK_BOX (details->first_hbox),
@@ -248,6 +251,7 @@ file_list_ready_cb (GList *files,
pixbuf = caja_file_get_icon_pixbuf (src,
CAJA_ICON_SIZE_LARGE,
TRUE,
+ gtk_widget_get_scale_factor (fcd->details->titles_vbox),
CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS);
details->src_image = gtk_image_new_from_pixbuf (pixbuf);
gtk_box_pack_start (GTK_BOX (details->second_hbox),
diff --git a/libcaja-private/caja-file.c b/libcaja-private/caja-file.c
index 769ca822..667f74af 100644
--- a/libcaja-private/caja-file.c
+++ b/libcaja-private/caja-file.c
@@ -4288,6 +4288,7 @@ get_default_file_icon (CajaFileIconFlags flags)
CajaIconInfo *
caja_file_get_icon (CajaFile *file,
int size,
+ int scale,
CajaFileIconFlags flags)
{
CajaIconInfo *icon;
@@ -4303,7 +4304,7 @@ caja_file_get_icon (CajaFile *file,
if (gicon) {
GdkPixbuf *pixbuf;
- icon = caja_icon_info_lookup (gicon, size);
+ icon = caja_icon_info_lookup (gicon, size, scale);
g_object_unref (gicon);
pixbuf = caja_icon_info_get_pixbuf (icon);
@@ -4313,7 +4314,7 @@ caja_file_get_icon (CajaFile *file,
}
g_object_unref (icon);
- icon = caja_icon_info_new_for_pixbuf (pixbuf);
+ icon = caja_icon_info_new_for_pixbuf (pixbuf, scale);
g_object_unref (pixbuf);
}
@@ -4329,7 +4330,7 @@ caja_file_get_icon (CajaFile *file,
caja_file_should_show_thumbnail (file)) {
if (file->details->thumbnail) {
int w, h, s;
- double scale;
+ double thumb_scale;
raw_pixbuf = g_object_ref (file->details->thumbnail);
@@ -4339,19 +4340,19 @@ caja_file_get_icon (CajaFile *file,
s = MAX (w, h);
/* Don't scale up small thumbnails in the standard view */
if (s <= cached_thumbnail_size) {
- scale = (double)size / CAJA_ICON_SIZE_STANDARD;
+ thumb_scale = (double)size / CAJA_ICON_SIZE_STANDARD;
}
else {
- scale = (double)modified_size / s;
+ thumb_scale = (double)modified_size / s;
}
/* Make sure that icons don't get smaller than CAJA_ICON_SIZE_SMALLEST */
- if (s*scale <= CAJA_ICON_SIZE_SMALLEST) {
- scale = (double) CAJA_ICON_SIZE_SMALLEST / s;
+ if (s*thumb_scale <= CAJA_ICON_SIZE_SMALLEST) {
+ thumb_scale = (double) CAJA_ICON_SIZE_SMALLEST / s;
}
scaled_pixbuf = gdk_pixbuf_scale_simple (raw_pixbuf,
- MAX (w * scale, 1),
- MAX (h * scale, 1),
+ MAX (w * thumb_scale, 1),
+ MAX (h * thumb_scale, 1),
GDK_INTERP_BILINEAR);
/* Render frames only for thumbnails of non-image files
@@ -4377,7 +4378,7 @@ caja_file_get_icon (CajaFile *file,
caja_file_invalidate_attributes (file, CAJA_FILE_ATTRIBUTE_THUMBNAIL);
}
- icon = caja_icon_info_new_for_pixbuf (scaled_pixbuf);
+ icon = caja_icon_info_new_for_pixbuf (scaled_pixbuf, scale);
g_object_unref (scaled_pixbuf);
return icon;
} else if (file->details->thumbnail_path == NULL &&
@@ -4397,15 +4398,15 @@ caja_file_get_icon (CajaFile *file,
gicon = caja_file_get_gicon (file, flags);
if (gicon) {
- icon = caja_icon_info_lookup (gicon, size);
+ icon = caja_icon_info_lookup (gicon, size, scale);
if (caja_icon_info_is_fallback (icon)) {
g_object_unref (icon);
- icon = caja_icon_info_lookup (get_default_file_icon (flags), size);
+ icon = caja_icon_info_lookup (get_default_file_icon (flags), size, scale);
}
g_object_unref (gicon);
return icon;
} else {
- return caja_icon_info_lookup (get_default_file_icon (flags), size);
+ return caja_icon_info_lookup (get_default_file_icon (flags), size, scale);
}
}
@@ -4413,12 +4414,13 @@ GdkPixbuf *
caja_file_get_icon_pixbuf (CajaFile *file,
int size,
gboolean force_size,
+ int scale,
CajaFileIconFlags flags)
{
CajaIconInfo *info;
GdkPixbuf *pixbuf;
- info = caja_file_get_icon (file, size, flags);
+ info = caja_file_get_icon (file, size, scale, flags);
if (force_size) {
pixbuf = caja_icon_info_get_pixbuf_at_size (info, size);
} else {
@@ -6719,7 +6721,7 @@ caja_file_get_emblem_pixbufs (CajaFile *file,
for (l = icons; l != NULL; l = l->next) {
icon = l->data;
- icon_info = caja_icon_info_lookup (icon, size);
+ icon_info = caja_icon_info_lookup (icon, size, 1);
if (force_size) {
pixbuf = caja_icon_info_get_pixbuf_nodefault_at_size (icon_info, size);
} else {
diff --git a/libcaja-private/caja-file.h b/libcaja-private/caja-file.h
index f94bbe33..6a30b618 100644
--- a/libcaja-private/caja-file.h
+++ b/libcaja-private/caja-file.h
@@ -453,10 +453,12 @@ GIcon * caja_file_get_gicon (CajaFile
CajaFileIconFlags flags);
CajaIconInfo * caja_file_get_icon (CajaFile *file,
int size,
+ int scale,
CajaFileIconFlags flags);
GdkPixbuf * caja_file_get_icon_pixbuf (CajaFile *file,
int size,
gboolean force_size,
+ int scale,
CajaFileIconFlags flags);
gboolean caja_file_has_open_window (CajaFile *file);
diff --git a/libcaja-private/caja-icon-canvas-item.c b/libcaja-private/caja-icon-canvas-item.c
index 88908196..98551be4 100644
--- a/libcaja-private/caja-icon-canvas-item.c
+++ b/libcaja-private/caja-icon-canvas-item.c
@@ -83,7 +83,7 @@ struct CajaIconCanvasItemDetails
/* The image, text, font. */
double x, y;
GdkPixbuf *pixbuf;
- GdkPixbuf *rendered_pixbuf;
+ cairo_surface_t *rendered_surface;
GList *emblem_pixbufs;
char *editable_text; /* Text that can be modified by a renaming function */
char *additional_text; /* Text that cannot be modifed, such as file size, etc. */
@@ -278,9 +278,9 @@ caja_icon_canvas_item_finalize (GObject *object)
g_free (details->additional_text);
g_free (details->attach_points);
- if (details->rendered_pixbuf != NULL)
+ if (details->rendered_surface != NULL)
{
- g_object_unref (details->rendered_pixbuf);
+ g_object_unref (details->rendered_surface);
}
if (details->editable_text_layout != NULL)
@@ -498,6 +498,27 @@ caja_icon_canvas_item_get_property (GObject *object,
}
}
+static void
+get_scaled_icon_size (CajaIconCanvasItem *item,
+ gint *width,
+ gint *height)
+{
+ EelCanvas *canvas;
+ GdkPixbuf *pixbuf = NULL;
+ gint scale;
+
+ if (item != NULL) {
+ canvas = EEL_CANVAS_ITEM (item)->canvas;
+ scale = gtk_widget_get_scale_factor (GTK_WIDGET (canvas));
+ pixbuf = item->details->pixbuf;
+ }
+
+ if (width)
+ *width = (pixbuf == NULL) ? 0 : (gdk_pixbuf_get_width (pixbuf) / scale);
+ if (height)
+ *height = (pixbuf == NULL) ? 0 : (gdk_pixbuf_get_height (pixbuf) / scale);
+}
+
cairo_surface_t *
caja_icon_canvas_item_get_drag_surface (CajaIconCanvasItem *item)
{
@@ -506,6 +527,7 @@ caja_icon_canvas_item_get_drag_surface (CajaIconCanvasItem *item)
EelCanvas *canvas;
GdkScreen *screen;
int width, height;
+ int pix_width, pix_height;
int item_offset_x, item_offset_y;
EelIRect icon_rect;
EelIRect emblem_rect;
@@ -554,11 +576,12 @@ caja_icon_canvas_item_get_drag_surface (CajaIconCanvasItem *item)
item_offset_x, item_offset_y);
cairo_surface_destroy (drag_surface);
+ get_scaled_icon_size (item, &pix_width, &pix_height);
icon_rect.x0 = item_offset_x;
icon_rect.y0 = item_offset_y;
- icon_rect.x1 = item_offset_x + gdk_pixbuf_get_width (item->details->pixbuf);
- icon_rect.y1 = item_offset_y + gdk_pixbuf_get_height (item->details->pixbuf);
+ icon_rect.x1 = item_offset_x + pix_width;
+ icon_rect.y1 = item_offset_y + pix_height;
is_rtl = caja_icon_container_is_layout_rtl (CAJA_ICON_CONTAINER (canvas));
@@ -607,10 +630,10 @@ caja_icon_canvas_item_set_image (CajaIconCanvasItem *item,
{
g_object_unref (details->pixbuf);
}
- if (details->rendered_pixbuf != NULL)
+ if (details->rendered_surface != NULL)
{
- g_object_unref (details->rendered_pixbuf);
- details->rendered_pixbuf = NULL;
+ cairo_surface_destroy (details->rendered_surface);
+ details->rendered_surface = NULL;
}
details->pixbuf = image;
@@ -1671,8 +1694,8 @@ draw_pixbuf (GdkPixbuf *pixbuf,
}
/* shared code to highlight or dim the passed-in pixbuf */
-static GdkPixbuf *
-real_map_pixbuf (CajaIconCanvasItem *icon_item)
+static cairo_surface_t *
+real_map_surface (CajaIconCanvasItem *icon_item)
{
EelCanvas *canvas;
char *audio_filename;
@@ -1681,6 +1704,7 @@ real_map_pixbuf (CajaIconCanvasItem *icon_item)
int emblem_size;
GtkStyleContext *style;
GdkRGBA color;
+ cairo_surface_t *surface;
temp_pixbuf = icon_item->details->pixbuf;
canvas = EEL_CANVAS_ITEM(icon_item)->canvas;
@@ -1758,13 +1782,18 @@ real_map_pixbuf (CajaIconCanvasItem *icon_item)
g_object_unref (old_pixbuf);
}
- return temp_pixbuf;
+ surface = gdk_cairo_surface_create_from_pixbuf (temp_pixbuf,
+ gtk_widget_get_scale_factor (GTK_WIDGET (canvas)),
+ gtk_widget_get_window (GTK_WIDGET (canvas)));
+ g_object_unref (temp_pixbuf);
+
+ return surface;
}
-static GdkPixbuf *
-map_pixbuf (CajaIconCanvasItem *icon_item)
+static cairo_surface_t *
+map_surface (CajaIconCanvasItem *icon_item)
{
- if (!(icon_item->details->rendered_pixbuf != NULL
+ if (!(icon_item->details->rendered_surface != NULL
&& icon_item->details->rendered_is_active == icon_item->details->is_active
&& icon_item->details->rendered_is_prelit == icon_item->details->is_prelit
&& icon_item->details->rendered_is_highlighted_for_selection == icon_item->details->is_highlighted_for_selection
@@ -1772,11 +1801,11 @@ map_pixbuf (CajaIconCanvasItem *icon_item)
&& icon_item->details->rendered_is_highlighted_for_clipboard == icon_item->details->is_highlighted_for_clipboard
&& (icon_item->details->is_highlighted_for_selection && icon_item->details->rendered_is_focused == gtk_widget_has_focus (GTK_WIDGET (EEL_CANVAS_ITEM (icon_item)->canvas)))))
{
- if (icon_item->details->rendered_pixbuf != NULL)
+ if (icon_item->details->rendered_surface != NULL)
{
- g_object_unref (icon_item->details->rendered_pixbuf);
+ cairo_surface_destroy (icon_item->details->rendered_surface);
}
- icon_item->details->rendered_pixbuf = real_map_pixbuf (icon_item);
+ icon_item->details->rendered_surface = real_map_surface (icon_item);
icon_item->details->rendered_is_active = icon_item->details->is_active;
icon_item->details->rendered_is_prelit = icon_item->details->is_prelit;
icon_item->details->rendered_is_highlighted_for_selection = icon_item->details->is_highlighted_for_selection;
@@ -1785,9 +1814,9 @@ map_pixbuf (CajaIconCanvasItem *icon_item)
icon_item->details->rendered_is_focused = gtk_widget_has_focus (GTK_WIDGET (EEL_CANVAS_ITEM (icon_item)->canvas));
}
- g_object_ref (icon_item->details->rendered_pixbuf);
+ cairo_surface_reference (icon_item->details->rendered_surface);
- return icon_item->details->rendered_pixbuf;
+ return icon_item->details->rendered_surface;
}
static void
@@ -1863,7 +1892,8 @@ caja_icon_canvas_item_draw (EelCanvasItem *item,
CajaIconCanvasItemDetails *details;
EelIRect icon_rect, emblem_rect;
EmblemLayout emblem_layout;
- GdkPixbuf *emblem_pixbuf, *temp_pixbuf;
+ GdkPixbuf *emblem_pixbuf;
+ cairo_surface_t *temp_surface;
GtkStyleContext *context;
container = CAJA_ICON_CONTAINER (item->canvas);
@@ -1884,12 +1914,12 @@ caja_icon_canvas_item_draw (EelCanvasItem *item,
icon_rect = icon_item->details->canvas_rect;
- temp_pixbuf = map_pixbuf (icon_item);
+ temp_surface = map_surface (icon_item);
- gtk_render_icon (context, cr,
- temp_pixbuf,
- icon_rect.x0, icon_rect.y0);
- g_object_unref (temp_pixbuf);
+ gtk_render_icon_surface (context, cr,
+ temp_surface,
+ icon_rect.x0, icon_rect.y0);
+ cairo_surface_destroy (temp_surface);
draw_embedded_text (icon_item, cr, icon_rect.x0, icon_rect.y0);
@@ -2360,6 +2390,7 @@ caja_icon_canvas_item_ensure_bounds_up_to_date (CajaIconCanvasItem *icon_item)
EelIRect total_rect, total_rect_for_layout, total_rect_for_entire_text;
EelCanvasItem *item;
double pixels_per_unit;
+ gint width, height;
EmblemLayout emblem_layout;
GdkPixbuf *emblem_pixbuf;
gboolean is_rtl;
@@ -2378,20 +2409,13 @@ caja_icon_canvas_item_ensure_bounds_up_to_date (CajaIconCanvasItem *icon_item)
icon_rect.y0 = 0;
icon_rect_raw.x0 = 0;
icon_rect_raw.y0 = 0;
- if (details->pixbuf == NULL)
- {
- icon_rect.x1 = icon_rect.x0;
- icon_rect.y1 = icon_rect.y0;
- icon_rect_raw.x1 = icon_rect_raw.x0;
- icon_rect_raw.y1 = icon_rect_raw.y0;
- }
- else
- {
- icon_rect_raw.x1 = icon_rect_raw.x0 + gdk_pixbuf_get_width (details->pixbuf);
- icon_rect_raw.y1 = icon_rect_raw.y0 + gdk_pixbuf_get_height (details->pixbuf);
- icon_rect.x1 = icon_rect_raw.x1 / pixels_per_unit;
- icon_rect.y1 = icon_rect_raw.y1 / pixels_per_unit;
- }
+
+ get_scaled_icon_size (icon_item, &width, &height);
+
+ icon_rect_raw.x1 = icon_rect_raw.x0 + width;
+ icon_rect_raw.y1 = icon_rect_raw.y0 + height;
+ icon_rect.x1 = icon_rect_raw.x1 / pixels_per_unit;
+ icon_rect.y1 = icon_rect_raw.y1 / pixels_per_unit;
/* Compute text rectangle. */
text_rect = compute_text_rectangle (icon_item, icon_rect, FALSE, BOUNDS_USAGE_FOR_DISPLAY);
@@ -2430,18 +2454,17 @@ caja_icon_canvas_item_get_icon_rectangle (const CajaIconCanvasItem *item)
{
EelDRect rectangle;
double pixels_per_unit;
- GdkPixbuf *pixbuf;
+ gint width, height;
g_return_val_if_fail (CAJA_IS_ICON_CANVAS_ITEM (item), eel_drect_empty);
rectangle.x0 = item->details->x;
rectangle.y0 = item->details->y;
- pixbuf = item->details->pixbuf;
-
pixels_per_unit = EEL_CANVAS_ITEM (item)->canvas->pixels_per_unit;
- rectangle.x1 = rectangle.x0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_width (pixbuf)) / pixels_per_unit;
- rectangle.y1 = rectangle.y0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_height (pixbuf)) / pixels_per_unit;
+ get_scaled_icon_size (EEL_CANVAS_ITEM (item), &width, &height);
+ rectangle.x1 = rectangle.x0 + width / pixels_per_unit;
+ rectangle.y1 = rectangle.y0 + height / pixels_per_unit;
eel_canvas_item_i2w (EEL_CANVAS_ITEM (item),
&rectangle.x0,
@@ -2462,18 +2485,17 @@ caja_icon_canvas_item_get_text_rectangle (CajaIconCanvasItem *item,
EelIRect text_rectangle;
EelDRect ret;
double pixels_per_unit;
- GdkPixbuf *pixbuf;
+ gint width, height;
g_return_val_if_fail (CAJA_IS_ICON_CANVAS_ITEM (item), eel_drect_empty);
icon_rectangle.x0 = item->details->x;
icon_rectangle.y0 = item->details->y;
- pixbuf = item->details->pixbuf;
-
pixels_per_unit = EEL_CANVAS_ITEM (item)->canvas->pixels_per_unit;
- icon_rectangle.x1 = icon_rectangle.x0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_width (pixbuf)) / pixels_per_unit;
- icon_rectangle.y1 = icon_rectangle.y0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_height (pixbuf)) / pixels_per_unit;
+ get_scaled_icon_size (item, &width, &height);
+ icon_rectangle.x1 = icon_rectangle.x0 + width / pixels_per_unit;
+ icon_rectangle.y1 = icon_rectangle.y0 + height / pixels_per_unit;
measure_label_text (item);
@@ -2495,27 +2517,27 @@ caja_icon_canvas_item_get_text_rectangle (CajaIconCanvasItem *item,
return ret;
}
-
/* Get the rectangle of the icon only, in canvas coordinates. */
static void
get_icon_canvas_rectangle (CajaIconCanvasItem *item,
EelIRect *rect)
{
- GdkPixbuf *pixbuf;
+ gint width, height;
g_assert (CAJA_IS_ICON_CANVAS_ITEM (item));
g_assert (rect != NULL);
+
eel_canvas_w2c (EEL_CANVAS_ITEM (item)->canvas,
item->details->x,
item->details->y,
&rect->x0,
&rect->y0);
- pixbuf = item->details->pixbuf;
+ get_scaled_icon_size (item, &width, &height);
- rect->x1 = rect->x0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_width (pixbuf));
- rect->y1 = rect->y0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_height (pixbuf));
+ rect->x1 = rect->x0 + width;
+ rect->y1 = rect->y0 + height;
}
void
@@ -3114,15 +3136,7 @@ caja_icon_canvas_item_accessible_get_image_size
item = CAJA_ICON_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (image)));
- if (!item || !item->details->pixbuf)
- {
- *width = *height = 0;
- }
- else
- {
- *width = gdk_pixbuf_get_width (item->details->pixbuf);
- *height = gdk_pixbuf_get_height (item->details->pixbuf);
- }
+ get_scaled_icon_size (item, width, height);
}
static void
@@ -3224,7 +3238,7 @@ caja_icon_canvas_item_accessible_get_offset_at_point (AtkText *text,
char *icon_text;
gboolean have_editable;
gboolean have_additional;
- gint text_offset;
+ gint text_offset, height;
atk_component_get_extents (ATK_COMPONENT (text), &real_x, &real_y,
&real_width, &real_height, coords);
@@ -3236,7 +3250,8 @@ caja_icon_canvas_item_accessible_get_offset_at_point (AtkText *text,
if (item->details->pixbuf)
{
- y -= gdk_pixbuf_get_height (item->details->pixbuf);
+ get_scaled_icon_size (item, NULL, &height);
+ y -= height;
}
have_editable = item->details->editable_text != NULL &&
item->details->editable_text[0] != '\0';
@@ -3353,14 +3368,15 @@ caja_icon_canvas_item_accessible_get_character_extents (AtkText *text,
PangoRectangle rect;
PangoRectangle rect0;
gboolean have_editable;
- gint text_offset;
+ gint text_offset, pix_height;
atk_component_get_extents (ATK_COMPONENT (text), &pos_x, &pos_y, NULL, NULL, coords);
item = CAJA_ICON_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)));
if (item->details->pixbuf)
{
- pos_y += gdk_pixbuf_get_height (item->details->pixbuf);
+ get_scaled_icon_size (item, NULL, &pix_height);
+ pos_y += pix_height;
}
have_editable = item->details->editable_text != NULL &&
diff --git a/libcaja-private/caja-icon-info.c b/libcaja-private/caja-icon-info.c
index 3cb90c54..7c35f713 100644
--- a/libcaja-private/caja-icon-info.c
+++ b/libcaja-private/caja-icon-info.c
@@ -40,6 +40,8 @@ struct _CajaIconInfo
GdkPoint *attach_points;
char *display_name;
char *icon_name;
+
+ gint orig_scale;
};
struct _CajaIconInfoClass
@@ -121,7 +123,8 @@ caja_icon_info_class_init (CajaIconInfoClass *icon_info_class)
}
CajaIconInfo *
-caja_icon_info_new_for_pixbuf (GdkPixbuf *pixbuf)
+caja_icon_info_new_for_pixbuf (GdkPixbuf *pixbuf,
+ gint scale)
{
CajaIconInfo *icon;
@@ -132,11 +135,14 @@ caja_icon_info_new_for_pixbuf (GdkPixbuf *pixbuf)
icon->pixbuf = g_object_ref (pixbuf);
}
+ icon->orig_scale = scale;
+
return icon;
}
static CajaIconInfo *
-caja_icon_info_new_for_icon_info (GtkIconInfo *icon_info)
+caja_icon_info_new_for_icon_info (GtkIconInfo *icon_info,
+ gint scale)
{
CajaIconInfo *icon;
GdkPoint *points;
@@ -171,6 +177,8 @@ caja_icon_info_new_for_icon_info (GtkIconInfo *icon_info)
icon->icon_name = basename;
}
+ icon->orig_scale = scale;
+
return icon;
}
@@ -347,7 +355,8 @@ themed_icon_key_free (ThemedIconKey *key)
CajaIconInfo *
caja_icon_info_lookup (GIcon *icon,
- int size)
+ int size,
+ int scale)
{
CajaIconInfo *icon_info;
GdkPixbuf *pixbuf;
@@ -378,18 +387,19 @@ caja_icon_info_lookup (GIcon *icon,
pixbuf = NULL;
stream = g_loadable_icon_load (G_LOADABLE_ICON (icon),
- size,
+ size * scale,
NULL, NULL, NULL);
if (stream)
{
pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream,
- size, size, TRUE,
+ size * scale, size * scale,
+ TRUE,
NULL, NULL);
g_input_stream_close (stream, NULL, NULL);
g_object_unref (stream);
}
- icon_info = caja_icon_info_new_for_pixbuf (pixbuf);
+ icon_info = caja_icon_info_new_for_pixbuf (pixbuf, scale);
key = loadable_icon_key_new (icon, size);
g_hash_table_insert (loadable_icon_cache, key, icon_info);
@@ -417,17 +427,18 @@ caja_icon_info_lookup (GIcon *icon,
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
icon_theme = gtk_icon_theme_get_default ();
- gtkicon_info = gtk_icon_theme_choose_icon (icon_theme, (const char **)names, size, 0);
+ gtkicon_info = gtk_icon_theme_choose_icon_for_scale (icon_theme, (const char **)names,
+ size, scale, 0);
if (gtkicon_info == NULL)
{
- return caja_icon_info_new_for_pixbuf (NULL);
+ return caja_icon_info_new_for_pixbuf (NULL, scale);
}
filename = gtk_icon_info_get_filename (gtkicon_info);
if (filename == NULL) {
g_object_unref (gtkicon_info);
- return caja_icon_info_new_for_pixbuf (NULL);
+ return caja_icon_info_new_for_pixbuf (NULL, scale);
}
lookup_key.filename = (char *)filename;
@@ -440,7 +451,7 @@ caja_icon_info_lookup (GIcon *icon,
return g_object_ref (icon_info);
}
- icon_info = caja_icon_info_new_for_icon_info (gtkicon_info);
+ icon_info = caja_icon_info_new_for_icon_info (gtkicon_info, scale);
key = themed_icon_key_new (filename, size);
g_hash_table_insert (themed_icon_cache, key, icon_info);
@@ -454,9 +465,10 @@ caja_icon_info_lookup (GIcon *icon,
GdkPixbuf *pixbuf;
GtkIconInfo *gtk_icon_info;
- gtk_icon_info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
+ gtk_icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (gtk_icon_theme_get_default (),
icon,
size,
+ scale,
GTK_ICON_LOOKUP_FORCE_SIZE);
if (gtk_icon_info != NULL)
{
@@ -468,7 +480,7 @@ caja_icon_info_lookup (GIcon *icon,
pixbuf = NULL;
}
- icon_info = caja_icon_info_new_for_pixbuf (pixbuf);
+ icon_info = caja_icon_info_new_for_pixbuf (pixbuf, scale);
if (pixbuf != NULL) {
g_object_unref (pixbuf);
@@ -480,20 +492,22 @@ caja_icon_info_lookup (GIcon *icon,
CajaIconInfo *
caja_icon_info_lookup_from_name (const char *name,
- int size)
+ int size,
+ int scale)
{
GIcon *icon;
CajaIconInfo *info;
icon = g_themed_icon_new (name);
- info = caja_icon_info_lookup (icon, size);
+ info = caja_icon_info_lookup (icon, size, scale);
g_object_unref (icon);
return info;
}
CajaIconInfo *
caja_icon_info_lookup_from_path (const char *path,
- int size)
+ int size,
+ int scale)
{
GFile *icon_file;
GIcon *icon;
@@ -501,7 +515,7 @@ caja_icon_info_lookup_from_path (const char *path,
icon_file = g_file_new_for_path (path);
icon = g_file_icon_new (icon_file);
- info = caja_icon_info_lookup (icon, size);
+ info = caja_icon_info_lookup (icon, size, scale);
g_object_unref (icon);
g_object_unref (icon_file);
return info;
@@ -568,8 +582,8 @@ caja_icon_info_get_pixbuf_nodefault_at_size (CajaIconInfo *icon,
if (pixbuf == NULL)
return NULL;
- w = gdk_pixbuf_get_width (pixbuf);
- h = gdk_pixbuf_get_height (pixbuf);
+ w = gdk_pixbuf_get_width (pixbuf) / icon->orig_scale;
+ h = gdk_pixbuf_get_height (pixbuf) / icon->orig_scale;
s = MAX (w, h);
if (s == forced_size)
{
@@ -595,8 +609,8 @@ caja_icon_info_get_pixbuf_at_size (CajaIconInfo *icon,
pixbuf = caja_icon_info_get_pixbuf (icon);
- w = gdk_pixbuf_get_width (pixbuf);
- h = gdk_pixbuf_get_height (pixbuf);
+ w = gdk_pixbuf_get_width (pixbuf) / icon->orig_scale;
+ h = gdk_pixbuf_get_height (pixbuf) / icon->orig_scale;
s = MAX (w, h);
if (s == forced_size)
{
diff --git a/libcaja-private/caja-icon-info.h b/libcaja-private/caja-icon-info.h
index d4523d1a..d456e575 100644
--- a/libcaja-private/caja-icon-info.h
+++ b/libcaja-private/caja-icon-info.h
@@ -56,13 +56,17 @@ extern "C" {
GType caja_icon_info_get_type (void) G_GNUC_CONST;
- CajaIconInfo * caja_icon_info_new_for_pixbuf (GdkPixbuf *pixbuf);
+ CajaIconInfo * caja_icon_info_new_for_pixbuf (GdkPixbuf *pixbuf,
+ int scale);
CajaIconInfo * caja_icon_info_lookup (GIcon *icon,
- int size);
+ int size,
+ int scale);
CajaIconInfo * caja_icon_info_lookup_from_name (const char *name,
- int size);
+ int size,
+ int scale);
CajaIconInfo * caja_icon_info_lookup_from_path (const char *path,
- int size);
+ int size,
+ int scale);
gboolean caja_icon_info_is_fallback (CajaIconInfo *icon);
GdkPixbuf * caja_icon_info_get_pixbuf (CajaIconInfo *icon);
GdkPixbuf * caja_icon_info_get_pixbuf_nodefault (CajaIconInfo *icon);
diff --git a/libcaja-private/caja-program-choosing.c b/libcaja-private/caja-program-choosing.c
index bee2bb00..ea1c9739 100644
--- a/libcaja-private/caja-program-choosing.c
+++ b/libcaja-private/caja-program-choosing.c
@@ -243,7 +243,9 @@ caja_launch_application_by_uri (GAppInfo *application,
}
file = caja_file_get_by_uri (uris->data);
- icon = caja_file_get_icon (file, 48, 0);
+ icon = caja_file_get_icon (file,
+ 48, gtk_widget_get_scale_factor (GTK_WIDGET (parent_window)),
+ 0);
caja_file_unref (file);
if (icon)
{
diff --git a/libcaja-private/caja-ui-utilities.c b/libcaja-private/caja-ui-utilities.c
index 8077e975..0bd096e1 100644
--- a/libcaja-private/caja-ui-utilities.c
+++ b/libcaja-private/caja-ui-utilities.c
@@ -138,18 +138,23 @@ extension_action_sensitive_callback (CajaMenuItem *item,
}
static GdkPixbuf *
-get_action_icon (const char *icon_name, int size)
+get_action_icon (const char *icon_name,
+ int size,
+ GtkWidget *parent_widget)
{
CajaIconInfo *info;
GdkPixbuf *pixbuf;
+ int scale;
+
+ scale = gtk_widget_get_scale_factor (parent_widget);
if (g_path_is_absolute (icon_name))
{
- info = caja_icon_info_lookup_from_path (icon_name, size);
+ info = caja_icon_info_lookup_from_path (icon_name, size, scale);
}
else
{
- info = caja_icon_info_lookup_from_name (icon_name, size);
+ info = caja_icon_info_lookup_from_name (icon_name, size, scale);
}
pixbuf = caja_icon_info_get_pixbuf_nodefault_at_size (info, size);
g_object_unref (info);
@@ -158,7 +163,8 @@ get_action_icon (const char *icon_name, int size)
}
GtkAction *
-caja_action_from_menu_item (CajaMenuItem *item)
+caja_action_from_menu_item (CajaMenuItem *item,
+ GtkWidget *parent_widget)
{
char *name, *label, *tip, *icon_name;
gboolean sensitive, priority;
@@ -180,7 +186,8 @@ caja_action_from_menu_item (CajaMenuItem *item)
if (icon_name != NULL)
{
pixbuf = get_action_icon (icon_name,
- caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU));
+ caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU),
+ parent_widget);
if (pixbuf != NULL)
{
g_object_set_data_full (G_OBJECT (action), "menu-icon",
@@ -206,7 +213,7 @@ caja_action_from_menu_item (CajaMenuItem *item)
}
GtkAction *
-caja_toolbar_action_from_menu_item (CajaMenuItem *item)
+caja_toolbar_action_from_menu_item (CajaMenuItem *item, GtkWidget *parent_widget)
{
char *name, *label, *tip, *icon_name;
gboolean sensitive, priority;
@@ -228,7 +235,8 @@ caja_toolbar_action_from_menu_item (CajaMenuItem *item)
if (icon_name != NULL)
{
pixbuf = get_action_icon (icon_name,
- caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_LARGE_TOOLBAR));
+ caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_LARGE_TOOLBAR),
+ parent_widget);
if (pixbuf != NULL)
{
g_object_set_data_full (G_OBJECT (action), "toolbar-icon",
diff --git a/libcaja-private/caja-ui-utilities.h b/libcaja-private/caja-ui-utilities.h
index 7fed1f5e..c7a8d595 100644
--- a/libcaja-private/caja-ui-utilities.h
+++ b/libcaja-private/caja-ui-utilities.h
@@ -36,8 +36,8 @@ void caja_ui_prepare_merge_ui (GtkUIManager *ui_manager,
const char *name,
guint *merge_id,
GtkActionGroup **action_group);
-GtkAction * caja_action_from_menu_item (CajaMenuItem *item);
-GtkAction * caja_toolbar_action_from_menu_item (CajaMenuItem *item);
+GtkAction * caja_action_from_menu_item (CajaMenuItem *item, GtkWidget *parent_widget);
+GtkAction * caja_toolbar_action_from_menu_item (CajaMenuItem *item, GtkWidget *parent_widget);
const char *caja_ui_string_get (const char *filename);
void caja_ui_frame_image (GdkPixbuf **pixbuf);