blob: 5fa266d3f84d40683b0333e36048c715be4e4d28 [file] [log] [blame]
Kristian Høgsberg2158a882013-04-18 15:07:39 -04001/*
2 * Copyright © 2013 Intel Corporation
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#include <stdlib.h>
24#include <stdint.h>
25#include <string.h>
Kristian Høgsbergb5e26102013-04-18 15:40:10 -040026#include <sys/mman.h>
27#include <assert.h>
28#include <unistd.h>
Kristian Høgsberg2158a882013-04-18 15:07:39 -040029
Kristian Høgsbergb5e26102013-04-18 15:40:10 -040030#include "../shared/os-compatibility.h"
Kristian Høgsberg2158a882013-04-18 15:07:39 -040031#include "compositor.h"
32
Kristian Høgsbergb5e26102013-04-18 15:40:10 -040033static void
34empty_region(pixman_region32_t *region)
35{
36 pixman_region32_fini(region);
37 pixman_region32_init(region);
38}
39
40static void unbind_resource(struct wl_resource *resource)
41{
42 wl_list_remove(&resource->link);
43 free(resource);
44}
45
46void
Kristian Høgsberga71e8b22013-05-06 21:51:21 -040047weston_seat_repick(struct weston_seat *seat)
Kristian Høgsbergb5e26102013-04-18 15:40:10 -040048{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -040049 const struct weston_pointer_grab_interface *interface;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -040050 struct weston_surface *surface, *focus;
Kristian Høgsberge3148752013-05-06 23:19:49 -040051 struct weston_pointer *pointer = seat->pointer;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -040052
53 if (!pointer)
54 return;
55
56 surface = weston_compositor_pick_surface(seat->compositor,
57 pointer->x,
58 pointer->y,
59 &pointer->current_x,
60 &pointer->current_y);
61
62 if (&surface->surface != pointer->current) {
63 interface = pointer->grab->interface;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -040064 weston_pointer_set_current(pointer, &surface->surface);
Kristian Høgsbergb5e26102013-04-18 15:40:10 -040065 interface->focus(pointer->grab, &surface->surface,
66 pointer->current_x,
67 pointer->current_y);
68 }
69
70 focus = (struct weston_surface *) pointer->grab->focus;
71 if (focus)
72 weston_surface_from_global_fixed(focus,
73 pointer->x,
74 pointer->y,
75 &pointer->grab->x,
76 &pointer->grab->y);
77}
78
79static void
80weston_compositor_idle_inhibit(struct weston_compositor *compositor)
81{
82 weston_compositor_wake(compositor);
83 compositor->idle_inhibit++;
84}
85
86static void
87weston_compositor_idle_release(struct weston_compositor *compositor)
88{
89 compositor->idle_inhibit--;
90 weston_compositor_wake(compositor);
91}
92
Kristian Høgsberg2158a882013-04-18 15:07:39 -040093static void
94lose_pointer_focus(struct wl_listener *listener, void *data)
95{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -040096 struct weston_pointer *pointer =
97 container_of(listener, struct weston_pointer, focus_listener);
Kristian Høgsberg2158a882013-04-18 15:07:39 -040098
99 pointer->focus_resource = NULL;
100}
101
102static void
103lose_keyboard_focus(struct wl_listener *listener, void *data)
104{
Kristian Høgsberg29139d42013-04-18 15:25:39 -0400105 struct weston_keyboard *keyboard =
106 container_of(listener, struct weston_keyboard, focus_listener);
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400107
108 keyboard->focus_resource = NULL;
109}
110
111static void
112lose_touch_focus(struct wl_listener *listener, void *data)
113{
Kristian Høgsberge329f362013-05-06 22:19:57 -0400114 struct weston_touch *touch =
115 container_of(listener, struct weston_touch, focus_listener);
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400116
117 touch->focus_resource = NULL;
118}
119
120static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400121default_grab_focus(struct weston_pointer_grab *grab,
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400122 struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
123{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400124 struct weston_pointer *pointer = grab->pointer;
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400125
126 if (pointer->button_count > 0)
127 return;
128
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400129 weston_pointer_set_focus(pointer, surface, x, y);
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400130}
131
132static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400133default_grab_motion(struct weston_pointer_grab *grab,
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400134 uint32_t time, wl_fixed_t x, wl_fixed_t y)
135{
136 struct wl_resource *resource;
137
138 resource = grab->pointer->focus_resource;
139 if (resource)
140 wl_pointer_send_motion(resource, time, x, y);
141}
142
143static void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400144default_grab_button(struct weston_pointer_grab *grab,
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400145 uint32_t time, uint32_t button, uint32_t state_w)
146{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400147 struct weston_pointer *pointer = grab->pointer;
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400148 struct wl_resource *resource;
149 uint32_t serial;
150 enum wl_pointer_button_state state = state_w;
151 struct wl_display *display;
152
153 resource = pointer->focus_resource;
154 if (resource) {
155 display = wl_client_get_display(resource->client);
156 serial = wl_display_next_serial(display);
157 wl_pointer_send_button(resource, serial, time, button, state_w);
158 }
159
160 if (pointer->button_count == 0 &&
161 state == WL_POINTER_BUTTON_STATE_RELEASED)
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400162 weston_pointer_set_focus(pointer, pointer->current,
163 pointer->current_x,
164 pointer->current_y);
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400165}
166
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400167static const struct weston_pointer_grab_interface
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400168 default_pointer_grab_interface = {
169 default_grab_focus,
170 default_grab_motion,
171 default_grab_button
172};
173
Kristian Høgsberge329f362013-05-06 22:19:57 -0400174static void
175default_grab_touch_down(struct weston_touch_grab *grab, uint32_t time,
176 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400177{
Kristian Høgsberge329f362013-05-06 22:19:57 -0400178 struct weston_touch *touch = grab->touch;
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400179 struct wl_display *display;
180 uint32_t serial;
181
182 if (touch->focus_resource && touch->focus) {
183 display = wl_client_get_display(touch->focus_resource->client);
184 serial = wl_display_next_serial(display);
185 wl_touch_send_down(touch->focus_resource, serial, time,
Kristian Høgsberge329f362013-05-06 22:19:57 -0400186 &touch->focus->resource,
187 touch_id, sx, sy);
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400188 }
189}
190
Kristian Høgsberge329f362013-05-06 22:19:57 -0400191static void
192default_grab_touch_up(struct weston_touch_grab *grab,
193 uint32_t time, int touch_id)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400194{
Kristian Høgsberge329f362013-05-06 22:19:57 -0400195 struct weston_touch *touch = grab->touch;
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400196 struct wl_display *display;
197 uint32_t serial;
198
199 if (touch->focus_resource) {
200 display = wl_client_get_display(touch->focus_resource->client);
201 serial = wl_display_next_serial(display);
202 wl_touch_send_up(touch->focus_resource, serial, time, touch_id);
203 }
204}
205
Kristian Høgsberge329f362013-05-06 22:19:57 -0400206static void
207default_grab_touch_motion(struct weston_touch_grab *grab, uint32_t time,
208 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400209{
Kristian Høgsberge329f362013-05-06 22:19:57 -0400210 struct weston_touch *touch = grab->touch;
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400211
212 if (touch->focus_resource) {
213 wl_touch_send_motion(touch->focus_resource, time,
Kristian Høgsberge329f362013-05-06 22:19:57 -0400214 touch_id, sx, sy);
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400215 }
216}
217
Kristian Høgsberge329f362013-05-06 22:19:57 -0400218static const struct weston_touch_grab_interface default_touch_grab_interface = {
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400219 default_grab_touch_down,
220 default_grab_touch_up,
221 default_grab_touch_motion
222};
223
224static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -0400225default_grab_key(struct weston_keyboard_grab *grab,
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400226 uint32_t time, uint32_t key, uint32_t state)
227{
Kristian Høgsberg29139d42013-04-18 15:25:39 -0400228 struct weston_keyboard *keyboard = grab->keyboard;
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400229 struct wl_resource *resource;
230 struct wl_display *display;
231 uint32_t serial;
232
233 resource = keyboard->focus_resource;
234 if (resource) {
235 display = wl_client_get_display(resource->client);
236 serial = wl_display_next_serial(display);
237 wl_keyboard_send_key(resource, serial, time, key, state);
238 }
239}
240
241static struct wl_resource *
242find_resource_for_surface(struct wl_list *list, struct wl_surface *surface)
243{
244 struct wl_resource *r;
245
246 if (!surface)
247 return NULL;
248
249 wl_list_for_each(r, list, link) {
250 if (r->client == surface->resource.client)
251 return r;
252 }
253
254 return NULL;
255}
256
257static void
Kristian Høgsberg29139d42013-04-18 15:25:39 -0400258default_grab_modifiers(struct weston_keyboard_grab *grab, uint32_t serial,
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400259 uint32_t mods_depressed, uint32_t mods_latched,
260 uint32_t mods_locked, uint32_t group)
261{
Kristian Høgsberg29139d42013-04-18 15:25:39 -0400262 struct weston_keyboard *keyboard = grab->keyboard;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400263 struct weston_pointer *pointer = keyboard->seat->pointer;
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400264 struct wl_resource *resource, *pr;
265
266 resource = keyboard->focus_resource;
267 if (!resource)
268 return;
269
270 wl_keyboard_send_modifiers(resource, serial, mods_depressed,
271 mods_latched, mods_locked, group);
272
273 if (pointer && pointer->focus && pointer->focus != keyboard->focus) {
274 pr = find_resource_for_surface(&keyboard->resource_list,
275 pointer->focus);
276 if (pr) {
277 wl_keyboard_send_modifiers(pr,
278 serial,
279 keyboard->modifiers.mods_depressed,
280 keyboard->modifiers.mods_latched,
281 keyboard->modifiers.mods_locked,
282 keyboard->modifiers.group);
283 }
284 }
285}
286
Kristian Høgsberg29139d42013-04-18 15:25:39 -0400287static const struct weston_keyboard_grab_interface
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400288 default_keyboard_grab_interface = {
289 default_grab_key,
290 default_grab_modifiers,
291};
292
293WL_EXPORT void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400294weston_pointer_init(struct weston_pointer *pointer)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400295{
296 memset(pointer, 0, sizeof *pointer);
297 wl_list_init(&pointer->resource_list);
298 pointer->focus_listener.notify = lose_pointer_focus;
299 pointer->default_grab.interface = &default_pointer_grab_interface;
300 pointer->default_grab.pointer = pointer;
301 pointer->grab = &pointer->default_grab;
302 wl_signal_init(&pointer->focus_signal);
303
304 /* FIXME: Pick better co-ords. */
305 pointer->x = wl_fixed_from_int(100);
306 pointer->y = wl_fixed_from_int(100);
307}
308
309WL_EXPORT void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400310weston_pointer_release(struct weston_pointer *pointer)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400311{
312 /* XXX: What about pointer->resource_list? */
313 if (pointer->focus_resource)
314 wl_list_remove(&pointer->focus_listener.link);
315}
316
317WL_EXPORT void
Kristian Høgsberg29139d42013-04-18 15:25:39 -0400318weston_keyboard_init(struct weston_keyboard *keyboard)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400319{
320 memset(keyboard, 0, sizeof *keyboard);
321 wl_list_init(&keyboard->resource_list);
322 wl_array_init(&keyboard->keys);
323 keyboard->focus_listener.notify = lose_keyboard_focus;
324 keyboard->default_grab.interface = &default_keyboard_grab_interface;
325 keyboard->default_grab.keyboard = keyboard;
326 keyboard->grab = &keyboard->default_grab;
327 wl_signal_init(&keyboard->focus_signal);
328}
329
330WL_EXPORT void
Kristian Høgsberg29139d42013-04-18 15:25:39 -0400331weston_keyboard_release(struct weston_keyboard *keyboard)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400332{
333 /* XXX: What about keyboard->resource_list? */
334 if (keyboard->focus_resource)
335 wl_list_remove(&keyboard->focus_listener.link);
336 wl_array_release(&keyboard->keys);
337}
338
339WL_EXPORT void
Kristian Høgsberge329f362013-05-06 22:19:57 -0400340weston_touch_init(struct weston_touch *touch)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400341{
342 memset(touch, 0, sizeof *touch);
343 wl_list_init(&touch->resource_list);
344 touch->focus_listener.notify = lose_touch_focus;
345 touch->default_grab.interface = &default_touch_grab_interface;
346 touch->default_grab.touch = touch;
347 touch->grab = &touch->default_grab;
348 wl_signal_init(&touch->focus_signal);
349}
350
351WL_EXPORT void
Kristian Høgsberge329f362013-05-06 22:19:57 -0400352weston_touch_release(struct weston_touch *touch)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400353{
354 /* XXX: What about touch->resource_list? */
355 if (touch->focus_resource)
356 wl_list_remove(&touch->focus_listener.link);
357}
358
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400359static void
Kristian Høgsberge3148752013-05-06 23:19:49 -0400360seat_send_updated_caps(struct weston_seat *seat)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400361{
362 struct wl_resource *r;
363 enum wl_seat_capability caps = 0;
364
365 if (seat->pointer)
366 caps |= WL_SEAT_CAPABILITY_POINTER;
367 if (seat->keyboard)
368 caps |= WL_SEAT_CAPABILITY_KEYBOARD;
369 if (seat->touch)
370 caps |= WL_SEAT_CAPABILITY_TOUCH;
371
372 wl_list_for_each(r, &seat->base_resource_list, link)
373 wl_seat_send_capabilities(r, caps);
374}
375
376WL_EXPORT void
Kristian Høgsberge3148752013-05-06 23:19:49 -0400377weston_seat_set_pointer(struct weston_seat *seat,
378 struct weston_pointer *pointer)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400379{
380 if (pointer && (seat->pointer || pointer->seat))
381 return; /* XXX: error? */
382 if (!pointer && !seat->pointer)
383 return;
384
385 seat->pointer = pointer;
386 if (pointer)
387 pointer->seat = seat;
388
389 seat_send_updated_caps(seat);
390}
391
392WL_EXPORT void
Kristian Høgsberge3148752013-05-06 23:19:49 -0400393weston_seat_set_keyboard(struct weston_seat *seat,
394 struct weston_keyboard *keyboard)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400395{
396 if (keyboard && (seat->keyboard || keyboard->seat))
397 return; /* XXX: error? */
398 if (!keyboard && !seat->keyboard)
399 return;
400
401 seat->keyboard = keyboard;
402 if (keyboard)
403 keyboard->seat = seat;
404
405 seat_send_updated_caps(seat);
406}
407
408WL_EXPORT void
Kristian Høgsberge3148752013-05-06 23:19:49 -0400409weston_seat_set_touch(struct weston_seat *seat, struct weston_touch *touch)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400410{
411 if (touch && (seat->touch || touch->seat))
412 return; /* XXX: error? */
413 if (!touch && !seat->touch)
414 return;
415
416 seat->touch = touch;
417 if (touch)
418 touch->seat = seat;
419
420 seat_send_updated_caps(seat);
421}
422
423WL_EXPORT void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400424weston_pointer_set_focus(struct weston_pointer *pointer,
425 struct wl_surface *surface,
426 wl_fixed_t sx, wl_fixed_t sy)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400427{
Kristian Høgsberg29139d42013-04-18 15:25:39 -0400428 struct weston_keyboard *kbd = pointer->seat->keyboard;
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400429 struct wl_resource *resource, *kr;
430 struct wl_display *display;
431 uint32_t serial;
432
433 resource = pointer->focus_resource;
434 if (resource && pointer->focus != surface) {
435 display = wl_client_get_display(resource->client);
436 serial = wl_display_next_serial(display);
437 wl_pointer_send_leave(resource, serial,
438 &pointer->focus->resource);
439 wl_list_remove(&pointer->focus_listener.link);
440 }
441
442 resource = find_resource_for_surface(&pointer->resource_list,
443 surface);
444 if (resource &&
445 (pointer->focus != surface ||
446 pointer->focus_resource != resource)) {
447 display = wl_client_get_display(resource->client);
448 serial = wl_display_next_serial(display);
449 if (kbd) {
450 kr = find_resource_for_surface(&kbd->resource_list,
451 surface);
452 if (kr) {
453 wl_keyboard_send_modifiers(kr,
454 serial,
455 kbd->modifiers.mods_depressed,
456 kbd->modifiers.mods_latched,
457 kbd->modifiers.mods_locked,
458 kbd->modifiers.group);
459 }
460 }
461 wl_pointer_send_enter(resource, serial, &surface->resource,
462 sx, sy);
463 wl_signal_add(&resource->destroy_signal,
464 &pointer->focus_listener);
465 pointer->focus_serial = serial;
466 }
467
468 pointer->focus_resource = resource;
469 pointer->focus = surface;
470 pointer->default_grab.focus = surface;
471 wl_signal_emit(&pointer->focus_signal, pointer);
472}
473
474WL_EXPORT void
Kristian Høgsberg29139d42013-04-18 15:25:39 -0400475weston_keyboard_set_focus(struct weston_keyboard *keyboard,
476 struct wl_surface *surface)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400477{
478 struct wl_resource *resource;
479 struct wl_display *display;
480 uint32_t serial;
481
482 if (keyboard->focus_resource && keyboard->focus != surface) {
483 resource = keyboard->focus_resource;
484 display = wl_client_get_display(resource->client);
485 serial = wl_display_next_serial(display);
486 wl_keyboard_send_leave(resource, serial,
487 &keyboard->focus->resource);
488 wl_list_remove(&keyboard->focus_listener.link);
489 }
490
491 resource = find_resource_for_surface(&keyboard->resource_list,
492 surface);
493 if (resource &&
494 (keyboard->focus != surface ||
495 keyboard->focus_resource != resource)) {
496 display = wl_client_get_display(resource->client);
497 serial = wl_display_next_serial(display);
498 wl_keyboard_send_modifiers(resource, serial,
499 keyboard->modifiers.mods_depressed,
500 keyboard->modifiers.mods_latched,
501 keyboard->modifiers.mods_locked,
502 keyboard->modifiers.group);
503 wl_keyboard_send_enter(resource, serial, &surface->resource,
504 &keyboard->keys);
505 wl_signal_add(&resource->destroy_signal,
506 &keyboard->focus_listener);
507 keyboard->focus_serial = serial;
508 }
509
510 keyboard->focus_resource = resource;
511 keyboard->focus = surface;
512 wl_signal_emit(&keyboard->focus_signal, keyboard);
513}
514
515WL_EXPORT void
Kristian Høgsberg29139d42013-04-18 15:25:39 -0400516weston_keyboard_start_grab(struct weston_keyboard *keyboard,
517 struct weston_keyboard_grab *grab)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400518{
519 keyboard->grab = grab;
520 grab->keyboard = keyboard;
521
522 /* XXX focus? */
523}
524
525WL_EXPORT void
Kristian Høgsberg29139d42013-04-18 15:25:39 -0400526weston_keyboard_end_grab(struct weston_keyboard *keyboard)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400527{
528 keyboard->grab = &keyboard->default_grab;
529}
530
531WL_EXPORT void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400532weston_pointer_start_grab(struct weston_pointer *pointer,
533 struct weston_pointer_grab *grab)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400534{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400535 const struct weston_pointer_grab_interface *interface;
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400536
537 pointer->grab = grab;
538 interface = pointer->grab->interface;
539 grab->pointer = pointer;
540
541 if (pointer->current)
542 interface->focus(pointer->grab, pointer->current,
543 pointer->current_x, pointer->current_y);
544}
545
546WL_EXPORT void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400547weston_pointer_end_grab(struct weston_pointer *pointer)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400548{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400549 const struct weston_pointer_grab_interface *interface;
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400550
551 pointer->grab = &pointer->default_grab;
552 interface = pointer->grab->interface;
553 interface->focus(pointer->grab, pointer->current,
554 pointer->current_x, pointer->current_y);
555}
556
557static void
558current_surface_destroy(struct wl_listener *listener, void *data)
559{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400560 struct weston_pointer *pointer =
561 container_of(listener, struct weston_pointer, current_listener);
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400562
563 pointer->current = NULL;
564}
565
566WL_EXPORT void
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400567weston_pointer_set_current(struct weston_pointer *pointer,
568 struct wl_surface *surface)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400569{
570 if (pointer->current)
571 wl_list_remove(&pointer->current_listener.link);
572
573 pointer->current = surface;
574
575 if (!surface)
576 return;
577
578 wl_signal_add(&surface->resource.destroy_signal,
579 &pointer->current_listener);
580 pointer->current_listener.notify = current_surface_destroy;
581}
582
583WL_EXPORT void
Kristian Høgsberge329f362013-05-06 22:19:57 -0400584weston_touch_start_grab(struct weston_touch *touch, struct weston_touch_grab *grab)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400585{
586 touch->grab = grab;
587 grab->touch = touch;
588}
589
590WL_EXPORT void
Kristian Høgsberge329f362013-05-06 22:19:57 -0400591weston_touch_end_grab(struct weston_touch *touch)
Kristian Høgsberg2158a882013-04-18 15:07:39 -0400592{
593 touch->grab = &touch->default_grab;
594}
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400595
596static void
597weston_seat_update_drag_surface(struct weston_seat *seat, int dx, int dy);
598
599static void
600clip_pointer_motion(struct weston_seat *seat, wl_fixed_t *fx, wl_fixed_t *fy)
601{
602 struct weston_compositor *ec = seat->compositor;
603 struct weston_output *output, *prev = NULL;
604 int x, y, old_x, old_y, valid = 0;
605
606 x = wl_fixed_to_int(*fx);
607 y = wl_fixed_to_int(*fy);
Kristian Høgsberge3148752013-05-06 23:19:49 -0400608 old_x = wl_fixed_to_int(seat->pointer->x);
609 old_y = wl_fixed_to_int(seat->pointer->y);
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400610
611 wl_list_for_each(output, &ec->output_list, link) {
612 if (pixman_region32_contains_point(&output->region,
613 x, y, NULL))
614 valid = 1;
615 if (pixman_region32_contains_point(&output->region,
616 old_x, old_y, NULL))
617 prev = output;
618 }
619
620 if (!valid) {
621 if (x < prev->x)
622 *fx = wl_fixed_from_int(prev->x);
623 else if (x >= prev->x + prev->width)
624 *fx = wl_fixed_from_int(prev->x +
625 prev->width - 1);
626 if (y < prev->y)
627 *fy = wl_fixed_from_int(prev->y);
628 else if (y >= prev->y + prev->current->height)
629 *fy = wl_fixed_from_int(prev->y +
630 prev->height - 1);
631 }
632}
633
634/* Takes absolute values */
635static void
636move_pointer(struct weston_seat *seat, wl_fixed_t x, wl_fixed_t y)
637{
638 struct weston_compositor *ec = seat->compositor;
Kristian Høgsberge3148752013-05-06 23:19:49 -0400639 struct weston_pointer *pointer = seat->pointer;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400640 struct weston_output *output;
641 int32_t ix, iy;
642
643 clip_pointer_motion(seat, &x, &y);
644
645 weston_seat_update_drag_surface(seat, x - pointer->x, y - pointer->y);
646
647 pointer->x = x;
648 pointer->y = y;
649
650 ix = wl_fixed_to_int(x);
651 iy = wl_fixed_to_int(y);
652
653 wl_list_for_each(output, &ec->output_list, link)
654 if (output->zoom.active &&
655 pixman_region32_contains_point(&output->region,
656 ix, iy, NULL))
657 weston_output_update_zoom(output, ZOOM_FOCUS_POINTER);
658
Kristian Høgsberga71e8b22013-05-06 21:51:21 -0400659 weston_seat_repick(seat);
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400660
661 if (seat->sprite) {
662 weston_surface_set_position(seat->sprite,
663 ix - seat->hotspot_x,
664 iy - seat->hotspot_y);
665 weston_surface_schedule_repaint(seat->sprite);
666 }
667}
668
669WL_EXPORT void
670notify_motion(struct weston_seat *seat,
671 uint32_t time, wl_fixed_t dx, wl_fixed_t dy)
672{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400673 const struct weston_pointer_grab_interface *interface;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400674 struct weston_compositor *ec = seat->compositor;
Kristian Høgsberge3148752013-05-06 23:19:49 -0400675 struct weston_pointer *pointer = seat->pointer;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400676
677 weston_compositor_wake(ec);
678
679 move_pointer(seat, pointer->x + dx, pointer->y + dy);
680
681 interface = pointer->grab->interface;
682 interface->motion(pointer->grab, time,
683 pointer->grab->x, pointer->grab->y);
684}
685
686WL_EXPORT void
687notify_motion_absolute(struct weston_seat *seat,
688 uint32_t time, wl_fixed_t x, wl_fixed_t y)
689{
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400690 const struct weston_pointer_grab_interface *interface;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400691 struct weston_compositor *ec = seat->compositor;
Kristian Høgsberge3148752013-05-06 23:19:49 -0400692 struct weston_pointer *pointer = seat->pointer;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400693
694 weston_compositor_wake(ec);
695
696 move_pointer(seat, x, y);
697
698 interface = pointer->grab->interface;
699 interface->motion(pointer->grab, time,
700 pointer->grab->x, pointer->grab->y);
701}
702
703WL_EXPORT void
704weston_surface_activate(struct weston_surface *surface,
705 struct weston_seat *seat)
706{
707 struct weston_compositor *compositor = seat->compositor;
708
Kristian Høgsberge3148752013-05-06 23:19:49 -0400709 if (seat->keyboard) {
710 weston_keyboard_set_focus(seat->keyboard, &surface->surface);
711 wl_data_device_set_keyboard_focus(seat);
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400712 }
713
714 wl_signal_emit(&compositor->activate_signal, surface);
715}
716
717WL_EXPORT void
718notify_button(struct weston_seat *seat, uint32_t time, int32_t button,
719 enum wl_pointer_button_state state)
720{
721 struct weston_compositor *compositor = seat->compositor;
Kristian Høgsberge3148752013-05-06 23:19:49 -0400722 struct weston_pointer *pointer = seat->pointer;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400723 struct weston_surface *focus =
724 (struct weston_surface *) pointer->focus;
725 uint32_t serial = wl_display_next_serial(compositor->wl_display);
726
727 if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
728 if (compositor->ping_handler && focus)
729 compositor->ping_handler(focus, serial);
730 weston_compositor_idle_inhibit(compositor);
731 if (pointer->button_count == 0) {
732 pointer->grab_button = button;
733 pointer->grab_time = time;
734 pointer->grab_x = pointer->x;
735 pointer->grab_y = pointer->y;
736 }
737 pointer->button_count++;
738 } else {
739 weston_compositor_idle_release(compositor);
740 pointer->button_count--;
741 }
742
743 weston_compositor_run_button_binding(compositor, seat, time, button,
744 state);
745
746 pointer->grab->interface->button(pointer->grab, time, button, state);
747
748 if (pointer->button_count == 1)
749 pointer->grab_serial =
750 wl_display_get_serial(compositor->wl_display);
751}
752
753WL_EXPORT void
754notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis,
755 wl_fixed_t value)
756{
757 struct weston_compositor *compositor = seat->compositor;
Kristian Høgsberge3148752013-05-06 23:19:49 -0400758 struct weston_pointer *pointer = seat->pointer;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400759 struct weston_surface *focus =
760 (struct weston_surface *) pointer->focus;
761 uint32_t serial = wl_display_next_serial(compositor->wl_display);
762
763 if (compositor->ping_handler && focus)
764 compositor->ping_handler(focus, serial);
765
766 weston_compositor_wake(compositor);
767
768 if (!value)
769 return;
770
771 if (weston_compositor_run_axis_binding(compositor, seat,
772 time, axis, value))
773 return;
774
775 if (pointer->focus_resource)
776 wl_pointer_send_axis(pointer->focus_resource, time, axis,
777 value);
778}
779
780WL_EXPORT void
781notify_modifiers(struct weston_seat *seat, uint32_t serial)
782{
Kristian Høgsberge3148752013-05-06 23:19:49 -0400783 struct weston_keyboard *keyboard = seat->keyboard;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400784 struct weston_keyboard_grab *grab = keyboard->grab;
785 uint32_t mods_depressed, mods_latched, mods_locked, group;
786 uint32_t mods_lookup;
787 enum weston_led leds = 0;
788 int changed = 0;
789
790 /* Serialize and update our internal state, checking to see if it's
791 * different to the previous state. */
792 mods_depressed = xkb_state_serialize_mods(seat->xkb_state.state,
793 XKB_STATE_DEPRESSED);
794 mods_latched = xkb_state_serialize_mods(seat->xkb_state.state,
795 XKB_STATE_LATCHED);
796 mods_locked = xkb_state_serialize_mods(seat->xkb_state.state,
797 XKB_STATE_LOCKED);
798 group = xkb_state_serialize_group(seat->xkb_state.state,
799 XKB_STATE_EFFECTIVE);
800
Kristian Høgsberge3148752013-05-06 23:19:49 -0400801 if (mods_depressed != seat->keyboard->modifiers.mods_depressed ||
802 mods_latched != seat->keyboard->modifiers.mods_latched ||
803 mods_locked != seat->keyboard->modifiers.mods_locked ||
804 group != seat->keyboard->modifiers.group)
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400805 changed = 1;
806
Kristian Høgsberge3148752013-05-06 23:19:49 -0400807 seat->keyboard->modifiers.mods_depressed = mods_depressed;
808 seat->keyboard->modifiers.mods_latched = mods_latched;
809 seat->keyboard->modifiers.mods_locked = mods_locked;
810 seat->keyboard->modifiers.group = group;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400811
812 /* And update the modifier_state for bindings. */
813 mods_lookup = mods_depressed | mods_latched;
814 seat->modifier_state = 0;
815 if (mods_lookup & (1 << seat->xkb_info.ctrl_mod))
816 seat->modifier_state |= MODIFIER_CTRL;
817 if (mods_lookup & (1 << seat->xkb_info.alt_mod))
818 seat->modifier_state |= MODIFIER_ALT;
819 if (mods_lookup & (1 << seat->xkb_info.super_mod))
820 seat->modifier_state |= MODIFIER_SUPER;
821 if (mods_lookup & (1 << seat->xkb_info.shift_mod))
822 seat->modifier_state |= MODIFIER_SHIFT;
823
824 /* Finally, notify the compositor that LEDs have changed. */
825 if (xkb_state_led_index_is_active(seat->xkb_state.state,
826 seat->xkb_info.num_led))
827 leds |= LED_NUM_LOCK;
828 if (xkb_state_led_index_is_active(seat->xkb_state.state,
829 seat->xkb_info.caps_led))
830 leds |= LED_CAPS_LOCK;
831 if (xkb_state_led_index_is_active(seat->xkb_state.state,
832 seat->xkb_info.scroll_led))
833 leds |= LED_SCROLL_LOCK;
834 if (leds != seat->xkb_state.leds && seat->led_update)
835 seat->led_update(seat, leds);
836 seat->xkb_state.leds = leds;
837
838 if (changed) {
839 grab->interface->modifiers(grab,
840 serial,
841 keyboard->modifiers.mods_depressed,
842 keyboard->modifiers.mods_latched,
843 keyboard->modifiers.mods_locked,
844 keyboard->modifiers.group);
845 }
846}
847
848static void
849update_modifier_state(struct weston_seat *seat, uint32_t serial, uint32_t key,
850 enum wl_keyboard_key_state state)
851{
852 enum xkb_key_direction direction;
853
854 if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
855 direction = XKB_KEY_DOWN;
856 else
857 direction = XKB_KEY_UP;
858
859 /* Offset the keycode by 8, as the evdev XKB rules reflect X's
860 * broken keycode system, which starts at 8. */
861 xkb_state_update_key(seat->xkb_state.state, key + 8, direction);
862
863 notify_modifiers(seat, serial);
864}
865
866WL_EXPORT void
867notify_key(struct weston_seat *seat, uint32_t time, uint32_t key,
868 enum wl_keyboard_key_state state,
869 enum weston_key_state_update update_state)
870{
871 struct weston_compositor *compositor = seat->compositor;
Kristian Høgsberge3148752013-05-06 23:19:49 -0400872 struct weston_keyboard *keyboard = seat->keyboard;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400873 struct weston_surface *focus =
874 (struct weston_surface *) keyboard->focus;
875 struct weston_keyboard_grab *grab = keyboard->grab;
876 uint32_t serial = wl_display_next_serial(compositor->wl_display);
877 uint32_t *k, *end;
878
879 if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
880 if (compositor->ping_handler && focus)
881 compositor->ping_handler(focus, serial);
882
883 weston_compositor_idle_inhibit(compositor);
884 keyboard->grab_key = key;
885 keyboard->grab_time = time;
886 } else {
887 weston_compositor_idle_release(compositor);
888 }
889
890 end = keyboard->keys.data + keyboard->keys.size;
891 for (k = keyboard->keys.data; k < end; k++) {
892 if (*k == key) {
893 /* Ignore server-generated repeats. */
894 if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
895 return;
896 *k = *--end;
897 }
898 }
899 keyboard->keys.size = (void *) end - keyboard->keys.data;
900 if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
901 k = wl_array_add(&keyboard->keys, sizeof *k);
902 *k = key;
903 }
904
905 if (grab == &keyboard->default_grab ||
906 grab == &keyboard->input_method_grab) {
907 weston_compositor_run_key_binding(compositor, seat, time, key,
908 state);
909 grab = keyboard->grab;
910 }
911
912 grab->interface->key(grab, time, key, state);
913
914 if (update_state == STATE_UPDATE_AUTOMATIC) {
915 update_modifier_state(seat,
916 wl_display_get_serial(compositor->wl_display),
917 key,
918 state);
919 }
920}
921
922WL_EXPORT void
923notify_pointer_focus(struct weston_seat *seat, struct weston_output *output,
924 wl_fixed_t x, wl_fixed_t y)
925{
926 struct weston_compositor *compositor = seat->compositor;
927
928 if (output) {
929 move_pointer(seat, x, y);
930 compositor->focus = 1;
931 } else {
932 compositor->focus = 0;
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -0400933 /* FIXME: We should call weston_pointer_set_focus(seat,
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400934 * NULL) here, but somehow that breaks re-entry... */
935 }
936}
937
938static void
939destroy_device_saved_kbd_focus(struct wl_listener *listener, void *data)
940{
941 struct weston_seat *ws;
942
943 ws = container_of(listener, struct weston_seat,
944 saved_kbd_focus_listener);
945
946 ws->saved_kbd_focus = NULL;
947}
948
949WL_EXPORT void
950notify_keyboard_focus_in(struct weston_seat *seat, struct wl_array *keys,
951 enum weston_key_state_update update_state)
952{
953 struct weston_compositor *compositor = seat->compositor;
Kristian Høgsberge3148752013-05-06 23:19:49 -0400954 struct weston_keyboard *keyboard = seat->keyboard;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400955 struct wl_surface *surface;
956 uint32_t *k, serial;
957
958 serial = wl_display_next_serial(compositor->wl_display);
959 wl_array_copy(&keyboard->keys, keys);
960 wl_array_for_each(k, &keyboard->keys) {
961 weston_compositor_idle_inhibit(compositor);
962 if (update_state == STATE_UPDATE_AUTOMATIC)
963 update_modifier_state(seat, serial, *k,
964 WL_KEYBOARD_KEY_STATE_PRESSED);
965 }
966
967 /* Run key bindings after we've updated the state. */
968 wl_array_for_each(k, &keyboard->keys) {
969 weston_compositor_run_key_binding(compositor, seat, 0, *k,
970 WL_KEYBOARD_KEY_STATE_PRESSED);
971 }
972
973 surface = seat->saved_kbd_focus;
974
975 if (surface) {
976 wl_list_remove(&seat->saved_kbd_focus_listener.link);
977 weston_keyboard_set_focus(keyboard, surface);
978 seat->saved_kbd_focus = NULL;
979 }
980}
981
982WL_EXPORT void
983notify_keyboard_focus_out(struct weston_seat *seat)
984{
985 struct weston_compositor *compositor = seat->compositor;
Kristian Høgsberge3148752013-05-06 23:19:49 -0400986 struct weston_keyboard *keyboard = seat->keyboard;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -0400987 uint32_t *k, serial;
988
989 serial = wl_display_next_serial(compositor->wl_display);
990 wl_array_for_each(k, &keyboard->keys) {
991 weston_compositor_idle_release(compositor);
992 update_modifier_state(seat, serial, *k,
993 WL_KEYBOARD_KEY_STATE_RELEASED);
994 }
995
996 seat->modifier_state = 0;
997
998 if (keyboard->focus) {
999 seat->saved_kbd_focus = keyboard->focus;
1000 seat->saved_kbd_focus_listener.notify =
1001 destroy_device_saved_kbd_focus;
1002 wl_signal_add(&keyboard->focus->resource.destroy_signal,
1003 &seat->saved_kbd_focus_listener);
1004 }
1005
1006 weston_keyboard_set_focus(keyboard, NULL);
1007 /* FIXME: We really need keyboard grab cancel here to
1008 * let the grab shut down properly. As it is we leak
1009 * the grab data. */
1010 weston_keyboard_end_grab(keyboard);
1011}
1012
1013static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04001014touch_set_focus(struct weston_seat *seat, struct wl_surface *surface)
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001015{
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001016 struct wl_resource *resource;
1017
1018 if (seat->touch->focus == surface)
1019 return;
1020
1021 if (seat->touch->focus_resource)
1022 wl_list_remove(&seat->touch->focus_listener.link);
1023 seat->touch->focus = NULL;
1024 seat->touch->focus_resource = NULL;
1025
1026 if (surface) {
1027 resource =
Kristian Høgsberg80fb82d2013-05-06 21:49:55 -04001028 find_resource_for_surface(&seat->touch->resource_list,
1029 surface);
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001030 if (!resource) {
1031 weston_log("couldn't find resource\n");
1032 return;
1033 }
1034
1035 seat->touch->focus = surface;
1036 seat->touch->focus_resource = resource;
1037 wl_signal_add(&resource->destroy_signal,
1038 &seat->touch->focus_listener);
1039 }
1040}
1041
1042/**
1043 * notify_touch - emulates button touches and notifies surfaces accordingly.
1044 *
1045 * It assumes always the correct cycle sequence until it gets here: touch_down
1046 * → touch_update → ... → touch_update → touch_end. The driver is responsible
1047 * for sending along such order.
1048 *
1049 */
1050WL_EXPORT void
1051notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
1052 wl_fixed_t x, wl_fixed_t y, int touch_type)
1053{
1054 struct weston_compositor *ec = seat->compositor;
Kristian Høgsberge3148752013-05-06 23:19:49 -04001055 struct weston_touch *touch = seat->touch;
Kristian Høgsberge329f362013-05-06 22:19:57 -04001056 struct weston_touch_grab *grab = touch->grab;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001057 struct weston_surface *es;
1058 wl_fixed_t sx, sy;
1059
1060 /* Update grab's global coordinates. */
1061 touch->grab_x = x;
1062 touch->grab_y = y;
1063
1064 switch (touch_type) {
1065 case WL_TOUCH_DOWN:
1066 weston_compositor_idle_inhibit(ec);
1067
1068 seat->num_tp++;
1069
1070 /* the first finger down picks the surface, and all further go
1071 * to that surface for the remainder of the touch session i.e.
1072 * until all touch points are up again. */
1073 if (seat->num_tp == 1) {
1074 es = weston_compositor_pick_surface(ec, x, y, &sx, &sy);
1075 touch_set_focus(seat, &es->surface);
1076 } else if (touch->focus) {
1077 es = (struct weston_surface *) touch->focus;
1078 weston_surface_from_global_fixed(es, x, y, &sx, &sy);
1079 } else {
1080 /* Unexpected condition: We have non-initial touch but
1081 * there is no focused surface.
1082 */
1083 weston_log("touch event received with %d points down"
1084 "but no surface focused\n", seat->num_tp);
1085 return;
1086 }
1087
1088 grab->interface->down(grab, time, touch_id, sx, sy);
1089 break;
1090 case WL_TOUCH_MOTION:
1091 es = (struct weston_surface *) touch->focus;
1092 if (!es)
1093 break;
1094
1095 weston_surface_from_global_fixed(es, x, y, &sx, &sy);
1096 grab->interface->motion(grab, time, touch_id, sx, sy);
1097 break;
1098 case WL_TOUCH_UP:
1099 weston_compositor_idle_release(ec);
1100 seat->num_tp--;
1101
1102 grab->interface->up(grab, time, touch_id);
1103 if (seat->num_tp == 0)
1104 touch_set_focus(seat, NULL);
1105 break;
1106 }
1107}
1108
1109static void
1110pointer_handle_sprite_destroy(struct wl_listener *listener, void *data)
1111{
1112 struct weston_seat *seat = container_of(listener, struct weston_seat,
1113 sprite_destroy_listener);
1114
1115 seat->sprite = NULL;
1116}
1117
1118static void
1119pointer_cursor_surface_configure(struct weston_surface *es,
1120 int32_t dx, int32_t dy, int32_t width, int32_t height)
1121{
1122 struct weston_seat *seat = es->configure_private;
1123 int x, y;
1124
1125 if (width == 0)
1126 return;
1127
1128 assert(es == seat->sprite);
1129
1130 seat->hotspot_x -= dx;
1131 seat->hotspot_y -= dy;
1132
Kristian Høgsberge3148752013-05-06 23:19:49 -04001133 x = wl_fixed_to_int(seat->pointer->x) - seat->hotspot_x;
1134 y = wl_fixed_to_int(seat->pointer->y) - seat->hotspot_y;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001135
1136 weston_surface_configure(seat->sprite, x, y,
1137 width, height);
1138
1139 empty_region(&es->pending.input);
1140
1141 if (!weston_surface_is_mapped(es)) {
1142 wl_list_insert(&es->compositor->cursor_layer.surface_list,
1143 &es->layer_link);
1144 weston_surface_update_transform(es);
1145 }
1146}
1147
1148static void
1149pointer_unmap_sprite(struct weston_seat *seat)
1150{
1151 if (weston_surface_is_mapped(seat->sprite))
1152 weston_surface_unmap(seat->sprite);
1153
1154 wl_list_remove(&seat->sprite_destroy_listener.link);
1155 seat->sprite->configure = NULL;
1156 seat->sprite->configure_private = NULL;
1157 seat->sprite = NULL;
1158}
1159
1160static void
1161pointer_set_cursor(struct wl_client *client, struct wl_resource *resource,
1162 uint32_t serial, struct wl_resource *surface_resource,
1163 int32_t x, int32_t y)
1164{
1165 struct weston_seat *seat = resource->data;
1166 struct weston_surface *surface = NULL;
1167
1168 if (surface_resource)
1169 surface = surface_resource->data;
1170
Kristian Høgsberge3148752013-05-06 23:19:49 -04001171 if (seat->pointer->focus == NULL)
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001172 return;
Kristian Høgsberge3148752013-05-06 23:19:49 -04001173 if (seat->pointer->focus->resource.client != client)
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001174 return;
Kristian Høgsberge3148752013-05-06 23:19:49 -04001175 if (seat->pointer->focus_serial - serial > UINT32_MAX / 2)
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001176 return;
1177
1178 if (surface && surface != seat->sprite) {
1179 if (surface->configure) {
1180 wl_resource_post_error(&surface->surface.resource,
1181 WL_DISPLAY_ERROR_INVALID_OBJECT,
1182 "surface->configure already "
1183 "set");
1184 return;
1185 }
1186 }
1187
1188 if (seat->sprite)
1189 pointer_unmap_sprite(seat);
1190
1191 if (!surface)
1192 return;
1193
1194 wl_signal_add(&surface->surface.resource.destroy_signal,
1195 &seat->sprite_destroy_listener);
1196
1197 surface->configure = pointer_cursor_surface_configure;
1198 surface->configure_private = seat;
1199 seat->sprite = surface;
1200 seat->hotspot_x = x;
1201 seat->hotspot_y = y;
1202
1203 if (surface->buffer_ref.buffer)
1204 pointer_cursor_surface_configure(surface, 0, 0, weston_surface_buffer_width(surface),
1205 weston_surface_buffer_height(surface));
1206}
1207
1208static const struct wl_pointer_interface pointer_interface = {
1209 pointer_set_cursor
1210};
1211
1212static void
1213handle_drag_surface_destroy(struct wl_listener *listener, void *data)
1214{
1215 struct weston_seat *seat;
1216
1217 seat = container_of(listener, struct weston_seat,
1218 drag_surface_destroy_listener);
1219
1220 seat->drag_surface = NULL;
1221}
1222
1223static void
1224seat_get_pointer(struct wl_client *client, struct wl_resource *resource,
1225 uint32_t id)
1226{
1227 struct weston_seat *seat = resource->data;
1228 struct wl_resource *cr;
1229
Kristian Høgsberge3148752013-05-06 23:19:49 -04001230 if (!seat->pointer)
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001231 return;
1232
1233 cr = wl_client_add_object(client, &wl_pointer_interface,
1234 &pointer_interface, id, seat);
Kristian Høgsberge3148752013-05-06 23:19:49 -04001235 wl_list_insert(&seat->pointer->resource_list, &cr->link);
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001236 cr->destroy = unbind_resource;
1237
Kristian Høgsberge3148752013-05-06 23:19:49 -04001238 if (seat->pointer->focus &&
1239 seat->pointer->focus->resource.client == client) {
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001240 struct weston_surface *surface;
1241 wl_fixed_t sx, sy;
1242
Kristian Høgsberge3148752013-05-06 23:19:49 -04001243 surface = (struct weston_surface *) seat->pointer->focus;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001244 weston_surface_from_global_fixed(surface,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001245 seat->pointer->x,
1246 seat->pointer->y,
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001247 &sx,
1248 &sy);
Kristian Høgsberge3148752013-05-06 23:19:49 -04001249 weston_pointer_set_focus(seat->pointer,
1250 seat->pointer->focus,
Kristian Høgsberg02bbabb2013-05-06 22:15:05 -04001251 sx,
1252 sy);
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001253 }
1254}
1255
1256static void
1257seat_get_keyboard(struct wl_client *client, struct wl_resource *resource,
1258 uint32_t id)
1259{
1260 struct weston_seat *seat = resource->data;
1261 struct wl_resource *cr;
1262
Kristian Høgsberge3148752013-05-06 23:19:49 -04001263 if (!seat->keyboard)
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001264 return;
1265
1266 cr = wl_client_add_object(client, &wl_keyboard_interface, NULL, id,
1267 seat);
Kristian Høgsberge3148752013-05-06 23:19:49 -04001268 wl_list_insert(&seat->keyboard->resource_list, &cr->link);
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001269 cr->destroy = unbind_resource;
1270
1271 wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
1272 seat->xkb_info.keymap_fd,
1273 seat->xkb_info.keymap_size);
1274
Kristian Høgsberge3148752013-05-06 23:19:49 -04001275 if (seat->keyboard->focus &&
1276 seat->keyboard->focus->resource.client == client) {
1277 weston_keyboard_set_focus(seat->keyboard,
1278 seat->keyboard->focus);
1279 wl_data_device_set_keyboard_focus(seat);
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001280 }
1281}
1282
1283static void
1284seat_get_touch(struct wl_client *client, struct wl_resource *resource,
1285 uint32_t id)
1286{
1287 struct weston_seat *seat = resource->data;
1288 struct wl_resource *cr;
1289
Kristian Høgsberge3148752013-05-06 23:19:49 -04001290 if (!seat->touch)
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001291 return;
1292
1293 cr = wl_client_add_object(client, &wl_touch_interface, NULL, id, seat);
Kristian Høgsberge3148752013-05-06 23:19:49 -04001294 wl_list_insert(&seat->touch->resource_list, &cr->link);
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001295 cr->destroy = unbind_resource;
1296}
1297
1298static const struct wl_seat_interface seat_interface = {
1299 seat_get_pointer,
1300 seat_get_keyboard,
1301 seat_get_touch,
1302};
1303
1304static void
1305bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1306{
Kristian Høgsberge3148752013-05-06 23:19:49 -04001307 struct weston_seat *seat = data;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001308 struct wl_resource *resource;
1309 enum wl_seat_capability caps = 0;
1310
1311 resource = wl_client_add_object(client, &wl_seat_interface,
1312 &seat_interface, id, data);
1313 wl_list_insert(&seat->base_resource_list, &resource->link);
1314 resource->destroy = unbind_resource;
1315
1316 if (seat->pointer)
1317 caps |= WL_SEAT_CAPABILITY_POINTER;
1318 if (seat->keyboard)
1319 caps |= WL_SEAT_CAPABILITY_KEYBOARD;
1320 if (seat->touch)
1321 caps |= WL_SEAT_CAPABILITY_TOUCH;
1322
1323 wl_seat_send_capabilities(resource, caps);
1324}
1325
1326static void
1327device_handle_new_drag_icon(struct wl_listener *listener, void *data)
1328{
1329 struct weston_seat *seat;
1330
1331 seat = container_of(listener, struct weston_seat,
1332 new_drag_icon_listener);
1333
1334 weston_seat_update_drag_surface(seat, 0, 0);
1335}
1336
1337int
1338weston_compositor_xkb_init(struct weston_compositor *ec,
1339 struct xkb_rule_names *names)
1340{
1341 if (ec->xkb_context == NULL) {
1342 ec->xkb_context = xkb_context_new(0);
1343 if (ec->xkb_context == NULL) {
1344 weston_log("failed to create XKB context\n");
1345 return -1;
1346 }
1347 }
1348
1349 if (names)
1350 ec->xkb_names = *names;
1351 if (!ec->xkb_names.rules)
1352 ec->xkb_names.rules = strdup("evdev");
1353 if (!ec->xkb_names.model)
1354 ec->xkb_names.model = strdup("pc105");
1355 if (!ec->xkb_names.layout)
1356 ec->xkb_names.layout = strdup("us");
1357
1358 return 0;
1359}
1360
1361static void xkb_info_destroy(struct weston_xkb_info *xkb_info)
1362{
1363 if (xkb_info->keymap)
1364 xkb_map_unref(xkb_info->keymap);
1365
1366 if (xkb_info->keymap_area)
1367 munmap(xkb_info->keymap_area, xkb_info->keymap_size);
1368 if (xkb_info->keymap_fd >= 0)
1369 close(xkb_info->keymap_fd);
1370}
1371
1372void
1373weston_compositor_xkb_destroy(struct weston_compositor *ec)
1374{
1375 free((char *) ec->xkb_names.rules);
1376 free((char *) ec->xkb_names.model);
1377 free((char *) ec->xkb_names.layout);
1378 free((char *) ec->xkb_names.variant);
1379 free((char *) ec->xkb_names.options);
1380
1381 xkb_info_destroy(&ec->xkb_info);
1382 xkb_context_unref(ec->xkb_context);
1383}
1384
1385static int
1386weston_xkb_info_new_keymap(struct weston_xkb_info *xkb_info)
1387{
1388 char *keymap_str;
1389
1390 xkb_info->shift_mod = xkb_map_mod_get_index(xkb_info->keymap,
1391 XKB_MOD_NAME_SHIFT);
1392 xkb_info->caps_mod = xkb_map_mod_get_index(xkb_info->keymap,
1393 XKB_MOD_NAME_CAPS);
1394 xkb_info->ctrl_mod = xkb_map_mod_get_index(xkb_info->keymap,
1395 XKB_MOD_NAME_CTRL);
1396 xkb_info->alt_mod = xkb_map_mod_get_index(xkb_info->keymap,
1397 XKB_MOD_NAME_ALT);
1398 xkb_info->mod2_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod2");
1399 xkb_info->mod3_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod3");
1400 xkb_info->super_mod = xkb_map_mod_get_index(xkb_info->keymap,
1401 XKB_MOD_NAME_LOGO);
1402 xkb_info->mod5_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod5");
1403
1404 xkb_info->num_led = xkb_map_led_get_index(xkb_info->keymap,
1405 XKB_LED_NAME_NUM);
1406 xkb_info->caps_led = xkb_map_led_get_index(xkb_info->keymap,
1407 XKB_LED_NAME_CAPS);
1408 xkb_info->scroll_led = xkb_map_led_get_index(xkb_info->keymap,
1409 XKB_LED_NAME_SCROLL);
1410
1411 keymap_str = xkb_map_get_as_string(xkb_info->keymap);
1412 if (keymap_str == NULL) {
1413 weston_log("failed to get string version of keymap\n");
1414 return -1;
1415 }
1416 xkb_info->keymap_size = strlen(keymap_str) + 1;
1417
1418 xkb_info->keymap_fd = os_create_anonymous_file(xkb_info->keymap_size);
1419 if (xkb_info->keymap_fd < 0) {
1420 weston_log("creating a keymap file for %lu bytes failed: %m\n",
1421 (unsigned long) xkb_info->keymap_size);
1422 goto err_keymap_str;
1423 }
1424
1425 xkb_info->keymap_area = mmap(NULL, xkb_info->keymap_size,
1426 PROT_READ | PROT_WRITE,
1427 MAP_SHARED, xkb_info->keymap_fd, 0);
1428 if (xkb_info->keymap_area == MAP_FAILED) {
1429 weston_log("failed to mmap() %lu bytes\n",
1430 (unsigned long) xkb_info->keymap_size);
1431 goto err_dev_zero;
1432 }
1433 strcpy(xkb_info->keymap_area, keymap_str);
1434 free(keymap_str);
1435
1436 return 0;
1437
1438err_dev_zero:
1439 close(xkb_info->keymap_fd);
1440 xkb_info->keymap_fd = -1;
1441err_keymap_str:
1442 free(keymap_str);
1443 return -1;
1444}
1445
1446static int
1447weston_compositor_build_global_keymap(struct weston_compositor *ec)
1448{
1449 if (ec->xkb_info.keymap != NULL)
1450 return 0;
1451
1452 ec->xkb_info.keymap = xkb_map_new_from_names(ec->xkb_context,
1453 &ec->xkb_names,
1454 0);
1455 if (ec->xkb_info.keymap == NULL) {
1456 weston_log("failed to compile global XKB keymap\n");
1457 weston_log(" tried rules %s, model %s, layout %s, variant %s, "
1458 "options %s\n",
1459 ec->xkb_names.rules, ec->xkb_names.model,
1460 ec->xkb_names.layout, ec->xkb_names.variant,
1461 ec->xkb_names.options);
1462 return -1;
1463 }
1464
1465 if (weston_xkb_info_new_keymap(&ec->xkb_info) < 0)
1466 return -1;
1467
1468 return 0;
1469}
1470
1471WL_EXPORT int
1472weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap)
1473{
1474 if (seat->has_keyboard)
1475 return 0;
1476
1477 if (keymap != NULL) {
1478 seat->xkb_info.keymap = xkb_map_ref(keymap);
1479 if (weston_xkb_info_new_keymap(&seat->xkb_info) < 0)
1480 return -1;
1481 } else {
1482 if (weston_compositor_build_global_keymap(seat->compositor) < 0)
1483 return -1;
1484 seat->xkb_info = seat->compositor->xkb_info;
1485 seat->xkb_info.keymap = xkb_map_ref(seat->xkb_info.keymap);
1486 }
1487
1488 seat->xkb_state.state = xkb_state_new(seat->xkb_info.keymap);
1489 if (seat->xkb_state.state == NULL) {
1490 weston_log("failed to initialise XKB state\n");
1491 return -1;
1492 }
1493
1494 seat->xkb_state.leds = 0;
1495
Kristian Høgsberge3148752013-05-06 23:19:49 -04001496 weston_keyboard_init(&seat->keyboard_instance);
1497 weston_seat_set_keyboard(seat, &seat->keyboard_instance);
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001498
1499 seat->has_keyboard = 1;
1500
1501 return 0;
1502}
1503
1504WL_EXPORT void
1505weston_seat_init_pointer(struct weston_seat *seat)
1506{
1507 if (seat->has_pointer)
1508 return;
1509
Kristian Høgsberge3148752013-05-06 23:19:49 -04001510 weston_pointer_init(&seat->pointer_instance);
1511 weston_seat_set_pointer(seat, &seat->pointer_instance);
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001512
1513 seat->has_pointer = 1;
1514}
1515
1516WL_EXPORT void
1517weston_seat_init_touch(struct weston_seat *seat)
1518{
1519 if (seat->has_touch)
1520 return;
1521
Kristian Høgsberge3148752013-05-06 23:19:49 -04001522 weston_touch_init(&seat->touch_instance);
1523 weston_seat_set_touch(seat, &seat->touch_instance);
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001524
1525 seat->has_touch = 1;
1526}
1527
1528WL_EXPORT void
1529weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec)
1530{
Kristian Høgsberg4a2a2742013-05-06 22:24:50 -04001531 memset(seat, 0, sizeof *seat);
1532
Kristian Høgsberge3148752013-05-06 23:19:49 -04001533 seat->selection_data_source = NULL;
1534 wl_list_init(&seat->base_resource_list);
1535 wl_signal_init(&seat->selection_signal);
1536 wl_list_init(&seat->drag_resource_list);
1537 wl_signal_init(&seat->drag_icon_signal);
1538 wl_signal_init(&seat->destroy_signal);
Kristian Høgsberg4a2a2742013-05-06 22:24:50 -04001539
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001540 seat->has_pointer = 0;
1541 seat->has_keyboard = 0;
1542 seat->has_touch = 0;
1543
1544 wl_display_add_global(ec->wl_display, &wl_seat_interface, seat,
1545 bind_seat);
1546
1547 seat->sprite = NULL;
1548 seat->sprite_destroy_listener.notify = pointer_handle_sprite_destroy;
1549
1550 seat->compositor = ec;
1551 seat->hotspot_x = 16;
1552 seat->hotspot_y = 16;
1553 seat->modifier_state = 0;
1554 seat->num_tp = 0;
1555
1556 seat->drag_surface_destroy_listener.notify =
1557 handle_drag_surface_destroy;
1558
1559 wl_list_insert(ec->seat_list.prev, &seat->link);
1560
1561 seat->new_drag_icon_listener.notify = device_handle_new_drag_icon;
Kristian Høgsberge3148752013-05-06 23:19:49 -04001562 wl_signal_add(&seat->drag_icon_signal,
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001563 &seat->new_drag_icon_listener);
1564
1565 clipboard_create(seat);
1566
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001567 wl_signal_emit(&ec->seat_created_signal, seat);
1568}
1569
1570WL_EXPORT void
1571weston_seat_release(struct weston_seat *seat)
1572{
1573 wl_list_remove(&seat->link);
1574 /* The global object is destroyed at wl_display_destroy() time. */
1575
1576 if (seat->sprite)
1577 pointer_unmap_sprite(seat);
1578
1579 if (seat->xkb_state.state != NULL)
1580 xkb_state_unref(seat->xkb_state.state);
1581 xkb_info_destroy(&seat->xkb_info);
1582
Kristian Høgsberge3148752013-05-06 23:19:49 -04001583 if (seat->pointer)
1584 weston_pointer_release(seat->pointer);
1585 if (seat->keyboard)
1586 weston_keyboard_release(seat->keyboard);
1587 if (seat->touch)
1588 weston_touch_release(seat->touch);
Kristian Høgsberg4a2a2742013-05-06 22:24:50 -04001589
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001590 wl_signal_emit(&seat->destroy_signal, seat);
1591}
1592
1593static void
1594drag_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
1595{
1596 empty_region(&es->pending.input);
1597
1598 weston_surface_configure(es,
1599 es->geometry.x + sx, es->geometry.y + sy,
1600 width, height);
1601}
1602
1603static int
Kristian Høgsberge3148752013-05-06 23:19:49 -04001604device_setup_new_drag_surface(struct weston_seat *seat,
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001605 struct weston_surface *surface)
1606{
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001607 if (surface->configure) {
1608 wl_resource_post_error(&surface->surface.resource,
1609 WL_DISPLAY_ERROR_INVALID_OBJECT,
1610 "surface->configure already set");
1611 return 0;
1612 }
1613
Kristian Høgsberge3148752013-05-06 23:19:49 -04001614 seat->drag_surface = surface;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001615
Kristian Høgsberge3148752013-05-06 23:19:49 -04001616 weston_surface_set_position(seat->drag_surface,
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001617 wl_fixed_to_double(seat->pointer->x),
1618 wl_fixed_to_double(seat->pointer->y));
1619
1620 surface->configure = drag_surface_configure;
1621
1622 wl_signal_add(&surface->surface.resource.destroy_signal,
Kristian Høgsberge3148752013-05-06 23:19:49 -04001623 &seat->drag_surface_destroy_listener);
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001624
1625 return 1;
1626}
1627
1628static void
1629device_release_drag_surface(struct weston_seat *seat)
1630{
1631 if (weston_surface_is_mapped(seat->drag_surface))
1632 weston_surface_unmap(seat->drag_surface);
1633
1634 seat->drag_surface->configure = NULL;
1635 empty_region(&seat->drag_surface->pending.input);
1636 wl_list_remove(&seat->drag_surface_destroy_listener.link);
1637 seat->drag_surface = NULL;
1638}
1639
1640static void
1641device_map_drag_surface(struct weston_seat *seat)
1642{
1643 struct wl_list *list;
1644
1645 if (weston_surface_is_mapped(seat->drag_surface) ||
1646 !seat->drag_surface->buffer_ref.buffer)
1647 return;
1648
1649 if (seat->sprite && weston_surface_is_mapped(seat->sprite))
1650 list = &seat->sprite->layer_link;
1651 else
1652 list = &seat->compositor->cursor_layer.surface_list;
1653
1654 wl_list_insert(list, &seat->drag_surface->layer_link);
1655 weston_surface_update_transform(seat->drag_surface);
1656 empty_region(&seat->drag_surface->input);
1657}
1658
1659static void
Kristian Høgsberge3148752013-05-06 23:19:49 -04001660weston_seat_update_drag_surface(struct weston_seat *seat, int dx, int dy)
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001661{
1662 int surface_changed = 0;
1663
Kristian Høgsberge3148752013-05-06 23:19:49 -04001664 if (!seat->drag_surface && !seat->drag_surface)
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001665 return;
1666
Kristian Høgsberge3148752013-05-06 23:19:49 -04001667 if (seat->drag_surface && seat->drag_surface &&
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001668 (&seat->drag_surface->surface.resource !=
Kristian Høgsberge3148752013-05-06 23:19:49 -04001669 &seat->next_drag_surface->resource))
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001670 /* between calls to this funcion we got a new drag_surface */
1671 surface_changed = 1;
1672
Kristian Høgsberge3148752013-05-06 23:19:49 -04001673 if (!seat->drag_surface || surface_changed) {
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001674 device_release_drag_surface(seat);
1675 if (!surface_changed)
1676 return;
1677 }
1678
1679 if (!seat->drag_surface || surface_changed) {
Kristian Høgsberge3148752013-05-06 23:19:49 -04001680 struct weston_surface *surface =
1681 (struct weston_surface *) seat->drag_surface;
Kristian Høgsbergb5e26102013-04-18 15:40:10 -04001682 if (!device_setup_new_drag_surface(seat, surface))
1683 return;
1684 }
1685
1686 /* the client may not have attached a buffer to the drag surface
1687 * when we setup it up, so check if map is needed on every update */
1688 device_map_drag_surface(seat);
1689
1690 if (!dx && !dy)
1691 return;
1692
1693 weston_surface_set_position(seat->drag_surface,
1694 seat->drag_surface->geometry.x + wl_fixed_to_double(dx),
1695 seat->drag_surface->geometry.y + wl_fixed_to_double(dy));
1696}
1697
1698WL_EXPORT void
1699weston_compositor_update_drag_surfaces(struct weston_compositor *compositor)
1700{
1701 struct weston_seat *seat;
1702
1703 wl_list_for_each(seat, &compositor->seat_list, link)
1704 weston_seat_update_drag_surface(seat, 0, 0);
1705}