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 reverse_workspace_change_animation(struct desktop_shell *shell,
582 struct workspace *from,
583 struct workspace *to)
585 shell->workspaces.current = index;
587 shell->workspaces.anim_to = to;
588 shell->workspaces.anim_from = from;
589 shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir;
590 shell->workspaces.anim_timestamp = 0;
592 restore_focus_state(shell, to);
594 weston_compositor_schedule_repaint(shell->compositor);
598 workspace_deactivate_transforms(struct workspace *ws)
600 struct weston_surface *surface;
601 struct shell_surface *shsurf;
603 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
604 shsurf = get_shell_surface(surface);
605 wl_list_remove(&shsurf->workspace_transform.link);
606 wl_list_init(&shsurf->workspace_transform.link);
607 shsurf->surface->geometry.dirty = 1;
612 finish_workspace_change_animation(struct desktop_shell *shell,
613 struct workspace *from,
614 struct workspace *to)
616 weston_compositor_schedule_repaint(shell->compositor);
618 wl_list_remove(&shell->workspaces.animation.link);
619 workspace_deactivate_transforms(from);
620 workspace_deactivate_transforms(to);
621 shell->workspaces.anim_to = NULL;
623 wl_list_remove(&shell->workspaces.anim_from->layer.link);
627 animate_workspace_change_frame(struct weston_animation *animation,
628 struct weston_output *output, uint32_t msecs)
630 struct desktop_shell *shell =
631 container_of(animation, struct desktop_shell,
632 workspaces.animation);
633 struct workspace *from = shell->workspaces.anim_from;
634 struct workspace *to = shell->workspaces.anim_to;
638 if (workspace_is_empty(from) && workspace_is_empty(to)) {
639 finish_workspace_change_animation(shell, from, to);
643 if (shell->workspaces.anim_timestamp == 0) {
644 if (shell->workspaces.anim_current == 0.0)
645 shell->workspaces.anim_timestamp = msecs;
647 shell->workspaces.anim_timestamp =
649 /* Invers of movement function 'y' below. */
650 (asin(1.0 - shell->workspaces.anim_current) *
651 DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH *
655 t = msecs - shell->workspaces.anim_timestamp;
661 x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2;
664 if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) {
665 weston_compositor_schedule_repaint(shell->compositor);
667 workspace_translate_out(from, shell->workspaces.anim_dir * y);
668 workspace_translate_in(to, shell->workspaces.anim_dir * y);
669 shell->workspaces.anim_current = y;
671 weston_compositor_schedule_repaint(shell->compositor);
674 finish_workspace_change_animation(shell, from, to);
678 animate_workspace_change(struct desktop_shell *shell,
680 struct workspace *from,
681 struct workspace *to)
683 struct weston_output *output;
687 if (index > shell->workspaces.current)
692 shell->workspaces.current = index;
694 shell->workspaces.anim_dir = dir;
695 shell->workspaces.anim_from = from;
696 shell->workspaces.anim_to = to;
697 shell->workspaces.anim_current = 0.0;
698 shell->workspaces.anim_timestamp = 0;
700 output = container_of(shell->compositor->output_list.next,
701 struct weston_output, link);
702 wl_list_insert(&output->animation_list,
703 &shell->workspaces.animation.link);
705 wl_list_insert(&from->layer.link, &to->layer.link);
707 workspace_translate_in(to, 0);
709 restore_focus_state(shell, to);
711 weston_compositor_schedule_repaint(shell->compositor);
715 change_workspace(struct desktop_shell *shell, unsigned int index)
717 struct workspace *from;
718 struct workspace *to;
720 if (index == shell->workspaces.current)
723 /* Don't change workspace when there is any fullscreen surfaces. */
724 if (!wl_list_empty(&shell->fullscreen_layer.surface_list))
727 from = get_current_workspace(shell);
728 to = get_workspace(shell, index);
730 if (shell->workspaces.anim_from == to &&
731 shell->workspaces.anim_to == from) {
732 reverse_workspace_change_animation(shell, index, from, to);
736 if (shell->workspaces.anim_to != NULL)
737 finish_workspace_change_animation(shell,
738 shell->workspaces.anim_from,
739 shell->workspaces.anim_to);
741 if (workspace_is_empty(to) && workspace_is_empty(from)) {
742 shell->workspaces.current = index;
743 wl_list_insert(&from->layer.link, &to->layer.link);
744 wl_list_remove(&from->layer.link);
746 restore_focus_state(shell, to);
749 animate_workspace_change(shell, index, from, to);
753 noop_grab_focus(struct wl_pointer_grab *grab,
754 struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
760 move_grab_motion(struct wl_pointer_grab *grab,
761 uint32_t time, wl_fixed_t x, wl_fixed_t y)
763 struct weston_move_grab *move = (struct weston_move_grab *) grab;
764 struct wl_pointer *pointer = grab->pointer;
765 struct shell_surface *shsurf = move->base.shsurf;
766 struct weston_surface *es;
767 int dx = wl_fixed_to_int(pointer->x + move->dx);
768 int dy = wl_fixed_to_int(pointer->y + move->dy);
773 es = shsurf->surface;
775 weston_surface_configure(es, dx, dy,
776 es->geometry.width, es->geometry.height);
778 weston_compositor_schedule_repaint(es->compositor);
782 move_grab_button(struct wl_pointer_grab *grab,
783 uint32_t time, uint32_t button, uint32_t state_w)
785 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
787 struct wl_pointer *pointer = grab->pointer;
788 enum wl_pointer_button_state state = state_w;
790 if (pointer->button_count == 0 &&
791 state == WL_POINTER_BUTTON_STATE_RELEASED) {
792 shell_grab_end(shell_grab);
797 static const struct wl_pointer_grab_interface move_grab_interface = {
804 surface_move(struct shell_surface *shsurf, struct weston_seat *ws)
806 struct weston_move_grab *move;
811 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
814 move = malloc(sizeof *move);
818 move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
819 ws->seat.pointer->grab_x;
820 move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
821 ws->seat.pointer->grab_y;
823 shell_grab_start(&move->base, &move_grab_interface, shsurf,
824 ws->seat.pointer, DESKTOP_SHELL_CURSOR_MOVE);
830 shell_surface_move(struct wl_client *client, struct wl_resource *resource,
831 struct wl_resource *seat_resource, uint32_t serial)
833 struct weston_seat *ws = seat_resource->data;
834 struct shell_surface *shsurf = resource->data;
836 if (ws->seat.pointer->button_count == 0 ||
837 ws->seat.pointer->grab_serial != serial ||
838 ws->seat.pointer->focus != &shsurf->surface->surface)
841 if (surface_move(shsurf, ws) < 0)
842 wl_resource_post_no_memory(resource);
845 struct weston_resize_grab {
846 struct shell_grab base;
848 int32_t width, height;
852 resize_grab_motion(struct wl_pointer_grab *grab,
853 uint32_t time, wl_fixed_t x, wl_fixed_t y)
855 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
856 struct wl_pointer *pointer = grab->pointer;
857 struct shell_surface *shsurf = resize->base.shsurf;
858 int32_t width, height;
859 wl_fixed_t from_x, from_y;
860 wl_fixed_t to_x, to_y;
865 weston_surface_from_global_fixed(shsurf->surface,
866 pointer->grab_x, pointer->grab_y,
868 weston_surface_from_global_fixed(shsurf->surface,
869 pointer->x, pointer->y, &to_x, &to_y);
871 width = resize->width;
872 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
873 width += wl_fixed_to_int(from_x - to_x);
874 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
875 width += wl_fixed_to_int(to_x - from_x);
878 height = resize->height;
879 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
880 height += wl_fixed_to_int(from_y - to_y);
881 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
882 height += wl_fixed_to_int(to_y - from_y);
885 shsurf->client->send_configure(shsurf->surface,
886 resize->edges, width, height);
890 send_configure(struct weston_surface *surface,
891 uint32_t edges, int32_t width, int32_t height)
893 struct shell_surface *shsurf = get_shell_surface(surface);
895 wl_shell_surface_send_configure(&shsurf->resource,
896 edges, width, height);
899 static const struct weston_shell_client shell_client = {
904 resize_grab_button(struct wl_pointer_grab *grab,
905 uint32_t time, uint32_t button, uint32_t state_w)
907 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
908 struct wl_pointer *pointer = grab->pointer;
909 enum wl_pointer_button_state state = state_w;
911 if (pointer->button_count == 0 &&
912 state == WL_POINTER_BUTTON_STATE_RELEASED) {
913 shell_grab_end(&resize->base);
918 static const struct wl_pointer_grab_interface resize_grab_interface = {
925 surface_resize(struct shell_surface *shsurf,
926 struct weston_seat *ws, uint32_t edges)
928 struct weston_resize_grab *resize;
930 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
933 if (edges == 0 || edges > 15 ||
934 (edges & 3) == 3 || (edges & 12) == 12)
937 resize = malloc(sizeof *resize);
941 resize->edges = edges;
942 resize->width = shsurf->surface->geometry.width;
943 resize->height = shsurf->surface->geometry.height;
945 shell_grab_start(&resize->base, &resize_grab_interface, shsurf,
946 ws->seat.pointer, edges);
952 shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
953 struct wl_resource *seat_resource, uint32_t serial,
956 struct weston_seat *ws = seat_resource->data;
957 struct shell_surface *shsurf = resource->data;
959 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
962 if (ws->seat.pointer->button_count == 0 ||
963 ws->seat.pointer->grab_serial != serial ||
964 ws->seat.pointer->focus != &shsurf->surface->surface)
967 if (surface_resize(shsurf, ws, edges) < 0)
968 wl_resource_post_no_memory(resource);
972 busy_cursor_grab_focus(struct wl_pointer_grab *base,
973 struct wl_surface *surface, int32_t x, int32_t y)
975 struct shell_grab *grab = (struct shell_grab *) base;
977 if (grab->grab.focus != surface) {
978 shell_grab_end(grab);
984 busy_cursor_grab_motion(struct wl_pointer_grab *grab,
985 uint32_t time, int32_t x, int32_t y)
990 busy_cursor_grab_button(struct wl_pointer_grab *base,
991 uint32_t time, uint32_t button, uint32_t state)
993 struct shell_grab *grab = (struct shell_grab *) base;
994 struct shell_surface *shsurf;
995 struct weston_surface *surface =
996 (struct weston_surface *) grab->grab.pointer->current;
997 struct weston_seat *seat =
998 (struct weston_seat *) grab->grab.pointer->seat;
1000 shsurf = get_shell_surface(surface);
1001 if (shsurf && button == BTN_LEFT && state) {
1002 activate(shsurf->shell, shsurf->surface, seat);
1003 surface_move(shsurf, seat);
1007 static const struct wl_pointer_grab_interface busy_cursor_grab_interface = {
1008 busy_cursor_grab_focus,
1009 busy_cursor_grab_motion,
1010 busy_cursor_grab_button,
1014 set_busy_cursor(struct shell_surface *shsurf, struct wl_pointer *pointer)
1016 struct shell_grab *grab;
1018 grab = malloc(sizeof *grab);
1022 shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer,
1023 DESKTOP_SHELL_CURSOR_BUSY);
1027 end_busy_cursor(struct shell_surface *shsurf, struct wl_pointer *pointer)
1029 struct shell_grab *grab = (struct shell_grab *) pointer->grab;
1031 if (grab->grab.interface == &busy_cursor_grab_interface) {
1032 shell_grab_end(grab);
1038 ping_timer_destroy(struct shell_surface *shsurf)
1040 if (!shsurf || !shsurf->ping_timer)
1043 if (shsurf->ping_timer->source)
1044 wl_event_source_remove(shsurf->ping_timer->source);
1046 free(shsurf->ping_timer);
1047 shsurf->ping_timer = NULL;
1051 ping_timeout_handler(void *data)
1053 struct shell_surface *shsurf = data;
1054 struct weston_seat *seat;
1056 /* Client is not responding */
1057 shsurf->unresponsive = 1;
1059 wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link)
1060 if (seat->seat.pointer->focus == &shsurf->surface->surface)
1061 set_busy_cursor(shsurf, seat->seat.pointer);
1067 ping_handler(struct weston_surface *surface, uint32_t serial)
1069 struct shell_surface *shsurf = get_shell_surface(surface);
1070 struct wl_event_loop *loop;
1071 int ping_timeout = 200;
1075 if (!shsurf->resource.client)
1078 if (shsurf->surface == shsurf->shell->grab_surface)
1081 if (!shsurf->ping_timer) {
1082 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
1083 if (!shsurf->ping_timer)
1086 shsurf->ping_timer->serial = serial;
1087 loop = wl_display_get_event_loop(surface->compositor->wl_display);
1088 shsurf->ping_timer->source =
1089 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
1090 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
1092 wl_shell_surface_send_ping(&shsurf->resource, serial);
1097 handle_pointer_focus(struct wl_listener *listener, void *data)
1099 struct wl_pointer *pointer = data;
1100 struct weston_surface *surface =
1101 (struct weston_surface *) pointer->focus;
1102 struct weston_compositor *compositor;
1103 struct shell_surface *shsurf;
1109 compositor = surface->compositor;
1110 shsurf = get_shell_surface(surface);
1112 if (shsurf && shsurf->unresponsive) {
1113 set_busy_cursor(shsurf, pointer);
1115 serial = wl_display_next_serial(compositor->wl_display);
1116 ping_handler(surface, serial);
1121 create_pointer_focus_listener(struct weston_seat *seat)
1123 struct wl_listener *listener;
1125 if (!seat->seat.pointer)
1128 listener = malloc(sizeof *listener);
1129 listener->notify = handle_pointer_focus;
1130 wl_signal_add(&seat->seat.pointer->focus_signal, listener);
1134 shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
1137 struct shell_surface *shsurf = resource->data;
1138 struct desktop_shell *shell = shsurf->shell;
1139 struct weston_seat *seat;
1140 struct weston_compositor *ec = shsurf->surface->compositor;
1141 struct wl_pointer *pointer;
1142 int was_unresponsive;
1144 if (shsurf->ping_timer == NULL)
1145 /* Just ignore unsolicited pong. */
1148 if (shsurf->ping_timer->serial == serial) {
1149 was_unresponsive = shsurf->unresponsive;
1150 shsurf->unresponsive = 0;
1151 if (was_unresponsive) {
1152 /* Received pong from previously unresponsive client */
1153 wl_list_for_each(seat, &ec->seat_list, link) {
1154 pointer = seat->seat.pointer;
1155 if (pointer->focus ==
1156 &shell->grab_surface->surface &&
1158 &shsurf->surface->surface)
1159 end_busy_cursor(shsurf, pointer);
1162 ping_timer_destroy(shsurf);
1167 shell_surface_set_title(struct wl_client *client,
1168 struct wl_resource *resource, const char *title)
1170 struct shell_surface *shsurf = resource->data;
1172 free(shsurf->title);
1173 shsurf->title = strdup(title);
1177 shell_surface_set_class(struct wl_client *client,
1178 struct wl_resource *resource, const char *class)
1180 struct shell_surface *shsurf = resource->data;
1182 free(shsurf->class);
1183 shsurf->class = strdup(class);
1186 static struct weston_output *
1187 get_default_output(struct weston_compositor *compositor)
1189 return container_of(compositor->output_list.next,
1190 struct weston_output, link);
1194 shell_unset_fullscreen(struct shell_surface *shsurf)
1196 /* undo all fullscreen things here */
1197 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1198 shell_surface_is_top_fullscreen(shsurf)) {
1199 weston_output_switch_mode(shsurf->fullscreen_output,
1200 shsurf->fullscreen_output->origin);
1202 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1203 shsurf->fullscreen.framerate = 0;
1204 wl_list_remove(&shsurf->fullscreen.transform.link);
1205 wl_list_init(&shsurf->fullscreen.transform.link);
1206 if (shsurf->fullscreen.black_surface)
1207 weston_surface_destroy(shsurf->fullscreen.black_surface);
1208 shsurf->fullscreen.black_surface = NULL;
1209 shsurf->fullscreen_output = NULL;
1210 weston_surface_set_position(shsurf->surface,
1211 shsurf->saved_x, shsurf->saved_y);
1212 if (shsurf->saved_rotation_valid) {
1213 wl_list_insert(&shsurf->surface->geometry.transformation_list,
1214 &shsurf->rotation.transform.link);
1215 shsurf->saved_rotation_valid = false;
1220 reset_shell_surface_type(struct shell_surface *surface)
1222 switch (surface->type) {
1223 case SHELL_SURFACE_FULLSCREEN:
1224 shell_unset_fullscreen(surface);
1226 case SHELL_SURFACE_MAXIMIZED:
1227 surface->output = get_default_output(surface->surface->compositor);
1228 weston_surface_set_position(surface->surface,
1232 case SHELL_SURFACE_NONE:
1233 case SHELL_SURFACE_TOPLEVEL:
1234 case SHELL_SURFACE_TRANSIENT:
1235 case SHELL_SURFACE_POPUP:
1239 surface->type = SHELL_SURFACE_NONE;
1244 set_surface_type(struct shell_surface *shsurf)
1246 struct weston_surface *surface = shsurf->surface;
1247 struct weston_surface *pes = shsurf->parent;
1249 reset_shell_surface_type(shsurf);
1251 shsurf->type = shsurf->next_type;
1252 shsurf->next_type = SHELL_SURFACE_NONE;
1254 switch (shsurf->type) {
1255 case SHELL_SURFACE_TOPLEVEL:
1257 case SHELL_SURFACE_TRANSIENT:
1258 weston_surface_set_position(surface,
1259 pes->geometry.x + shsurf->transient.x,
1260 pes->geometry.y + shsurf->transient.y);
1263 case SHELL_SURFACE_MAXIMIZED:
1264 shsurf->saved_x = surface->geometry.x;
1265 shsurf->saved_y = surface->geometry.y;
1266 shsurf->saved_position_valid = true;
1269 case SHELL_SURFACE_FULLSCREEN:
1270 shsurf->saved_x = surface->geometry.x;
1271 shsurf->saved_y = surface->geometry.y;
1272 shsurf->saved_position_valid = true;
1274 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
1275 wl_list_remove(&shsurf->rotation.transform.link);
1276 wl_list_init(&shsurf->rotation.transform.link);
1277 shsurf->surface->geometry.dirty = 1;
1278 shsurf->saved_rotation_valid = true;
1288 set_toplevel(struct shell_surface *shsurf)
1290 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
1294 shell_surface_set_toplevel(struct wl_client *client,
1295 struct wl_resource *resource)
1297 struct shell_surface *surface = resource->data;
1299 set_toplevel(surface);
1303 set_transient(struct shell_surface *shsurf,
1304 struct weston_surface *parent, int x, int y, uint32_t flags)
1306 /* assign to parents output */
1307 shsurf->parent = parent;
1308 shsurf->transient.x = x;
1309 shsurf->transient.y = y;
1310 shsurf->transient.flags = flags;
1311 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
1315 shell_surface_set_transient(struct wl_client *client,
1316 struct wl_resource *resource,
1317 struct wl_resource *parent_resource,
1318 int x, int y, uint32_t flags)
1320 struct shell_surface *shsurf = resource->data;
1321 struct weston_surface *parent = parent_resource->data;
1323 set_transient(shsurf, parent, x, y, flags);
1326 static struct desktop_shell *
1327 shell_surface_get_shell(struct shell_surface *shsurf)
1329 return shsurf->shell;
1333 get_output_panel_height(struct desktop_shell *shell,
1334 struct weston_output *output)
1336 struct weston_surface *surface;
1337 int panel_height = 0;
1342 wl_list_for_each(surface, &shell->panel_layer.surface_list, layer_link) {
1343 if (surface->output == output) {
1344 panel_height = surface->geometry.height;
1349 return panel_height;
1353 shell_surface_set_maximized(struct wl_client *client,
1354 struct wl_resource *resource,
1355 struct wl_resource *output_resource )
1357 struct shell_surface *shsurf = resource->data;
1358 struct weston_surface *es = shsurf->surface;
1359 struct desktop_shell *shell = NULL;
1360 uint32_t edges = 0, panel_height = 0;
1362 /* get the default output, if the client set it as NULL
1363 check whether the ouput is available */
1364 if (output_resource)
1365 shsurf->output = output_resource->data;
1366 else if (es->output)
1367 shsurf->output = es->output;
1369 shsurf->output = get_default_output(es->compositor);
1371 shell = shell_surface_get_shell(shsurf);
1372 panel_height = get_output_panel_height(shell, shsurf->output);
1373 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
1375 shsurf->client->send_configure(shsurf->surface, edges,
1376 shsurf->output->width,
1377 shsurf->output->height - panel_height);
1379 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
1383 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy);
1385 static struct weston_surface *
1386 create_black_surface(struct weston_compositor *ec,
1387 struct weston_surface *fs_surface,
1388 GLfloat x, GLfloat y, int w, int h)
1390 struct weston_surface *surface = NULL;
1392 surface = weston_surface_create(ec);
1393 if (surface == NULL) {
1394 weston_log("no memory\n");
1398 surface->configure = black_surface_configure;
1399 surface->private = fs_surface;
1400 weston_surface_configure(surface, x, y, w, h);
1401 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
1402 pixman_region32_init_rect(&surface->opaque, 0, 0, w, h);
1407 /* Create black surface and append it to the associated fullscreen surface.
1408 * Handle size dismatch and positioning according to the method. */
1410 shell_configure_fullscreen(struct shell_surface *shsurf)
1412 struct weston_output *output = shsurf->fullscreen_output;
1413 struct weston_surface *surface = shsurf->surface;
1414 struct weston_matrix *matrix;
1415 float scale, output_aspect, surface_aspect, x, y;
1417 if (!shsurf->fullscreen.black_surface)
1418 shsurf->fullscreen.black_surface =
1419 create_black_surface(surface->compositor,
1421 output->x, output->y,
1425 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
1426 wl_list_insert(&surface->layer_link,
1427 &shsurf->fullscreen.black_surface->layer_link);
1428 shsurf->fullscreen.black_surface->output = output;
1430 switch (shsurf->fullscreen.type) {
1431 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
1432 if (surface->buffer)
1433 center_on_output(surface, shsurf->fullscreen_output);
1435 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
1436 matrix = &shsurf->fullscreen.transform.matrix;
1437 weston_matrix_init(matrix);
1439 output_aspect = (float) output->width /
1440 (float) output->height;
1441 surface_aspect = (float) surface->geometry.width /
1442 (float) surface->geometry.height;
1443 if (output_aspect < surface_aspect)
1444 scale = (float) output->width /
1445 (float) surface->geometry.width;
1447 scale = (float) output->height /
1448 (float) surface->geometry.height;
1450 weston_matrix_scale(matrix, scale, scale, 1);
1451 wl_list_remove(&shsurf->fullscreen.transform.link);
1452 wl_list_insert(&surface->geometry.transformation_list,
1453 &shsurf->fullscreen.transform.link);
1454 x = output->x + (output->width - surface->geometry.width * scale) / 2;
1455 y = output->y + (output->height - surface->geometry.height * scale) / 2;
1456 weston_surface_set_position(surface, x, y);
1459 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
1460 if (shell_surface_is_top_fullscreen(shsurf)) {
1461 struct weston_mode mode = {0,
1462 surface->geometry.width,
1463 surface->geometry.height,
1464 shsurf->fullscreen.framerate};
1466 if (weston_output_switch_mode(output, &mode) == 0) {
1467 weston_surface_configure(shsurf->fullscreen.black_surface,
1468 output->x, output->y,
1471 weston_surface_set_position(surface, output->x, output->y);
1476 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
1483 /* make the fullscreen and black surface at the top */
1485 shell_stack_fullscreen(struct shell_surface *shsurf)
1487 struct weston_output *output = shsurf->fullscreen_output;
1488 struct weston_surface *surface = shsurf->surface;
1489 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
1491 wl_list_remove(&surface->layer_link);
1492 wl_list_insert(&shell->fullscreen_layer.surface_list,
1493 &surface->layer_link);
1494 weston_surface_damage(surface);
1496 if (!shsurf->fullscreen.black_surface)
1497 shsurf->fullscreen.black_surface =
1498 create_black_surface(surface->compositor,
1500 output->x, output->y,
1504 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
1505 wl_list_insert(&surface->layer_link,
1506 &shsurf->fullscreen.black_surface->layer_link);
1507 weston_surface_damage(shsurf->fullscreen.black_surface);
1511 shell_map_fullscreen(struct shell_surface *shsurf)
1513 shell_stack_fullscreen(shsurf);
1514 shell_configure_fullscreen(shsurf);
1518 shell_surface_set_fullscreen(struct wl_client *client,
1519 struct wl_resource *resource,
1522 struct wl_resource *output_resource)
1524 struct shell_surface *shsurf = resource->data;
1525 struct weston_surface *es = shsurf->surface;
1527 if (output_resource)
1528 shsurf->output = output_resource->data;
1529 else if (es->output)
1530 shsurf->output = es->output;
1532 shsurf->output = get_default_output(es->compositor);
1534 shsurf->fullscreen_output = shsurf->output;
1535 shsurf->fullscreen.type = method;
1536 shsurf->fullscreen.framerate = framerate;
1537 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
1539 shsurf->client->send_configure(shsurf->surface, 0,
1540 shsurf->output->width,
1541 shsurf->output->height);
1545 popup_grab_focus(struct wl_pointer_grab *grab,
1546 struct wl_surface *surface,
1550 struct wl_pointer *pointer = grab->pointer;
1551 struct shell_surface *priv =
1552 container_of(grab, struct shell_surface, popup.grab);
1553 struct wl_client *client = priv->surface->surface.resource.client;
1555 if (surface && surface->resource.client == client) {
1556 wl_pointer_set_focus(pointer, surface, x, y);
1557 grab->focus = surface;
1559 wl_pointer_set_focus(pointer, NULL,
1560 wl_fixed_from_int(0),
1561 wl_fixed_from_int(0));
1567 popup_grab_motion(struct wl_pointer_grab *grab,
1568 uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
1570 struct wl_resource *resource;
1572 resource = grab->pointer->focus_resource;
1574 wl_pointer_send_motion(resource, time, sx, sy);
1578 popup_grab_button(struct wl_pointer_grab *grab,
1579 uint32_t time, uint32_t button, uint32_t state_w)
1581 struct wl_resource *resource;
1582 struct shell_surface *shsurf =
1583 container_of(grab, struct shell_surface, popup.grab);
1584 struct wl_display *display;
1585 enum wl_pointer_button_state state = state_w;
1588 resource = grab->pointer->focus_resource;
1590 display = wl_client_get_display(resource->client);
1591 serial = wl_display_get_serial(display);
1592 wl_pointer_send_button(resource, serial, time, button, state);
1593 } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
1594 (shsurf->popup.initial_up ||
1595 time - shsurf->popup.seat->pointer->grab_time > 500)) {
1596 wl_shell_surface_send_popup_done(&shsurf->resource);
1597 wl_pointer_end_grab(grab->pointer);
1598 shsurf->popup.grab.pointer = NULL;
1601 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
1602 shsurf->popup.initial_up = 1;
1605 static const struct wl_pointer_grab_interface popup_grab_interface = {
1612 shell_map_popup(struct shell_surface *shsurf)
1614 struct wl_seat *seat = shsurf->popup.seat;
1615 struct weston_surface *es = shsurf->surface;
1616 struct weston_surface *parent = shsurf->parent;
1618 es->output = parent->output;
1619 shsurf->popup.grab.interface = &popup_grab_interface;
1621 weston_surface_update_transform(parent);
1622 if (parent->transform.enabled) {
1623 shsurf->popup.parent_transform.matrix =
1624 parent->transform.matrix;
1626 /* construct x, y translation matrix */
1627 weston_matrix_init(&shsurf->popup.parent_transform.matrix);
1628 shsurf->popup.parent_transform.matrix.d[12] =
1630 shsurf->popup.parent_transform.matrix.d[13] =
1633 wl_list_insert(es->geometry.transformation_list.prev,
1634 &shsurf->popup.parent_transform.link);
1635 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
1637 shsurf->popup.initial_up = 0;
1639 /* We don't require the grab to still be active, but if another
1640 * grab has started in the meantime, we end the popup now. */
1641 if (seat->pointer->grab_serial == shsurf->popup.serial) {
1642 wl_pointer_start_grab(seat->pointer, &shsurf->popup.grab);
1644 wl_shell_surface_send_popup_done(&shsurf->resource);
1649 shell_surface_set_popup(struct wl_client *client,
1650 struct wl_resource *resource,
1651 struct wl_resource *seat_resource,
1653 struct wl_resource *parent_resource,
1654 int32_t x, int32_t y, uint32_t flags)
1656 struct shell_surface *shsurf = resource->data;
1658 shsurf->type = SHELL_SURFACE_POPUP;
1659 shsurf->parent = parent_resource->data;
1660 shsurf->popup.seat = seat_resource->data;
1661 shsurf->popup.serial = serial;
1662 shsurf->popup.x = x;
1663 shsurf->popup.y = y;
1666 static const struct wl_shell_surface_interface shell_surface_implementation = {
1669 shell_surface_resize,
1670 shell_surface_set_toplevel,
1671 shell_surface_set_transient,
1672 shell_surface_set_fullscreen,
1673 shell_surface_set_popup,
1674 shell_surface_set_maximized,
1675 shell_surface_set_title,
1676 shell_surface_set_class
1680 destroy_shell_surface(struct shell_surface *shsurf)
1682 if (shsurf->popup.grab.pointer)
1683 wl_pointer_end_grab(shsurf->popup.grab.pointer);
1685 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1686 shell_surface_is_top_fullscreen(shsurf)) {
1687 weston_output_switch_mode(shsurf->fullscreen_output,
1688 shsurf->fullscreen_output->origin);
1691 if (shsurf->fullscreen.black_surface)
1692 weston_surface_destroy(shsurf->fullscreen.black_surface);
1694 /* As destroy_resource() use wl_list_for_each_safe(),
1695 * we can always remove the listener.
1697 wl_list_remove(&shsurf->surface_destroy_listener.link);
1698 shsurf->surface->configure = NULL;
1699 ping_timer_destroy(shsurf);
1701 wl_list_remove(&shsurf->link);
1706 shell_destroy_shell_surface(struct wl_resource *resource)
1708 struct shell_surface *shsurf = resource->data;
1710 destroy_shell_surface(shsurf);
1714 shell_handle_surface_destroy(struct wl_listener *listener, void *data)
1716 struct shell_surface *shsurf = container_of(listener,
1717 struct shell_surface,
1718 surface_destroy_listener);
1720 if (shsurf->resource.client) {
1721 wl_resource_destroy(&shsurf->resource);
1723 wl_signal_emit(&shsurf->resource.destroy_signal,
1725 destroy_shell_surface(shsurf);
1730 shell_surface_configure(struct weston_surface *, int32_t, int32_t);
1732 static struct shell_surface *
1733 get_shell_surface(struct weston_surface *surface)
1735 if (surface->configure == shell_surface_configure)
1736 return surface->private;
1741 static struct shell_surface *
1742 create_shell_surface(void *shell, struct weston_surface *surface,
1743 const struct weston_shell_client *client)
1745 struct shell_surface *shsurf;
1747 if (surface->configure) {
1748 weston_log("surface->configure already set\n");
1752 shsurf = calloc(1, sizeof *shsurf);
1754 weston_log("no memory to allocate shell surface\n");
1758 surface->configure = shell_surface_configure;
1759 surface->private = shsurf;
1761 shsurf->shell = (struct desktop_shell *) shell;
1762 shsurf->unresponsive = 0;
1763 shsurf->saved_position_valid = false;
1764 shsurf->saved_rotation_valid = false;
1765 shsurf->surface = surface;
1766 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1767 shsurf->fullscreen.framerate = 0;
1768 shsurf->fullscreen.black_surface = NULL;
1769 shsurf->ping_timer = NULL;
1770 wl_list_init(&shsurf->fullscreen.transform.link);
1772 wl_signal_init(&shsurf->resource.destroy_signal);
1773 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
1774 wl_signal_add(&surface->surface.resource.destroy_signal,
1775 &shsurf->surface_destroy_listener);
1777 /* init link so its safe to always remove it in destroy_shell_surface */
1778 wl_list_init(&shsurf->link);
1780 /* empty when not in use */
1781 wl_list_init(&shsurf->rotation.transform.link);
1782 weston_matrix_init(&shsurf->rotation.rotation);
1784 wl_list_init(&shsurf->workspace_transform.link);
1786 shsurf->type = SHELL_SURFACE_NONE;
1787 shsurf->next_type = SHELL_SURFACE_NONE;
1789 shsurf->client = client;
1795 shell_get_shell_surface(struct wl_client *client,
1796 struct wl_resource *resource,
1798 struct wl_resource *surface_resource)
1800 struct weston_surface *surface = surface_resource->data;
1801 struct desktop_shell *shell = resource->data;
1802 struct shell_surface *shsurf;
1804 if (get_shell_surface(surface)) {
1805 wl_resource_post_error(surface_resource,
1806 WL_DISPLAY_ERROR_INVALID_OBJECT,
1807 "desktop_shell::get_shell_surface already requested");
1811 shsurf = create_shell_surface(shell, surface, &shell_client);
1813 wl_resource_post_error(surface_resource,
1814 WL_DISPLAY_ERROR_INVALID_OBJECT,
1815 "surface->configure already set");
1819 shsurf->resource.destroy = shell_destroy_shell_surface;
1820 shsurf->resource.object.id = id;
1821 shsurf->resource.object.interface = &wl_shell_surface_interface;
1822 shsurf->resource.object.implementation =
1823 (void (**)(void)) &shell_surface_implementation;
1824 shsurf->resource.data = shsurf;
1826 wl_client_add_resource(client, &shsurf->resource);
1829 static const struct wl_shell_interface shell_implementation = {
1830 shell_get_shell_surface
1834 handle_screensaver_sigchld(struct weston_process *proc, int status)
1840 launch_screensaver(struct desktop_shell *shell)
1842 if (shell->screensaver.binding)
1845 if (!shell->screensaver.path)
1848 if (shell->screensaver.process.pid != 0) {
1849 weston_log("old screensaver still running\n");
1853 weston_client_launch(shell->compositor,
1854 &shell->screensaver.process,
1855 shell->screensaver.path,
1856 handle_screensaver_sigchld);
1860 terminate_screensaver(struct desktop_shell *shell)
1862 if (shell->screensaver.process.pid == 0)
1865 kill(shell->screensaver.process.pid, SIGTERM);
1869 configure_static_surface(struct weston_surface *es, struct weston_layer *layer)
1871 struct weston_surface *s, *next;
1873 wl_list_for_each_safe(s, next, &layer->surface_list, layer_link) {
1874 if (s->output == es->output && s != es) {
1875 weston_surface_unmap(s);
1876 s->configure = NULL;
1880 weston_surface_configure(es, es->output->x, es->output->y,
1881 es->buffer->width, es->buffer->height);
1883 if (wl_list_empty(&es->layer_link)) {
1884 wl_list_insert(&layer->surface_list, &es->layer_link);
1885 weston_compositor_schedule_repaint(es->compositor);
1890 background_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1892 struct desktop_shell *shell = es->private;
1894 configure_static_surface(es, &shell->background_layer);
1898 desktop_shell_set_background(struct wl_client *client,
1899 struct wl_resource *resource,
1900 struct wl_resource *output_resource,
1901 struct wl_resource *surface_resource)
1903 struct desktop_shell *shell = resource->data;
1904 struct weston_surface *surface = surface_resource->data;
1906 if (surface->configure) {
1907 wl_resource_post_error(surface_resource,
1908 WL_DISPLAY_ERROR_INVALID_OBJECT,
1909 "surface role already assigned");
1913 surface->configure = background_configure;
1914 surface->private = shell;
1915 surface->output = output_resource->data;
1916 desktop_shell_send_configure(resource, 0,
1918 surface->output->width,
1919 surface->output->height);
1923 panel_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1925 struct desktop_shell *shell = es->private;
1927 configure_static_surface(es, &shell->panel_layer);
1931 desktop_shell_set_panel(struct wl_client *client,
1932 struct wl_resource *resource,
1933 struct wl_resource *output_resource,
1934 struct wl_resource *surface_resource)
1936 struct desktop_shell *shell = resource->data;
1937 struct weston_surface *surface = surface_resource->data;
1939 if (surface->configure) {
1940 wl_resource_post_error(surface_resource,
1941 WL_DISPLAY_ERROR_INVALID_OBJECT,
1942 "surface role already assigned");
1946 surface->configure = panel_configure;
1947 surface->private = shell;
1948 surface->output = output_resource->data;
1949 desktop_shell_send_configure(resource, 0,
1951 surface->output->width,
1952 surface->output->height);
1956 lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
1958 struct desktop_shell *shell = surface->private;
1960 center_on_output(surface, get_default_output(shell->compositor));
1962 if (!weston_surface_is_mapped(surface)) {
1963 wl_list_insert(&shell->lock_layer.surface_list,
1964 &surface->layer_link);
1965 weston_surface_assign_output(surface);
1966 weston_compositor_wake(shell->compositor);
1971 handle_lock_surface_destroy(struct wl_listener *listener, void *data)
1973 struct desktop_shell *shell =
1974 container_of(listener, struct desktop_shell, lock_surface_listener);
1976 weston_log("lock surface gone\n");
1977 shell->lock_surface = NULL;
1981 desktop_shell_set_lock_surface(struct wl_client *client,
1982 struct wl_resource *resource,
1983 struct wl_resource *surface_resource)
1985 struct desktop_shell *shell = resource->data;
1986 struct weston_surface *surface = surface_resource->data;
1988 shell->prepare_event_sent = false;
1993 shell->lock_surface = surface;
1995 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
1996 wl_signal_add(&surface_resource->destroy_signal,
1997 &shell->lock_surface_listener);
1999 surface->configure = lock_surface_configure;
2000 surface->private = shell;
2004 resume_desktop(struct desktop_shell *shell)
2006 struct weston_surface *surface;
2007 struct workspace *ws = get_current_workspace(shell);
2009 wl_list_for_each(surface, &shell->screensaver.surfaces, link)
2010 weston_surface_unmap(surface);
2012 terminate_screensaver(shell);
2014 wl_list_remove(&shell->lock_layer.link);
2015 wl_list_insert(&shell->compositor->cursor_layer.link,
2016 &shell->fullscreen_layer.link);
2017 wl_list_insert(&shell->fullscreen_layer.link,
2018 &shell->panel_layer.link);
2019 if (shell->showing_input_panels) {
2020 wl_list_insert(&shell->panel_layer.link,
2021 &shell->input_panel_layer.link);
2022 wl_list_insert(&shell->input_panel_layer.link,
2025 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
2028 restore_focus_state(shell, get_current_workspace(shell));
2030 shell->locked = false;
2031 shell->compositor->idle_time = shell->compositor->option_idle_time;
2032 weston_compositor_wake(shell->compositor);
2033 weston_compositor_damage_all(shell->compositor);
2037 desktop_shell_unlock(struct wl_client *client,
2038 struct wl_resource *resource)
2040 struct desktop_shell *shell = resource->data;
2042 shell->prepare_event_sent = false;
2045 resume_desktop(shell);
2049 desktop_shell_set_grab_surface(struct wl_client *client,
2050 struct wl_resource *resource,
2051 struct wl_resource *surface_resource)
2053 struct desktop_shell *shell = resource->data;
2055 shell->grab_surface = surface_resource->data;
2058 static const struct desktop_shell_interface desktop_shell_implementation = {
2059 desktop_shell_set_background,
2060 desktop_shell_set_panel,
2061 desktop_shell_set_lock_surface,
2062 desktop_shell_unlock,
2063 desktop_shell_set_grab_surface
2066 static enum shell_surface_type
2067 get_shell_surface_type(struct weston_surface *surface)
2069 struct shell_surface *shsurf;
2071 shsurf = get_shell_surface(surface);
2073 return SHELL_SURFACE_NONE;
2074 return shsurf->type;
2078 move_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data)
2080 struct weston_surface *surface =
2081 (struct weston_surface *) seat->pointer->focus;
2082 struct shell_surface *shsurf;
2084 if (surface == NULL)
2087 shsurf = get_shell_surface(surface);
2088 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN)
2091 surface_move(shsurf, (struct weston_seat *) seat);
2095 resize_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data)
2097 struct weston_surface *surface =
2098 (struct weston_surface *) seat->pointer->focus;
2101 struct shell_surface *shsurf;
2103 if (surface == NULL)
2106 shsurf = get_shell_surface(surface);
2107 if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN)
2110 weston_surface_from_global(surface,
2111 wl_fixed_to_int(seat->pointer->grab_x),
2112 wl_fixed_to_int(seat->pointer->grab_y),
2115 if (x < surface->geometry.width / 3)
2116 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
2117 else if (x < 2 * surface->geometry.width / 3)
2120 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
2122 if (y < surface->geometry.height / 3)
2123 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
2124 else if (y < 2 * surface->geometry.height / 3)
2127 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
2129 surface_resize(shsurf, (struct weston_seat *) seat, edges);
2133 surface_opacity_binding(struct wl_seat *seat, uint32_t time, uint32_t axis,
2134 wl_fixed_t value, void *data)
2137 struct shell_surface *shsurf;
2138 struct weston_surface *surface =
2139 (struct weston_surface *) seat->pointer->focus;
2141 if (surface == NULL)
2144 shsurf = get_shell_surface(surface);
2148 surface->alpha += wl_fixed_to_double(value) * step;
2150 if (surface->alpha > 1.0)
2151 surface->alpha = 1.0;
2152 if (surface->alpha < step)
2153 surface->alpha = step;
2155 surface->geometry.dirty = 1;
2156 weston_surface_damage(surface);
2160 do_zoom(struct wl_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
2163 struct weston_seat *ws = (struct weston_seat *) seat;
2164 struct weston_compositor *compositor = ws->compositor;
2165 struct weston_output *output;
2168 wl_list_for_each(output, &compositor->output_list, link) {
2169 if (pixman_region32_contains_point(&output->region,
2170 wl_fixed_to_double(seat->pointer->x),
2171 wl_fixed_to_double(seat->pointer->y),
2173 if (key == KEY_PAGEUP)
2174 increment = output->zoom.increment;
2175 else if (key == KEY_PAGEDOWN)
2176 increment = -output->zoom.increment;
2177 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
2178 increment = output->zoom.increment *
2179 wl_fixed_to_double(value);
2183 output->zoom.level += increment;
2185 if (output->zoom.level < 0.0)
2186 output->zoom.level = 0.0;
2187 else if (output->zoom.level > output->zoom.max_level)
2188 output->zoom.level = output->zoom.max_level;
2190 output->zoom.active = 1;
2191 output->disable_planes++;
2194 output->zoom.spring_z.target = output->zoom.level;
2196 weston_output_update_zoom(output, output->zoom.type);
2202 zoom_axis_binding(struct wl_seat *seat, uint32_t time, uint32_t axis,
2203 wl_fixed_t value, void *data)
2205 do_zoom(seat, time, 0, axis, value);
2209 zoom_key_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
2212 do_zoom(seat, time, key, 0, 0);
2216 terminate_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
2219 struct weston_compositor *compositor = data;
2221 wl_display_terminate(compositor->wl_display);
2225 rotate_grab_motion(struct wl_pointer_grab *grab,
2226 uint32_t time, wl_fixed_t x, wl_fixed_t y)
2228 struct rotate_grab *rotate =
2229 container_of(grab, struct rotate_grab, base.grab);
2230 struct wl_pointer *pointer = grab->pointer;
2231 struct shell_surface *shsurf = rotate->base.shsurf;
2232 struct weston_surface *surface;
2233 GLfloat cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
2238 surface = shsurf->surface;
2240 cx = 0.5f * surface->geometry.width;
2241 cy = 0.5f * surface->geometry.height;
2243 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
2244 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
2245 r = sqrtf(dx * dx + dy * dy);
2247 wl_list_remove(&shsurf->rotation.transform.link);
2248 shsurf->surface->geometry.dirty = 1;
2251 struct weston_matrix *matrix =
2252 &shsurf->rotation.transform.matrix;
2254 weston_matrix_init(&rotate->rotation);
2255 rotate->rotation.d[0] = dx / r;
2256 rotate->rotation.d[4] = -dy / r;
2257 rotate->rotation.d[1] = -rotate->rotation.d[4];
2258 rotate->rotation.d[5] = rotate->rotation.d[0];
2260 weston_matrix_init(matrix);
2261 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
2262 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
2263 weston_matrix_multiply(matrix, &rotate->rotation);
2264 weston_matrix_translate(matrix, cx, cy, 0.0f);
2267 &shsurf->surface->geometry.transformation_list,
2268 &shsurf->rotation.transform.link);
2270 wl_list_init(&shsurf->rotation.transform.link);
2271 weston_matrix_init(&shsurf->rotation.rotation);
2272 weston_matrix_init(&rotate->rotation);
2275 /* We need to adjust the position of the surface
2276 * in case it was resized in a rotated state before */
2277 cposx = surface->geometry.x + cx;
2278 cposy = surface->geometry.y + cy;
2279 dposx = rotate->center.x - cposx;
2280 dposy = rotate->center.y - cposy;
2281 if (dposx != 0.0f || dposy != 0.0f) {
2282 weston_surface_set_position(surface,
2283 surface->geometry.x + dposx,
2284 surface->geometry.y + dposy);
2287 /* Repaint implies weston_surface_update_transform(), which
2288 * lazily applies the damage due to rotation update.
2290 weston_compositor_schedule_repaint(shsurf->surface->compositor);
2294 rotate_grab_button(struct wl_pointer_grab *grab,
2295 uint32_t time, uint32_t button, uint32_t state_w)
2297 struct rotate_grab *rotate =
2298 container_of(grab, struct rotate_grab, base.grab);
2299 struct wl_pointer *pointer = grab->pointer;
2300 struct shell_surface *shsurf = rotate->base.shsurf;
2301 enum wl_pointer_button_state state = state_w;
2303 if (pointer->button_count == 0 &&
2304 state == WL_POINTER_BUTTON_STATE_RELEASED) {
2306 weston_matrix_multiply(&shsurf->rotation.rotation,
2308 shell_grab_end(&rotate->base);
2313 static const struct wl_pointer_grab_interface rotate_grab_interface = {
2320 rotate_binding(struct wl_seat *seat, uint32_t time, uint32_t button,
2323 struct weston_surface *base_surface =
2324 (struct weston_surface *) seat->pointer->focus;
2325 struct shell_surface *surface;
2326 struct rotate_grab *rotate;
2330 if (base_surface == NULL)
2333 surface = get_shell_surface(base_surface);
2334 if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN)
2337 rotate = malloc(sizeof *rotate);
2341 weston_surface_to_global_float(surface->surface,
2342 surface->surface->geometry.width / 2,
2343 surface->surface->geometry.height / 2,
2344 &rotate->center.x, &rotate->center.y);
2346 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
2347 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
2348 r = sqrtf(dx * dx + dy * dy);
2350 struct weston_matrix inverse;
2352 weston_matrix_init(&inverse);
2353 inverse.d[0] = dx / r;
2354 inverse.d[4] = dy / r;
2355 inverse.d[1] = -inverse.d[4];
2356 inverse.d[5] = inverse.d[0];
2357 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
2359 weston_matrix_init(&rotate->rotation);
2360 rotate->rotation.d[0] = dx / r;
2361 rotate->rotation.d[4] = -dy / r;
2362 rotate->rotation.d[1] = -rotate->rotation.d[4];
2363 rotate->rotation.d[5] = rotate->rotation.d[0];
2365 weston_matrix_init(&surface->rotation.rotation);
2366 weston_matrix_init(&rotate->rotation);
2369 shell_grab_start(&rotate->base, &rotate_grab_interface, surface,
2370 seat->pointer, DESKTOP_SHELL_CURSOR_ARROW);
2374 lower_fullscreen_layer(struct desktop_shell *shell)
2376 struct workspace *ws;
2377 struct weston_surface *surface, *prev;
2379 ws = get_current_workspace(shell);
2380 wl_list_for_each_reverse_safe(surface, prev,
2381 &shell->fullscreen_layer.surface_list,
2383 weston_surface_restack(surface, &ws->layer.surface_list);
2387 activate(struct desktop_shell *shell, struct weston_surface *es,
2388 struct weston_seat *seat)
2390 struct workspace *ws = get_current_workspace(shell);
2391 struct focus_state *state;
2393 weston_surface_activate(es, seat);
2395 wl_list_for_each(state, &ws->focus_list, link)
2396 if (state->seat == seat)
2399 if (&state->link == &ws->focus_list) {
2400 state = focus_state_create(seat, ws);
2405 state->keyboard_focus = es;
2406 wl_list_remove(&state->surface_destroy_listener.link);
2407 wl_signal_add(&es->surface.resource.destroy_signal,
2408 &state->surface_destroy_listener);
2410 switch (get_shell_surface_type(es)) {
2411 case SHELL_SURFACE_FULLSCREEN:
2412 /* should on top of panels */
2413 shell_stack_fullscreen(get_shell_surface(es));
2414 shell_configure_fullscreen(get_shell_surface(es));
2417 ws = get_current_workspace(shell);
2418 lower_fullscreen_layer(shell);
2419 weston_surface_restack(es, &ws->layer.surface_list);
2424 /* no-op func for checking black surface */
2426 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
2431 is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
2433 if (es->configure == black_surface_configure) {
2435 *fs_surface = (struct weston_surface *)es->private;
2442 click_to_activate_binding(struct wl_seat *seat, uint32_t time, uint32_t button,
2445 struct weston_seat *ws = (struct weston_seat *) seat;
2446 struct desktop_shell *shell = data;
2447 struct weston_surface *focus;
2448 struct weston_surface *upper;
2450 focus = (struct weston_surface *) seat->pointer->focus;
2454 if (is_black_surface(focus, &upper))
2457 if (get_shell_surface_type(focus) == SHELL_SURFACE_NONE)
2460 if (seat->pointer->grab == &seat->pointer->default_grab)
2461 activate(shell, focus, ws);
2465 lock(struct wl_listener *listener, void *data)
2467 struct desktop_shell *shell =
2468 container_of(listener, struct desktop_shell, lock_listener);
2469 struct weston_output *output;
2470 struct workspace *ws = get_current_workspace(shell);
2472 if (shell->locked) {
2473 wl_list_for_each(output, &shell->compositor->output_list, link)
2474 /* TODO: find a way to jump to other DPMS levels */
2475 if (output->set_dpms)
2476 output->set_dpms(output, WESTON_DPMS_STANDBY);
2480 shell->locked = true;
2482 /* Hide all surfaces by removing the fullscreen, panel and
2483 * toplevel layers. This way nothing else can show or receive
2484 * input events while we are locked. */
2486 wl_list_remove(&shell->panel_layer.link);
2487 wl_list_remove(&shell->fullscreen_layer.link);
2488 if (shell->showing_input_panels)
2489 wl_list_remove(&shell->input_panel_layer.link);
2490 wl_list_remove(&ws->layer.link);
2491 wl_list_insert(&shell->compositor->cursor_layer.link,
2492 &shell->lock_layer.link);
2494 launch_screensaver(shell);
2496 /* TODO: disable bindings that should not work while locked. */
2498 /* All this must be undone in resume_desktop(). */
2502 unlock(struct wl_listener *listener, void *data)
2504 struct desktop_shell *shell =
2505 container_of(listener, struct desktop_shell, unlock_listener);
2507 if (!shell->locked || shell->lock_surface) {
2508 weston_compositor_wake(shell->compositor);
2512 /* If desktop-shell client has gone away, unlock immediately. */
2513 if (!shell->child.desktop_shell) {
2514 resume_desktop(shell);
2518 if (shell->prepare_event_sent)
2521 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
2522 shell->prepare_event_sent = true;
2526 show_input_panels(struct wl_listener *listener, void *data)
2528 struct desktop_shell *shell =
2529 container_of(listener, struct desktop_shell,
2530 show_input_panel_listener);
2531 struct input_panel_surface *surface, *next;
2532 struct weston_surface *ws;
2534 shell->showing_input_panels = true;
2536 wl_list_insert(&shell->panel_layer.link,
2537 &shell->input_panel_layer.link);
2539 wl_list_for_each_safe(surface, next,
2540 &shell->input_panel.surfaces, link) {
2541 ws = surface->surface;
2542 wl_list_insert(&shell->input_panel_layer.surface_list,
2544 weston_surface_assign_output(ws);
2545 weston_surface_damage(ws);
2546 weston_slide_run(ws, ws->geometry.height, 0, NULL, NULL);
2551 hide_input_panels(struct wl_listener *listener, void *data)
2553 struct desktop_shell *shell =
2554 container_of(listener, struct desktop_shell,
2555 hide_input_panel_listener);
2556 struct weston_surface *surface, *next;
2558 shell->showing_input_panels = false;
2560 wl_list_remove(&shell->input_panel_layer.link);
2562 wl_list_for_each_safe(surface, next,
2563 &shell->input_panel_layer.surface_list, layer_link)
2564 weston_surface_unmap(surface);
2568 center_on_output(struct weston_surface *surface, struct weston_output *output)
2570 GLfloat x = (output->width - surface->buffer->width) / 2;
2571 GLfloat y = (output->height - surface->buffer->height) / 2;
2573 weston_surface_configure(surface, output->x + x, output->y + y,
2574 surface->buffer->width,
2575 surface->buffer->height);
2579 weston_surface_set_initial_position (struct weston_surface *surface,
2580 struct desktop_shell *shell)
2582 struct weston_compositor *compositor = shell->compositor;
2584 int range_x, range_y;
2585 int dx, dy, x, y, panel_height;
2586 struct weston_output *output, *target_output = NULL;
2587 struct weston_seat *seat;
2589 /* As a heuristic place the new window on the same output as the
2590 * pointer. Falling back to the output containing 0, 0.
2592 * TODO: Do something clever for touch too?
2594 wl_list_for_each(seat, &compositor->seat_list, link) {
2595 if (seat->has_pointer) {
2596 ix = wl_fixed_to_int(seat->pointer.x);
2597 iy = wl_fixed_to_int(seat->pointer.y);
2602 wl_list_for_each(output, &compositor->output_list, link) {
2603 if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) {
2604 target_output = output;
2609 if (!target_output) {
2610 weston_surface_set_position(surface, 10 + random() % 400,
2611 10 + random() % 400);
2615 /* Valid range within output where the surface will still be onscreen.
2616 * If this is negative it means that the surface is bigger than
2619 panel_height = get_output_panel_height(shell, target_output);
2620 range_x = target_output->width - surface->geometry.width;
2621 range_y = (target_output->height - panel_height) -
2622 surface->geometry.height;
2625 dx = random() % range_x;
2630 dy = panel_height + random() % range_y;
2634 x = target_output->x + dx;
2635 y = target_output->y + dy;
2637 weston_surface_set_position (surface, x, y);
2641 map(struct desktop_shell *shell, struct weston_surface *surface,
2642 int32_t width, int32_t height, int32_t sx, int32_t sy)
2644 struct weston_compositor *compositor = shell->compositor;
2645 struct shell_surface *shsurf = get_shell_surface(surface);
2646 enum shell_surface_type surface_type = shsurf->type;
2647 struct weston_surface *parent;
2648 struct weston_seat *seat;
2649 struct workspace *ws;
2650 int panel_height = 0;
2652 surface->geometry.width = width;
2653 surface->geometry.height = height;
2654 surface->geometry.dirty = 1;
2656 /* initial positioning, see also configure() */
2657 switch (surface_type) {
2658 case SHELL_SURFACE_TOPLEVEL:
2659 weston_surface_set_initial_position(surface, shell);
2661 case SHELL_SURFACE_FULLSCREEN:
2662 center_on_output(surface, shsurf->fullscreen_output);
2663 shell_map_fullscreen(shsurf);
2665 case SHELL_SURFACE_MAXIMIZED:
2666 /* use surface configure to set the geometry */
2667 panel_height = get_output_panel_height(shell,surface->output);
2668 weston_surface_set_position(surface, shsurf->output->x,
2669 shsurf->output->y + panel_height);
2671 case SHELL_SURFACE_POPUP:
2672 shell_map_popup(shsurf);
2673 case SHELL_SURFACE_NONE:
2674 weston_surface_set_position(surface,
2675 surface->geometry.x + sx,
2676 surface->geometry.y + sy);
2682 /* surface stacking order, see also activate() */
2683 switch (surface_type) {
2684 case SHELL_SURFACE_POPUP:
2685 case SHELL_SURFACE_TRANSIENT:
2686 parent = shsurf->parent;
2687 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
2689 case SHELL_SURFACE_FULLSCREEN:
2690 case SHELL_SURFACE_NONE:
2693 ws = get_current_workspace(shell);
2694 wl_list_insert(&ws->layer.surface_list, &surface->layer_link);
2698 if (surface_type != SHELL_SURFACE_NONE) {
2699 weston_surface_assign_output(surface);
2700 if (surface_type == SHELL_SURFACE_MAXIMIZED)
2701 surface->output = shsurf->output;
2704 switch (surface_type) {
2705 case SHELL_SURFACE_TRANSIENT:
2706 if (shsurf->transient.flags ==
2707 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
2709 case SHELL_SURFACE_TOPLEVEL:
2710 case SHELL_SURFACE_FULLSCREEN:
2711 case SHELL_SURFACE_MAXIMIZED:
2712 if (!shell->locked) {
2713 wl_list_for_each(seat, &compositor->seat_list, link)
2714 activate(shell, surface, seat);
2721 if (surface_type == SHELL_SURFACE_TOPLEVEL)
2723 switch (shell->win_animation_type) {
2724 case ANIMATION_FADE:
2725 weston_fade_run(surface, NULL, NULL);
2727 case ANIMATION_ZOOM:
2728 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
2737 configure(struct desktop_shell *shell, struct weston_surface *surface,
2738 GLfloat x, GLfloat y, int32_t width, int32_t height)
2740 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
2741 struct shell_surface *shsurf;
2743 shsurf = get_shell_surface(surface);
2745 surface_type = shsurf->type;
2747 surface->geometry.x = x;
2748 surface->geometry.y = y;
2749 surface->geometry.width = width;
2750 surface->geometry.height = height;
2751 surface->geometry.dirty = 1;
2753 switch (surface_type) {
2754 case SHELL_SURFACE_FULLSCREEN:
2755 shell_stack_fullscreen(shsurf);
2756 shell_configure_fullscreen(shsurf);
2758 case SHELL_SURFACE_MAXIMIZED:
2759 /* setting x, y and using configure to change that geometry */
2760 surface->geometry.x = surface->output->x;
2761 surface->geometry.y = surface->output->y +
2762 get_output_panel_height(shell,surface->output);
2764 case SHELL_SURFACE_TOPLEVEL:
2770 /* XXX: would a fullscreen surface need the same handling? */
2771 if (surface->output) {
2772 weston_surface_assign_output(surface);
2774 if (surface_type == SHELL_SURFACE_MAXIMIZED)
2775 surface->output = shsurf->output;
2780 shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
2782 struct shell_surface *shsurf = get_shell_surface(es);
2783 struct desktop_shell *shell = shsurf->shell;
2784 int type_changed = 0;
2786 if (shsurf->next_type != SHELL_SURFACE_NONE &&
2787 shsurf->type != shsurf->next_type) {
2788 set_surface_type(shsurf);
2792 if (!weston_surface_is_mapped(es)) {
2793 map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
2794 } else if (type_changed || sx != 0 || sy != 0 ||
2795 es->geometry.width != es->buffer->width ||
2796 es->geometry.height != es->buffer->height) {
2797 GLfloat from_x, from_y;
2800 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
2801 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
2802 configure(shell, es,
2803 es->geometry.x + to_x - from_x,
2804 es->geometry.y + to_y - from_y,
2805 es->buffer->width, es->buffer->height);
2809 static int launch_desktop_shell_process(struct desktop_shell *shell);
2812 desktop_shell_sigchld(struct weston_process *process, int status)
2815 struct desktop_shell *shell =
2816 container_of(process, struct desktop_shell, child.process);
2818 shell->child.process.pid = 0;
2819 shell->child.client = NULL; /* already destroyed by wayland */
2821 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
2822 time = weston_compositor_get_time();
2823 if (time - shell->child.deathstamp > 30000) {
2824 shell->child.deathstamp = time;
2825 shell->child.deathcount = 0;
2828 shell->child.deathcount++;
2829 if (shell->child.deathcount > 5) {
2830 weston_log("weston-desktop-shell died, giving up.\n");
2834 weston_log("weston-desktop-shell died, respawning...\n");
2835 launch_desktop_shell_process(shell);
2839 launch_desktop_shell_process(struct desktop_shell *shell)
2841 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
2843 shell->child.client = weston_client_launch(shell->compositor,
2844 &shell->child.process,
2846 desktop_shell_sigchld);
2848 if (!shell->child.client)
2854 bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
2856 struct desktop_shell *shell = data;
2858 wl_client_add_object(client, &wl_shell_interface,
2859 &shell_implementation, id, shell);
2863 unbind_desktop_shell(struct wl_resource *resource)
2865 struct desktop_shell *shell = resource->data;
2868 resume_desktop(shell);
2870 shell->child.desktop_shell = NULL;
2871 shell->prepare_event_sent = false;
2876 bind_desktop_shell(struct wl_client *client,
2877 void *data, uint32_t version, uint32_t id)
2879 struct desktop_shell *shell = data;
2880 struct wl_resource *resource;
2882 resource = wl_client_add_object(client, &desktop_shell_interface,
2883 &desktop_shell_implementation,
2886 if (client == shell->child.client) {
2887 resource->destroy = unbind_desktop_shell;
2888 shell->child.desktop_shell = resource;
2892 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2893 "permission to bind desktop_shell denied");
2894 wl_resource_destroy(resource);
2898 screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
2900 struct desktop_shell *shell = surface->private;
2905 center_on_output(surface, surface->output);
2907 if (wl_list_empty(&surface->layer_link)) {
2908 wl_list_insert(shell->lock_layer.surface_list.prev,
2909 &surface->layer_link);
2910 weston_surface_assign_output(surface);
2911 shell->compositor->idle_time = shell->screensaver.duration;
2912 weston_compositor_wake(shell->compositor);
2913 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
2918 screensaver_set_surface(struct wl_client *client,
2919 struct wl_resource *resource,
2920 struct wl_resource *surface_resource,
2921 struct wl_resource *output_resource)
2923 struct desktop_shell *shell = resource->data;
2924 struct weston_surface *surface = surface_resource->data;
2925 struct weston_output *output = output_resource->data;
2927 surface->configure = screensaver_configure;
2928 surface->private = shell;
2929 surface->output = output;
2932 static const struct screensaver_interface screensaver_implementation = {
2933 screensaver_set_surface
2937 unbind_screensaver(struct wl_resource *resource)
2939 struct desktop_shell *shell = resource->data;
2941 shell->screensaver.binding = NULL;
2946 bind_screensaver(struct wl_client *client,
2947 void *data, uint32_t version, uint32_t id)
2949 struct desktop_shell *shell = data;
2950 struct wl_resource *resource;
2952 resource = wl_client_add_object(client, &screensaver_interface,
2953 &screensaver_implementation,
2956 if (shell->screensaver.binding == NULL) {
2957 resource->destroy = unbind_screensaver;
2958 shell->screensaver.binding = resource;
2962 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2963 "interface object already bound");
2964 wl_resource_destroy(resource);
2968 input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
2970 struct weston_mode *mode = surface->output->current;
2971 GLfloat x = (mode->width - surface->buffer->width) / 2;
2972 GLfloat y = mode->height - surface->buffer->height;
2974 /* Don't map the input panel here, wait for
2975 * show_input_panels signal. */
2977 weston_surface_configure(surface,
2978 surface->output->x + x,
2979 surface->output->y + y,
2980 surface->buffer->width,
2981 surface->buffer->height);
2985 destroy_input_panel_surface(struct wl_listener *listener,
2988 struct input_panel_surface *input_panel_surface =
2989 container_of(listener, struct input_panel_surface, listener);
2991 wl_list_remove(&listener->link);
2992 wl_list_remove(&input_panel_surface->link);
2994 free(input_panel_surface);
2998 input_panel_set_surface(struct wl_client *client,
2999 struct wl_resource *resource,
3000 struct wl_resource *surface_resource,
3001 struct wl_resource *output_resource)
3003 struct desktop_shell *shell = resource->data;
3004 struct weston_surface *surface = surface_resource->data;
3005 struct weston_output *output = output_resource->data;
3006 struct input_panel_surface *input_panel_surface;
3008 surface->configure = input_panel_configure;
3009 surface->private = shell;
3010 surface->output = output;
3012 input_panel_surface = malloc(sizeof *input_panel_surface);
3013 if (!input_panel_surface) {
3014 wl_resource_post_no_memory(resource);
3018 input_panel_surface->surface = surface;
3019 input_panel_surface->listener.notify = destroy_input_panel_surface;
3021 wl_signal_add(&surface_resource->destroy_signal,
3022 &input_panel_surface->listener);
3024 wl_list_insert(&shell->input_panel.surfaces,
3025 &input_panel_surface->link);
3028 static const struct input_panel_interface input_panel_implementation = {
3029 input_panel_set_surface
3033 unbind_input_panel(struct wl_resource *resource)
3035 struct desktop_shell *shell = resource->data;
3037 shell->input_panel.binding = NULL;
3042 bind_input_panel(struct wl_client *client,
3043 void *data, uint32_t version, uint32_t id)
3045 struct desktop_shell *shell = data;
3046 struct wl_resource *resource;
3048 resource = wl_client_add_object(client, &input_panel_interface,
3049 &input_panel_implementation,
3052 if (shell->input_panel.binding == NULL) {
3053 resource->destroy = unbind_input_panel;
3054 shell->input_panel.binding = resource;
3058 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
3059 "interface object already bound");
3060 wl_resource_destroy(resource);
3064 struct desktop_shell *shell;
3065 struct weston_surface *current;
3066 struct wl_listener listener;
3067 struct wl_keyboard_grab grab;
3071 switcher_next(struct switcher *switcher)
3073 struct weston_surface *surface;
3074 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
3075 struct shell_surface *shsurf;
3076 struct workspace *ws = get_current_workspace(switcher->shell);
3078 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
3079 switch (get_shell_surface_type(surface)) {
3080 case SHELL_SURFACE_TOPLEVEL:
3081 case SHELL_SURFACE_FULLSCREEN:
3082 case SHELL_SURFACE_MAXIMIZED:
3085 if (prev == switcher->current)
3088 surface->alpha = 0.25;
3089 surface->geometry.dirty = 1;
3090 weston_surface_damage(surface);
3096 if (is_black_surface(surface, NULL)) {
3097 surface->alpha = 0.25;
3098 surface->geometry.dirty = 1;
3099 weston_surface_damage(surface);
3109 wl_list_remove(&switcher->listener.link);
3110 wl_signal_add(&next->surface.resource.destroy_signal,
3111 &switcher->listener);
3113 switcher->current = next;
3116 shsurf = get_shell_surface(switcher->current);
3117 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
3118 shsurf->fullscreen.black_surface->alpha = 1.0;
3122 switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
3124 struct switcher *switcher =
3125 container_of(listener, struct switcher, listener);
3127 switcher_next(switcher);
3131 switcher_destroy(struct switcher *switcher)
3133 struct weston_surface *surface;
3134 struct wl_keyboard *keyboard = switcher->grab.keyboard;
3135 struct workspace *ws = get_current_workspace(switcher->shell);
3137 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
3138 surface->alpha = 1.0;
3139 weston_surface_damage(surface);
3142 if (switcher->current)
3143 activate(switcher->shell, switcher->current,
3144 (struct weston_seat *) keyboard->seat);
3145 wl_list_remove(&switcher->listener.link);
3146 wl_keyboard_end_grab(keyboard);
3151 switcher_key(struct wl_keyboard_grab *grab,
3152 uint32_t time, uint32_t key, uint32_t state_w)
3154 struct switcher *switcher = container_of(grab, struct switcher, grab);
3155 enum wl_keyboard_key_state state = state_w;
3157 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
3158 switcher_next(switcher);
3162 switcher_modifier(struct wl_keyboard_grab *grab, uint32_t serial,
3163 uint32_t mods_depressed, uint32_t mods_latched,
3164 uint32_t mods_locked, uint32_t group)
3166 struct switcher *switcher = container_of(grab, struct switcher, grab);
3167 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
3169 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0)
3170 switcher_destroy(switcher);
3173 static const struct wl_keyboard_grab_interface switcher_grab = {
3179 switcher_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
3182 struct desktop_shell *shell = data;
3183 struct switcher *switcher;
3185 switcher = malloc(sizeof *switcher);
3186 switcher->shell = shell;
3187 switcher->current = NULL;
3188 switcher->listener.notify = switcher_handle_surface_destroy;
3189 wl_list_init(&switcher->listener.link);
3191 lower_fullscreen_layer(switcher->shell);
3192 switcher->grab.interface = &switcher_grab;
3193 wl_keyboard_start_grab(seat->keyboard, &switcher->grab);
3194 wl_keyboard_set_focus(seat->keyboard, NULL);
3195 switcher_next(switcher);
3199 backlight_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
3202 struct weston_compositor *compositor = data;
3203 struct weston_output *output;
3204 long backlight_new = 0;
3206 /* TODO: we're limiting to simple use cases, where we assume just
3207 * control on the primary display. We'd have to extend later if we
3208 * ever get support for setting backlights on random desktop LCD
3210 output = get_default_output(compositor);
3214 if (!output->set_backlight)
3217 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
3218 backlight_new = output->backlight_current - 25;
3219 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
3220 backlight_new = output->backlight_current + 25;
3222 if (backlight_new < 5)
3224 if (backlight_new > 255)
3225 backlight_new = 255;
3227 output->backlight_current = backlight_new;
3228 output->set_backlight(output, output->backlight_current);
3232 debug_repaint_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
3235 struct desktop_shell *shell = data;
3236 struct weston_compositor *compositor = shell->compositor;
3237 struct weston_surface *surface;
3238 struct weston_plane plane;
3240 if (shell->debug_repaint_surface) {
3241 weston_surface_destroy(shell->debug_repaint_surface);
3242 shell->debug_repaint_surface = NULL;
3244 surface = weston_surface_create(compositor);
3245 weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2);
3246 weston_surface_configure(surface, 0, 0, 8192, 8192);
3247 wl_list_insert(&compositor->fade_layer.surface_list,
3248 &surface->layer_link);
3249 weston_surface_assign_output(surface);
3250 pixman_region32_init(&surface->input);
3252 /* Here's the dirty little trick that makes the
3253 * repaint debugging work: we move the surface to a
3254 * different plane and force an update_transform to
3255 * update dependent state and clear the
3256 * geometry.dirty bit. This way the call to
3257 * damage_below() in update_transform() does not
3258 * add damage to the primary plane. */
3260 weston_plane_init(&plane, 0, 0);
3261 surface->plane = &plane;
3262 weston_surface_update_transform(surface);
3263 shell->debug_repaint_surface = surface;
3264 surface->plane = &compositor->primary_plane;
3265 weston_plane_release(&plane);
3271 fan_debug_repaint_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
3274 struct desktop_shell *shell = data;
3275 struct weston_compositor *compositor = shell->compositor;
3276 compositor->fan_debug = !compositor->fan_debug;
3277 weston_compositor_damage_all(compositor);
3281 force_kill_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
3284 struct wl_surface *focus_surface;
3285 struct wl_client *client;
3290 focus_surface = seat->keyboard->focus;
3294 client = focus_surface->resource.client;
3295 wl_client_get_credentials(client, &pid, &uid, &gid);
3301 workspace_up_binding(struct wl_seat *seat, uint32_t time,
3302 uint32_t key, void *data)
3304 struct desktop_shell *shell = data;
3305 unsigned int new_index = shell->workspaces.current;
3312 change_workspace(shell, new_index);
3316 workspace_down_binding(struct wl_seat *seat, uint32_t time,
3317 uint32_t key, void *data)
3319 struct desktop_shell *shell = data;
3320 unsigned int new_index = shell->workspaces.current;
3324 if (new_index < shell->workspaces.num - 1)
3327 change_workspace(shell, new_index);
3331 workspace_f_binding(struct wl_seat *seat, uint32_t time,
3332 uint32_t key, void *data)
3334 struct desktop_shell *shell = data;
3335 unsigned int new_index;
3339 new_index = key - KEY_F1;
3340 if (new_index >= shell->workspaces.num)
3341 new_index = shell->workspaces.num - 1;
3343 change_workspace(shell, new_index);
3348 shell_destroy(struct wl_listener *listener, void *data)
3350 struct desktop_shell *shell =
3351 container_of(listener, struct desktop_shell, destroy_listener);
3352 struct workspace **ws;
3354 if (shell->child.client)
3355 wl_client_destroy(shell->child.client);
3357 wl_list_remove(&shell->lock_listener.link);
3358 wl_list_remove(&shell->unlock_listener.link);
3359 wl_list_remove(&shell->show_input_panel_listener.link);
3360 wl_list_remove(&shell->hide_input_panel_listener.link);
3362 wl_array_for_each(ws, &shell->workspaces.array)
3363 workspace_destroy(*ws);
3364 wl_array_release(&shell->workspaces.array);
3366 free(shell->screensaver.path);
3371 shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
3374 int i, num_workspace_bindings;
3376 /* fixed bindings */
3377 weston_compositor_add_key_binding(ec, KEY_BACKSPACE,
3378 MODIFIER_CTRL | MODIFIER_ALT,
3379 terminate_binding, ec);
3380 weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
3381 click_to_activate_binding,
3383 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
3384 MODIFIER_SUPER | MODIFIER_ALT,
3385 surface_opacity_binding, NULL);
3386 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
3387 MODIFIER_SUPER, zoom_axis_binding,
3390 /* configurable bindings */
3391 mod = shell->binding_modifier;
3392 weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod,
3393 zoom_key_binding, NULL);
3394 weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod,
3395 zoom_key_binding, NULL);
3396 weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding,
3398 weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod,
3399 resize_binding, shell);
3400 weston_compositor_add_button_binding(ec, BTN_RIGHT, mod,
3401 rotate_binding, NULL);
3402 weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding,
3404 weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding,
3406 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0,
3407 backlight_binding, ec);
3408 weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding,
3410 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0,
3411 backlight_binding, ec);
3412 weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT,
3413 debug_repaint_binding, shell);
3414 weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_ALT,
3415 fan_debug_repaint_binding, shell);
3416 weston_compositor_add_key_binding(ec, KEY_K, mod,
3417 force_kill_binding, shell);
3418 weston_compositor_add_key_binding(ec, KEY_UP, mod,
3419 workspace_up_binding, shell);
3420 weston_compositor_add_key_binding(ec, KEY_DOWN, mod,
3421 workspace_down_binding, shell);
3423 /* Add bindings for mod+F[1-6] for workspace 1 to 6. */
3424 if (shell->workspaces.num > 1) {
3425 num_workspace_bindings = shell->workspaces.num;
3426 if (num_workspace_bindings > 6)
3427 num_workspace_bindings = 6;
3428 for (i = 0; i < num_workspace_bindings; i++)
3429 weston_compositor_add_key_binding(ec, KEY_F1 + i, mod,
3430 workspace_f_binding,
3436 shell_init(struct weston_compositor *ec);
3439 shell_init(struct weston_compositor *ec)
3441 struct weston_seat *seat;
3442 struct desktop_shell *shell;
3443 struct workspace **pws;
3446 shell = malloc(sizeof *shell);
3450 memset(shell, 0, sizeof *shell);
3451 shell->compositor = ec;
3453 shell->destroy_listener.notify = shell_destroy;
3454 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
3455 shell->lock_listener.notify = lock;
3456 wl_signal_add(&ec->lock_signal, &shell->lock_listener);
3457 shell->unlock_listener.notify = unlock;
3458 wl_signal_add(&ec->unlock_signal, &shell->unlock_listener);
3459 shell->show_input_panel_listener.notify = show_input_panels;
3460 wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener);
3461 shell->hide_input_panel_listener.notify = hide_input_panels;
3462 wl_signal_add(&ec->hide_input_panel_signal, &shell->hide_input_panel_listener);
3463 ec->ping_handler = ping_handler;
3464 ec->shell_interface.shell = shell;
3465 ec->shell_interface.create_shell_surface = create_shell_surface;
3466 ec->shell_interface.set_toplevel = set_toplevel;
3467 ec->shell_interface.set_transient = set_transient;
3468 ec->shell_interface.move = surface_move;
3469 ec->shell_interface.resize = surface_resize;
3471 wl_list_init(&shell->screensaver.surfaces);
3472 wl_list_init(&shell->input_panel.surfaces);
3474 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
3475 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
3476 weston_layer_init(&shell->background_layer, &shell->panel_layer.link);
3477 weston_layer_init(&shell->lock_layer, NULL);
3478 weston_layer_init(&shell->input_panel_layer, NULL);
3480 wl_array_init(&shell->workspaces.array);
3482 shell_configuration(shell);
3484 for (i = 0; i < shell->workspaces.num; i++) {
3485 pws = wl_array_add(&shell->workspaces.array, sizeof *pws);
3489 *pws = workspace_create();
3493 activate_workspace(shell, 0);
3495 wl_list_init(&shell->workspaces.animation.link);
3496 shell->workspaces.animation.frame = animate_workspace_change_frame;
3498 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
3499 shell, bind_shell) == NULL)
3502 if (wl_display_add_global(ec->wl_display,
3503 &desktop_shell_interface,
3504 shell, bind_desktop_shell) == NULL)
3507 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
3508 shell, bind_screensaver) == NULL)
3511 if (wl_display_add_global(ec->wl_display, &input_panel_interface,
3512 shell, bind_input_panel) == NULL)
3515 shell->child.deathstamp = weston_compositor_get_time();
3516 if (launch_desktop_shell_process(shell) != 0)
3519 wl_list_for_each(seat, &ec->seat_list, link)
3520 create_pointer_focus_listener(seat);
3522 shell_add_bindings(ec, shell);