OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef UI_WAYLAND_WAYLAND_INPUT_DEVICE_H_ | |
6 #define UI_WAYLAND_WAYLAND_INPUT_DEVICE_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "ui/gfx/point.h" | |
12 #include "ui/wayland/wayland_widget.h" | |
13 | |
14 struct xkb_desc; | |
15 struct wl_array; | |
16 struct wl_buffer; | |
17 struct wl_display; | |
18 struct wl_input_device; | |
19 struct wl_surface; | |
20 | |
21 namespace ui { | |
22 | |
23 class WaylandWindow; | |
24 | |
25 // This class represents an input device that was registered with Wayland. | |
26 // The purpose of this class is to parse and wrap events into generic | |
27 // WaylandEvent types and dispatch the event to the appropriate WaylandWindow. | |
28 // | |
29 // How Wayland events work: | |
30 // ------------------------ | |
31 // | |
32 // When the On*Focus events are triggered, the input device receives a | |
33 // reference to the surface that just received/lost focus. Each surface is | |
34 // associated with a unique WaylandWindow. When processing the focus events we | |
35 // keep track of the currently focused window such that when we receive | |
36 // different events (mouse button press or key press) we only send the event to | |
37 // the window in focus. | |
38 class WaylandInputDevice { | |
39 public: | |
40 WaylandInputDevice(wl_display* display, uint32_t id); | |
41 ~WaylandInputDevice(); | |
42 | |
43 // Used to change the surface of the input device (normally pointer image). | |
44 void Attach(wl_buffer* buffer, int32_t x, int32_t y); | |
45 | |
46 private: | |
47 // Input device callback functions. These will create 'WaylandEvent's and | |
48 // send them to the currently focused window. | |
49 // Args: | |
50 // - data: Pointer to the WaylandInputDevice object associated with the | |
51 // 'input_device' | |
52 // - input_device: | |
53 // The input device that sent the event | |
54 // - time: The time of the event. | |
55 static void OnMotionNotify(void* data, | |
56 wl_input_device* input_device, | |
57 uint32_t time, | |
58 int32_t x, | |
59 int32_t y, | |
60 int32_t sx, | |
61 int32_t sy); | |
62 | |
63 static void OnButtonNotify(void* data, | |
64 wl_input_device* input_device, | |
65 uint32_t time, | |
66 uint32_t button, | |
67 uint32_t state); | |
68 | |
69 static void OnKeyNotify(void* data, | |
70 wl_input_device* input_device, | |
71 uint32_t time, | |
72 uint32_t key, | |
73 uint32_t state); | |
74 | |
75 // On*Focus events also have a Wayland surface associated with them. If the | |
76 // surface is NULL, then the event signifies a loss of focus. Otherwise we | |
77 // use the surface to get the WaylandWindow that receives focus. | |
78 static void OnPointerFocus(void* data, | |
79 wl_input_device* input_device, | |
80 uint32_t time, | |
81 wl_surface* surface, | |
82 int32_t x, | |
83 int32_t y, | |
84 int32_t sx, | |
85 int32_t sy); | |
86 | |
87 static void OnKeyboardFocus(void* data, | |
88 wl_input_device* input_device, | |
89 uint32_t time, | |
90 wl_surface* surface, | |
91 wl_array* keys); | |
92 | |
93 wl_input_device* input_device_; | |
94 | |
95 // These keep track of the window that's currently under focus. NULL if no | |
96 // window is under focus. | |
97 WaylandWindow* pointer_focus_; | |
98 WaylandWindow* keyboard_focus_; | |
99 | |
100 // Keeps track of the currently active keyboard modifiers. We keep this | |
101 // since we want to advertise keyboard modifiers with mouse events. | |
102 uint32_t keyboard_modifiers_; | |
103 | |
104 // Keeps track of the last position for the motion event. We want to | |
105 // publish this with events such as button notify which doesn't have a | |
106 // position associated by default. | |
107 gfx::Point global_position_; | |
108 gfx::Point surface_position_; | |
109 | |
110 // Keep track of the time of last event. Useful when we get buffer Attach | |
111 // calls and the calls wouldn't have a way of getting an event time. | |
112 uint32_t last_event_time_; | |
113 | |
114 // keymap used to transform keyboard events. | |
115 xkb_desc* xkb_; | |
116 | |
117 DISALLOW_COPY_AND_ASSIGN(WaylandInputDevice); | |
118 }; | |
119 | |
120 } // namespace ui | |
121 | |
122 #endif // UI_WAYLAND_WAYLAND_INPUT_DEVICE_H_ | |
OLD | NEW |