OLD | NEW |
---|---|
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 "ui/views/widget/desktop_aura/desktop_screen_x11.h" | 5 #include "ui/views/widget/desktop_aura/desktop_screen_x11.h" |
6 | 6 |
7 #include <X11/extensions/Xrandr.h> | 7 #include <X11/extensions/Xrandr.h> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 | 9 |
10 // It clashes with out RootWindow. | 10 // It clashes with out RootWindow. |
(...skipping 27 matching lines...) Expand all Loading... | |
38 const int kCSSDefaultDPI = 96; | 38 const int kCSSDefaultDPI = 96; |
39 const float kInchInMm = 25.4f; | 39 const float kInchInMm = 25.4f; |
40 | 40 |
41 float screen_inches = screen_mm / kInchInMm; | 41 float screen_inches = screen_mm / kInchInMm; |
42 float screen_dpi = screen_pixels / screen_inches; | 42 float screen_dpi = screen_pixels / screen_inches; |
43 float scale = screen_dpi / kCSSDefaultDPI; | 43 float scale = screen_dpi / kCSSDefaultDPI; |
44 | 44 |
45 return ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(scale)); | 45 return ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(scale)); |
46 } | 46 } |
47 | 47 |
48 float GetDeviceScaleFactor() { | |
49 gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | |
50 return display.device_scale_factor(); | |
51 } | |
52 | |
53 gfx::Point ScreenToDIPPoint(const gfx::Point& pixel_point) { | |
sadrul
2015/03/17 15:56:06
Let's call this ToDIPPoint, or PixelToDIPPoint.
I
stapelberg
2015/03/19 08:25:44
Done.
| |
54 return ToFlooredPoint(ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactor())); | |
55 } | |
56 | |
57 gfx::Point DIPToScreenPoint(const gfx::Point& dip_point) { | |
58 return ToFlooredPoint(gfx::ScalePoint(dip_point, GetDeviceScaleFactor())); | |
59 } | |
60 | |
sadrul
2015/03/17 15:56:06
Is there any way we can avoid dup'ing this block o
stapelberg
2015/03/19 08:25:44
I wouldn’t know how, if not by introducing yet ano
| |
48 std::vector<gfx::Display> GetFallbackDisplayList() { | 61 std::vector<gfx::Display> GetFallbackDisplayList() { |
49 ::XDisplay* display = gfx::GetXDisplay(); | 62 ::XDisplay* display = gfx::GetXDisplay(); |
50 ::Screen* screen = DefaultScreenOfDisplay(display); | 63 ::Screen* screen = DefaultScreenOfDisplay(display); |
51 int width = WidthOfScreen(screen); | 64 int width = WidthOfScreen(screen); |
52 int height = HeightOfScreen(screen); | 65 int height = HeightOfScreen(screen); |
53 gfx::Size physical_size(WidthMMOfScreen(screen), HeightMMOfScreen(screen)); | 66 gfx::Size physical_size(WidthMMOfScreen(screen), HeightMMOfScreen(screen)); |
54 | 67 |
55 gfx::Rect bounds_in_pixels(0, 0, width, height); | 68 gfx::Rect bounds_in_pixels(0, 0, width, height); |
56 gfx::Display gfx_display(0, bounds_in_pixels); | 69 gfx::Display gfx_display(0, bounds_in_pixels); |
57 if (!gfx::Display::HasForceDeviceScaleFactor() && | 70 if (!gfx::Display::HasForceDeviceScaleFactor() && |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 XQueryPointer(display, | 136 XQueryPointer(display, |
124 DefaultRootWindow(display), | 137 DefaultRootWindow(display), |
125 &root, | 138 &root, |
126 &child, | 139 &child, |
127 &root_x, | 140 &root_x, |
128 &root_y, | 141 &root_y, |
129 &win_x, | 142 &win_x, |
130 &win_y, | 143 &win_y, |
131 &mask); | 144 &mask); |
132 | 145 |
133 return gfx::Point(root_x, root_y); | 146 return ScreenToDIPPoint(gfx::Point(root_x, root_y)); |
134 } | 147 } |
135 | 148 |
136 gfx::NativeWindow DesktopScreenX11::GetWindowUnderCursor() { | 149 gfx::NativeWindow DesktopScreenX11::GetWindowUnderCursor() { |
137 return GetWindowAtScreenPoint(GetCursorScreenPoint()); | 150 return GetWindowAtScreenPoint(GetCursorScreenPoint()); |
138 } | 151 } |
139 | 152 |
140 gfx::NativeWindow DesktopScreenX11::GetWindowAtScreenPoint( | 153 gfx::NativeWindow DesktopScreenX11::GetWindowAtScreenPoint( |
141 const gfx::Point& point) { | 154 const gfx::Point& point) { |
142 X11TopmostWindowFinder finder; | 155 X11TopmostWindowFinder finder; |
143 return finder.FindLocalProcessWindowAt(point, std::set<aura::Window*>()); | 156 return finder.FindLocalProcessWindowAt(point, std::set<aura::Window*>()); |
(...skipping 26 matching lines...) Expand all Loading... | |
170 DesktopWindowTreeHostX11* rwh = DesktopWindowTreeHostX11::GetHostForXID( | 183 DesktopWindowTreeHostX11* rwh = DesktopWindowTreeHostX11::GetHostForXID( |
171 host->GetAcceleratedWidget()); | 184 host->GetAcceleratedWidget()); |
172 if (rwh) | 185 if (rwh) |
173 return GetDisplayMatching(rwh->GetX11RootWindowBounds()); | 186 return GetDisplayMatching(rwh->GetX11RootWindowBounds()); |
174 } | 187 } |
175 | 188 |
176 return GetPrimaryDisplay(); | 189 return GetPrimaryDisplay(); |
177 } | 190 } |
178 | 191 |
179 gfx::Display DesktopScreenX11::GetDisplayNearestPoint( | 192 gfx::Display DesktopScreenX11::GetDisplayNearestPoint( |
180 const gfx::Point& point) const { | 193 const gfx::Point& requested_point) const { |
194 const gfx::Point point = DIPToScreenPoint(requested_point); | |
sadrul
2015/03/17 15:56:06
point_in_pixel
stapelberg
2015/03/19 08:25:44
Done.
| |
181 for (std::vector<gfx::Display>::const_iterator it = displays_.begin(); | 195 for (std::vector<gfx::Display>::const_iterator it = displays_.begin(); |
182 it != displays_.end(); ++it) { | 196 it != displays_.end(); ++it) { |
183 if (it->bounds().Contains(point)) | 197 if (it->bounds().Contains(point)) |
184 return *it; | 198 return *it; |
185 } | 199 } |
186 | 200 |
187 return GetPrimaryDisplay(); | 201 return GetPrimaryDisplay(); |
188 } | 202 } |
189 | 203 |
190 gfx::Display DesktopScreenX11::GetDisplayMatching( | 204 gfx::Display DesktopScreenX11::GetDisplayMatching( |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); | 372 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); |
359 } | 373 } |
360 | 374 |
361 //////////////////////////////////////////////////////////////////////////////// | 375 //////////////////////////////////////////////////////////////////////////////// |
362 | 376 |
363 gfx::Screen* CreateDesktopScreen() { | 377 gfx::Screen* CreateDesktopScreen() { |
364 return new DesktopScreenX11; | 378 return new DesktopScreenX11; |
365 } | 379 } |
366 | 380 |
367 } // namespace views | 381 } // namespace views |
OLD | NEW |