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;
442 struct wl_surface *surface;
444 wl_list_for_each_safe(state, next, &ws->focus_list, link) {
445 surface = state->keyboard_focus ?
446 &state->keyboard_focus->surface : NULL;
448 wl_keyboard_set_focus(state->seat->seat.keyboard, surface);
453 workspace_destroy(struct workspace *ws)
455 struct focus_state *state, *next;
457 wl_list_for_each_safe(state, next, &ws->focus_list, link)
458 focus_state_destroy(state);
464 seat_destroyed(struct wl_listener *listener, void *data)
466 struct weston_seat *seat = data;
467 struct focus_state *state, *next;
468 struct workspace *ws = container_of(listener,
470 seat_destroyed_listener);
472 wl_list_for_each_safe(state, next, &ws->focus_list, link)
473 if (state->seat == seat)
474 wl_list_remove(&state->link);
477 static struct workspace *
478 workspace_create(void)
480 struct workspace *ws = malloc(sizeof *ws);
484 weston_layer_init(&ws->layer, NULL);
486 wl_list_init(&ws->focus_list);
487 wl_list_init(&ws->seat_destroyed_listener.link);
488 ws->seat_destroyed_listener.notify = seat_destroyed;
494 workspace_is_empty(struct workspace *ws)
496 return wl_list_empty(&ws->layer.surface_list);
499 static struct workspace *
500 get_workspace(struct desktop_shell *shell, unsigned int index)
502 struct workspace **pws = shell->workspaces.array.data;
507 static struct workspace *
508 get_current_workspace(struct desktop_shell *shell)
510 return get_workspace(shell, shell->workspaces.current);
514 activate_workspace(struct desktop_shell *shell, unsigned int index)
516 struct workspace *ws;
518 ws = get_workspace(shell, index);
519 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
521 shell->workspaces.current = index;
525 get_output_height(struct weston_output *output)
527 return abs(output->region.extents.y1 - output->region.extents.y2);
531 surface_translate(struct weston_surface *surface, double d)
533 struct shell_surface *shsurf = get_shell_surface(surface);
534 struct weston_transform *transform;
536 transform = &shsurf->workspace_transform;
537 if (wl_list_empty(&transform->link))
538 wl_list_insert(surface->geometry.transformation_list.prev,
539 &shsurf->workspace_transform.link);
541 weston_matrix_init(&shsurf->workspace_transform.matrix);
542 weston_matrix_translate(&shsurf->workspace_transform.matrix,
544 surface->geometry.dirty = 1;
548 workspace_translate_out(struct workspace *ws, double fraction)
550 struct weston_surface *surface;
554 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
555 height = get_output_height(surface->output);
556 d = height * fraction;
558 surface_translate(surface, d);
563 workspace_translate_in(struct workspace *ws, double fraction)
565 struct weston_surface *surface;
569 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
570 height = get_output_height(surface->output);
573 d = -(height - height * fraction);
575 d = height + height * fraction;
577 surface_translate(surface, d);
582 reverse_workspace_change_animation(struct desktop_shell *shell,
584 struct workspace *from,
585 struct workspace *to)
587 shell->workspaces.current = index;
589 shell->workspaces.anim_to = to;
590 shell->workspaces.anim_from = from;
591 shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir;
592 shell->workspaces.anim_timestamp = 0;
594 restore_focus_state(shell, to);
596 weston_compositor_schedule_repaint(shell->compositor);
600 workspace_deactivate_transforms(struct workspace *ws)
602 struct weston_surface *surface;
603 struct shell_surface *shsurf;
605 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
606 shsurf = get_shell_surface(surface);
607 wl_list_remove(&shsurf->workspace_transform.link);
608 wl_list_init(&shsurf->workspace_transform.link);
609 shsurf->surface->geometry.dirty = 1;
614 finish_workspace_change_animation(struct desktop_shell *shell,
615 struct workspace *from,
616 struct workspace *to)
618 weston_compositor_schedule_repaint(shell->compositor);
620 wl_list_remove(&shell->workspaces.animation.link);
621 workspace_deactivate_transforms(from);
622 workspace_deactivate_transforms(to);
623 shell->workspaces.anim_to = NULL;
625 wl_list_remove(&shell->workspaces.anim_from->layer.link);
629 animate_workspace_change_frame(struct weston_animation *animation,
630 struct weston_output *output, uint32_t msecs)
632 struct desktop_shell *shell =
633 container_of(animation, struct desktop_shell,
634 workspaces.animation);
635 struct workspace *from = shell->workspaces.anim_from;
636 struct workspace *to = shell->workspaces.anim_to;
640 if (workspace_is_empty(from) && workspace_is_empty(to)) {
641 finish_workspace_change_animation(shell, from, to);
645 if (shell->workspaces.anim_timestamp == 0) {
646 if (shell->workspaces.anim_current == 0.0)
647 shell->workspaces.anim_timestamp = msecs;
649 shell->workspaces.anim_timestamp =
651 /* Invers of movement function 'y' below. */
652 (asin(1.0 - shell->workspaces.anim_current) *
653 DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH *
657 t = msecs - shell->workspaces.anim_timestamp;
663 x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2;
666 if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) {
667 weston_compositor_schedule_repaint(shell->compositor);
669 workspace_translate_out(from, shell->workspaces.anim_dir * y);
670 workspace_translate_in(to, shell->workspaces.anim_dir * y);
671 shell->workspaces.anim_current = y;
673 weston_compositor_schedule_repaint(shell->compositor);
676 finish_workspace_change_animation(shell, from, to);
680 animate_workspace_change(struct desktop_shell *shell,
682 struct workspace *from,
683 struct workspace *to)
685 struct weston_output *output;
689 if (index > shell->workspaces.current)
694 shell->workspaces.current = index;
696 shell->workspaces.anim_dir = dir;
697 shell->workspaces.anim_from = from;
698 shell->workspaces.anim_to = to;
699 shell->workspaces.anim_current = 0.0;
700 shell->workspaces.anim_timestamp = 0;
702 output = container_of(shell->compositor->output_list.next,
703 struct weston_output, link);
704 wl_list_insert(&output->animation_list,
705 &shell->workspaces.animation.link);
707 wl_list_insert(&from->layer.link, &to->layer.link);
709 workspace_translate_in(to, 0);
711 restore_focus_state(shell, to);
713 weston_compositor_schedule_repaint(shell->compositor);
717 change_workspace(struct desktop_shell *shell, unsigned int index)
719 struct workspace *from;
720 struct workspace *to;
722 if (index == shell->workspaces.current)
725 /* Don't change workspace when there is any fullscreen surfaces. */
726 if (!wl_list_empty(&shell->fullscreen_layer.surface_list))
729 from = get_current_workspace(shell);
730 to = get_workspace(shell, index);
732 if (shell->workspaces.anim_from == to &&
733 shell->workspaces.anim_to == from) {
734 reverse_workspace_change_animation(shell, index, from, to);
738 if (shell->workspaces.anim_to != NULL)
739 finish_workspace_change_animation(shell,
740 shell->workspaces.anim_from,
741 shell->workspaces.anim_to);
743 if (workspace_is_empty(to) && workspace_is_empty(from)) {
744 shell->workspaces.current = index;
745 wl_list_insert(&from->layer.link, &to->layer.link);
746 wl_list_remove(&from->layer.link);
748 restore_focus_state(shell, to);
751 animate_workspace_change(shell, index, from, to);
755 noop_grab_focus(struct wl_pointer_grab *grab,
756 struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
762 move_grab_motion(struct wl_pointer_grab *grab,
763 uint32_t time, wl_fixed_t x, wl_fixed_t y)
765 struct weston_move_grab *move = (struct weston_move_grab *) grab;
766 struct wl_pointer *pointer = grab->pointer;
767 struct shell_surface *shsurf = move->base.shsurf;
768 struct weston_surface *es;
769 int dx = wl_fixed_to_int(pointer->x + move->dx);
770 int dy = wl_fixed_to_int(pointer->y + move->dy);
775 es = shsurf->surface;
777 weston_surface_configure(es, dx, dy,
778 es->geometry.width, es->geometry.height);
780 weston_compositor_schedule_repaint(es->compositor);
784 move_grab_button(struct wl_pointer_grab *grab,
785 uint32_t time, uint32_t button, uint32_t state_w)
787 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
789 struct wl_pointer *pointer = grab->pointer;
790 enum wl_pointer_button_state state = state_w;
792 if (pointer->button_count == 0 &&
793 state == WL_POINTER_BUTTON_STATE_RELEASED) {
794 shell_grab_end(shell_grab);
799 static const struct wl_pointer_grab_interface move_grab_interface = {
806 surface_move(struct shell_surface *shsurf, struct weston_seat *ws)
808 struct weston_move_grab *move;
813 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
816 move = malloc(sizeof *move);
820 move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
821 ws->seat.pointer->grab_x;
822 move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
823 ws->seat.pointer->grab_y;
825 shell_grab_start(&move->base, &move_grab_interface, shsurf,
826 ws->seat.pointer, DESKTOP_SHELL_CURSOR_MOVE);
832 shell_surface_move(struct wl_client *client, struct wl_resource *resource,
833 struct wl_resource *seat_resource, uint32_t serial)
835 struct weston_seat *ws = seat_resource->data;
836 struct shell_surface *shsurf = resource->data;
838 if (ws->seat.pointer->button_count == 0 ||
839 ws->seat.pointer->grab_serial != serial ||
840 ws->seat.pointer->focus != &shsurf->surface->surface)
843 if (surface_move(shsurf, ws) < 0)
844 wl_resource_post_no_memory(resource);
847 struct weston_resize_grab {
848 struct shell_grab base;
850 int32_t width, height;
854 resize_grab_motion(struct wl_pointer_grab *grab,
855 uint32_t time, wl_fixed_t x, wl_fixed_t y)
857 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
858 struct wl_pointer *pointer = grab->pointer;
859 struct shell_surface *shsurf = resize->base.shsurf;
860 int32_t width, height;
861 wl_fixed_t from_x, from_y;
862 wl_fixed_t to_x, to_y;
867 weston_surface_from_global_fixed(shsurf->surface,
868 pointer->grab_x, pointer->grab_y,
870 weston_surface_from_global_fixed(shsurf->surface,
871 pointer->x, pointer->y, &to_x, &to_y);
873 width = resize->width;
874 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
875 width += wl_fixed_to_int(from_x - to_x);
876 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
877 width += wl_fixed_to_int(to_x - from_x);
880 height = resize->height;
881 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
882 height += wl_fixed_to_int(from_y - to_y);
883 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
884 height += wl_fixed_to_int(to_y - from_y);
887 shsurf->client->send_configure(shsurf->surface,
888 resize->edges, width, height);
892 send_configure(struct weston_surface *surface,
893 uint32_t edges, int32_t width, int32_t height)
895 struct shell_surface *shsurf = get_shell_surface(surface);
897 wl_shell_surface_send_configure(&shsurf->resource,
898 edges, width, height);
901 static const struct weston_shell_client shell_client = {
906 resize_grab_button(struct wl_pointer_grab *grab,
907 uint32_t time, uint32_t button, uint32_t state_w)
909 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
910 struct wl_pointer *pointer = grab->pointer;
911 enum wl_pointer_button_state state = state_w;
913 if (pointer->button_count == 0 &&
914 state == WL_POINTER_BUTTON_STATE_RELEASED) {
915 shell_grab_end(&resize->base);
920 static const struct wl_pointer_grab_interface resize_grab_interface = {
927 surface_resize(struct shell_surface *shsurf,
928 struct weston_seat *ws, uint32_t edges)
930 struct weston_resize_grab *resize;
932 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
935 if (edges == 0 || edges > 15 ||
936 (edges & 3) == 3 || (edges & 12) == 12)
939 resize = malloc(sizeof *resize);
943 resize->edges = edges;
944 resize->width = shsurf->surface->geometry.width;
945 resize->height = shsurf->surface->geometry.height;
947 shell_grab_start(&resize->base, &resize_grab_interface, shsurf,
948 ws->seat.pointer, edges);
954 shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
955 struct wl_resource *seat_resource, uint32_t serial,
958 struct weston_seat *ws = seat_resource->data;
959 struct shell_surface *shsurf = resource->data;
961 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
964 if (ws->seat.pointer->button_count == 0 ||
965 ws->seat.pointer->grab_serial != serial ||
966 ws->seat.pointer->focus != &shsurf->surface->surface)
969 if (surface_resize(shsurf, ws, edges) < 0)
970 wl_resource_post_no_memory(resource);
974 busy_cursor_grab_focus(struct wl_pointer_grab *base,
975 struct wl_surface *surface, int32_t x, int32_t y)
977 struct shell_grab *grab = (struct shell_grab *) base;
979 if (grab->grab.focus != surface) {
980 shell_grab_end(grab);
986 busy_cursor_grab_motion(struct wl_pointer_grab *grab,
987 uint32_t time, int32_t x, int32_t y)
992 busy_cursor_grab_button(struct wl_pointer_grab *base,
993 uint32_t time, uint32_t button, uint32_t state)
995 struct shell_grab *grab = (struct shell_grab *) base;
996 struct shell_surface *shsurf;
997 struct weston_surface *surface =
998 (struct weston_surface *) grab->grab.pointer->current;
999 struct weston_seat *seat =
1000 (struct weston_seat *) grab->grab.pointer->seat;
1002 shsurf = get_shell_surface(surface);
1003 if (shsurf && button == BTN_LEFT && state) {
1004 activate(shsurf->shell, shsurf->surface, seat);
1005 surface_move(shsurf, seat);
1009 static const struct wl_pointer_grab_interface busy_cursor_grab_interface = {
1010 busy_cursor_grab_focus,
1011 busy_cursor_grab_motion,
1012 busy_cursor_grab_button,
1016 set_busy_cursor(struct shell_surface *shsurf, struct wl_pointer *pointer)
1018 struct shell_grab *grab;
1020 grab = malloc(sizeof *grab);
1024 shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer,
1025 DESKTOP_SHELL_CURSOR_BUSY);
1029 end_busy_cursor(struct shell_surface *shsurf, struct wl_pointer *pointer)
1031 struct shell_grab *grab = (struct shell_grab *) pointer->grab;
1033 if (grab->grab.interface == &busy_cursor_grab_interface) {
1034 shell_grab_end(grab);
1040 ping_timer_destroy(struct shell_surface *shsurf)
1042 if (!shsurf || !shsurf->ping_timer)
1045 if (shsurf->ping_timer->source)
1046 wl_event_source_remove(shsurf->ping_timer->source);
1048 free(shsurf->ping_timer);
1049 shsurf->ping_timer = NULL;
1053 ping_timeout_handler(void *data)
1055 struct shell_surface *shsurf = data;
1056 struct weston_seat *seat;
1058 /* Client is not responding */
1059 shsurf->unresponsive = 1;
1061 wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link)
1062 if (seat->seat.pointer->focus == &shsurf->surface->surface)
1063 set_busy_cursor(shsurf, seat->seat.pointer);
1069 ping_handler(struct weston_surface *surface, uint32_t serial)
1071 struct shell_surface *shsurf = get_shell_surface(surface);
1072 struct wl_event_loop *loop;
1073 int ping_timeout = 200;
1077 if (!shsurf->resource.client)
1080 if (shsurf->surface == shsurf->shell->grab_surface)
1083 if (!shsurf->ping_timer) {
1084 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
1085 if (!shsurf->ping_timer)
1088 shsurf->ping_timer->serial = serial;
1089 loop = wl_display_get_event_loop(surface->compositor->wl_display);
1090 shsurf->ping_timer->source =
1091 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
1092 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
1094 wl_shell_surface_send_ping(&shsurf->resource, serial);
1099 handle_pointer_focus(struct wl_listener *listener, void *data)
1101 struct wl_pointer *pointer = data;
1102 struct weston_surface *surface =
1103 (struct weston_surface *) pointer->focus;
1104 struct weston_compositor *compositor;
1105 struct shell_surface *shsurf;
1111 compositor = surface->compositor;
1112 shsurf = get_shell_surface(surface);
1114 if (shsurf && shsurf->unresponsive) {
1115 set_busy_cursor(shsurf, pointer);
1117 serial = wl_display_next_serial(compositor->wl_display);
1118 ping_handler(surface, serial);
1123 create_pointer_focus_listener(struct weston_seat *seat)
1125 struct wl_listener *listener;
1127 if (!seat->seat.pointer)
1130 listener = malloc(sizeof *listener);
1131 listener->notify = handle_pointer_focus;
1132 wl_signal_add(&seat->seat.pointer->focus_signal, listener);
1136 shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
1139 struct shell_surface *shsurf = resource->data;
1140 struct desktop_shell *shell = shsurf->shell;
1141 struct weston_seat *seat;
1142 struct weston_compositor *ec = shsurf->surface->compositor;
1143 struct wl_pointer *pointer;
1144 int was_unresponsive;
1146 if (shsurf->ping_timer == NULL)
1147 /* Just ignore unsolicited pong. */
1150 if (shsurf->ping_timer->serial == serial) {
1151 was_unresponsive = shsurf->unresponsive;
1152 shsurf->unresponsive = 0;
1153 if (was_unresponsive) {
1154 /* Received pong from previously unresponsive client */
1155 wl_list_for_each(seat, &ec->seat_list, link) {
1156 pointer = seat->seat.pointer;
1157 if (pointer->focus ==
1158 &shell->grab_surface->surface &&
1160 &shsurf->surface->surface)
1161 end_busy_cursor(shsurf, pointer);
1164 ping_timer_destroy(shsurf);
1169 shell_surface_set_title(struct wl_client *client,
1170 struct wl_resource *resource, const char *title)
1172 struct shell_surface *shsurf = resource->data;
1174 free(shsurf->title);
1175 shsurf->title = strdup(title);
1179 shell_surface_set_class(struct wl_client *client,
1180 struct wl_resource *resource, const char *class)
1182 struct shell_surface *shsurf = resource->data;
1184 free(shsurf->class);
1185 shsurf->class = strdup(class);
1188 static struct weston_output *
1189 get_default_output(struct weston_compositor *compositor)
1191 return container_of(compositor->output_list.next,
1192 struct weston_output, link);
1196 shell_unset_fullscreen(struct shell_surface *shsurf)
1198 /* undo all fullscreen things here */
1199 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1200 shell_surface_is_top_fullscreen(shsurf)) {
1201 weston_output_switch_mode(shsurf->fullscreen_output,
1202 shsurf->fullscreen_output->origin);
1204 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1205 shsurf->fullscreen.framerate = 0;
1206 wl_list_remove(&shsurf->fullscreen.transform.link);
1207 wl_list_init(&shsurf->fullscreen.transform.link);
1208 if (shsurf->fullscreen.black_surface)
1209 weston_surface_destroy(shsurf->fullscreen.black_surface);
1210 shsurf->fullscreen.black_surface = NULL;
1211 shsurf->fullscreen_output = NULL;
1212 weston_surface_set_position(shsurf->surface,
1213 shsurf->saved_x, shsurf->saved_y);
1214 if (shsurf->saved_rotation_valid) {
1215 wl_list_insert(&shsurf->surface->geometry.transformation_list,
1216 &shsurf->rotation.transform.link);
1217 shsurf->saved_rotation_valid = false;
1222 reset_shell_surface_type(struct shell_surface *surface)
1224 switch (surface->type) {
1225 case SHELL_SURFACE_FULLSCREEN:
1226 shell_unset_fullscreen(surface);
1228 case SHELL_SURFACE_MAXIMIZED:
1229 surface->output = get_default_output(surface->surface->compositor);
1230 weston_surface_set_position(surface->surface,
1234 case SHELL_SURFACE_NONE:
1235 case SHELL_SURFACE_TOPLEVEL:
1236 case SHELL_SURFACE_TRANSIENT:
1237 case SHELL_SURFACE_POPUP:
1241 surface->type = SHELL_SURFACE_NONE;
1246 set_surface_type(struct shell_surface *shsurf)
1248 struct weston_surface *surface = shsurf->surface;
1249 struct weston_surface *pes = shsurf->parent;
1251 reset_shell_surface_type(shsurf);
1253 shsurf->type = shsurf->next_type;
1254 shsurf->next_type = SHELL_SURFACE_NONE;
1256 switch (shsurf->type) {
1257 case SHELL_SURFACE_TOPLEVEL:
1259 case SHELL_SURFACE_TRANSIENT:
1260 weston_surface_set_position(surface,
1261 pes->geometry.x + shsurf->transient.x,
1262 pes->geometry.y + shsurf->transient.y);
1265 case SHELL_SURFACE_MAXIMIZED:
1266 shsurf->saved_x = surface->geometry.x;
1267 shsurf->saved_y = surface->geometry.y;
1268 shsurf->saved_position_valid = true;
1271 case SHELL_SURFACE_FULLSCREEN:
1272 shsurf->saved_x = surface->geometry.x;
1273 shsurf->saved_y = surface->geometry.y;
1274 shsurf->saved_position_valid = true;
1276 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
1277 wl_list_remove(&shsurf->rotation.transform.link);
1278 wl_list_init(&shsurf->rotation.transform.link);
1279 shsurf->surface->geometry.dirty = 1;
1280 shsurf->saved_rotation_valid = true;
1290 set_toplevel(struct shell_surface *shsurf)
1292 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
1296 shell_surface_set_toplevel(struct wl_client *client,
1297 struct wl_resource *resource)
1299 struct shell_surface *surface = resource->data;
1301 set_toplevel(surface);
1305 set_transient(struct shell_surface *shsurf,
1306 struct weston_surface *parent, int x, int y, uint32_t flags)
1308 /* assign to parents output */
1309 shsurf->parent = parent;
1310 shsurf->transient.x = x;
1311 shsurf->transient.y = y;
1312 shsurf->transient.flags = flags;
1313 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
1317 shell_surface_set_transient(struct wl_client *client,
1318 struct wl_resource *resource,
1319 struct wl_resource *parent_resource,
1320 int x, int y, uint32_t flags)
1322 struct shell_surface *shsurf = resource->data;
1323 struct weston_surface *parent = parent_resource->data;
1325 set_transient(shsurf, parent, x, y, flags);
1328 static struct desktop_shell *
1329 shell_surface_get_shell(struct shell_surface *shsurf)
1331 return shsurf->shell;
1335 get_output_panel_height(struct desktop_shell *shell,
1336 struct weston_output *output)
1338 struct weston_surface *surface;
1339 int panel_height = 0;
1344 wl_list_for_each(surface, &shell->panel_layer.surface_list, layer_link) {
1345 if (surface->output == output) {
1346 panel_height = surface->geometry.height;
1351 return panel_height;
1355 shell_surface_set_maximized(struct wl_client *client,
1356 struct wl_resource *resource,
1357 struct wl_resource *output_resource )
1359 struct shell_surface *shsurf = resource->data;
1360 struct weston_surface *es = shsurf->surface;
1361 struct desktop_shell *shell = NULL;
1362 uint32_t edges = 0, panel_height = 0;
1364 /* get the default output, if the client set it as NULL
1365 check whether the ouput is available */
1366 if (output_resource)
1367 shsurf->output = output_resource->data;
1368 else if (es->output)
1369 shsurf->output = es->output;
1371 shsurf->output = get_default_output(es->compositor);
1373 shell = shell_surface_get_shell(shsurf);
1374 panel_height = get_output_panel_height(shell, shsurf->output);
1375 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
1377 shsurf->client->send_configure(shsurf->surface, edges,
1378 shsurf->output->width,
1379 shsurf->output->height - panel_height);
1381 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
1385 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy);
1387 static struct weston_surface *
1388 create_black_surface(struct weston_compositor *ec,
1389 struct weston_surface *fs_surface,
1390 GLfloat x, GLfloat y, int w, int h)
1392 struct weston_surface *surface = NULL;
1394 surface = weston_surface_create(ec);
1395 if (surface == NULL) {
1396 weston_log("no memory\n");
1400 surface->configure = black_surface_configure;
1401 surface->private = fs_surface;
1402 weston_surface_configure(surface, x, y, w, h);
1403 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
1404 pixman_region32_init_rect(&surface->opaque, 0, 0, w, h);
1409 /* Create black surface and append it to the associated fullscreen surface.
1410 * Handle size dismatch and positioning according to the method. */
1412 shell_configure_fullscreen(struct shell_surface *shsurf)
1414 struct weston_output *output = shsurf->fullscreen_output;
1415 struct weston_surface *surface = shsurf->surface;
1416 struct weston_matrix *matrix;
1417 float scale, output_aspect, surface_aspect, x, y;
1419 if (!shsurf->fullscreen.black_surface)
1420 shsurf->fullscreen.black_surface =
1421 create_black_surface(surface->compositor,
1423 output->x, output->y,
1427 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
1428 wl_list_insert(&surface->layer_link,
1429 &shsurf->fullscreen.black_surface->layer_link);
1430 shsurf->fullscreen.black_surface->output = output;
1432 switch (shsurf->fullscreen.type) {
1433 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
1434 if (surface->buffer)
1435 center_on_output(surface, shsurf->fullscreen_output);
1437 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
1438 matrix = &shsurf->fullscreen.transform.matrix;
1439 weston_matrix_init(matrix);
1441 output_aspect = (float) output->width /
1442 (float) output->height;
1443 surface_aspect = (float) surface->geometry.width /
1444 (float) surface->geometry.height;
1445 if (output_aspect < surface_aspect)
1446 scale = (float) output->width /
1447 (float) surface->geometry.width;
1449 scale = (float) output->height /
1450 (float) surface->geometry.height;
1452 weston_matrix_scale(matrix, scale, scale, 1);
1453 wl_list_remove(&shsurf->fullscreen.transform.link);
1454 wl_list_insert(&surface->geometry.transformation_list,
1455 &shsurf->fullscreen.transform.link);
1456 x = output->x + (output->width - surface->geometry.width * scale) / 2;
1457 y = output->y + (output->height - surface->geometry.height * scale) / 2;
1458 weston_surface_set_position(surface, x, y);
1461 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
1462 if (shell_surface_is_top_fullscreen(shsurf)) {
1463 struct weston_mode mode = {0,
1464 surface->geometry.width,
1465 surface->geometry.height,
1466 shsurf->fullscreen.framerate};
1468 if (weston_output_switch_mode(output, &mode) == 0) {
1469 weston_surface_configure(shsurf->fullscreen.black_surface,
1470 output->x, output->y,
1473 weston_surface_set_position(surface, output->x, output->y);
1478 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
1485 /* make the fullscreen and black surface at the top */
1487 shell_stack_fullscreen(struct shell_surface *shsurf)
1489 struct weston_output *output = shsurf->fullscreen_output;
1490 struct weston_surface *surface = shsurf->surface;
1491 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
1493 wl_list_remove(&surface->layer_link);
1494 wl_list_insert(&shell->fullscreen_layer.surface_list,
1495 &surface->layer_link);
1496 weston_surface_damage(surface);
1498 if (!shsurf->fullscreen.black_surface)
1499 shsurf->fullscreen.black_surface =
1500 create_black_surface(surface->compositor,
1502 output->x, output->y,
1506 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
1507 wl_list_insert(&surface->layer_link,
1508 &shsurf->fullscreen.black_surface->layer_link);
1509 weston_surface_damage(shsurf->fullscreen.black_surface);
1513 shell_map_fullscreen(struct shell_surface *shsurf)
1515 shell_stack_fullscreen(shsurf);
1516 shell_configure_fullscreen(shsurf);
1520 shell_surface_set_fullscreen(struct wl_client *client,
1521 struct wl_resource *resource,
1524 struct wl_resource *output_resource)
1526 struct shell_surface *shsurf = resource->data;
1527 struct weston_surface *es = shsurf->surface;
1529 if (output_resource)
1530 shsurf->output = output_resource->data;
1531 else if (es->output)
1532 shsurf->output = es->output;
1534 shsurf->output = get_default_output(es->compositor);
1536 shsurf->fullscreen_output = shsurf->output;
1537 shsurf->fullscreen.type = method;
1538 shsurf->fullscreen.framerate = framerate;
1539 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
1541 shsurf->client->send_configure(shsurf->surface, 0,
1542 shsurf->output->width,
1543 shsurf->output->height);
1547 popup_grab_focus(struct wl_pointer_grab *grab,
1548 struct wl_surface *surface,
1552 struct wl_pointer *pointer = grab->pointer;
1553 struct shell_surface *priv =
1554 container_of(grab, struct shell_surface, popup.grab);
1555 struct wl_client *client = priv->surface->surface.resource.client;
1557 if (surface && surface->resource.client == client) {
1558 wl_pointer_set_focus(pointer, surface, x, y);
1559 grab->focus = surface;
1561 wl_pointer_set_focus(pointer, NULL,
1562 wl_fixed_from_int(0),
1563 wl_fixed_from_int(0));
1569 popup_grab_motion(struct wl_pointer_grab *grab,
1570 uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
1572 struct wl_resource *resource;
1574 resource = grab->pointer->focus_resource;
1576 wl_pointer_send_motion(resource, time, sx, sy);
1580 popup_grab_button(struct wl_pointer_grab *grab,
1581 uint32_t time, uint32_t button, uint32_t state_w)
1583 struct wl_resource *resource;
1584 struct shell_surface *shsurf =
1585 container_of(grab, struct shell_surface, popup.grab);
1586 struct wl_display *display;
1587 enum wl_pointer_button_state state = state_w;
1590 resource = grab->pointer->focus_resource;
1592 display = wl_client_get_display(resource->client);
1593 serial = wl_display_get_serial(display);
1594 wl_pointer_send_button(resource, serial, time, button, state);
1595 } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
1596 (shsurf->popup.initial_up ||
1597 time - shsurf->popup.seat->pointer->grab_time > 500)) {
1598 wl_shell_surface_send_popup_done(&shsurf->resource);
1599 wl_pointer_end_grab(grab->pointer);
1600 shsurf->popup.grab.pointer = NULL;
1603 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
1604 shsurf->popup.initial_up = 1;
1607 static const struct wl_pointer_grab_interface popup_grab_interface = {
1614 shell_map_popup(struct shell_surface *shsurf)
1616 struct wl_seat *seat = shsurf->popup.seat;
1617 struct weston_surface *es = shsurf->surface;
1618 struct weston_surface *parent = shsurf->parent;
1620 es->output = parent->output;
1621 shsurf->popup.grab.interface = &popup_grab_interface;
1623 weston_surface_update_transform(parent);
1624 if (parent->transform.enabled) {
1625 shsurf->popup.parent_transform.matrix =
1626 parent->transform.matrix;
1628 /* construct x, y translation matrix */
1629 weston_matrix_init(&shsurf->popup.parent_transform.matrix);
1630 shsurf->popup.parent_transform.matrix.d[12] =
1632 shsurf->popup.parent_transform.matrix.d[13] =
1635 wl_list_insert(es->geometry.transformation_list.prev,
1636 &shsurf->popup.parent_transform.link);
1637 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
1639 shsurf->popup.initial_up = 0;
1641 /* We don't require the grab to still be active, but if another
1642 * grab has started in the meantime, we end the popup now. */
1643 if (seat->pointer->grab_serial == shsurf->popup.serial) {
1644 wl_pointer_start_grab(seat->pointer, &shsurf->popup.grab);
1646 wl_shell_surface_send_popup_done(&shsurf->resource);
1651 shell_surface_set_popup(struct wl_client *client,
1652 struct wl_resource *resource,
1653 struct wl_resource *seat_resource,
1655 struct wl_resource *parent_resource,
1656 int32_t x, int32_t y, uint32_t flags)
1658 struct shell_surface *shsurf = resource->data;
1660 shsurf->type = SHELL_SURFACE_POPUP;
1661 shsurf->parent = parent_resource->data;
1662 shsurf->popup.seat = seat_resource->data;
1663 shsurf->popup.serial = serial;
1664 shsurf->popup.x = x;
1665 shsurf->popup.y = y;
1668 static const struct wl_shell_surface_interface shell_surface_implementation = {
1671 shell_surface_resize,
1672 shell_surface_set_toplevel,
1673 shell_surface_set_transient,
1674 shell_surface_set_fullscreen,
1675 shell_surface_set_popup,
1676 shell_surface_set_maximized,
1677 shell_surface_set_title,
1678 shell_surface_set_class
1682 destroy_shell_surface(struct shell_surface *shsurf)
1684 if (shsurf->popup.grab.pointer)
1685 wl_pointer_end_grab(shsurf->popup.grab.pointer);
1687 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1688 shell_surface_is_top_fullscreen(shsurf)) {
1689 weston_output_switch_mode(shsurf->fullscreen_output,
1690 shsurf->fullscreen_output->origin);
1693 if (shsurf->fullscreen.black_surface)
1694 weston_surface_destroy(shsurf->fullscreen.black_surface);
1696 /* As destroy_resource() use wl_list_for_each_safe(),
1697 * we can always remove the listener.
1699 wl_list_remove(&shsurf->surface_destroy_listener.link);
1700 shsurf->surface->configure = NULL;
1701 ping_timer_destroy(shsurf);
1703 wl_list_remove(&shsurf->link);
1708 shell_destroy_shell_surface(struct wl_resource *resource)
1710 struct shell_surface *shsurf = resource->data;
1712 destroy_shell_surface(shsurf);
1716 shell_handle_surface_destroy(struct wl_listener *listener, void *data)
1718 struct shell_surface *shsurf = container_of(listener,
1719 struct shell_surface,
1720 surface_destroy_listener);
1722 if (shsurf->resource.client) {
1723 wl_resource_destroy(&shsurf->resource);
1725 wl_signal_emit(&shsurf->resource.destroy_signal,
1727 destroy_shell_surface(shsurf);
1732 shell_surface_configure(struct weston_surface *, int32_t, int32_t);
1734 static struct shell_surface *
1735 get_shell_surface(struct weston_surface *surface)
1737 if (surface->configure == shell_surface_configure)
1738 return surface->private;
1743 static struct shell_surface *
1744 create_shell_surface(void *shell, struct weston_surface *surface,
1745 const struct weston_shell_client *client)
1747 struct shell_surface *shsurf;
1749 if (surface->configure) {
1750 weston_log("surface->configure already set\n");
1754 shsurf = calloc(1, sizeof *shsurf);
1756 weston_log("no memory to allocate shell surface\n");
1760 surface->configure = shell_surface_configure;
1761 surface->private = shsurf;
1763 shsurf->shell = (struct desktop_shell *) shell;
1764 shsurf->unresponsive = 0;
1765 shsurf->saved_position_valid = false;
1766 shsurf->saved_rotation_valid = false;
1767 shsurf->surface = surface;
1768 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1769 shsurf->fullscreen.framerate = 0;
1770 shsurf->fullscreen.black_surface = NULL;
1771 shsurf->ping_timer = NULL;
1772 wl_list_init(&shsurf->fullscreen.transform.link);
1774 wl_signal_init(&shsurf->resource.destroy_signal);
1775 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
1776 wl_signal_add(&surface->surface.resource.destroy_signal,
1777 &shsurf->surface_destroy_listener);
1779 /* init link so its safe to always remove it in destroy_shell_surface */
1780 wl_list_init(&shsurf->link);
1782 /* empty when not in use */
1783 wl_list_init(&shsurf->rotation.transform.link);
1784 weston_matrix_init(&shsurf->rotation.rotation);
1786 wl_list_init(&shsurf->workspace_transform.link);
1788 shsurf->type = SHELL_SURFACE_NONE;
1789 shsurf->next_type = SHELL_SURFACE_NONE;
1791 shsurf->client = client;
1797 shell_get_shell_surface(struct wl_client *client,
1798 struct wl_resource *resource,
1800 struct wl_resource *surface_resource)
1802 struct weston_surface *surface = surface_resource->data;
1803 struct desktop_shell *shell = resource->data;
1804 struct shell_surface *shsurf;
1806 if (get_shell_surface(surface)) {
1807 wl_resource_post_error(surface_resource,
1808 WL_DISPLAY_ERROR_INVALID_OBJECT,
1809 "desktop_shell::get_shell_surface already requested");
1813 shsurf = create_shell_surface(shell, surface, &shell_client);
1815 wl_resource_post_error(surface_resource,
1816 WL_DISPLAY_ERROR_INVALID_OBJECT,
1817 "surface->configure already set");
1821 shsurf->resource.destroy = shell_destroy_shell_surface;
1822 shsurf->resource.object.id = id;
1823 shsurf->resource.object.interface = &wl_shell_surface_interface;
1824 shsurf->resource.object.implementation =
1825 (void (**)(void)) &shell_surface_implementation;
1826 shsurf->resource.data = shsurf;
1828 wl_client_add_resource(client, &shsurf->resource);
1831 static const struct wl_shell_interface shell_implementation = {
1832 shell_get_shell_surface
1836 handle_screensaver_sigchld(struct weston_process *proc, int status)
1842 launch_screensaver(struct desktop_shell *shell)
1844 if (shell->screensaver.binding)
1847 if (!shell->screensaver.path)
1850 if (shell->screensaver.process.pid != 0) {
1851 weston_log("old screensaver still running\n");
1855 weston_client_launch(shell->compositor,
1856 &shell->screensaver.process,
1857 shell->screensaver.path,
1858 handle_screensaver_sigchld);
1862 terminate_screensaver(struct desktop_shell *shell)
1864 if (shell->screensaver.process.pid == 0)
1867 kill(shell->screensaver.process.pid, SIGTERM);
1871 configure_static_surface(struct weston_surface *es, struct weston_layer *layer)
1873 struct weston_surface *s, *next;
1875 wl_list_for_each_safe(s, next, &layer->surface_list, layer_link) {
1876 if (s->output == es->output && s != es) {
1877 weston_surface_unmap(s);
1878 s->configure = NULL;
1882 weston_surface_configure(es, es->output->x, es->output->y,
1883 es->buffer->width, es->buffer->height);
1885 if (wl_list_empty(&es->layer_link)) {
1886 wl_list_insert(&layer->surface_list, &es->layer_link);
1887 weston_compositor_schedule_repaint(es->compositor);
1892 background_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1894 struct desktop_shell *shell = es->private;
1896 configure_static_surface(es, &shell->background_layer);
1900 desktop_shell_set_background(struct wl_client *client,
1901 struct wl_resource *resource,
1902 struct wl_resource *output_resource,
1903 struct wl_resource *surface_resource)
1905 struct desktop_shell *shell = resource->data;
1906 struct weston_surface *surface = surface_resource->data;
1908 if (surface->configure) {
1909 wl_resource_post_error(surface_resource,
1910 WL_DISPLAY_ERROR_INVALID_OBJECT,
1911 "surface role already assigned");
1915 surface->configure = background_configure;
1916 surface->private = shell;
1917 surface->output = output_resource->data;
1918 desktop_shell_send_configure(resource, 0,
1920 surface->output->width,
1921 surface->output->height);
1925 panel_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1927 struct desktop_shell *shell = es->private;
1929 configure_static_surface(es, &shell->panel_layer);
1933 desktop_shell_set_panel(struct wl_client *client,
1934 struct wl_resource *resource,
1935 struct wl_resource *output_resource,
1936 struct wl_resource *surface_resource)
1938 struct desktop_shell *shell = resource->data;
1939 struct weston_surface *surface = surface_resource->data;
1941 if (surface->configure) {
1942 wl_resource_post_error(surface_resource,
1943 WL_DISPLAY_ERROR_INVALID_OBJECT,
1944 "surface role already assigned");
1948 surface->configure = panel_configure;
1949 surface->private = shell;
1950 surface->output = output_resource->data;
1951 desktop_shell_send_configure(resource, 0,
1953 surface->output->width,
1954 surface->output->height);
1958 lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
1960 struct desktop_shell *shell = surface->private;
1962 center_on_output(surface, get_default_output(shell->compositor));
1964 if (!weston_surface_is_mapped(surface)) {
1965 wl_list_insert(&shell->lock_layer.surface_list,
1966 &surface->layer_link);
1967 weston_surface_assign_output(surface);
1968 weston_compositor_wake(shell->compositor);
1973 handle_lock_surface_destroy(struct wl_listener *listener, void *data)
1975 struct desktop_shell *shell =
1976 container_of(listener, struct desktop_shell, lock_surface_listener);
1978 weston_log("lock surface gone\n");
1979 shell->lock_surface = NULL;
1983 desktop_shell_set_lock_surface(struct wl_client *client,
1984 struct wl_resource *resource,
1985 struct wl_resource *surface_resource)
1987 struct desktop_shell *shell = resource->data;
1988 struct weston_surface *surface = surface_resource->data;
1990 shell->prepare_event_sent = false;
1995 shell->lock_surface = surface;
1997 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
1998 wl_signal_add(&surface_resource->destroy_signal,
1999 &shell->lock_surface_listener);
2001 surface->configure = lock_surface_configure;
2002 surface->private = shell;
2006 resume_desktop(struct desktop_shell *shell)
2008 struct weston_surface *surface;
2009 struct workspace *ws = get_current_workspace(shell);
2011 wl_list_for_each(surface, &shell->screensaver.surfaces, link)
2012 weston_surface_unmap(surface);
2014 terminate_screensaver(shell);
2016 wl_list_remove(&shell->lock_layer.link);
2017 wl_list_insert(&shell->compositor->cursor_layer.link,
2018 &shell->fullscreen_layer.link);
2019 wl_list_insert(&shell->fullscreen_layer.link,
2020 &shell->panel_layer.link);
2021 if (shell->showing_input_panels) {
2022 wl_list_insert(&shell->panel_layer.link,
2023 &shell->input_panel_layer.link);
2024 wl_list_insert(&shell->input_panel_layer.link,
2027 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
2030 restore_focus_state(shell, get_current_workspace(shell));
2032 shell->locked = false;
2033 shell->compositor->idle_time = shell->compositor->option_idle_time;
2034 weston_compositor_wake(shell->compositor);
2035 weston_compositor_damage_all(shell->compositor);
2039 desktop_shell_unlock(struct wl_client *client,
2040 struct wl_resource *resource)
2042 struct desktop_shell *shell = resource->data;
2044 shell->prepare_event_sent = false;
2047 resume_desktop(shell);
2051 desktop_shell_set_grab_surface(struct wl_client *client,
2052 struct wl_resource *resource,
2053 struct wl_resource *surface_resource)
2055 struct desktop_shell *shell = resource->data;
2057 shell->grab_surface = surface_resource->data;
2060 static const struct desktop_shell_interface desktop_shell_implementation = {
2061 desktop_shell_set_background,
2062 desktop_shell_set_panel,
2063 desktop_shell_set_lock_surface,
2064 desktop_shell_unlock,
2065 desktop_shell_set_grab_surface
2068 static enum shell_surface_type
2069 get_shell_surface_type(struct weston_surface *surface)
2071 struct shell_surface *shsurf;
2073 shsurf = get_shell_surface(surface);
2075 return SHELL_SURFACE_NONE;
2076 return shsurf->type;
2080 move_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data)
2082 struct weston_surface *surface =
2083 (struct weston_surface *) seat->pointer->focus;
2084 struct shell_surface *shsurf;
2086 if (surface == NULL)
2089 shsurf = get_shell_surface(surface);
2090 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN)
2093 surface_move(shsurf, (struct weston_seat *) seat);
2097 resize_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data)
2099 struct weston_surface *surface =
2100 (struct weston_surface *) seat->pointer->focus;
2103 struct shell_surface *shsurf;
2105 if (surface == NULL)
2108 shsurf = get_shell_surface(surface);
2109 if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN)
2112 weston_surface_from_global(surface,
2113 wl_fixed_to_int(seat->pointer->grab_x),
2114 wl_fixed_to_int(seat->pointer->grab_y),
2117 if (x < surface->geometry.width / 3)
2118 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
2119 else if (x < 2 * surface->geometry.width / 3)
2122 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
2124 if (y < surface->geometry.height / 3)
2125 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
2126 else if (y < 2 * surface->geometry.height / 3)
2129 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
2131 surface_resize(shsurf, (struct weston_seat *) seat, edges);
2135 surface_opacity_binding(struct wl_seat *seat, uint32_t time, uint32_t axis,
2136 wl_fixed_t value, void *data)
2139 struct shell_surface *shsurf;
2140 struct weston_surface *surface =
2141 (struct weston_surface *) seat->pointer->focus;
2143 if (surface == NULL)
2146 shsurf = get_shell_surface(surface);
2150 surface->alpha += wl_fixed_to_double(value) * step;
2152 if (surface->alpha > 1.0)
2153 surface->alpha = 1.0;
2154 if (surface->alpha < step)
2155 surface->alpha = step;
2157 surface->geometry.dirty = 1;
2158 weston_surface_damage(surface);
2162 do_zoom(struct wl_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
2165 struct weston_seat *ws = (struct weston_seat *) seat;
2166 struct weston_compositor *compositor = ws->compositor;
2167 struct weston_output *output;
2170 wl_list_for_each(output, &compositor->output_list, link) {
2171 if (pixman_region32_contains_point(&output->region,
2172 wl_fixed_to_double(seat->pointer->x),
2173 wl_fixed_to_double(seat->pointer->y),
2175 if (key == KEY_PAGEUP)
2176 increment = output->zoom.increment;
2177 else if (key == KEY_PAGEDOWN)
2178 increment = -output->zoom.increment;
2179 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
2180 increment = output->zoom.increment *
2181 wl_fixed_to_double(value);
2185 output->zoom.level += increment;
2187 if (output->zoom.level < 0.0)
2188 output->zoom.level = 0.0;
2189 else if (output->zoom.level > output->zoom.max_level)
2190 output->zoom.level = output->zoom.max_level;
2192 output->zoom.active = 1;
2193 output->disable_planes++;
2196 output->zoom.spring_z.target = output->zoom.level;
2198 weston_output_update_zoom(output, output->zoom.type);
2204 zoom_axis_binding(struct wl_seat *seat, uint32_t time, uint32_t axis,
2205 wl_fixed_t value, void *data)
2207 do_zoom(seat, time, 0, axis, value);
2211 zoom_key_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
2214 do_zoom(seat, time, key, 0, 0);
2218 terminate_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
2221 struct weston_compositor *compositor = data;
2223 wl_display_terminate(compositor->wl_display);
2227 rotate_grab_motion(struct wl_pointer_grab *grab,
2228 uint32_t time, wl_fixed_t x, wl_fixed_t y)
2230 struct rotate_grab *rotate =
2231 container_of(grab, struct rotate_grab, base.grab);
2232 struct wl_pointer *pointer = grab->pointer;
2233 struct shell_surface *shsurf = rotate->base.shsurf;
2234 struct weston_surface *surface;
2235 GLfloat cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
2240 surface = shsurf->surface;
2242 cx = 0.5f * surface->geometry.width;
2243 cy = 0.5f * surface->geometry.height;
2245 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
2246 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
2247 r = sqrtf(dx * dx + dy * dy);
2249 wl_list_remove(&shsurf->rotation.transform.link);
2250 shsurf->surface->geometry.dirty = 1;
2253 struct weston_matrix *matrix =
2254 &shsurf->rotation.transform.matrix;
2256 weston_matrix_init(&rotate->rotation);
2257 rotate->rotation.d[0] = dx / r;
2258 rotate->rotation.d[4] = -dy / r;
2259 rotate->rotation.d[1] = -rotate->rotation.d[4];
2260 rotate->rotation.d[5] = rotate->rotation.d[0];
2262 weston_matrix_init(matrix);
2263 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
2264 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
2265 weston_matrix_multiply(matrix, &rotate->rotation);
2266 weston_matrix_translate(matrix, cx, cy, 0.0f);
2269 &shsurf->surface->geometry.transformation_list,
2270 &shsurf->rotation.transform.link);
2272 wl_list_init(&shsurf->rotation.transform.link);
2273 weston_matrix_init(&shsurf->rotation.rotation);
2274 weston_matrix_init(&rotate->rotation);
2277 /* We need to adjust the position of the surface
2278 * in case it was resized in a rotated state before */
2279 cposx = surface->geometry.x + cx;
2280 cposy = surface->geometry.y + cy;
2281 dposx = rotate->center.x - cposx;
2282 dposy = rotate->center.y - cposy;
2283 if (dposx != 0.0f || dposy != 0.0f) {
2284 weston_surface_set_position(surface,
2285 surface->geometry.x + dposx,
2286 surface->geometry.y + dposy);
2289 /* Repaint implies weston_surface_update_transform(), which
2290 * lazily applies the damage due to rotation update.
2292 weston_compositor_schedule_repaint(shsurf->surface->compositor);
2296 rotate_grab_button(struct wl_pointer_grab *grab,
2297 uint32_t time, uint32_t button, uint32_t state_w)
2299 struct rotate_grab *rotate =
2300 container_of(grab, struct rotate_grab, base.grab);
2301 struct wl_pointer *pointer = grab->pointer;
2302 struct shell_surface *shsurf = rotate->base.shsurf;
2303 enum wl_pointer_button_state state = state_w;
2305 if (pointer->button_count == 0 &&
2306 state == WL_POINTER_BUTTON_STATE_RELEASED) {
2308 weston_matrix_multiply(&shsurf->rotation.rotation,
2310 shell_grab_end(&rotate->base);
2315 static const struct wl_pointer_grab_interface rotate_grab_interface = {
2322 rotate_binding(struct wl_seat *seat, uint32_t time, uint32_t button,
2325 struct weston_surface *base_surface =
2326 (struct weston_surface *) seat->pointer->focus;
2327 struct shell_surface *surface;
2328 struct rotate_grab *rotate;
2332 if (base_surface == NULL)
2335 surface = get_shell_surface(base_surface);
2336 if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN)
2339 rotate = malloc(sizeof *rotate);
2343 weston_surface_to_global_float(surface->surface,
2344 surface->surface->geometry.width / 2,
2345 surface->surface->geometry.height / 2,
2346 &rotate->center.x, &rotate->center.y);
2348 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
2349 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
2350 r = sqrtf(dx * dx + dy * dy);
2352 struct weston_matrix inverse;
2354 weston_matrix_init(&inverse);
2355 inverse.d[0] = dx / r;
2356 inverse.d[4] = dy / r;
2357 inverse.d[1] = -inverse.d[4];
2358 inverse.d[5] = inverse.d[0];
2359 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
2361 weston_matrix_init(&rotate->rotation);
2362 rotate->rotation.d[0] = dx / r;
2363 rotate->rotation.d[4] = -dy / r;
2364 rotate->rotation.d[1] = -rotate->rotation.d[4];
2365 rotate->rotation.d[5] = rotate->rotation.d[0];
2367 weston_matrix_init(&surface->rotation.rotation);
2368 weston_matrix_init(&rotate->rotation);
2371 shell_grab_start(&rotate->base, &rotate_grab_interface, surface,
2372 seat->pointer, DESKTOP_SHELL_CURSOR_ARROW);
2376 lower_fullscreen_layer(struct desktop_shell *shell)
2378 struct workspace *ws;
2379 struct weston_surface *surface, *prev;
2381 ws = get_current_workspace(shell);
2382 wl_list_for_each_reverse_safe(surface, prev,
2383 &shell->fullscreen_layer.surface_list,
2385 weston_surface_restack(surface, &ws->layer.surface_list);
2389 activate(struct desktop_shell *shell, struct weston_surface *es,
2390 struct weston_seat *seat)
2392 struct workspace *ws = get_current_workspace(shell);
2393 struct focus_state *state;
2395 weston_surface_activate(es, seat);
2397 wl_list_for_each(state, &ws->focus_list, link)
2398 if (state->seat == seat)
2401 if (&state->link == &ws->focus_list) {
2402 state = focus_state_create(seat, ws);
2407 state->keyboard_focus = es;
2408 wl_list_remove(&state->surface_destroy_listener.link);
2409 wl_signal_add(&es->surface.resource.destroy_signal,
2410 &state->surface_destroy_listener);
2412 switch (get_shell_surface_type(es)) {
2413 case SHELL_SURFACE_FULLSCREEN:
2414 /* should on top of panels */
2415 shell_stack_fullscreen(get_shell_surface(es));
2416 shell_configure_fullscreen(get_shell_surface(es));
2419 ws = get_current_workspace(shell);
2420 lower_fullscreen_layer(shell);
2421 weston_surface_restack(es, &ws->layer.surface_list);
2426 /* no-op func for checking black surface */
2428 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
2433 is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
2435 if (es->configure == black_surface_configure) {
2437 *fs_surface = (struct weston_surface *)es->private;
2444 click_to_activate_binding(struct wl_seat *seat, uint32_t time, uint32_t button,
2447 struct weston_seat *ws = (struct weston_seat *) seat;
2448 struct desktop_shell *shell = data;
2449 struct weston_surface *focus;
2450 struct weston_surface *upper;
2452 focus = (struct weston_surface *) seat->pointer->focus;
2456 if (is_black_surface(focus, &upper))
2459 if (get_shell_surface_type(focus) == SHELL_SURFACE_NONE)
2462 if (seat->pointer->grab == &seat->pointer->default_grab)
2463 activate(shell, focus, ws);
2467 lock(struct wl_listener *listener, void *data)
2469 struct desktop_shell *shell =
2470 container_of(listener, struct desktop_shell, lock_listener);
2471 struct weston_output *output;
2472 struct workspace *ws = get_current_workspace(shell);
2474 if (shell->locked) {
2475 wl_list_for_each(output, &shell->compositor->output_list, link)
2476 /* TODO: find a way to jump to other DPMS levels */
2477 if (output->set_dpms)
2478 output->set_dpms(output, WESTON_DPMS_STANDBY);
2482 shell->locked = true;
2484 /* Hide all surfaces by removing the fullscreen, panel and
2485 * toplevel layers. This way nothing else can show or receive
2486 * input events while we are locked. */
2488 wl_list_remove(&shell->panel_layer.link);
2489 wl_list_remove(&shell->fullscreen_layer.link);
2490 if (shell->showing_input_panels)
2491 wl_list_remove(&shell->input_panel_layer.link);
2492 wl_list_remove(&ws->layer.link);
2493 wl_list_insert(&shell->compositor->cursor_layer.link,
2494 &shell->lock_layer.link);
2496 launch_screensaver(shell);
2498 /* TODO: disable bindings that should not work while locked. */
2500 /* All this must be undone in resume_desktop(). */
2504 unlock(struct wl_listener *listener, void *data)
2506 struct desktop_shell *shell =
2507 container_of(listener, struct desktop_shell, unlock_listener);
2509 if (!shell->locked || shell->lock_surface) {
2510 weston_compositor_wake(shell->compositor);
2514 /* If desktop-shell client has gone away, unlock immediately. */
2515 if (!shell->child.desktop_shell) {
2516 resume_desktop(shell);
2520 if (shell->prepare_event_sent)
2523 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
2524 shell->prepare_event_sent = true;
2528 show_input_panels(struct wl_listener *listener, void *data)
2530 struct desktop_shell *shell =
2531 container_of(listener, struct desktop_shell,
2532 show_input_panel_listener);
2533 struct input_panel_surface *surface, *next;
2534 struct weston_surface *ws;
2536 shell->showing_input_panels = true;
2538 wl_list_insert(&shell->panel_layer.link,
2539 &shell->input_panel_layer.link);
2541 wl_list_for_each_safe(surface, next,
2542 &shell->input_panel.surfaces, link) {
2543 ws = surface->surface;
2544 wl_list_insert(&shell->input_panel_layer.surface_list,
2546 weston_surface_assign_output(ws);
2547 weston_surface_damage(ws);
2548 weston_slide_run(ws, ws->geometry.height, 0, NULL, NULL);
2553 hide_input_panels(struct wl_listener *listener, void *data)
2555 struct desktop_shell *shell =
2556 container_of(listener, struct desktop_shell,
2557 hide_input_panel_listener);
2558 struct weston_surface *surface, *next;
2560 shell->showing_input_panels = false;
2562 wl_list_remove(&shell->input_panel_layer.link);
2564 wl_list_for_each_safe(surface, next,
2565 &shell->input_panel_layer.surface_list, layer_link)
2566 weston_surface_unmap(surface);
2570 center_on_output(struct weston_surface *surface, struct weston_output *output)
2572 GLfloat x = (output->width - surface->buffer->width) / 2;
2573 GLfloat y = (output->height - surface->buffer->height) / 2;
2575 weston_surface_configure(surface, output->x + x, output->y + y,
2576 surface->buffer->width,
2577 surface->buffer->height);
2581 weston_surface_set_initial_position (struct weston_surface *surface,
2582 struct desktop_shell *shell)
2584 struct weston_compositor *compositor = shell->compositor;
2586 int range_x, range_y;
2587 int dx, dy, x, y, panel_height;
2588 struct weston_output *output, *target_output = NULL;
2589 struct weston_seat *seat;
2591 /* As a heuristic place the new window on the same output as the
2592 * pointer. Falling back to the output containing 0, 0.
2594 * TODO: Do something clever for touch too?
2596 wl_list_for_each(seat, &compositor->seat_list, link) {
2597 if (seat->has_pointer) {
2598 ix = wl_fixed_to_int(seat->pointer.x);
2599 iy = wl_fixed_to_int(seat->pointer.y);
2604 wl_list_for_each(output, &compositor->output_list, link) {
2605 if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) {
2606 target_output = output;
2611 if (!target_output) {
2612 weston_surface_set_position(surface, 10 + random() % 400,
2613 10 + random() % 400);
2617 /* Valid range within output where the surface will still be onscreen.
2618 * If this is negative it means that the surface is bigger than
2621 panel_height = get_output_panel_height(shell, target_output);
2622 range_x = target_output->width - surface->geometry.width;
2623 range_y = (target_output->height - panel_height) -
2624 surface->geometry.height;
2627 dx = random() % range_x;
2632 dy = panel_height + random() % range_y;
2636 x = target_output->x + dx;
2637 y = target_output->y + dy;
2639 weston_surface_set_position (surface, x, y);
2643 map(struct desktop_shell *shell, struct weston_surface *surface,
2644 int32_t width, int32_t height, int32_t sx, int32_t sy)
2646 struct weston_compositor *compositor = shell->compositor;
2647 struct shell_surface *shsurf = get_shell_surface(surface);
2648 enum shell_surface_type surface_type = shsurf->type;
2649 struct weston_surface *parent;
2650 struct weston_seat *seat;
2651 struct workspace *ws;
2652 int panel_height = 0;
2654 surface->geometry.width = width;
2655 surface->geometry.height = height;
2656 surface->geometry.dirty = 1;
2658 /* initial positioning, see also configure() */
2659 switch (surface_type) {
2660 case SHELL_SURFACE_TOPLEVEL:
2661 weston_surface_set_initial_position(surface, shell);
2663 case SHELL_SURFACE_FULLSCREEN:
2664 center_on_output(surface, shsurf->fullscreen_output);
2665 shell_map_fullscreen(shsurf);
2667 case SHELL_SURFACE_MAXIMIZED:
2668 /* use surface configure to set the geometry */
2669 panel_height = get_output_panel_height(shell,surface->output);
2670 weston_surface_set_position(surface, shsurf->output->x,
2671 shsurf->output->y + panel_height);
2673 case SHELL_SURFACE_POPUP:
2674 shell_map_popup(shsurf);
2675 case SHELL_SURFACE_NONE:
2676 weston_surface_set_position(surface,
2677 surface->geometry.x + sx,
2678 surface->geometry.y + sy);
2684 /* surface stacking order, see also activate() */
2685 switch (surface_type) {
2686 case SHELL_SURFACE_POPUP:
2687 case SHELL_SURFACE_TRANSIENT:
2688 parent = shsurf->parent;
2689 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
2691 case SHELL_SURFACE_FULLSCREEN:
2692 case SHELL_SURFACE_NONE:
2695 ws = get_current_workspace(shell);
2696 wl_list_insert(&ws->layer.surface_list, &surface->layer_link);
2700 if (surface_type != SHELL_SURFACE_NONE) {
2701 weston_surface_assign_output(surface);
2702 if (surface_type == SHELL_SURFACE_MAXIMIZED)
2703 surface->output = shsurf->output;
2706 switch (surface_type) {
2707 case SHELL_SURFACE_TRANSIENT:
2708 if (shsurf->transient.flags ==
2709 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
2711 case SHELL_SURFACE_TOPLEVEL:
2712 case SHELL_SURFACE_FULLSCREEN:
2713 case SHELL_SURFACE_MAXIMIZED:
2714 if (!shell->locked) {
2715 wl_list_for_each(seat, &compositor->seat_list, link)
2716 activate(shell, surface, seat);
2723 if (surface_type == SHELL_SURFACE_TOPLEVEL)
2725 switch (shell->win_animation_type) {
2726 case ANIMATION_FADE:
2727 weston_fade_run(surface, NULL, NULL);
2729 case ANIMATION_ZOOM:
2730 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
2739 configure(struct desktop_shell *shell, struct weston_surface *surface,
2740 GLfloat x, GLfloat y, int32_t width, int32_t height)
2742 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
2743 struct shell_surface *shsurf;
2745 shsurf = get_shell_surface(surface);
2747 surface_type = shsurf->type;
2749 surface->geometry.x = x;
2750 surface->geometry.y = y;
2751 surface->geometry.width = width;
2752 surface->geometry.height = height;
2753 surface->geometry.dirty = 1;
2755 switch (surface_type) {
2756 case SHELL_SURFACE_FULLSCREEN:
2757 shell_stack_fullscreen(shsurf);
2758 shell_configure_fullscreen(shsurf);
2760 case SHELL_SURFACE_MAXIMIZED:
2761 /* setting x, y and using configure to change that geometry */
2762 surface->geometry.x = surface->output->x;
2763 surface->geometry.y = surface->output->y +
2764 get_output_panel_height(shell,surface->output);
2766 case SHELL_SURFACE_TOPLEVEL:
2772 /* XXX: would a fullscreen surface need the same handling? */
2773 if (surface->output) {
2774 weston_surface_assign_output(surface);
2776 if (surface_type == SHELL_SURFACE_MAXIMIZED)
2777 surface->output = shsurf->output;
2782 shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
2784 struct shell_surface *shsurf = get_shell_surface(es);
2785 struct desktop_shell *shell = shsurf->shell;
2786 int type_changed = 0;
2788 if (shsurf->next_type != SHELL_SURFACE_NONE &&
2789 shsurf->type != shsurf->next_type) {
2790 set_surface_type(shsurf);
2794 if (!weston_surface_is_mapped(es)) {
2795 map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
2796 } else if (type_changed || sx != 0 || sy != 0 ||
2797 es->geometry.width != es->buffer->width ||
2798 es->geometry.height != es->buffer->height) {
2799 GLfloat from_x, from_y;
2802 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
2803 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
2804 configure(shell, es,
2805 es->geometry.x + to_x - from_x,
2806 es->geometry.y + to_y - from_y,
2807 es->buffer->width, es->buffer->height);
2811 static int launch_desktop_shell_process(struct desktop_shell *shell);
2814 desktop_shell_sigchld(struct weston_process *process, int status)
2817 struct desktop_shell *shell =
2818 container_of(process, struct desktop_shell, child.process);
2820 shell->child.process.pid = 0;
2821 shell->child.client = NULL; /* already destroyed by wayland */
2823 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
2824 time = weston_compositor_get_time();
2825 if (time - shell->child.deathstamp > 30000) {
2826 shell->child.deathstamp = time;
2827 shell->child.deathcount = 0;
2830 shell->child.deathcount++;
2831 if (shell->child.deathcount > 5) {
2832 weston_log("weston-desktop-shell died, giving up.\n");
2836 weston_log("weston-desktop-shell died, respawning...\n");
2837 launch_desktop_shell_process(shell);
2841 launch_desktop_shell_process(struct desktop_shell *shell)
2843 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
2845 shell->child.client = weston_client_launch(shell->compositor,
2846 &shell->child.process,
2848 desktop_shell_sigchld);
2850 if (!shell->child.client)
2856 bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
2858 struct desktop_shell *shell = data;
2860 wl_client_add_object(client, &wl_shell_interface,
2861 &shell_implementation, id, shell);
2865 unbind_desktop_shell(struct wl_resource *resource)
2867 struct desktop_shell *shell = resource->data;
2870 resume_desktop(shell);
2872 shell->child.desktop_shell = NULL;
2873 shell->prepare_event_sent = false;
2878 bind_desktop_shell(struct wl_client *client,
2879 void *data, uint32_t version, uint32_t id)
2881 struct desktop_shell *shell = data;
2882 struct wl_resource *resource;
2884 resource = wl_client_add_object(client, &desktop_shell_interface,
2885 &desktop_shell_implementation,
2888 if (client == shell->child.client) {
2889 resource->destroy = unbind_desktop_shell;
2890 shell->child.desktop_shell = resource;
2894 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2895 "permission to bind desktop_shell denied");
2896 wl_resource_destroy(resource);
2900 screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
2902 struct desktop_shell *shell = surface->private;
2907 center_on_output(surface, surface->output);
2909 if (wl_list_empty(&surface->layer_link)) {
2910 wl_list_insert(shell->lock_layer.surface_list.prev,
2911 &surface->layer_link);
2912 weston_surface_assign_output(surface);
2913 shell->compositor->idle_time = shell->screensaver.duration;
2914 weston_compositor_wake(shell->compositor);
2915 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
2920 screensaver_set_surface(struct wl_client *client,
2921 struct wl_resource *resource,
2922 struct wl_resource *surface_resource,
2923 struct wl_resource *output_resource)
2925 struct desktop_shell *shell = resource->data;
2926 struct weston_surface *surface = surface_resource->data;
2927 struct weston_output *output = output_resource->data;
2929 surface->configure = screensaver_configure;
2930 surface->private = shell;
2931 surface->output = output;
2934 static const struct screensaver_interface screensaver_implementation = {
2935 screensaver_set_surface
2939 unbind_screensaver(struct wl_resource *resource)
2941 struct desktop_shell *shell = resource->data;
2943 shell->screensaver.binding = NULL;
2948 bind_screensaver(struct wl_client *client,
2949 void *data, uint32_t version, uint32_t id)
2951 struct desktop_shell *shell = data;
2952 struct wl_resource *resource;
2954 resource = wl_client_add_object(client, &screensaver_interface,
2955 &screensaver_implementation,
2958 if (shell->screensaver.binding == NULL) {
2959 resource->destroy = unbind_screensaver;
2960 shell->screensaver.binding = resource;
2964 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2965 "interface object already bound");
2966 wl_resource_destroy(resource);
2970 input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
2972 struct weston_mode *mode = surface->output->current;
2973 GLfloat x = (mode->width - surface->buffer->width) / 2;
2974 GLfloat y = mode->height - surface->buffer->height;
2976 /* Don't map the input panel here, wait for
2977 * show_input_panels signal. */
2979 weston_surface_configure(surface,
2980 surface->output->x + x,
2981 surface->output->y + y,
2982 surface->buffer->width,
2983 surface->buffer->height);
2987 destroy_input_panel_surface(struct wl_listener *listener,
2990 struct input_panel_surface *input_panel_surface =
2991 container_of(listener, struct input_panel_surface, listener);
2993 wl_list_remove(&listener->link);
2994 wl_list_remove(&input_panel_surface->link);
2996 free(input_panel_surface);
3000 input_panel_set_surface(struct wl_client *client,
3001 struct wl_resource *resource,
3002 struct wl_resource *surface_resource,
3003 struct wl_resource *output_resource)
3005 struct desktop_shell *shell = resource->data;
3006 struct weston_surface *surface = surface_resource->data;
3007 struct weston_output *output = output_resource->data;
3008 struct input_panel_surface *input_panel_surface;
3010 surface->configure = input_panel_configure;
3011 surface->private = shell;
3012 surface->output = output;
3014 input_panel_surface = malloc(sizeof *input_panel_surface);
3015 if (!input_panel_surface) {
3016 wl_resource_post_no_memory(resource);
3020 input_panel_surface->surface = surface;
3021 input_panel_surface->listener.notify = destroy_input_panel_surface;
3023 wl_signal_add(&surface_resource->destroy_signal,
3024 &input_panel_surface->listener);
3026 wl_list_insert(&shell->input_panel.surfaces,
3027 &input_panel_surface->link);
3030 static const struct input_panel_interface input_panel_implementation = {
3031 input_panel_set_surface
3035 unbind_input_panel(struct wl_resource *resource)
3037 struct desktop_shell *shell = resource->data;
3039 shell->input_panel.binding = NULL;
3044 bind_input_panel(struct wl_client *client,
3045 void *data, uint32_t version, uint32_t id)
3047 struct desktop_shell *shell = data;
3048 struct wl_resource *resource;
3050 resource = wl_client_add_object(client, &input_panel_interface,
3051 &input_panel_implementation,
3054 if (shell->input_panel.binding == NULL) {
3055 resource->destroy = unbind_input_panel;
3056 shell->input_panel.binding = resource;
3060 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
3061 "interface object already bound");
3062 wl_resource_destroy(resource);
3066 struct desktop_shell *shell;
3067 struct weston_surface *current;
3068 struct wl_listener listener;
3069 struct wl_keyboard_grab grab;
3073 switcher_next(struct switcher *switcher)
3075 struct weston_surface *surface;
3076 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
3077 struct shell_surface *shsurf;
3078 struct workspace *ws = get_current_workspace(switcher->shell);
3080 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
3081 switch (get_shell_surface_type(surface)) {
3082 case SHELL_SURFACE_TOPLEVEL:
3083 case SHELL_SURFACE_FULLSCREEN:
3084 case SHELL_SURFACE_MAXIMIZED:
3087 if (prev == switcher->current)
3090 surface->alpha = 0.25;
3091 surface->geometry.dirty = 1;
3092 weston_surface_damage(surface);
3098 if (is_black_surface(surface, NULL)) {
3099 surface->alpha = 0.25;
3100 surface->geometry.dirty = 1;
3101 weston_surface_damage(surface);
3111 wl_list_remove(&switcher->listener.link);
3112 wl_signal_add(&next->surface.resource.destroy_signal,
3113 &switcher->listener);
3115 switcher->current = next;
3118 shsurf = get_shell_surface(switcher->current);
3119 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
3120 shsurf->fullscreen.black_surface->alpha = 1.0;
3124 switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
3126 struct switcher *switcher =
3127 container_of(listener, struct switcher, listener);
3129 switcher_next(switcher);
3133 switcher_destroy(struct switcher *switcher)
3135 struct weston_surface *surface;
3136 struct wl_keyboard *keyboard = switcher->grab.keyboard;
3137 struct workspace *ws = get_current_workspace(switcher->shell);
3139 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
3140 surface->alpha = 1.0;
3141 weston_surface_damage(surface);
3144 if (switcher->current)
3145 activate(switcher->shell, switcher->current,
3146 (struct weston_seat *) keyboard->seat);
3147 wl_list_remove(&switcher->listener.link);
3148 wl_keyboard_end_grab(keyboard);
3153 switcher_key(struct wl_keyboard_grab *grab,
3154 uint32_t time, uint32_t key, uint32_t state_w)
3156 struct switcher *switcher = container_of(grab, struct switcher, grab);
3157 enum wl_keyboard_key_state state = state_w;
3159 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
3160 switcher_next(switcher);
3164 switcher_modifier(struct wl_keyboard_grab *grab, uint32_t serial,
3165 uint32_t mods_depressed, uint32_t mods_latched,
3166 uint32_t mods_locked, uint32_t group)
3168 struct switcher *switcher = container_of(grab, struct switcher, grab);
3169 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
3171 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0)
3172 switcher_destroy(switcher);
3175 static const struct wl_keyboard_grab_interface switcher_grab = {
3181 switcher_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
3184 struct desktop_shell *shell = data;
3185 struct switcher *switcher;
3187 switcher = malloc(sizeof *switcher);
3188 switcher->shell = shell;
3189 switcher->current = NULL;
3190 switcher->listener.notify = switcher_handle_surface_destroy;
3191 wl_list_init(&switcher->listener.link);
3193 lower_fullscreen_layer(switcher->shell);
3194 switcher->grab.interface = &switcher_grab;
3195 wl_keyboard_start_grab(seat->keyboard, &switcher->grab);
3196 wl_keyboard_set_focus(seat->keyboard, NULL);
3197 switcher_next(switcher);
3201 backlight_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
3204 struct weston_compositor *compositor = data;
3205 struct weston_output *output;
3206 long backlight_new = 0;
3208 /* TODO: we're limiting to simple use cases, where we assume just
3209 * control on the primary display. We'd have to extend later if we
3210 * ever get support for setting backlights on random desktop LCD
3212 output = get_default_output(compositor);
3216 if (!output->set_backlight)
3219 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
3220 backlight_new = output->backlight_current - 25;
3221 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
3222 backlight_new = output->backlight_current + 25;
3224 if (backlight_new < 5)
3226 if (backlight_new > 255)
3227 backlight_new = 255;
3229 output->backlight_current = backlight_new;
3230 output->set_backlight(output, output->backlight_current);
3234 debug_repaint_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
3237 struct desktop_shell *shell = data;
3238 struct weston_compositor *compositor = shell->compositor;
3239 struct weston_surface *surface;
3240 struct weston_plane plane;
3242 if (shell->debug_repaint_surface) {
3243 weston_surface_destroy(shell->debug_repaint_surface);
3244 shell->debug_repaint_surface = NULL;
3246 surface = weston_surface_create(compositor);
3247 weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2);
3248 weston_surface_configure(surface, 0, 0, 8192, 8192);
3249 wl_list_insert(&compositor->fade_layer.surface_list,
3250 &surface->layer_link);
3251 weston_surface_assign_output(surface);
3252 pixman_region32_init(&surface->input);
3254 /* Here's the dirty little trick that makes the
3255 * repaint debugging work: we move the surface to a
3256 * different plane and force an update_transform to
3257 * update dependent state and clear the
3258 * geometry.dirty bit. This way the call to
3259 * damage_below() in update_transform() does not
3260 * add damage to the primary plane. */
3262 weston_plane_init(&plane, 0, 0);
3263 surface->plane = &plane;
3264 weston_surface_update_transform(surface);
3265 shell->debug_repaint_surface = surface;
3266 surface->plane = &compositor->primary_plane;
3267 weston_plane_release(&plane);
3273 fan_debug_repaint_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
3276 struct desktop_shell *shell = data;
3277 struct weston_compositor *compositor = shell->compositor;
3278 compositor->fan_debug = !compositor->fan_debug;
3279 weston_compositor_damage_all(compositor);
3283 force_kill_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
3286 struct wl_surface *focus_surface;
3287 struct wl_client *client;
3292 focus_surface = seat->keyboard->focus;
3296 client = focus_surface->resource.client;
3297 wl_client_get_credentials(client, &pid, &uid, &gid);
3303 workspace_up_binding(struct wl_seat *seat, uint32_t time,
3304 uint32_t key, void *data)
3306 struct desktop_shell *shell = data;
3307 unsigned int new_index = shell->workspaces.current;
3314 change_workspace(shell, new_index);
3318 workspace_down_binding(struct wl_seat *seat, uint32_t time,
3319 uint32_t key, void *data)
3321 struct desktop_shell *shell = data;
3322 unsigned int new_index = shell->workspaces.current;
3326 if (new_index < shell->workspaces.num - 1)
3329 change_workspace(shell, new_index);
3333 workspace_f_binding(struct wl_seat *seat, uint32_t time,
3334 uint32_t key, void *data)
3336 struct desktop_shell *shell = data;
3337 unsigned int new_index;
3341 new_index = key - KEY_F1;
3342 if (new_index >= shell->workspaces.num)
3343 new_index = shell->workspaces.num - 1;
3345 change_workspace(shell, new_index);
3350 shell_destroy(struct wl_listener *listener, void *data)
3352 struct desktop_shell *shell =
3353 container_of(listener, struct desktop_shell, destroy_listener);
3354 struct workspace **ws;
3356 if (shell->child.client)
3357 wl_client_destroy(shell->child.client);
3359 wl_list_remove(&shell->lock_listener.link);
3360 wl_list_remove(&shell->unlock_listener.link);
3361 wl_list_remove(&shell->show_input_panel_listener.link);
3362 wl_list_remove(&shell->hide_input_panel_listener.link);
3364 wl_array_for_each(ws, &shell->workspaces.array)
3365 workspace_destroy(*ws);
3366 wl_array_release(&shell->workspaces.array);
3368 free(shell->screensaver.path);
3373 shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
3376 int i, num_workspace_bindings;
3378 /* fixed bindings */
3379 weston_compositor_add_key_binding(ec, KEY_BACKSPACE,
3380 MODIFIER_CTRL | MODIFIER_ALT,
3381 terminate_binding, ec);
3382 weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
3383 click_to_activate_binding,
3385 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
3386 MODIFIER_SUPER | MODIFIER_ALT,
3387 surface_opacity_binding, NULL);
3388 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
3389 MODIFIER_SUPER, zoom_axis_binding,
3392 /* configurable bindings */
3393 mod = shell->binding_modifier;
3394 weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod,
3395 zoom_key_binding, NULL);
3396 weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod,
3397 zoom_key_binding, NULL);
3398 weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding,
3400 weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod,
3401 resize_binding, shell);
3402 weston_compositor_add_button_binding(ec, BTN_RIGHT, mod,
3403 rotate_binding, NULL);
3404 weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding,
3406 weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding,
3408 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0,
3409 backlight_binding, ec);
3410 weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding,
3412 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0,
3413 backlight_binding, ec);
3414 weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT,
3415 debug_repaint_binding, shell);
3416 weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_ALT,
3417 fan_debug_repaint_binding, shell);
3418 weston_compositor_add_key_binding(ec, KEY_K, mod,
3419 force_kill_binding, shell);
3420 weston_compositor_add_key_binding(ec, KEY_UP, mod,
3421 workspace_up_binding, shell);
3422 weston_compositor_add_key_binding(ec, KEY_DOWN, mod,
3423 workspace_down_binding, shell);
3425 /* Add bindings for mod+F[1-6] for workspace 1 to 6. */
3426 if (shell->workspaces.num > 1) {
3427 num_workspace_bindings = shell->workspaces.num;
3428 if (num_workspace_bindings > 6)
3429 num_workspace_bindings = 6;
3430 for (i = 0; i < num_workspace_bindings; i++)
3431 weston_compositor_add_key_binding(ec, KEY_F1 + i, mod,
3432 workspace_f_binding,
3438 shell_init(struct weston_compositor *ec);
3441 shell_init(struct weston_compositor *ec)
3443 struct weston_seat *seat;
3444 struct desktop_shell *shell;
3445 struct workspace **pws;
3448 shell = malloc(sizeof *shell);
3452 memset(shell, 0, sizeof *shell);
3453 shell->compositor = ec;
3455 shell->destroy_listener.notify = shell_destroy;
3456 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
3457 shell->lock_listener.notify = lock;
3458 wl_signal_add(&ec->lock_signal, &shell->lock_listener);
3459 shell->unlock_listener.notify = unlock;
3460 wl_signal_add(&ec->unlock_signal, &shell->unlock_listener);
3461 shell->show_input_panel_listener.notify = show_input_panels;
3462 wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener);
3463 shell->hide_input_panel_listener.notify = hide_input_panels;
3464 wl_signal_add(&ec->hide_input_panel_signal, &shell->hide_input_panel_listener);
3465 ec->ping_handler = ping_handler;
3466 ec->shell_interface.shell = shell;
3467 ec->shell_interface.create_shell_surface = create_shell_surface;
3468 ec->shell_interface.set_toplevel = set_toplevel;
3469 ec->shell_interface.set_transient = set_transient;
3470 ec->shell_interface.move = surface_move;
3471 ec->shell_interface.resize = surface_resize;
3473 wl_list_init(&shell->screensaver.surfaces);
3474 wl_list_init(&shell->input_panel.surfaces);
3476 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
3477 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
3478 weston_layer_init(&shell->background_layer, &shell->panel_layer.link);
3479 weston_layer_init(&shell->lock_layer, NULL);
3480 weston_layer_init(&shell->input_panel_layer, NULL);
3482 wl_array_init(&shell->workspaces.array);
3484 shell_configuration(shell);
3486 for (i = 0; i < shell->workspaces.num; i++) {
3487 pws = wl_array_add(&shell->workspaces.array, sizeof *pws);
3491 *pws = workspace_create();
3495 activate_workspace(shell, 0);
3497 wl_list_init(&shell->workspaces.animation.link);
3498 shell->workspaces.animation.frame = animate_workspace_change_frame;
3500 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
3501 shell, bind_shell) == NULL)
3504 if (wl_display_add_global(ec->wl_display,
3505 &desktop_shell_interface,
3506 shell, bind_desktop_shell) == NULL)
3509 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
3510 shell, bind_screensaver) == NULL)
3513 if (wl_display_add_global(ec->wl_display, &input_panel_interface,
3514 shell, bind_input_panel) == NULL)
3517 shell->child.deathstamp = weston_compositor_get_time();
3518 if (launch_desktop_shell_process(shell) != 0)
3521 wl_list_for_each(seat, &ec->seat_list, link)
3522 create_pointer_focus_listener(seat);
3524 shell_add_bindings(ec, shell);