diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-17 21:04:02 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-17 21:04:02 +0000 |
commit | cc4c974335ecf328de5a22e9e75254397f18702e (patch) | |
tree | 2686fcc00a58973a9700edca1b11d1762e1018c4 /chrome/browser/chromeos | |
parent | dd963e61f462ae0ec47d5d559d6b52f6219a9c19 (diff) | |
download | chromium_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
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r-- | chrome/browser/chromeos/system_key_event_listener.cc | 78 | ||||
-rw-r--r-- | chrome/browser/chromeos/system_key_event_listener.h | 41 |
2 files changed, 119 insertions, 0 deletions
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_ + |