blob: e8e92d6085f5f80aaaa306b20c748424477314c9 [file] [log] [blame]
Kristian Monsen3f50c382011-05-24 16:24:13 +01001// Copyright (c) 2011 The Chromium Authors. All rights reserved.
Ben Murdoch513209b2010-11-18 18:32:45 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_MESSAGE_PUMP_GLIB_X_H
6#define BASE_MESSAGE_PUMP_GLIB_X_H
7
8#include "base/message_pump.h"
9#include "base/message_pump_glib.h"
10
11#include <bitset>
Ben Murdoch4a5e2dc2010-11-25 19:40:10 +000012#include <set>
Ben Murdoch513209b2010-11-18 18:32:45 +000013
14#include <glib.h>
15#include <gtk/gtk.h>
16#include <X11/X.h>
17
18namespace base {
19
20class MessagePumpGlibX : public MessagePumpForUI {
21 public:
22 MessagePumpGlibX();
23 virtual ~MessagePumpGlibX();
24
Ben Murdoch513209b2010-11-18 18:32:45 +000025 // Indicates whether a GDK event was injected by chrome (when |true|) or if it
26 // was captured and being processed by GDK (when |false|).
27 bool IsDispatchingEvent(void) { return dispatching_event_; }
28
Ben Murdoch4a5e2dc2010-11-25 19:40:10 +000029#if defined(HAVE_XINPUT2)
30 // Setup an X Window for XInput2 events.
31 void SetupXInput2ForXWindow(Window xid);
32#endif
33
Kristian Monsen3f50c382011-05-24 16:24:13 +010034 // Overridden from MessagePumpForUI:
35 virtual bool RunOnce(GMainContext* context, bool block);
36
Ben Murdoch513209b2010-11-18 18:32:45 +000037 private:
38 static void EventDispatcherX(GdkEvent* event, gpointer data);
39
40 // Update the lookup table and flag the events that should be captured and
41 // processed so that GDK doesn't get to them.
42 void InitializeEventsToCapture(void);
43
Ben Murdoch4a5e2dc2010-11-25 19:40:10 +000044#if defined(HAVE_XINPUT2)
45 // Initialize X2 input.
46 void InitializeXInput2(void);
47
48 // The opcode used for checking events.
49 int xiopcode_;
50
Kristian Monsenddb351d2011-06-28 21:49:31 +010051 // The list of pointer devices we care about. We maintain this list so that
52 // it is not necessary to query X for the list of devices for each
53 // GdkWindow created.
54 std::set<int> pointer_devices_;
Ben Murdoch4a5e2dc2010-11-25 19:40:10 +000055#endif
56
Ben Murdoch513209b2010-11-18 18:32:45 +000057 // The event source for GDK events.
58 GSource* gdksource_;
59
Kristian Monsen21d179b2011-05-11 20:53:37 +010060 // The default GDK event dispatcher. This is stored so that it can be restored
61 // when necessary during nested event dispatching.
62 gboolean (*gdkdispatcher_)(GSource*, GSourceFunc, void*);
63
Ben Murdoch513209b2010-11-18 18:32:45 +000064 // Indicates whether a GDK event was injected by chrome (when |true|) or if it
65 // was captured and being processed by GDK (when |false|).
66 bool dispatching_event_;
67
68#if ! GTK_CHECK_VERSION(2,18,0)
69// GDK_EVENT_LAST was introduced in GTK+ 2.18.0. For earlier versions, we pick a
70// large enough value (the value of GDK_EVENT_LAST in 2.18.0) so that it works
71// for all versions.
72#define GDK_EVENT_LAST 37
73#endif
74
75 // We do not want to process all the events ourselves. So we use a lookup
76 // table to quickly check if a particular event should be handled by us or if
77 // it should be passed on to the default GDK handler.
78 std::bitset<LASTEvent> capture_x_events_;
79 std::bitset<GDK_EVENT_LAST> capture_gdk_events_;
80
81 DISALLOW_COPY_AND_ASSIGN(MessagePumpGlibX);
82};
83
84} // namespace base
85
86#endif // BASE_MESSAGE_PUMP_GLIB_X_H