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