summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-17 21:04:02 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-17 21:04:02 +0000
commitcc4c974335ecf328de5a22e9e75254397f18702e (patch)
tree2686fcc00a58973a9700edca1b11d1762e1018c4
parentdd963e61f462ae0ec47d5d559d6b52f6219a9c19 (diff)
downloadchromium_src-cc4c974335ecf328de5a22e9e75254397f18702e.zip
chromium_src-cc4c974335ecf328de5a22e9e75254397f18702e.tar.gz
chromium_src-cc4c974335ecf328de5a22e9e75254397f18702e.tar.bz2
Handling volume up/down/mute keypresses within Chrome.
When Window Manager sends us a NOTIFY_SYSKEY_CLICKED message, we adjust the volume accordingly. Currently just calling amixer as WM was doing before. There will be a different change submitted for WM to send this message instead of calling amixer itself. Patch by davej@chromium.org: http://codereview.chromium.org/2102001/show BUG=cros/525 TEST=none Related to issue 2107001. Review URL: http://codereview.chromium.org/2107010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47451 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_init.cc5
-rw-r--r--chrome/browser/chromeos/system_key_event_listener.cc78
-rw-r--r--chrome/browser/chromeos/system_key_event_listener.h41
-rw-r--r--chrome/chrome_browser.gypi2
4 files changed, 126 insertions, 0 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc
index 446ffa4..536e808 100644
--- a/chrome/browser/browser_init.cc
+++ b/chrome/browser/browser_init.cc
@@ -73,6 +73,7 @@
#include "chrome/browser/chromeos/cros/power_library.h"
#include "chrome/browser/chromeos/gview_request_interceptor.h"
#include "chrome/browser/chromeos/low_battery_observer.h"
+#include "chrome/browser/chromeos/system_key_event_listener.h"
#include "chrome/browser/chromeos/usb_mount_observer.h"
#include "chrome/browser/chromeos/wm_message_listener.h"
#include "chrome/browser/chromeos/wm_overview_controller.h"
@@ -423,6 +424,10 @@ bool BrowserInit::LaunchBrowser(
static chromeos::LowBatteryObserver* observer =
new chromeos::LowBatteryObserver(profile);
chromeos::CrosLibrary::Get()->GetPowerLibrary()->AddObserver(observer);
+
+ // Creates the SystemKeyEventListener to listen for keypress messages
+ // regardless of what window has focus.
+ chromeos::SystemKeyEventListener::instance();
}
#endif
diff --git a/chrome/browser/chromeos/system_key_event_listener.cc b/chrome/browser/chromeos/system_key_event_listener.cc
new file mode 100644
index 0000000..b5f53f0
--- /dev/null
+++ b/chrome/browser/chromeos/system_key_event_listener.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 2010 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.
+
+#include "chrome/browser/chromeos/system_key_event_listener.h"
+
+#include "third_party/cros/chromeos_wm_ipc_enums.h"
+
+namespace chromeos {
+
+// For now, this file contains the SystemKeyEventListener, which listens for key
+// presses from Window Manager, and just calls amixer to adjust volume. Start
+// by just calling instance() to get it going.
+//
+// TODO(davej): Create AudioHandler() class and call its volume up/down/mute
+// functions, getting rid of these constants and RunCommand(). This class will
+// eventually call PulseAudio directly to get current volume and adjust
+// accordingly, giving us more control over Mute/UnMute behavior as well.
+
+namespace {
+
+const char kIncreaseVolumeLevelCommand[] =
+ "/usr/bin/amixer -- sset Master unmute 5%+";
+const char kDecreaseVolumeLevelCommand[] =
+ "/usr/bin/amixer -- sset Master unmute 5%-";
+const char kMuteAudioCommand[] =
+ "/usr/bin/amixer -- sset Master mute";
+
+} // namespace
+
+// static
+SystemKeyEventListener* SystemKeyEventListener::instance() {
+ SystemKeyEventListener* instance = Singleton<SystemKeyEventListener>::get();
+ return instance;
+}
+
+SystemKeyEventListener::SystemKeyEventListener() {
+ WmMessageListener::instance()->AddObserver(this);
+}
+
+SystemKeyEventListener::~SystemKeyEventListener() {
+ WmMessageListener::instance()->RemoveObserver(this);
+}
+
+void SystemKeyEventListener::ProcessWmMessage(const WmIpc::Message& message,
+ GdkWindow* window) {
+ if (message.type() != WM_IPC_MESSAGE_CHROME_NOTIFY_SYSKEY_PRESSED)
+ return;
+
+ // TODO(davej): Use WmIpcSystemKey enums when available.
+ switch (message.param(0)) {
+ case 0:
+ RunCommand(kMuteAudioCommand);
+ break;
+ case 1:
+ RunCommand(kIncreaseVolumeLevelCommand);
+ break;
+ case 2:
+ RunCommand(kDecreaseVolumeLevelCommand);
+ break;
+ default:
+ DLOG(ERROR) << "SystemKeyEventListener: Unexpected message "
+ << message.param(0)
+ << " received";
+ }
+}
+
+void SystemKeyEventListener::RunCommand(std::string command) {
+ if (command.empty())
+ return;
+ command += " &";
+ DLOG(INFO) << "Running command \"" << command << "\"";
+ if (system(command.c_str()) < 0)
+ LOG(WARNING) << "Got error while running \"" << command << "\"";
+}
+
+} // namespace chromeos
+
diff --git a/chrome/browser/chromeos/system_key_event_listener.h b/chrome/browser/chromeos/system_key_event_listener.h
new file mode 100644
index 0000000..9814483
--- /dev/null
+++ b/chrome/browser/chromeos/system_key_event_listener.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2010 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.
+
+#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_KEY_EVENT_LISTENER_H_
+#define CHROME_BROWSER_CHROMEOS_SYSTEM_KEY_EVENT_LISTENER_H_
+
+#include <gtk/gtk.h>
+
+#include <string>
+
+#include "base/singleton.h"
+#include "chrome/browser/chromeos/wm_message_listener.h"
+
+namespace chromeos {
+
+class SystemKeyEventListener : public WmMessageListener::Observer {
+ public:
+ static SystemKeyEventListener* instance();
+
+ // WmMessageListener::Observer:
+ virtual void ProcessWmMessage(const WmIpc::Message& message,
+ GdkWindow* window);
+
+ private:
+ // Defines the delete on exit Singleton traits we like. Best to have this
+ // and const/dest private as recommended for Singletons.
+ friend struct DefaultSingletonTraits<SystemKeyEventListener>;
+
+ SystemKeyEventListener();
+ virtual ~SystemKeyEventListener();
+
+ void RunCommand(std::string command);
+
+ DISALLOW_COPY_AND_ASSIGN(SystemKeyEventListener);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_KEY_EVENT_LISTENER_H_
+
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index f741231..745952d 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -500,6 +500,8 @@
'browser/chromeos/status/status_area_host.h',
'browser/chromeos/status/status_area_view.cc',
'browser/chromeos/status/status_area_view.h',
+ 'browser/chromeos/system_key_event_listener.cc',
+ 'browser/chromeos/system_key_event_listener.h',
'browser/chromeos/usb_mount_observer.cc',
'browser/chromeos/usb_mount_observer.h',
'browser/chromeos/version_loader.cc',