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 "input-method-server-protocol.h"
39 #include "workspaces-server-protocol.h"
40 #include "../shared/config-parser.h"
42 #define DEFAULT_NUM_WORKSPACES 1
43 #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200
58 struct weston_seat *seat;
60 struct weston_surface *keyboard_focus;
62 struct wl_listener seat_destroy_listener;
63 struct wl_listener surface_destroy_listener;
67 struct weston_layer layer;
69 struct wl_list focus_list;
70 struct wl_listener seat_destroyed_listener;
73 struct input_panel_surface {
74 struct wl_resource resource;
76 struct desktop_shell *shell;
79 struct weston_surface *surface;
80 struct wl_listener surface_destroy_listener;
82 struct weston_output *output;
86 struct desktop_shell {
87 struct weston_compositor *compositor;
89 struct wl_listener idle_listener;
90 struct wl_listener wake_listener;
91 struct wl_listener destroy_listener;
92 struct wl_listener show_input_panel_listener;
93 struct wl_listener hide_input_panel_listener;
94 struct wl_listener update_input_panel_listener;
96 struct weston_layer fullscreen_layer;
97 struct weston_layer panel_layer;
98 struct weston_layer background_layer;
99 struct weston_layer lock_layer;
100 struct weston_layer input_panel_layer;
102 struct wl_listener pointer_focus_listener;
103 struct weston_surface *grab_surface;
106 struct weston_process process;
107 struct wl_client *client;
108 struct wl_resource *desktop_shell;
115 bool showing_input_panels;
116 bool prepare_event_sent;
119 struct weston_surface *surface;
120 pixman_box32_t cursor_rectangle;
123 struct weston_surface *lock_surface;
124 struct wl_listener lock_surface_listener;
127 struct wl_array array;
128 unsigned int current;
131 struct wl_list client_list;
133 struct weston_animation animation;
134 struct wl_list anim_sticky_list;
136 uint32_t anim_timestamp;
138 struct workspace *anim_from;
139 struct workspace *anim_to;
145 struct wl_resource *binding;
146 struct weston_process process;
147 struct wl_event_source *timer;
151 struct wl_resource *binding;
152 struct wl_list surfaces;
156 struct weston_surface *surface;
157 struct weston_surface_animation *animation;
161 uint32_t binding_modifier;
162 enum animation_type win_animation_type;
165 enum shell_surface_type {
167 SHELL_SURFACE_TOPLEVEL,
168 SHELL_SURFACE_TRANSIENT,
169 SHELL_SURFACE_FULLSCREEN,
170 SHELL_SURFACE_MAXIMIZED,
175 struct wl_event_source *source;
179 struct shell_surface {
180 struct wl_resource resource;
182 struct weston_surface *surface;
183 struct wl_listener surface_destroy_listener;
184 struct weston_surface *parent;
185 struct desktop_shell *shell;
187 enum shell_surface_type type, next_type;
189 int32_t saved_x, saved_y;
190 bool saved_position_valid;
191 bool saved_rotation_valid;
195 struct weston_transform transform;
196 struct weston_matrix rotation;
200 struct wl_list grab_link;
202 struct shell_seat *shseat;
212 enum wl_shell_surface_fullscreen_method type;
213 struct weston_transform transform; /* matrix from x, y */
215 struct weston_surface *black_surface;
218 struct ping_timer *ping_timer;
220 struct weston_transform workspace_transform;
222 struct weston_output *fullscreen_output;
223 struct weston_output *output;
226 const struct weston_shell_client *client;
230 struct weston_pointer_grab grab;
231 struct shell_surface *shsurf;
232 struct wl_listener shsurf_destroy_listener;
233 struct weston_pointer *pointer;
236 struct weston_move_grab {
237 struct shell_grab base;
242 struct shell_grab base;
243 struct weston_matrix rotation;
251 struct weston_seat *seat;
252 struct wl_listener seat_destroy_listener;
255 struct weston_pointer_grab grab;
256 struct wl_list surfaces_list;
257 struct wl_client *client;
263 activate(struct desktop_shell *shell, struct weston_surface *es,
264 struct weston_seat *seat);
266 static struct workspace *
267 get_current_workspace(struct desktop_shell *shell);
269 static struct shell_surface *
270 get_shell_surface(struct weston_surface *surface);
272 static struct desktop_shell *
273 shell_surface_get_shell(struct shell_surface *shsurf);
276 surface_rotate(struct shell_surface *surface, struct weston_seat *seat);
279 shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
281 struct desktop_shell *shell;
282 struct weston_surface *top_fs_es;
284 shell = shell_surface_get_shell(shsurf);
286 if (wl_list_empty(&shell->fullscreen_layer.surface_list))
289 top_fs_es = container_of(shell->fullscreen_layer.surface_list.next,
290 struct weston_surface,
292 return (shsurf == get_shell_surface(top_fs_es));
296 destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
298 struct shell_grab *grab;
300 grab = container_of(listener, struct shell_grab,
301 shsurf_destroy_listener);
307 popup_grab_end(struct weston_pointer *pointer);
310 shell_grab_start(struct shell_grab *grab,
311 const struct weston_pointer_grab_interface *interface,
312 struct shell_surface *shsurf,
313 struct weston_pointer *pointer,
314 enum desktop_shell_cursor cursor)
316 struct desktop_shell *shell = shsurf->shell;
318 popup_grab_end(pointer);
320 grab->grab.interface = interface;
321 grab->shsurf = shsurf;
322 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
323 wl_signal_add(&shsurf->resource.destroy_signal,
324 &grab->shsurf_destroy_listener);
326 grab->pointer = pointer;
328 weston_pointer_start_grab(pointer, &grab->grab);
329 desktop_shell_send_grab_cursor(shell->child.desktop_shell, cursor);
330 weston_pointer_set_focus(pointer, shell->grab_surface,
331 wl_fixed_from_int(0), wl_fixed_from_int(0));
335 shell_grab_end(struct shell_grab *grab)
338 wl_list_remove(&grab->shsurf_destroy_listener.link);
340 weston_pointer_end_grab(grab->pointer);
344 center_on_output(struct weston_surface *surface,
345 struct weston_output *output);
347 static enum weston_keyboard_modifier
348 get_modifier(char *modifier)
351 return MODIFIER_SUPER;
353 if (!strcmp("ctrl", modifier))
354 return MODIFIER_CTRL;
355 else if (!strcmp("alt", modifier))
357 else if (!strcmp("super", modifier))
358 return MODIFIER_SUPER;
360 return MODIFIER_SUPER;
363 static enum animation_type
364 get_animation_type(char *animation)
367 return ANIMATION_NONE;
369 if (!strcmp("zoom", animation))
370 return ANIMATION_ZOOM;
371 else if (!strcmp("fade", animation))
372 return ANIMATION_FADE;
374 return ANIMATION_NONE;
378 shell_configuration(struct desktop_shell *shell, const char *config_file)
382 unsigned int num_workspaces = DEFAULT_NUM_WORKSPACES;
383 char *modifier = NULL;
384 char *win_animation = NULL;
386 struct config_key shell_keys[] = {
387 { "binding-modifier", CONFIG_KEY_STRING, &modifier },
388 { "animation", CONFIG_KEY_STRING, &win_animation},
390 CONFIG_KEY_UNSIGNED_INTEGER, &num_workspaces },
393 struct config_key saver_keys[] = {
394 { "path", CONFIG_KEY_STRING, &path },
395 { "duration", CONFIG_KEY_INTEGER, &duration },
398 struct config_section cs[] = {
399 { "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL },
400 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
403 parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell);
405 shell->screensaver.path = path;
406 shell->screensaver.duration = duration * 1000;
407 shell->binding_modifier = get_modifier(modifier);
408 shell->win_animation_type = get_animation_type(win_animation);
409 shell->workspaces.num = num_workspaces > 0 ? num_workspaces : 1;
413 focus_state_destroy(struct focus_state *state)
415 wl_list_remove(&state->seat_destroy_listener.link);
416 wl_list_remove(&state->surface_destroy_listener.link);
421 focus_state_seat_destroy(struct wl_listener *listener, void *data)
423 struct focus_state *state = container_of(listener,
425 seat_destroy_listener);
427 wl_list_remove(&state->link);
428 focus_state_destroy(state);
432 focus_state_surface_destroy(struct wl_listener *listener, void *data)
434 struct focus_state *state = container_of(listener,
436 surface_destroy_listener);
437 struct desktop_shell *shell;
438 struct weston_surface *main_surface;
439 struct weston_surface *surface, *next;
441 main_surface = weston_surface_get_main_surface(state->keyboard_focus);
444 wl_list_for_each(surface, &state->ws->layer.surface_list, layer_link) {
445 if (surface == main_surface)
452 /* if the focus was a sub-surface, activate its main surface */
453 if (main_surface != state->keyboard_focus)
457 shell = state->seat->compositor->shell_interface.shell;
458 activate(shell, next, state->seat);
460 wl_list_remove(&state->link);
461 focus_state_destroy(state);
465 static struct focus_state *
466 focus_state_create(struct weston_seat *seat, struct workspace *ws)
468 struct focus_state *state;
470 state = malloc(sizeof *state);
476 wl_list_insert(&ws->focus_list, &state->link);
478 state->seat_destroy_listener.notify = focus_state_seat_destroy;
479 state->surface_destroy_listener.notify = focus_state_surface_destroy;
480 wl_signal_add(&seat->destroy_signal,
481 &state->seat_destroy_listener);
482 wl_list_init(&state->surface_destroy_listener.link);
487 static struct focus_state *
488 ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat)
490 struct workspace *ws = get_current_workspace(shell);
491 struct focus_state *state;
493 wl_list_for_each(state, &ws->focus_list, link)
494 if (state->seat == seat)
497 if (&state->link == &ws->focus_list)
498 state = focus_state_create(seat, ws);
504 restore_focus_state(struct desktop_shell *shell, struct workspace *ws)
506 struct focus_state *state, *next;
507 struct weston_surface *surface;
509 wl_list_for_each_safe(state, next, &ws->focus_list, link) {
510 surface = state->keyboard_focus;
512 weston_keyboard_set_focus(state->seat->keyboard, surface);
517 replace_focus_state(struct desktop_shell *shell, struct workspace *ws,
518 struct weston_seat *seat)
520 struct focus_state *state;
521 struct weston_surface *surface;
523 wl_list_for_each(state, &ws->focus_list, link) {
524 if (state->seat == seat) {
525 surface = seat->keyboard->focus;
526 state->keyboard_focus =
527 (struct weston_surface *) surface;
534 drop_focus_state(struct desktop_shell *shell, struct workspace *ws,
535 struct weston_surface *surface)
537 struct focus_state *state;
539 wl_list_for_each(state, &ws->focus_list, link)
540 if (state->keyboard_focus == surface)
541 state->keyboard_focus = NULL;
545 workspace_destroy(struct workspace *ws)
547 struct focus_state *state, *next;
549 wl_list_for_each_safe(state, next, &ws->focus_list, link)
550 focus_state_destroy(state);
556 seat_destroyed(struct wl_listener *listener, void *data)
558 struct weston_seat *seat = data;
559 struct focus_state *state, *next;
560 struct workspace *ws = container_of(listener,
562 seat_destroyed_listener);
564 wl_list_for_each_safe(state, next, &ws->focus_list, link)
565 if (state->seat == seat)
566 wl_list_remove(&state->link);
569 static struct workspace *
570 workspace_create(void)
572 struct workspace *ws = malloc(sizeof *ws);
576 weston_layer_init(&ws->layer, NULL);
578 wl_list_init(&ws->focus_list);
579 wl_list_init(&ws->seat_destroyed_listener.link);
580 ws->seat_destroyed_listener.notify = seat_destroyed;
586 workspace_is_empty(struct workspace *ws)
588 return wl_list_empty(&ws->layer.surface_list);
591 static struct workspace *
592 get_workspace(struct desktop_shell *shell, unsigned int index)
594 struct workspace **pws = shell->workspaces.array.data;
595 assert(index < shell->workspaces.num);
600 static struct workspace *
601 get_current_workspace(struct desktop_shell *shell)
603 return get_workspace(shell, shell->workspaces.current);
607 activate_workspace(struct desktop_shell *shell, unsigned int index)
609 struct workspace *ws;
611 ws = get_workspace(shell, index);
612 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
614 shell->workspaces.current = index;
618 get_output_height(struct weston_output *output)
620 return abs(output->region.extents.y1 - output->region.extents.y2);
624 surface_translate(struct weston_surface *surface, double d)
626 struct shell_surface *shsurf = get_shell_surface(surface);
627 struct weston_transform *transform;
629 transform = &shsurf->workspace_transform;
630 if (wl_list_empty(&transform->link))
631 wl_list_insert(surface->geometry.transformation_list.prev,
632 &shsurf->workspace_transform.link);
634 weston_matrix_init(&shsurf->workspace_transform.matrix);
635 weston_matrix_translate(&shsurf->workspace_transform.matrix,
637 weston_surface_geometry_dirty(surface);
641 workspace_translate_out(struct workspace *ws, double fraction)
643 struct weston_surface *surface;
647 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
648 height = get_output_height(surface->output);
649 d = height * fraction;
651 surface_translate(surface, d);
656 workspace_translate_in(struct workspace *ws, double fraction)
658 struct weston_surface *surface;
662 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
663 height = get_output_height(surface->output);
666 d = -(height - height * fraction);
668 d = height + height * fraction;
670 surface_translate(surface, d);
675 broadcast_current_workspace_state(struct desktop_shell *shell)
677 struct wl_resource *resource;
679 wl_list_for_each(resource, &shell->workspaces.client_list, link)
680 workspace_manager_send_state(resource,
681 shell->workspaces.current,
682 shell->workspaces.num);
686 reverse_workspace_change_animation(struct desktop_shell *shell,
688 struct workspace *from,
689 struct workspace *to)
691 shell->workspaces.current = index;
693 shell->workspaces.anim_to = to;
694 shell->workspaces.anim_from = from;
695 shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir;
696 shell->workspaces.anim_timestamp = 0;
698 weston_compositor_schedule_repaint(shell->compositor);
702 workspace_deactivate_transforms(struct workspace *ws)
704 struct weston_surface *surface;
705 struct shell_surface *shsurf;
707 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
708 shsurf = get_shell_surface(surface);
709 if (!wl_list_empty(&shsurf->workspace_transform.link)) {
710 wl_list_remove(&shsurf->workspace_transform.link);
711 wl_list_init(&shsurf->workspace_transform.link);
713 weston_surface_geometry_dirty(surface);
718 finish_workspace_change_animation(struct desktop_shell *shell,
719 struct workspace *from,
720 struct workspace *to)
722 weston_compositor_schedule_repaint(shell->compositor);
724 wl_list_remove(&shell->workspaces.animation.link);
725 workspace_deactivate_transforms(from);
726 workspace_deactivate_transforms(to);
727 shell->workspaces.anim_to = NULL;
729 wl_list_remove(&shell->workspaces.anim_from->layer.link);
733 animate_workspace_change_frame(struct weston_animation *animation,
734 struct weston_output *output, uint32_t msecs)
736 struct desktop_shell *shell =
737 container_of(animation, struct desktop_shell,
738 workspaces.animation);
739 struct workspace *from = shell->workspaces.anim_from;
740 struct workspace *to = shell->workspaces.anim_to;
744 if (workspace_is_empty(from) && workspace_is_empty(to)) {
745 finish_workspace_change_animation(shell, from, to);
749 if (shell->workspaces.anim_timestamp == 0) {
750 if (shell->workspaces.anim_current == 0.0)
751 shell->workspaces.anim_timestamp = msecs;
753 shell->workspaces.anim_timestamp =
755 /* Invers of movement function 'y' below. */
756 (asin(1.0 - shell->workspaces.anim_current) *
757 DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH *
761 t = msecs - shell->workspaces.anim_timestamp;
767 x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2;
770 if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) {
771 weston_compositor_schedule_repaint(shell->compositor);
773 workspace_translate_out(from, shell->workspaces.anim_dir * y);
774 workspace_translate_in(to, shell->workspaces.anim_dir * y);
775 shell->workspaces.anim_current = y;
777 weston_compositor_schedule_repaint(shell->compositor);
780 finish_workspace_change_animation(shell, from, to);
784 animate_workspace_change(struct desktop_shell *shell,
786 struct workspace *from,
787 struct workspace *to)
789 struct weston_output *output;
793 if (index > shell->workspaces.current)
798 shell->workspaces.current = index;
800 shell->workspaces.anim_dir = dir;
801 shell->workspaces.anim_from = from;
802 shell->workspaces.anim_to = to;
803 shell->workspaces.anim_current = 0.0;
804 shell->workspaces.anim_timestamp = 0;
806 output = container_of(shell->compositor->output_list.next,
807 struct weston_output, link);
808 wl_list_insert(&output->animation_list,
809 &shell->workspaces.animation.link);
811 wl_list_insert(from->layer.link.prev, &to->layer.link);
813 workspace_translate_in(to, 0);
815 restore_focus_state(shell, to);
817 weston_compositor_schedule_repaint(shell->compositor);
821 update_workspace(struct desktop_shell *shell, unsigned int index,
822 struct workspace *from, struct workspace *to)
824 shell->workspaces.current = index;
825 wl_list_insert(&from->layer.link, &to->layer.link);
826 wl_list_remove(&from->layer.link);
830 change_workspace(struct desktop_shell *shell, unsigned int index)
832 struct workspace *from;
833 struct workspace *to;
835 if (index == shell->workspaces.current)
838 /* Don't change workspace when there is any fullscreen surfaces. */
839 if (!wl_list_empty(&shell->fullscreen_layer.surface_list))
842 from = get_current_workspace(shell);
843 to = get_workspace(shell, index);
845 if (shell->workspaces.anim_from == to &&
846 shell->workspaces.anim_to == from) {
847 restore_focus_state(shell, to);
848 reverse_workspace_change_animation(shell, index, from, to);
849 broadcast_current_workspace_state(shell);
853 if (shell->workspaces.anim_to != NULL)
854 finish_workspace_change_animation(shell,
855 shell->workspaces.anim_from,
856 shell->workspaces.anim_to);
858 restore_focus_state(shell, to);
860 if (workspace_is_empty(to) && workspace_is_empty(from))
861 update_workspace(shell, index, from, to);
863 animate_workspace_change(shell, index, from, to);
865 broadcast_current_workspace_state(shell);
869 workspace_has_only(struct workspace *ws, struct weston_surface *surface)
871 struct wl_list *list = &ws->layer.surface_list;
874 if (wl_list_empty(list))
882 return container_of(e, struct weston_surface, layer_link) == surface;
886 move_surface_to_workspace(struct desktop_shell *shell,
887 struct weston_surface *surface,
890 struct workspace *from;
891 struct workspace *to;
892 struct weston_seat *seat;
893 struct weston_surface *focus;
895 assert(weston_surface_get_main_surface(surface) == surface);
897 if (workspace == shell->workspaces.current)
900 if (workspace >= shell->workspaces.num)
901 workspace = shell->workspaces.num - 1;
903 from = get_current_workspace(shell);
904 to = get_workspace(shell, workspace);
906 wl_list_remove(&surface->layer_link);
907 wl_list_insert(&to->layer.surface_list, &surface->layer_link);
909 drop_focus_state(shell, from, surface);
910 wl_list_for_each(seat, &shell->compositor->seat_list, link) {
914 focus = weston_surface_get_main_surface(seat->keyboard->focus);
915 if (focus == surface)
916 weston_keyboard_set_focus(seat->keyboard, NULL);
919 weston_surface_damage_below(surface);
923 take_surface_to_workspace_by_seat(struct desktop_shell *shell,
924 struct weston_seat *seat,
927 struct weston_surface *surface;
928 struct shell_surface *shsurf;
929 struct workspace *from;
930 struct workspace *to;
931 struct focus_state *state;
933 surface = weston_surface_get_main_surface(seat->keyboard->focus);
934 if (surface == NULL ||
935 index == shell->workspaces.current)
938 from = get_current_workspace(shell);
939 to = get_workspace(shell, index);
941 wl_list_remove(&surface->layer_link);
942 wl_list_insert(&to->layer.surface_list, &surface->layer_link);
944 replace_focus_state(shell, to, seat);
945 drop_focus_state(shell, from, surface);
947 if (shell->workspaces.anim_from == to &&
948 shell->workspaces.anim_to == from) {
949 wl_list_remove(&to->layer.link);
950 wl_list_insert(from->layer.link.prev, &to->layer.link);
952 reverse_workspace_change_animation(shell, index, from, to);
953 broadcast_current_workspace_state(shell);
958 if (shell->workspaces.anim_to != NULL)
959 finish_workspace_change_animation(shell,
960 shell->workspaces.anim_from,
961 shell->workspaces.anim_to);
963 if (workspace_is_empty(from) &&
964 workspace_has_only(to, surface))
965 update_workspace(shell, index, from, to);
967 shsurf = get_shell_surface(surface);
968 if (wl_list_empty(&shsurf->workspace_transform.link))
969 wl_list_insert(&shell->workspaces.anim_sticky_list,
970 &shsurf->workspace_transform.link);
972 animate_workspace_change(shell, index, from, to);
975 broadcast_current_workspace_state(shell);
977 state = ensure_focus_state(shell, seat);
979 state->keyboard_focus = surface;
983 workspace_manager_move_surface(struct wl_client *client,
984 struct wl_resource *resource,
985 struct wl_resource *surface_resource,
988 struct desktop_shell *shell = resource->data;
989 struct weston_surface *surface =
990 (struct weston_surface *) surface_resource;
991 struct weston_surface *main_surface;
993 main_surface = weston_surface_get_main_surface(surface);
994 move_surface_to_workspace(shell, main_surface, workspace);
997 static const struct workspace_manager_interface workspace_manager_implementation = {
998 workspace_manager_move_surface,
1002 unbind_resource(struct wl_resource *resource)
1004 wl_list_remove(&resource->link);
1009 bind_workspace_manager(struct wl_client *client,
1010 void *data, uint32_t version, uint32_t id)
1012 struct desktop_shell *shell = data;
1013 struct wl_resource *resource;
1015 resource = wl_client_add_object(client, &workspace_manager_interface,
1016 &workspace_manager_implementation,
1019 if (resource == NULL) {
1020 weston_log("couldn't add workspace manager object");
1024 resource->destroy = unbind_resource;
1025 wl_list_insert(&shell->workspaces.client_list, &resource->link);
1027 workspace_manager_send_state(resource,
1028 shell->workspaces.current,
1029 shell->workspaces.num);
1033 noop_grab_focus(struct weston_pointer_grab *grab)
1038 move_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
1040 struct weston_move_grab *move = (struct weston_move_grab *) grab;
1041 struct weston_pointer *pointer = grab->pointer;
1042 struct shell_surface *shsurf = move->base.shsurf;
1043 struct weston_surface *es;
1044 int dx = wl_fixed_to_int(pointer->x + move->dx);
1045 int dy = wl_fixed_to_int(pointer->y + move->dy);
1050 es = shsurf->surface;
1052 weston_surface_configure(es, dx, dy,
1053 es->geometry.width, es->geometry.height);
1055 weston_compositor_schedule_repaint(es->compositor);
1059 move_grab_button(struct weston_pointer_grab *grab,
1060 uint32_t time, uint32_t button, uint32_t state_w)
1062 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
1064 struct weston_pointer *pointer = grab->pointer;
1065 enum wl_pointer_button_state state = state_w;
1067 if (pointer->button_count == 0 &&
1068 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1069 shell_grab_end(shell_grab);
1074 static const struct weston_pointer_grab_interface move_grab_interface = {
1081 surface_move(struct shell_surface *shsurf, struct weston_seat *seat)
1083 struct weston_move_grab *move;
1088 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1091 move = malloc(sizeof *move);
1095 move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
1096 seat->pointer->grab_x;
1097 move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
1098 seat->pointer->grab_y;
1100 shell_grab_start(&move->base, &move_grab_interface, shsurf,
1101 seat->pointer, DESKTOP_SHELL_CURSOR_MOVE);
1107 shell_surface_move(struct wl_client *client, struct wl_resource *resource,
1108 struct wl_resource *seat_resource, uint32_t serial)
1110 struct weston_seat *seat = seat_resource->data;
1111 struct shell_surface *shsurf = resource->data;
1112 struct weston_surface *surface;
1114 surface = weston_surface_get_main_surface(seat->pointer->focus);
1115 if (seat->pointer->button_count == 0 ||
1116 seat->pointer->grab_serial != serial ||
1117 surface != shsurf->surface)
1120 if (surface_move(shsurf, seat) < 0)
1121 wl_resource_post_no_memory(resource);
1124 struct weston_resize_grab {
1125 struct shell_grab base;
1127 int32_t width, height;
1131 resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
1133 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1134 struct weston_pointer *pointer = grab->pointer;
1135 struct shell_surface *shsurf = resize->base.shsurf;
1136 int32_t width, height;
1137 wl_fixed_t from_x, from_y;
1138 wl_fixed_t to_x, to_y;
1143 weston_surface_from_global_fixed(shsurf->surface,
1144 pointer->grab_x, pointer->grab_y,
1146 weston_surface_from_global_fixed(shsurf->surface,
1147 pointer->x, pointer->y, &to_x, &to_y);
1149 width = resize->width;
1150 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
1151 width += wl_fixed_to_int(from_x - to_x);
1152 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
1153 width += wl_fixed_to_int(to_x - from_x);
1156 height = resize->height;
1157 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
1158 height += wl_fixed_to_int(from_y - to_y);
1159 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
1160 height += wl_fixed_to_int(to_y - from_y);
1163 shsurf->client->send_configure(shsurf->surface,
1164 resize->edges, width, height);
1168 send_configure(struct weston_surface *surface,
1169 uint32_t edges, int32_t width, int32_t height)
1171 struct shell_surface *shsurf = get_shell_surface(surface);
1173 wl_shell_surface_send_configure(&shsurf->resource,
1174 edges, width, height);
1177 static const struct weston_shell_client shell_client = {
1182 resize_grab_button(struct weston_pointer_grab *grab,
1183 uint32_t time, uint32_t button, uint32_t state_w)
1185 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1186 struct weston_pointer *pointer = grab->pointer;
1187 enum wl_pointer_button_state state = state_w;
1189 if (pointer->button_count == 0 &&
1190 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1191 shell_grab_end(&resize->base);
1196 static const struct weston_pointer_grab_interface resize_grab_interface = {
1203 * Returns the bounding box of a surface and all its sub-surfaces,
1204 * in the surface coordinates system. */
1206 surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x,
1207 int32_t *y, int32_t *w, int32_t *h) {
1208 pixman_region32_t region;
1209 pixman_box32_t *box;
1210 struct weston_subsurface *subsurface;
1212 pixman_region32_init_rect(®ion, 0, 0,
1213 surface->geometry.width,
1214 surface->geometry.height);
1216 wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
1217 pixman_region32_union_rect(®ion, ®ion,
1218 subsurface->position.x,
1219 subsurface->position.y,
1220 subsurface->surface->geometry.width,
1221 subsurface->surface->geometry.height);
1224 box = pixman_region32_extents(®ion);
1230 *w = box->x2 - box->x1;
1232 *h = box->y2 - box->y1;
1234 pixman_region32_fini(®ion);
1238 surface_resize(struct shell_surface *shsurf,
1239 struct weston_seat *seat, uint32_t edges)
1241 struct weston_resize_grab *resize;
1243 if (shsurf->type == SHELL_SURFACE_FULLSCREEN ||
1244 shsurf->type == SHELL_SURFACE_MAXIMIZED)
1247 if (edges == 0 || edges > 15 ||
1248 (edges & 3) == 3 || (edges & 12) == 12)
1251 resize = malloc(sizeof *resize);
1255 resize->edges = edges;
1256 surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL,
1257 &resize->width, &resize->height);
1259 shell_grab_start(&resize->base, &resize_grab_interface, shsurf,
1260 seat->pointer, edges);
1266 shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
1267 struct wl_resource *seat_resource, uint32_t serial,
1270 struct weston_seat *seat = seat_resource->data;
1271 struct shell_surface *shsurf = resource->data;
1272 struct weston_surface *surface;
1274 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1277 surface = weston_surface_get_main_surface(seat->pointer->focus);
1278 if (seat->pointer->button_count == 0 ||
1279 seat->pointer->grab_serial != serial ||
1280 surface != shsurf->surface)
1283 if (surface_resize(shsurf, seat, edges) < 0)
1284 wl_resource_post_no_memory(resource);
1288 busy_cursor_grab_focus(struct weston_pointer_grab *base)
1290 struct shell_grab *grab = (struct shell_grab *) base;
1291 struct weston_pointer *pointer = base->pointer;
1292 struct weston_surface *surface;
1295 surface = weston_compositor_pick_surface(pointer->seat->compositor,
1296 pointer->x, pointer->y,
1299 if (grab->shsurf->surface != surface) {
1300 shell_grab_end(grab);
1306 busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
1311 busy_cursor_grab_button(struct weston_pointer_grab *base,
1312 uint32_t time, uint32_t button, uint32_t state)
1314 struct shell_grab *grab = (struct shell_grab *) base;
1315 struct shell_surface *shsurf = grab->shsurf;
1316 struct weston_seat *seat = grab->grab.pointer->seat;
1318 if (shsurf && button == BTN_LEFT && state) {
1319 activate(shsurf->shell, shsurf->surface, seat);
1320 surface_move(shsurf, seat);
1321 } else if (shsurf && button == BTN_RIGHT && state) {
1322 activate(shsurf->shell, shsurf->surface, seat);
1323 surface_rotate(shsurf, seat);
1327 static const struct weston_pointer_grab_interface busy_cursor_grab_interface = {
1328 busy_cursor_grab_focus,
1329 busy_cursor_grab_motion,
1330 busy_cursor_grab_button,
1334 set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
1336 struct shell_grab *grab;
1338 grab = malloc(sizeof *grab);
1342 shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer,
1343 DESKTOP_SHELL_CURSOR_BUSY);
1347 end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
1349 struct shell_grab *grab = (struct shell_grab *) pointer->grab;
1351 if (grab->grab.interface == &busy_cursor_grab_interface &&
1352 grab->shsurf == shsurf) {
1353 shell_grab_end(grab);
1359 ping_timer_destroy(struct shell_surface *shsurf)
1361 if (!shsurf || !shsurf->ping_timer)
1364 if (shsurf->ping_timer->source)
1365 wl_event_source_remove(shsurf->ping_timer->source);
1367 free(shsurf->ping_timer);
1368 shsurf->ping_timer = NULL;
1372 ping_timeout_handler(void *data)
1374 struct shell_surface *shsurf = data;
1375 struct weston_seat *seat;
1377 /* Client is not responding */
1378 shsurf->unresponsive = 1;
1380 wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link)
1381 if (seat->pointer->focus == shsurf->surface)
1382 set_busy_cursor(shsurf, seat->pointer);
1388 ping_handler(struct weston_surface *surface, uint32_t serial)
1390 struct shell_surface *shsurf = get_shell_surface(surface);
1391 struct wl_event_loop *loop;
1392 int ping_timeout = 200;
1396 if (!shsurf->resource.client)
1399 if (shsurf->surface == shsurf->shell->grab_surface)
1402 if (!shsurf->ping_timer) {
1403 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
1404 if (!shsurf->ping_timer)
1407 shsurf->ping_timer->serial = serial;
1408 loop = wl_display_get_event_loop(surface->compositor->wl_display);
1409 shsurf->ping_timer->source =
1410 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
1411 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
1413 wl_shell_surface_send_ping(&shsurf->resource, serial);
1418 handle_pointer_focus(struct wl_listener *listener, void *data)
1420 struct weston_pointer *pointer = data;
1421 struct weston_surface *surface =
1422 (struct weston_surface *) pointer->focus;
1423 struct weston_compositor *compositor;
1424 struct shell_surface *shsurf;
1430 compositor = surface->compositor;
1431 shsurf = get_shell_surface(surface);
1433 if (shsurf && shsurf->unresponsive) {
1434 set_busy_cursor(shsurf, pointer);
1436 serial = wl_display_next_serial(compositor->wl_display);
1437 ping_handler(surface, serial);
1442 create_pointer_focus_listener(struct weston_seat *seat)
1444 struct wl_listener *listener;
1449 listener = malloc(sizeof *listener);
1450 listener->notify = handle_pointer_focus;
1451 wl_signal_add(&seat->pointer->focus_signal, listener);
1455 shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
1458 struct shell_surface *shsurf = resource->data;
1459 struct weston_seat *seat;
1460 struct weston_compositor *ec = shsurf->surface->compositor;
1462 if (shsurf->ping_timer == NULL)
1463 /* Just ignore unsolicited pong. */
1466 if (shsurf->ping_timer->serial == serial) {
1467 shsurf->unresponsive = 0;
1468 wl_list_for_each(seat, &ec->seat_list, link)
1469 end_busy_cursor(shsurf, seat->pointer);
1470 ping_timer_destroy(shsurf);
1475 shell_surface_set_title(struct wl_client *client,
1476 struct wl_resource *resource, const char *title)
1478 struct shell_surface *shsurf = resource->data;
1480 free(shsurf->title);
1481 shsurf->title = strdup(title);
1485 shell_surface_set_class(struct wl_client *client,
1486 struct wl_resource *resource, const char *class)
1488 struct shell_surface *shsurf = resource->data;
1490 free(shsurf->class);
1491 shsurf->class = strdup(class);
1494 static struct weston_output *
1495 get_default_output(struct weston_compositor *compositor)
1497 return container_of(compositor->output_list.next,
1498 struct weston_output, link);
1502 shell_unset_fullscreen(struct shell_surface *shsurf)
1504 struct workspace *ws;
1505 /* undo all fullscreen things here */
1506 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1507 shell_surface_is_top_fullscreen(shsurf)) {
1508 weston_output_switch_mode(shsurf->fullscreen_output,
1509 shsurf->fullscreen_output->origin);
1511 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1512 shsurf->fullscreen.framerate = 0;
1513 wl_list_remove(&shsurf->fullscreen.transform.link);
1514 wl_list_init(&shsurf->fullscreen.transform.link);
1515 if (shsurf->fullscreen.black_surface)
1516 weston_surface_destroy(shsurf->fullscreen.black_surface);
1517 shsurf->fullscreen.black_surface = NULL;
1518 shsurf->fullscreen_output = NULL;
1519 weston_surface_set_position(shsurf->surface,
1520 shsurf->saved_x, shsurf->saved_y);
1521 if (shsurf->saved_rotation_valid) {
1522 wl_list_insert(&shsurf->surface->geometry.transformation_list,
1523 &shsurf->rotation.transform.link);
1524 shsurf->saved_rotation_valid = false;
1527 ws = get_current_workspace(shsurf->shell);
1528 wl_list_remove(&shsurf->surface->layer_link);
1529 wl_list_insert(&ws->layer.surface_list, &shsurf->surface->layer_link);
1533 shell_unset_maximized(struct shell_surface *shsurf)
1535 struct workspace *ws;
1536 /* undo all maximized things here */
1537 shsurf->output = get_default_output(shsurf->surface->compositor);
1538 weston_surface_set_position(shsurf->surface,
1542 if (shsurf->saved_rotation_valid) {
1543 wl_list_insert(&shsurf->surface->geometry.transformation_list,
1544 &shsurf->rotation.transform.link);
1545 shsurf->saved_rotation_valid = false;
1548 ws = get_current_workspace(shsurf->shell);
1549 wl_list_remove(&shsurf->surface->layer_link);
1550 wl_list_insert(&ws->layer.surface_list, &shsurf->surface->layer_link);
1554 reset_shell_surface_type(struct shell_surface *surface)
1556 switch (surface->type) {
1557 case SHELL_SURFACE_FULLSCREEN:
1558 shell_unset_fullscreen(surface);
1560 case SHELL_SURFACE_MAXIMIZED:
1561 shell_unset_maximized(surface);
1563 case SHELL_SURFACE_NONE:
1564 case SHELL_SURFACE_TOPLEVEL:
1565 case SHELL_SURFACE_TRANSIENT:
1566 case SHELL_SURFACE_POPUP:
1570 surface->type = SHELL_SURFACE_NONE;
1575 set_surface_type(struct shell_surface *shsurf)
1577 struct weston_surface *surface = shsurf->surface;
1578 struct weston_surface *pes = shsurf->parent;
1580 reset_shell_surface_type(shsurf);
1582 shsurf->type = shsurf->next_type;
1583 shsurf->next_type = SHELL_SURFACE_NONE;
1585 switch (shsurf->type) {
1586 case SHELL_SURFACE_TOPLEVEL:
1588 case SHELL_SURFACE_TRANSIENT:
1589 weston_surface_set_position(surface,
1590 pes->geometry.x + shsurf->transient.x,
1591 pes->geometry.y + shsurf->transient.y);
1594 case SHELL_SURFACE_MAXIMIZED:
1595 case SHELL_SURFACE_FULLSCREEN:
1596 shsurf->saved_x = surface->geometry.x;
1597 shsurf->saved_y = surface->geometry.y;
1598 shsurf->saved_position_valid = true;
1600 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
1601 wl_list_remove(&shsurf->rotation.transform.link);
1602 wl_list_init(&shsurf->rotation.transform.link);
1603 weston_surface_geometry_dirty(shsurf->surface);
1604 shsurf->saved_rotation_valid = true;
1614 set_toplevel(struct shell_surface *shsurf)
1616 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
1620 shell_surface_set_toplevel(struct wl_client *client,
1621 struct wl_resource *resource)
1623 struct shell_surface *surface = resource->data;
1625 set_toplevel(surface);
1629 set_transient(struct shell_surface *shsurf,
1630 struct weston_surface *parent, int x, int y, uint32_t flags)
1632 /* assign to parents output */
1633 shsurf->parent = parent;
1634 shsurf->transient.x = x;
1635 shsurf->transient.y = y;
1636 shsurf->transient.flags = flags;
1637 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
1641 shell_surface_set_transient(struct wl_client *client,
1642 struct wl_resource *resource,
1643 struct wl_resource *parent_resource,
1644 int x, int y, uint32_t flags)
1646 struct shell_surface *shsurf = resource->data;
1647 struct weston_surface *parent = parent_resource->data;
1649 set_transient(shsurf, parent, x, y, flags);
1652 static struct desktop_shell *
1653 shell_surface_get_shell(struct shell_surface *shsurf)
1655 return shsurf->shell;
1659 get_output_panel_height(struct desktop_shell *shell,
1660 struct weston_output *output)
1662 struct weston_surface *surface;
1663 int panel_height = 0;
1668 wl_list_for_each(surface, &shell->panel_layer.surface_list, layer_link) {
1669 if (surface->output == output) {
1670 panel_height = surface->geometry.height;
1675 return panel_height;
1679 shell_surface_set_maximized(struct wl_client *client,
1680 struct wl_resource *resource,
1681 struct wl_resource *output_resource )
1683 struct shell_surface *shsurf = resource->data;
1684 struct weston_surface *es = shsurf->surface;
1685 struct desktop_shell *shell = NULL;
1686 uint32_t edges = 0, panel_height = 0;
1688 /* get the default output, if the client set it as NULL
1689 check whether the ouput is available */
1690 if (output_resource)
1691 shsurf->output = output_resource->data;
1692 else if (es->output)
1693 shsurf->output = es->output;
1695 shsurf->output = get_default_output(es->compositor);
1697 shell = shell_surface_get_shell(shsurf);
1698 panel_height = get_output_panel_height(shell, shsurf->output);
1699 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
1701 shsurf->client->send_configure(shsurf->surface, edges,
1702 shsurf->output->width,
1703 shsurf->output->height - panel_height);
1705 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
1709 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height);
1711 static struct weston_surface *
1712 create_black_surface(struct weston_compositor *ec,
1713 struct weston_surface *fs_surface,
1714 float x, float y, int w, int h)
1716 struct weston_surface *surface = NULL;
1718 surface = weston_surface_create(ec);
1719 if (surface == NULL) {
1720 weston_log("no memory\n");
1724 surface->configure = black_surface_configure;
1725 surface->configure_private = fs_surface;
1726 weston_surface_configure(surface, x, y, w, h);
1727 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
1728 pixman_region32_fini(&surface->opaque);
1729 pixman_region32_init_rect(&surface->opaque, 0, 0, w, h);
1730 pixman_region32_fini(&surface->input);
1731 pixman_region32_init_rect(&surface->input, 0, 0, w, h);
1736 /* Create black surface and append it to the associated fullscreen surface.
1737 * Handle size dismatch and positioning according to the method. */
1739 shell_configure_fullscreen(struct shell_surface *shsurf)
1741 struct weston_output *output = shsurf->fullscreen_output;
1742 struct weston_surface *surface = shsurf->surface;
1743 struct weston_matrix *matrix;
1744 float scale, output_aspect, surface_aspect, x, y;
1745 int32_t surf_x, surf_y, surf_width, surf_height;
1747 if (!shsurf->fullscreen.black_surface)
1748 shsurf->fullscreen.black_surface =
1749 create_black_surface(surface->compositor,
1751 output->x, output->y,
1755 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
1756 wl_list_insert(&surface->layer_link,
1757 &shsurf->fullscreen.black_surface->layer_link);
1758 shsurf->fullscreen.black_surface->output = output;
1760 surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y,
1761 &surf_width, &surf_height);
1763 switch (shsurf->fullscreen.type) {
1764 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
1765 if (surface->buffer_ref.buffer)
1766 center_on_output(surface, shsurf->fullscreen_output);
1768 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
1769 /* 1:1 mapping between surface and output dimensions */
1770 if (output->width == surf_width &&
1771 output->height == surf_height) {
1772 weston_surface_set_position(surface, output->x - surf_x,
1773 output->y - surf_y);
1777 matrix = &shsurf->fullscreen.transform.matrix;
1778 weston_matrix_init(matrix);
1780 output_aspect = (float) output->width /
1781 (float) output->height;
1782 surface_aspect = (float) surface->geometry.width /
1783 (float) surface->geometry.height;
1784 if (output_aspect < surface_aspect)
1785 scale = (float) output->width /
1788 scale = (float) output->height /
1789 (float) surf_height;
1791 weston_matrix_scale(matrix, scale, scale, 1);
1792 wl_list_remove(&shsurf->fullscreen.transform.link);
1793 wl_list_insert(&surface->geometry.transformation_list,
1794 &shsurf->fullscreen.transform.link);
1795 x = output->x + (output->width - surf_width * scale) / 2 - surf_x;
1796 y = output->y + (output->height - surf_height * scale) / 2 - surf_y;
1797 weston_surface_set_position(surface, x, y);
1800 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
1801 if (shell_surface_is_top_fullscreen(shsurf)) {
1802 struct weston_mode mode = {0,
1805 shsurf->fullscreen.framerate};
1807 if (weston_output_switch_mode(output, &mode) == 0) {
1808 weston_surface_configure(shsurf->fullscreen.black_surface,
1817 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
1824 /* make the fullscreen and black surface at the top */
1826 shell_stack_fullscreen(struct shell_surface *shsurf)
1828 struct weston_output *output = shsurf->fullscreen_output;
1829 struct weston_surface *surface = shsurf->surface;
1830 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
1832 wl_list_remove(&surface->layer_link);
1833 wl_list_insert(&shell->fullscreen_layer.surface_list,
1834 &surface->layer_link);
1835 weston_surface_damage(surface);
1837 if (!shsurf->fullscreen.black_surface)
1838 shsurf->fullscreen.black_surface =
1839 create_black_surface(surface->compositor,
1841 output->x, output->y,
1845 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
1846 wl_list_insert(&surface->layer_link,
1847 &shsurf->fullscreen.black_surface->layer_link);
1848 weston_surface_damage(shsurf->fullscreen.black_surface);
1852 shell_map_fullscreen(struct shell_surface *shsurf)
1854 shell_stack_fullscreen(shsurf);
1855 shell_configure_fullscreen(shsurf);
1859 set_fullscreen(struct shell_surface *shsurf,
1862 struct weston_output *output)
1864 struct weston_surface *es = shsurf->surface;
1867 shsurf->output = output;
1868 else if (es->output)
1869 shsurf->output = es->output;
1871 shsurf->output = get_default_output(es->compositor);
1873 shsurf->fullscreen_output = shsurf->output;
1874 shsurf->fullscreen.type = method;
1875 shsurf->fullscreen.framerate = framerate;
1876 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
1878 shsurf->client->send_configure(shsurf->surface, 0,
1879 shsurf->output->width,
1880 shsurf->output->height);
1884 shell_surface_set_fullscreen(struct wl_client *client,
1885 struct wl_resource *resource,
1888 struct wl_resource *output_resource)
1890 struct shell_surface *shsurf = resource->data;
1891 struct weston_output *output;
1893 if (output_resource)
1894 output = output_resource->data;
1898 set_fullscreen(shsurf, method, framerate, output);
1901 static const struct weston_pointer_grab_interface popup_grab_interface;
1904 destroy_shell_seat(struct wl_listener *listener, void *data)
1906 struct shell_seat *shseat =
1907 container_of(listener,
1908 struct shell_seat, seat_destroy_listener);
1909 struct shell_surface *shsurf, *prev = NULL;
1911 if (shseat->popup_grab.grab.interface == &popup_grab_interface) {
1912 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
1913 shseat->popup_grab.client = NULL;
1915 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
1916 shsurf->popup.shseat = NULL;
1918 wl_list_init(&prev->popup.grab_link);
1922 wl_list_init(&prev->popup.grab_link);
1925 wl_list_remove(&shseat->seat_destroy_listener.link);
1929 static struct shell_seat *
1930 create_shell_seat(struct weston_seat *seat)
1932 struct shell_seat *shseat;
1934 shseat = calloc(1, sizeof *shseat);
1936 weston_log("no memory to allocate shell seat\n");
1940 shseat->seat = seat;
1941 wl_list_init(&shseat->popup_grab.surfaces_list);
1943 shseat->seat_destroy_listener.notify = destroy_shell_seat;
1944 wl_signal_add(&seat->destroy_signal,
1945 &shseat->seat_destroy_listener);
1950 static struct shell_seat *
1951 get_shell_seat(struct weston_seat *seat)
1953 struct wl_listener *listener;
1955 listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat);
1956 if (listener == NULL)
1957 return create_shell_seat(seat);
1959 return container_of(listener,
1960 struct shell_seat, seat_destroy_listener);
1964 popup_grab_focus(struct weston_pointer_grab *grab)
1966 struct weston_pointer *pointer = grab->pointer;
1967 struct weston_surface *surface;
1968 struct shell_seat *shseat =
1969 container_of(grab, struct shell_seat, popup_grab.grab);
1970 struct wl_client *client = shseat->popup_grab.client;
1973 surface = weston_compositor_pick_surface(pointer->seat->compositor,
1974 pointer->x, pointer->y,
1977 if (surface && surface->resource.client == client) {
1978 weston_pointer_set_focus(pointer, surface, sx, sy);
1980 weston_pointer_set_focus(pointer, NULL,
1981 wl_fixed_from_int(0),
1982 wl_fixed_from_int(0));
1987 popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
1989 struct weston_pointer *pointer = grab->pointer;
1992 if (pointer->focus_resource) {
1993 weston_surface_from_global_fixed(pointer->focus,
1994 pointer->x, pointer->y,
1996 wl_pointer_send_motion(pointer->focus_resource, time, sx, sy);
2001 popup_grab_button(struct weston_pointer_grab *grab,
2002 uint32_t time, uint32_t button, uint32_t state_w)
2004 struct wl_resource *resource;
2005 struct shell_seat *shseat =
2006 container_of(grab, struct shell_seat, popup_grab.grab);
2007 struct wl_display *display;
2008 enum wl_pointer_button_state state = state_w;
2011 resource = grab->pointer->focus_resource;
2013 display = wl_client_get_display(resource->client);
2014 serial = wl_display_get_serial(display);
2015 wl_pointer_send_button(resource, serial, time, button, state);
2016 } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
2017 (shseat->popup_grab.initial_up ||
2018 time - shseat->seat->pointer->grab_time > 500)) {
2019 popup_grab_end(grab->pointer);
2022 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
2023 shseat->popup_grab.initial_up = 1;
2026 static const struct weston_pointer_grab_interface popup_grab_interface = {
2033 popup_grab_end(struct weston_pointer *pointer)
2035 struct weston_pointer_grab *grab = pointer->grab;
2036 struct shell_seat *shseat =
2037 container_of(grab, struct shell_seat, popup_grab.grab);
2038 struct shell_surface *shsurf;
2039 struct shell_surface *prev = NULL;
2041 if (pointer->grab->interface == &popup_grab_interface) {
2042 weston_pointer_end_grab(grab->pointer);
2043 shseat->popup_grab.client = NULL;
2044 shseat->popup_grab.grab.interface = NULL;
2045 assert(!wl_list_empty(&shseat->popup_grab.surfaces_list));
2046 /* Send the popup_done event to all the popups open */
2047 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
2048 wl_shell_surface_send_popup_done(&shsurf->resource);
2049 shsurf->popup.shseat = NULL;
2051 wl_list_init(&prev->popup.grab_link);
2055 wl_list_init(&prev->popup.grab_link);
2056 wl_list_init(&shseat->popup_grab.surfaces_list);
2061 add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat)
2063 struct weston_seat *seat = shseat->seat;
2065 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
2066 shseat->popup_grab.client = shsurf->resource.client;
2067 shseat->popup_grab.grab.interface = &popup_grab_interface;
2068 /* We must make sure here that this popup was opened after
2069 * a mouse press, and not just by moving around with other
2070 * popups already open. */
2071 if (shseat->seat->pointer->button_count > 0)
2072 shseat->popup_grab.initial_up = 0;
2074 weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab);
2076 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
2080 remove_popup_grab(struct shell_surface *shsurf)
2082 struct shell_seat *shseat = shsurf->popup.shseat;
2084 wl_list_remove(&shsurf->popup.grab_link);
2085 wl_list_init(&shsurf->popup.grab_link);
2086 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
2087 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
2088 shseat->popup_grab.grab.interface = NULL;
2093 shell_map_popup(struct shell_surface *shsurf)
2095 struct shell_seat *shseat = shsurf->popup.shseat;
2096 struct weston_surface *es = shsurf->surface;
2097 struct weston_surface *parent = shsurf->parent;
2099 es->output = parent->output;
2101 weston_surface_set_transform_parent(es, parent);
2102 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
2103 weston_surface_update_transform(es);
2105 if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) {
2106 add_popup_grab(shsurf, shseat);
2108 wl_shell_surface_send_popup_done(&shsurf->resource);
2109 shseat->popup_grab.client = NULL;
2114 shell_surface_set_popup(struct wl_client *client,
2115 struct wl_resource *resource,
2116 struct wl_resource *seat_resource,
2118 struct wl_resource *parent_resource,
2119 int32_t x, int32_t y, uint32_t flags)
2121 struct shell_surface *shsurf = resource->data;
2123 shsurf->type = SHELL_SURFACE_POPUP;
2124 shsurf->parent = parent_resource->data;
2125 shsurf->popup.shseat = get_shell_seat(seat_resource->data);
2126 shsurf->popup.serial = serial;
2127 shsurf->popup.x = x;
2128 shsurf->popup.y = y;
2131 static const struct wl_shell_surface_interface shell_surface_implementation = {
2134 shell_surface_resize,
2135 shell_surface_set_toplevel,
2136 shell_surface_set_transient,
2137 shell_surface_set_fullscreen,
2138 shell_surface_set_popup,
2139 shell_surface_set_maximized,
2140 shell_surface_set_title,
2141 shell_surface_set_class
2145 destroy_shell_surface(struct shell_surface *shsurf)
2147 if (!wl_list_empty(&shsurf->popup.grab_link)) {
2148 remove_popup_grab(shsurf);
2151 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
2152 shell_surface_is_top_fullscreen(shsurf)) {
2153 weston_output_switch_mode(shsurf->fullscreen_output,
2154 shsurf->fullscreen_output->origin);
2157 if (shsurf->fullscreen.black_surface)
2158 weston_surface_destroy(shsurf->fullscreen.black_surface);
2160 /* As destroy_resource() use wl_list_for_each_safe(),
2161 * we can always remove the listener.
2163 wl_list_remove(&shsurf->surface_destroy_listener.link);
2164 shsurf->surface->configure = NULL;
2165 ping_timer_destroy(shsurf);
2166 free(shsurf->title);
2168 wl_list_remove(&shsurf->link);
2173 shell_destroy_shell_surface(struct wl_resource *resource)
2175 struct shell_surface *shsurf = resource->data;
2177 destroy_shell_surface(shsurf);
2181 shell_handle_surface_destroy(struct wl_listener *listener, void *data)
2183 struct shell_surface *shsurf = container_of(listener,
2184 struct shell_surface,
2185 surface_destroy_listener);
2187 if (shsurf->resource.client) {
2188 wl_resource_destroy(&shsurf->resource);
2190 wl_signal_emit(&shsurf->resource.destroy_signal,
2192 destroy_shell_surface(shsurf);
2197 shell_surface_configure(struct weston_surface *, int32_t, int32_t, int32_t, int32_t);
2199 static struct shell_surface *
2200 get_shell_surface(struct weston_surface *surface)
2202 if (surface->configure == shell_surface_configure)
2203 return surface->configure_private;
2208 static struct shell_surface *
2209 create_shell_surface(void *shell, struct weston_surface *surface,
2210 const struct weston_shell_client *client)
2212 struct shell_surface *shsurf;
2214 if (surface->configure) {
2215 weston_log("surface->configure already set\n");
2219 shsurf = calloc(1, sizeof *shsurf);
2221 weston_log("no memory to allocate shell surface\n");
2225 surface->configure = shell_surface_configure;
2226 surface->configure_private = shsurf;
2228 shsurf->shell = (struct desktop_shell *) shell;
2229 shsurf->unresponsive = 0;
2230 shsurf->saved_position_valid = false;
2231 shsurf->saved_rotation_valid = false;
2232 shsurf->surface = surface;
2233 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
2234 shsurf->fullscreen.framerate = 0;
2235 shsurf->fullscreen.black_surface = NULL;
2236 shsurf->ping_timer = NULL;
2237 wl_list_init(&shsurf->fullscreen.transform.link);
2239 wl_signal_init(&shsurf->resource.destroy_signal);
2240 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
2241 wl_signal_add(&surface->resource.destroy_signal,
2242 &shsurf->surface_destroy_listener);
2244 /* init link so its safe to always remove it in destroy_shell_surface */
2245 wl_list_init(&shsurf->link);
2246 wl_list_init(&shsurf->popup.grab_link);
2248 /* empty when not in use */
2249 wl_list_init(&shsurf->rotation.transform.link);
2250 weston_matrix_init(&shsurf->rotation.rotation);
2252 wl_list_init(&shsurf->workspace_transform.link);
2254 shsurf->type = SHELL_SURFACE_NONE;
2255 shsurf->next_type = SHELL_SURFACE_NONE;
2257 shsurf->client = client;
2263 shell_get_shell_surface(struct wl_client *client,
2264 struct wl_resource *resource,
2266 struct wl_resource *surface_resource)
2268 struct weston_surface *surface = surface_resource->data;
2269 struct desktop_shell *shell = resource->data;
2270 struct shell_surface *shsurf;
2272 if (get_shell_surface(surface)) {
2273 wl_resource_post_error(surface_resource,
2274 WL_DISPLAY_ERROR_INVALID_OBJECT,
2275 "desktop_shell::get_shell_surface already requested");
2279 shsurf = create_shell_surface(shell, surface, &shell_client);
2281 wl_resource_post_error(surface_resource,
2282 WL_DISPLAY_ERROR_INVALID_OBJECT,
2283 "surface->configure already set");
2287 shsurf->resource.destroy = shell_destroy_shell_surface;
2288 shsurf->resource.object.id = id;
2289 shsurf->resource.object.interface = &wl_shell_surface_interface;
2290 shsurf->resource.object.implementation =
2291 (void (**)(void)) &shell_surface_implementation;
2292 shsurf->resource.data = shsurf;
2294 wl_client_add_resource(client, &shsurf->resource);
2297 static const struct wl_shell_interface shell_implementation = {
2298 shell_get_shell_surface
2302 shell_fade(struct desktop_shell *shell, enum fade_type type);
2305 screensaver_timeout(void *data)
2307 struct desktop_shell *shell = data;
2309 shell_fade(shell, FADE_OUT);
2315 handle_screensaver_sigchld(struct weston_process *proc, int status)
2317 struct desktop_shell *shell =
2318 container_of(proc, struct desktop_shell, screensaver.process);
2323 weston_compositor_sleep(shell->compositor);
2327 launch_screensaver(struct desktop_shell *shell)
2329 if (shell->screensaver.binding)
2332 if (!shell->screensaver.path) {
2333 weston_compositor_sleep(shell->compositor);
2337 if (shell->screensaver.process.pid != 0) {
2338 weston_log("old screensaver still running\n");
2342 weston_client_launch(shell->compositor,
2343 &shell->screensaver.process,
2344 shell->screensaver.path,
2345 handle_screensaver_sigchld);
2349 terminate_screensaver(struct desktop_shell *shell)
2351 if (shell->screensaver.process.pid == 0)
2354 kill(shell->screensaver.process.pid, SIGTERM);
2358 configure_static_surface(struct weston_surface *es, struct weston_layer *layer, int32_t width, int32_t height)
2360 struct weston_surface *s, *next;
2365 wl_list_for_each_safe(s, next, &layer->surface_list, layer_link) {
2366 if (s->output == es->output && s != es) {
2367 weston_surface_unmap(s);
2368 s->configure = NULL;
2372 weston_surface_configure(es, es->output->x, es->output->y, width, height);
2374 if (wl_list_empty(&es->layer_link)) {
2375 wl_list_insert(&layer->surface_list, &es->layer_link);
2376 weston_compositor_schedule_repaint(es->compositor);
2381 background_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
2383 struct desktop_shell *shell = es->configure_private;
2385 configure_static_surface(es, &shell->background_layer, width, height);
2389 desktop_shell_set_background(struct wl_client *client,
2390 struct wl_resource *resource,
2391 struct wl_resource *output_resource,
2392 struct wl_resource *surface_resource)
2394 struct desktop_shell *shell = resource->data;
2395 struct weston_surface *surface = surface_resource->data;
2397 if (surface->configure) {
2398 wl_resource_post_error(surface_resource,
2399 WL_DISPLAY_ERROR_INVALID_OBJECT,
2400 "surface role already assigned");
2404 surface->configure = background_configure;
2405 surface->configure_private = shell;
2406 surface->output = output_resource->data;
2407 desktop_shell_send_configure(resource, 0,
2409 surface->output->width,
2410 surface->output->height);
2414 panel_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
2416 struct desktop_shell *shell = es->configure_private;
2418 configure_static_surface(es, &shell->panel_layer, width, height);
2422 desktop_shell_set_panel(struct wl_client *client,
2423 struct wl_resource *resource,
2424 struct wl_resource *output_resource,
2425 struct wl_resource *surface_resource)
2427 struct desktop_shell *shell = resource->data;
2428 struct weston_surface *surface = surface_resource->data;
2430 if (surface->configure) {
2431 wl_resource_post_error(surface_resource,
2432 WL_DISPLAY_ERROR_INVALID_OBJECT,
2433 "surface role already assigned");
2437 surface->configure = panel_configure;
2438 surface->configure_private = shell;
2439 surface->output = output_resource->data;
2440 desktop_shell_send_configure(resource, 0,
2442 surface->output->width,
2443 surface->output->height);
2447 lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
2449 struct desktop_shell *shell = surface->configure_private;
2454 center_on_output(surface, get_default_output(shell->compositor));
2456 if (!weston_surface_is_mapped(surface)) {
2457 wl_list_insert(&shell->lock_layer.surface_list,
2458 &surface->layer_link);
2459 weston_surface_update_transform(surface);
2460 shell_fade(shell, FADE_IN);
2465 handle_lock_surface_destroy(struct wl_listener *listener, void *data)
2467 struct desktop_shell *shell =
2468 container_of(listener, struct desktop_shell, lock_surface_listener);
2470 weston_log("lock surface gone\n");
2471 shell->lock_surface = NULL;
2475 desktop_shell_set_lock_surface(struct wl_client *client,
2476 struct wl_resource *resource,
2477 struct wl_resource *surface_resource)
2479 struct desktop_shell *shell = resource->data;
2480 struct weston_surface *surface = surface_resource->data;
2482 shell->prepare_event_sent = false;
2487 shell->lock_surface = surface;
2489 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
2490 wl_signal_add(&surface_resource->destroy_signal,
2491 &shell->lock_surface_listener);
2493 surface->configure = lock_surface_configure;
2494 surface->configure_private = shell;
2498 resume_desktop(struct desktop_shell *shell)
2500 struct workspace *ws = get_current_workspace(shell);
2502 terminate_screensaver(shell);
2504 wl_list_remove(&shell->lock_layer.link);
2505 wl_list_insert(&shell->compositor->cursor_layer.link,
2506 &shell->fullscreen_layer.link);
2507 wl_list_insert(&shell->fullscreen_layer.link,
2508 &shell->panel_layer.link);
2509 if (shell->showing_input_panels) {
2510 wl_list_insert(&shell->panel_layer.link,
2511 &shell->input_panel_layer.link);
2512 wl_list_insert(&shell->input_panel_layer.link,
2515 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
2518 restore_focus_state(shell, get_current_workspace(shell));
2520 shell->locked = false;
2521 shell_fade(shell, FADE_IN);
2522 weston_compositor_damage_all(shell->compositor);
2526 desktop_shell_unlock(struct wl_client *client,
2527 struct wl_resource *resource)
2529 struct desktop_shell *shell = resource->data;
2531 shell->prepare_event_sent = false;
2534 resume_desktop(shell);
2538 desktop_shell_set_grab_surface(struct wl_client *client,
2539 struct wl_resource *resource,
2540 struct wl_resource *surface_resource)
2542 struct desktop_shell *shell = resource->data;
2544 shell->grab_surface = surface_resource->data;
2547 static const struct desktop_shell_interface desktop_shell_implementation = {
2548 desktop_shell_set_background,
2549 desktop_shell_set_panel,
2550 desktop_shell_set_lock_surface,
2551 desktop_shell_unlock,
2552 desktop_shell_set_grab_surface
2555 static enum shell_surface_type
2556 get_shell_surface_type(struct weston_surface *surface)
2558 struct shell_surface *shsurf;
2560 shsurf = get_shell_surface(surface);
2562 return SHELL_SURFACE_NONE;
2563 return shsurf->type;
2567 move_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
2569 struct weston_surface *focus =
2570 (struct weston_surface *) seat->pointer->focus;
2571 struct weston_surface *surface;
2572 struct shell_surface *shsurf;
2574 surface = weston_surface_get_main_surface(focus);
2575 if (surface == NULL)
2578 shsurf = get_shell_surface(surface);
2579 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
2580 shsurf->type == SHELL_SURFACE_MAXIMIZED)
2583 surface_move(shsurf, (struct weston_seat *) seat);
2587 resize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
2589 struct weston_surface *focus =
2590 (struct weston_surface *) seat->pointer->focus;
2591 struct weston_surface *surface;
2594 struct shell_surface *shsurf;
2596 surface = weston_surface_get_main_surface(focus);
2597 if (surface == NULL)
2600 shsurf = get_shell_surface(surface);
2601 if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
2602 shsurf->type == SHELL_SURFACE_MAXIMIZED)
2605 weston_surface_from_global(surface,
2606 wl_fixed_to_int(seat->pointer->grab_x),
2607 wl_fixed_to_int(seat->pointer->grab_y),
2610 if (x < surface->geometry.width / 3)
2611 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
2612 else if (x < 2 * surface->geometry.width / 3)
2615 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
2617 if (y < surface->geometry.height / 3)
2618 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
2619 else if (y < 2 * surface->geometry.height / 3)
2622 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
2624 surface_resize(shsurf, (struct weston_seat *) seat, edges);
2628 surface_opacity_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
2629 wl_fixed_t value, void *data)
2632 struct shell_surface *shsurf;
2633 struct weston_surface *focus =
2634 (struct weston_surface *) seat->pointer->focus;
2635 struct weston_surface *surface;
2637 /* XXX: broken for windows containing sub-surfaces */
2638 surface = weston_surface_get_main_surface(focus);
2639 if (surface == NULL)
2642 shsurf = get_shell_surface(surface);
2646 surface->alpha -= wl_fixed_to_double(value) * step;
2648 if (surface->alpha > 1.0)
2649 surface->alpha = 1.0;
2650 if (surface->alpha < step)
2651 surface->alpha = step;
2653 weston_surface_geometry_dirty(surface);
2654 weston_surface_damage(surface);
2658 do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
2661 struct weston_seat *ws = (struct weston_seat *) seat;
2662 struct weston_compositor *compositor = ws->compositor;
2663 struct weston_output *output;
2666 wl_list_for_each(output, &compositor->output_list, link) {
2667 if (pixman_region32_contains_point(&output->region,
2668 wl_fixed_to_double(seat->pointer->x),
2669 wl_fixed_to_double(seat->pointer->y),
2671 if (key == KEY_PAGEUP)
2672 increment = output->zoom.increment;
2673 else if (key == KEY_PAGEDOWN)
2674 increment = -output->zoom.increment;
2675 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
2676 /* For every pixel zoom 20th of a step */
2677 increment = output->zoom.increment *
2678 -wl_fixed_to_double(value) / 20.0;
2682 output->zoom.level += increment;
2684 if (output->zoom.level < 0.0)
2685 output->zoom.level = 0.0;
2686 else if (output->zoom.level > output->zoom.max_level)
2687 output->zoom.level = output->zoom.max_level;
2688 else if (!output->zoom.active) {
2689 output->zoom.active = 1;
2690 output->disable_planes++;
2693 output->zoom.spring_z.target = output->zoom.level;
2695 weston_output_update_zoom(output, output->zoom.type);
2701 zoom_axis_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
2702 wl_fixed_t value, void *data)
2704 do_zoom(seat, time, 0, axis, value);
2708 zoom_key_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
2711 do_zoom(seat, time, key, 0, 0);
2715 terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
2718 struct weston_compositor *compositor = data;
2720 wl_display_terminate(compositor->wl_display);
2724 rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
2726 struct rotate_grab *rotate =
2727 container_of(grab, struct rotate_grab, base.grab);
2728 struct weston_pointer *pointer = grab->pointer;
2729 struct shell_surface *shsurf = rotate->base.shsurf;
2730 struct weston_surface *surface;
2731 float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
2736 surface = shsurf->surface;
2738 cx = 0.5f * surface->geometry.width;
2739 cy = 0.5f * surface->geometry.height;
2741 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
2742 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
2743 r = sqrtf(dx * dx + dy * dy);
2745 wl_list_remove(&shsurf->rotation.transform.link);
2746 weston_surface_geometry_dirty(shsurf->surface);
2749 struct weston_matrix *matrix =
2750 &shsurf->rotation.transform.matrix;
2752 weston_matrix_init(&rotate->rotation);
2753 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
2755 weston_matrix_init(matrix);
2756 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
2757 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
2758 weston_matrix_multiply(matrix, &rotate->rotation);
2759 weston_matrix_translate(matrix, cx, cy, 0.0f);
2762 &shsurf->surface->geometry.transformation_list,
2763 &shsurf->rotation.transform.link);
2765 wl_list_init(&shsurf->rotation.transform.link);
2766 weston_matrix_init(&shsurf->rotation.rotation);
2767 weston_matrix_init(&rotate->rotation);
2770 /* We need to adjust the position of the surface
2771 * in case it was resized in a rotated state before */
2772 cposx = surface->geometry.x + cx;
2773 cposy = surface->geometry.y + cy;
2774 dposx = rotate->center.x - cposx;
2775 dposy = rotate->center.y - cposy;
2776 if (dposx != 0.0f || dposy != 0.0f) {
2777 weston_surface_set_position(surface,
2778 surface->geometry.x + dposx,
2779 surface->geometry.y + dposy);
2782 /* Repaint implies weston_surface_update_transform(), which
2783 * lazily applies the damage due to rotation update.
2785 weston_compositor_schedule_repaint(shsurf->surface->compositor);
2789 rotate_grab_button(struct weston_pointer_grab *grab,
2790 uint32_t time, uint32_t button, uint32_t state_w)
2792 struct rotate_grab *rotate =
2793 container_of(grab, struct rotate_grab, base.grab);
2794 struct weston_pointer *pointer = grab->pointer;
2795 struct shell_surface *shsurf = rotate->base.shsurf;
2796 enum wl_pointer_button_state state = state_w;
2798 if (pointer->button_count == 0 &&
2799 state == WL_POINTER_BUTTON_STATE_RELEASED) {
2801 weston_matrix_multiply(&shsurf->rotation.rotation,
2803 shell_grab_end(&rotate->base);
2808 static const struct weston_pointer_grab_interface rotate_grab_interface = {
2815 surface_rotate(struct shell_surface *surface, struct weston_seat *seat)
2817 struct rotate_grab *rotate;
2821 rotate = malloc(sizeof *rotate);
2825 weston_surface_to_global_float(surface->surface,
2826 surface->surface->geometry.width / 2,
2827 surface->surface->geometry.height / 2,
2828 &rotate->center.x, &rotate->center.y);
2830 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
2831 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
2832 r = sqrtf(dx * dx + dy * dy);
2834 struct weston_matrix inverse;
2836 weston_matrix_init(&inverse);
2837 weston_matrix_rotate_xy(&inverse, dx / r, -dy / r);
2838 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
2840 weston_matrix_init(&rotate->rotation);
2841 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
2843 weston_matrix_init(&surface->rotation.rotation);
2844 weston_matrix_init(&rotate->rotation);
2847 shell_grab_start(&rotate->base, &rotate_grab_interface, surface,
2848 seat->pointer, DESKTOP_SHELL_CURSOR_ARROW);
2852 rotate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
2855 struct weston_surface *focus =
2856 (struct weston_surface *) seat->pointer->focus;
2857 struct weston_surface *base_surface;
2858 struct shell_surface *surface;
2860 base_surface = weston_surface_get_main_surface(focus);
2861 if (base_surface == NULL)
2864 surface = get_shell_surface(base_surface);
2865 if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN ||
2866 surface->type == SHELL_SURFACE_MAXIMIZED)
2869 surface_rotate(surface, seat);
2873 lower_fullscreen_layer(struct desktop_shell *shell)
2875 struct workspace *ws;
2876 struct weston_surface *surface, *prev;
2878 ws = get_current_workspace(shell);
2879 wl_list_for_each_reverse_safe(surface, prev,
2880 &shell->fullscreen_layer.surface_list,
2882 weston_surface_restack(surface, &ws->layer.surface_list);
2886 activate(struct desktop_shell *shell, struct weston_surface *es,
2887 struct weston_seat *seat)
2889 struct weston_surface *main_surface;
2890 struct focus_state *state;
2891 struct workspace *ws;
2893 main_surface = weston_surface_get_main_surface(es);
2895 weston_surface_activate(es, seat);
2897 state = ensure_focus_state(shell, seat);
2901 state->keyboard_focus = es;
2902 wl_list_remove(&state->surface_destroy_listener.link);
2903 wl_signal_add(&es->resource.destroy_signal,
2904 &state->surface_destroy_listener);
2906 switch (get_shell_surface_type(main_surface)) {
2907 case SHELL_SURFACE_FULLSCREEN:
2908 /* should on top of panels */
2909 shell_stack_fullscreen(get_shell_surface(main_surface));
2910 shell_configure_fullscreen(get_shell_surface(main_surface));
2913 ws = get_current_workspace(shell);
2914 weston_surface_restack(main_surface, &ws->layer.surface_list);
2919 /* no-op func for checking black surface */
2921 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
2926 is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
2928 if (es->configure == black_surface_configure) {
2930 *fs_surface = (struct weston_surface *)es->configure_private;
2937 click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
2940 struct weston_seat *ws = (struct weston_seat *) seat;
2941 struct desktop_shell *shell = data;
2942 struct weston_surface *focus;
2943 struct weston_surface *main_surface;
2945 focus = (struct weston_surface *) seat->pointer->focus;
2949 if (is_black_surface(focus, &main_surface))
2950 focus = main_surface;
2952 main_surface = weston_surface_get_main_surface(focus);
2953 if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE)
2956 if (seat->pointer->grab == &seat->pointer->default_grab)
2957 activate(shell, focus, ws);
2961 lock(struct desktop_shell *shell)
2963 struct workspace *ws = get_current_workspace(shell);
2965 if (shell->locked) {
2966 weston_compositor_sleep(shell->compositor);
2970 shell->locked = true;
2972 /* Hide all surfaces by removing the fullscreen, panel and
2973 * toplevel layers. This way nothing else can show or receive
2974 * input events while we are locked. */
2976 wl_list_remove(&shell->panel_layer.link);
2977 wl_list_remove(&shell->fullscreen_layer.link);
2978 if (shell->showing_input_panels)
2979 wl_list_remove(&shell->input_panel_layer.link);
2980 wl_list_remove(&ws->layer.link);
2981 wl_list_insert(&shell->compositor->cursor_layer.link,
2982 &shell->lock_layer.link);
2984 launch_screensaver(shell);
2986 /* TODO: disable bindings that should not work while locked. */
2988 /* All this must be undone in resume_desktop(). */
2992 unlock(struct desktop_shell *shell)
2994 if (!shell->locked || shell->lock_surface) {
2995 shell_fade(shell, FADE_IN);
2999 /* If desktop-shell client has gone away, unlock immediately. */
3000 if (!shell->child.desktop_shell) {
3001 resume_desktop(shell);
3005 if (shell->prepare_event_sent)
3008 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
3009 shell->prepare_event_sent = true;
3013 shell_fade_done(struct weston_surface_animation *animation, void *data)
3015 struct desktop_shell *shell = data;
3017 shell->fade.animation = NULL;
3019 switch (shell->fade.type) {
3021 weston_surface_destroy(shell->fade.surface);
3022 shell->fade.surface = NULL;
3031 shell_fade(struct desktop_shell *shell, enum fade_type type)
3033 struct weston_compositor *compositor = shell->compositor;
3034 struct weston_surface *surface;
3045 weston_log("shell: invalid fade type\n");
3049 shell->fade.type = type;
3051 if (shell->fade.surface == NULL) {
3052 surface = weston_surface_create(compositor);
3056 weston_surface_configure(surface, 0, 0, 8192, 8192);
3057 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
3058 surface->alpha = 1.0 - tint;
3059 wl_list_insert(&compositor->fade_layer.surface_list,
3060 &surface->layer_link);
3061 weston_surface_update_transform(surface);
3062 shell->fade.surface = surface;
3063 pixman_region32_init(&surface->input);
3066 if (shell->fade.animation)
3067 weston_fade_update(shell->fade.animation,
3068 shell->fade.surface->alpha, tint, 30.0);
3070 shell->fade.animation =
3071 weston_fade_run(shell->fade.surface,
3072 1.0 - tint, tint, 30.0,
3073 shell_fade_done, shell);
3077 idle_handler(struct wl_listener *listener, void *data)
3079 struct desktop_shell *shell =
3080 container_of(listener, struct desktop_shell, idle_listener);
3082 shell_fade(shell, FADE_OUT);
3083 /* lock() is called from shell_fade_done() */
3087 wake_handler(struct wl_listener *listener, void *data)
3089 struct desktop_shell *shell =
3090 container_of(listener, struct desktop_shell, wake_listener);
3096 show_input_panels(struct wl_listener *listener, void *data)
3098 struct desktop_shell *shell =
3099 container_of(listener, struct desktop_shell,
3100 show_input_panel_listener);
3101 struct input_panel_surface *surface, *next;
3102 struct weston_surface *ws;
3104 shell->text_input.surface = (struct weston_surface*)data;
3106 if (shell->showing_input_panels)
3109 shell->showing_input_panels = true;
3112 wl_list_insert(&shell->panel_layer.link,
3113 &shell->input_panel_layer.link);
3115 wl_list_for_each_safe(surface, next,
3116 &shell->input_panel.surfaces, link) {
3117 ws = surface->surface;
3118 if (!ws->buffer_ref.buffer)
3120 wl_list_insert(&shell->input_panel_layer.surface_list,
3122 weston_surface_geometry_dirty(ws);
3123 weston_surface_update_transform(ws);
3124 weston_surface_damage(ws);
3125 weston_slide_run(ws, ws->geometry.height, 0, NULL, NULL);
3130 hide_input_panels(struct wl_listener *listener, void *data)
3132 struct desktop_shell *shell =
3133 container_of(listener, struct desktop_shell,
3134 hide_input_panel_listener);
3135 struct weston_surface *surface, *next;
3137 if (!shell->showing_input_panels)
3140 shell->showing_input_panels = false;
3143 wl_list_remove(&shell->input_panel_layer.link);
3145 wl_list_for_each_safe(surface, next,
3146 &shell->input_panel_layer.surface_list, layer_link)
3147 weston_surface_unmap(surface);
3151 update_input_panels(struct wl_listener *listener, void *data)
3153 struct desktop_shell *shell =
3154 container_of(listener, struct desktop_shell,
3155 update_input_panel_listener);
3157 memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t));
3161 center_on_output(struct weston_surface *surface, struct weston_output *output)
3163 int32_t surf_x, surf_y, width, height;
3166 surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y, &width, &height);
3168 x = output->x + (output->width - width) / 2 - surf_x / 2;
3169 y = output->y + (output->height - height) / 2 - surf_y / 2;
3171 weston_surface_configure(surface, x, y, width, height);
3175 weston_surface_set_initial_position (struct weston_surface *surface,
3176 struct desktop_shell *shell)
3178 struct weston_compositor *compositor = shell->compositor;
3180 int range_x, range_y;
3181 int dx, dy, x, y, panel_height;
3182 struct weston_output *output, *target_output = NULL;
3183 struct weston_seat *seat;
3185 /* As a heuristic place the new window on the same output as the
3186 * pointer. Falling back to the output containing 0, 0.
3188 * TODO: Do something clever for touch too?
3190 wl_list_for_each(seat, &compositor->seat_list, link) {
3191 if (seat->pointer) {
3192 ix = wl_fixed_to_int(seat->pointer->x);
3193 iy = wl_fixed_to_int(seat->pointer->y);
3198 wl_list_for_each(output, &compositor->output_list, link) {
3199 if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) {
3200 target_output = output;
3205 if (!target_output) {
3206 weston_surface_set_position(surface, 10 + random() % 400,
3207 10 + random() % 400);
3211 /* Valid range within output where the surface will still be onscreen.
3212 * If this is negative it means that the surface is bigger than
3215 panel_height = get_output_panel_height(shell, target_output);
3216 range_x = target_output->width - surface->geometry.width;
3217 range_y = (target_output->height - panel_height) -
3218 surface->geometry.height;
3221 dx = random() % range_x;
3226 dy = panel_height + random() % range_y;
3230 x = target_output->x + dx;
3231 y = target_output->y + dy;
3233 weston_surface_set_position (surface, x, y);
3237 map(struct desktop_shell *shell, struct weston_surface *surface,
3238 int32_t width, int32_t height, int32_t sx, int32_t sy)
3240 struct weston_compositor *compositor = shell->compositor;
3241 struct shell_surface *shsurf = get_shell_surface(surface);
3242 enum shell_surface_type surface_type = shsurf->type;
3243 struct weston_surface *parent;
3244 struct weston_seat *seat;
3245 struct workspace *ws;
3246 int panel_height = 0;
3247 int32_t surf_x, surf_y;
3249 surface->geometry.width = width;
3250 surface->geometry.height = height;
3251 weston_surface_geometry_dirty(surface);
3253 /* initial positioning, see also configure() */
3254 switch (surface_type) {
3255 case SHELL_SURFACE_TOPLEVEL:
3256 weston_surface_set_initial_position(surface, shell);
3258 case SHELL_SURFACE_FULLSCREEN:
3259 center_on_output(surface, shsurf->fullscreen_output);
3260 shell_map_fullscreen(shsurf);
3262 case SHELL_SURFACE_MAXIMIZED:
3263 /* use surface configure to set the geometry */
3264 panel_height = get_output_panel_height(shell,surface->output);
3265 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
3267 weston_surface_set_position(surface, shsurf->output->x - surf_x,
3268 shsurf->output->y + panel_height - surf_y);
3270 case SHELL_SURFACE_POPUP:
3271 shell_map_popup(shsurf);
3273 case SHELL_SURFACE_NONE:
3274 weston_surface_set_position(surface,
3275 surface->geometry.x + sx,
3276 surface->geometry.y + sy);
3282 /* surface stacking order, see also activate() */
3283 switch (surface_type) {
3284 case SHELL_SURFACE_POPUP:
3285 case SHELL_SURFACE_TRANSIENT:
3286 parent = shsurf->parent;
3287 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
3289 case SHELL_SURFACE_FULLSCREEN:
3290 case SHELL_SURFACE_NONE:
3293 ws = get_current_workspace(shell);
3294 wl_list_insert(&ws->layer.surface_list, &surface->layer_link);
3298 if (surface_type != SHELL_SURFACE_NONE) {
3299 weston_surface_update_transform(surface);
3300 if (surface_type == SHELL_SURFACE_MAXIMIZED)
3301 surface->output = shsurf->output;
3304 switch (surface_type) {
3305 case SHELL_SURFACE_TRANSIENT:
3306 if (shsurf->transient.flags ==
3307 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
3309 case SHELL_SURFACE_TOPLEVEL:
3310 case SHELL_SURFACE_FULLSCREEN:
3311 case SHELL_SURFACE_MAXIMIZED:
3312 if (!shell->locked) {
3313 wl_list_for_each(seat, &compositor->seat_list, link)
3314 activate(shell, surface, seat);
3321 if (surface_type == SHELL_SURFACE_TOPLEVEL)
3323 switch (shell->win_animation_type) {
3324 case ANIMATION_FADE:
3325 weston_fade_run(surface, 0.0, 1.0, 200.0, NULL, NULL);
3327 case ANIMATION_ZOOM:
3328 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
3337 configure(struct desktop_shell *shell, struct weston_surface *surface,
3338 float x, float y, int32_t width, int32_t height)
3340 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
3341 struct shell_surface *shsurf;
3342 int32_t surf_x, surf_y;
3344 shsurf = get_shell_surface(surface);
3346 surface_type = shsurf->type;
3348 weston_surface_configure(surface, x, y, width, height);
3350 switch (surface_type) {
3351 case SHELL_SURFACE_FULLSCREEN:
3352 shell_stack_fullscreen(shsurf);
3353 shell_configure_fullscreen(shsurf);
3355 case SHELL_SURFACE_MAXIMIZED:
3356 /* setting x, y and using configure to change that geometry */
3357 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
3359 surface->geometry.x = surface->output->x - surf_x;
3360 surface->geometry.y = surface->output->y +
3361 get_output_panel_height(shell,surface->output) - surf_y;
3363 case SHELL_SURFACE_TOPLEVEL:
3369 /* XXX: would a fullscreen surface need the same handling? */
3370 if (surface->output) {
3371 weston_surface_update_transform(surface);
3373 if (surface_type == SHELL_SURFACE_MAXIMIZED)
3374 surface->output = shsurf->output;
3379 shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
3381 struct shell_surface *shsurf = get_shell_surface(es);
3382 struct desktop_shell *shell = shsurf->shell;
3384 int type_changed = 0;
3386 if (!weston_surface_is_mapped(es) && !wl_list_empty(&shsurf->popup.grab_link)) {
3387 remove_popup_grab(shsurf);
3393 if (shsurf->next_type != SHELL_SURFACE_NONE &&
3394 shsurf->type != shsurf->next_type) {
3395 set_surface_type(shsurf);
3399 if (!weston_surface_is_mapped(es)) {
3400 map(shell, es, width, height, sx, sy);
3401 } else if (type_changed || sx != 0 || sy != 0 ||
3402 es->geometry.width != width ||
3403 es->geometry.height != height) {
3404 float from_x, from_y;
3407 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
3408 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
3409 configure(shell, es,
3410 es->geometry.x + to_x - from_x,
3411 es->geometry.y + to_y - from_y,
3416 static void launch_desktop_shell_process(void *data);
3419 desktop_shell_sigchld(struct weston_process *process, int status)
3422 struct desktop_shell *shell =
3423 container_of(process, struct desktop_shell, child.process);
3425 shell->child.process.pid = 0;
3426 shell->child.client = NULL; /* already destroyed by wayland */
3428 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
3429 time = weston_compositor_get_time();
3430 if (time - shell->child.deathstamp > 30000) {
3431 shell->child.deathstamp = time;
3432 shell->child.deathcount = 0;
3435 shell->child.deathcount++;
3436 if (shell->child.deathcount > 5) {
3437 weston_log("weston-desktop-shell died, giving up.\n");
3441 weston_log("weston-desktop-shell died, respawning...\n");
3442 launch_desktop_shell_process(shell);
3446 launch_desktop_shell_process(void *data)
3448 struct desktop_shell *shell = data;
3449 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
3451 shell->child.client = weston_client_launch(shell->compositor,
3452 &shell->child.process,
3454 desktop_shell_sigchld);
3456 if (!shell->child.client)
3457 weston_log("not able to start %s\n", shell_exe);
3461 bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
3463 struct desktop_shell *shell = data;
3465 wl_client_add_object(client, &wl_shell_interface,
3466 &shell_implementation, id, shell);
3470 unbind_desktop_shell(struct wl_resource *resource)
3472 struct desktop_shell *shell = resource->data;
3475 resume_desktop(shell);
3477 shell->child.desktop_shell = NULL;
3478 shell->prepare_event_sent = false;
3483 bind_desktop_shell(struct wl_client *client,
3484 void *data, uint32_t version, uint32_t id)
3486 struct desktop_shell *shell = data;
3487 struct wl_resource *resource;
3489 resource = wl_client_add_object(client, &desktop_shell_interface,
3490 &desktop_shell_implementation,
3493 if (client == shell->child.client) {
3494 resource->destroy = unbind_desktop_shell;
3495 shell->child.desktop_shell = resource;
3499 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
3500 "permission to bind desktop_shell denied");
3501 wl_resource_destroy(resource);
3505 screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
3507 struct desktop_shell *shell = surface->configure_private;
3512 /* XXX: starting weston-screensaver beforehand does not work */
3516 center_on_output(surface, surface->output);
3518 if (wl_list_empty(&surface->layer_link)) {
3519 wl_list_insert(shell->lock_layer.surface_list.prev,
3520 &surface->layer_link);
3521 weston_surface_update_transform(surface);
3522 wl_event_source_timer_update(shell->screensaver.timer,
3523 shell->screensaver.duration);
3524 shell_fade(shell, FADE_IN);
3529 screensaver_set_surface(struct wl_client *client,
3530 struct wl_resource *resource,
3531 struct wl_resource *surface_resource,
3532 struct wl_resource *output_resource)
3534 struct desktop_shell *shell = resource->data;
3535 struct weston_surface *surface = surface_resource->data;
3536 struct weston_output *output = output_resource->data;
3538 surface->configure = screensaver_configure;
3539 surface->configure_private = shell;
3540 surface->output = output;
3543 static const struct screensaver_interface screensaver_implementation = {
3544 screensaver_set_surface
3548 unbind_screensaver(struct wl_resource *resource)
3550 struct desktop_shell *shell = resource->data;
3552 shell->screensaver.binding = NULL;
3557 bind_screensaver(struct wl_client *client,
3558 void *data, uint32_t version, uint32_t id)
3560 struct desktop_shell *shell = data;
3561 struct wl_resource *resource;
3563 resource = wl_client_add_object(client, &screensaver_interface,
3564 &screensaver_implementation,
3567 if (shell->screensaver.binding == NULL) {
3568 resource->destroy = unbind_screensaver;
3569 shell->screensaver.binding = resource;
3573 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
3574 "interface object already bound");
3575 wl_resource_destroy(resource);
3579 input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
3581 struct input_panel_surface *ip_surface = surface->configure_private;
3582 struct desktop_shell *shell = ip_surface->shell;
3583 struct weston_mode *mode;
3585 uint32_t show_surface = 0;
3590 if (!weston_surface_is_mapped(surface)) {
3591 if (!shell->showing_input_panels)
3597 fprintf(stderr, "%s panel: %d, output: %p\n", __FUNCTION__, ip_surface->panel, ip_surface->output);
3599 if (ip_surface->panel) {
3600 x = shell->text_input.surface->geometry.x + shell->text_input.cursor_rectangle.x2;
3601 y = shell->text_input.surface->geometry.y + shell->text_input.cursor_rectangle.y2;
3603 mode = ip_surface->output->current;
3605 x = ip_surface->output->x + (mode->width - width) / 2;
3606 y = ip_surface->output->y + mode->height - height;
3609 weston_surface_configure(surface,
3614 wl_list_insert(&shell->input_panel_layer.surface_list,
3615 &surface->layer_link);
3616 weston_surface_update_transform(surface);
3617 weston_surface_damage(surface);
3618 weston_slide_run(surface, surface->geometry.height, 0, NULL, NULL);
3623 destroy_input_panel_surface(struct input_panel_surface *input_panel_surface)
3625 wl_list_remove(&input_panel_surface->surface_destroy_listener.link);
3626 wl_list_remove(&input_panel_surface->link);
3628 input_panel_surface->surface->configure = NULL;
3630 free(input_panel_surface);
3633 static struct input_panel_surface *
3634 get_input_panel_surface(struct weston_surface *surface)
3636 if (surface->configure == input_panel_configure) {
3637 return surface->configure_private;
3644 input_panel_handle_surface_destroy(struct wl_listener *listener, void *data)
3646 struct input_panel_surface *ipsurface = container_of(listener,
3647 struct input_panel_surface,
3648 surface_destroy_listener);
3650 if (ipsurface->resource.client) {
3651 wl_resource_destroy(&ipsurface->resource);
3653 wl_signal_emit(&ipsurface->resource.destroy_signal,
3654 &ipsurface->resource);
3655 destroy_input_panel_surface(ipsurface);
3658 static struct input_panel_surface *
3659 create_input_panel_surface(struct desktop_shell *shell,
3660 struct weston_surface *surface)
3662 struct input_panel_surface *input_panel_surface;
3664 input_panel_surface = calloc(1, sizeof *input_panel_surface);
3665 if (!input_panel_surface)
3668 surface->configure = input_panel_configure;
3669 surface->configure_private = input_panel_surface;
3671 input_panel_surface->shell = shell;
3673 input_panel_surface->surface = surface;
3675 wl_signal_init(&input_panel_surface->resource.destroy_signal);
3676 input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy;
3677 wl_signal_add(&surface->resource.destroy_signal,
3678 &input_panel_surface->surface_destroy_listener);
3680 wl_list_init(&input_panel_surface->link);
3682 return input_panel_surface;
3686 input_panel_surface_set_toplevel(struct wl_client *client,
3687 struct wl_resource *resource,
3688 struct wl_resource *output_resource,
3691 struct input_panel_surface *input_panel_surface = resource->data;
3692 struct desktop_shell *shell = input_panel_surface->shell;
3694 wl_list_insert(&shell->input_panel.surfaces,
3695 &input_panel_surface->link);
3697 input_panel_surface->output = output_resource->data;
3698 input_panel_surface->panel = 0;
3700 fprintf(stderr, "%s panel: %d, output: %p\n", __FUNCTION__,
3701 input_panel_surface->panel,
3702 input_panel_surface->output);
3706 input_panel_surface_set_overlay_panel(struct wl_client *client,
3707 struct wl_resource *resource)
3709 struct input_panel_surface *input_panel_surface = resource->data;
3710 struct desktop_shell *shell = input_panel_surface->shell;
3712 wl_list_insert(&shell->input_panel.surfaces,
3713 &input_panel_surface->link);
3715 input_panel_surface->panel = 1;
3718 static const struct wl_input_panel_surface_interface input_panel_surface_implementation = {
3719 input_panel_surface_set_toplevel,
3720 input_panel_surface_set_overlay_panel
3724 destroy_input_panel_surface_resource(struct wl_resource *resource)
3726 struct input_panel_surface *ipsurf = resource->data;
3728 destroy_input_panel_surface(ipsurf);
3732 input_panel_get_input_panel_surface(struct wl_client *client,
3733 struct wl_resource *resource,
3735 struct wl_resource *surface_resource)
3737 struct weston_surface *surface = surface_resource->data;
3738 struct desktop_shell *shell = resource->data;
3739 struct input_panel_surface *ipsurf;
3741 if (get_input_panel_surface(surface)) {
3742 wl_resource_post_error(surface_resource,
3743 WL_DISPLAY_ERROR_INVALID_OBJECT,
3744 "wl_input_panel::get_input_panel_surface already requested");
3748 ipsurf = create_input_panel_surface(shell, surface);
3750 wl_resource_post_error(surface_resource,
3751 WL_DISPLAY_ERROR_INVALID_OBJECT,
3752 "surface->configure already set");
3756 ipsurf->resource.destroy = destroy_input_panel_surface_resource;
3757 ipsurf->resource.object.id = id;
3758 ipsurf->resource.object.interface = &wl_input_panel_surface_interface;
3759 ipsurf->resource.object.implementation =
3760 (void (**)(void)) &input_panel_surface_implementation;
3761 ipsurf->resource.data = ipsurf;
3763 wl_client_add_resource(client, &ipsurf->resource);
3766 static const struct wl_input_panel_interface input_panel_implementation = {
3767 input_panel_get_input_panel_surface
3771 unbind_input_panel(struct wl_resource *resource)
3773 struct desktop_shell *shell = resource->data;
3775 shell->input_panel.binding = NULL;
3780 bind_input_panel(struct wl_client *client,
3781 void *data, uint32_t version, uint32_t id)
3783 struct desktop_shell *shell = data;
3784 struct wl_resource *resource;
3786 resource = wl_client_add_object(client, &wl_input_panel_interface,
3787 &input_panel_implementation,
3790 if (shell->input_panel.binding == NULL) {
3791 resource->destroy = unbind_input_panel;
3792 shell->input_panel.binding = resource;
3796 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
3797 "interface object already bound");
3798 wl_resource_destroy(resource);
3802 struct desktop_shell *shell;
3803 struct weston_surface *current;
3804 struct wl_listener listener;
3805 struct weston_keyboard_grab grab;
3809 switcher_next(struct switcher *switcher)
3811 struct weston_surface *surface;
3812 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
3813 struct shell_surface *shsurf;
3814 struct workspace *ws = get_current_workspace(switcher->shell);
3816 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
3817 switch (get_shell_surface_type(surface)) {
3818 case SHELL_SURFACE_TOPLEVEL:
3819 case SHELL_SURFACE_FULLSCREEN:
3820 case SHELL_SURFACE_MAXIMIZED:
3823 if (prev == switcher->current)
3826 surface->alpha = 0.25;
3827 weston_surface_geometry_dirty(surface);
3828 weston_surface_damage(surface);
3834 if (is_black_surface(surface, NULL)) {
3835 surface->alpha = 0.25;
3836 weston_surface_geometry_dirty(surface);
3837 weston_surface_damage(surface);
3847 wl_list_remove(&switcher->listener.link);
3848 wl_signal_add(&next->resource.destroy_signal, &switcher->listener);
3850 switcher->current = next;
3853 shsurf = get_shell_surface(switcher->current);
3854 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
3855 shsurf->fullscreen.black_surface->alpha = 1.0;
3859 switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
3861 struct switcher *switcher =
3862 container_of(listener, struct switcher, listener);
3864 switcher_next(switcher);
3868 switcher_destroy(struct switcher *switcher)
3870 struct weston_surface *surface;
3871 struct weston_keyboard *keyboard = switcher->grab.keyboard;
3872 struct workspace *ws = get_current_workspace(switcher->shell);
3874 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
3875 surface->alpha = 1.0;
3876 weston_surface_damage(surface);
3879 if (switcher->current)
3880 activate(switcher->shell, switcher->current,
3881 (struct weston_seat *) keyboard->seat);
3882 wl_list_remove(&switcher->listener.link);
3883 weston_keyboard_end_grab(keyboard);
3884 if (keyboard->input_method_resource)
3885 keyboard->grab = &keyboard->input_method_grab;
3890 switcher_key(struct weston_keyboard_grab *grab,
3891 uint32_t time, uint32_t key, uint32_t state_w)
3893 struct switcher *switcher = container_of(grab, struct switcher, grab);
3894 enum wl_keyboard_key_state state = state_w;
3896 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
3897 switcher_next(switcher);
3901 switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
3902 uint32_t mods_depressed, uint32_t mods_latched,
3903 uint32_t mods_locked, uint32_t group)
3905 struct switcher *switcher = container_of(grab, struct switcher, grab);
3906 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
3908 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0)
3909 switcher_destroy(switcher);
3912 static const struct weston_keyboard_grab_interface switcher_grab = {
3918 switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
3921 struct desktop_shell *shell = data;
3922 struct switcher *switcher;
3924 switcher = malloc(sizeof *switcher);
3925 switcher->shell = shell;
3926 switcher->current = NULL;
3927 switcher->listener.notify = switcher_handle_surface_destroy;
3928 wl_list_init(&switcher->listener.link);
3930 lower_fullscreen_layer(switcher->shell);
3931 switcher->grab.interface = &switcher_grab;
3932 weston_keyboard_start_grab(seat->keyboard, &switcher->grab);
3933 weston_keyboard_set_focus(seat->keyboard, NULL);
3934 switcher_next(switcher);
3938 backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
3941 struct weston_compositor *compositor = data;
3942 struct weston_output *output;
3943 long backlight_new = 0;
3945 /* TODO: we're limiting to simple use cases, where we assume just
3946 * control on the primary display. We'd have to extend later if we
3947 * ever get support for setting backlights on random desktop LCD
3949 output = get_default_output(compositor);
3953 if (!output->set_backlight)
3956 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
3957 backlight_new = output->backlight_current - 25;
3958 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
3959 backlight_new = output->backlight_current + 25;
3961 if (backlight_new < 5)
3963 if (backlight_new > 255)
3964 backlight_new = 255;
3966 output->backlight_current = backlight_new;
3967 output->set_backlight(output, output->backlight_current);
3970 struct debug_binding_grab {
3971 struct weston_keyboard_grab grab;
3972 struct weston_seat *seat;
3974 int key_released[2];
3978 debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
3979 uint32_t key, uint32_t state)
3981 struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
3982 struct wl_resource *resource;
3983 struct wl_display *display;
3985 int send = 0, terminate = 0;
3986 int check_binding = 1;
3989 if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
3990 /* Do not run bindings on key releases */
3993 for (i = 0; i < 2; i++)
3994 if (key == db->key[i])
3995 db->key_released[i] = 1;
3997 if (db->key_released[0] && db->key_released[1]) {
3998 /* All key releases been swalled so end the grab */
4000 } else if (key != db->key[0] && key != db->key[1]) {
4001 /* Should not swallow release of other keys */
4004 } else if (key == db->key[0] && !db->key_released[0]) {
4005 /* Do not check bindings for the first press of the binding
4006 * key. This allows it to be used as a debug shortcut.
4007 * We still need to swallow this event. */
4009 } else if (db->key[1]) {
4010 /* If we already ran a binding don't process another one since
4011 * we can't keep track of all the binding keys that were
4012 * pressed in order to swallow the release events. */
4017 if (check_binding) {
4018 struct weston_compositor *ec = db->seat->compositor;
4020 if (weston_compositor_run_debug_binding(ec, db->seat, time,
4022 /* We ran a binding so swallow the press and keep the
4023 * grab to swallow the released too. */
4028 /* Terminate the grab since the key pressed is not a
4029 * debug binding key. */
4036 resource = grab->keyboard->focus_resource;
4039 display = wl_client_get_display(resource->client);
4040 serial = wl_display_next_serial(display);
4041 wl_keyboard_send_key(resource, serial, time, key, state);
4046 weston_keyboard_end_grab(grab->keyboard);
4047 if (grab->keyboard->input_method_resource)
4048 grab->keyboard->grab = &grab->keyboard->input_method_grab;
4054 debug_binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial,
4055 uint32_t mods_depressed, uint32_t mods_latched,
4056 uint32_t mods_locked, uint32_t group)
4058 struct wl_resource *resource;
4060 resource = grab->keyboard->focus_resource;
4064 wl_keyboard_send_modifiers(resource, serial, mods_depressed,
4065 mods_latched, mods_locked, group);
4068 struct weston_keyboard_grab_interface debug_binding_keyboard_grab = {
4070 debug_binding_modifiers
4074 debug_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
4076 struct debug_binding_grab *grab;
4078 grab = calloc(1, sizeof *grab);
4082 grab->seat = (struct weston_seat *) seat;
4084 grab->grab.interface = &debug_binding_keyboard_grab;
4085 weston_keyboard_start_grab(seat->keyboard, &grab->grab);
4089 force_kill_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
4092 struct weston_surface *focus_surface;
4093 struct wl_client *client;
4094 struct desktop_shell *shell = data;
4095 struct weston_compositor *compositor = shell->compositor;
4098 focus_surface = seat->keyboard->focus;
4102 wl_signal_emit(&compositor->kill_signal, focus_surface);
4104 client = focus_surface->resource.client;
4105 wl_client_get_credentials(client, &pid, NULL, NULL);
4107 /* Skip clients that we launched ourselves (the credentials of
4108 * the socketpair is ours) */
4109 if (pid == getpid())
4116 workspace_up_binding(struct weston_seat *seat, uint32_t time,
4117 uint32_t key, void *data)
4119 struct desktop_shell *shell = data;
4120 unsigned int new_index = shell->workspaces.current;
4127 change_workspace(shell, new_index);
4131 workspace_down_binding(struct weston_seat *seat, uint32_t time,
4132 uint32_t key, void *data)
4134 struct desktop_shell *shell = data;
4135 unsigned int new_index = shell->workspaces.current;
4139 if (new_index < shell->workspaces.num - 1)
4142 change_workspace(shell, new_index);
4146 workspace_f_binding(struct weston_seat *seat, uint32_t time,
4147 uint32_t key, void *data)
4149 struct desktop_shell *shell = data;
4150 unsigned int new_index;
4154 new_index = key - KEY_F1;
4155 if (new_index >= shell->workspaces.num)
4156 new_index = shell->workspaces.num - 1;
4158 change_workspace(shell, new_index);
4162 workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time,
4163 uint32_t key, void *data)
4165 struct desktop_shell *shell = data;
4166 unsigned int new_index = shell->workspaces.current;
4174 take_surface_to_workspace_by_seat(shell, seat, new_index);
4178 workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time,
4179 uint32_t key, void *data)
4181 struct desktop_shell *shell = data;
4182 unsigned int new_index = shell->workspaces.current;
4187 if (new_index < shell->workspaces.num - 1)
4190 take_surface_to_workspace_by_seat(shell, seat, new_index);
4194 shell_destroy(struct wl_listener *listener, void *data)
4196 struct desktop_shell *shell =
4197 container_of(listener, struct desktop_shell, destroy_listener);
4198 struct workspace **ws;
4200 if (shell->child.client)
4201 wl_client_destroy(shell->child.client);
4203 wl_list_remove(&shell->idle_listener.link);
4204 wl_list_remove(&shell->wake_listener.link);
4205 wl_list_remove(&shell->show_input_panel_listener.link);
4206 wl_list_remove(&shell->hide_input_panel_listener.link);
4208 wl_array_for_each(ws, &shell->workspaces.array)
4209 workspace_destroy(*ws);
4210 wl_array_release(&shell->workspaces.array);
4212 free(shell->screensaver.path);
4217 shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
4220 int i, num_workspace_bindings;
4222 /* fixed bindings */
4223 weston_compositor_add_key_binding(ec, KEY_BACKSPACE,
4224 MODIFIER_CTRL | MODIFIER_ALT,
4225 terminate_binding, ec);
4226 weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
4227 click_to_activate_binding,
4229 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
4230 MODIFIER_SUPER | MODIFIER_ALT,
4231 surface_opacity_binding, NULL);
4232 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
4233 MODIFIER_SUPER, zoom_axis_binding,
4236 /* configurable bindings */
4237 mod = shell->binding_modifier;
4238 weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod,
4239 zoom_key_binding, NULL);
4240 weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod,
4241 zoom_key_binding, NULL);
4242 weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding,
4244 weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod,
4245 resize_binding, shell);
4246 weston_compositor_add_button_binding(ec, BTN_RIGHT, mod,
4247 rotate_binding, NULL);
4248 weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding,
4250 weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding,
4252 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0,
4253 backlight_binding, ec);
4254 weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding,
4256 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0,
4257 backlight_binding, ec);
4258 weston_compositor_add_key_binding(ec, KEY_K, mod,
4259 force_kill_binding, shell);
4260 weston_compositor_add_key_binding(ec, KEY_UP, mod,
4261 workspace_up_binding, shell);
4262 weston_compositor_add_key_binding(ec, KEY_DOWN, mod,
4263 workspace_down_binding, shell);
4264 weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT,
4265 workspace_move_surface_up_binding,
4267 weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT,
4268 workspace_move_surface_down_binding,
4271 /* Add bindings for mod+F[1-6] for workspace 1 to 6. */
4272 if (shell->workspaces.num > 1) {
4273 num_workspace_bindings = shell->workspaces.num;
4274 if (num_workspace_bindings > 6)
4275 num_workspace_bindings = 6;
4276 for (i = 0; i < num_workspace_bindings; i++)
4277 weston_compositor_add_key_binding(ec, KEY_F1 + i, mod,
4278 workspace_f_binding,
4282 /* Debug bindings */
4283 weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT,
4284 debug_binding, shell);
4288 module_init(struct weston_compositor *ec,
4289 int *argc, char *argv[], const char *config_file)
4291 struct weston_seat *seat;
4292 struct desktop_shell *shell;
4293 struct workspace **pws;
4295 struct wl_event_loop *loop;
4297 shell = malloc(sizeof *shell);
4301 memset(shell, 0, sizeof *shell);
4302 shell->compositor = ec;
4304 shell->destroy_listener.notify = shell_destroy;
4305 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
4306 shell->idle_listener.notify = idle_handler;
4307 wl_signal_add(&ec->idle_signal, &shell->idle_listener);
4308 shell->wake_listener.notify = wake_handler;
4309 wl_signal_add(&ec->wake_signal, &shell->wake_listener);
4310 shell->show_input_panel_listener.notify = show_input_panels;
4311 wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener);
4312 shell->hide_input_panel_listener.notify = hide_input_panels;
4313 wl_signal_add(&ec->hide_input_panel_signal, &shell->hide_input_panel_listener);
4314 shell->update_input_panel_listener.notify = update_input_panels;
4315 wl_signal_add(&ec->update_input_panel_signal, &shell->update_input_panel_listener);
4316 ec->ping_handler = ping_handler;
4317 ec->shell_interface.shell = shell;
4318 ec->shell_interface.create_shell_surface = create_shell_surface;
4319 ec->shell_interface.set_toplevel = set_toplevel;
4320 ec->shell_interface.set_transient = set_transient;
4321 ec->shell_interface.set_fullscreen = set_fullscreen;
4322 ec->shell_interface.move = surface_move;
4323 ec->shell_interface.resize = surface_resize;
4325 wl_list_init(&shell->input_panel.surfaces);
4327 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
4328 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
4329 weston_layer_init(&shell->background_layer, &shell->panel_layer.link);
4330 weston_layer_init(&shell->lock_layer, NULL);
4331 weston_layer_init(&shell->input_panel_layer, NULL);
4333 wl_array_init(&shell->workspaces.array);
4334 wl_list_init(&shell->workspaces.client_list);
4336 shell_configuration(shell, config_file);
4338 for (i = 0; i < shell->workspaces.num; i++) {
4339 pws = wl_array_add(&shell->workspaces.array, sizeof *pws);
4343 *pws = workspace_create();
4347 activate_workspace(shell, 0);
4349 wl_list_init(&shell->workspaces.anim_sticky_list);
4350 wl_list_init(&shell->workspaces.animation.link);
4351 shell->workspaces.animation.frame = animate_workspace_change_frame;
4353 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
4354 shell, bind_shell) == NULL)
4357 if (wl_display_add_global(ec->wl_display,
4358 &desktop_shell_interface,
4359 shell, bind_desktop_shell) == NULL)
4362 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
4363 shell, bind_screensaver) == NULL)
4366 if (wl_display_add_global(ec->wl_display, &wl_input_panel_interface,
4367 shell, bind_input_panel) == NULL)
4370 if (wl_display_add_global(ec->wl_display, &workspace_manager_interface,
4371 shell, bind_workspace_manager) == NULL)
4374 shell->child.deathstamp = weston_compositor_get_time();
4376 loop = wl_display_get_event_loop(ec->wl_display);
4377 wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell);
4379 shell->screensaver.timer =
4380 wl_event_loop_add_timer(loop, screensaver_timeout, shell);
4382 wl_list_for_each(seat, &ec->seat_list, link)
4383 create_pointer_focus_listener(seat);
4385 shell_add_bindings(ec, shell);
4387 shell_fade(shell, FADE_IN);