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

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

Issue 2869763004: Fix DPI scaling on Linux with GTK3 (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 bfe4e89c0592e0fde550462afb5589c92b819b9b..546beeefa0ca0880917ed3e4862d8113c6d45d7c 100644
--- a/chrome/browser/ui/libgtkui/gtk_ui.cc
+++ b/chrome/browser/ui/libgtkui/gtk_ui.cc
@@ -315,23 +315,38 @@ gfx::FontRenderParams GetGtkFontRenderParams() {
return params;
}
-double GetDpi() {
- if (display::Display::HasForceDeviceScaleFactor())
- return display::Display::GetForcedDeviceScaleFactor() * kDefaultDPI;
+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))
+ return -1;
+ return g_value_get_int(&scale);
+}
+
+float GetScaleFromXftDPI() {
GtkSettings* gtk_settings = gtk_settings_get_default();
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.0 : kDefaultDPI;
+ return (gtk_dpi > 0) ? gtk_dpi / (1024 * kDefaultDPI) : -1;
}
float GetRawDeviceScaleFactor() {
if (display::Display::HasForceDeviceScaleFactor())
return display::Display::GetForcedDeviceScaleFactor();
- return GetDpi() / kDefaultDPI;
+
+ float scale = GetGdkWindowScalingFactor();
+ if (scale > 0)
+ return scale;
+
+ scale = GetScaleFromXftDPI();
+ if (scale > 0)
+ return scale;
+
+ return 1;
}
views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() {
« 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