| 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 |
| 11 namespace { | |
| 12 | |
| 13 // Pro-processes an XEvent before it is handled. The pre-processings include: | |
| 14 // - Map Alt+Button1 to Button3 | |
| 15 void PreprocessXEvent(XEvent* xevent) { | |
| 16 if (!xevent || xevent->type != GenericEvent) | |
| 17 return; | |
| 18 | |
| 19 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xevent->xcookie.data); | |
| 20 if ((xievent->evtype == XI_ButtonPress || | |
| 21 xievent->evtype == XI_ButtonRelease) && | |
| 22 (xievent->mods.effective & Mod1Mask) && | |
| 23 xievent->detail == 1) { | |
| 24 xievent->mods.effective &= ~Mod1Mask; | |
| 25 xievent->detail = 3; | |
| 26 if (xievent->evtype == XI_ButtonRelease) { | |
| 27 // On the release clear the left button from the existing state and the | |
| 28 // mods, and set the right button. | |
| 29 XISetMask(xievent->buttons.mask, 3); | |
| 30 XIClearMask(xievent->buttons.mask, 1); | |
| 31 xievent->mods.effective &= ~Button1Mask; | |
| 32 } | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 namespace aura { | 11 namespace aura { |
| 39 | 12 |
| 40 DispatcherLinux::DispatcherLinux() | 13 DispatcherLinux::DispatcherLinux() |
| 41 : x_root_window_( | 14 : x_root_window_( |
| 42 DefaultRootWindow(base::MessagePumpAuraX11::GetDefaultXDisplay())) { | 15 DefaultRootWindow(base::MessagePumpAuraX11::GetDefaultXDisplay())) { |
| 43 base::MessagePumpAuraX11::SetDefaultDispatcher(this); | 16 base::MessagePumpAuraX11::SetDefaultDispatcher(this); |
| 44 MessageLoopForUI::current()->AddObserver(this); | 17 MessageLoopForUI::current()->AddObserver(this); |
| 45 } | 18 } |
| 46 | 19 |
| 47 DispatcherLinux::~DispatcherLinux() { | 20 DispatcherLinux::~DispatcherLinux() { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 (*it)->Dispatch(xev); | 75 (*it)->Dispatch(xev); |
| 103 } | 76 } |
| 104 return true; | 77 return true; |
| 105 } | 78 } |
| 106 MessageLoop::Dispatcher* dispatcher = GetDispatcherForXEvent(xev); | 79 MessageLoop::Dispatcher* dispatcher = GetDispatcherForXEvent(xev); |
| 107 return dispatcher ? dispatcher->Dispatch(xev) : true; | 80 return dispatcher ? dispatcher->Dispatch(xev) : true; |
| 108 } | 81 } |
| 109 | 82 |
| 110 base::EventStatus DispatcherLinux::WillProcessEvent( | 83 base::EventStatus DispatcherLinux::WillProcessEvent( |
| 111 const base::NativeEvent& event) { | 84 const base::NativeEvent& event) { |
| 112 PreprocessXEvent(event); | |
| 113 return base::EVENT_CONTINUE; | 85 return base::EVENT_CONTINUE; |
| 114 } | 86 } |
| 115 | 87 |
| 116 void DispatcherLinux::DidProcessEvent(const base::NativeEvent& event) { | 88 void DispatcherLinux::DidProcessEvent(const base::NativeEvent& event) { |
| 117 } | 89 } |
| 118 | 90 |
| 119 MessageLoop::Dispatcher* DispatcherLinux::GetDispatcherForXEvent( | 91 MessageLoop::Dispatcher* DispatcherLinux::GetDispatcherForXEvent( |
| 120 XEvent* xev) const { | 92 XEvent* xev) const { |
| 121 ::Window x_window = xev->xany.window; | 93 ::Window x_window = xev->xany.window; |
| 122 if (xev->type == GenericEvent) { | 94 if (xev->type == GenericEvent) { |
| 123 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); | 95 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
| 124 x_window = xievent->event; | 96 x_window = xievent->event; |
| 125 } | 97 } |
| 126 DispatchersMap::const_iterator it = dispatchers_.find(x_window); | 98 DispatchersMap::const_iterator it = dispatchers_.find(x_window); |
| 127 return it != dispatchers_.end() ? it->second : NULL; | 99 return it != dispatchers_.end() ? it->second : NULL; |
| 128 } | 100 } |
| 129 | 101 |
| 130 MessageLoop::Dispatcher* CreateDispatcher() { | 102 MessageLoop::Dispatcher* CreateDispatcher() { |
| 131 return new DispatcherLinux; | 103 return new DispatcherLinux; |
| 132 } | 104 } |
| 133 | 105 |
| 134 } // namespace aura | 106 } // namespace aura |
| OLD | NEW |