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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/libgtkui/gtk_ui.h" 5 #include "chrome/browser/ui/libgtkui/gtk_ui.h"
6 6
7 #include <X11/Xcursor/Xcursor.h> 7 #include <X11/Xcursor/Xcursor.h>
8 #include <dlfcn.h> 8 #include <dlfcn.h>
9 #include <math.h> 9 #include <math.h>
10 #include <pango/pango.h> 10 #include <pango/pango.h>
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\""; 305 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\"";
306 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; 306 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
307 } 307 }
308 308
309 g_free(hint_style); 309 g_free(hint_style);
310 g_free(rgba); 310 g_free(rgba);
311 311
312 return params; 312 return params;
313 } 313 }
314 314
315 float GtkDpiToScaleFactor(int dpi) {
316 // GTK multiplies the DPI by 1024 before storing it.
317 return dpi / (1024 * kDefaultDPI);
318 }
319
320 gint GetGdkScreenSettingInt(const char* setting_name) {
321 GValue value = G_VALUE_INIT;
322 g_value_init(&value, G_TYPE_INT);
323 if (!gdk_screen_get_setting(gdk_screen_get_default(), setting_name, &value))
324 return -1;
325 return g_value_get_int(&value);
326 }
327
328 float GetScaleFromGdkScreenSettings() {
329 gint window_scale = GetGdkScreenSettingInt("gdk-window-scaling-factor");
330 if (window_scale <= 0)
331 return -1;
332 gint font_dpi = GetGdkScreenSettingInt("gdk-unscaled-dpi");
333 if (font_dpi <= 0)
334 return -1;
335 return window_scale * GtkDpiToScaleFactor(font_dpi);
336 }
337
338 float GetScaleFromXftDPI() {
339 GtkSettings* gtk_settings = gtk_settings_get_default();
340 CHECK(gtk_settings);
341 gint gtk_dpi = -1;
342 g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, nullptr);
343 if (gtk_dpi <= 0)
344 return -1;
345 return GtkDpiToScaleFactor(gtk_dpi);
346 }
347
348 float GetRawDeviceScaleFactor() { 315 float GetRawDeviceScaleFactor() {
349 if (display::Display::HasForceDeviceScaleFactor()) 316 if (display::Display::HasForceDeviceScaleFactor())
350 return display::Display::GetForcedDeviceScaleFactor(); 317 return display::Display::GetForcedDeviceScaleFactor();
351 318
352 float scale = GetScaleFromGdkScreenSettings(); 319 GdkScreen* screen = gdk_screen_get_default();
353 if (scale > 0) 320 gint scale = gdk_screen_get_monitor_scale_factor(
354 return scale; 321 screen, gdk_screen_get_primary_monitor(screen));
355 322 gdouble resolution = gdk_screen_get_resolution(screen);
356 scale = GetScaleFromXftDPI(); 323 return resolution <= 0 ? scale : resolution * scale / kDefaultDPI;
357 if (scale > 0)
358 return scale;
359
360 return 1;
361 } 324 }
362 325
363 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { 326 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() {
364 std::unique_ptr<base::Environment> env(base::Environment::Create()); 327 std::unique_ptr<base::Environment> env(base::Environment::Create());
365 switch (base::nix::GetDesktopEnvironment(env.get())) { 328 switch (base::nix::GetDesktopEnvironment(env.get())) {
366 case base::nix::DESKTOP_ENVIRONMENT_KDE4: 329 case base::nix::DESKTOP_ENVIRONMENT_KDE4:
367 case base::nix::DESKTOP_ENVIRONMENT_KDE5: 330 case base::nix::DESKTOP_ENVIRONMENT_KDE5:
368 // Starting with KDE 4.4, windows' titlebars can be dragged with the 331 // Starting with KDE 4.4, windows' titlebars can be dragged with the
369 // middle mouse button to create tab groups. We don't support that in 332 // middle mouse button to create tab groups. We don't support that in
370 // Chrome, but at least avoid lowering windows in response to middle 333 // Chrome, but at least avoid lowering windows in response to middle
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 1047
1085 float GtkUi::GetDeviceScaleFactor() const { 1048 float GtkUi::GetDeviceScaleFactor() const {
1086 return device_scale_factor_; 1049 return device_scale_factor_;
1087 } 1050 }
1088 1051
1089 } // namespace libgtkui 1052 } // namespace libgtkui
1090 1053
1091 views::LinuxUI* BuildGtkUi() { 1054 views::LinuxUI* BuildGtkUi() {
1092 return new libgtkui::GtkUi; 1055 return new libgtkui::GtkUi;
1093 } 1056 }
OLDNEW
« 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