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

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

Issue 2937623006: Respect GDK_SCALE and GDK_DPI_SCALE when calculating scale factor (Closed)
Patch Set: simplify Created 3 years, 6 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 eb8eb01600485b17bbdefa429660aedcf1bedcd2..d8ce7babcb2d416210ef7d0120623698db04a155 100644
--- a/chrome/browser/ui/libgtkui/gtk_ui.cc
+++ b/chrome/browser/ui/libgtkui/gtk_ui.cc
@@ -312,52 +312,15 @@ gfx::FontRenderParams GetGtkFontRenderParams() {
return params;
}
-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);
-}
-
-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() {
- 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);
- if (gtk_dpi <= 0)
- return -1;
- return GtkDpiToScaleFactor(gtk_dpi);
-}
-
float GetRawDeviceScaleFactor() {
if (display::Display::HasForceDeviceScaleFactor())
return display::Display::GetForcedDeviceScaleFactor();
- float scale = GetScaleFromGdkScreenSettings();
- if (scale > 0)
- return scale;
-
- scale = GetScaleFromXftDPI();
- if (scale > 0)
- return scale;
-
- return 1;
+ GdkScreen* screen = gdk_screen_get_default();
+ gint scale = gdk_screen_get_monitor_scale_factor(
+ screen, gdk_screen_get_primary_monitor(screen));
+ gdouble resolution = gdk_screen_get_resolution(screen);
+ return resolution <= 0 ? scale : resolution * scale / kDefaultDPI;
}
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