summaryrefslogtreecommitdiff
path: root/src/file-manager
diff options
context:
space:
mode:
authorCosimo Cecchi <[email protected]>2013-08-02 14:37:13 +0200
committerlukefromdc <[email protected]>2018-04-04 21:53:21 -0400
commitbc1405c9f54e19e74f973581130229ef1053ff9c (patch)
tree8ae544cad7a3b815ff6c48304ced204f37dd4947 /src/file-manager
parent779e0af4042b6572d729190067cfee6a876d73e5 (diff)
downloadcaja-bc1405c9f54e19e74f973581130229ef1053ff9c.tar.bz2
caja-bc1405c9f54e19e74f973581130229ef1053ff9c.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 'src/file-manager')
-rw-r--r--src/file-manager/fm-desktop-icon-view.c7
-rw-r--r--src/file-manager/fm-directory-view.c32
-rw-r--r--src/file-manager/fm-icon-container.c5
-rw-r--r--src/file-manager/fm-list-model.c38
-rw-r--r--src/file-manager/fm-list-view.c14
-rw-r--r--src/file-manager/fm-properties-window.c23
-rw-r--r--src/file-manager/fm-tree-model.c10
7 files changed, 94 insertions, 35 deletions
diff --git a/src/file-manager/fm-desktop-icon-view.c b/src/file-manager/fm-desktop-icon-view.c
index 98a0258e..8cbf0b62 100644
--- a/src/file-manager/fm-desktop-icon-view.c
+++ b/src/file-manager/fm-desktop-icon-view.c
@@ -120,11 +120,10 @@ icon_container_set_workarea (CajaIconContainer *icon_container,
left = right = top = bottom = 0;
- screen_width = WidthOfScreen (gdk_x11_screen_get_xscreen (screen));
- screen_height = HeightOfScreen (gdk_x11_screen_get_xscreen (screen));
-
scale = gdk_window_get_scale_factor (gdk_screen_get_root_window (screen));
- scale = scale ? scale : 1;
+
+ screen_width = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
+ screen_height = HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
for (i = 0; i < n_items; i += 4)
{
diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c
index 90697145..46a8fd42 100644
--- a/src/file-manager/fm-directory-view.c
+++ b/src/file-manager/fm-directory-view.c
@@ -4903,18 +4903,20 @@ extension_action_callback (GtkAction *action,
}
static GdkPixbuf *
-get_menu_icon (const char *icon_name)
+get_menu_icon (const char *icon_name,
+ GtkWidget *widget)
{
CajaIconInfo *info;
GdkPixbuf *pixbuf;
- int size;
+ int size, scale;
size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);
+ scale = gtk_widget_get_scale_factor (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);
@@ -4923,15 +4925,17 @@ get_menu_icon (const char *icon_name)
}
static GdkPixbuf *
-get_menu_icon_for_file (CajaFile *file)
+get_menu_icon_for_file (CajaFile *file,
+ GtkWidget *widget)
{
CajaIconInfo *info;
GdkPixbuf *pixbuf;
- int size;
+ int size, scale;
size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);
+ scale = gtk_widget_get_scale_factor (widget);
- info = caja_file_get_icon (file, size, 0);
+ info = caja_file_get_icon (file, size, scale, 0);
pixbuf = caja_icon_info_get_pixbuf_nodefault_at_size (info, size);
g_object_unref (info);
@@ -4962,7 +4966,7 @@ add_extension_action_for_files (FMDirectoryView *view,
icon);
if (icon != NULL) {
- pixbuf = get_menu_icon (icon);
+ pixbuf = get_menu_icon (icon, GTK_WIDGET (view));
if (pixbuf != NULL) {
g_object_set_data_full (G_OBJECT (action), "menu-icon",
pixbuf,
@@ -5429,7 +5433,7 @@ add_script_to_scripts_menus (FMDirectoryView *directory_view,
tip,
NULL);
- pixbuf = get_menu_icon_for_file (file);
+ pixbuf = get_menu_icon_for_file (file, GTK_WIDGET (directory_view));
if (pixbuf != NULL) {
g_object_set_data_full (G_OBJECT (action), "menu-icon",
pixbuf,
@@ -5493,7 +5497,7 @@ add_submenu_to_directory_menus (FMDirectoryView *directory_view,
ui_manager = caja_window_info_get_ui_manager (directory_view->details->window);
uri = caja_file_get_uri (file);
name = caja_file_get_display_name (file);
- pixbuf = get_menu_icon_for_file (file);
+ pixbuf = get_menu_icon_for_file (file, GTK_WIDGET (directory_view));
add_submenu (ui_manager, action_group, merge_id, menu_path, uri, name, pixbuf, TRUE);
add_submenu (ui_manager, action_group, merge_id, popup_path, uri, name, pixbuf, FALSE);
add_submenu (ui_manager, action_group, merge_id, popup_bg_path, uri, name, pixbuf, FALSE);
@@ -5680,7 +5684,7 @@ add_template_to_templates_menus (FMDirectoryView *directory_view,
tip,
NULL);
- pixbuf = get_menu_icon_for_file (file);
+ pixbuf = get_menu_icon_for_file (file, GTK_WIDGET (directory_view));
if (pixbuf != NULL) {
g_object_set_data_full (G_OBJECT (action), "menu-icon",
pixbuf,
@@ -6978,6 +6982,7 @@ action_connect_to_server_link_callback (GtkAction *action,
GtkWidget *entry;
GtkWidget *box;
char *title;
+ gint scale;
view = FM_DIRECTORY_VIEW (data);
@@ -6989,9 +6994,10 @@ action_connect_to_server_link_callback (GtkAction *action,
}
file = CAJA_FILE (selection->data);
+ scale = gtk_widget_get_scale_factor (GTK_WIDGET (view));
uri = caja_file_get_activation_uri (file);
- icon = caja_file_get_icon (file, CAJA_ICON_SIZE_STANDARD, 0);
+ icon = caja_file_get_icon (file, CAJA_ICON_SIZE_STANDARD, scale, 0);
icon_name = caja_icon_info_get_used_name (icon);
name = caja_file_get_display_name (file);
@@ -7583,7 +7589,7 @@ connect_proxy (FMDirectoryView *view,
if (strcmp (gtk_action_get_name (action), FM_ACTION_NEW_EMPTY_FILE) == 0 &&
GTK_IS_IMAGE_MENU_ITEM (proxy)) {
- pixbuf = get_menu_icon ("text-x-generic");
+ pixbuf = get_menu_icon ("text-x-generic", GTK_WIDGET (view));
if (pixbuf != NULL) {
image = gtk_image_new_from_pixbuf (pixbuf);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy), image);
diff --git a/src/file-manager/fm-icon-container.c b/src/file-manager/fm-icon-container.c
index be3acee2..f744d65a 100644
--- a/src/file-manager/fm-icon-container.c
+++ b/src/file-manager/fm-icon-container.c
@@ -65,6 +65,7 @@ fm_icon_container_get_icon_images (CajaIconContainer *container,
gboolean use_embedding;
CajaFileIconFlags flags;
guint emblem_size;
+ gint scale;
file = (CajaFile *) data;
@@ -119,7 +120,9 @@ fm_icon_container_get_icon_images (CajaIconContainer *container,
flags |= CAJA_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
}
- return caja_file_get_icon (file, size, flags);
+ scale = gtk_widget_get_scale_factor (GTK_WIDGET (icon_view));
+
+ return caja_file_get_icon (file, size, scale, flags);
}
static char *
diff --git a/src/file-manager/fm-list-model.c b/src/file-manager/fm-list-model.c
index 315fef70..715303b5 100644
--- a/src/file-manager/fm-list-model.c
+++ b/src/file-manager/fm-list-model.c
@@ -34,10 +34,12 @@
#include <glib/gi18n.h>
#include <libcaja-private/caja-dnd.h>
#include <glib.h>
+#include <cairo-gobject.h>
enum
{
SUBDIRECTORY_UNLOADED,
+ GET_ICON_SCALE,
LAST_SIGNAL
};
@@ -163,7 +165,7 @@ fm_list_model_get_column_type (GtkTreeModel *tree_model, int index)
case FM_LIST_MODEL_LARGE_ICON_COLUMN:
case FM_LIST_MODEL_LARGER_ICON_COLUMN:
case FM_LIST_MODEL_LARGEST_ICON_COLUMN:
- return GDK_TYPE_PIXBUF;
+ return CAIRO_GOBJECT_TYPE_SURFACE;
case FM_LIST_MODEL_FILE_NAME_IS_EDITABLE_COLUMN:
return G_TYPE_BOOLEAN;
default:
@@ -259,6 +261,21 @@ fm_list_model_get_path (GtkTreeModel *tree_model, GtkTreeIter *iter)
return path;
}
+static gint
+fm_list_model_get_icon_scale (FMListModel *model)
+{
+ gint retval = -1;
+
+ g_signal_emit (model, list_model_signals[GET_ICON_SCALE], 0,
+ &retval);
+
+ if (retval == -1) {
+ retval = gdk_screen_get_monitor_scale_factor (gdk_screen_get_default (), 0);
+ }
+
+ return retval;
+}
+
static void
fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value)
{
@@ -271,12 +288,13 @@ fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column
CajaIconInfo *icon_info;
GEmblem *emblem;
GList *emblem_icons, *l;
- int icon_size;
+ int icon_size, icon_scale;
CajaZoomLevel zoom_level;
CajaFile *parent_file;
char *emblems_to_ignore[3];
int i;
CajaFileIconFlags flags;
+ cairo_surface_t *surface;
model = (FMListModel *)tree_model;
@@ -305,12 +323,13 @@ fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column
case FM_LIST_MODEL_LARGE_ICON_COLUMN:
case FM_LIST_MODEL_LARGER_ICON_COLUMN:
case FM_LIST_MODEL_LARGEST_ICON_COLUMN:
- g_value_init (value, GDK_TYPE_PIXBUF);
+ g_value_init (value, CAIRO_GOBJECT_TYPE_SURFACE);
if (file != NULL)
{
zoom_level = fm_list_model_get_zoom_level_from_column_id (column);
icon_size = caja_get_icon_size_for_zoom_level (zoom_level);
+ icon_scale = fm_list_model_get_icon_scale (model);
flags = CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS |
CAJA_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE |
@@ -376,7 +395,7 @@ fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column
gicon = emblemed_icon;
}
- icon_info = caja_icon_info_lookup (gicon, icon_size);
+ icon_info = caja_icon_info_lookup (gicon, icon_size, icon_scale);
icon = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
g_object_unref (icon_info);
@@ -395,7 +414,8 @@ fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column
}
}
- g_value_set_object (value, icon);
+ surface = gdk_cairo_surface_create_from_pixbuf (icon, icon_scale, NULL);
+ g_value_take_boxed (value, surface);
g_object_unref (icon);
}
break;
@@ -1675,6 +1695,14 @@ fm_list_model_class_init (FMListModelClass *klass)
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
CAJA_TYPE_DIRECTORY);
+
+ list_model_signals[GET_ICON_SCALE] =
+ g_signal_new ("get-icon-scale",
+ FM_TYPE_LIST_MODEL,
+ G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ NULL,
+ G_TYPE_INT, 0);
}
static void
diff --git a/src/file-manager/fm-list-view.c b/src/file-manager/fm-list-view.c
index d2353e7a..b68b6a31 100644
--- a/src/file-manager/fm-list-view.c
+++ b/src/file-manager/fm-list-view.c
@@ -1638,6 +1638,13 @@ focus_in_event_callback (GtkWidget *widget, GdkEventFocus *event, gpointer user_
return FALSE;
}
+static gint
+get_icon_scale_callback (FMListModel *model,
+ FMListView *view)
+{
+ return gtk_widget_get_scale_factor (GTK_WIDGET (view->details->tree_view));
+}
+
static void
create_and_set_up_tree_view (FMListView *view)
{
@@ -1727,6 +1734,9 @@ create_and_set_up_tree_view (FMListView *view)
g_signal_connect_object (view->details->model, "subdirectory_unloaded",
G_CALLBACK (subdirectory_unloaded_callback), view, 0);
+ g_signal_connect_object (view->details->model, "get-icon-scale",
+ G_CALLBACK (get_icon_scale_callback), view, 0);
+
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (view->details->tree_view), GTK_SELECTION_MULTIPLE);
caja_columns = caja_get_all_columns ();
@@ -1782,7 +1792,7 @@ create_and_set_up_tree_view (FMListView *view)
gtk_tree_view_column_pack_start (view->details->file_name_column, cell, FALSE);
gtk_tree_view_column_set_attributes (view->details->file_name_column,
cell,
- "pixbuf", FM_LIST_MODEL_SMALLEST_ICON_COLUMN,
+ "surface", FM_LIST_MODEL_SMALLEST_ICON_COLUMN,
NULL);
cell = gtk_cell_renderer_text_new ();
@@ -2779,7 +2789,7 @@ fm_list_view_set_zoom_level (FMListView *view,
column = fm_list_model_get_column_id_from_zoom_level (new_level);
gtk_tree_view_column_set_attributes (view->details->file_name_column,
GTK_CELL_RENDERER (view->details->pixbuf_cell),
- "pixbuf", column,
+ "surface", column,
NULL);
/* Scale text. */
diff --git a/src/file-manager/fm-properties-window.c b/src/file-manager/fm-properties-window.c
index 56af2094..6de9f98a 100644
--- a/src/file-manager/fm-properties-window.c
+++ b/src/file-manager/fm-properties-window.c
@@ -363,17 +363,24 @@ get_image_for_properties_window (FMPropertiesWindow *window,
{
CajaIconInfo *icon, *new_icon;
GList *l;
+ gint icon_scale;
icon = NULL;
+ icon_scale = gtk_widget_get_scale_factor (GTK_WIDGET (window->details->notebook));
+
for (l = window->details->original_files; l != NULL; l = l->next) {
CajaFile *file;
file = CAJA_FILE (l->data);
if (!icon) {
- icon = caja_file_get_icon (file, CAJA_ICON_SIZE_STANDARD, CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS | CAJA_FILE_ICON_FLAGS_IGNORE_VISITING);
+ icon = caja_file_get_icon (file, CAJA_ICON_SIZE_STANDARD, icon_scale,
+ CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS |
+ CAJA_FILE_ICON_FLAGS_IGNORE_VISITING);
} else {
- new_icon = caja_file_get_icon (file, CAJA_ICON_SIZE_STANDARD, CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS | CAJA_FILE_ICON_FLAGS_IGNORE_VISITING);
+ new_icon = caja_file_get_icon (file, CAJA_ICON_SIZE_STANDARD, icon_scale,
+ CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS |
+ CAJA_FILE_ICON_FLAGS_IGNORE_VISITING);
if (!new_icon || new_icon != icon) {
g_object_unref (icon);
g_object_unref (new_icon);
@@ -385,7 +392,9 @@ get_image_for_properties_window (FMPropertiesWindow *window,
}
if (!icon) {
- icon = caja_icon_info_lookup_from_name ("text-x-generic", CAJA_ICON_SIZE_STANDARD);
+ icon = caja_icon_info_lookup_from_name ("text-x-generic",
+ CAJA_ICON_SIZE_STANDARD,
+ icon_scale);
}
if (icon_name != NULL) {
@@ -3412,6 +3421,7 @@ create_emblems_page (FMPropertiesWindow *window)
char *label;
GList *icons, *l;
CajaIconInfo *info;
+ gint scale;
/* The emblems wrapped table */
scroller = eel_scrolled_wrap_table_new (TRUE, GTK_SHADOW_NONE, &emblems_table);
@@ -3427,6 +3437,7 @@ create_emblems_page (FMPropertiesWindow *window)
scroller, gtk_label_new (_("Emblems")));
icons = caja_emblem_list_available ();
+ scale = gtk_widget_get_scale_factor (scroller);
window->details->initial_emblems = get_initial_emblems (window->details->original_files);
@@ -3439,7 +3450,7 @@ create_emblems_page (FMPropertiesWindow *window)
continue;
}
- info = caja_icon_info_lookup_from_name (emblem_name, CAJA_ICON_SIZE_SMALL);
+ info = caja_icon_info_lookup_from_name (emblem_name, CAJA_ICON_SIZE_SMALL, scale);
pixbuf = caja_icon_info_get_pixbuf_nodefault_at_size (info, CAJA_ICON_SIZE_SMALL);
if (pixbuf == NULL) {
@@ -3454,8 +3465,8 @@ create_emblems_page (FMPropertiesWindow *window)
}
button = eel_labeled_image_check_button_new (label, pixbuf);
- eel_labeled_image_set_fixed_image_height (EEL_LABELED_IMAGE (gtk_bin_get_child (GTK_BIN (button))), STANDARD_EMBLEM_HEIGHT);
- eel_labeled_image_set_spacing (EEL_LABELED_IMAGE (gtk_bin_get_child (GTK_BIN (button))), EMBLEM_LABEL_SPACING);
+ eel_labeled_image_set_fixed_image_height (EEL_LABELED_IMAGE (gtk_bin_get_child (GTK_BIN (button))), STANDARD_EMBLEM_HEIGHT * scale);
+ eel_labeled_image_set_spacing (EEL_LABELED_IMAGE (gtk_bin_get_child (GTK_BIN (button))), EMBLEM_LABEL_SPACING * scale);
g_free (label);
g_object_unref (pixbuf);
diff --git a/src/file-manager/fm-tree-model.c b/src/file-manager/fm-tree-model.c
index cf400375..e3bcfd3c 100644
--- a/src/file-manager/fm-tree-model.c
+++ b/src/file-manager/fm-tree-model.c
@@ -258,11 +258,12 @@ get_menu_icon (GIcon *icon)
{
CajaIconInfo *info;
GdkPixbuf *pixbuf;
- int size;
+ int size, scale;
size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);
+ scale = gdk_window_get_scale_factor (gdk_get_default_root_window ());
- info = caja_icon_info_lookup (icon, size);
+ info = caja_icon_info_lookup (icon, size, scale);
pixbuf = caja_icon_info_get_pixbuf_nodefault_at_size (info, size);
g_object_unref (info);
@@ -279,13 +280,14 @@ get_menu_icon_for_file (TreeNode *node,
GEmblem *emblem;
GdkPixbuf *pixbuf, *retval;
gboolean highlight;
- int size;
+ int size, scale;
FMTreeModel *model;
GList *emblem_icons, *l;
char *emblems_to_ignore[3];
int i;
size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);
+ scale = gdk_window_get_scale_factor (gdk_get_default_root_window ());
gicon = caja_file_get_gicon (file, flags);
@@ -321,7 +323,7 @@ get_menu_icon_for_file (TreeNode *node,
g_list_free_full (emblem_icons, g_object_unref);
- info = caja_icon_info_lookup (gicon, size);
+ info = caja_icon_info_lookup (gicon, size, scale);
retval = caja_icon_info_get_pixbuf_nodefault_at_size (info, size);
model = node->root->model;