OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/time/default_tick_clock.h" | 5 #include "base/time/default_tick_clock.h" |
6 #include "ui/display/chromeos/x11/native_display_event_dispatcher_x11.h" | 6 #include "ui/display/chromeos/x11/native_display_event_dispatcher_x11.h" |
7 #include "ui/display/chromeos/x11/display_mode_x11.h" | 7 #include "ui/display/chromeos/x11/display_mode_x11.h" |
8 #include "ui/display/chromeos/x11/display_snapshot_x11.h" | 8 #include "ui/display/chromeos/x11/display_snapshot_x11.h" |
| 9 #include "ui/events/platform/platform_event_source.h" |
9 | 10 |
10 #include <X11/extensions/Xrandr.h> | 11 #include <X11/extensions/Xrandr.h> |
11 | 12 |
12 namespace ui { | 13 namespace ui { |
13 | 14 |
14 // static | 15 // static |
15 const int NativeDisplayEventDispatcherX11::kCachedOutputsExpirationMs = 5000; | 16 const int NativeDisplayEventDispatcherX11::kCachedOutputsExpirationMs = 5000; |
16 | 17 |
17 NativeDisplayEventDispatcherX11::NativeDisplayEventDispatcherX11( | 18 NativeDisplayEventDispatcherX11::NativeDisplayEventDispatcherX11( |
18 NativeDisplayDelegateX11::HelperDelegate* delegate, | 19 NativeDisplayDelegateX11::HelperDelegate* delegate, |
19 int xrandr_event_base) | 20 int xrandr_event_base) |
20 : delegate_(delegate), | 21 : delegate_(delegate), |
21 xrandr_event_base_(xrandr_event_base), | 22 xrandr_event_base_(xrandr_event_base), |
22 tick_clock_(new base::DefaultTickClock) {} | 23 tick_clock_(new base::DefaultTickClock) {} |
23 | 24 |
24 NativeDisplayEventDispatcherX11::~NativeDisplayEventDispatcherX11() {} | 25 NativeDisplayEventDispatcherX11::~NativeDisplayEventDispatcherX11() {} |
25 | 26 |
26 uint32_t NativeDisplayEventDispatcherX11::Dispatch( | 27 bool NativeDisplayEventDispatcherX11::CanDispatchEvent( |
27 const base::NativeEvent& event) { | 28 const PlatformEvent& event) { |
| 29 return (event->type - xrandr_event_base_ == RRScreenChangeNotify) || |
| 30 (event->type - xrandr_event_base_ == RRNotify); |
| 31 } |
| 32 |
| 33 uint32_t NativeDisplayEventDispatcherX11::DispatchEvent( |
| 34 const PlatformEvent& event) { |
28 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { | 35 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { |
29 VLOG(1) << "Received RRScreenChangeNotify event"; | 36 VLOG(1) << "Received RRScreenChangeNotify event"; |
30 delegate_->UpdateXRandRConfiguration(event); | 37 delegate_->UpdateXRandRConfiguration(event); |
31 return POST_DISPATCH_PERFORM_DEFAULT; | 38 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
32 } | 39 } |
33 | 40 |
34 // Bail out early for everything except RRNotify_OutputChange events | 41 // Bail out early for everything except RRNotify_OutputChange events |
35 // about an output getting connected or disconnected. | 42 // about an output getting connected or disconnected. |
36 if (event->type - xrandr_event_base_ != RRNotify) | 43 if (event->type - xrandr_event_base_ != RRNotify) |
37 return POST_DISPATCH_PERFORM_DEFAULT; | 44 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
38 const XRRNotifyEvent* notify_event = reinterpret_cast<XRRNotifyEvent*>(event); | 45 const XRRNotifyEvent* notify_event = reinterpret_cast<XRRNotifyEvent*>(event); |
39 if (notify_event->subtype != RRNotify_OutputChange) | 46 if (notify_event->subtype != RRNotify_OutputChange) |
40 return POST_DISPATCH_PERFORM_DEFAULT; | 47 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
41 const XRROutputChangeNotifyEvent* output_change_event = | 48 const XRROutputChangeNotifyEvent* output_change_event = |
42 reinterpret_cast<XRROutputChangeNotifyEvent*>(event); | 49 reinterpret_cast<XRROutputChangeNotifyEvent*>(event); |
43 const int action = output_change_event->connection; | 50 const int action = output_change_event->connection; |
44 if (action != RR_Connected && action != RR_Disconnected) | 51 if (action != RR_Connected && action != RR_Disconnected) |
45 return POST_DISPATCH_PERFORM_DEFAULT; | 52 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
46 | 53 |
47 const bool connected = (action == RR_Connected); | 54 const bool connected = (action == RR_Connected); |
48 VLOG(1) << "Received RRNotify_OutputChange event:" | 55 VLOG(1) << "Received RRNotify_OutputChange event:" |
49 << " output=" << output_change_event->output | 56 << " output=" << output_change_event->output |
50 << " crtc=" << output_change_event->crtc | 57 << " crtc=" << output_change_event->crtc |
51 << " mode=" << output_change_event->mode | 58 << " mode=" << output_change_event->mode |
52 << " action=" << (connected ? "connected" : "disconnected"); | 59 << " action=" << (connected ? "connected" : "disconnected"); |
53 | 60 |
54 bool force_notify = last_notified_time_.is_null() || | 61 bool force_notify = last_notified_time_.is_null() || |
55 (tick_clock_->NowTicks() - last_notified_time_).InMilliseconds() >= | 62 (tick_clock_->NowTicks() - last_notified_time_).InMilliseconds() >= |
(...skipping 17 matching lines...) Expand all Loading... |
73 VLOG(1) << "Ignoring event describing already-cached state"; | 80 VLOG(1) << "Ignoring event describing already-cached state"; |
74 return POST_DISPATCH_PERFORM_DEFAULT; | 81 return POST_DISPATCH_PERFORM_DEFAULT; |
75 } | 82 } |
76 found_changed_output = true; | 83 found_changed_output = true; |
77 break; | 84 break; |
78 } | 85 } |
79 } | 86 } |
80 | 87 |
81 if (!connected && !found_changed_output) { | 88 if (!connected && !found_changed_output) { |
82 VLOG(1) << "Ignoring event describing already-disconnected output"; | 89 VLOG(1) << "Ignoring event describing already-disconnected output"; |
83 return POST_DISPATCH_PERFORM_DEFAULT; | 90 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
84 } | 91 } |
85 } | 92 } |
86 | 93 |
87 last_notified_time_ = tick_clock_->NowTicks(); | 94 last_notified_time_ = tick_clock_->NowTicks(); |
88 | 95 |
89 delegate_->NotifyDisplayObservers(); | 96 delegate_->NotifyDisplayObservers(); |
90 | 97 |
91 return POST_DISPATCH_PERFORM_DEFAULT; | 98 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
92 } | 99 } |
93 | 100 |
94 void NativeDisplayEventDispatcherX11::SetTickClockForTest( | 101 void NativeDisplayEventDispatcherX11::SetTickClockForTest( |
95 scoped_ptr<base::TickClock> tick_clock) { | 102 scoped_ptr<base::TickClock> tick_clock) { |
96 tick_clock_ = tick_clock.Pass(); | 103 tick_clock_ = tick_clock.Pass(); |
97 } | 104 } |
98 | 105 |
99 } // namespace ui | 106 } // namespace ui |
OLD | NEW |