Adapt zoom level for high dpi displays (#67).
authorDaniel Carl <danielcarl@gmx.de>
Wed, 5 Mar 2014 21:39:34 +0000 (22:39 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Wed, 5 Mar 2014 21:39:34 +0000 (22:39 +0100)
src/config.def.h
src/main.c
src/main.h
src/normal.c

index 3986b24..ff0807d 100644 (file)
@@ -36,6 +36,8 @@
 #define FEATURE_TITLE_PROGRESS
 /* should the history indicator [+-] be shown in status bar after url */
 #define FEATURE_HISTORY_INDICATOR
+/* enables workaround for hight dpi displays */
+#define FEATURE_HIGH_DPI
 
 
 /* time in seconds after that message will be removed from inputbox if the
index 8532898..f6cbfd8 100644 (file)
@@ -653,6 +653,24 @@ static void init_core(void)
 
     /* make sure the main window and all its contents are visible */
     gtk_widget_show_all(gui->window);
+
+    vb.config.default_zoom = 1.0;
+
+#ifdef FEATURE_HIGH_DPI
+    /* fix for high dpi displays */
+    GdkScreen *screen = gdk_window_get_screen(GTK_WIDGET(vb.gui.window)->window);
+    gdouble dpi = gdk_screen_get_resolution(screen);
+    if (dpi != -1) {
+        WebKitWebSettings *setting = webkit_web_view_get_settings(gui->webview);
+        webkit_web_view_set_full_content_zoom(gui->webview, true);
+        g_object_set(G_OBJECT(setting), "enforce-96-dpi", true, NULL);
+
+        /* calculate the zoom level based on 96 dpi */
+        vb.config.default_zoom = dpi/96;
+
+        webkit_web_view_set_zoom_level(gui->webview, vb.config.default_zoom);
+    }
+#endif
 }
 
 static void marks_clear(void)
index 4717989..a59ba0a 100644 (file)
@@ -302,6 +302,7 @@ typedef struct {
     char         *autocmd;        /* command given by --cmd option */
     char         *cafile;         /* path to the ca file */
     GTlsDatabase *tls_db;         /* tls database */
+    float        default_zoom;    /* default zoomlevel that is applied on zz zoom reset */
 } Config;
 
 typedef struct {
index e69f13e..ccdc24f 100644 (file)
@@ -776,7 +776,11 @@ static VbResult normal_zoom(const NormalCmdInfo *info)
     count = info->count ? (float)info->count : 1.0;
 
     if (info->key2 == 'z') { /* zz reset zoom */
-        webkit_web_view_set_zoom_level(view, 1.0);
+#ifdef FEATURE_HIGH_DPI
+        /* to set the zoom for high dpi displays we need full content zoom */
+        webkit_web_view_set_full_content_zoom(view, true);
+#endif
+        webkit_web_view_set_zoom_level(view, vb.config.default_zoom);
 
         return RESULT_COMPLETE;
     }