| 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_AURAX11_H | 5 #ifndef BASE_MESSAGE_PUMP_AURAX11_H |
| 6 #define BASE_MESSAGE_PUMP_AURAX11_H | 6 #define BASE_MESSAGE_PUMP_AURAX11_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 #include <map> |
| 16 #include <vector> |
| 15 | 17 |
| 16 // It would be nice to include the X11 headers here so that we use Window | 18 // It would be nice to include the X11 headers here so that we use Window |
| 17 // instead of its typedef of unsigned long, but we can't because everything in | 19 // instead of its typedef of unsigned long, but we can't because everything in |
| 18 // chrome includes us through base/message_loop.h, and X11's crappy #define | 20 // chrome includes us through base/message_loop.h, and X11's crappy #define |
| 19 // heavy headers muck up half of chrome. | 21 // heavy headers muck up half of chrome. |
| 20 | 22 |
| 21 typedef struct _GPollFD GPollFD; | 23 typedef struct _GPollFD GPollFD; |
| 22 typedef struct _GSource GSource; | 24 typedef struct _GSource GSource; |
| 23 typedef struct _XDisplay Display; | 25 typedef struct _XDisplay Display; |
| 24 | 26 |
| 25 namespace base { | 27 namespace base { |
| 26 | 28 |
| 27 // This class implements a message-pump for dispatching X events. | 29 // This class implements a message-pump for dispatching X events. |
| 28 class BASE_EXPORT MessagePumpAuraX11 : public MessagePumpGlib { | 30 // |
| 31 // If there's a current dispatcher given through RunWithDispatcher(), that |
| 32 // dispatcher receives events. Otherwise, we route to messages to dispatchers |
| 33 // who have subscribed to messages from a specific X11 window. |
| 34 class BASE_EXPORT MessagePumpAuraX11 : public MessagePumpGlib, |
| 35 public MessagePumpDispatcher { |
| 29 public: | 36 public: |
| 30 MessagePumpAuraX11(); | 37 MessagePumpAuraX11(); |
| 31 | 38 |
| 32 // Returns default X Display. | 39 // Returns default X Display. |
| 33 static Display* GetDefaultXDisplay(); | 40 static Display* GetDefaultXDisplay(); |
| 34 | 41 |
| 35 // Returns true if the system supports XINPUT2. | 42 // Returns true if the system supports XINPUT2. |
| 36 static bool HasXInput2(); | 43 static bool HasXInput2(); |
| 37 | 44 |
| 38 // Sets the default dispatcher to process native events. | |
| 39 static void SetDefaultDispatcher(MessagePumpDispatcher* dispatcher); | |
| 40 | |
| 41 // Returns the UI message pump. | 45 // Returns the UI message pump. |
| 42 static MessagePumpAuraX11* Current(); | 46 static MessagePumpAuraX11* Current(); |
| 43 | 47 |
| 48 // Adds/Removes |dispatcher| for the |xid|. This will route all messages from |
| 49 // the window |xid| to |dispatcher. |
| 50 void AddDispatcherForWindow(MessagePumpDispatcher* dispatcher, |
| 51 unsigned long xid); |
| 52 void RemoveDispatcherForWindow(unsigned long xid); |
| 53 |
| 54 // Adds/Removes |dispatcher| to receive all events sent to the X root |
| 55 // window. A root window can have multiple dispatchers, and events on root |
| 56 // windows will be dispatched to all. |
| 57 void AddDispatcherForRootWindow(MessagePumpDispatcher* dispatcher); |
| 58 void RemoveDispatcherForRootWindow(MessagePumpDispatcher* dispatcher); |
| 59 |
| 44 // Internal function. Called by the glib source dispatch function. Processes | 60 // Internal function. Called by the glib source dispatch function. Processes |
| 45 // all available X events. | 61 // all available X events. |
| 46 bool DispatchXEvents(); | 62 bool DispatchXEvents(); |
| 47 | 63 |
| 48 // Blocks on the X11 event queue until we receive notification from the | 64 // Blocks on the X11 event queue until we receive notification from the |
| 49 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are | 65 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are |
| 50 // pulled out from the queue and dispatched out of order. | 66 // pulled out from the queue and dispatched out of order. |
| 51 // | 67 // |
| 52 // For those that know X11, this is really a wrapper around XWindowEvent | 68 // For those that know X11, this is really a wrapper around XWindowEvent |
| 53 // which still makes sure the preempted event is dispatched instead of | 69 // which still makes sure the preempted event is dispatched instead of |
| 54 // dropped on the floor. This method exists because mapping a window is | 70 // dropped on the floor. This method exists because mapping a window is |
| 55 // asynchronous (and we receive an XEvent when mapped), while there are also | 71 // asynchronous (and we receive an XEvent when mapped), while there are also |
| 56 // functions which require a mapped window. | 72 // functions which require a mapped window. |
| 57 void BlockUntilWindowMapped(unsigned long window); | 73 void BlockUntilWindowMapped(unsigned long xid); |
| 58 | 74 |
| 59 protected: | 75 protected: |
| 60 virtual ~MessagePumpAuraX11(); | 76 virtual ~MessagePumpAuraX11(); |
| 61 | 77 |
| 62 private: | 78 private: |
| 79 typedef std::map<unsigned long, MessagePumpDispatcher*> DispatchersMap; |
| 80 typedef std::vector<MessagePumpDispatcher*> Dispatchers; |
| 81 |
| 63 // Initializes the glib event source for X. | 82 // Initializes the glib event source for X. |
| 64 void InitXSource(); | 83 void InitXSource(); |
| 65 | 84 |
| 66 // Dispatches the XEvent and returns true if we should exit the current loop | 85 // Dispatches the XEvent and returns true if we should exit the current loop |
| 67 // of message processing. | 86 // of message processing. |
| 68 bool ProcessXEvent(MessagePumpDispatcher* dispatcher, XEvent* event); | 87 bool ProcessXEvent(MessagePumpDispatcher* dispatcher, XEvent* event); |
| 69 | 88 |
| 70 // Sends the event to the observers. If an observer returns true, then it does | 89 // Sends the event to the observers. If an observer returns true, then it does |
| 71 // not send the event to any other observers and returns true. Returns false | 90 // not send the event to any other observers and returns true. Returns false |
| 72 // if no observer returns true. | 91 // if no observer returns true. |
| 73 bool WillProcessXEvent(XEvent* xevent); | 92 bool WillProcessXEvent(XEvent* xevent); |
| 74 void DidProcessXEvent(XEvent* xevent); | 93 void DidProcessXEvent(XEvent* xevent); |
| 75 | 94 |
| 95 // Returns the Dispatcher based on the event's target window. |
| 96 MessagePumpDispatcher* GetDispatcherForXEvent( |
| 97 const base::NativeEvent& xev) const; |
| 98 |
| 99 // Overridden from MessagePumpDispatcher: |
| 100 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; |
| 101 |
| 76 // The event source for X events. | 102 // The event source for X events. |
| 77 GSource* x_source_; | 103 GSource* x_source_; |
| 78 | 104 |
| 79 // The poll attached to |x_source_|. | 105 // The poll attached to |x_source_|. |
| 80 scoped_ptr<GPollFD> x_poll_; | 106 scoped_ptr<GPollFD> x_poll_; |
| 81 | 107 |
| 108 DispatchersMap dispatchers_; |
| 109 Dispatchers root_window_dispatchers_; |
| 110 |
| 111 unsigned long x_root_window_; |
| 112 |
| 82 DISALLOW_COPY_AND_ASSIGN(MessagePumpAuraX11); | 113 DISALLOW_COPY_AND_ASSIGN(MessagePumpAuraX11); |
| 83 }; | 114 }; |
| 84 | 115 |
| 85 typedef MessagePumpAuraX11 MessagePumpForUI; | 116 typedef MessagePumpAuraX11 MessagePumpForUI; |
| 86 | 117 |
| 87 } // namespace base | 118 } // namespace base |
| 88 | 119 |
| 89 #endif // BASE_MESSAGE_PUMP_AURAX11_H | 120 #endif // BASE_MESSAGE_PUMP_AURAX11_H |
| OLD | NEW |