1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_KEY_EVENT_LISTENER_H_ 6#define CHROME_BROWSER_CHROMEOS_SYSTEM_KEY_EVENT_LISTENER_H_ 7#pragma once 8 9#include <gdk/gdk.h> 10 11#include "base/memory/singleton.h" 12#include "chrome/browser/chromeos/wm_message_listener.h" 13 14namespace chromeos { 15 16class AudioHandler; 17 18// SystemKeyEventListener listens for volume related key presses from GDK, then 19// tells the AudioHandler to adjust volume accordingly. Start by just calling 20// instance() to get it going. 21 22// TODO(davej): Remove WmMessageListener::Observer once volume key handling has 23// been removed from the window manager since those keys take precedence. 24 25class SystemKeyEventListener : public WmMessageListener::Observer { 26 public: 27 static SystemKeyEventListener* GetInstance(); 28 29 // WmMessageListener::Observer: 30 virtual void ProcessWmMessage(const WmIpc::Message& message, 31 GdkWindow* window); 32 33 void Stop(); 34 35 private: 36 // Defines the delete on exit Singleton traits we like. Best to have this 37 // and const/dest private as recommended for Singletons. 38 friend struct DefaultSingletonTraits<SystemKeyEventListener>; 39 40 SystemKeyEventListener(); 41 virtual ~SystemKeyEventListener(); 42 43 // This event filter intercepts events before they reach GDK, allowing us to 44 // check for system level keyboard events regardless of which window has 45 // focus. 46 static GdkFilterReturn GdkEventFilter(GdkXEvent* gxevent, 47 GdkEvent* gevent, 48 gpointer data); 49 50 // Tell X we are interested in the specified key/mask combination. 51 // Capslock and Numlock are always ignored. 52 void GrabKey(int32 key, uint32 mask); 53 54 void OnVolumeMute(); 55 void OnVolumeDown(); 56 void OnVolumeUp(); 57 58 int32 key_volume_mute_; 59 int32 key_volume_down_; 60 int32 key_volume_up_; 61 int32 key_f8_; 62 int32 key_f9_; 63 int32 key_f10_; 64 65 bool stopped_; 66 67 // AudioHandler is a Singleton class we are just caching a pointer to here, 68 // and we do not own the pointer. 69 AudioHandler* const audio_handler_; 70 71 DISALLOW_COPY_AND_ASSIGN(SystemKeyEventListener); 72}; 73 74} // namespace chromeos 75 76#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_KEY_EVENT_LISTENER_H_ 77 78