| 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 17 matching lines...) Expand all Loading... |
| 28 #include "ui/gfx/geometry/size_conversions.h" | 28 #include "ui/gfx/geometry/size_conversions.h" |
| 29 #include "ui/gfx/native_widget_types.h" | 29 #include "ui/gfx/native_widget_types.h" |
| 30 #include "ui/gfx/x/x11_types.h" | 30 #include "ui/gfx/x/x11_types.h" |
| 31 #include "ui/views/linux_ui/linux_ui.h" | 31 #include "ui/views/linux_ui/linux_ui.h" |
| 32 #include "ui/views/widget/desktop_aura/desktop_screen.h" | 32 #include "ui/views/widget/desktop_aura/desktop_screen.h" |
| 33 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 33 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
| 34 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" | 34 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 const char* const kAtomsToCache[] = { | |
| 39 "_NET_WORKAREA", | |
| 40 nullptr | |
| 41 }; | |
| 42 | |
| 43 // The delay to perform configuration after RRNotify. See the comment | 38 // The delay to perform configuration after RRNotify. See the comment |
| 44 // in |Dispatch()|. | 39 // in |Dispatch()|. |
| 45 const int64_t kConfigureDelayMs = 500; | 40 const int64_t kConfigureDelayMs = 500; |
| 46 | 41 |
| 47 double GetDeviceScaleFactor() { | 42 double GetDeviceScaleFactor() { |
| 48 float device_scale_factor = 1.0f; | 43 float device_scale_factor = 1.0f; |
| 49 if (views::LinuxUI::instance()) { | 44 if (views::LinuxUI::instance()) { |
| 50 device_scale_factor = | 45 device_scale_factor = |
| 51 views::LinuxUI::instance()->GetDeviceScaleFactor(); | 46 views::LinuxUI::instance()->GetDeviceScaleFactor(); |
| 52 } else if (display::Display::HasForceDeviceScaleFactor()) { | 47 } else if (display::Display::HasForceDeviceScaleFactor()) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 namespace views { | 82 namespace views { |
| 88 | 83 |
| 89 //////////////////////////////////////////////////////////////////////////////// | 84 //////////////////////////////////////////////////////////////////////////////// |
| 90 // DesktopScreenX11, public: | 85 // DesktopScreenX11, public: |
| 91 | 86 |
| 92 DesktopScreenX11::DesktopScreenX11() | 87 DesktopScreenX11::DesktopScreenX11() |
| 93 : xdisplay_(gfx::GetXDisplay()), | 88 : xdisplay_(gfx::GetXDisplay()), |
| 94 x_root_window_(DefaultRootWindow(xdisplay_)), | 89 x_root_window_(DefaultRootWindow(xdisplay_)), |
| 95 has_xrandr_(false), | 90 has_xrandr_(false), |
| 96 xrandr_event_base_(0), | 91 xrandr_event_base_(0), |
| 97 primary_display_index_(0), | 92 primary_display_index_(0) { |
| 98 atom_cache_(xdisplay_, kAtomsToCache) { | |
| 99 // We only support 1.3+. There were library changes before this and we should | 93 // We only support 1.3+. There were library changes before this and we should |
| 100 // use the new interface instead of the 1.2 one. | 94 // use the new interface instead of the 1.2 one. |
| 101 int randr_version_major = 0; | 95 int randr_version_major = 0; |
| 102 int randr_version_minor = 0; | 96 int randr_version_minor = 0; |
| 103 has_xrandr_ = XRRQueryVersion( | 97 has_xrandr_ = XRRQueryVersion( |
| 104 xdisplay_, &randr_version_major, &randr_version_minor) && | 98 xdisplay_, &randr_version_major, &randr_version_minor) && |
| 105 randr_version_major == 1 && | 99 randr_version_major == 1 && |
| 106 randr_version_minor >= 3; | 100 randr_version_minor >= 3; |
| 107 | 101 |
| 108 if (has_xrandr_) { | 102 if (has_xrandr_) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 228 |
| 235 void DesktopScreenX11::RemoveObserver(display::DisplayObserver* observer) { | 229 void DesktopScreenX11::RemoveObserver(display::DisplayObserver* observer) { |
| 236 change_notifier_.RemoveObserver(observer); | 230 change_notifier_.RemoveObserver(observer); |
| 237 } | 231 } |
| 238 | 232 |
| 239 bool DesktopScreenX11::CanDispatchEvent(const ui::PlatformEvent& event) { | 233 bool DesktopScreenX11::CanDispatchEvent(const ui::PlatformEvent& event) { |
| 240 return event->type - xrandr_event_base_ == RRScreenChangeNotify || | 234 return event->type - xrandr_event_base_ == RRScreenChangeNotify || |
| 241 event->type - xrandr_event_base_ == RRNotify || | 235 event->type - xrandr_event_base_ == RRNotify || |
| 242 (event->type == PropertyNotify && | 236 (event->type == PropertyNotify && |
| 243 event->xproperty.window == x_root_window_ && | 237 event->xproperty.window == x_root_window_ && |
| 244 event->xproperty.atom == atom_cache_.GetAtom("_NET_WORKAREA")); | 238 event->xproperty.atom == ui::GetAtom("_NET_WORKAREA")); |
| 245 } | 239 } |
| 246 | 240 |
| 247 uint32_t DesktopScreenX11::DispatchEvent(const ui::PlatformEvent& event) { | 241 uint32_t DesktopScreenX11::DispatchEvent(const ui::PlatformEvent& event) { |
| 248 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { | 242 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { |
| 249 // Pass the event through to xlib. | 243 // Pass the event through to xlib. |
| 250 XRRUpdateConfiguration(event); | 244 XRRUpdateConfiguration(event); |
| 251 } else if (event->type - xrandr_event_base_ == RRNotify || | 245 } else if (event->type - xrandr_event_base_ == RRNotify || |
| 252 (event->type == PropertyNotify && | 246 (event->type == PropertyNotify && |
| 253 event->xproperty.atom == atom_cache_.GetAtom("_NET_WORKAREA"))) { | 247 event->xproperty.atom == ui::GetAtom("_NET_WORKAREA"))) { |
| 254 // There's some sort of observer dispatch going on here, but I don't think | 248 // There's some sort of observer dispatch going on here, but I don't think |
| 255 // it's the screen's? | 249 // it's the screen's? |
| 256 if (configure_timer_.get() && configure_timer_->IsRunning()) { | 250 if (configure_timer_.get() && configure_timer_->IsRunning()) { |
| 257 configure_timer_->Reset(); | 251 configure_timer_->Reset(); |
| 258 } else { | 252 } else { |
| 259 configure_timer_.reset(new base::OneShotTimer()); | 253 configure_timer_.reset(new base::OneShotTimer()); |
| 260 configure_timer_->Start( | 254 configure_timer_->Start( |
| 261 FROM_HERE, | 255 FROM_HERE, |
| 262 base::TimeDelta::FromMilliseconds(kConfigureDelayMs), | 256 base::TimeDelta::FromMilliseconds(kConfigureDelayMs), |
| 263 this, | 257 this, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 280 //////////////////////////////////////////////////////////////////////////////// | 274 //////////////////////////////////////////////////////////////////////////////// |
| 281 // DesktopScreenX11, private: | 275 // DesktopScreenX11, private: |
| 282 | 276 |
| 283 DesktopScreenX11::DesktopScreenX11( | 277 DesktopScreenX11::DesktopScreenX11( |
| 284 const std::vector<display::Display>& test_displays) | 278 const std::vector<display::Display>& test_displays) |
| 285 : xdisplay_(gfx::GetXDisplay()), | 279 : xdisplay_(gfx::GetXDisplay()), |
| 286 x_root_window_(DefaultRootWindow(xdisplay_)), | 280 x_root_window_(DefaultRootWindow(xdisplay_)), |
| 287 has_xrandr_(false), | 281 has_xrandr_(false), |
| 288 xrandr_event_base_(0), | 282 xrandr_event_base_(0), |
| 289 displays_(test_displays), | 283 displays_(test_displays), |
| 290 primary_display_index_(0), | 284 primary_display_index_(0) {} |
| 291 atom_cache_(xdisplay_, kAtomsToCache) {} | |
| 292 | 285 |
| 293 std::vector<display::Display> DesktopScreenX11::BuildDisplaysFromXRandRInfo() { | 286 std::vector<display::Display> DesktopScreenX11::BuildDisplaysFromXRandRInfo() { |
| 294 std::vector<display::Display> displays; | 287 std::vector<display::Display> displays; |
| 295 gfx::XScopedPtr< | 288 gfx::XScopedPtr< |
| 296 XRRScreenResources, | 289 XRRScreenResources, |
| 297 gfx::XObjectDeleter<XRRScreenResources, void, XRRFreeScreenResources>> | 290 gfx::XObjectDeleter<XRRScreenResources, void, XRRFreeScreenResources>> |
| 298 resources(XRRGetScreenResourcesCurrent(xdisplay_, x_root_window_)); | 291 resources(XRRGetScreenResourcesCurrent(xdisplay_, x_root_window_)); |
| 299 if (!resources) { | 292 if (!resources) { |
| 300 LOG(ERROR) << "XRandR returned no displays. Falling back to Root Window."; | 293 LOG(ERROR) << "XRandR returned no displays. Falling back to Root Window."; |
| 301 return GetFallbackDisplayList(); | 294 return GetFallbackDisplayList(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 GetPrimaryDisplay().device_scale_factor()); | 396 GetPrimaryDisplay().device_scale_factor()); |
| 404 } | 397 } |
| 405 | 398 |
| 406 //////////////////////////////////////////////////////////////////////////////// | 399 //////////////////////////////////////////////////////////////////////////////// |
| 407 | 400 |
| 408 display::Screen* CreateDesktopScreen() { | 401 display::Screen* CreateDesktopScreen() { |
| 409 return new DesktopScreenX11; | 402 return new DesktopScreenX11; |
| 410 } | 403 } |
| 411 | 404 |
| 412 } // namespace views | 405 } // namespace views |
| OLD | NEW |