2 * Copyright © 2020 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 #include <linux/input.h>
32 #include "ivi-compositor.h"
33 #include "shared/helpers.h"
36 get_ivi_shell_surface(struct weston_surface *surface)
38 struct weston_desktop_surface *desktop_surface =
39 weston_surface_get_desktop_surface(surface);
42 return weston_desktop_surface_get_user_data(desktop_surface);
48 ivi_shell_seat_handle_destroy(struct wl_listener *listener, void *data)
50 struct ivi_shell_seat *shseat =
51 container_of(listener,
52 struct ivi_shell_seat, seat_destroy_listener);
54 wl_list_remove(&shseat->keyboard_focus_listener.link);
55 wl_list_remove(&shseat->caps_changed_listener.link);
56 wl_list_remove(&shseat->pointer_focus_listener.link);
57 wl_list_remove(&shseat->seat_destroy_listener.link);
62 struct ivi_shell_seat *
63 get_ivi_shell_seat(struct weston_seat *seat)
65 struct wl_listener *listener;
71 listener = wl_signal_get(&seat->destroy_signal,
72 ivi_shell_seat_handle_destroy);
76 return container_of(listener,
77 struct ivi_shell_seat, seat_destroy_listener);
81 get_ivi_shell_weston_first_seat(struct ivi_compositor *ivi)
84 struct weston_compositor *compositor = ivi->compositor;
86 if (wl_list_empty(&compositor->seat_list))
89 node = compositor->seat_list.next;
90 return container_of(node, struct weston_seat, link);
94 ivi_shell_seat_handle_pointer_focus(struct wl_listener *listener, void *data)
96 struct weston_pointer *pointer = data;
97 struct ivi_shell_seat *shseat = get_ivi_shell_seat(pointer->seat);
98 struct wl_resource *resource;
101 /* FIXME: should probably query it and not assume all caps */
102 uint32_t caps = (WL_SEAT_CAPABILITY_POINTER |
103 WL_SEAT_CAPABILITY_TOUCH |
104 WL_SEAT_CAPABILITY_KEYBOARD);
106 wl_resource_for_each(resource, &pointer->seat->base_resource_list)
109 /* remove the POINTER capability such that the client will not install
110 * a cursor surface */
111 if (shseat->disable_cursor && !shseat->new_caps_sent && resources) {
112 caps &= ~WL_SEAT_CAPABILITY_POINTER;
113 wl_resource_for_each(resource, &pointer->seat->base_resource_list) {
114 wl_seat_send_capabilities(resource, caps);
116 shseat->new_caps_sent = true;
121 ivi_shell_seat_handle_caps_changed(struct wl_listener *listener, void *data)
123 struct weston_pointer *pointer;
124 struct ivi_shell_seat *shseat;
126 shseat = container_of(listener, struct ivi_shell_seat,
127 caps_changed_listener);
128 pointer = weston_seat_get_pointer(shseat->seat);
130 if (pointer && wl_list_empty(&shseat->pointer_focus_listener.link)) {
131 wl_signal_add(&pointer->focus_signal,
132 &shseat->pointer_focus_listener);
134 wl_list_remove(&shseat->pointer_focus_listener.link);
135 wl_list_init(&shseat->pointer_focus_listener.link);
139 static struct ivi_shell_seat *
140 ivi_shell_seat_create(struct weston_seat *seat, bool disable_cursor)
142 struct ivi_shell_seat *shseat;
144 shseat = zalloc(sizeof(*shseat));
146 weston_log("no memory to allocate shell seat\n");
151 shseat->disable_cursor = disable_cursor;
152 shseat->new_caps_sent = false;
154 shseat->seat_destroy_listener.notify = ivi_shell_seat_handle_destroy;
155 wl_signal_add(&seat->destroy_signal, &shseat->seat_destroy_listener);
157 wl_list_init(&shseat->keyboard_focus_listener.link);
159 shseat->pointer_focus_listener.notify =
160 ivi_shell_seat_handle_pointer_focus;
161 wl_list_init(&shseat->pointer_focus_listener.link);
163 shseat->caps_changed_listener.notify =
164 ivi_shell_seat_handle_caps_changed;
165 wl_signal_add(&seat->updated_caps_signal, &shseat->caps_changed_listener);
167 ivi_shell_seat_handle_caps_changed(&shseat->caps_changed_listener, NULL);
174 ivi_shell_handle_seat_created(struct wl_listener *listener, void *data)
176 struct weston_seat *seat = data;
177 struct ivi_compositor *ivi =
178 container_of(listener, struct ivi_compositor, seat_created_listener);
180 weston_log("Cursor is %s\n", ivi->disable_cursor ? "disabled" : "not disabled");
181 ivi_shell_seat_create(seat, ivi->disable_cursor);
185 * useful to reset the fact that 'new' capabilities have seent
188 ivi_seat_reset_caps_sent(struct ivi_compositor *ivi)
190 struct weston_compositor *ec = ivi->compositor;
191 struct weston_seat *seat;
193 wl_list_for_each(seat, &ec->seat_list, link) {
194 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(seat);
195 ivi_seat->new_caps_sent = false;
200 ivi_seat_init(struct ivi_compositor *ivi)
202 struct weston_compositor *ec = ivi->compositor;
203 struct weston_seat *seat;
205 wl_list_for_each(seat, &ec->seat_list, link) {
206 weston_log("Seat %p, cursor is %s\n", seat, ivi->disable_cursor ?
207 "not disabled" : "disabled");
208 ivi_shell_seat_create(seat, ivi->disable_cursor);
211 ivi->seat_created_listener.notify = ivi_shell_handle_seat_created;
212 wl_signal_add(&ec->seat_created_signal, &ivi->seat_created_listener);