Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: ui/wayland/wayland_input_device.cc

Issue 7457023: Adding a Wayland basic toolkit (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed naming for consts Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #include "ui/wayland/wayland_input_device.h"
6
7 #include <X11/extensions/XKBcommon.h>
8 #include <wayland-client.h>
9
10 #include "ui/wayland/events/wayland_event.h"
11 #include "ui/wayland/wayland_widget.h"
12 #include "ui/wayland/wayland_window.h"
13
14 namespace ui {
15
16 WaylandInputDevice::WaylandInputDevice(wl_display* display,
tfarina 2011/07/25 16:27:13 display in the next line.
17 uint32_t id) : input_device_(wl_input_device_create(display, id, 1)),
tfarina 2011/07/25 16:27:13 the : should be on the next line indented 4 spaces
18 pointer_focus_(NULL),
19 keyboard_focus_(NULL),
20 keyboard_modifiers_(0) {
21
22 // List of callback functions for input device events.
23 static const struct wl_input_device_listener kInputDeviceListener = {
24 WaylandInputDevice::OnMotionNotify,
25 WaylandInputDevice::OnButtonNotify,
26 WaylandInputDevice::OnKeyNotify,
27 WaylandInputDevice::OnPointerFocus,
28 WaylandInputDevice::OnKeyboardFocus,
29 };
30
31 wl_input_device_add_listener(input_device_, &kInputDeviceListener, this);
32 wl_input_device_set_user_data(input_device_, this);
33
34 struct xkb_rule_names names;
35 names.rules = "evdev";
36 names.model = "pc105";
37 names.layout = "us";
38 names.variant = "";
39 names.options = "";
40
41 xkb_ = xkb_compile_keymap_from_rules(&names);
42 }
43
44 WaylandInputDevice::~WaylandInputDevice() {
45 if (input_device_)
46 wl_input_device_destroy(input_device_);
47 }
48
49 void WaylandInputDevice::Attach(wl_buffer* buffer,
50 int32_t x, int32_t y) {
51 wl_input_device_attach(input_device_, last_event_time_, buffer, x, y);
52 }
53
54 void WaylandInputDevice::OnMotionNotify(void* data,
55 wl_input_device *input_device, uint32_t time,
56 int32_t x, int32_t y, int32_t sx, int32_t sy) {
57
58 WaylandInputDevice *device = static_cast<WaylandInputDevice*>(data);
59 WaylandWindow* window = device->pointer_focus_;
60
61 device->last_event_time_ = time;
62 device->global_position_.SetPoint(x, y);
63 device->surface_position_.SetPoint(sx, sy);
64
65 WaylandEvent event;
66 event.type = WAYLAND_MOTION;
67 event.motion.time = time;
68 event.motion.modifiers = device->keyboard_modifiers_;
69 event.motion.x = sx;
70 event.motion.y = sy;
71
72 window->GetWidget()->OnMotionNotify(event);
73 }
74
75 void WaylandInputDevice::OnButtonNotify(void* data,
76 wl_input_device *input_device, uint32_t time,
77 uint32_t button, uint32_t state) {
78
79 WaylandInputDevice *device = static_cast<WaylandInputDevice*>(data);
80 WaylandWindow* window = device->pointer_focus_;
81
82 device->last_event_time_ = time;
83
84 WaylandEvent event;
85 event.type = WAYLAND_BUTTON;
86 event.button.time = time;
87 event.button.button = button;
88 event.button.state = state;
89 event.button.modifiers = device->keyboard_modifiers_;
90 event.button.x = device->surface_position_.x();
91 event.button.y = device->surface_position_.y();
92
93 window->GetWidget()->OnButtonNotify(event);
94 }
95
96 void WaylandInputDevice::OnKeyNotify(void* data,
tfarina 2011/07/25 16:27:13 void* data on the next line. And one arg per line.
97 wl_input_device *input_device, uint32_t time,
98 uint32_t key, uint32_t state) {
99
100 WaylandInputDevice *device = static_cast<WaylandInputDevice*>(data);
101 WaylandWindow* window = device->keyboard_focus_;
102 struct xkb_desc *xkb = device->xkb_;
103
104 device->last_event_time_ = time;
105
106 WaylandEvent event;
107 event.type = WAYLAND_KEY;
108 event.key.time = time;
109 event.key.key = key;
110 event.key.state = state;
111
112 uint32_t code = key + xkb->min_key_code;
113 uint32_t level = 0;
114 if ((device->keyboard_modifiers_ & XKB_COMMON_SHIFT_MASK) &&
115 XkbKeyGroupWidth(xkb, code, 0) > 1) {
116 level = 1;
117 }
118
119 event.key.sym = XkbKeySymEntry(xkb, code, level, 0);
120 if (state)
121 device->keyboard_modifiers_ |= xkb->map->modmap[code];
122 else
123 device->keyboard_modifiers_ &= ~xkb->map->modmap[code];
124
125 event.key.modifiers = device->keyboard_modifiers_;
126
127 window->GetWidget()->OnKeyNotify(event);
128 }
129
130 void WaylandInputDevice::OnPointerFocus(void* data,
131 wl_input_device *input_device, uint32_t time,
132 wl_surface *surface, int32_t x, int32_t y,
133 int32_t sx, int32_t sy) {
134
135 WaylandInputDevice *device = static_cast<WaylandInputDevice*>(data);
136 WaylandWindow* window = device->pointer_focus_;
137
138 device->last_event_time_ = time;
139
140 WaylandEvent event;
141 event.type = WAYLAND_POINTER_FOCUS;
142 event.pointer_focus.time = time;
143 event.pointer_focus.x = sx;
144 event.pointer_focus.y = sy;
145
146 // If we have a window, then this means it loses focus
147 if (window) {
148 event.pointer_focus.state = 0;
149 device->pointer_focus_ = NULL;
150 window->GetWidget()->OnPointerFocus(event);
151 }
152
153 // If we have a surface, then a new window is in focus
154 if (surface) {
155 event.pointer_focus.state = 1;
156 window = static_cast<WaylandWindow*>(wl_surface_get_user_data(surface));
157 device->pointer_focus_ = window;
158 window->GetWidget()->OnPointerFocus(event);
159 }
160 }
161
162 void WaylandInputDevice::OnKeyboardFocus(void* data,
tfarina 2011/07/25 16:27:13 One argument per line is more readable. And also v
163 wl_input_device *input_device, uint32_t time,
164 wl_surface *surface, wl_array *keys) {
165
166 WaylandInputDevice *device = static_cast<WaylandInputDevice*>(data);
167 WaylandWindow* window = device->keyboard_focus_;
168 struct xkb_desc *xkb = device->xkb_;
169
170 device->last_event_time_ = time;
171
172 WaylandEvent event;
173 event.type = WAYLAND_KEYBOARD_FOCUS;
174 event.keyboard_focus.time = time;
175 device->keyboard_modifiers_ = 0;
176
177 uint32_t* codes = static_cast<uint32_t*>(keys->data);
178 int codes_size = keys->size / sizeof(uint32_t);
179 for (int i = 0; i < codes_size; i++) {
180 uint32_t code = codes[i] + xkb->min_key_code;
181 device->keyboard_modifiers_ |= xkb->map->modmap[code];
182 }
183 event.keyboard_focus.modifiers = device->keyboard_modifiers_;
184
185 // If there is a window, then it loses focus
186 if (window) {
187 event.keyboard_focus.state = 0;
188 device->keyboard_focus_ = NULL;
189 window->GetWidget()->OnKeyboardFocus(event);
190 }
191
192 // If we have a surface, then a window gains focus
193 if (surface) {
194 event.keyboard_focus.state = 1;
195 window = static_cast<WaylandWindow*>(wl_surface_get_user_data(surface));
196 device->keyboard_focus_ = window;
197 window->GetWidget()->OnKeyboardFocus(event);
198 }
199 }
200
201 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698