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

Unified Diff: chrome/browser/chromeos/system_key_event_listener.cc

Issue 7011005: Use observer for an X message pump to intercept keyevents for volume control. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/system_key_event_listener.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/system_key_event_listener.cc
diff --git a/chrome/browser/chromeos/system_key_event_listener.cc b/chrome/browser/chromeos/system_key_event_listener.cc
index 5fa6a50513e7578e3c480655401b9e8487b74676..00991b819494c2590276f0539953536063883d2d 100644
--- a/chrome/browser/chromeos/system_key_event_listener.cc
+++ b/chrome/browser/chromeos/system_key_event_listener.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -13,6 +13,10 @@
#include "content/browser/user_metrics.h"
#include "third_party/cros/chromeos_wm_ipc_enums.h"
+#if defined(TOUCH_UI)
+#include "base/message_pump_glib_x_dispatch.h"
+#endif
+
namespace chromeos {
namespace {
@@ -47,7 +51,12 @@ SystemKeyEventListener::SystemKeyEventListener()
GrabKey(key_f8_, 0);
GrabKey(key_f9_, 0);
GrabKey(key_f10_, 0);
+
+#if defined(TOUCH_UI)
+ MessageLoopForUI::current()->AddObserver(this);
+#else
gdk_window_add_filter(NULL, GdkEventFilter, this);
+#endif
}
SystemKeyEventListener::~SystemKeyEventListener() {
@@ -58,7 +67,11 @@ void SystemKeyEventListener::Stop() {
if (stopped_)
return;
WmMessageListener::GetInstance()->RemoveObserver(this);
+#if defined(TOUCH_UI)
+ MessageLoopForUI::current()->RemoveObserver(this);
+#else
gdk_window_remove_filter(NULL, GdkEventFilter, this);
+#endif
audio_handler_->Disconnect();
stopped_ = true;
}
@@ -93,34 +106,8 @@ GdkFilterReturn SystemKeyEventListener::GdkEventFilter(GdkXEvent* gxevent,
SystemKeyEventListener* listener = static_cast<SystemKeyEventListener*>(data);
XEvent* xevent = static_cast<XEvent*>(gxevent);
- if (xevent->type == KeyPress) {
- int32 keycode = xevent->xkey.keycode;
- if (keycode) {
- // Only doing non-Alt/Shift/Ctrl modified keys
- if (!(xevent->xkey.state & (Mod1Mask | ShiftMask | ControlMask))) {
- if ((keycode == listener->key_f8_) ||
- (keycode == listener->key_volume_mute_)) {
- if (keycode == listener->key_f8_)
- UserMetrics::RecordAction(UserMetricsAction("Accel_VolumeMute_F8"));
- listener->OnVolumeMute();
- return GDK_FILTER_REMOVE;
- } else if ((keycode == listener->key_f9_) ||
- keycode == listener->key_volume_down_) {
- if (keycode == listener->key_f9_)
- UserMetrics::RecordAction(UserMetricsAction("Accel_VolumeDown_F9"));
- listener->OnVolumeDown();
- return GDK_FILTER_REMOVE;
- } else if ((keycode == listener->key_f10_) ||
- (keycode == listener->key_volume_up_)) {
- if (keycode == listener->key_f10_)
- UserMetrics::RecordAction(UserMetricsAction("Accel_VolumeUp_F10"));
- listener->OnVolumeUp();
- return GDK_FILTER_REMOVE;
- }
- }
- }
- }
- return GDK_FILTER_CONTINUE;
+ return listener->WillProcessXEvent(xevent) ? GDK_FILTER_REMOVE
+ : GDK_FILTER_CONTINUE;
}
void SystemKeyEventListener::GrabKey(int32 key, uint32 mask) {
@@ -173,4 +160,35 @@ void SystemKeyEventListener::OnVolumeUp() {
BrightnessBubble::GetInstance()->HideBubble();
}
+bool SystemKeyEventListener::WillProcessXEvent(XEvent* xevent) {
+ if (xevent->type == KeyPress) {
+ int32 keycode = xevent->xkey.keycode;
+ if (keycode) {
+ // Only doing non-Alt/Shift/Ctrl modified keys
+ if (!(xevent->xkey.state & (Mod1Mask | ShiftMask | ControlMask))) {
+ if ((keycode == key_f8_) ||
+ (keycode == key_volume_mute_)) {
+ if (keycode == key_f8_)
+ UserMetrics::RecordAction(UserMetricsAction("Accel_VolumeMute_F8"));
+ OnVolumeMute();
+ return true;
+ } else if ((keycode == key_f9_) ||
+ keycode == key_volume_down_) {
+ if (keycode == key_f9_)
+ UserMetrics::RecordAction(UserMetricsAction("Accel_VolumeDown_F9"));
+ OnVolumeDown();
+ return true;
+ } else if ((keycode == key_f10_) ||
+ (keycode == key_volume_up_)) {
+ if (keycode == key_f10_)
+ UserMetrics::RecordAction(UserMetricsAction("Accel_VolumeUp_F10"));
+ OnVolumeUp();
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/system_key_event_listener.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698