OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_MESSAGE_PUMP_X_H | 5 #ifndef BASE_MESSAGE_PUMP_X_H |
6 #define BASE_MESSAGE_PUMP_X_H | 6 #define BASE_MESSAGE_PUMP_X_H |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_pump.h" | 9 #include "base/message_pump.h" |
10 #include "base/message_pump_glib.h" | 10 #include "base/message_pump_glib.h" |
11 #include "base/message_pump_dispatcher.h" | 11 #include "base/message_pump_dispatcher.h" |
12 #include "base/message_pump_observer.h" | 12 #include "base/message_pump_observer.h" |
13 | 13 |
14 #include <bitset> | 14 #include <bitset> |
15 | 15 |
16 #include <glib.h> | 16 #include <glib.h> |
17 | 17 |
18 typedef struct _XDisplay Display; | 18 typedef struct _XDisplay Display; |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 | 21 |
22 // This class implements a message-pump for dispatching X events. | 22 // This class implements a message-pump for dispatching X events. |
23 class BASE_EXPORT MessagePumpX : public MessagePumpGlib { | 23 class BASE_EXPORT MessagePumpX : public MessagePumpGlib { |
24 public: | 24 public: |
25 MessagePumpX(); | 25 MessagePumpX(); |
26 virtual ~MessagePumpX(); | |
27 | 26 |
28 // Returns default X Display. | 27 // Returns default X Display. |
29 static Display* GetDefaultXDisplay(); | 28 static Display* GetDefaultXDisplay(); |
30 | 29 |
31 // Returns true if the system supports XINPUT2. | 30 // Returns true if the system supports XINPUT2. |
32 static bool HasXInput2(); | 31 static bool HasXInput2(); |
33 | 32 |
34 // Sets the default dispatcher to process native events. | 33 // Sets the default dispatcher to process native events. |
35 static void SetDefaultDispatcher(MessagePumpDispatcher* dispatcher); | 34 static void SetDefaultDispatcher(MessagePumpDispatcher* dispatcher); |
36 | 35 |
37 // Internal function. Called by the glib source dispatch function. Processes | 36 // Internal function. Called by the glib source dispatch function. Processes |
38 // all available X events. | 37 // all available X events. |
39 gboolean DispatchXEvents(); | 38 gboolean DispatchXEvents(); |
40 | 39 |
| 40 protected: |
| 41 virtual ~MessagePumpX(); |
| 42 |
41 private: | 43 private: |
42 // Initializes the glib event source for X. | 44 // Initializes the glib event source for X. |
43 void InitXSource(); | 45 void InitXSource(); |
44 | 46 |
45 // Dispatches the XEvent and returns true if we should exit the current loop | 47 // Dispatches the XEvent and returns true if we should exit the current loop |
46 // of message processing. | 48 // of message processing. |
47 bool ProcessXEvent(MessagePumpDispatcher* dispatcher, XEvent* event); | 49 bool ProcessXEvent(MessagePumpDispatcher* dispatcher, XEvent* event); |
48 | 50 |
49 // Sends the event to the observers. If an observer returns true, then it does | 51 // Sends the event to the observers. If an observer returns true, then it does |
50 // not send the event to any other observers and returns true. Returns false | 52 // not send the event to any other observers and returns true. Returns false |
51 // if no observer returns true. | 53 // if no observer returns true. |
52 bool WillProcessXEvent(XEvent* xevent); | 54 bool WillProcessXEvent(XEvent* xevent); |
53 void DidProcessXEvent(XEvent* xevent); | 55 void DidProcessXEvent(XEvent* xevent); |
54 | 56 |
55 // The event source for X events. | 57 // The event source for X events. |
56 GSource* x_source_; | 58 GSource* x_source_; |
57 | 59 |
58 // The poll attached to |x_source_|. | 60 // The poll attached to |x_source_|. |
59 scoped_ptr<GPollFD> x_poll_; | 61 scoped_ptr<GPollFD> x_poll_; |
60 | 62 |
61 DISALLOW_COPY_AND_ASSIGN(MessagePumpX); | 63 DISALLOW_COPY_AND_ASSIGN(MessagePumpX); |
62 }; | 64 }; |
63 | 65 |
64 typedef MessagePumpX MessagePumpForUI; | 66 typedef MessagePumpX MessagePumpForUI; |
65 | 67 |
66 } // namespace base | 68 } // namespace base |
67 | 69 |
68 #endif // BASE_MESSAGE_PUMP_X_H | 70 #endif // BASE_MESSAGE_PUMP_X_H |
OLD | NEW |