1 // Copyright (c) 2012 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_XINPUT_HIERARCHY_CHANGED_EVENT_LISTENER_H_ 6 #define CHROME_BROWSER_CHROMEOS_XINPUT_HIERARCHY_CHANGED_EVENT_LISTENER_H_ 7 8 #include "base/memory/singleton.h" 9 #include "base/message_loop/message_loop.h" 10 #include "base/observer_list.h" 11 #include "chrome/browser/chromeos/device_hierarchy_observer.h" 12 13 typedef union _XEvent XEvent; 14 15 namespace chromeos { 16 17 // XInputHierarchyChangedEventListener listens for an XI_HierarchyChanged event, 18 // which is sent to Chrome when X detects a system or USB keyboard (or mouse), 19 // then tells X to change the current XKB keyboard layout. Start by just calling 20 // instance() to get it going. 21 class XInputHierarchyChangedEventListener 22 : public base::MessageLoopForUI::Observer { 23 public: 24 static XInputHierarchyChangedEventListener* GetInstance(); 25 26 void Stop(); 27 28 void AddObserver(DeviceHierarchyObserver* observer); 29 void RemoveObserver(DeviceHierarchyObserver* observer); 30 31 private: 32 // Defines the delete on exit Singleton traits we like. Best to have this 33 // and const/dest private as recommended for Singletons. 34 friend struct DefaultSingletonTraits<XInputHierarchyChangedEventListener>; 35 36 XInputHierarchyChangedEventListener(); 37 virtual ~XInputHierarchyChangedEventListener(); 38 39 void Init(); 40 void StopImpl(); 41 42 // MessageLoopForUI::Observer overrides. 43 virtual base::EventStatus WillProcessEvent( 44 const base::NativeEvent& event) OVERRIDE; 45 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE; 46 47 // Returns true if the event was processed, false otherwise. 48 virtual bool ProcessedXEvent(XEvent* xevent); 49 50 // Notify observers that a device has been added/removed. 51 void NotifyDeviceHierarchyChanged(); 52 53 bool stopped_; 54 int xiopcode_; 55 56 ObserverList<DeviceHierarchyObserver> observer_list_; 57 58 DISALLOW_COPY_AND_ASSIGN(XInputHierarchyChangedEventListener); 59 }; 60 61 } // namespace chromeos 62 63 #endif // CHROME_BROWSER_CHROMEOS_XINPUT_HIERARCHY_CHANGED_EVENT_LISTENER_H_ 64