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

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

Issue 2852593002: 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 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 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 double GetDpi() { 318 float GetGdkWindowScalingFactor() {
319 if (display::Display::HasForceDeviceScaleFactor()) 319 GValue scale = G_VALUE_INIT;
320 return display::Display::GetForcedDeviceScaleFactor() * kDefaultDPI; 320 g_value_init(&scale, G_TYPE_INT);
321 if (!gdk_screen_get_setting(gdk_screen_get_default(),
322 "gdk-window-scaling-factor", &scale))
323 return -1;
321 324
325 return g_value_get_int(&scale);
326 }
327
328 float GetScaleFromDPI() {
oshima 2017/04/28 18:31:18 nit: GetScaleFromXftDPI
Chris Coulson 2017/04/28 18:40:50 Acknowledged.
322 GtkSettings* gtk_settings = gtk_settings_get_default(); 329 GtkSettings* gtk_settings = gtk_settings_get_default();
323 CHECK(gtk_settings); 330 CHECK(gtk_settings);
324 gint gtk_dpi = -1; 331 gint gtk_dpi = -1;
325 g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, nullptr); 332 g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, nullptr);
326
327 // GTK multiplies the DPI by 1024 before storing it. 333 // GTK multiplies the DPI by 1024 before storing it.
328 return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : kDefaultDPI; 334 return (gtk_dpi > 0) ? gtk_dpi / (1024 * kDefaultDPI) : -1;
329 } 335 }
330 336
331 float GetRawDeviceScaleFactor() { 337 float GetRawDeviceScaleFactor() {
332 if (display::Display::HasForceDeviceScaleFactor()) 338 if (display::Display::HasForceDeviceScaleFactor())
333 return display::Display::GetForcedDeviceScaleFactor(); 339 return display::Display::GetForcedDeviceScaleFactor();
334 return GetDpi() / kDefaultDPI; 340
341 float scale = GetGdkWindowScalingFactor();
342 if (scale > 0)
343 return scale;
344
345 scale = GetScaleFromDPI();
346 if (scale > 0)
347 return scale;
348
349 return 1;
335 } 350 }
336 351
337 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { 352 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() {
338 std::unique_ptr<base::Environment> env(base::Environment::Create()); 353 std::unique_ptr<base::Environment> env(base::Environment::Create());
339 switch (base::nix::GetDesktopEnvironment(env.get())) { 354 switch (base::nix::GetDesktopEnvironment(env.get())) {
340 case base::nix::DESKTOP_ENVIRONMENT_KDE4: 355 case base::nix::DESKTOP_ENVIRONMENT_KDE4:
341 case base::nix::DESKTOP_ENVIRONMENT_KDE5: 356 case base::nix::DESKTOP_ENVIRONMENT_KDE5:
342 // Starting with KDE 4.4, windows' titlebars can be dragged with the 357 // Starting with KDE 4.4, windows' titlebars can be dragged with the
343 // middle mouse button to create tab groups. We don't support that in 358 // middle mouse button to create tab groups. We don't support that in
344 // Chrome, but at least avoid lowering windows in response to middle 359 // Chrome, but at least avoid lowering windows in response to middle
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 1073
1059 float GtkUi::GetDeviceScaleFactor() const { 1074 float GtkUi::GetDeviceScaleFactor() const {
1060 return device_scale_factor_; 1075 return device_scale_factor_;
1061 } 1076 }
1062 1077
1063 } // namespace libgtkui 1078 } // namespace libgtkui
1064 1079
1065 views::LinuxUI* BuildGtkUi() { 1080 views::LinuxUI* BuildGtkUi() {
1066 return new libgtkui::GtkUi; 1081 return new libgtkui::GtkUi;
1067 } 1082 }
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