Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: ui/views/widget/desktop_aura/desktop_screen_x11.cc

Issue 219743002: x11: Move X event handling out of the message-pump. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge-r261267 Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.
11 #undef RootWindow 11 #undef RootWindow
12 12
13 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
16 #include "ui/aura/window_event_dispatcher.h" 16 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/aura/window_tree_host.h" 17 #include "ui/aura/window_tree_host.h"
18 #include "ui/base/layout.h" 18 #include "ui/base/layout.h"
19 #include "ui/base/x/x11_util.h" 19 #include "ui/base/x/x11_util.h"
20 #include "ui/display/x11/edid_parser_x11.h" 20 #include "ui/display/x11/edid_parser_x11.h"
21 #include "ui/events/platform/platform_event_source.h"
21 #include "ui/gfx/display.h" 22 #include "ui/gfx/display.h"
22 #include "ui/gfx/display_observer.h" 23 #include "ui/gfx/display_observer.h"
23 #include "ui/gfx/native_widget_types.h" 24 #include "ui/gfx/native_widget_types.h"
24 #include "ui/gfx/screen.h" 25 #include "ui/gfx/screen.h"
25 #include "ui/gfx/x/x11_types.h" 26 #include "ui/gfx/x/x11_types.h"
26 #include "ui/views/widget/desktop_aura/desktop_screen.h" 27 #include "ui/views/widget/desktop_aura/desktop_screen.h"
27 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" 28 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
28 29
29 namespace { 30 namespace {
30 31
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 int randr_version_minor = 0; 130 int randr_version_minor = 0;
130 has_xrandr_ = XRRQueryVersion( 131 has_xrandr_ = XRRQueryVersion(
131 xdisplay_, &randr_version_major, &randr_version_minor) && 132 xdisplay_, &randr_version_major, &randr_version_minor) &&
132 randr_version_major == 1 && 133 randr_version_major == 1 &&
133 randr_version_minor >= 3; 134 randr_version_minor >= 3;
134 135
135 if (has_xrandr_) { 136 if (has_xrandr_) {
136 int error_base_ignored = 0; 137 int error_base_ignored = 0;
137 XRRQueryExtension(xdisplay_, &xrandr_event_base_, &error_base_ignored); 138 XRRQueryExtension(xdisplay_, &xrandr_event_base_, &error_base_ignored);
138 139
139 base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this); 140 if (ui::PlatformEventSource::GetInstance())
141 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
140 XRRSelectInput(xdisplay_, 142 XRRSelectInput(xdisplay_,
141 x_root_window_, 143 x_root_window_,
142 RRScreenChangeNotifyMask | RROutputChangeNotifyMask); 144 RRScreenChangeNotifyMask | RROutputChangeNotifyMask);
143 145
144 displays_ = BuildDisplaysFromXRandRInfo(); 146 displays_ = BuildDisplaysFromXRandRInfo();
145 } else { 147 } else {
146 displays_ = GetFallbackDisplayList(); 148 displays_ = GetFallbackDisplayList();
147 } 149 }
148 } 150 }
149 151
150 DesktopScreenX11::~DesktopScreenX11() { 152 DesktopScreenX11::~DesktopScreenX11() {
151 if (has_xrandr_) 153 if (has_xrandr_ && ui::PlatformEventSource::GetInstance())
152 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); 154 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
153 } 155 }
154 156
155 void DesktopScreenX11::ProcessDisplayChange( 157 void DesktopScreenX11::ProcessDisplayChange(
156 const std::vector<gfx::Display>& incoming) { 158 const std::vector<gfx::Display>& incoming) {
157 std::vector<gfx::Display> old_displays = displays_; 159 std::vector<gfx::Display> old_displays = displays_;
158 displays_ = incoming; 160 displays_ = incoming;
159 161
160 typedef std::vector<gfx::Display>::const_iterator DisplayIt; 162 typedef std::vector<gfx::Display>::const_iterator DisplayIt;
161 std::vector<gfx::Display>::const_iterator old_it = old_displays.begin(); 163 std::vector<gfx::Display>::const_iterator old_it = old_displays.begin();
162 for (; old_it != old_displays.end(); ++old_it) { 164 for (; old_it != old_displays.end(); ++old_it) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 301 }
300 302
301 void DesktopScreenX11::AddObserver(gfx::DisplayObserver* observer) { 303 void DesktopScreenX11::AddObserver(gfx::DisplayObserver* observer) {
302 observer_list_.AddObserver(observer); 304 observer_list_.AddObserver(observer);
303 } 305 }
304 306
305 void DesktopScreenX11::RemoveObserver(gfx::DisplayObserver* observer) { 307 void DesktopScreenX11::RemoveObserver(gfx::DisplayObserver* observer) {
306 observer_list_.RemoveObserver(observer); 308 observer_list_.RemoveObserver(observer);
307 } 309 }
308 310
309 uint32_t DesktopScreenX11::Dispatch(const base::NativeEvent& event) { 311 bool DesktopScreenX11::CanDispatchEvent(const ui::PlatformEvent& event) {
312 return event->type - xrandr_event_base_ == RRScreenChangeNotify ||
313 event->type - xrandr_event_base_ == RRNotify;
314 }
315
316 uint32_t DesktopScreenX11::DispatchEvent(const ui::PlatformEvent& event) {
310 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { 317 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) {
311 // Pass the event through to xlib. 318 // Pass the event through to xlib.
312 XRRUpdateConfiguration(event); 319 XRRUpdateConfiguration(event);
313 } else if (event->type - xrandr_event_base_ == RRNotify) { 320 } else if (event->type - xrandr_event_base_ == RRNotify) {
314 // There's some sort of observer dispatch going on here, but I don't think 321 // There's some sort of observer dispatch going on here, but I don't think
315 // it's the screen's? 322 // it's the screen's?
316 if (configure_timer_.get() && configure_timer_->IsRunning()) { 323 if (configure_timer_.get() && configure_timer_->IsRunning()) {
317 configure_timer_->Reset(); 324 configure_timer_->Reset();
318 } else { 325 } else {
319 configure_timer_.reset(new base::OneShotTimer<DesktopScreenX11>()); 326 configure_timer_.reset(new base::OneShotTimer<DesktopScreenX11>());
320 configure_timer_->Start( 327 configure_timer_->Start(
321 FROM_HERE, 328 FROM_HERE,
322 base::TimeDelta::FromMilliseconds(kConfigureDelayMs), 329 base::TimeDelta::FromMilliseconds(kConfigureDelayMs),
323 this, 330 this,
324 &DesktopScreenX11::ConfigureTimerFired); 331 &DesktopScreenX11::ConfigureTimerFired);
325 } 332 }
333 } else {
334 NOTREACHED();
326 } 335 }
327 336
328 return POST_DISPATCH_NONE; 337 return ui::POST_DISPATCH_NONE;
329 } 338 }
330 339
331 //////////////////////////////////////////////////////////////////////////////// 340 ////////////////////////////////////////////////////////////////////////////////
332 // DesktopScreenX11, private: 341 // DesktopScreenX11, private:
333 342
334 DesktopScreenX11::DesktopScreenX11( 343 DesktopScreenX11::DesktopScreenX11(
335 const std::vector<gfx::Display>& test_displays) 344 const std::vector<gfx::Display>& test_displays)
336 : xdisplay_(base::MessagePumpX11::GetDefaultXDisplay()), 345 : xdisplay_(base::MessagePumpX11::GetDefaultXDisplay()),
337 x_root_window_(DefaultRootWindow(xdisplay_)), 346 x_root_window_(DefaultRootWindow(xdisplay_)),
338 has_xrandr_(false), 347 has_xrandr_(false),
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 ProcessDisplayChange(new_displays); 433 ProcessDisplayChange(new_displays);
425 } 434 }
426 435
427 //////////////////////////////////////////////////////////////////////////////// 436 ////////////////////////////////////////////////////////////////////////////////
428 437
429 gfx::Screen* CreateDesktopScreen() { 438 gfx::Screen* CreateDesktopScreen() {
430 return new DesktopScreenX11; 439 return new DesktopScreenX11;
431 } 440 }
432 441
433 } // namespace views 442 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_screen_x11.h ('k') | ui/views/widget/desktop_aura/desktop_screen_x11_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698