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

Side by Side Diff: chrome/browser/ui/libgtkui/gtk_ui.cc

Issue 2961473002: [Merge to M60] Respect GDK_SCALE and GDK_DPI_SCALE when calculating scale factor (Closed)
Patch Set: 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 | chrome/installer/linux/debian/expected_deps_x64_jessie » ('j') | 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\""; 308 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\"";
309 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; 309 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
310 } 310 }
311 311
312 g_free(hint_style); 312 g_free(hint_style);
313 g_free(rgba); 313 g_free(rgba);
314 314
315 return params; 315 return params;
316 } 316 }
317 317
318 float GtkDpiToScaleFactor(int dpi) {
319 // GTK multiplies the DPI by 1024 before storing it.
320 return dpi / (1024 * kDefaultDPI);
321 }
322
323 gint GetGdkScreenSettingInt(const char* setting_name) {
324 GValue value = G_VALUE_INIT;
325 g_value_init(&value, G_TYPE_INT);
326 if (!gdk_screen_get_setting(gdk_screen_get_default(), setting_name, &value))
327 return -1;
328 return g_value_get_int(&value);
329 }
330
331 float GetScaleFromGdkScreenSettings() {
332 gint window_scale = GetGdkScreenSettingInt("gdk-window-scaling-factor");
333 if (window_scale <= 0)
334 return -1;
335 gint font_dpi = GetGdkScreenSettingInt("gdk-unscaled-dpi");
336 if (font_dpi <= 0)
337 return -1;
338 return window_scale * GtkDpiToScaleFactor(font_dpi);
339 }
340
341 float GetScaleFromXftDPI() {
342 GtkSettings* gtk_settings = gtk_settings_get_default();
343 CHECK(gtk_settings);
344 gint gtk_dpi = -1;
345 g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, nullptr);
346 if (gtk_dpi <= 0)
347 return -1;
348 return GtkDpiToScaleFactor(gtk_dpi);
349 }
350
351 float GetRawDeviceScaleFactor() { 318 float GetRawDeviceScaleFactor() {
352 if (display::Display::HasForceDeviceScaleFactor()) 319 if (display::Display::HasForceDeviceScaleFactor())
353 return display::Display::GetForcedDeviceScaleFactor(); 320 return display::Display::GetForcedDeviceScaleFactor();
354 321
355 float scale = GetScaleFromGdkScreenSettings(); 322 GdkScreen* screen = gdk_screen_get_default();
356 if (scale > 0) 323 gint scale = gdk_screen_get_monitor_scale_factor(
357 return scale; 324 screen, gdk_screen_get_primary_monitor(screen));
358 325 gdouble resolution = gdk_screen_get_resolution(screen);
359 scale = GetScaleFromXftDPI(); 326 return resolution <= 0 ? scale : resolution * scale / kDefaultDPI;
360 if (scale > 0)
361 return scale;
362
363 return 1;
364 } 327 }
365 328
366 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { 329 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() {
367 std::unique_ptr<base::Environment> env(base::Environment::Create()); 330 std::unique_ptr<base::Environment> env(base::Environment::Create());
368 switch (base::nix::GetDesktopEnvironment(env.get())) { 331 switch (base::nix::GetDesktopEnvironment(env.get())) {
369 case base::nix::DESKTOP_ENVIRONMENT_KDE4: 332 case base::nix::DESKTOP_ENVIRONMENT_KDE4:
370 case base::nix::DESKTOP_ENVIRONMENT_KDE5: 333 case base::nix::DESKTOP_ENVIRONMENT_KDE5:
371 // Starting with KDE 4.4, windows' titlebars can be dragged with the 334 // Starting with KDE 4.4, windows' titlebars can be dragged with the
372 // middle mouse button to create tab groups. We don't support that in 335 // middle mouse button to create tab groups. We don't support that in
373 // Chrome, but at least avoid lowering windows in response to middle 336 // Chrome, but at least avoid lowering windows in response to middle
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 1050
1088 float GtkUi::GetDeviceScaleFactor() const { 1051 float GtkUi::GetDeviceScaleFactor() const {
1089 return device_scale_factor_; 1052 return device_scale_factor_;
1090 } 1053 }
1091 1054
1092 } // namespace libgtkui 1055 } // namespace libgtkui
1093 1056
1094 views::LinuxUI* BuildGtkUi() { 1057 views::LinuxUI* BuildGtkUi() {
1095 return new libgtkui::GtkUi; 1058 return new libgtkui::GtkUi;
1096 } 1059 }
OLDNEW
« no previous file with comments | « no previous file | chrome/installer/linux/debian/expected_deps_x64_jessie » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698