OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 <xkbcommon/xkbcommon.h> |
| 11 #include "base/basictypes.h" |
| 12 #include "ui/gfx/point.h" |
| 13 #include "ui/wayland/wayland_delegate.h" |
| 14 |
| 15 #define MOD_SHIFT_MASK 0x01 |
| 16 #define MOD_ALT_MASK 0x02 |
| 17 #define MOD_CONTROL_MASK 0x04 |
| 18 |
| 19 struct wl_array; |
| 20 struct wl_buffer; |
| 21 struct wl_display; |
| 22 struct wl_input_device; |
| 23 struct wl_surface; |
| 24 |
| 25 namespace ui { |
| 26 |
| 27 class WaylandWindow; |
| 28 |
| 29 enum CursorType { |
| 30 CURSOR_BOTTOM_LEFT, |
| 31 CURSOR_BOTTOM_RIGHT, |
| 32 CURSOR_BOTTOM, |
| 33 CURSOR_DRAGGING, |
| 34 CURSOR_LEFT_PTR, |
| 35 CURSOR_LEFT, |
| 36 CURSOR_RIGHT, |
| 37 CURSOR_TOP_LEFT, |
| 38 CURSOR_TOP_RIGHT, |
| 39 CURSOR_TOP, |
| 40 CURSOR_IBEAM, |
| 41 CURSOR_HAND1, |
| 42 }; |
| 43 |
| 44 // Constants to identify the type of resize. |
| 45 enum BoundsChangeType |
| 46 { |
| 47 kBoundsChange_None = 0, |
| 48 kBoundsChange_Repositions, |
| 49 kBoundsChange_Resizes, |
| 50 }; |
| 51 |
| 52 enum WindowLocation { |
| 53 WINDOW_INTERIOR = 0, |
| 54 WINDOW_RESIZING_TOP = 1, |
| 55 WINDOW_RESIZING_BOTTOM = 2, |
| 56 WINDOW_RESIZING_LEFT = 4, |
| 57 WINDOW_RESIZING_TOP_LEFT = 5, |
| 58 WINDOW_RESIZING_BOTTOM_LEFT = 6, |
| 59 WINDOW_RESIZING_RIGHT = 8, |
| 60 WINDOW_RESIZING_TOP_RIGHT = 9, |
| 61 WINDOW_RESIZING_BOTTOM_RIGHT = 10, |
| 62 WINDOW_RESIZING_MASK = 15, |
| 63 WINDOW_EXTERIOR = 16, |
| 64 WINDOW_TITLEBAR = 17, |
| 65 WINDOW_CLIENT_AREA = 18, |
| 66 }; |
| 67 |
| 68 // This class represents an input device that was registered with Wayland. |
| 69 // The purpose of this class is to parse and wrap events into generic |
| 70 // WaylandEvent types and dispatch the event to the appropriate WaylandWindow. |
| 71 // |
| 72 // How Wayland events work: |
| 73 // ------------------------ |
| 74 // |
| 75 // When the On*Focus events are triggered, the input device receives a |
| 76 // reference to the surface that just received/lost focus. Each surface is |
| 77 // associated with a unique WaylandWindow. When processing the focus events we |
| 78 // keep track of the currently focused window such that when we receive |
| 79 // different events (mouse button press or key press) we only send the event to |
| 80 // the window in focus. |
| 81 class WaylandInputDevice { |
| 82 public: |
| 83 WaylandInputDevice(WaylandDisplay* display, uint32_t id); |
| 84 ~WaylandInputDevice(); |
| 85 |
| 86 // Returns a bitmask of the kBoundsChange_ values. |
| 87 static BoundsChangeType GetBoundsChangeForWindowComponent(int component); |
| 88 static WindowLocation GetLocationForWindowComponent(int component); |
| 89 static int GetPointerImageForWindowComponent(int component); |
| 90 |
| 91 void SetCurrentPointerImage(int pointer) { current_pointer_image_ = pointer; } |
| 92 int GetCurrentPointerImage() { return current_pointer_image_; } |
| 93 |
| 94 wl_seat* GetInputSeat() { return input_seat_; } |
| 95 wl_pointer* GetPointer() { return input_pointer_; } |
| 96 |
| 97 private: |
| 98 // Input device callback functions. These will create 'WaylandEvent's and |
| 99 // send them to the currently focused window. |
| 100 // Args: |
| 101 // - data: Pointer to the WaylandInputDevice object associated with the |
| 102 // 'input_device' |
| 103 // - input_device: |
| 104 // The input device that sent the event |
| 105 // - time: The time of the event. |
| 106 static void OnMotionNotify(void* data, |
| 107 wl_pointer* input_pointer, |
| 108 uint32_t time, |
| 109 wl_fixed_t sx_w, |
| 110 wl_fixed_t sy_w); |
| 111 |
| 112 static void OnButtonNotify(void* data, |
| 113 wl_pointer* input_pointer, |
| 114 uint32_t serial, |
| 115 uint32_t time, |
| 116 uint32_t button, |
| 117 uint32_t state); |
| 118 |
| 119 static void OnKeyNotify(void* data, |
| 120 wl_keyboard* input_keyboard, |
| 121 uint32_t serial, |
| 122 uint32_t time, |
| 123 uint32_t key, |
| 124 uint32_t state); |
| 125 |
| 126 static void OnAxisNotify(void* data, |
| 127 wl_pointer* input_pointer, |
| 128 uint32_t time, |
| 129 uint32_t axis, |
| 130 int32_t value); |
| 131 |
| 132 // On*Focus events also have a Wayland surface associated with them. If the |
| 133 // surface is NULL, then the event signifies a loss of focus. Otherwise we |
| 134 // use the surface to get the WaylandWindow that receives focus. |
| 135 static void OnPointerEnter(void* data, |
| 136 wl_pointer* input_pointer, |
| 137 uint32_t serial, |
| 138 wl_surface* surface, |
| 139 wl_fixed_t sx_w, |
| 140 wl_fixed_t sy_w); |
| 141 static void OnPointerLeave(void* data, |
| 142 wl_pointer* input_pointer, |
| 143 uint32_t serial, |
| 144 wl_surface* surface); |
| 145 static void OnKeyboardKeymap(void *data, |
| 146 struct wl_keyboard *keyboard, |
| 147 uint32_t format, int fd, uint32_t size); |
| 148 static void OnKeyboardEnter(void* data, |
| 149 wl_keyboard* input_keyboard, |
| 150 uint32_t serial, |
| 151 wl_surface* surface, |
| 152 wl_array* keys); |
| 153 static void OnKeyboardLeave(void* data, |
| 154 wl_keyboard* input_keyboard, |
| 155 uint32_t serial, |
| 156 wl_surface* surface); |
| 157 static void OnKeyModifiers(void *data, wl_keyboard *keyboard, |
| 158 uint32_t serial, uint32_t mods_depressed, |
| 159 uint32_t mods_latched, uint32_t mods_locked, |
| 160 uint32_t group); |
| 161 |
| 162 static void OnSeatCapabilities(void *data, |
| 163 wl_seat *seat, |
| 164 uint32_t caps); |
| 165 |
| 166 wl_seat* input_seat_; |
| 167 wl_pointer* input_pointer_; |
| 168 wl_keyboard* input_keyboard_; |
| 169 wl_display* display_; |
| 170 wl_registry* registry_; |
| 171 |
| 172 // These keep track of the window that's currently under focus. NULL if no |
| 173 // window is under focus. |
| 174 WaylandWindow* pointer_focus_; |
| 175 WaylandWindow* keyboard_focus_; |
| 176 |
| 177 // Keeps track of the currently active keyboard modifiers. We keep this |
| 178 // since we want to advertise keyboard modifiers with mouse events. |
| 179 uint32_t keyboard_modifiers_; |
| 180 |
| 181 // Keeps track of the last position for the motion event. We want to |
| 182 // publish this with events such as button notify which doesn't have a |
| 183 // position associated by default. |
| 184 gfx::Point global_position_; |
| 185 gfx::Point surface_position_; |
| 186 |
| 187 // Keep track of the time of last event. Useful when we get buffer Attach |
| 188 // calls and the calls wouldn't have a way of getting an event time. |
| 189 uint32_t pointer_enter_serial_; |
| 190 |
| 191 // keymap used to transform keyboard events. |
| 192 struct xkb { |
| 193 struct xkb_rule_names names; |
| 194 struct xkb_keymap *keymap; |
| 195 struct xkb_state *state; |
| 196 struct xkb_context *context; |
| 197 xkb_mod_mask_t control_mask; |
| 198 xkb_mod_mask_t alt_mask; |
| 199 xkb_mod_mask_t shift_mask; |
| 200 }; |
| 201 |
| 202 xkb xkb_; |
| 203 |
| 204 void InitXKB(); |
| 205 void FiniXKB(); |
| 206 |
| 207 int current_pointer_image_; |
| 208 |
| 209 DISALLOW_COPY_AND_ASSIGN(WaylandInputDevice); |
| 210 }; |
| 211 |
| 212 } // namespace ui |
| 213 |
| 214 #endif // UI_WAYLAND_WAYLAND_INPUT_DEVICE_H_ |
OLD | NEW |