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