Zoom amount overcorrects for HiDPI
On my laptop with 2x scaling, the zoom amount is calculated incorrectly, so that 100% is very large and 50% is a regular size.
Here is a 1920x1080 no-HiDPI screenshot:
And here is a 3840x2160 2x scaling screenshot, where everything is the same physical size, but scaled to 2 physical pixels per logical dot:
Note that in the first, it thinks it is 56.6%, while in the second, it wrongly thinks it's half that size, only 28.3%.
This diff resolved the problem for me:
diff --git a/libdocument/ev-document-misc.c b/libdocument/ev-document-misc.c
index cf983bde..0e9a450a 100644
--- a/libdocument/ev-document-misc.c
+++ b/libdocument/ev-document-misc.c
@@ -566,7 +566,7 @@ ev_document_misc_get_widget_dpi (GtkWidget *widget)
GdkDisplay *display;
GdkMonitor *monitor;
GdkWindow *window;
- gdouble dp, di;
+ gdouble pixels, dots, inches;
display = gtk_widget_get_display (widget);
window = gtk_widget_get_window (widget);
@@ -581,16 +581,25 @@ ev_document_misc_get_widget_dpi (GtkWidget *widget)
if (monitor != NULL) {
/* diagonal in pixels */
gdk_monitor_get_geometry (monitor, &geometry);
- dp = hypot (geometry.width, geometry.height);
- if (dp == 0)
+ pixels = hypot (geometry.width, geometry.height);
+ if (pixels == 0)
return 96;
+ /* diagonal in dots */
+#ifdef HAVE_HIDPI_SUPPORT
+ dots = pixels / gdk_monitor_get_scale_factor (monitor);
+#else
+ dots = pixels;
+#endif
+
/* diagonal in inches */
- di = hypot (gdk_monitor_get_width_mm (monitor), gdk_monitor_get_height_mm (monitor)) / 25.4;
- if (di == 0)
+ inches = hypot (gdk_monitor_get_width_mm (monitor), gdk_monitor_get_height_mm (monitor)) / 25.4;
+ if (inches == 0)
return 96;
- return (dp / di);
+ return (dots / inches);
} else {
return 96;
}
It seems that it was calculating the PPI, and using that as the logical DPI to calculate the zoom amount. I'm unfamiliar with G[td]k though, so since I only tried it on my own computer, I'm not confident enough to submit a PR.