OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <X11/keysym.h> | 5 #include <X11/keysym.h> |
6 #include <X11/Xlib.h> | 6 #include <X11/Xlib.h> |
7 | 7 |
8 // X macro fail. | 8 // X macro fail. |
9 #if defined(RootWindow) | 9 #if defined(RootWindow) |
10 #undef RootWindow | 10 #undef RootWindow |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 66 } |
67 | 67 |
68 private: | 68 private: |
69 base::Closure closure_; | 69 base::Closure closure_; |
70 EventWaiterMatcher matcher_; | 70 EventWaiterMatcher matcher_; |
71 DISALLOW_COPY_AND_ASSIGN(EventWaiter); | 71 DISALLOW_COPY_AND_ASSIGN(EventWaiter); |
72 }; | 72 }; |
73 | 73 |
74 // Returns atom that indidates that the XEvent is marker event. | 74 // Returns atom that indidates that the XEvent is marker event. |
75 Atom MarkerEventAtom() { | 75 Atom MarkerEventAtom() { |
76 return XInternAtom(ui::GetXDisplay(), "marker_event", False); | 76 return XInternAtom(gfx::GetXDisplay(), "marker_event", False); |
77 } | 77 } |
78 | 78 |
79 // Returns true when the event is a marker event. | 79 // Returns true when the event is a marker event. |
80 bool Matcher(const base::NativeEvent& event) { | 80 bool Matcher(const base::NativeEvent& event) { |
81 return event->xany.type == ClientMessage && | 81 return event->xany.type == ClientMessage && |
82 event->xclient.message_type == MarkerEventAtom(); | 82 event->xclient.message_type == MarkerEventAtom(); |
83 } | 83 } |
84 | 84 |
85 class UIControlsX11 : public UIControlsAura { | 85 class UIControlsX11 : public UIControlsAura { |
86 public: | 86 public: |
(...skipping 21 matching lines...) Expand all Loading... |
108 DCHECK(!command); // No command key on Aura | 108 DCHECK(!command); // No command key on Aura |
109 XEvent xevent = {0}; | 109 XEvent xevent = {0}; |
110 xevent.xkey.type = KeyPress; | 110 xevent.xkey.type = KeyPress; |
111 if (control) | 111 if (control) |
112 SetKeycodeAndSendThenMask(&xevent, XK_Control_L, ControlMask); | 112 SetKeycodeAndSendThenMask(&xevent, XK_Control_L, ControlMask); |
113 if (shift) | 113 if (shift) |
114 SetKeycodeAndSendThenMask(&xevent, XK_Shift_L, ShiftMask); | 114 SetKeycodeAndSendThenMask(&xevent, XK_Shift_L, ShiftMask); |
115 if (alt) | 115 if (alt) |
116 SetKeycodeAndSendThenMask(&xevent, XK_Alt_L, Mod1Mask); | 116 SetKeycodeAndSendThenMask(&xevent, XK_Alt_L, Mod1Mask); |
117 xevent.xkey.keycode = | 117 xevent.xkey.keycode = |
118 XKeysymToKeycode(ui::GetXDisplay(), | 118 XKeysymToKeycode(gfx::GetXDisplay(), |
119 ui::XKeysymForWindowsKeyCode(key, shift)); | 119 ui::XKeysymForWindowsKeyCode(key, shift)); |
120 root_window_->PostNativeEvent(&xevent); | 120 root_window_->PostNativeEvent(&xevent); |
121 | 121 |
122 // Send key release events. | 122 // Send key release events. |
123 xevent.xkey.type = KeyRelease; | 123 xevent.xkey.type = KeyRelease; |
124 root_window_->PostNativeEvent(&xevent); | 124 root_window_->PostNativeEvent(&xevent); |
125 if (alt) | 125 if (alt) |
126 UnmaskAndSetKeycodeThenSend(&xevent, Mod1Mask, XK_Alt_L); | 126 UnmaskAndSetKeycodeThenSend(&xevent, Mod1Mask, XK_Alt_L); |
127 if (shift) | 127 if (shift) |
128 UnmaskAndSetKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L); | 128 UnmaskAndSetKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 } | 218 } |
219 marker_event->xclient.message_type = MarkerEventAtom(); | 219 marker_event->xclient.message_type = MarkerEventAtom(); |
220 root_window_->PostNativeEvent(marker_event); | 220 root_window_->PostNativeEvent(marker_event); |
221 new EventWaiter(closure, &Matcher); | 221 new EventWaiter(closure, &Matcher); |
222 } | 222 } |
223 private: | 223 private: |
224 void SetKeycodeAndSendThenMask(XEvent* xevent, | 224 void SetKeycodeAndSendThenMask(XEvent* xevent, |
225 KeySym keysym, | 225 KeySym keysym, |
226 unsigned int mask) { | 226 unsigned int mask) { |
227 xevent->xkey.keycode = | 227 xevent->xkey.keycode = |
228 XKeysymToKeycode(ui::GetXDisplay(), keysym); | 228 XKeysymToKeycode(gfx::GetXDisplay(), keysym); |
229 root_window_->PostNativeEvent(xevent); | 229 root_window_->PostNativeEvent(xevent); |
230 xevent->xkey.state |= mask; | 230 xevent->xkey.state |= mask; |
231 } | 231 } |
232 | 232 |
233 void UnmaskAndSetKeycodeThenSend(XEvent* xevent, | 233 void UnmaskAndSetKeycodeThenSend(XEvent* xevent, |
234 unsigned int mask, | 234 unsigned int mask, |
235 KeySym keysym) { | 235 KeySym keysym) { |
236 xevent->xkey.state ^= mask; | 236 xevent->xkey.state ^= mask; |
237 xevent->xkey.keycode = | 237 xevent->xkey.keycode = |
238 XKeysymToKeycode(ui::GetXDisplay(), keysym); | 238 XKeysymToKeycode(gfx::GetXDisplay(), keysym); |
239 root_window_->PostNativeEvent(xevent); | 239 root_window_->PostNativeEvent(xevent); |
240 } | 240 } |
241 | 241 |
242 aura::RootWindow* root_window_; | 242 aura::RootWindow* root_window_; |
243 | 243 |
244 DISALLOW_COPY_AND_ASSIGN(UIControlsX11); | 244 DISALLOW_COPY_AND_ASSIGN(UIControlsX11); |
245 }; | 245 }; |
246 | 246 |
247 } // namespace | 247 } // namespace |
248 | 248 |
249 UIControlsAura* CreateUIControlsAura(aura::RootWindow* root_window) { | 249 UIControlsAura* CreateUIControlsAura(aura::RootWindow* root_window) { |
250 return new UIControlsX11(root_window); | 250 return new UIControlsX11(root_window); |
251 } | 251 } |
252 | 252 |
253 } // namespace test | 253 } // namespace test |
254 } // namespace aura | 254 } // namespace aura |
OLD | NEW |