2 * Copyright © 2010-2012 Intel Corporation
3 * Copyright © 2011-2012 Collabora, Ltd.
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 #include <linux/input.h>
33 #include <sys/types.h>
35 #include <wayland-server.h>
36 #include "compositor.h"
37 #include "desktop-shell-server-protocol.h"
38 #include "../shared/config-parser.h"
40 #define DEFAULT_NUM_WORKSPACES 1
41 #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200
51 struct weston_seat *seat;
53 struct weston_surface *keyboard_focus;
55 struct wl_listener seat_destroy_listener;
56 struct wl_listener surface_destroy_listener;
60 struct weston_layer layer;
62 struct wl_list focus_list;
63 struct wl_listener seat_destroyed_listener;
66 struct input_panel_surface {
68 struct weston_surface *surface;
69 struct wl_listener listener;
72 struct desktop_shell {
73 struct weston_compositor *compositor;
75 struct wl_listener lock_listener;
76 struct wl_listener unlock_listener;
77 struct wl_listener destroy_listener;
78 struct wl_listener show_input_panel_listener;
79 struct wl_listener hide_input_panel_listener;
81 struct weston_layer fullscreen_layer;
82 struct weston_layer panel_layer;
83 struct weston_layer background_layer;
84 struct weston_layer lock_layer;
85 struct weston_layer input_panel_layer;
87 struct wl_listener pointer_focus_listener;
88 struct weston_surface *grab_surface;
91 struct weston_process process;
92 struct wl_client *client;
93 struct wl_resource *desktop_shell;
100 bool showing_input_panels;
101 bool prepare_event_sent;
103 struct weston_surface *lock_surface;
104 struct wl_listener lock_surface_listener;
107 struct wl_array array;
108 unsigned int current;
111 struct weston_animation animation;
113 uint32_t anim_timestamp;
115 struct workspace *anim_from;
116 struct workspace *anim_to;
122 struct wl_resource *binding;
123 struct wl_list surfaces;
124 struct weston_process process;
128 struct wl_resource *binding;
129 struct wl_list surfaces;
132 uint32_t binding_modifier;
133 enum animation_type win_animation_type;
134 struct weston_surface *debug_repaint_surface;
137 enum shell_surface_type {
139 SHELL_SURFACE_TOPLEVEL,
140 SHELL_SURFACE_TRANSIENT,
141 SHELL_SURFACE_FULLSCREEN,
142 SHELL_SURFACE_MAXIMIZED,
147 struct wl_event_source *source;
151 struct shell_surface {
152 struct wl_resource resource;
154 struct weston_surface *surface;
155 struct wl_listener surface_destroy_listener;
156 struct weston_surface *parent;
157 struct desktop_shell *shell;
159 enum shell_surface_type type, next_type;
161 int32_t saved_x, saved_y;
162 bool saved_position_valid;
163 bool saved_rotation_valid;
167 struct weston_transform transform;
168 struct weston_matrix rotation;
172 struct wl_pointer_grab grab;
174 struct weston_transform parent_transform;
176 struct wl_seat *seat;
186 enum wl_shell_surface_fullscreen_method type;
187 struct weston_transform transform; /* matrix from x, y */
189 struct weston_surface *black_surface;
192 struct ping_timer *ping_timer;
194 struct weston_transform workspace_transform;
196 struct weston_output *fullscreen_output;
197 struct weston_output *output;
200 const struct weston_shell_client *client;
204 struct wl_pointer_grab grab;
205 struct shell_surface *shsurf;
206 struct wl_listener shsurf_destroy_listener;
207 struct wl_pointer *pointer;
210 struct weston_move_grab {
211 struct shell_grab base;
216 struct shell_grab base;
217 struct weston_matrix rotation;
225 activate(struct desktop_shell *shell, struct weston_surface *es,
226 struct weston_seat *seat);
228 static struct workspace *
229 get_current_workspace(struct desktop_shell *shell);
231 static struct shell_surface *
232 get_shell_surface(struct weston_surface *surface);
234 static struct desktop_shell *
235 shell_surface_get_shell(struct shell_surface *shsurf);
238 shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
240 struct desktop_shell *shell;
241 struct weston_surface *top_fs_es;
243 shell = shell_surface_get_shell(shsurf);
245 if (wl_list_empty(&shell->fullscreen_layer.surface_list))
248 top_fs_es = container_of(shell->fullscreen_layer.surface_list.next,
249 struct weston_surface,
251 return (shsurf == get_shell_surface(top_fs_es));
255 destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
257 struct shell_grab *grab;
259 grab = container_of(listener, struct shell_grab,
260 shsurf_destroy_listener);
266 shell_grab_start(struct shell_grab *grab,
267 const struct wl_pointer_grab_interface *interface,
268 struct shell_surface *shsurf,
269 struct wl_pointer *pointer,
270 enum desktop_shell_cursor cursor)
272 struct desktop_shell *shell = shsurf->shell;
274 grab->grab.interface = interface;
275 grab->shsurf = shsurf;
276 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
277 wl_signal_add(&shsurf->resource.destroy_signal,
278 &grab->shsurf_destroy_listener);
280 grab->pointer = pointer;
281 grab->grab.focus = &shsurf->surface->surface;
283 wl_pointer_start_grab(pointer, &grab->grab);
284 desktop_shell_send_grab_cursor(shell->child.desktop_shell, cursor);
285 wl_pointer_set_focus(pointer, &shell->grab_surface->surface,
286 wl_fixed_from_int(0), wl_fixed_from_int(0));
290 shell_grab_end(struct shell_grab *grab)
293 wl_list_remove(&grab->shsurf_destroy_listener.link);
295 wl_pointer_end_grab(grab->pointer);
299 center_on_output(struct weston_surface *surface,
300 struct weston_output *output);
302 static enum weston_keyboard_modifier
303 get_modifier(char *modifier)
306 return MODIFIER_SUPER;
308 if (!strcmp("ctrl", modifier))
309 return MODIFIER_CTRL;
310 else if (!strcmp("alt", modifier))
312 else if (!strcmp("super", modifier))
313 return MODIFIER_SUPER;
315 return MODIFIER_SUPER;
318 static enum animation_type
319 get_animation_type(char *animation)
322 return ANIMATION_NONE;
324 if (!strcmp("zoom", animation))
325 return ANIMATION_ZOOM;
326 else if (!strcmp("fade", animation))
327 return ANIMATION_FADE;
329 return ANIMATION_NONE;
333 shell_configuration(struct desktop_shell *shell)
338 unsigned int num_workspaces = DEFAULT_NUM_WORKSPACES;
339 char *modifier = NULL;
340 char *win_animation = NULL;
342 struct config_key shell_keys[] = {
343 { "binding-modifier", CONFIG_KEY_STRING, &modifier },
344 { "animation", CONFIG_KEY_STRING, &win_animation},
346 CONFIG_KEY_UNSIGNED_INTEGER, &num_workspaces },
349 struct config_key saver_keys[] = {
350 { "path", CONFIG_KEY_STRING, &path },
351 { "duration", CONFIG_KEY_INTEGER, &duration },
354 struct config_section cs[] = {
355 { "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL },
356 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
359 config_file = config_file_path("weston.ini");
360 parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell);
363 shell->screensaver.path = path;
364 shell->screensaver.duration = duration;
365 shell->binding_modifier = get_modifier(modifier);
366 shell->win_animation_type = get_animation_type(win_animation);
367 shell->workspaces.num = num_workspaces > 0 ? num_workspaces : 1;
371 focus_state_destroy(struct focus_state *state)
373 wl_list_remove(&state->seat_destroy_listener.link);
374 wl_list_remove(&state->surface_destroy_listener.link);
379 focus_state_seat_destroy(struct wl_listener *listener, void *data)
381 struct focus_state *state = container_of(listener,
383 seat_destroy_listener);
385 wl_list_remove(&state->link);
386 focus_state_destroy(state);
390 focus_state_surface_destroy(struct wl_listener *listener, void *data)
392 struct focus_state *state = container_of(listener,
394 surface_destroy_listener);
395 struct desktop_shell *shell;
396 struct weston_surface *surface, *next;
399 wl_list_for_each(surface, &state->ws->layer.surface_list, layer_link) {
400 if (surface == state->keyboard_focus)
408 shell = state->seat->compositor->shell_interface.shell;
409 activate(shell, next, state->seat);
411 wl_list_remove(&state->link);
412 focus_state_destroy(state);
416 static struct focus_state *
417 focus_state_create(struct weston_seat *seat, struct workspace *ws)
419 struct focus_state *state;
421 state = malloc(sizeof *state);
427 wl_list_insert(&ws->focus_list, &state->link);
429 state->seat_destroy_listener.notify = focus_state_seat_destroy;
430 state->surface_destroy_listener.notify = focus_state_surface_destroy;
431 wl_signal_add(&seat->seat.destroy_signal,
432 &state->seat_destroy_listener);
433 wl_list_init(&state->surface_destroy_listener.link);
439 restore_focus_state(struct desktop_shell *shell, struct workspace *ws)
441 struct focus_state *state, *next;
443 wl_list_for_each_safe(state, next, &ws->focus_list, link) {
444 if (state->keyboard_focus)
445 wl_keyboard_set_focus(state->seat->seat.keyboard,
446 &state->keyboard_focus->surface);
451 workspace_destroy(struct workspace *ws)
453 struct focus_state *state, *next;
455 wl_list_for_each_safe(state, next, &ws->focus_list, link)
456 focus_state_destroy(state);
462 seat_destroyed(struct wl_listener *listener, void *data)
464 struct weston_seat *seat = data;
465 struct focus_state *state, *next;
466 struct workspace *ws = container_of(listener,
468 seat_destroyed_listener);
470 wl_list_for_each_safe(state, next, &ws->focus_list, link)
471 if (state->seat == seat)
472 wl_list_remove(&state->link);
475 static struct workspace *
476 workspace_create(void)
478 struct workspace *ws = malloc(sizeof *ws);
482 weston_layer_init(&ws->layer, NULL);
484 wl_list_init(&ws->focus_list);
485 wl_list_init(&ws->seat_destroyed_listener.link);
486 ws->seat_destroyed_listener.notify = seat_destroyed;
492 workspace_is_empty(struct workspace *ws)
494 return wl_list_empty(&ws->layer.surface_list);
497 static struct workspace *
498 get_workspace(struct desktop_shell *shell, unsigned int index)
500 struct workspace **pws = shell->workspaces.array.data;
505 static struct workspace *
506 get_current_workspace(struct desktop_shell *shell)
508 return get_workspace(shell, shell->workspaces.current);
512 activate_workspace(struct desktop_shell *shell, unsigned int index)
514 struct workspace *ws;
516 ws = get_workspace(shell, index);
517 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
519 shell->workspaces.current = index;
523 get_output_height(struct weston_output *output)
525 return abs(output->region.extents.y1 - output->region.extents.y2);
529 surface_translate(struct weston_surface *surface, double d)
531 struct shell_surface *shsurf = get_shell_surface(surface);
532 struct weston_transform *transform;
534 transform = &shsurf->workspace_transform;
535 if (wl_list_empty(&transform->link))
536 wl_list_insert(surface->geometry.transformation_list.prev,
537 &shsurf->workspace_transform.link);
539 weston_matrix_init(&shsurf->workspace_transform.matrix);
540 weston_matrix_translate(&shsurf->workspace_transform.matrix,
542 surface->geometry.dirty = 1;
546 workspace_translate_out(struct workspace *ws, double fraction)
548 struct weston_surface *surface;
552 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
553 height = get_output_height(surface->output);
554 d = height * fraction;
556 surface_translate(surface, d);
561 workspace_translate_in(struct workspace *ws, double fraction)
563 struct weston_surface *surface;
567 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
568 height = get_output_height(surface->output);
571 d = -(height - height * fraction);
573 d = height + height * fraction;
575 surface_translate(surface, d);
580 workspace_damage_all_surfaces(struct workspace *ws)
582 struct weston_surface *surface;
584 wl_list_for_each(surface, &ws->layer.surface_list, layer_link)
585 weston_surface_damage(surface);
589 reverse_workspace_change_animation(struct desktop_shell *shell,
591 struct workspace *from,
592 struct workspace *to)
594 shell->workspaces.current = index;
596 shell->workspaces.anim_to = to;
597 shell->workspaces.anim_from = from;
598 shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir;
599 shell->workspaces.anim_timestamp = 0;
601 restore_focus_state(shell, to);
603 workspace_damage_all_surfaces(from);
604 workspace_damage_all_surfaces(to);
608 workspace_deactivate_transforms(struct workspace *ws)
610 struct weston_surface *surface;
611 struct shell_surface *shsurf;
613 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
614 shsurf = get_shell_surface(surface);
615 wl_list_remove(&shsurf->workspace_transform.link);
616 wl_list_init(&shsurf->workspace_transform.link);
617 shsurf->surface->geometry.dirty = 1;
622 finish_workspace_change_animation(struct desktop_shell *shell,
623 struct workspace *from,
624 struct workspace *to)
626 workspace_damage_all_surfaces(from);
627 workspace_damage_all_surfaces(to);
629 wl_list_remove(&shell->workspaces.animation.link);
630 workspace_deactivate_transforms(from);
631 workspace_deactivate_transforms(to);
632 shell->workspaces.anim_to = NULL;
634 wl_list_remove(&shell->workspaces.anim_from->layer.link);
638 animate_workspace_change_frame(struct weston_animation *animation,
639 struct weston_output *output, uint32_t msecs)
641 struct desktop_shell *shell =
642 container_of(animation, struct desktop_shell,
643 workspaces.animation);
644 struct workspace *from = shell->workspaces.anim_from;
645 struct workspace *to = shell->workspaces.anim_to;
649 if (workspace_is_empty(from) && workspace_is_empty(to)) {
650 finish_workspace_change_animation(shell, from, to);
654 if (shell->workspaces.anim_timestamp == 0) {
655 if (shell->workspaces.anim_current == 0.0)
656 shell->workspaces.anim_timestamp = msecs;
658 shell->workspaces.anim_timestamp =
660 /* Invers of movement function 'y' below. */
661 (asin(1.0 - shell->workspaces.anim_current) *
662 DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH *
666 t = msecs - shell->workspaces.anim_timestamp;
672 x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2;
675 if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) {
676 workspace_damage_all_surfaces(from);
677 workspace_damage_all_surfaces(to);
679 workspace_translate_out(from, shell->workspaces.anim_dir * y);
680 workspace_translate_in(to, shell->workspaces.anim_dir * y);
681 shell->workspaces.anim_current = y;
683 workspace_damage_all_surfaces(from);
684 workspace_damage_all_surfaces(to);
687 finish_workspace_change_animation(shell, from, to);
691 animate_workspace_change(struct desktop_shell *shell,
693 struct workspace *from,
694 struct workspace *to)
696 struct weston_output *output;
700 if (index > shell->workspaces.current)
705 shell->workspaces.current = index;
707 shell->workspaces.anim_dir = dir;
708 shell->workspaces.anim_from = from;
709 shell->workspaces.anim_to = to;
710 shell->workspaces.anim_current = 0.0;
711 shell->workspaces.anim_timestamp = 0;
713 output = container_of(shell->compositor->output_list.next,
714 struct weston_output, link);
715 wl_list_insert(&output->animation_list,
716 &shell->workspaces.animation.link);
718 wl_list_insert(&from->layer.link, &to->layer.link);
720 workspace_translate_in(to, 0);
722 restore_focus_state(shell, to);
724 workspace_damage_all_surfaces(from);
725 workspace_damage_all_surfaces(to);
729 change_workspace(struct desktop_shell *shell, unsigned int index)
731 struct workspace *from;
732 struct workspace *to;
734 if (index == shell->workspaces.current)
737 /* Don't change workspace when there is any fullscreen surfaces. */
738 if (!wl_list_empty(&shell->fullscreen_layer.surface_list))
741 from = get_current_workspace(shell);
742 to = get_workspace(shell, index);
744 if (shell->workspaces.anim_from == to &&
745 shell->workspaces.anim_to == from) {
746 reverse_workspace_change_animation(shell, index, from, to);
750 if (shell->workspaces.anim_to != NULL)
751 finish_workspace_change_animation(shell,
752 shell->workspaces.anim_from,
753 shell->workspaces.anim_to);
755 if (workspace_is_empty(to) && workspace_is_empty(from)) {
756 shell->workspaces.current = index;
757 wl_list_insert(&from->layer.link, &to->layer.link);
758 wl_list_remove(&from->layer.link);
760 restore_focus_state(shell, to);
763 animate_workspace_change(shell, index, from, to);
767 noop_grab_focus(struct wl_pointer_grab *grab,
768 struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
774 move_grab_motion(struct wl_pointer_grab *grab,
775 uint32_t time, wl_fixed_t x, wl_fixed_t y)
777 struct weston_move_grab *move = (struct weston_move_grab *) grab;
778 struct wl_pointer *pointer = grab->pointer;
779 struct shell_surface *shsurf = move->base.shsurf;
780 struct weston_surface *es;
781 int dx = wl_fixed_to_int(pointer->x + move->dx);
782 int dy = wl_fixed_to_int(pointer->y + move->dy);
787 es = shsurf->surface;
789 weston_surface_configure(es, dx, dy,
790 es->geometry.width, es->geometry.height);
792 weston_compositor_schedule_repaint(es->compositor);
796 move_grab_button(struct wl_pointer_grab *grab,
797 uint32_t time, uint32_t button, uint32_t state_w)
799 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
801 struct wl_pointer *pointer = grab->pointer;
802 enum wl_pointer_button_state state = state_w;
804 if (pointer->button_count == 0 &&
805 state == WL_POINTER_BUTTON_STATE_RELEASED) {
806 shell_grab_end(shell_grab);
811 static const struct wl_pointer_grab_interface move_grab_interface = {
818 surface_move(struct shell_surface *shsurf, struct weston_seat *ws)
820 struct weston_move_grab *move;
825 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
828 move = malloc(sizeof *move);
832 move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
833 ws->seat.pointer->grab_x;
834 move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
835 ws->seat.pointer->grab_y;
837 shell_grab_start(&move->base, &move_grab_interface, shsurf,
838 ws->seat.pointer, DESKTOP_SHELL_CURSOR_MOVE);
844 shell_surface_move(struct wl_client *client, struct wl_resource *resource,
845 struct wl_resource *seat_resource, uint32_t serial)
847 struct weston_seat *ws = seat_resource->data;
848 struct shell_surface *shsurf = resource->data;
850 if (ws->seat.pointer->button_count == 0 ||
851 ws->seat.pointer->grab_serial != serial ||
852 ws->seat.pointer->focus != &shsurf->surface->surface)
855 if (surface_move(shsurf, ws) < 0)
856 wl_resource_post_no_memory(resource);
859 struct weston_resize_grab {
860 struct shell_grab base;
862 int32_t width, height;
866 resize_grab_motion(struct wl_pointer_grab *grab,
867 uint32_t time, wl_fixed_t x, wl_fixed_t y)
869 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
870 struct wl_pointer *pointer = grab->pointer;
871 struct shell_surface *shsurf = resize->base.shsurf;
872 int32_t width, height;
873 wl_fixed_t from_x, from_y;
874 wl_fixed_t to_x, to_y;
879 weston_surface_from_global_fixed(shsurf->surface,
880 pointer->grab_x, pointer->grab_y,
882 weston_surface_from_global_fixed(shsurf->surface,
883 pointer->x, pointer->y, &to_x, &to_y);
885 width = resize->width;
886 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
887 width += wl_fixed_to_int(from_x - to_x);
888 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
889 width += wl_fixed_to_int(to_x - from_x);
892 height = resize->height;
893 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
894 height += wl_fixed_to_int(from_y - to_y);
895 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
896 height += wl_fixed_to_int(to_y - from_y);
899 shsurf->client->send_configure(shsurf->surface,
900 resize->edges, width, height);
904 send_configure(struct weston_surface *surface,
905 uint32_t edges, int32_t width, int32_t height)
907 struct shell_surface *shsurf = get_shell_surface(surface);
909 wl_shell_surface_send_configure(&shsurf->resource,
910 edges, width, height);
913 static const struct weston_shell_client shell_client = {
918 resize_grab_button(struct wl_pointer_grab *grab,
919 uint32_t time, uint32_t button, uint32_t state_w)
921 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
922 struct wl_pointer *pointer = grab->pointer;
923 enum wl_pointer_button_state state = state_w;
925 if (pointer->button_count == 0 &&
926 state == WL_POINTER_BUTTON_STATE_RELEASED) {
927 shell_grab_end(&resize->base);
932 static const struct wl_pointer_grab_interface resize_grab_interface = {
939 surface_resize(struct shell_surface *shsurf,
940 struct weston_seat *ws, uint32_t edges)
942 struct weston_resize_grab *resize;
944 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
947 if (edges == 0 || edges > 15 ||
948 (edges & 3) == 3 || (edges & 12) == 12)
951 resize = malloc(sizeof *resize);
955 resize->edges = edges;
956 resize->width = shsurf->surface->geometry.width;
957 resize->height = shsurf->surface->geometry.height;
959 shell_grab_start(&resize->base, &resize_grab_interface, shsurf,
960 ws->seat.pointer, edges);
966 shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
967 struct wl_resource *seat_resource, uint32_t serial,
970 struct weston_seat *ws = seat_resource->data;
971 struct shell_surface *shsurf = resource->data;
973 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
976 if (ws->seat.pointer->button_count == 0 ||
977 ws->seat.pointer->grab_serial != serial ||
978 ws->seat.pointer->focus != &shsurf->surface->surface)
981 if (surface_resize(shsurf, ws, edges) < 0)
982 wl_resource_post_no_memory(resource);
986 busy_cursor_grab_focus(struct wl_pointer_grab *base,
987 struct wl_surface *surface, int32_t x, int32_t y)
989 struct shell_grab *grab = (struct shell_grab *) base;
991 if (grab->grab.focus != surface) {
992 shell_grab_end(grab);
998 busy_cursor_grab_motion(struct wl_pointer_grab *grab,
999 uint32_t time, int32_t x, int32_t y)
1004 busy_cursor_grab_button(struct wl_pointer_grab *base,
1005 uint32_t time, uint32_t button, uint32_t state)
1007 struct shell_grab *grab = (struct shell_grab *) base;
1008 struct shell_surface *shsurf;
1009 struct weston_surface *surface =
1010 (struct weston_surface *) grab->grab.pointer->current;
1011 struct weston_seat *seat =
1012 (struct weston_seat *) grab->grab.pointer->seat;
1014 shsurf = get_shell_surface(surface);
1015 if (shsurf && button == BTN_LEFT && state) {
1016 activate(shsurf->shell, shsurf->surface, seat);
1017 surface_move(shsurf, seat);
1021 static const struct wl_pointer_grab_interface busy_cursor_grab_interface = {
1022 busy_cursor_grab_focus,
1023 busy_cursor_grab_motion,
1024 busy_cursor_grab_button,
1028 set_busy_cursor(struct shell_surface *shsurf, struct wl_pointer *pointer)
1030 struct shell_grab *grab;
1032 grab = malloc(sizeof *grab);
1036 shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer,
1037 DESKTOP_SHELL_CURSOR_BUSY);
1041 end_busy_cursor(struct shell_surface *shsurf, struct wl_pointer *pointer)
1043 struct shell_grab *grab = (struct shell_grab *) pointer->grab;
1045 if (grab->grab.interface == &busy_cursor_grab_interface) {
1046 shell_grab_end(grab);
1052 ping_timer_destroy(struct shell_surface *shsurf)
1054 if (!shsurf || !shsurf->ping_timer)
1057 if (shsurf->ping_timer->source)
1058 wl_event_source_remove(shsurf->ping_timer->source);
1060 free(shsurf->ping_timer);
1061 shsurf->ping_timer = NULL;
1065 ping_timeout_handler(void *data)
1067 struct shell_surface *shsurf = data;
1068 struct weston_seat *seat;
1070 /* Client is not responding */
1071 shsurf->unresponsive = 1;
1073 wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link)
1074 if (seat->seat.pointer->focus == &shsurf->surface->surface)
1075 set_busy_cursor(shsurf, seat->seat.pointer);
1081 ping_handler(struct weston_surface *surface, uint32_t serial)
1083 struct shell_surface *shsurf = get_shell_surface(surface);
1084 struct wl_event_loop *loop;
1085 int ping_timeout = 200;
1089 if (!shsurf->resource.client)
1092 if (shsurf->surface == shsurf->shell->grab_surface)
1095 if (!shsurf->ping_timer) {
1096 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
1097 if (!shsurf->ping_timer)
1100 shsurf->ping_timer->serial = serial;
1101 loop = wl_display_get_event_loop(surface->compositor->wl_display);
1102 shsurf->ping_timer->source =
1103 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
1104 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
1106 wl_shell_surface_send_ping(&shsurf->resource, serial);
1111 handle_pointer_focus(struct wl_listener *listener, void *data)
1113 struct wl_pointer *pointer = data;
1114 struct weston_surface *surface =
1115 (struct weston_surface *) pointer->focus;
1116 struct weston_compositor *compositor;
1117 struct shell_surface *shsurf;
1123 compositor = surface->compositor;
1124 shsurf = get_shell_surface(surface);
1126 if (shsurf && shsurf->unresponsive) {
1127 set_busy_cursor(shsurf, pointer);
1129 serial = wl_display_next_serial(compositor->wl_display);
1130 ping_handler(surface, serial);
1135 create_pointer_focus_listener(struct weston_seat *seat)
1137 struct wl_listener *listener;
1139 if (!seat->seat.pointer)
1142 listener = malloc(sizeof *listener);
1143 listener->notify = handle_pointer_focus;
1144 wl_signal_add(&seat->seat.pointer->focus_signal, listener);
1148 shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
1151 struct shell_surface *shsurf = resource->data;
1152 struct desktop_shell *shell = shsurf->shell;
1153 struct weston_seat *seat;
1154 struct weston_compositor *ec = shsurf->surface->compositor;
1155 struct wl_pointer *pointer;
1156 int was_unresponsive;
1158 if (shsurf->ping_timer == NULL)
1159 /* Just ignore unsolicited pong. */
1162 if (shsurf->ping_timer->serial == serial) {
1163 was_unresponsive = shsurf->unresponsive;
1164 shsurf->unresponsive = 0;
1165 if (was_unresponsive) {
1166 /* Received pong from previously unresponsive client */
1167 wl_list_for_each(seat, &ec->seat_list, link) {
1168 pointer = seat->seat.pointer;
1169 if (pointer->focus ==
1170 &shell->grab_surface->surface &&
1172 &shsurf->surface->surface)
1173 end_busy_cursor(shsurf, pointer);
1176 ping_timer_destroy(shsurf);
1181 shell_surface_set_title(struct wl_client *client,
1182 struct wl_resource *resource, const char *title)
1184 struct shell_surface *shsurf = resource->data;
1186 free(shsurf->title);
1187 shsurf->title = strdup(title);
1191 shell_surface_set_class(struct wl_client *client,
1192 struct wl_resource *resource, const char *class)
1194 struct shell_surface *shsurf = resource->data;
1196 free(shsurf->class);
1197 shsurf->class = strdup(class);
1200 static struct weston_output *
1201 get_default_output(struct weston_compositor *compositor)
1203 return container_of(compositor->output_list.next,
1204 struct weston_output, link);
1208 shell_unset_fullscreen(struct shell_surface *shsurf)
1210 /* undo all fullscreen things here */
1211 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1212 shell_surface_is_top_fullscreen(shsurf)) {
1213 weston_output_switch_mode(shsurf->fullscreen_output,
1214 shsurf->fullscreen_output->origin);
1216 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1217 shsurf->fullscreen.framerate = 0;
1218 wl_list_remove(&shsurf->fullscreen.transform.link);
1219 wl_list_init(&shsurf->fullscreen.transform.link);
1220 if (shsurf->fullscreen.black_surface)
1221 weston_surface_destroy(shsurf->fullscreen.black_surface);
1222 shsurf->fullscreen.black_surface = NULL;
1223 shsurf->fullscreen_output = NULL;
1224 weston_surface_set_position(shsurf->surface,
1225 shsurf->saved_x, shsurf->saved_y);
1226 if (shsurf->saved_rotation_valid) {
1227 wl_list_insert(&shsurf->surface->geometry.transformation_list,
1228 &shsurf->rotation.transform.link);
1229 shsurf->saved_rotation_valid = false;
1234 reset_shell_surface_type(struct shell_surface *surface)
1236 switch (surface->type) {
1237 case SHELL_SURFACE_FULLSCREEN:
1238 shell_unset_fullscreen(surface);
1240 case SHELL_SURFACE_MAXIMIZED:
1241 surface->output = get_default_output(surface->surface->compositor);
1242 weston_surface_set_position(surface->surface,
1246 case SHELL_SURFACE_NONE:
1247 case SHELL_SURFACE_TOPLEVEL:
1248 case SHELL_SURFACE_TRANSIENT:
1249 case SHELL_SURFACE_POPUP:
1253 surface->type = SHELL_SURFACE_NONE;
1258 set_surface_type(struct shell_surface *shsurf)
1260 struct weston_surface *surface = shsurf->surface;
1261 struct weston_surface *pes = shsurf->parent;
1263 reset_shell_surface_type(shsurf);
1265 shsurf->type = shsurf->next_type;
1266 shsurf->next_type = SHELL_SURFACE_NONE;
1268 switch (shsurf->type) {
1269 case SHELL_SURFACE_TOPLEVEL:
1271 case SHELL_SURFACE_TRANSIENT:
1272 weston_surface_set_position(surface,
1273 pes->geometry.x + shsurf->transient.x,
1274 pes->geometry.y + shsurf->transient.y);
1277 case SHELL_SURFACE_MAXIMIZED:
1278 shsurf->saved_x = surface->geometry.x;
1279 shsurf->saved_y = surface->geometry.y;
1280 shsurf->saved_position_valid = true;
1283 case SHELL_SURFACE_FULLSCREEN:
1284 shsurf->saved_x = surface->geometry.x;
1285 shsurf->saved_y = surface->geometry.y;
1286 shsurf->saved_position_valid = true;
1288 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
1289 wl_list_remove(&shsurf->rotation.transform.link);
1290 wl_list_init(&shsurf->rotation.transform.link);
1291 shsurf->surface->geometry.dirty = 1;
1292 shsurf->saved_rotation_valid = true;
1302 set_toplevel(struct shell_surface *shsurf)
1304 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
1308 shell_surface_set_toplevel(struct wl_client *client,
1309 struct wl_resource *resource)
1311 struct shell_surface *surface = resource->data;
1313 set_toplevel(surface);
1317 set_transient(struct shell_surface *shsurf,
1318 struct weston_surface *parent, int x, int y, uint32_t flags)
1320 /* assign to parents output */
1321 shsurf->parent = parent;
1322 shsurf->transient.x = x;
1323 shsurf->transient.y = y;
1324 shsurf->transient.flags = flags;
1325 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
1329 shell_surface_set_transient(struct wl_client *client,
1330 struct wl_resource *resource,
1331 struct wl_resource *parent_resource,
1332 int x, int y, uint32_t flags)
1334 struct shell_surface *shsurf = resource->data;
1335 struct weston_surface *parent = parent_resource->data;
1337 set_transient(shsurf, parent, x, y, flags);
1340 static struct desktop_shell *
1341 shell_surface_get_shell(struct shell_surface *shsurf)
1343 return shsurf->shell;
1347 get_output_panel_height(struct desktop_shell *shell,
1348 struct weston_output *output)
1350 struct weston_surface *surface;
1351 int panel_height = 0;
1356 wl_list_for_each(surface, &shell->panel_layer.surface_list, layer_link) {
1357 if (surface->output == output) {
1358 panel_height = surface->geometry.height;
1363 return panel_height;
1367 shell_surface_set_maximized(struct wl_client *client,
1368 struct wl_resource *resource,
1369 struct wl_resource *output_resource )
1371 struct shell_surface *shsurf = resource->data;
1372 struct weston_surface *es = shsurf->surface;
1373 struct desktop_shell *shell = NULL;
1374 uint32_t edges = 0, panel_height = 0;
1376 /* get the default output, if the client set it as NULL
1377 check whether the ouput is available */
1378 if (output_resource)
1379 shsurf->output = output_resource->data;
1380 else if (es->output)
1381 shsurf->output = es->output;
1383 shsurf->output = get_default_output(es->compositor);
1385 shell = shell_surface_get_shell(shsurf);
1386 panel_height = get_output_panel_height(shell, shsurf->output);
1387 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
1389 shsurf->client->send_configure(shsurf->surface, edges,
1390 shsurf->output->current->width,
1391 shsurf->output->current->height - panel_height);
1393 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
1397 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy);
1399 static struct weston_surface *
1400 create_black_surface(struct weston_compositor *ec,
1401 struct weston_surface *fs_surface,
1402 GLfloat x, GLfloat y, int w, int h)
1404 struct weston_surface *surface = NULL;
1406 surface = weston_surface_create(ec);
1407 if (surface == NULL) {
1408 weston_log("no memory\n");
1412 surface->configure = black_surface_configure;
1413 surface->private = fs_surface;
1414 weston_surface_configure(surface, x, y, w, h);
1415 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
1416 pixman_region32_init_rect(&surface->opaque, 0, 0, w, h);
1421 /* Create black surface and append it to the associated fullscreen surface.
1422 * Handle size dismatch and positioning according to the method. */
1424 shell_configure_fullscreen(struct shell_surface *shsurf)
1426 struct weston_output *output = shsurf->fullscreen_output;
1427 struct weston_surface *surface = shsurf->surface;
1428 struct weston_matrix *matrix;
1429 float scale, output_aspect, surface_aspect, x, y;
1431 if (!shsurf->fullscreen.black_surface)
1432 shsurf->fullscreen.black_surface =
1433 create_black_surface(surface->compositor,
1435 output->x, output->y,
1436 output->current->width,
1437 output->current->height);
1439 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
1440 wl_list_insert(&surface->layer_link,
1441 &shsurf->fullscreen.black_surface->layer_link);
1442 shsurf->fullscreen.black_surface->output = output;
1444 switch (shsurf->fullscreen.type) {
1445 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
1446 if (surface->buffer)
1447 center_on_output(surface, shsurf->fullscreen_output);
1449 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
1450 matrix = &shsurf->fullscreen.transform.matrix;
1451 weston_matrix_init(matrix);
1453 output_aspect = (float) output->current->width /
1454 (float) output->current->height;
1455 surface_aspect = (float) surface->geometry.width /
1456 (float) surface->geometry.height;
1457 if (output_aspect < surface_aspect)
1458 scale = (float) output->current->width /
1459 (float) surface->geometry.width;
1461 scale = (float) output->current->height /
1462 (float) surface->geometry.height;
1464 weston_matrix_scale(matrix, scale, scale, 1);
1465 wl_list_remove(&shsurf->fullscreen.transform.link);
1466 wl_list_insert(&surface->geometry.transformation_list,
1467 &shsurf->fullscreen.transform.link);
1468 x = output->x + (output->current->width - surface->geometry.width * scale) / 2;
1469 y = output->y + (output->current->height - surface->geometry.height * scale) / 2;
1470 weston_surface_set_position(surface, x, y);
1473 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
1474 if (shell_surface_is_top_fullscreen(shsurf)) {
1475 struct weston_mode mode = {0,
1476 surface->geometry.width,
1477 surface->geometry.height,
1478 shsurf->fullscreen.framerate};
1480 if (weston_output_switch_mode(output, &mode) == 0) {
1481 weston_surface_configure(shsurf->fullscreen.black_surface,
1482 output->x, output->y,
1483 output->current->width,
1484 output->current->height);
1485 weston_surface_set_position(surface, output->x, output->y);
1490 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
1497 /* make the fullscreen and black surface at the top */
1499 shell_stack_fullscreen(struct shell_surface *shsurf)
1501 struct weston_output *output = shsurf->fullscreen_output;
1502 struct weston_surface *surface = shsurf->surface;
1503 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
1505 wl_list_remove(&surface->layer_link);
1506 wl_list_insert(&shell->fullscreen_layer.surface_list,
1507 &surface->layer_link);
1508 weston_surface_damage(surface);
1510 if (!shsurf->fullscreen.black_surface)
1511 shsurf->fullscreen.black_surface =
1512 create_black_surface(surface->compositor,
1514 output->x, output->y,
1515 output->current->width,
1516 output->current->height);
1518 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
1519 wl_list_insert(&surface->layer_link,
1520 &shsurf->fullscreen.black_surface->layer_link);
1521 weston_surface_damage(shsurf->fullscreen.black_surface);
1525 shell_map_fullscreen(struct shell_surface *shsurf)
1527 shell_stack_fullscreen(shsurf);
1528 shell_configure_fullscreen(shsurf);
1532 shell_surface_set_fullscreen(struct wl_client *client,
1533 struct wl_resource *resource,
1536 struct wl_resource *output_resource)
1538 struct shell_surface *shsurf = resource->data;
1539 struct weston_surface *es = shsurf->surface;
1541 if (output_resource)
1542 shsurf->output = output_resource->data;
1543 else if (es->output)
1544 shsurf->output = es->output;
1546 shsurf->output = get_default_output(es->compositor);
1548 shsurf->fullscreen_output = shsurf->output;
1549 shsurf->fullscreen.type = method;
1550 shsurf->fullscreen.framerate = framerate;
1551 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
1553 shsurf->client->send_configure(shsurf->surface, 0,
1554 shsurf->output->current->width,
1555 shsurf->output->current->height);
1559 popup_grab_focus(struct wl_pointer_grab *grab,
1560 struct wl_surface *surface,
1564 struct wl_pointer *pointer = grab->pointer;
1565 struct shell_surface *priv =
1566 container_of(grab, struct shell_surface, popup.grab);
1567 struct wl_client *client = priv->surface->surface.resource.client;
1569 if (surface && surface->resource.client == client) {
1570 wl_pointer_set_focus(pointer, surface, x, y);
1571 grab->focus = surface;
1573 wl_pointer_set_focus(pointer, NULL,
1574 wl_fixed_from_int(0),
1575 wl_fixed_from_int(0));
1581 popup_grab_motion(struct wl_pointer_grab *grab,
1582 uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
1584 struct wl_resource *resource;
1586 resource = grab->pointer->focus_resource;
1588 wl_pointer_send_motion(resource, time, sx, sy);
1592 popup_grab_button(struct wl_pointer_grab *grab,
1593 uint32_t time, uint32_t button, uint32_t state_w)
1595 struct wl_resource *resource;
1596 struct shell_surface *shsurf =
1597 container_of(grab, struct shell_surface, popup.grab);
1598 struct wl_display *display;
1599 enum wl_pointer_button_state state = state_w;
1602 resource = grab->pointer->focus_resource;
1604 display = wl_client_get_display(resource->client);
1605 serial = wl_display_get_serial(display);
1606 wl_pointer_send_button(resource, serial, time, button, state);
1607 } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
1608 (shsurf->popup.initial_up ||
1609 time - shsurf->popup.seat->pointer->grab_time > 500)) {
1610 wl_shell_surface_send_popup_done(&shsurf->resource);
1611 wl_pointer_end_grab(grab->pointer);
1612 shsurf->popup.grab.pointer = NULL;
1615 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
1616 shsurf->popup.initial_up = 1;
1619 static const struct wl_pointer_grab_interface popup_grab_interface = {
1626 shell_map_popup(struct shell_surface *shsurf)
1628 struct wl_seat *seat = shsurf->popup.seat;
1629 struct weston_surface *es = shsurf->surface;
1630 struct weston_surface *parent = shsurf->parent;
1632 es->output = parent->output;
1633 shsurf->popup.grab.interface = &popup_grab_interface;
1635 weston_surface_update_transform(parent);
1636 if (parent->transform.enabled) {
1637 shsurf->popup.parent_transform.matrix =
1638 parent->transform.matrix;
1640 /* construct x, y translation matrix */
1641 weston_matrix_init(&shsurf->popup.parent_transform.matrix);
1642 shsurf->popup.parent_transform.matrix.d[12] =
1644 shsurf->popup.parent_transform.matrix.d[13] =
1647 wl_list_insert(es->geometry.transformation_list.prev,
1648 &shsurf->popup.parent_transform.link);
1649 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
1651 shsurf->popup.initial_up = 0;
1653 /* We don't require the grab to still be active, but if another
1654 * grab has started in the meantime, we end the popup now. */
1655 if (seat->pointer->grab_serial == shsurf->popup.serial) {
1656 wl_pointer_start_grab(seat->pointer, &shsurf->popup.grab);
1658 wl_shell_surface_send_popup_done(&shsurf->resource);
1663 shell_surface_set_popup(struct wl_client *client,
1664 struct wl_resource *resource,
1665 struct wl_resource *seat_resource,
1667 struct wl_resource *parent_resource,
1668 int32_t x, int32_t y, uint32_t flags)
1670 struct shell_surface *shsurf = resource->data;
1672 shsurf->type = SHELL_SURFACE_POPUP;
1673 shsurf->parent = parent_resource->data;
1674 shsurf->popup.seat = seat_resource->data;
1675 shsurf->popup.serial = serial;
1676 shsurf->popup.x = x;
1677 shsurf->popup.y = y;
1680 static const struct wl_shell_surface_interface shell_surface_implementation = {
1683 shell_surface_resize,
1684 shell_surface_set_toplevel,
1685 shell_surface_set_transient,
1686 shell_surface_set_fullscreen,
1687 shell_surface_set_popup,
1688 shell_surface_set_maximized,
1689 shell_surface_set_title,
1690 shell_surface_set_class
1694 destroy_shell_surface(struct shell_surface *shsurf)
1696 if (shsurf->popup.grab.pointer)
1697 wl_pointer_end_grab(shsurf->popup.grab.pointer);
1699 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1700 shell_surface_is_top_fullscreen(shsurf)) {
1701 weston_output_switch_mode(shsurf->fullscreen_output,
1702 shsurf->fullscreen_output->origin);
1705 if (shsurf->fullscreen.black_surface)
1706 weston_surface_destroy(shsurf->fullscreen.black_surface);
1708 /* As destroy_resource() use wl_list_for_each_safe(),
1709 * we can always remove the listener.
1711 wl_list_remove(&shsurf->surface_destroy_listener.link);
1712 shsurf->surface->configure = NULL;
1713 ping_timer_destroy(shsurf);
1715 wl_list_remove(&shsurf->link);
1720 shell_destroy_shell_surface(struct wl_resource *resource)
1722 struct shell_surface *shsurf = resource->data;
1724 destroy_shell_surface(shsurf);
1728 shell_handle_surface_destroy(struct wl_listener *listener, void *data)
1730 struct shell_surface *shsurf = container_of(listener,
1731 struct shell_surface,
1732 surface_destroy_listener);
1734 if (shsurf->resource.client) {
1735 wl_resource_destroy(&shsurf->resource);
1737 wl_signal_emit(&shsurf->resource.destroy_signal,
1739 destroy_shell_surface(shsurf);
1744 shell_surface_configure(struct weston_surface *, int32_t, int32_t);
1746 static struct shell_surface *
1747 get_shell_surface(struct weston_surface *surface)
1749 if (surface->configure == shell_surface_configure)
1750 return surface->private;
1755 static struct shell_surface *
1756 create_shell_surface(void *shell, struct weston_surface *surface,
1757 const struct weston_shell_client *client)
1759 struct shell_surface *shsurf;
1761 if (surface->configure) {
1762 weston_log("surface->configure already set\n");
1766 shsurf = calloc(1, sizeof *shsurf);
1768 weston_log("no memory to allocate shell surface\n");
1772 surface->configure = shell_surface_configure;
1773 surface->private = shsurf;
1775 shsurf->shell = (struct desktop_shell *) shell;
1776 shsurf->unresponsive = 0;
1777 shsurf->saved_position_valid = false;
1778 shsurf->saved_rotation_valid = false;
1779 shsurf->surface = surface;
1780 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1781 shsurf->fullscreen.framerate = 0;
1782 shsurf->fullscreen.black_surface = NULL;
1783 shsurf->ping_timer = NULL;
1784 wl_list_init(&shsurf->fullscreen.transform.link);
1786 wl_signal_init(&shsurf->resource.destroy_signal);
1787 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
1788 wl_signal_add(&surface->surface.resource.destroy_signal,
1789 &shsurf->surface_destroy_listener);
1791 /* init link so its safe to always remove it in destroy_shell_surface */
1792 wl_list_init(&shsurf->link);
1794 /* empty when not in use */
1795 wl_list_init(&shsurf->rotation.transform.link);
1796 weston_matrix_init(&shsurf->rotation.rotation);
1798 wl_list_init(&shsurf->workspace_transform.link);
1800 shsurf->type = SHELL_SURFACE_NONE;
1801 shsurf->next_type = SHELL_SURFACE_NONE;
1803 shsurf->client = client;
1809 shell_get_shell_surface(struct wl_client *client,
1810 struct wl_resource *resource,
1812 struct wl_resource *surface_resource)
1814 struct weston_surface *surface = surface_resource->data;
1815 struct desktop_shell *shell = resource->data;
1816 struct shell_surface *shsurf;
1818 if (get_shell_surface(surface)) {
1819 wl_resource_post_error(surface_resource,
1820 WL_DISPLAY_ERROR_INVALID_OBJECT,
1821 "desktop_shell::get_shell_surface already requested");
1825 shsurf = create_shell_surface(shell, surface, &shell_client);
1827 wl_resource_post_error(surface_resource,
1828 WL_DISPLAY_ERROR_INVALID_OBJECT,
1829 "surface->configure already set");
1833 shsurf->resource.destroy = shell_destroy_shell_surface;
1834 shsurf->resource.object.id = id;
1835 shsurf->resource.object.interface = &wl_shell_surface_interface;
1836 shsurf->resource.object.implementation =
1837 (void (**)(void)) &shell_surface_implementation;
1838 shsurf->resource.data = shsurf;
1840 wl_client_add_resource(client, &shsurf->resource);
1843 static const struct wl_shell_interface shell_implementation = {
1844 shell_get_shell_surface
1848 handle_screensaver_sigchld(struct weston_process *proc, int status)
1854 launch_screensaver(struct desktop_shell *shell)
1856 if (shell->screensaver.binding)
1859 if (!shell->screensaver.path)
1862 if (shell->screensaver.process.pid != 0) {
1863 weston_log("old screensaver still running\n");
1867 weston_client_launch(shell->compositor,
1868 &shell->screensaver.process,
1869 shell->screensaver.path,
1870 handle_screensaver_sigchld);
1874 terminate_screensaver(struct desktop_shell *shell)
1876 if (shell->screensaver.process.pid == 0)
1879 kill(shell->screensaver.process.pid, SIGTERM);
1883 configure_static_surface(struct weston_surface *es, struct weston_layer *layer)
1885 struct weston_surface *s, *next;
1887 wl_list_for_each_safe(s, next, &layer->surface_list, layer_link) {
1888 if (s->output == es->output && s != es) {
1889 weston_surface_unmap(s);
1890 s->configure = NULL;
1894 weston_surface_configure(es, es->output->x, es->output->y,
1895 es->buffer->width, es->buffer->height);
1897 if (wl_list_empty(&es->layer_link)) {
1898 wl_list_insert(&layer->surface_list, &es->layer_link);
1899 weston_compositor_schedule_repaint(es->compositor);
1904 background_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1906 struct desktop_shell *shell = es->private;
1908 configure_static_surface(es, &shell->background_layer);
1912 desktop_shell_set_background(struct wl_client *client,
1913 struct wl_resource *resource,
1914 struct wl_resource *output_resource,
1915 struct wl_resource *surface_resource)
1917 struct desktop_shell *shell = resource->data;
1918 struct weston_surface *surface = surface_resource->data;
1920 if (surface->configure) {
1921 wl_resource_post_error(surface_resource,
1922 WL_DISPLAY_ERROR_INVALID_OBJECT,
1923 "surface role already assigned");
1927 surface->configure = background_configure;
1928 surface->private = shell;
1929 surface->output = output_resource->data;
1930 desktop_shell_send_configure(resource, 0,
1932 surface->output->current->width,
1933 surface->output->current->height);
1937 panel_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1939 struct desktop_shell *shell = es->private;
1941 configure_static_surface(es, &shell->panel_layer);
1945 desktop_shell_set_panel(struct wl_client *client,
1946 struct wl_resource *resource,
1947 struct wl_resource *output_resource,
1948 struct wl_resource *surface_resource)
1950 struct desktop_shell *shell = resource->data;
1951 struct weston_surface *surface = surface_resource->data;
1953 if (surface->configure) {
1954 wl_resource_post_error(surface_resource,
1955 WL_DISPLAY_ERROR_INVALID_OBJECT,
1956 "surface role already assigned");
1960 surface->configure = panel_configure;
1961 surface->private = shell;
1962 surface->output = output_resource->data;
1963 desktop_shell_send_configure(resource, 0,
1965 surface->output->current->width,
1966 surface->output->current->height);
1970 lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
1972 struct desktop_shell *shell = surface->private;
1974 center_on_output(surface, get_default_output(shell->compositor));
1976 if (!weston_surface_is_mapped(surface)) {
1977 wl_list_insert(&shell->lock_layer.surface_list,
1978 &surface->layer_link);
1979 weston_surface_assign_output(surface);
1980 weston_compositor_wake(shell->compositor);
1985 handle_lock_surface_destroy(struct wl_listener *listener, void *data)
1987 struct desktop_shell *shell =
1988 container_of(listener, struct desktop_shell, lock_surface_listener);
1990 weston_log("lock surface gone\n");
1991 shell->lock_surface = NULL;
1995 desktop_shell_set_lock_surface(struct wl_client *client,
1996 struct wl_resource *resource,
1997 struct wl_resource *surface_resource)
1999 struct desktop_shell *shell = resource->data;
2000 struct weston_surface *surface = surface_resource->data;
2002 shell->prepare_event_sent = false;
2007 shell->lock_surface = surface;
2009 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
2010 wl_signal_add(&surface_resource->destroy_signal,
2011 &shell->lock_surface_listener);
2013 surface->configure = lock_surface_configure;
2014 surface->private = shell;
2018 resume_desktop(struct desktop_shell *shell)
2020 struct weston_surface *surface;
2021 struct workspace *ws = get_current_workspace(shell);
2023 wl_list_for_each(surface, &shell->screensaver.surfaces, link)
2024 weston_surface_unmap(surface);
2026 terminate_screensaver(shell);
2028 wl_list_remove(&shell->lock_layer.link);
2029 wl_list_insert(&shell->compositor->cursor_layer.link,
2030 &shell->fullscreen_layer.link);
2031 wl_list_insert(&shell->fullscreen_layer.link,
2032 &shell->panel_layer.link);
2033 if (shell->showing_input_panels) {
2034 wl_list_insert(&shell->panel_layer.link,
2035 &shell->input_panel_layer.link);
2036 wl_list_insert(&shell->input_panel_layer.link,
2039 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
2042 restore_focus_state(shell, get_current_workspace(shell));
2044 shell->locked = false;
2045 shell->compositor->idle_time = shell->compositor->option_idle_time;
2046 weston_compositor_wake(shell->compositor);
2047 weston_compositor_damage_all(shell->compositor);
2051 desktop_shell_unlock(struct wl_client *client,
2052 struct wl_resource *resource)
2054 struct desktop_shell *shell = resource->data;
2056 shell->prepare_event_sent = false;
2059 resume_desktop(shell);
2063 desktop_shell_set_grab_surface(struct wl_client *client,
2064 struct wl_resource *resource,
2065 struct wl_resource *surface_resource)
2067 struct desktop_shell *shell = resource->data;
2069 shell->grab_surface = surface_resource->data;
2072 static const struct desktop_shell_interface desktop_shell_implementation = {
2073 desktop_shell_set_background,
2074 desktop_shell_set_panel,
2075 desktop_shell_set_lock_surface,
2076 desktop_shell_unlock,
2077 desktop_shell_set_grab_surface
2080 static enum shell_surface_type
2081 get_shell_surface_type(struct weston_surface *surface)
2083 struct shell_surface *shsurf;
2085 shsurf = get_shell_surface(surface);
2087 return SHELL_SURFACE_NONE;
2088 return shsurf->type;
2092 move_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data)
2094 struct weston_surface *surface =
2095 (struct weston_surface *) seat->pointer->focus;
2096 struct shell_surface *shsurf;
2098 if (surface == NULL)
2101 shsurf = get_shell_surface(surface);
2102 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN)
2105 surface_move(shsurf, (struct weston_seat *) seat);
2109 resize_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data)
2111 struct weston_surface *surface =
2112 (struct weston_surface *) seat->pointer->focus;
2115 struct shell_surface *shsurf;
2117 if (surface == NULL)
2120 shsurf = get_shell_surface(surface);
2121 if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN)
2124 weston_surface_from_global(surface,
2125 wl_fixed_to_int(seat->pointer->grab_x),
2126 wl_fixed_to_int(seat->pointer->grab_y),
2129 if (x < surface->geometry.width / 3)
2130 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
2131 else if (x < 2 * surface->geometry.width / 3)
2134 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
2136 if (y < surface->geometry.height / 3)
2137 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
2138 else if (y < 2 * surface->geometry.height / 3)
2141 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
2143 surface_resize(shsurf, (struct weston_seat *) seat, edges);
2147 surface_opacity_binding(struct wl_seat *seat, uint32_t time, uint32_t axis,
2148 wl_fixed_t value, void *data)
2151 struct shell_surface *shsurf;
2152 struct weston_surface *surface =
2153 (struct weston_surface *) seat->pointer->focus;
2155 if (surface == NULL)
2158 shsurf = get_shell_surface(surface);
2162 surface->alpha += wl_fixed_to_double(value) * step;
2164 if (surface->alpha > 1.0)
2165 surface->alpha = 1.0;
2166 if (surface->alpha < step)
2167 surface->alpha = step;
2169 surface->geometry.dirty = 1;
2170 weston_surface_damage(surface);
2174 do_zoom(struct wl_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
2177 struct weston_seat *ws = (struct weston_seat *) seat;
2178 struct weston_compositor *compositor = ws->compositor;
2179 struct weston_output *output;
2182 wl_list_for_each(output, &compositor->output_list, link) {
2183 if (pixman_region32_contains_point(&output->region,
2184 wl_fixed_to_double(seat->pointer->x),
2185 wl_fixed_to_double(seat->pointer->y),
2187 if (key == KEY_PAGEUP)
2188 increment = output->zoom.increment;
2189 else if (key == KEY_PAGEDOWN)
2190 increment = -output->zoom.increment;
2191 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
2192 increment = output->zoom.increment *
2193 wl_fixed_to_double(value);
2197 output->zoom.level += increment;
2199 if (output->zoom.level < 0.0)
2200 output->zoom.level = 0.0;
2201 else if (output->zoom.level > output->zoom.max_level)
2202 output->zoom.level = output->zoom.max_level;
2204 output->zoom.active = 1;
2205 output->disable_planes++;
2208 output->zoom.spring_z.target = output->zoom.level;
2210 weston_output_update_zoom(output, output->zoom.type);
2216 zoom_axis_binding(struct wl_seat *seat, uint32_t time, uint32_t axis,
2217 wl_fixed_t value, void *data)
2219 do_zoom(seat, time, 0, axis, value);
2223 zoom_key_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
2226 do_zoom(seat, time, key, 0, 0);
2230 terminate_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
2233 struct weston_compositor *compositor = data;
2235 wl_display_terminate(compositor->wl_display);
2239 rotate_grab_motion(struct wl_pointer_grab *grab,
2240 uint32_t time, wl_fixed_t x, wl_fixed_t y)
2242 struct rotate_grab *rotate =
2243 container_of(grab, struct rotate_grab, base.grab);
2244 struct wl_pointer *pointer = grab->pointer;
2245 struct shell_surface *shsurf = rotate->base.shsurf;
2246 struct weston_surface *surface;
2247 GLfloat cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
2252 surface = shsurf->surface;
2254 cx = 0.5f * surface->geometry.width;
2255 cy = 0.5f * surface->geometry.height;
2257 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
2258 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
2259 r = sqrtf(dx * dx + dy * dy);
2261 wl_list_remove(&shsurf->rotation.transform.link);
2262 shsurf->surface->geometry.dirty = 1;
2265 struct weston_matrix *matrix =
2266 &shsurf->rotation.transform.matrix;
2268 weston_matrix_init(&rotate->rotation);
2269 rotate->rotation.d[0] = dx / r;
2270 rotate->rotation.d[4] = -dy / r;
2271 rotate->rotation.d[1] = -rotate->rotation.d[4];
2272 rotate->rotation.d[5] = rotate->rotation.d[0];
2274 weston_matrix_init(matrix);
2275 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
2276 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
2277 weston_matrix_multiply(matrix, &rotate->rotation);
2278 weston_matrix_translate(matrix, cx, cy, 0.0f);
2281 &shsurf->surface->geometry.transformation_list,
2282 &shsurf->rotation.transform.link);
2284 wl_list_init(&shsurf->rotation.transform.link);
2285 weston_matrix_init(&shsurf->rotation.rotation);
2286 weston_matrix_init(&rotate->rotation);
2289 /* We need to adjust the position of the surface
2290 * in case it was resized in a rotated state before */
2291 cposx = surface->geometry.x + cx;
2292 cposy = surface->geometry.y + cy;
2293 dposx = rotate->center.x - cposx;
2294 dposy = rotate->center.y - cposy;
2295 if (dposx != 0.0f || dposy != 0.0f) {
2296 weston_surface_set_position(surface,
2297 surface->geometry.x + dposx,
2298 surface->geometry.y + dposy);
2301 /* Repaint implies weston_surface_update_transform(), which
2302 * lazily applies the damage due to rotation update.
2304 weston_compositor_schedule_repaint(shsurf->surface->compositor);
2308 rotate_grab_button(struct wl_pointer_grab *grab,
2309 uint32_t time, uint32_t button, uint32_t state_w)
2311 struct rotate_grab *rotate =
2312 container_of(grab, struct rotate_grab, base.grab);
2313 struct wl_pointer *pointer = grab->pointer;
2314 struct shell_surface *shsurf = rotate->base.shsurf;
2315 enum wl_pointer_button_state state = state_w;
2317 if (pointer->button_count == 0 &&
2318 state == WL_POINTER_BUTTON_STATE_RELEASED) {
2320 weston_matrix_multiply(&shsurf->rotation.rotation,
2322 shell_grab_end(&rotate->base);
2327 static const struct wl_pointer_grab_interface rotate_grab_interface = {
2334 rotate_binding(struct wl_seat *seat, uint32_t time, uint32_t button,
2337 struct weston_surface *base_surface =
2338 (struct weston_surface *) seat->pointer->focus;
2339 struct shell_surface *surface;
2340 struct rotate_grab *rotate;
2344 if (base_surface == NULL)
2347 surface = get_shell_surface(base_surface);
2348 if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN)
2351 rotate = malloc(sizeof *rotate);
2355 weston_surface_to_global_float(surface->surface,
2356 surface->surface->geometry.width / 2,
2357 surface->surface->geometry.height / 2,
2358 &rotate->center.x, &rotate->center.y);
2360 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
2361 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
2362 r = sqrtf(dx * dx + dy * dy);
2364 struct weston_matrix inverse;
2366 weston_matrix_init(&inverse);
2367 inverse.d[0] = dx / r;
2368 inverse.d[4] = dy / r;
2369 inverse.d[1] = -inverse.d[4];
2370 inverse.d[5] = inverse.d[0];
2371 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
2373 weston_matrix_init(&rotate->rotation);
2374 rotate->rotation.d[0] = dx / r;
2375 rotate->rotation.d[4] = -dy / r;
2376 rotate->rotation.d[1] = -rotate->rotation.d[4];
2377 rotate->rotation.d[5] = rotate->rotation.d[0];
2379 weston_matrix_init(&surface->rotation.rotation);
2380 weston_matrix_init(&rotate->rotation);
2383 shell_grab_start(&rotate->base, &rotate_grab_interface, surface,
2384 seat->pointer, DESKTOP_SHELL_CURSOR_ARROW);
2388 lower_fullscreen_layer(struct desktop_shell *shell)
2390 struct workspace *ws;
2391 struct weston_surface *surface, *prev;
2393 ws = get_current_workspace(shell);
2394 wl_list_for_each_reverse_safe(surface, prev,
2395 &shell->fullscreen_layer.surface_list,
2397 weston_surface_restack(surface, &ws->layer.surface_list);
2401 activate(struct desktop_shell *shell, struct weston_surface *es,
2402 struct weston_seat *seat)
2404 struct workspace *ws = get_current_workspace(shell);
2405 struct focus_state *state;
2407 weston_surface_activate(es, seat);
2409 wl_list_for_each(state, &ws->focus_list, link)
2410 if (state->seat == seat)
2413 if (&state->link == &ws->focus_list) {
2414 state = focus_state_create(seat, ws);
2419 state->keyboard_focus = es;
2420 wl_list_remove(&state->surface_destroy_listener.link);
2421 wl_signal_add(&es->surface.resource.destroy_signal,
2422 &state->surface_destroy_listener);
2424 switch (get_shell_surface_type(es)) {
2425 case SHELL_SURFACE_FULLSCREEN:
2426 /* should on top of panels */
2427 shell_stack_fullscreen(get_shell_surface(es));
2428 shell_configure_fullscreen(get_shell_surface(es));
2431 ws = get_current_workspace(shell);
2432 lower_fullscreen_layer(shell);
2433 weston_surface_restack(es, &ws->layer.surface_list);
2438 /* no-op func for checking black surface */
2440 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
2445 is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
2447 if (es->configure == black_surface_configure) {
2449 *fs_surface = (struct weston_surface *)es->private;
2456 click_to_activate_binding(struct wl_seat *seat, uint32_t time, uint32_t button,
2459 struct weston_seat *ws = (struct weston_seat *) seat;
2460 struct desktop_shell *shell = data;
2461 struct weston_surface *focus;
2462 struct weston_surface *upper;
2464 focus = (struct weston_surface *) seat->pointer->focus;
2468 if (is_black_surface(focus, &upper))
2471 if (get_shell_surface_type(focus) == SHELL_SURFACE_NONE)
2474 if (seat->pointer->grab == &seat->pointer->default_grab)
2475 activate(shell, focus, ws);
2479 lock(struct wl_listener *listener, void *data)
2481 struct desktop_shell *shell =
2482 container_of(listener, struct desktop_shell, lock_listener);
2483 struct weston_output *output;
2484 struct workspace *ws = get_current_workspace(shell);
2486 if (shell->locked) {
2487 wl_list_for_each(output, &shell->compositor->output_list, link)
2488 /* TODO: find a way to jump to other DPMS levels */
2489 if (output->set_dpms)
2490 output->set_dpms(output, WESTON_DPMS_STANDBY);
2494 shell->locked = true;
2496 /* Hide all surfaces by removing the fullscreen, panel and
2497 * toplevel layers. This way nothing else can show or receive
2498 * input events while we are locked. */
2500 wl_list_remove(&shell->panel_layer.link);
2501 wl_list_remove(&shell->fullscreen_layer.link);
2502 if (shell->showing_input_panels)
2503 wl_list_remove(&shell->input_panel_layer.link);
2504 wl_list_remove(&ws->layer.link);
2505 wl_list_insert(&shell->compositor->cursor_layer.link,
2506 &shell->lock_layer.link);
2508 launch_screensaver(shell);
2510 /* TODO: disable bindings that should not work while locked. */
2512 /* All this must be undone in resume_desktop(). */
2516 unlock(struct wl_listener *listener, void *data)
2518 struct desktop_shell *shell =
2519 container_of(listener, struct desktop_shell, unlock_listener);
2521 if (!shell->locked || shell->lock_surface) {
2522 weston_compositor_wake(shell->compositor);
2526 /* If desktop-shell client has gone away, unlock immediately. */
2527 if (!shell->child.desktop_shell) {
2528 resume_desktop(shell);
2532 if (shell->prepare_event_sent)
2535 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
2536 shell->prepare_event_sent = true;
2540 show_input_panels(struct wl_listener *listener, void *data)
2542 struct desktop_shell *shell =
2543 container_of(listener, struct desktop_shell,
2544 show_input_panel_listener);
2545 struct input_panel_surface *surface, *next;
2546 struct weston_surface *ws;
2548 shell->showing_input_panels = true;
2550 wl_list_insert(&shell->panel_layer.link,
2551 &shell->input_panel_layer.link);
2553 wl_list_for_each_safe(surface, next,
2554 &shell->input_panel.surfaces, link) {
2555 ws = surface->surface;
2556 wl_list_insert(&shell->input_panel_layer.surface_list,
2558 weston_surface_assign_output(ws);
2559 weston_surface_damage(ws);
2560 weston_slide_run(ws, ws->geometry.height, 0, NULL, NULL);
2565 hide_input_panels(struct wl_listener *listener, void *data)
2567 struct desktop_shell *shell =
2568 container_of(listener, struct desktop_shell,
2569 hide_input_panel_listener);
2570 struct weston_surface *surface, *next;
2572 shell->showing_input_panels = false;
2574 wl_list_remove(&shell->input_panel_layer.link);
2576 wl_list_for_each_safe(surface, next,
2577 &shell->input_panel_layer.surface_list, layer_link)
2578 weston_surface_unmap(surface);
2582 center_on_output(struct weston_surface *surface, struct weston_output *output)
2584 struct weston_mode *mode = output->current;
2585 GLfloat x = (mode->width - surface->buffer->width) / 2;
2586 GLfloat y = (mode->height - surface->buffer->height) / 2;
2588 weston_surface_configure(surface, output->x + x, output->y + y,
2589 surface->buffer->width,
2590 surface->buffer->height);
2594 map(struct desktop_shell *shell, struct weston_surface *surface,
2595 int32_t width, int32_t height, int32_t sx, int32_t sy)
2597 struct weston_compositor *compositor = shell->compositor;
2598 struct shell_surface *shsurf = get_shell_surface(surface);
2599 enum shell_surface_type surface_type = shsurf->type;
2600 struct weston_surface *parent;
2601 struct weston_seat *seat;
2602 struct workspace *ws;
2603 int panel_height = 0;
2605 surface->geometry.width = width;
2606 surface->geometry.height = height;
2607 surface->geometry.dirty = 1;
2609 /* initial positioning, see also configure() */
2610 switch (surface_type) {
2611 case SHELL_SURFACE_TOPLEVEL:
2612 weston_surface_set_position(surface, 10 + random() % 400,
2613 10 + random() % 400);
2615 case SHELL_SURFACE_FULLSCREEN:
2616 center_on_output(surface, shsurf->fullscreen_output);
2617 shell_map_fullscreen(shsurf);
2619 case SHELL_SURFACE_MAXIMIZED:
2620 /* use surface configure to set the geometry */
2621 panel_height = get_output_panel_height(shell,surface->output);
2622 weston_surface_set_position(surface, shsurf->output->x,
2623 shsurf->output->y + panel_height);
2625 case SHELL_SURFACE_POPUP:
2626 shell_map_popup(shsurf);
2627 case SHELL_SURFACE_NONE:
2628 weston_surface_set_position(surface,
2629 surface->geometry.x + sx,
2630 surface->geometry.y + sy);
2636 /* surface stacking order, see also activate() */
2637 switch (surface_type) {
2638 case SHELL_SURFACE_POPUP:
2639 case SHELL_SURFACE_TRANSIENT:
2640 parent = shsurf->parent;
2641 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
2643 case SHELL_SURFACE_FULLSCREEN:
2644 case SHELL_SURFACE_NONE:
2647 ws = get_current_workspace(shell);
2648 wl_list_insert(&ws->layer.surface_list, &surface->layer_link);
2652 if (surface_type != SHELL_SURFACE_NONE) {
2653 weston_surface_assign_output(surface);
2654 if (surface_type == SHELL_SURFACE_MAXIMIZED)
2655 surface->output = shsurf->output;
2658 switch (surface_type) {
2659 case SHELL_SURFACE_TRANSIENT:
2660 if (shsurf->transient.flags ==
2661 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
2663 case SHELL_SURFACE_TOPLEVEL:
2664 case SHELL_SURFACE_FULLSCREEN:
2665 case SHELL_SURFACE_MAXIMIZED:
2666 if (!shell->locked) {
2667 wl_list_for_each(seat, &compositor->seat_list, link)
2668 activate(shell, surface, seat);
2675 if (surface_type == SHELL_SURFACE_TOPLEVEL)
2677 switch (shell->win_animation_type) {
2678 case ANIMATION_FADE:
2679 weston_fade_run(surface, NULL, NULL);
2681 case ANIMATION_ZOOM:
2682 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
2691 configure(struct desktop_shell *shell, struct weston_surface *surface,
2692 GLfloat x, GLfloat y, int32_t width, int32_t height)
2694 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
2695 struct shell_surface *shsurf;
2697 shsurf = get_shell_surface(surface);
2699 surface_type = shsurf->type;
2701 surface->geometry.x = x;
2702 surface->geometry.y = y;
2703 surface->geometry.width = width;
2704 surface->geometry.height = height;
2705 surface->geometry.dirty = 1;
2707 switch (surface_type) {
2708 case SHELL_SURFACE_FULLSCREEN:
2709 shell_stack_fullscreen(shsurf);
2710 shell_configure_fullscreen(shsurf);
2712 case SHELL_SURFACE_MAXIMIZED:
2713 /* setting x, y and using configure to change that geometry */
2714 surface->geometry.x = surface->output->x;
2715 surface->geometry.y = surface->output->y +
2716 get_output_panel_height(shell,surface->output);
2718 case SHELL_SURFACE_TOPLEVEL:
2724 /* XXX: would a fullscreen surface need the same handling? */
2725 if (surface->output) {
2726 weston_surface_assign_output(surface);
2728 if (surface_type == SHELL_SURFACE_MAXIMIZED)
2729 surface->output = shsurf->output;
2734 shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
2736 struct shell_surface *shsurf = get_shell_surface(es);
2737 struct desktop_shell *shell = shsurf->shell;
2738 int type_changed = 0;
2740 if (shsurf->next_type != SHELL_SURFACE_NONE &&
2741 shsurf->type != shsurf->next_type) {
2742 set_surface_type(shsurf);
2746 if (!weston_surface_is_mapped(es)) {
2747 map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
2748 } else if (type_changed || sx != 0 || sy != 0 ||
2749 es->geometry.width != es->buffer->width ||
2750 es->geometry.height != es->buffer->height) {
2751 GLfloat from_x, from_y;
2754 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
2755 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
2756 configure(shell, es,
2757 es->geometry.x + to_x - from_x,
2758 es->geometry.y + to_y - from_y,
2759 es->buffer->width, es->buffer->height);
2763 static int launch_desktop_shell_process(struct desktop_shell *shell);
2766 desktop_shell_sigchld(struct weston_process *process, int status)
2769 struct desktop_shell *shell =
2770 container_of(process, struct desktop_shell, child.process);
2772 shell->child.process.pid = 0;
2773 shell->child.client = NULL; /* already destroyed by wayland */
2775 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
2776 time = weston_compositor_get_time();
2777 if (time - shell->child.deathstamp > 30000) {
2778 shell->child.deathstamp = time;
2779 shell->child.deathcount = 0;
2782 shell->child.deathcount++;
2783 if (shell->child.deathcount > 5) {
2784 weston_log("weston-desktop-shell died, giving up.\n");
2788 weston_log("weston-desktop-shell died, respawning...\n");
2789 launch_desktop_shell_process(shell);
2793 launch_desktop_shell_process(struct desktop_shell *shell)
2795 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
2797 shell->child.client = weston_client_launch(shell->compositor,
2798 &shell->child.process,
2800 desktop_shell_sigchld);
2802 if (!shell->child.client)
2808 bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
2810 struct desktop_shell *shell = data;
2812 wl_client_add_object(client, &wl_shell_interface,
2813 &shell_implementation, id, shell);
2817 unbind_desktop_shell(struct wl_resource *resource)
2819 struct desktop_shell *shell = resource->data;
2822 resume_desktop(shell);
2824 shell->child.desktop_shell = NULL;
2825 shell->prepare_event_sent = false;
2830 bind_desktop_shell(struct wl_client *client,
2831 void *data, uint32_t version, uint32_t id)
2833 struct desktop_shell *shell = data;
2834 struct wl_resource *resource;
2836 resource = wl_client_add_object(client, &desktop_shell_interface,
2837 &desktop_shell_implementation,
2840 if (client == shell->child.client) {
2841 resource->destroy = unbind_desktop_shell;
2842 shell->child.desktop_shell = resource;
2846 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2847 "permission to bind desktop_shell denied");
2848 wl_resource_destroy(resource);
2852 screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
2854 struct desktop_shell *shell = surface->private;
2859 center_on_output(surface, surface->output);
2861 if (wl_list_empty(&surface->layer_link)) {
2862 wl_list_insert(shell->lock_layer.surface_list.prev,
2863 &surface->layer_link);
2864 weston_surface_assign_output(surface);
2865 shell->compositor->idle_time = shell->screensaver.duration;
2866 weston_compositor_wake(shell->compositor);
2867 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
2872 screensaver_set_surface(struct wl_client *client,
2873 struct wl_resource *resource,
2874 struct wl_resource *surface_resource,
2875 struct wl_resource *output_resource)
2877 struct desktop_shell *shell = resource->data;
2878 struct weston_surface *surface = surface_resource->data;
2879 struct weston_output *output = output_resource->data;
2881 surface->configure = screensaver_configure;
2882 surface->private = shell;
2883 surface->output = output;
2886 static const struct screensaver_interface screensaver_implementation = {
2887 screensaver_set_surface
2891 unbind_screensaver(struct wl_resource *resource)
2893 struct desktop_shell *shell = resource->data;
2895 shell->screensaver.binding = NULL;
2900 bind_screensaver(struct wl_client *client,
2901 void *data, uint32_t version, uint32_t id)
2903 struct desktop_shell *shell = data;
2904 struct wl_resource *resource;
2906 resource = wl_client_add_object(client, &screensaver_interface,
2907 &screensaver_implementation,
2910 if (shell->screensaver.binding == NULL) {
2911 resource->destroy = unbind_screensaver;
2912 shell->screensaver.binding = resource;
2916 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2917 "interface object already bound");
2918 wl_resource_destroy(resource);
2922 input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
2924 struct weston_mode *mode = surface->output->current;
2925 GLfloat x = (mode->width - surface->buffer->width) / 2;
2926 GLfloat y = mode->height - surface->buffer->height;
2928 /* Don't map the input panel here, wait for
2929 * show_input_panels signal. */
2931 weston_surface_configure(surface,
2932 surface->output->x + x,
2933 surface->output->y + y,
2934 surface->buffer->width,
2935 surface->buffer->height);
2939 destroy_input_panel_surface(struct wl_listener *listener,
2942 struct input_panel_surface *input_panel_surface =
2943 container_of(listener, struct input_panel_surface, listener);
2945 wl_list_remove(&listener->link);
2946 wl_list_remove(&input_panel_surface->link);
2948 free(input_panel_surface);
2952 input_panel_set_surface(struct wl_client *client,
2953 struct wl_resource *resource,
2954 struct wl_resource *surface_resource,
2955 struct wl_resource *output_resource)
2957 struct desktop_shell *shell = resource->data;
2958 struct weston_surface *surface = surface_resource->data;
2959 struct weston_output *output = output_resource->data;
2960 struct input_panel_surface *input_panel_surface;
2962 surface->configure = input_panel_configure;
2963 surface->private = shell;
2964 surface->output = output;
2966 input_panel_surface = malloc(sizeof *input_panel_surface);
2967 if (!input_panel_surface) {
2968 wl_resource_post_no_memory(resource);
2972 input_panel_surface->surface = surface;
2973 input_panel_surface->listener.notify = destroy_input_panel_surface;
2975 wl_signal_add(&surface_resource->destroy_signal,
2976 &input_panel_surface->listener);
2978 wl_list_insert(&shell->input_panel.surfaces,
2979 &input_panel_surface->link);
2982 static const struct input_panel_interface input_panel_implementation = {
2983 input_panel_set_surface
2987 unbind_input_panel(struct wl_resource *resource)
2989 struct desktop_shell *shell = resource->data;
2991 shell->input_panel.binding = NULL;
2996 bind_input_panel(struct wl_client *client,
2997 void *data, uint32_t version, uint32_t id)
2999 struct desktop_shell *shell = data;
3000 struct wl_resource *resource;
3002 resource = wl_client_add_object(client, &input_panel_interface,
3003 &input_panel_implementation,
3006 if (shell->input_panel.binding == NULL) {
3007 resource->destroy = unbind_input_panel;
3008 shell->input_panel.binding = resource;
3012 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
3013 "interface object already bound");
3014 wl_resource_destroy(resource);
3018 struct desktop_shell *shell;
3019 struct weston_surface *current;
3020 struct wl_listener listener;
3021 struct wl_keyboard_grab grab;
3025 switcher_next(struct switcher *switcher)
3027 struct weston_surface *surface;
3028 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
3029 struct shell_surface *shsurf;
3030 struct workspace *ws = get_current_workspace(switcher->shell);
3032 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
3033 switch (get_shell_surface_type(surface)) {
3034 case SHELL_SURFACE_TOPLEVEL:
3035 case SHELL_SURFACE_FULLSCREEN:
3036 case SHELL_SURFACE_MAXIMIZED:
3039 if (prev == switcher->current)
3042 surface->alpha = 0.25;
3043 surface->geometry.dirty = 1;
3044 weston_surface_damage(surface);
3050 if (is_black_surface(surface, NULL)) {
3051 surface->alpha = 0.25;
3052 surface->geometry.dirty = 1;
3053 weston_surface_damage(surface);
3063 wl_list_remove(&switcher->listener.link);
3064 wl_signal_add(&next->surface.resource.destroy_signal,
3065 &switcher->listener);
3067 switcher->current = next;
3070 shsurf = get_shell_surface(switcher->current);
3071 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
3072 shsurf->fullscreen.black_surface->alpha = 1.0;
3076 switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
3078 struct switcher *switcher =
3079 container_of(listener, struct switcher, listener);
3081 switcher_next(switcher);
3085 switcher_destroy(struct switcher *switcher)
3087 struct weston_surface *surface;
3088 struct wl_keyboard *keyboard = switcher->grab.keyboard;
3089 struct workspace *ws = get_current_workspace(switcher->shell);
3091 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
3092 surface->alpha = 1.0;
3093 weston_surface_damage(surface);
3096 if (switcher->current)
3097 activate(switcher->shell, switcher->current,
3098 (struct weston_seat *) keyboard->seat);
3099 wl_list_remove(&switcher->listener.link);
3100 wl_keyboard_end_grab(keyboard);
3105 switcher_key(struct wl_keyboard_grab *grab,
3106 uint32_t time, uint32_t key, uint32_t state_w)
3108 struct switcher *switcher = container_of(grab, struct switcher, grab);
3109 enum wl_keyboard_key_state state = state_w;
3111 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
3112 switcher_next(switcher);
3116 switcher_modifier(struct wl_keyboard_grab *grab, uint32_t serial,
3117 uint32_t mods_depressed, uint32_t mods_latched,
3118 uint32_t mods_locked, uint32_t group)
3120 struct switcher *switcher = container_of(grab, struct switcher, grab);
3121 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
3123 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0)
3124 switcher_destroy(switcher);
3127 static const struct wl_keyboard_grab_interface switcher_grab = {
3133 switcher_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
3136 struct desktop_shell *shell = data;
3137 struct switcher *switcher;
3139 switcher = malloc(sizeof *switcher);
3140 switcher->shell = shell;
3141 switcher->current = NULL;
3142 switcher->listener.notify = switcher_handle_surface_destroy;
3143 wl_list_init(&switcher->listener.link);
3145 lower_fullscreen_layer(switcher->shell);
3146 switcher->grab.interface = &switcher_grab;
3147 wl_keyboard_start_grab(seat->keyboard, &switcher->grab);
3148 wl_keyboard_set_focus(seat->keyboard, NULL);
3149 switcher_next(switcher);
3153 backlight_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
3156 struct weston_compositor *compositor = data;
3157 struct weston_output *output;
3158 long backlight_new = 0;
3160 /* TODO: we're limiting to simple use cases, where we assume just
3161 * control on the primary display. We'd have to extend later if we
3162 * ever get support for setting backlights on random desktop LCD
3164 output = get_default_output(compositor);
3168 if (!output->set_backlight)
3171 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
3172 backlight_new = output->backlight_current - 25;
3173 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
3174 backlight_new = output->backlight_current + 25;
3176 if (backlight_new < 5)
3178 if (backlight_new > 255)
3179 backlight_new = 255;
3181 output->backlight_current = backlight_new;
3182 output->set_backlight(output, output->backlight_current);
3186 debug_repaint_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
3189 struct desktop_shell *shell = data;
3190 struct weston_compositor *compositor = shell->compositor;
3191 struct weston_surface *surface;
3192 struct weston_plane plane;
3194 if (shell->debug_repaint_surface) {
3195 weston_surface_destroy(shell->debug_repaint_surface);
3196 shell->debug_repaint_surface = NULL;
3198 surface = weston_surface_create(compositor);
3199 weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2);
3200 weston_surface_configure(surface, 0, 0, 8192, 8192);
3201 wl_list_insert(&compositor->fade_layer.surface_list,
3202 &surface->layer_link);
3203 weston_surface_assign_output(surface);
3204 pixman_region32_init(&surface->input);
3206 /* Here's the dirty little trick that makes the
3207 * repaint debugging work: we move the surface to a
3208 * different plane and force an update_transform to
3209 * update dependent state and clear the
3210 * geometry.dirty bit. This way the call to
3211 * damage_below() in update_transform() does not
3212 * add damage to the primary plane. */
3214 weston_plane_init(&plane, 0, 0);
3215 surface->plane = &plane;
3216 weston_surface_update_transform(surface);
3217 shell->debug_repaint_surface = surface;
3218 surface->plane = &compositor->primary_plane;
3219 weston_plane_release(&plane);
3224 force_kill_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
3227 struct wl_client *client;
3232 client = seat->keyboard->focus->resource.client;
3233 wl_client_get_credentials(client, &pid, &uid, &gid);
3239 workspace_up_binding(struct wl_seat *seat, uint32_t time,
3240 uint32_t key, void *data)
3242 struct desktop_shell *shell = data;
3243 unsigned int new_index = shell->workspaces.current;
3250 change_workspace(shell, new_index);
3254 workspace_down_binding(struct wl_seat *seat, uint32_t time,
3255 uint32_t key, void *data)
3257 struct desktop_shell *shell = data;
3258 unsigned int new_index = shell->workspaces.current;
3262 if (new_index < shell->workspaces.num - 1)
3265 change_workspace(shell, new_index);
3269 workspace_f_binding(struct wl_seat *seat, uint32_t time,
3270 uint32_t key, void *data)
3272 struct desktop_shell *shell = data;
3273 unsigned int new_index;
3277 new_index = key - KEY_F1;
3278 if (new_index >= shell->workspaces.num)
3279 new_index = shell->workspaces.num - 1;
3281 change_workspace(shell, new_index);
3286 shell_destroy(struct wl_listener *listener, void *data)
3288 struct desktop_shell *shell =
3289 container_of(listener, struct desktop_shell, destroy_listener);
3290 struct workspace **ws;
3292 if (shell->child.client)
3293 wl_client_destroy(shell->child.client);
3295 wl_list_remove(&shell->lock_listener.link);
3296 wl_list_remove(&shell->unlock_listener.link);
3297 wl_list_remove(&shell->show_input_panel_listener.link);
3298 wl_list_remove(&shell->hide_input_panel_listener.link);
3300 wl_array_for_each(ws, &shell->workspaces.array)
3301 workspace_destroy(*ws);
3302 wl_array_release(&shell->workspaces.array);
3304 free(shell->screensaver.path);
3309 shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
3312 int i, num_workspace_bindings;
3314 /* fixed bindings */
3315 weston_compositor_add_key_binding(ec, KEY_BACKSPACE,
3316 MODIFIER_CTRL | MODIFIER_ALT,
3317 terminate_binding, ec);
3318 weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
3319 click_to_activate_binding,
3321 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
3322 MODIFIER_SUPER | MODIFIER_ALT,
3323 surface_opacity_binding, NULL);
3324 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
3325 MODIFIER_SUPER, zoom_axis_binding,
3328 /* configurable bindings */
3329 mod = shell->binding_modifier;
3330 weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod,
3331 zoom_key_binding, NULL);
3332 weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod,
3333 zoom_key_binding, NULL);
3334 weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding,
3336 weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod,
3337 resize_binding, shell);
3338 weston_compositor_add_button_binding(ec, BTN_RIGHT, mod,
3339 rotate_binding, NULL);
3340 weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding,
3342 weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding,
3344 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0,
3345 backlight_binding, ec);
3346 weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding,
3348 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0,
3349 backlight_binding, ec);
3350 weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT,
3351 debug_repaint_binding, shell);
3352 weston_compositor_add_key_binding(ec, KEY_K, mod,
3353 force_kill_binding, shell);
3354 weston_compositor_add_key_binding(ec, KEY_UP, mod,
3355 workspace_up_binding, shell);
3356 weston_compositor_add_key_binding(ec, KEY_DOWN, mod,
3357 workspace_down_binding, shell);
3359 /* Add bindings for mod+F[1-6] for workspace 1 to 6. */
3360 if (shell->workspaces.num > 1) {
3361 num_workspace_bindings = shell->workspaces.num;
3362 if (num_workspace_bindings > 6)
3363 num_workspace_bindings = 6;
3364 for (i = 0; i < num_workspace_bindings; i++)
3365 weston_compositor_add_key_binding(ec, KEY_F1 + i, mod,
3366 workspace_f_binding,
3372 shell_init(struct weston_compositor *ec);
3375 shell_init(struct weston_compositor *ec)
3377 struct weston_seat *seat;
3378 struct desktop_shell *shell;
3379 struct workspace **pws;
3382 shell = malloc(sizeof *shell);
3386 memset(shell, 0, sizeof *shell);
3387 shell->compositor = ec;
3389 shell->destroy_listener.notify = shell_destroy;
3390 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
3391 shell->lock_listener.notify = lock;
3392 wl_signal_add(&ec->lock_signal, &shell->lock_listener);
3393 shell->unlock_listener.notify = unlock;
3394 wl_signal_add(&ec->unlock_signal, &shell->unlock_listener);
3395 shell->show_input_panel_listener.notify = show_input_panels;
3396 wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener);
3397 shell->hide_input_panel_listener.notify = hide_input_panels;
3398 wl_signal_add(&ec->hide_input_panel_signal, &shell->hide_input_panel_listener);
3399 ec->ping_handler = ping_handler;
3400 ec->shell_interface.shell = shell;
3401 ec->shell_interface.create_shell_surface = create_shell_surface;
3402 ec->shell_interface.set_toplevel = set_toplevel;
3403 ec->shell_interface.set_transient = set_transient;
3404 ec->shell_interface.move = surface_move;
3405 ec->shell_interface.resize = surface_resize;
3407 wl_list_init(&shell->screensaver.surfaces);
3408 wl_list_init(&shell->input_panel.surfaces);
3410 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
3411 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
3412 weston_layer_init(&shell->background_layer, &shell->panel_layer.link);
3413 weston_layer_init(&shell->lock_layer, NULL);
3414 weston_layer_init(&shell->input_panel_layer, NULL);
3416 wl_array_init(&shell->workspaces.array);
3418 shell_configuration(shell);
3420 for (i = 0; i < shell->workspaces.num; i++) {
3421 pws = wl_array_add(&shell->workspaces.array, sizeof *pws);
3425 *pws = workspace_create();
3429 activate_workspace(shell, 0);
3431 wl_list_init(&shell->workspaces.animation.link);
3432 shell->workspaces.animation.frame = animate_workspace_change_frame;
3434 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
3435 shell, bind_shell) == NULL)
3438 if (wl_display_add_global(ec->wl_display,
3439 &desktop_shell_interface,
3440 shell, bind_desktop_shell) == NULL)
3443 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
3444 shell, bind_screensaver) == NULL)
3447 if (wl_display_add_global(ec->wl_display, &input_panel_interface,
3448 shell, bind_input_panel) == NULL)
3451 shell->child.deathstamp = weston_compositor_get_time();
3452 if (launch_desktop_shell_process(shell) != 0)
3455 wl_list_for_each(seat, &ec->seat_list, link)
3456 create_pointer_focus_listener(seat);
3458 shell_add_bindings(ec, shell);