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