| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/aura/dispatcher_linux.h" | |
| 6 | |
| 7 #include <X11/extensions/XInput2.h> | |
| 8 | |
| 9 #include "ui/base/events.h" | |
| 10 | |
| 11 namespace aura { | |
| 12 | |
| 13 DispatcherLinux::DispatcherLinux() | |
| 14 : x_root_window_( | |
| 15 DefaultRootWindow(base::MessagePumpAuraX11::GetDefaultXDisplay())) { | |
| 16 base::MessagePumpAuraX11::SetDefaultDispatcher(this); | |
| 17 MessageLoopForUI::current()->AddObserver(this); | |
| 18 } | |
| 19 | |
| 20 DispatcherLinux::~DispatcherLinux() { | |
| 21 MessageLoopForUI::current()->RemoveObserver(this); | |
| 22 base::MessagePumpAuraX11::SetDefaultDispatcher(NULL); | |
| 23 } | |
| 24 | |
| 25 void DispatcherLinux::AddDispatcherForWindow( | |
| 26 MessageLoop::Dispatcher* dispatcher, | |
| 27 ::Window x_window) { | |
| 28 dispatchers_.insert(std::make_pair(x_window, dispatcher)); | |
| 29 } | |
| 30 | |
| 31 void DispatcherLinux::RemoveDispatcherForWindow(::Window x_window) { | |
| 32 dispatchers_.erase(x_window); | |
| 33 } | |
| 34 | |
| 35 void DispatcherLinux::AddDispatcherForRootWindow( | |
| 36 MessageLoop::Dispatcher* dispatcher) { | |
| 37 DCHECK(std::find(root_window_dispatchers_.begin(), | |
| 38 root_window_dispatchers_.end(), | |
| 39 dispatcher) == | |
| 40 root_window_dispatchers_.end()); | |
| 41 root_window_dispatchers_.push_back(dispatcher); | |
| 42 } | |
| 43 | |
| 44 void DispatcherLinux::RemoveDispatcherForRootWindow( | |
| 45 MessageLoop::Dispatcher* dispatcher) { | |
| 46 root_window_dispatchers_.erase( | |
| 47 std::remove(root_window_dispatchers_.begin(), | |
| 48 root_window_dispatchers_.end(), | |
| 49 dispatcher)); | |
| 50 } | |
| 51 | |
| 52 bool DispatcherLinux::Dispatch(const base::NativeEvent& xev) { | |
| 53 // XI_HierarchyChanged events are special. There is no window associated with | |
| 54 // these events. So process them directly from here. | |
| 55 if (xev->type == GenericEvent && | |
| 56 xev->xgeneric.evtype == XI_HierarchyChanged) { | |
| 57 ui::UpdateDeviceList(); | |
| 58 return true; | |
| 59 } | |
| 60 | |
| 61 // MappingNotify events (meaning that the keyboard or pointer buttons have | |
| 62 // been remapped) aren't associated with a window; send them to all | |
| 63 // dispatchers. | |
| 64 if (xev->type == MappingNotify) { | |
| 65 for (DispatchersMap::const_iterator it = dispatchers_.begin(); | |
| 66 it != dispatchers_.end(); ++it) { | |
| 67 it->second->Dispatch(xev); | |
| 68 } | |
| 69 return true; | |
| 70 } | |
| 71 if (xev->xany.window == x_root_window_) { | |
| 72 for (Dispatchers::const_iterator it = root_window_dispatchers_.begin(); | |
| 73 it != root_window_dispatchers_.end(); | |
| 74 ++it) { | |
| 75 (*it)->Dispatch(xev); | |
| 76 } | |
| 77 return true; | |
| 78 } | |
| 79 MessageLoop::Dispatcher* dispatcher = GetDispatcherForXEvent(xev); | |
| 80 return dispatcher ? dispatcher->Dispatch(xev) : true; | |
| 81 } | |
| 82 | |
| 83 base::EventStatus DispatcherLinux::WillProcessEvent( | |
| 84 const base::NativeEvent& event) { | |
| 85 return base::EVENT_CONTINUE; | |
| 86 } | |
| 87 | |
| 88 void DispatcherLinux::DidProcessEvent(const base::NativeEvent& event) { | |
| 89 } | |
| 90 | |
| 91 MessageLoop::Dispatcher* DispatcherLinux::GetDispatcherForXEvent( | |
| 92 XEvent* xev) const { | |
| 93 ::Window x_window = xev->xany.window; | |
| 94 if (xev->type == GenericEvent) { | |
| 95 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); | |
| 96 x_window = xievent->event; | |
| 97 } | |
| 98 DispatchersMap::const_iterator it = dispatchers_.find(x_window); | |
| 99 return it != dispatchers_.end() ? it->second : NULL; | |
| 100 } | |
| 101 | |
| 102 MessageLoop::Dispatcher* CreateDispatcher() { | |
| 103 return new DispatcherLinux; | |
| 104 } | |
| 105 | |
| 106 } // namespace aura | |
| OLD | NEW |