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.
5 #ifndef CHROME_BROWSER_CHROMEOS_XINPUT_HIERARCHY_CHANGED_EVENT_LISTENER_H_
6 #define CHROME_BROWSER_CHROMEOS_XINPUT_HIERARCHY_CHANGED_EVENT_LISTENER_H_
9 #if defined(TOOLKIT_USES_GTK)
13 #include "base/memory/singleton.h"
14 #include "base/message_loop.h"
15 #include "base/observer_list.h"
16 #include "chrome/browser/chromeos/device_hierarchy_observer.h"
18 typedef union _XEvent XEvent
;
22 // XInputHierarchyChangedEventListener listens for an XI_HierarchyChanged event,
23 // which is sent to Chrome when X detects a system or USB keyboard (or mouse),
24 // then tells X to change the current XKB keyboard layout. Start by just calling
25 // instance() to get it going.
26 class XInputHierarchyChangedEventListener
: public MessageLoopForUI::Observer
{
28 static XInputHierarchyChangedEventListener
* GetInstance();
32 void AddObserver(DeviceHierarchyObserver
* observer
);
33 void RemoveObserver(DeviceHierarchyObserver
* observer
);
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
<XInputHierarchyChangedEventListener
>;
40 XInputHierarchyChangedEventListener();
41 virtual ~XInputHierarchyChangedEventListener();
46 #if defined(TOOLKIT_USES_GTK)
47 // When GTK events are processed, WillProcessXEvent() is not called
48 // automatically. It is necessary to call the function manually by adding the
50 static GdkFilterReturn
GdkEventFilter(GdkXEvent
* gxevent
,
54 // MessageLoopForUI::Observer overrides.
55 virtual void WillProcessEvent(GdkEvent
* event
) OVERRIDE
{}
56 virtual void DidProcessEvent(GdkEvent
* event
) OVERRIDE
{}
58 // MessageLoopForUI::Observer overrides.
59 virtual base::EventStatus
WillProcessEvent(
60 const base::NativeEvent
& event
) OVERRIDE
;
61 virtual void DidProcessEvent(const base::NativeEvent
& event
) OVERRIDE
;
64 // Returns true if the event was processed, false otherwise.
65 virtual bool ProcessedXEvent(XEvent
* xevent
);
67 // Notify observers that a device has been added/removed.
68 void NotifyDeviceHierarchyChanged();
73 ObserverList
<DeviceHierarchyObserver
> observer_list_
;
75 DISALLOW_COPY_AND_ASSIGN(XInputHierarchyChangedEventListener
);
78 } // namespace chromeos
80 #endif // CHROME_BROWSER_CHROMEOS_XINPUT_HIERARCHY_CHANGED_EVENT_LISTENER_H_