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 PixelToDIPPoint(const gfx::Point& pixel_point) { |
| 54 return ToFlooredPoint(ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactor())); |
| 55 } |
| 56 |
| 57 gfx::Point DIPToPixelPoint(const gfx::Point& dip_point) { |
| 58 return ToFlooredPoint(gfx::ScalePoint(dip_point, GetDeviceScaleFactor())); |
| 59 } |
| 60 |
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 PixelToDIPPoint(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( |
| 157 DIPToPixelPoint(point), std::set<aura::Window*>()); |
144 } | 158 } |
145 | 159 |
146 int DesktopScreenX11::GetNumDisplays() const { | 160 int DesktopScreenX11::GetNumDisplays() const { |
147 return displays_.size(); | 161 return displays_.size(); |
148 } | 162 } |
149 | 163 |
150 std::vector<gfx::Display> DesktopScreenX11::GetAllDisplays() const { | 164 std::vector<gfx::Display> DesktopScreenX11::GetAllDisplays() const { |
151 return displays_; | 165 return displays_; |
152 } | 166 } |
153 | 167 |
(...skipping 16 matching lines...) Expand all Loading... |
170 DesktopWindowTreeHostX11* rwh = DesktopWindowTreeHostX11::GetHostForXID( | 184 DesktopWindowTreeHostX11* rwh = DesktopWindowTreeHostX11::GetHostForXID( |
171 host->GetAcceleratedWidget()); | 185 host->GetAcceleratedWidget()); |
172 if (rwh) | 186 if (rwh) |
173 return GetDisplayMatching(rwh->GetX11RootWindowBounds()); | 187 return GetDisplayMatching(rwh->GetX11RootWindowBounds()); |
174 } | 188 } |
175 | 189 |
176 return GetPrimaryDisplay(); | 190 return GetPrimaryDisplay(); |
177 } | 191 } |
178 | 192 |
179 gfx::Display DesktopScreenX11::GetDisplayNearestPoint( | 193 gfx::Display DesktopScreenX11::GetDisplayNearestPoint( |
180 const gfx::Point& point) const { | 194 const gfx::Point& requested_point) const { |
| 195 const gfx::Point point_in_pixel = DIPToPixelPoint(requested_point); |
181 for (std::vector<gfx::Display>::const_iterator it = displays_.begin(); | 196 for (std::vector<gfx::Display>::const_iterator it = displays_.begin(); |
182 it != displays_.end(); ++it) { | 197 it != displays_.end(); ++it) { |
183 if (it->bounds().Contains(point)) | 198 if (it->bounds().Contains(point_in_pixel)) |
184 return *it; | 199 return *it; |
185 } | 200 } |
186 | 201 |
187 return GetPrimaryDisplay(); | 202 return GetPrimaryDisplay(); |
188 } | 203 } |
189 | 204 |
190 gfx::Display DesktopScreenX11::GetDisplayMatching( | 205 gfx::Display DesktopScreenX11::GetDisplayMatching( |
191 const gfx::Rect& match_rect) const { | 206 const gfx::Rect& match_rect) const { |
192 int max_area = 0; | 207 int max_area = 0; |
193 const gfx::Display* matching = NULL; | 208 const gfx::Display* matching = NULL; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); | 373 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); |
359 } | 374 } |
360 | 375 |
361 //////////////////////////////////////////////////////////////////////////////// | 376 //////////////////////////////////////////////////////////////////////////////// |
362 | 377 |
363 gfx::Screen* CreateDesktopScreen() { | 378 gfx::Screen* CreateDesktopScreen() { |
364 return new DesktopScreenX11; | 379 return new DesktopScreenX11; |
365 } | 380 } |
366 | 381 |
367 } // namespace views | 382 } // namespace views |
OLD | NEW |