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/aura/dispatcher_linux.h" | 5 #include "ui/aura/dispatcher_linux.h" |
6 | 6 |
7 #include <X11/extensions/XInput2.h> | 7 #include <X11/extensions/XInput2.h> |
8 | 8 |
9 #include "ui/base/events.h" | 9 #include "ui/base/events.h" |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... | |
30 XIClearMask(xievent->buttons.mask, 1); | 30 XIClearMask(xievent->buttons.mask, 1); |
31 xievent->mods.effective &= ~Button1Mask; | 31 xievent->mods.effective &= ~Button1Mask; |
32 } | 32 } |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 namespace aura { | 38 namespace aura { |
39 | 39 |
40 DispatcherLinux::DispatcherLinux() { | 40 DispatcherLinux::DispatcherLinux() |
41 : root_window_( | |
42 DefaultRootWindow(base::MessagePumpX::GetDefaultXDisplay())) { | |
41 base::MessagePumpX::SetDefaultDispatcher(this); | 43 base::MessagePumpX::SetDefaultDispatcher(this); |
42 MessageLoopForUI::current()->AddObserver(this); | 44 MessageLoopForUI::current()->AddObserver(this); |
43 } | 45 } |
44 | 46 |
45 DispatcherLinux::~DispatcherLinux() { | 47 DispatcherLinux::~DispatcherLinux() { |
46 MessageLoopForUI::current()->RemoveObserver(this); | 48 MessageLoopForUI::current()->RemoveObserver(this); |
47 base::MessagePumpX::SetDefaultDispatcher(NULL); | 49 base::MessagePumpX::SetDefaultDispatcher(NULL); |
48 } | 50 } |
49 | 51 |
50 void DispatcherLinux::WindowDispatcherCreated( | 52 void DispatcherLinux::RegisterDispatcher( |
51 ::Window window, | 53 ::Window window, |
52 MessageLoop::Dispatcher* dispatcher) { | 54 MessageLoop::Dispatcher* dispatcher) { |
53 dispatchers_.insert(std::make_pair(window, dispatcher)); | 55 dispatchers_.insert(std::make_pair(window, dispatcher)); |
54 } | 56 } |
55 | 57 |
56 void DispatcherLinux::WindowDispatcherDestroying(::Window window) { | 58 void DispatcherLinux::RegisterRootWindowDispatcher( |
59 MessageLoop::Dispatcher* dispatcher) { | |
60 DCHECK(std::find(root_window_dispatchers_.begin(), | |
61 root_window_dispatchers_.end(), | |
62 dispatcher) == | |
63 root_window_dispatchers_.end()); | |
64 root_window_dispatchers_.push_back(dispatcher); | |
65 } | |
66 | |
67 void DispatcherLinux::UnregisterDispatcher(::Window window) { | |
Daniel Erat
2012/05/22 14:33:42
nit: move this after RegisterDispatcher() to match
oshima
2012/05/22 19:50:02
Done.
| |
57 dispatchers_.erase(window); | 68 dispatchers_.erase(window); |
58 } | 69 } |
59 | 70 |
71 void DispatcherLinux::UnregisterRootWindowDispatcher( | |
72 MessageLoop::Dispatcher* dispatcher) { | |
73 root_window_dispatchers_.erase( | |
74 std::remove(root_window_dispatchers_.begin(), | |
75 root_window_dispatchers_.end(), | |
76 dispatcher)); | |
77 } | |
78 | |
60 bool DispatcherLinux::Dispatch(const base::NativeEvent& xev) { | 79 bool DispatcherLinux::Dispatch(const base::NativeEvent& xev) { |
61 // XI_HierarchyChanged events are special. There is no window associated with | 80 // XI_HierarchyChanged events are special. There is no window associated with |
62 // these events. So process them directly from here. | 81 // these events. So process them directly from here. |
63 if (xev->type == GenericEvent && | 82 if (xev->type == GenericEvent && |
64 xev->xgeneric.evtype == XI_HierarchyChanged) { | 83 xev->xgeneric.evtype == XI_HierarchyChanged) { |
65 ui::UpdateDeviceList(); | 84 ui::UpdateDeviceList(); |
66 return true; | 85 return true; |
67 } | 86 } |
68 | 87 |
69 // MappingNotify events (meaning that the keyboard or pointer buttons have | 88 // MappingNotify events (meaning that the keyboard or pointer buttons have |
70 // been remapped) aren't associated with a window; send them to all | 89 // been remapped) aren't associated with a window; send them to all |
71 // dispatchers. | 90 // dispatchers. |
72 if (xev->type == MappingNotify) { | 91 if (xev->type == MappingNotify) { |
73 for (DispatchersMap::const_iterator it = dispatchers_.begin(); | 92 for (DispatchersMap::const_iterator it = dispatchers_.begin(); |
74 it != dispatchers_.end(); ++it) { | 93 it != dispatchers_.end(); ++it) { |
75 it->second->Dispatch(xev); | 94 it->second->Dispatch(xev); |
76 } | 95 } |
77 return true; | 96 return true; |
78 } | 97 } |
79 | 98 if (xev->xany.window == root_window_) { |
99 DispatchRootWindowEvent(xev); | |
100 return true; | |
101 } | |
80 MessageLoop::Dispatcher* dispatcher = GetDispatcherForXEvent(xev); | 102 MessageLoop::Dispatcher* dispatcher = GetDispatcherForXEvent(xev); |
81 return dispatcher ? dispatcher->Dispatch(xev) : true; | 103 return dispatcher ? dispatcher->Dispatch(xev) : true; |
82 } | 104 } |
83 | 105 |
84 base::EventStatus DispatcherLinux::WillProcessEvent( | 106 base::EventStatus DispatcherLinux::WillProcessEvent( |
85 const base::NativeEvent& event) { | 107 const base::NativeEvent& event) { |
86 PreprocessXEvent(event); | 108 PreprocessXEvent(event); |
87 return base::EVENT_CONTINUE; | 109 return base::EVENT_CONTINUE; |
88 } | 110 } |
89 | 111 |
90 void DispatcherLinux::DidProcessEvent(const base::NativeEvent& event) { | 112 void DispatcherLinux::DidProcessEvent(const base::NativeEvent& event) { |
91 } | 113 } |
92 | 114 |
93 MessageLoop::Dispatcher* DispatcherLinux::GetDispatcherForXEvent( | 115 MessageLoop::Dispatcher* DispatcherLinux::GetDispatcherForXEvent( |
94 XEvent* xev) const { | 116 XEvent* xev) const { |
95 ::Window window = xev->xany.window; | 117 ::Window window = xev->xany.window; |
96 if (xev->type == GenericEvent) { | 118 if (xev->type == GenericEvent) { |
97 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); | 119 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
98 window = xievent->event; | 120 window = xievent->event; |
99 } | 121 } |
100 DispatchersMap::const_iterator it = dispatchers_.find(window); | 122 DispatchersMap::const_iterator it = dispatchers_.find(window); |
101 return it != dispatchers_.end() ? it->second : NULL; | 123 return it != dispatchers_.end() ? it->second : NULL; |
102 } | 124 } |
103 | 125 |
126 void DispatcherLinux::DispatchRootWindowEvent(XEvent* xev) { | |
127 for (Dispatchers::const_iterator it = root_window_dispatchers_.begin(); | |
Daniel Erat
2012/05/22 14:33:42
nit: maybe move this into Dispatch() to improve re
oshima
2012/05/22 19:50:02
Done.
| |
128 it != root_window_dispatchers_.end(); | |
129 ++it) { | |
130 (*it)->Dispatch(xev); | |
131 } | |
132 } | |
133 | |
104 MessageLoop::Dispatcher* CreateDispatcher() { | 134 MessageLoop::Dispatcher* CreateDispatcher() { |
105 return new DispatcherLinux; | 135 return new DispatcherLinux; |
106 } | 136 } |
107 | 137 |
108 } // namespace aura | 138 } // namespace aura |
OLD | NEW |