Blob Blame Raw
From 8b881f9b4ce47ec11ebb93ee63550acda7228b25 Mon Sep 17 00:00:00 2001
From: Michael Webster <miketwebster@gmail.com>
Date: Sat, 6 May 2017 19:12:11 -0400
Subject: [PATCH] icon view/desktop: Fix hidpi scaling on the desktop.  This
 also fixes compact view mode in hidpi, which was semi-broken since hidpi was
 implemented, and very broken since the desktop grid was added.

---
 libnemo-private/nemo-icon-container.c | 27 ++++++++++++++++----
 src/nemo-icon-view.c                  | 46 ++++++++++++++++++++++++-----------
 2 files changed, 54 insertions(+), 19 deletions(-)

diff --git a/libnemo-private/nemo-icon-container.c b/libnemo-private/nemo-icon-container.c
index a9b2fbb..40d63cc 100644
--- a/libnemo-private/nemo-icon-container.c
+++ b/libnemo-private/nemo-icon-container.c
@@ -1102,6 +1102,19 @@ invalidate_label_sizes (NemoIconContainer *container)
 	}
 }
 
+static void
+update_icons (NemoIconContainer *container)
+{
+    GList *p;
+    NemoIcon *icon;
+
+    for (p = container->details->icons; p != NULL; p = p->next) {
+        icon = p->data;
+
+        nemo_icon_container_update_icon (container, icon);
+    }
+}
+
 static gboolean
 select_range (NemoIconContainer *container,
 	      NemoIcon *icon1,
@@ -5807,11 +5820,14 @@ nemo_icon_container_update_icon (NemoIconContainer *container,
 							     large_embedded_text, &embedded_text_needs_loading,
 							     &has_open_window);
 
-	if (container->details->forced_icon_size > 0) {
-		pixbuf = nemo_icon_info_get_pixbuf_at_size (icon_info, icon_size);
-	} else {
-		pixbuf = nemo_icon_info_get_pixbuf (icon_info);
-	}
+    if (container->details->forced_icon_size > 0) {
+        gint scale_factor;
+
+        scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (container));
+        pixbuf = nemo_icon_info_get_pixbuf_at_size (icon_info, icon_size * scale_factor);
+    } else {
+        pixbuf = nemo_icon_info_get_pixbuf (icon_info);
+    }
 
 	nemo_icon_info_get_attach_points (icon_info, &attach_points, &n_attach_points);
 	has_embedded_text_rect = nemo_icon_info_get_embedded_rect (icon_info,
@@ -7374,6 +7390,7 @@ nemo_icon_container_set_forced_icon_size (NemoIconContainer *container,
 		container->details->forced_icon_size = forced_icon_size;
 
 		invalidate_label_sizes (container);
+        update_icons (container);
 		nemo_icon_container_request_update_all (container);
 	}
 }
diff --git a/src/nemo-icon-view.c b/src/nemo-icon-view.c
index 2eba863..40b5878 100644
--- a/src/nemo-icon-view.c
+++ b/src/nemo-icon-view.c
@@ -2545,6 +2545,29 @@ nemo_icon_view_get_id (NemoView *view)
 }
 
 static void
+set_compact_view (NemoIconView *icon_view,
+                  gboolean      compact)
+{
+    icon_view->details->compact = compact;
+
+    if (compact) {
+        nemo_icon_container_set_layout_mode (get_icon_container (icon_view),
+                                             gtk_widget_get_direction (GTK_WIDGET(icon_view)) == GTK_TEXT_DIR_RTL ?
+                                                                                                     NEMO_ICON_LAYOUT_T_B_R_L :
+                                                                                                     NEMO_ICON_LAYOUT_T_B_L_R);
+        nemo_icon_container_set_forced_icon_size (get_icon_container (icon_view),
+                                                  NEMO_ICON_SIZE_SMALLEST);
+    } else {
+        nemo_icon_container_set_layout_mode (get_icon_container (icon_view),
+                                             gtk_widget_get_direction (GTK_WIDGET(icon_view)) == GTK_TEXT_DIR_RTL ?
+                                                                                                     NEMO_ICON_LAYOUT_R_L_T_B :
+                                                                                                     NEMO_ICON_LAYOUT_L_R_T_B);
+        nemo_icon_container_set_forced_icon_size (get_icon_container (icon_view),
+                                                  0);
+    }
+}
+
+static void
 nemo_icon_view_set_property (GObject         *object,
 			   guint            prop_id,
 			   const GValue    *value,
@@ -2556,15 +2579,7 @@ nemo_icon_view_set_property (GObject         *object,
 
 	switch (prop_id)  {
 	case PROP_COMPACT:
-		icon_view->details->compact = g_value_get_boolean (value);
-		if (icon_view->details->compact) {
-			nemo_icon_container_set_layout_mode (get_icon_container (icon_view),
-								 gtk_widget_get_direction (GTK_WIDGET(icon_view)) == GTK_TEXT_DIR_RTL ?
-								 NEMO_ICON_LAYOUT_T_B_R_L :
-								 NEMO_ICON_LAYOUT_T_B_L_R);
-			nemo_icon_container_set_forced_icon_size (get_icon_container (icon_view),
-								      NEMO_ICON_SIZE_SMALLEST);
-		}
+        set_compact_view (icon_view, g_value_get_boolean (value));
 		break;
 	case PROP_SUPPORTS_AUTO_LAYOUT:
 		icon_view->details->supports_auto_layout = g_value_get_boolean (value);
@@ -2764,8 +2779,7 @@ nemo_icon_view_class_init (NemoIconViewClass *klass)
 				      "Compact",
 				      "Whether this view provides a compact listing",
 				      FALSE,
-				      G_PARAM_WRITABLE |
-				      G_PARAM_CONSTRUCT_ONLY);
+				      G_PARAM_WRITABLE);
 	properties[PROP_SUPPORTS_AUTO_LAYOUT] =
 		g_param_spec_boolean ("supports-auto-layout",
 				      "Supports auto layout",
@@ -2812,11 +2826,13 @@ nemo_icon_view_create (NemoWindowSlot *slot)
 
 	view = g_object_new (NEMO_TYPE_ICON_VIEW,
 			     "window-slot", slot,
-			     "compact", FALSE,
 			     NULL);
 #if GTK_CHECK_VERSION (3, 20, 0)
 	gtk_style_context_add_class (gtk_widget_get_style_context (view), GTK_STYLE_CLASS_VIEW);
 #endif
+
+    set_compact_view (view, FALSE);
+
 	return NEMO_VIEW (view);
 }
 
@@ -2827,12 +2843,14 @@ nemo_compact_view_create (NemoWindowSlot *slot)
 
 	view = g_object_new (NEMO_TYPE_ICON_VIEW,
 			     "window-slot", slot,
-			     "compact", TRUE,
 			     NULL);
 #if GTK_CHECK_VERSION (3, 20, 0)
 	gtk_style_context_add_class (gtk_widget_get_style_context (view), GTK_STYLE_CLASS_VIEW);
 #endif
-	return NEMO_VIEW (view);
+
+    set_compact_view (view, TRUE);
+
+    return NEMO_VIEW (view);
 }
 
 static gboolean