Chromium Code Reviews| 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* kAtomsToCache[] = { | |
|
Lei Zhang
2016/04/21 22:45:31
const char* const, otherwise one can write: kAtoms
Tom (Use chromium acct)
2016/04/21 22:57:50
Done.
| |
| 37 "_NET_WORKAREA", | |
| 38 NULL | |
|
Lei Zhang
2016/04/21 22:45:31
nullptr
Tom (Use chromium acct)
2016/04/21 22:57:50
Done.
| |
| 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->xproperty.atom == atom_cache_.GetAtom("_NET_WORKAREA")) { | |
|
Elliot Glaysher
2016/04/21 22:43:05
XEvent is a giant union, not a struct. Check event
Tom (Use chromium acct)
2016/04/21 22:57:50
Done.
| |
| 240 // There's some sort of observer dispatch going on here, but I don't think | 250 // There's some sort of observer dispatch going on here, but I don't think |
| 241 // it's the screen's? | 251 // it's the screen's? |
| 242 if (configure_timer_.get() && configure_timer_->IsRunning()) { | 252 if (configure_timer_.get() && configure_timer_->IsRunning()) { |
| 243 configure_timer_->Reset(); | 253 configure_timer_->Reset(); |
| 244 } else { | 254 } else { |
| 245 configure_timer_.reset(new base::OneShotTimer()); | 255 configure_timer_.reset(new base::OneShotTimer()); |
| 246 configure_timer_->Start( | 256 configure_timer_->Start( |
| 247 FROM_HERE, | 257 FROM_HERE, |
| 248 base::TimeDelta::FromMilliseconds(kConfigureDelayMs), | 258 base::TimeDelta::FromMilliseconds(kConfigureDelayMs), |
| 249 this, | 259 this, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 265 | 275 |
| 266 //////////////////////////////////////////////////////////////////////////////// | 276 //////////////////////////////////////////////////////////////////////////////// |
| 267 // DesktopScreenX11, private: | 277 // DesktopScreenX11, private: |
| 268 | 278 |
| 269 DesktopScreenX11::DesktopScreenX11( | 279 DesktopScreenX11::DesktopScreenX11( |
| 270 const std::vector<gfx::Display>& test_displays) | 280 const std::vector<gfx::Display>& test_displays) |
| 271 : xdisplay_(gfx::GetXDisplay()), | 281 : xdisplay_(gfx::GetXDisplay()), |
| 272 x_root_window_(DefaultRootWindow(xdisplay_)), | 282 x_root_window_(DefaultRootWindow(xdisplay_)), |
| 273 has_xrandr_(false), | 283 has_xrandr_(false), |
| 274 xrandr_event_base_(0), | 284 xrandr_event_base_(0), |
| 275 displays_(test_displays) { | 285 displays_(test_displays), |
| 286 atom_cache_(xdisplay_, kAtomsToCache) { | |
| 276 } | 287 } |
| 277 | 288 |
| 278 std::vector<gfx::Display> DesktopScreenX11::BuildDisplaysFromXRandRInfo() { | 289 std::vector<gfx::Display> DesktopScreenX11::BuildDisplaysFromXRandRInfo() { |
| 279 std::vector<gfx::Display> displays; | 290 std::vector<gfx::Display> displays; |
| 280 gfx::XScopedPtr< | 291 gfx::XScopedPtr< |
| 281 XRRScreenResources, | 292 XRRScreenResources, |
| 282 gfx::XObjectDeleter<XRRScreenResources, void, XRRFreeScreenResources>> | 293 gfx::XObjectDeleter<XRRScreenResources, void, XRRFreeScreenResources>> |
| 283 resources(XRRGetScreenResourcesCurrent(xdisplay_, x_root_window_)); | 294 resources(XRRGetScreenResourcesCurrent(xdisplay_, x_root_window_)); |
| 284 if (!resources) { | 295 if (!resources) { |
| 285 LOG(ERROR) << "XRandR returned no displays. Falling back to Root Window."; | 296 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()); | 389 GetPrimaryDisplay().device_scale_factor()); |
| 379 } | 390 } |
| 380 | 391 |
| 381 //////////////////////////////////////////////////////////////////////////////// | 392 //////////////////////////////////////////////////////////////////////////////// |
| 382 | 393 |
| 383 gfx::Screen* CreateDesktopScreen() { | 394 gfx::Screen* CreateDesktopScreen() { |
| 384 return new DesktopScreenX11; | 395 return new DesktopScreenX11; |
| 385 } | 396 } |
| 386 | 397 |
| 387 } // namespace views | 398 } // namespace views |
| OLD | NEW |