| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chromeos/display/native_display_event_dispatcher_x11.h" | |
| 6 | |
| 7 #include <X11/extensions/Xrandr.h> | |
| 8 | |
| 9 namespace chromeos { | |
| 10 | |
| 11 NativeDisplayEventDispatcherX11::NativeDisplayEventDispatcherX11( | |
| 12 NativeDisplayDelegateX11::HelperDelegate* delegate, int xrandr_event_base) | |
| 13 : delegate_(delegate), | |
| 14 xrandr_event_base_(xrandr_event_base) {} | |
| 15 | |
| 16 NativeDisplayEventDispatcherX11::~NativeDisplayEventDispatcherX11() {} | |
| 17 | |
| 18 uint32_t NativeDisplayEventDispatcherX11::Dispatch( | |
| 19 const base::NativeEvent& event) { | |
| 20 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { | |
| 21 VLOG(1) << "Received RRScreenChangeNotify event"; | |
| 22 delegate_->UpdateXRandRConfiguration(event); | |
| 23 return POST_DISPATCH_PERFORM_DEFAULT; | |
| 24 } | |
| 25 | |
| 26 // Bail out early for everything except RRNotify_OutputChange events | |
| 27 // about an output getting connected or disconnected. | |
| 28 if (event->type - xrandr_event_base_ != RRNotify) | |
| 29 return POST_DISPATCH_PERFORM_DEFAULT; | |
| 30 const XRRNotifyEvent* notify_event = reinterpret_cast<XRRNotifyEvent*>(event); | |
| 31 if (notify_event->subtype != RRNotify_OutputChange) | |
| 32 return POST_DISPATCH_PERFORM_DEFAULT; | |
| 33 const XRROutputChangeNotifyEvent* output_change_event = | |
| 34 reinterpret_cast<XRROutputChangeNotifyEvent*>(event); | |
| 35 const int action = output_change_event->connection; | |
| 36 if (action != RR_Connected && action != RR_Disconnected) | |
| 37 return POST_DISPATCH_PERFORM_DEFAULT; | |
| 38 | |
| 39 const bool connected = (action == RR_Connected); | |
| 40 VLOG(1) << "Received RRNotify_OutputChange event:" | |
| 41 << " output=" << output_change_event->output | |
| 42 << " crtc=" << output_change_event->crtc | |
| 43 << " mode=" << output_change_event->mode | |
| 44 << " action=" << (connected ? "connected" : "disconnected"); | |
| 45 | |
| 46 bool found_changed_output = false; | |
| 47 const std::vector<OutputConfigurator::OutputSnapshot>& cached_outputs = | |
| 48 delegate_->GetCachedOutputs(); | |
| 49 for (std::vector<OutputConfigurator::OutputSnapshot>::const_iterator | |
| 50 it = cached_outputs.begin(); | |
| 51 it != cached_outputs.end(); ++it) { | |
| 52 if (it->output == output_change_event->output) { | |
| 53 if (connected && it->crtc == output_change_event->crtc && | |
| 54 it->current_mode == output_change_event->mode) { | |
| 55 VLOG(1) << "Ignoring event describing already-cached state"; | |
| 56 return POST_DISPATCH_PERFORM_DEFAULT; | |
| 57 } | |
| 58 found_changed_output = true; | |
| 59 break; | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 if (!connected && !found_changed_output) { | |
| 64 VLOG(1) << "Ignoring event describing already-disconnected output"; | |
| 65 return POST_DISPATCH_PERFORM_DEFAULT; | |
| 66 } | |
| 67 | |
| 68 delegate_->NotifyDisplayObservers(); | |
| 69 | |
| 70 return POST_DISPATCH_PERFORM_DEFAULT; | |
| 71 } | |
| 72 | |
| 73 } // namespace chromeos | |
| OLD | NEW |