Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3326)

Unified Diff: chrome/browser/ui/libgtkui/gtk_ui.cc

Issue 2899943002: Gtk: Consider font dpi when calculating device scale factor (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/libgtkui/gtk_ui.cc
diff --git a/chrome/browser/ui/libgtkui/gtk_ui.cc b/chrome/browser/ui/libgtkui/gtk_ui.cc
index 546beeefa0ca0880917ed3e4862d8113c6d45d7c..cef1ef060470e395ed5c13fd59e297883d2f1cb6 100644
--- a/chrome/browser/ui/libgtkui/gtk_ui.cc
+++ b/chrome/browser/ui/libgtkui/gtk_ui.cc
@@ -315,14 +315,27 @@ gfx::FontRenderParams GetGtkFontRenderParams() {
return params;
}
-float GetGdkWindowScalingFactor() {
- GValue scale = G_VALUE_INIT;
- g_value_init(&scale, G_TYPE_INT);
- if (!gdk_screen_get_setting(gdk_screen_get_default(),
- "gdk-window-scaling-factor", &scale))
+float GtkDpiToScaleFactor(int dpi) {
+ // GTK multiplies the DPI by 1024 before storing it.
+ return dpi / (1024 * kDefaultDPI);
+}
+
+gint GetGdkScreenSettingInt(const char* setting_name) {
+ GValue value = G_VALUE_INIT;
+ g_value_init(&value, G_TYPE_INT);
+ if (!gdk_screen_get_setting(gdk_screen_get_default(), setting_name, &value))
return -1;
+ return g_value_get_int(&value);
+}
- return g_value_get_int(&scale);
+float GetScaleFromGdkScreenSettings() {
+ gint window_scale = GetGdkScreenSettingInt("gdk-window-scaling-factor");
+ if (window_scale <= 0)
+ return -1;
+ gint font_dpi = GetGdkScreenSettingInt("gdk-unscaled-dpi");
+ if (font_dpi <= 0)
+ return -1;
+ return window_scale * GtkDpiToScaleFactor(font_dpi);
}
float GetScaleFromXftDPI() {
@@ -330,15 +343,16 @@ float GetScaleFromXftDPI() {
CHECK(gtk_settings);
gint gtk_dpi = -1;
g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, nullptr);
- // GTK multiplies the DPI by 1024 before storing it.
- return (gtk_dpi > 0) ? gtk_dpi / (1024 * kDefaultDPI) : -1;
+ if (gtk_dpi <= 0)
+ return -1;
+ return GtkDpiToScaleFactor(gtk_dpi);
}
float GetRawDeviceScaleFactor() {
if (display::Display::HasForceDeviceScaleFactor())
return display::Display::GetForcedDeviceScaleFactor();
- float scale = GetGdkWindowScalingFactor();
+ float scale = GetScaleFromGdkScreenSettings();
if (scale > 0)
return scale;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698