From 315b9912e1c381d7af8e0dc26b76b4749172541b Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Wed, 5 Mar 2014 22:39:34 +0100 Subject: [PATCH] Adapt zoom level for high dpi displays (#67). --- src/config.def.h | 2 ++ src/main.c | 18 ++++++++++++++++++ src/main.h | 1 + src/normal.c | 6 +++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/config.def.h b/src/config.def.h index 3986b24..ff0807d 100644 --- a/src/config.def.h +++ b/src/config.def.h @@ -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 diff --git a/src/main.c b/src/main.c index 8532898..f6cbfd8 100644 --- a/src/main.c +++ b/src/main.c @@ -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) diff --git a/src/main.h b/src/main.h index 4717989..a59ba0a 100644 --- a/src/main.h +++ b/src/main.h @@ -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 { diff --git a/src/normal.c b/src/normal.c index e69f13e..ccdc24f 100644 --- a/src/normal.c +++ b/src/normal.c @@ -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; } -- 2.20.1