Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 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 <string.h> |
| 25 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 26 | #include <linux/input.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 27 | |
| 28 | #include "wayland-server.h" |
| 29 | #include "compositor.h" |
| 30 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 31 | struct wl_shell { |
| 32 | struct wl_object object; |
| 33 | struct wlsc_shell shell; |
| 34 | }; |
| 35 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 36 | struct wlsc_move_grab { |
| 37 | struct wl_grab grab; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 38 | struct wlsc_surface *surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 39 | int32_t dx, dy; |
| 40 | }; |
| 41 | |
| 42 | static void |
| 43 | move_grab_motion(struct wl_grab *grab, |
| 44 | uint32_t time, int32_t x, int32_t y) |
| 45 | { |
| 46 | struct wlsc_move_grab *move = (struct wlsc_move_grab *) grab; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 47 | struct wlsc_surface *es = move->surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 48 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame^] | 49 | wlsc_surface_configure(es, x + move->dx, y + move->dy, |
| 50 | es->width, es->height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static void |
| 54 | move_grab_button(struct wl_grab *grab, |
| 55 | uint32_t time, int32_t button, int32_t state) |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | static void |
| 60 | move_grab_end(struct wl_grab *grab, uint32_t time) |
| 61 | { |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 62 | struct wlsc_surface *es; |
| 63 | struct wl_input_device *device = grab->input_device; |
| 64 | int32_t sx, sy; |
| 65 | |
| 66 | es = pick_surface(grab->input_device, &sx, &sy); |
| 67 | wl_input_device_set_pointer_focus(device, |
| 68 | &es->surface, time, |
| 69 | device->x, device->y, sx, sy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 70 | free(grab); |
| 71 | } |
| 72 | |
| 73 | static const struct wl_grab_interface move_grab_interface = { |
| 74 | move_grab_motion, |
| 75 | move_grab_button, |
| 76 | move_grab_end |
| 77 | }; |
| 78 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 79 | static void |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 80 | shell_move(struct wl_client *client, struct wl_shell *shell, |
| 81 | struct wl_surface *surface, |
| 82 | struct wl_input_device *device, uint32_t time) |
| 83 | { |
| 84 | struct wlsc_input_device *wd = (struct wlsc_input_device *) device; |
| 85 | struct wlsc_surface *es = (struct wlsc_surface *) surface; |
| 86 | struct wlsc_move_grab *move; |
| 87 | |
Kristian Høgsberg | 0ce2457 | 2011-01-28 15:18:33 -0500 | [diff] [blame] | 88 | /* FIXME: Reject if fullscreen */ |
| 89 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 90 | move = malloc(sizeof *move); |
| 91 | if (!move) { |
| 92 | wl_client_post_no_memory(client); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | move->grab.interface = &move_grab_interface; |
| 97 | move->dx = es->x - wd->input_device.grab_x; |
| 98 | move->dy = es->y - wd->input_device.grab_y; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 99 | move->surface = es; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 100 | |
| 101 | if (wl_input_device_update_grab(&wd->input_device, |
| 102 | &move->grab, surface, time) < 0) |
| 103 | return; |
| 104 | |
| 105 | wlsc_input_device_set_pointer_image(wd, WLSC_POINTER_DRAGGING); |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 106 | wl_input_device_set_pointer_focus(device, NULL, time, 0, 0, 0, 0); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | struct wlsc_resize_grab { |
| 110 | struct wl_grab grab; |
| 111 | uint32_t edges; |
| 112 | int32_t dx, dy, width, height; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 113 | struct wlsc_surface *surface; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 114 | struct wl_shell *shell; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | static void |
| 118 | resize_grab_motion(struct wl_grab *grab, |
| 119 | uint32_t time, int32_t x, int32_t y) |
| 120 | { |
| 121 | struct wlsc_resize_grab *resize = (struct wlsc_resize_grab *) grab; |
| 122 | struct wl_input_device *device = grab->input_device; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 123 | struct wl_surface *surface = &resize->surface->surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 124 | int32_t width, height; |
| 125 | |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 126 | if (resize->edges & WL_SHELL_RESIZE_LEFT) { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 127 | width = device->grab_x - x + resize->width; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 128 | } else if (resize->edges & WL_SHELL_RESIZE_RIGHT) { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 129 | width = x - device->grab_x + resize->width; |
| 130 | } else { |
| 131 | width = resize->width; |
| 132 | } |
| 133 | |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 134 | if (resize->edges & WL_SHELL_RESIZE_TOP) { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 135 | height = device->grab_y - y + resize->height; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 136 | } else if (resize->edges & WL_SHELL_RESIZE_BOTTOM) { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 137 | height = y - device->grab_y + resize->height; |
| 138 | } else { |
| 139 | height = resize->height; |
| 140 | } |
| 141 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 142 | wl_client_post_event(surface->client, &resize->shell->object, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 143 | WL_SHELL_CONFIGURE, time, resize->edges, |
| 144 | surface, width, height); |
| 145 | } |
| 146 | |
| 147 | static void |
| 148 | resize_grab_button(struct wl_grab *grab, |
| 149 | uint32_t time, int32_t button, int32_t state) |
| 150 | { |
| 151 | } |
| 152 | |
| 153 | static void |
| 154 | resize_grab_end(struct wl_grab *grab, uint32_t time) |
| 155 | { |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 156 | struct wlsc_surface *es; |
| 157 | struct wl_input_device *device = grab->input_device; |
| 158 | int32_t sx, sy; |
| 159 | |
| 160 | es = pick_surface(grab->input_device, &sx, &sy); |
| 161 | wl_input_device_set_pointer_focus(device, |
| 162 | &es->surface, time, |
| 163 | device->x, device->y, sx, sy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 164 | free(grab); |
| 165 | } |
| 166 | |
| 167 | static const struct wl_grab_interface resize_grab_interface = { |
| 168 | resize_grab_motion, |
| 169 | resize_grab_button, |
| 170 | resize_grab_end |
| 171 | }; |
| 172 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 173 | static void |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 174 | shell_resize(struct wl_client *client, struct wl_shell *shell, |
| 175 | struct wl_surface *surface, |
| 176 | struct wl_input_device *device, uint32_t time, uint32_t edges) |
| 177 | { |
| 178 | struct wlsc_input_device *wd = (struct wlsc_input_device *) device; |
| 179 | struct wlsc_resize_grab *resize; |
| 180 | enum wlsc_pointer_type pointer = WLSC_POINTER_LEFT_PTR; |
| 181 | struct wlsc_surface *es = (struct wlsc_surface *) surface; |
| 182 | |
Kristian Høgsberg | 0ce2457 | 2011-01-28 15:18:33 -0500 | [diff] [blame] | 183 | /* FIXME: Reject if fullscreen */ |
| 184 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 185 | resize = malloc(sizeof *resize); |
| 186 | if (!resize) { |
| 187 | wl_client_post_no_memory(client); |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | resize->grab.interface = &resize_grab_interface; |
| 192 | resize->edges = edges; |
| 193 | resize->dx = es->x - wd->input_device.grab_x; |
| 194 | resize->dy = es->y - wd->input_device.grab_y; |
| 195 | resize->width = es->width; |
| 196 | resize->height = es->height; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 197 | resize->surface = es; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 198 | resize->shell = shell; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 199 | |
| 200 | if (edges == 0 || edges > 15 || |
| 201 | (edges & 3) == 3 || (edges & 12) == 12) |
| 202 | return; |
| 203 | |
| 204 | switch (edges) { |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 205 | case WL_SHELL_RESIZE_TOP: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 206 | pointer = WLSC_POINTER_TOP; |
| 207 | break; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 208 | case WL_SHELL_RESIZE_BOTTOM: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 209 | pointer = WLSC_POINTER_BOTTOM; |
| 210 | break; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 211 | case WL_SHELL_RESIZE_LEFT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 212 | pointer = WLSC_POINTER_LEFT; |
| 213 | break; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 214 | case WL_SHELL_RESIZE_TOP_LEFT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 215 | pointer = WLSC_POINTER_TOP_LEFT; |
| 216 | break; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 217 | case WL_SHELL_RESIZE_BOTTOM_LEFT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 218 | pointer = WLSC_POINTER_BOTTOM_LEFT; |
| 219 | break; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 220 | case WL_SHELL_RESIZE_RIGHT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 221 | pointer = WLSC_POINTER_RIGHT; |
| 222 | break; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 223 | case WL_SHELL_RESIZE_TOP_RIGHT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 224 | pointer = WLSC_POINTER_TOP_RIGHT; |
| 225 | break; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 226 | case WL_SHELL_RESIZE_BOTTOM_RIGHT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 227 | pointer = WLSC_POINTER_BOTTOM_RIGHT; |
| 228 | break; |
| 229 | } |
| 230 | |
| 231 | if (wl_input_device_update_grab(&wd->input_device, |
| 232 | &resize->grab, surface, time) < 0) |
| 233 | return; |
| 234 | |
| 235 | wlsc_input_device_set_pointer_image(wd, pointer); |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 236 | wl_input_device_set_pointer_focus(device, NULL, time, 0, 0, 0, 0); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static void |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 240 | shell_set_toplevel(struct wl_client *client, |
| 241 | struct wl_shell *wl_shell, |
| 242 | struct wl_surface *surface) |
| 243 | |
| 244 | { |
| 245 | struct wlsc_surface *es = (struct wlsc_surface *) surface; |
| 246 | struct wlsc_compositor *ec = es->compositor; |
| 247 | |
| 248 | if (es->map_type == WLSC_SURFACE_MAP_FULLSCREEN) { |
| 249 | es->x = es->saved_x; |
| 250 | es->y = es->saved_y; |
| 251 | } else if (es->map_type == WLSC_SURFACE_MAP_UNMAPPED) { |
| 252 | es->x = 10 + random() % 400; |
| 253 | es->y = 10 + random() % 400; |
| 254 | /* assign to first output */ |
| 255 | es->output = container_of(ec->output_list.next, |
| 256 | struct wlsc_output, link); |
| 257 | } |
| 258 | |
| 259 | wlsc_surface_damage(es); |
| 260 | es->map_type = WLSC_SURFACE_MAP_TOPLEVEL; |
| 261 | es->fullscreen_output = NULL; |
| 262 | } |
| 263 | |
| 264 | static void |
| 265 | shell_set_transient(struct wl_client *client, |
| 266 | struct wl_shell *wl_shell, |
| 267 | struct wl_surface *surface, |
| 268 | struct wl_surface *parent, |
| 269 | int x, int y, uint32_t flags) |
| 270 | { |
| 271 | struct wlsc_surface *es = (struct wlsc_surface *) surface; |
| 272 | struct wlsc_surface *pes = (struct wlsc_surface *) parent; |
| 273 | |
| 274 | /* assign to parents output */ |
| 275 | es->output = pes->output; |
| 276 | |
| 277 | es->x = pes->x + x; |
| 278 | es->y = pes->y + y; |
| 279 | |
| 280 | wlsc_surface_damage(es); |
| 281 | es->map_type = WLSC_SURFACE_MAP_TRANSIENT; |
| 282 | } |
| 283 | |
| 284 | static void |
| 285 | shell_set_fullscreen(struct wl_client *client, |
| 286 | struct wl_shell *wl_shell, |
| 287 | struct wl_surface *surface) |
| 288 | |
| 289 | { |
| 290 | struct wlsc_surface *es = (struct wlsc_surface *) surface; |
| 291 | struct wlsc_output *output; |
| 292 | |
| 293 | /* FIXME: Fullscreen on first output */ |
| 294 | /* FIXME: Handle output going away */ |
| 295 | output = container_of(es->compositor->output_list.next, |
| 296 | struct wlsc_output, link); |
| 297 | es->output = output; |
| 298 | |
| 299 | es->saved_x = es->x; |
| 300 | es->saved_y = es->y; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 301 | es->x = (output->current->width - es->width) / 2; |
| 302 | es->y = (output->current->height - es->height) / 2; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 303 | es->fullscreen_output = output; |
| 304 | wlsc_surface_damage(es); |
| 305 | es->map_type = WLSC_SURFACE_MAP_FULLSCREEN; |
| 306 | } |
| 307 | |
| 308 | static void |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 309 | destroy_drag(struct wl_resource *resource, struct wl_client *client) |
| 310 | { |
| 311 | struct wl_drag *drag = |
| 312 | container_of(resource, struct wl_drag, resource); |
| 313 | |
| 314 | wl_list_remove(&drag->drag_focus_listener.link); |
| 315 | if (drag->grab.input_device) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 316 | wl_input_device_end_grab(drag->grab.input_device, |
| 317 | wlsc_compositor_get_time()); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 318 | |
| 319 | free(drag); |
| 320 | } |
| 321 | |
| 322 | |
| 323 | static void |
| 324 | wl_drag_set_pointer_focus(struct wl_drag *drag, |
| 325 | struct wl_surface *surface, uint32_t time, |
| 326 | int32_t x, int32_t y, int32_t sx, int32_t sy) |
| 327 | { |
| 328 | char **p, **end; |
| 329 | |
| 330 | if (drag->drag_focus == surface) |
| 331 | return; |
| 332 | |
| 333 | if (drag->drag_focus && |
| 334 | (!surface || drag->drag_focus->client != surface->client)) |
| 335 | wl_client_post_event(drag->drag_focus->client, |
| 336 | &drag->drag_offer.object, |
| 337 | WL_DRAG_OFFER_POINTER_FOCUS, |
| 338 | time, NULL, 0, 0, 0, 0); |
| 339 | |
| 340 | if (surface && |
| 341 | (!drag->drag_focus || |
| 342 | drag->drag_focus->client != surface->client)) { |
| 343 | wl_client_post_global(surface->client, |
| 344 | &drag->drag_offer.object); |
| 345 | |
| 346 | end = drag->types.data + drag->types.size; |
| 347 | for (p = drag->types.data; p < end; p++) |
| 348 | wl_client_post_event(surface->client, |
| 349 | &drag->drag_offer.object, |
| 350 | WL_DRAG_OFFER_OFFER, *p); |
| 351 | } |
| 352 | |
| 353 | if (surface) { |
| 354 | wl_client_post_event(surface->client, |
| 355 | &drag->drag_offer.object, |
| 356 | WL_DRAG_OFFER_POINTER_FOCUS, |
| 357 | time, surface, |
| 358 | x, y, sx, sy); |
| 359 | |
| 360 | } |
| 361 | |
| 362 | drag->drag_focus = surface; |
| 363 | drag->pointer_focus_time = time; |
| 364 | drag->target = NULL; |
| 365 | |
| 366 | wl_list_remove(&drag->drag_focus_listener.link); |
| 367 | if (surface) |
Benjamin Franzke | 4721a3c | 2011-05-06 17:13:17 +0200 | [diff] [blame] | 368 | wl_list_insert(surface->resource.destroy_listener_list.prev, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 369 | &drag->drag_focus_listener.link); |
| 370 | } |
| 371 | |
| 372 | static void |
| 373 | drag_offer_accept(struct wl_client *client, |
| 374 | struct wl_drag_offer *offer, uint32_t time, const char *type) |
| 375 | { |
| 376 | struct wl_drag *drag = container_of(offer, struct wl_drag, drag_offer); |
| 377 | char **p, **end; |
| 378 | |
| 379 | /* If the client responds to drag pointer_focus or motion |
| 380 | * events after the pointer has left the surface, we just |
| 381 | * discard the accept requests. The drag source just won't |
| 382 | * get the corresponding 'target' events and eventually the |
| 383 | * next surface/root will start sending events. */ |
| 384 | if (time < drag->pointer_focus_time) |
| 385 | return; |
| 386 | |
| 387 | drag->target = client; |
| 388 | drag->type = NULL; |
| 389 | end = drag->types.data + drag->types.size; |
| 390 | for (p = drag->types.data; p < end; p++) |
| 391 | if (type && strcmp(*p, type) == 0) |
| 392 | drag->type = *p; |
| 393 | |
| 394 | wl_client_post_event(drag->source->client, &drag->resource.object, |
| 395 | WL_DRAG_TARGET, drag->type); |
| 396 | } |
| 397 | |
| 398 | static void |
| 399 | drag_offer_receive(struct wl_client *client, |
| 400 | struct wl_drag_offer *offer, int fd) |
| 401 | { |
| 402 | struct wl_drag *drag = container_of(offer, struct wl_drag, drag_offer); |
| 403 | |
| 404 | wl_client_post_event(drag->source->client, &drag->resource.object, |
| 405 | WL_DRAG_FINISH, fd); |
| 406 | close(fd); |
| 407 | } |
| 408 | |
| 409 | static void |
| 410 | drag_offer_reject(struct wl_client *client, struct wl_drag_offer *offer) |
| 411 | { |
| 412 | struct wl_drag *drag = container_of(offer, struct wl_drag, drag_offer); |
| 413 | |
| 414 | wl_client_post_event(drag->source->client, &drag->resource.object, |
| 415 | WL_DRAG_REJECT); |
| 416 | } |
| 417 | |
| 418 | static const struct wl_drag_offer_interface drag_offer_interface = { |
| 419 | drag_offer_accept, |
| 420 | drag_offer_receive, |
| 421 | drag_offer_reject |
| 422 | }; |
| 423 | |
| 424 | static void |
| 425 | drag_offer(struct wl_client *client, struct wl_drag *drag, const char *type) |
| 426 | { |
| 427 | char **p; |
| 428 | |
| 429 | p = wl_array_add(&drag->types, sizeof *p); |
| 430 | if (p) |
| 431 | *p = strdup(type); |
| 432 | if (!p || !*p) |
| 433 | wl_client_post_no_memory(client); |
| 434 | } |
| 435 | |
| 436 | static void |
| 437 | drag_grab_motion(struct wl_grab *grab, |
| 438 | uint32_t time, int32_t x, int32_t y) |
| 439 | { |
| 440 | struct wl_drag *drag = container_of(grab, struct wl_drag, grab); |
| 441 | struct wlsc_surface *es; |
| 442 | int32_t sx, sy; |
| 443 | |
| 444 | es = pick_surface(grab->input_device, &sx, &sy); |
| 445 | wl_drag_set_pointer_focus(drag, &es->surface, time, x, y, sx, sy); |
| 446 | if (es) |
| 447 | wl_client_post_event(es->surface.client, |
| 448 | &drag->drag_offer.object, |
| 449 | WL_DRAG_OFFER_MOTION, |
| 450 | time, x, y, sx, sy); |
| 451 | } |
| 452 | |
| 453 | static void |
| 454 | drag_grab_button(struct wl_grab *grab, |
| 455 | uint32_t time, int32_t button, int32_t state) |
| 456 | { |
| 457 | } |
| 458 | |
| 459 | static void |
| 460 | drag_grab_end(struct wl_grab *grab, uint32_t time) |
| 461 | { |
| 462 | struct wl_drag *drag = container_of(grab, struct wl_drag, grab); |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 463 | struct wlsc_surface *es; |
| 464 | struct wl_input_device *device = grab->input_device; |
| 465 | int32_t sx, sy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 466 | |
| 467 | if (drag->target) |
| 468 | wl_client_post_event(drag->target, |
| 469 | &drag->drag_offer.object, |
| 470 | WL_DRAG_OFFER_DROP); |
| 471 | |
| 472 | wl_drag_set_pointer_focus(drag, NULL, time, 0, 0, 0, 0); |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 473 | |
| 474 | es = pick_surface(grab->input_device, &sx, &sy); |
| 475 | wl_input_device_set_pointer_focus(device, |
| 476 | &es->surface, time, |
| 477 | device->x, device->y, sx, sy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | static const struct wl_grab_interface drag_grab_interface = { |
| 481 | drag_grab_motion, |
| 482 | drag_grab_button, |
| 483 | drag_grab_end |
| 484 | }; |
| 485 | |
| 486 | static void |
| 487 | drag_activate(struct wl_client *client, |
| 488 | struct wl_drag *drag, |
| 489 | struct wl_surface *surface, |
| 490 | struct wl_input_device *device, uint32_t time) |
| 491 | { |
| 492 | struct wl_display *display = wl_client_get_display (client); |
| 493 | struct wlsc_surface *target; |
| 494 | int32_t sx, sy; |
| 495 | |
| 496 | if (wl_input_device_update_grab(device, |
| 497 | &drag->grab, surface, time) < 0) |
| 498 | return; |
| 499 | |
| 500 | drag->grab.interface = &drag_grab_interface; |
| 501 | |
| 502 | drag->source = surface; |
| 503 | |
| 504 | drag->drag_offer.object.interface = &wl_drag_offer_interface; |
| 505 | drag->drag_offer.object.implementation = |
| 506 | (void (**)(void)) &drag_offer_interface; |
| 507 | |
| 508 | wl_display_add_object(display, &drag->drag_offer.object); |
| 509 | |
| 510 | target = pick_surface(device, &sx, &sy); |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 511 | wl_input_device_set_pointer_focus(device, NULL, time, 0, 0, 0, 0); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 512 | wl_drag_set_pointer_focus(drag, &target->surface, time, |
| 513 | device->x, device->y, sx, sy); |
| 514 | } |
| 515 | |
| 516 | static void |
| 517 | drag_destroy(struct wl_client *client, struct wl_drag *drag) |
| 518 | { |
Benjamin Franzke | 4721a3c | 2011-05-06 17:13:17 +0200 | [diff] [blame] | 519 | wl_resource_destroy(&drag->resource, client, |
| 520 | wlsc_compositor_get_time()); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | static const struct wl_drag_interface drag_interface = { |
| 524 | drag_offer, |
| 525 | drag_activate, |
| 526 | drag_destroy, |
| 527 | }; |
| 528 | |
| 529 | static void |
| 530 | drag_handle_surface_destroy(struct wl_listener *listener, |
Benjamin Franzke | 4721a3c | 2011-05-06 17:13:17 +0200 | [diff] [blame] | 531 | struct wl_resource *resource, uint32_t time) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 532 | { |
| 533 | struct wl_drag *drag = |
| 534 | container_of(listener, struct wl_drag, drag_focus_listener); |
Benjamin Franzke | 4721a3c | 2011-05-06 17:13:17 +0200 | [diff] [blame] | 535 | struct wl_surface *surface = (struct wl_surface *) resource; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 536 | |
| 537 | if (drag->drag_focus == surface) |
| 538 | wl_drag_set_pointer_focus(drag, NULL, time, 0, 0, 0, 0); |
| 539 | } |
| 540 | |
| 541 | static void |
| 542 | shell_create_drag(struct wl_client *client, |
| 543 | struct wl_shell *shell, uint32_t id) |
| 544 | { |
| 545 | struct wl_drag *drag; |
| 546 | |
| 547 | drag = malloc(sizeof *drag); |
| 548 | if (drag == NULL) { |
| 549 | wl_client_post_no_memory(client); |
| 550 | return; |
| 551 | } |
| 552 | |
| 553 | memset(drag, 0, sizeof *drag); |
| 554 | drag->resource.object.id = id; |
| 555 | drag->resource.object.interface = &wl_drag_interface; |
| 556 | drag->resource.object.implementation = |
| 557 | (void (**)(void)) &drag_interface; |
| 558 | |
| 559 | drag->resource.destroy = destroy_drag; |
| 560 | |
| 561 | drag->drag_focus_listener.func = drag_handle_surface_destroy; |
| 562 | wl_list_init(&drag->drag_focus_listener.link); |
| 563 | |
| 564 | wl_client_add_resource(client, &drag->resource); |
| 565 | } |
| 566 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 567 | static void |
| 568 | wlsc_selection_set_focus(struct wlsc_shell *shell, |
| 569 | struct wl_selection *selection, |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 570 | struct wl_surface *surface, uint32_t time) |
| 571 | { |
| 572 | char **p, **end; |
| 573 | |
| 574 | if (selection->selection_focus == surface) |
| 575 | return; |
| 576 | |
| 577 | if (selection->selection_focus != NULL) |
| 578 | wl_client_post_event(selection->selection_focus->client, |
| 579 | &selection->selection_offer.object, |
| 580 | WL_SELECTION_OFFER_KEYBOARD_FOCUS, |
| 581 | NULL); |
| 582 | |
| 583 | if (surface) { |
| 584 | wl_client_post_global(surface->client, |
| 585 | &selection->selection_offer.object); |
| 586 | |
| 587 | end = selection->types.data + selection->types.size; |
| 588 | for (p = selection->types.data; p < end; p++) |
| 589 | wl_client_post_event(surface->client, |
| 590 | &selection->selection_offer.object, |
| 591 | WL_SELECTION_OFFER_OFFER, *p); |
| 592 | |
| 593 | wl_list_remove(&selection->selection_focus_listener.link); |
Benjamin Franzke | 4721a3c | 2011-05-06 17:13:17 +0200 | [diff] [blame] | 594 | wl_list_insert(surface->resource.destroy_listener_list.prev, |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 595 | &selection->selection_focus_listener.link); |
| 596 | |
| 597 | wl_client_post_event(surface->client, |
| 598 | &selection->selection_offer.object, |
| 599 | WL_SELECTION_OFFER_KEYBOARD_FOCUS, |
| 600 | selection->input_device); |
| 601 | } |
| 602 | |
| 603 | selection->selection_focus = surface; |
| 604 | |
| 605 | wl_list_remove(&selection->selection_focus_listener.link); |
| 606 | if (surface) |
Benjamin Franzke | 4721a3c | 2011-05-06 17:13:17 +0200 | [diff] [blame] | 607 | wl_list_insert(surface->resource.destroy_listener_list.prev, |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 608 | &selection->selection_focus_listener.link); |
| 609 | } |
| 610 | |
| 611 | static void |
| 612 | selection_offer_receive(struct wl_client *client, |
| 613 | struct wl_selection_offer *offer, |
| 614 | const char *mime_type, int fd) |
| 615 | { |
| 616 | struct wl_selection *selection = |
| 617 | container_of(offer, struct wl_selection, selection_offer); |
| 618 | |
| 619 | wl_client_post_event(selection->client, |
| 620 | &selection->resource.object, |
| 621 | WL_SELECTION_SEND, mime_type, fd); |
| 622 | close(fd); |
| 623 | } |
| 624 | |
| 625 | static const struct wl_selection_offer_interface selection_offer_interface = { |
| 626 | selection_offer_receive |
| 627 | }; |
| 628 | |
| 629 | static void |
| 630 | selection_offer(struct wl_client *client, |
| 631 | struct wl_selection *selection, const char *type) |
| 632 | { |
| 633 | char **p; |
| 634 | |
| 635 | p = wl_array_add(&selection->types, sizeof *p); |
| 636 | if (p) |
| 637 | *p = strdup(type); |
| 638 | if (!p || !*p) |
| 639 | wl_client_post_no_memory(client); |
| 640 | } |
| 641 | |
| 642 | static void |
| 643 | selection_activate(struct wl_client *client, |
| 644 | struct wl_selection *selection, |
| 645 | struct wl_input_device *device, uint32_t time) |
| 646 | { |
| 647 | struct wlsc_input_device *wd = (struct wlsc_input_device *) device; |
| 648 | struct wl_display *display = wl_client_get_display (client); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 649 | struct wlsc_compositor *compositor = |
| 650 | (struct wlsc_compositor *) device->compositor; |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 651 | |
| 652 | selection->input_device = device; |
| 653 | |
| 654 | selection->selection_offer.object.interface = |
| 655 | &wl_selection_offer_interface; |
| 656 | selection->selection_offer.object.implementation = |
| 657 | (void (**)(void)) &selection_offer_interface; |
| 658 | |
| 659 | wl_display_add_object(display, &selection->selection_offer.object); |
| 660 | |
| 661 | if (wd->selection) { |
| 662 | wl_client_post_event(wd->selection->client, |
| 663 | &wd->selection->resource.object, |
| 664 | WL_SELECTION_CANCELLED); |
| 665 | } |
| 666 | wd->selection = selection; |
| 667 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 668 | wlsc_selection_set_focus(compositor->shell, |
| 669 | selection, device->keyboard_focus, time); |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | static void |
| 673 | selection_destroy(struct wl_client *client, struct wl_selection *selection) |
| 674 | { |
Benjamin Franzke | 4721a3c | 2011-05-06 17:13:17 +0200 | [diff] [blame] | 675 | wl_resource_destroy(&selection->resource, client, |
| 676 | wlsc_compositor_get_time()); |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | static const struct wl_selection_interface selection_interface = { |
| 680 | selection_offer, |
| 681 | selection_activate, |
| 682 | selection_destroy |
| 683 | }; |
| 684 | |
| 685 | static void |
| 686 | destroy_selection(struct wl_resource *resource, struct wl_client *client) |
| 687 | { |
| 688 | struct wl_selection *selection = |
| 689 | container_of(resource, struct wl_selection, resource); |
| 690 | struct wlsc_input_device *wd = |
| 691 | (struct wlsc_input_device *) selection->input_device; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 692 | struct wlsc_compositor *compositor = |
| 693 | (struct wlsc_compositor *) wd->input_device.compositor; |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 694 | |
| 695 | if (wd && wd->selection == selection) { |
| 696 | wd->selection = NULL; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 697 | wlsc_selection_set_focus(compositor->shell, |
| 698 | selection, NULL, |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 699 | wlsc_compositor_get_time()); |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | wl_list_remove(&selection->selection_focus_listener.link); |
| 703 | free(selection); |
| 704 | } |
| 705 | |
| 706 | static void |
| 707 | selection_handle_surface_destroy(struct wl_listener *listener, |
Benjamin Franzke | 4721a3c | 2011-05-06 17:13:17 +0200 | [diff] [blame] | 708 | struct wl_resource *resource, uint32_t time) |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 709 | { |
| 710 | } |
| 711 | |
| 712 | static void |
| 713 | shell_create_selection(struct wl_client *client, |
| 714 | struct wl_shell *shell, uint32_t id) |
| 715 | { |
| 716 | struct wl_selection *selection; |
| 717 | |
| 718 | selection = malloc(sizeof *selection); |
| 719 | if (selection == NULL) { |
| 720 | wl_client_post_no_memory(client); |
| 721 | return; |
| 722 | } |
| 723 | |
| 724 | memset(selection, 0, sizeof *selection); |
| 725 | selection->resource.object.id = id; |
| 726 | selection->resource.object.interface = &wl_selection_interface; |
| 727 | selection->resource.object.implementation = |
| 728 | (void (**)(void)) &selection_interface; |
| 729 | |
| 730 | selection->client = client; |
| 731 | selection->resource.destroy = destroy_selection; |
| 732 | selection->selection_focus = NULL; |
| 733 | |
| 734 | selection->selection_focus_listener.func = |
| 735 | selection_handle_surface_destroy; |
| 736 | wl_list_init(&selection->selection_focus_listener.link); |
| 737 | |
| 738 | wl_client_add_resource(client, &selection->resource); |
| 739 | } |
| 740 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 741 | const static struct wl_shell_interface shell_interface = { |
| 742 | shell_move, |
| 743 | shell_resize, |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 744 | shell_create_drag, |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 745 | shell_create_selection, |
| 746 | shell_set_toplevel, |
| 747 | shell_set_transient, |
| 748 | shell_set_fullscreen |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 749 | }; |
| 750 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 751 | static void |
| 752 | move_binding(struct wl_input_device *device, uint32_t time, |
| 753 | uint32_t key, uint32_t button, uint32_t state, void *data) |
| 754 | { |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 755 | struct wl_shell *shell = data; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 756 | struct wlsc_surface *surface = |
| 757 | (struct wlsc_surface *) device->pointer_focus; |
| 758 | |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 759 | if (surface == NULL) |
| 760 | return; |
| 761 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 762 | shell_move(NULL, shell, &surface->surface, device, time); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | static void |
| 766 | resize_binding(struct wl_input_device *device, uint32_t time, |
| 767 | uint32_t key, uint32_t button, uint32_t state, void *data) |
| 768 | { |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 769 | struct wl_shell *shell = data; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 770 | struct wlsc_surface *surface = |
| 771 | (struct wlsc_surface *) device->pointer_focus; |
| 772 | uint32_t edges = 0; |
| 773 | int32_t x, y; |
| 774 | |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 775 | if (surface == NULL) |
| 776 | return; |
| 777 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 778 | x = device->grab_x - surface->x; |
| 779 | y = device->grab_y - surface->y; |
| 780 | |
| 781 | if (x < surface->width / 3) |
| 782 | edges |= WL_SHELL_RESIZE_LEFT; |
| 783 | else if (x < 2 * surface->width / 3) |
| 784 | edges |= 0; |
| 785 | else |
| 786 | edges |= WL_SHELL_RESIZE_RIGHT; |
| 787 | |
| 788 | if (y < surface->height / 3) |
| 789 | edges |= WL_SHELL_RESIZE_TOP; |
| 790 | else if (y < 2 * surface->height / 3) |
| 791 | edges |= 0; |
| 792 | else |
| 793 | edges |= WL_SHELL_RESIZE_BOTTOM; |
| 794 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 795 | shell_resize(NULL, shell, &surface->surface, device, time, edges); |
| 796 | } |
| 797 | |
| 798 | static void |
| 799 | lock(struct wlsc_shell *shell) |
| 800 | { |
| 801 | } |
| 802 | |
| 803 | static void |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 804 | attach(struct wlsc_shell *shell, struct wlsc_surface *es) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 805 | { |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 806 | if (es->map_type == WLSC_SURFACE_MAP_FULLSCREEN) { |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 807 | es->x = (es->fullscreen_output->current->width - es->width) / 2; |
| 808 | es->y = (es->fullscreen_output->current->height - es->height) / 2; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 809 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 810 | } |
| 811 | |
Kristian Høgsberg | 6c709a3 | 2011-05-06 14:52:41 -0400 | [diff] [blame] | 812 | int |
| 813 | shell_init(struct wlsc_compositor *ec); |
| 814 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 815 | WL_EXPORT int |
| 816 | shell_init(struct wlsc_compositor *ec) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 817 | { |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 818 | struct wl_shell *shell; |
| 819 | |
| 820 | shell = malloc(sizeof *shell); |
| 821 | if (shell == NULL) |
| 822 | return -1; |
| 823 | |
| 824 | shell->shell.lock = lock; |
| 825 | shell->shell.attach = attach; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 826 | shell->shell.set_selection_focus = wlsc_selection_set_focus; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 827 | |
| 828 | shell->object.interface = &wl_shell_interface; |
| 829 | shell->object.implementation = (void (**)(void)) &shell_interface; |
| 830 | wl_display_add_object(ec->wl_display, &shell->object); |
| 831 | if (wl_display_add_global(ec->wl_display, &shell->object, NULL)) |
| 832 | return -1; |
| 833 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 834 | wlsc_compositor_add_binding(ec, 0, BTN_LEFT, MODIFIER_SUPER, |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 835 | move_binding, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 836 | wlsc_compositor_add_binding(ec, 0, BTN_MIDDLE, MODIFIER_SUPER, |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 837 | resize_binding, shell); |
| 838 | |
| 839 | ec->shell = &shell->shell; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 840 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 841 | return 0; |
| 842 | } |