Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: chrome/browser/extensions/global_shortcut_listener_x11.cc

Issue 219743002: x11: Move X event handling out of the message-pump. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge-r261267 Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/extensions/global_shortcut_listener_x11.h" 5 #include "chrome/browser/extensions/global_shortcut_listener_x11.h"
6 6
7 #include "content/public/browser/browser_thread.h" 7 #include "content/public/browser/browser_thread.h"
8 #include "ui/base/accelerators/accelerator.h" 8 #include "ui/base/accelerators/accelerator.h"
9 #include "ui/events/keycodes/keyboard_code_conversion_x.h" 9 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
10 #include "ui/gfx/x/x11_error_tracker.h" 10 #include "ui/gfx/x/x11_error_tracker.h"
11 #include "ui/gfx/x/x11_types.h" 11 #include "ui/gfx/x/x11_types.h"
12 12
13 #if defined(TOOLKIT_GTK) 13 #if defined(TOOLKIT_GTK)
14 #include <gdk/gdkx.h> 14 #include <gdk/gdkx.h>
15 #else 15 #else
16 #include "base/message_loop/message_pump_x11.h" 16 #include "ui/events/platform/x11/x11_event_source.h"
17 #endif 17 #endif
18 18
19 using content::BrowserThread; 19 using content::BrowserThread;
20 20
21 namespace { 21 namespace {
22 22
23 // The modifiers masks used for grabing keys. Due to XGrabKey only working on 23 // The modifiers masks used for grabing keys. Due to XGrabKey only working on
24 // exact modifiers, we need to grab all key combination including zero or more 24 // exact modifiers, we need to grab all key combination including zero or more
25 // of the following: Num lock, Caps lock and Scroll lock. So that we can make 25 // of the following: Num lock, Caps lock and Scroll lock. So that we can make
26 // sure the behavior of global shortcuts is consistent on all platforms. 26 // sure the behavior of global shortcuts is consistent on all platforms.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 void GlobalShortcutListenerX11::StartListening() { 71 void GlobalShortcutListenerX11::StartListening() {
72 DCHECK(!is_listening_); // Don't start twice. 72 DCHECK(!is_listening_); // Don't start twice.
73 DCHECK(!registered_hot_keys_.empty()); // Also don't start if no hotkey is 73 DCHECK(!registered_hot_keys_.empty()); // Also don't start if no hotkey is
74 // registered. 74 // registered.
75 #if defined(TOOLKIT_GTK) 75 #if defined(TOOLKIT_GTK)
76 gdk_window_add_filter(gdk_get_default_root_window(), 76 gdk_window_add_filter(gdk_get_default_root_window(),
77 &GlobalShortcutListenerX11::OnXEventThunk, 77 &GlobalShortcutListenerX11::OnXEventThunk,
78 this); 78 this);
79 #else 79 #else
80 base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this); 80 ui::X11EventSource::GetInstance()->AddPlatformEventDispatcher(this);
81 #endif 81 #endif
82 82
83 is_listening_ = true; 83 is_listening_ = true;
84 } 84 }
85 85
86 void GlobalShortcutListenerX11::StopListening() { 86 void GlobalShortcutListenerX11::StopListening() {
87 DCHECK(is_listening_); // No point if we are not already listening. 87 DCHECK(is_listening_); // No point if we are not already listening.
88 DCHECK(registered_hot_keys_.empty()); // Make sure the set is clean before 88 DCHECK(registered_hot_keys_.empty()); // Make sure the set is clean before
89 // ending. 89 // ending.
90 90
91 #if defined(TOOLKIT_GTK) 91 #if defined(TOOLKIT_GTK)
92 gdk_window_remove_filter(NULL, 92 gdk_window_remove_filter(NULL,
93 &GlobalShortcutListenerX11::OnXEventThunk, 93 &GlobalShortcutListenerX11::OnXEventThunk,
94 this); 94 this);
95 #else 95 #else
96 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); 96 ui::X11EventSource::GetInstance()->RemovePlatformEventDispatcher(this);
97 #endif 97 #endif
98 98
99 is_listening_ = false; 99 is_listening_ = false;
100 } 100 }
101 101
102 #if !defined(TOOLKIT_GTK) 102 #if !defined(TOOLKIT_GTK)
103 uint32_t GlobalShortcutListenerX11::Dispatch(const base::NativeEvent& event) { 103 bool GlobalShortcutListenerX11::CanDispatchEvent(
104 if (event->type == KeyPress) 104 const ui::PlatformEvent& event) {
105 OnXKeyPressEvent(event); 105 return event->type == KeyPress;
106 }
106 107
107 return POST_DISPATCH_NONE; 108 uint32_t GlobalShortcutListenerX11::DispatchEvent(
109 const ui::PlatformEvent& event) {
110 CHECK_EQ(KeyPress, event->type);
111 OnXKeyPressEvent(event);
112
113 return ui::POST_DISPATCH_NONE;
108 } 114 }
109 #endif 115 #endif
110 116
111 bool GlobalShortcutListenerX11::RegisterAcceleratorImpl( 117 bool GlobalShortcutListenerX11::RegisterAcceleratorImpl(
112 const ui::Accelerator& accelerator) { 118 const ui::Accelerator& accelerator) {
113 DCHECK(registered_hot_keys_.find(accelerator) == registered_hot_keys_.end()); 119 DCHECK(registered_hot_keys_.find(accelerator) == registered_hot_keys_.end());
114 120
115 int modifiers = GetNativeModifiers(accelerator); 121 int modifiers = GetNativeModifiers(accelerator);
116 KeyCode keycode = XKeysymToKeycode(x_display_, 122 KeyCode keycode = XKeysymToKeycode(x_display_,
117 XKeysymForWindowsKeyCode(accelerator.key_code(), false)); 123 XKeysymForWindowsKeyCode(accelerator.key_code(), false));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 modifiers |= (x_event->xkey.state & ControlMask) ? ui::EF_CONTROL_DOWN : 0; 178 modifiers |= (x_event->xkey.state & ControlMask) ? ui::EF_CONTROL_DOWN : 0;
173 modifiers |= (x_event->xkey.state & Mod1Mask) ? ui::EF_ALT_DOWN : 0; 179 modifiers |= (x_event->xkey.state & Mod1Mask) ? ui::EF_ALT_DOWN : 0;
174 180
175 ui::Accelerator accelerator( 181 ui::Accelerator accelerator(
176 ui::KeyboardCodeFromXKeyEvent(x_event), modifiers); 182 ui::KeyboardCodeFromXKeyEvent(x_event), modifiers);
177 if (registered_hot_keys_.find(accelerator) != registered_hot_keys_.end()) 183 if (registered_hot_keys_.find(accelerator) != registered_hot_keys_.end())
178 NotifyKeyPressed(accelerator); 184 NotifyKeyPressed(accelerator);
179 } 185 }
180 186
181 } // namespace extensions 187 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698