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;
159 struct wl_event_source *startup_timer;
162 uint32_t binding_modifier;
163 enum animation_type win_animation_type;
166 enum shell_surface_type {
168 SHELL_SURFACE_TOPLEVEL,
169 SHELL_SURFACE_TRANSIENT,
170 SHELL_SURFACE_FULLSCREEN,
171 SHELL_SURFACE_MAXIMIZED,
176 struct wl_event_source *source;
180 struct shell_surface {
181 struct wl_resource resource;
183 struct weston_surface *surface;
184 struct wl_listener surface_destroy_listener;
185 struct weston_surface *parent;
186 struct desktop_shell *shell;
188 enum shell_surface_type type, next_type;
190 int32_t saved_x, saved_y;
191 bool saved_position_valid;
192 bool saved_rotation_valid;
196 struct weston_transform transform;
197 struct weston_matrix rotation;
201 struct wl_list grab_link;
203 struct shell_seat *shseat;
213 enum wl_shell_surface_fullscreen_method type;
214 struct weston_transform transform; /* matrix from x, y */
216 struct weston_surface *black_surface;
219 struct ping_timer *ping_timer;
221 struct weston_transform workspace_transform;
223 struct weston_output *fullscreen_output;
224 struct weston_output *output;
227 const struct weston_shell_client *client;
231 struct weston_pointer_grab grab;
232 struct shell_surface *shsurf;
233 struct wl_listener shsurf_destroy_listener;
234 struct weston_pointer *pointer;
237 struct weston_move_grab {
238 struct shell_grab base;
243 struct shell_grab base;
244 struct weston_matrix rotation;
252 struct weston_seat *seat;
253 struct wl_listener seat_destroy_listener;
256 struct weston_pointer_grab grab;
257 struct wl_list surfaces_list;
258 struct wl_client *client;
264 activate(struct desktop_shell *shell, struct weston_surface *es,
265 struct weston_seat *seat);
267 static struct workspace *
268 get_current_workspace(struct desktop_shell *shell);
270 static struct shell_surface *
271 get_shell_surface(struct weston_surface *surface);
273 static struct desktop_shell *
274 shell_surface_get_shell(struct shell_surface *shsurf);
277 surface_rotate(struct shell_surface *surface, struct weston_seat *seat);
280 shell_fade_startup(struct desktop_shell *shell);
283 shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
285 struct desktop_shell *shell;
286 struct weston_surface *top_fs_es;
288 shell = shell_surface_get_shell(shsurf);
290 if (wl_list_empty(&shell->fullscreen_layer.surface_list))
293 top_fs_es = container_of(shell->fullscreen_layer.surface_list.next,
294 struct weston_surface,
296 return (shsurf == get_shell_surface(top_fs_es));
300 destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
302 struct shell_grab *grab;
304 grab = container_of(listener, struct shell_grab,
305 shsurf_destroy_listener);
311 popup_grab_end(struct weston_pointer *pointer);
314 shell_grab_start(struct shell_grab *grab,
315 const struct weston_pointer_grab_interface *interface,
316 struct shell_surface *shsurf,
317 struct weston_pointer *pointer,
318 enum desktop_shell_cursor cursor)
320 struct desktop_shell *shell = shsurf->shell;
322 popup_grab_end(pointer);
324 grab->grab.interface = interface;
325 grab->shsurf = shsurf;
326 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
327 wl_signal_add(&shsurf->resource.destroy_signal,
328 &grab->shsurf_destroy_listener);
330 grab->pointer = pointer;
332 weston_pointer_start_grab(pointer, &grab->grab);
333 desktop_shell_send_grab_cursor(shell->child.desktop_shell, cursor);
334 weston_pointer_set_focus(pointer, shell->grab_surface,
335 wl_fixed_from_int(0), wl_fixed_from_int(0));
339 shell_grab_end(struct shell_grab *grab)
342 wl_list_remove(&grab->shsurf_destroy_listener.link);
344 weston_pointer_end_grab(grab->pointer);
348 center_on_output(struct weston_surface *surface,
349 struct weston_output *output);
351 static enum weston_keyboard_modifier
352 get_modifier(char *modifier)
355 return MODIFIER_SUPER;
357 if (!strcmp("ctrl", modifier))
358 return MODIFIER_CTRL;
359 else if (!strcmp("alt", modifier))
361 else if (!strcmp("super", modifier))
362 return MODIFIER_SUPER;
364 return MODIFIER_SUPER;
367 static enum animation_type
368 get_animation_type(char *animation)
371 return ANIMATION_NONE;
373 if (!strcmp("zoom", animation))
374 return ANIMATION_ZOOM;
375 else if (!strcmp("fade", animation))
376 return ANIMATION_FADE;
378 return ANIMATION_NONE;
382 shell_configuration(struct desktop_shell *shell, int config_fd)
386 unsigned int num_workspaces = DEFAULT_NUM_WORKSPACES;
387 char *modifier = NULL;
388 char *win_animation = NULL;
390 struct config_key shell_keys[] = {
391 { "binding-modifier", CONFIG_KEY_STRING, &modifier },
392 { "animation", CONFIG_KEY_STRING, &win_animation},
394 CONFIG_KEY_UNSIGNED_INTEGER, &num_workspaces },
397 struct config_key saver_keys[] = {
398 { "path", CONFIG_KEY_STRING, &path },
399 { "duration", CONFIG_KEY_INTEGER, &duration },
402 struct config_section cs[] = {
403 { "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL },
404 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
407 parse_config_file(config_fd, cs, ARRAY_LENGTH(cs), shell);
409 shell->screensaver.path = path;
410 shell->screensaver.duration = duration * 1000;
411 shell->binding_modifier = get_modifier(modifier);
412 shell->win_animation_type = get_animation_type(win_animation);
413 shell->workspaces.num = num_workspaces > 0 ? num_workspaces : 1;
417 focus_state_destroy(struct focus_state *state)
419 wl_list_remove(&state->seat_destroy_listener.link);
420 wl_list_remove(&state->surface_destroy_listener.link);
425 focus_state_seat_destroy(struct wl_listener *listener, void *data)
427 struct focus_state *state = container_of(listener,
429 seat_destroy_listener);
431 wl_list_remove(&state->link);
432 focus_state_destroy(state);
436 focus_state_surface_destroy(struct wl_listener *listener, void *data)
438 struct focus_state *state = container_of(listener,
440 surface_destroy_listener);
441 struct desktop_shell *shell;
442 struct weston_surface *main_surface;
443 struct weston_surface *surface, *next;
445 main_surface = weston_surface_get_main_surface(state->keyboard_focus);
448 wl_list_for_each(surface, &state->ws->layer.surface_list, layer_link) {
449 if (surface == main_surface)
456 /* if the focus was a sub-surface, activate its main surface */
457 if (main_surface != state->keyboard_focus)
461 shell = state->seat->compositor->shell_interface.shell;
462 activate(shell, next, state->seat);
464 wl_list_remove(&state->link);
465 focus_state_destroy(state);
469 static struct focus_state *
470 focus_state_create(struct weston_seat *seat, struct workspace *ws)
472 struct focus_state *state;
474 state = malloc(sizeof *state);
480 wl_list_insert(&ws->focus_list, &state->link);
482 state->seat_destroy_listener.notify = focus_state_seat_destroy;
483 state->surface_destroy_listener.notify = focus_state_surface_destroy;
484 wl_signal_add(&seat->destroy_signal,
485 &state->seat_destroy_listener);
486 wl_list_init(&state->surface_destroy_listener.link);
491 static struct focus_state *
492 ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat)
494 struct workspace *ws = get_current_workspace(shell);
495 struct focus_state *state;
497 wl_list_for_each(state, &ws->focus_list, link)
498 if (state->seat == seat)
501 if (&state->link == &ws->focus_list)
502 state = focus_state_create(seat, ws);
508 restore_focus_state(struct desktop_shell *shell, struct workspace *ws)
510 struct focus_state *state, *next;
511 struct weston_surface *surface;
513 wl_list_for_each_safe(state, next, &ws->focus_list, link) {
514 surface = state->keyboard_focus;
516 weston_keyboard_set_focus(state->seat->keyboard, surface);
521 replace_focus_state(struct desktop_shell *shell, struct workspace *ws,
522 struct weston_seat *seat)
524 struct focus_state *state;
525 struct weston_surface *surface;
527 wl_list_for_each(state, &ws->focus_list, link) {
528 if (state->seat == seat) {
529 surface = seat->keyboard->focus;
530 state->keyboard_focus =
531 (struct weston_surface *) surface;
538 drop_focus_state(struct desktop_shell *shell, struct workspace *ws,
539 struct weston_surface *surface)
541 struct focus_state *state;
543 wl_list_for_each(state, &ws->focus_list, link)
544 if (state->keyboard_focus == surface)
545 state->keyboard_focus = NULL;
549 workspace_destroy(struct workspace *ws)
551 struct focus_state *state, *next;
553 wl_list_for_each_safe(state, next, &ws->focus_list, link)
554 focus_state_destroy(state);
560 seat_destroyed(struct wl_listener *listener, void *data)
562 struct weston_seat *seat = data;
563 struct focus_state *state, *next;
564 struct workspace *ws = container_of(listener,
566 seat_destroyed_listener);
568 wl_list_for_each_safe(state, next, &ws->focus_list, link)
569 if (state->seat == seat)
570 wl_list_remove(&state->link);
573 static struct workspace *
574 workspace_create(void)
576 struct workspace *ws = malloc(sizeof *ws);
580 weston_layer_init(&ws->layer, NULL);
582 wl_list_init(&ws->focus_list);
583 wl_list_init(&ws->seat_destroyed_listener.link);
584 ws->seat_destroyed_listener.notify = seat_destroyed;
590 workspace_is_empty(struct workspace *ws)
592 return wl_list_empty(&ws->layer.surface_list);
595 static struct workspace *
596 get_workspace(struct desktop_shell *shell, unsigned int index)
598 struct workspace **pws = shell->workspaces.array.data;
599 assert(index < shell->workspaces.num);
604 static struct workspace *
605 get_current_workspace(struct desktop_shell *shell)
607 return get_workspace(shell, shell->workspaces.current);
611 activate_workspace(struct desktop_shell *shell, unsigned int index)
613 struct workspace *ws;
615 ws = get_workspace(shell, index);
616 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
618 shell->workspaces.current = index;
622 get_output_height(struct weston_output *output)
624 return abs(output->region.extents.y1 - output->region.extents.y2);
628 surface_translate(struct weston_surface *surface, double d)
630 struct shell_surface *shsurf = get_shell_surface(surface);
631 struct weston_transform *transform;
633 transform = &shsurf->workspace_transform;
634 if (wl_list_empty(&transform->link))
635 wl_list_insert(surface->geometry.transformation_list.prev,
636 &shsurf->workspace_transform.link);
638 weston_matrix_init(&shsurf->workspace_transform.matrix);
639 weston_matrix_translate(&shsurf->workspace_transform.matrix,
641 weston_surface_geometry_dirty(surface);
645 workspace_translate_out(struct workspace *ws, double fraction)
647 struct weston_surface *surface;
651 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
652 height = get_output_height(surface->output);
653 d = height * fraction;
655 surface_translate(surface, d);
660 workspace_translate_in(struct workspace *ws, double fraction)
662 struct weston_surface *surface;
666 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
667 height = get_output_height(surface->output);
670 d = -(height - height * fraction);
672 d = height + height * fraction;
674 surface_translate(surface, d);
679 broadcast_current_workspace_state(struct desktop_shell *shell)
681 struct wl_resource *resource;
683 wl_list_for_each(resource, &shell->workspaces.client_list, link)
684 workspace_manager_send_state(resource,
685 shell->workspaces.current,
686 shell->workspaces.num);
690 reverse_workspace_change_animation(struct desktop_shell *shell,
692 struct workspace *from,
693 struct workspace *to)
695 shell->workspaces.current = index;
697 shell->workspaces.anim_to = to;
698 shell->workspaces.anim_from = from;
699 shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir;
700 shell->workspaces.anim_timestamp = 0;
702 weston_compositor_schedule_repaint(shell->compositor);
706 workspace_deactivate_transforms(struct workspace *ws)
708 struct weston_surface *surface;
709 struct shell_surface *shsurf;
711 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
712 shsurf = get_shell_surface(surface);
713 if (!wl_list_empty(&shsurf->workspace_transform.link)) {
714 wl_list_remove(&shsurf->workspace_transform.link);
715 wl_list_init(&shsurf->workspace_transform.link);
717 weston_surface_geometry_dirty(surface);
722 finish_workspace_change_animation(struct desktop_shell *shell,
723 struct workspace *from,
724 struct workspace *to)
726 weston_compositor_schedule_repaint(shell->compositor);
728 wl_list_remove(&shell->workspaces.animation.link);
729 workspace_deactivate_transforms(from);
730 workspace_deactivate_transforms(to);
731 shell->workspaces.anim_to = NULL;
733 wl_list_remove(&shell->workspaces.anim_from->layer.link);
737 animate_workspace_change_frame(struct weston_animation *animation,
738 struct weston_output *output, uint32_t msecs)
740 struct desktop_shell *shell =
741 container_of(animation, struct desktop_shell,
742 workspaces.animation);
743 struct workspace *from = shell->workspaces.anim_from;
744 struct workspace *to = shell->workspaces.anim_to;
748 if (workspace_is_empty(from) && workspace_is_empty(to)) {
749 finish_workspace_change_animation(shell, from, to);
753 if (shell->workspaces.anim_timestamp == 0) {
754 if (shell->workspaces.anim_current == 0.0)
755 shell->workspaces.anim_timestamp = msecs;
757 shell->workspaces.anim_timestamp =
759 /* Invers of movement function 'y' below. */
760 (asin(1.0 - shell->workspaces.anim_current) *
761 DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH *
765 t = msecs - shell->workspaces.anim_timestamp;
771 x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2;
774 if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) {
775 weston_compositor_schedule_repaint(shell->compositor);
777 workspace_translate_out(from, shell->workspaces.anim_dir * y);
778 workspace_translate_in(to, shell->workspaces.anim_dir * y);
779 shell->workspaces.anim_current = y;
781 weston_compositor_schedule_repaint(shell->compositor);
784 finish_workspace_change_animation(shell, from, to);
788 animate_workspace_change(struct desktop_shell *shell,
790 struct workspace *from,
791 struct workspace *to)
793 struct weston_output *output;
797 if (index > shell->workspaces.current)
802 shell->workspaces.current = index;
804 shell->workspaces.anim_dir = dir;
805 shell->workspaces.anim_from = from;
806 shell->workspaces.anim_to = to;
807 shell->workspaces.anim_current = 0.0;
808 shell->workspaces.anim_timestamp = 0;
810 output = container_of(shell->compositor->output_list.next,
811 struct weston_output, link);
812 wl_list_insert(&output->animation_list,
813 &shell->workspaces.animation.link);
815 wl_list_insert(from->layer.link.prev, &to->layer.link);
817 workspace_translate_in(to, 0);
819 restore_focus_state(shell, to);
821 weston_compositor_schedule_repaint(shell->compositor);
825 update_workspace(struct desktop_shell *shell, unsigned int index,
826 struct workspace *from, struct workspace *to)
828 shell->workspaces.current = index;
829 wl_list_insert(&from->layer.link, &to->layer.link);
830 wl_list_remove(&from->layer.link);
834 change_workspace(struct desktop_shell *shell, unsigned int index)
836 struct workspace *from;
837 struct workspace *to;
839 if (index == shell->workspaces.current)
842 /* Don't change workspace when there is any fullscreen surfaces. */
843 if (!wl_list_empty(&shell->fullscreen_layer.surface_list))
846 from = get_current_workspace(shell);
847 to = get_workspace(shell, index);
849 if (shell->workspaces.anim_from == to &&
850 shell->workspaces.anim_to == from) {
851 restore_focus_state(shell, to);
852 reverse_workspace_change_animation(shell, index, from, to);
853 broadcast_current_workspace_state(shell);
857 if (shell->workspaces.anim_to != NULL)
858 finish_workspace_change_animation(shell,
859 shell->workspaces.anim_from,
860 shell->workspaces.anim_to);
862 restore_focus_state(shell, to);
864 if (workspace_is_empty(to) && workspace_is_empty(from))
865 update_workspace(shell, index, from, to);
867 animate_workspace_change(shell, index, from, to);
869 broadcast_current_workspace_state(shell);
873 workspace_has_only(struct workspace *ws, struct weston_surface *surface)
875 struct wl_list *list = &ws->layer.surface_list;
878 if (wl_list_empty(list))
886 return container_of(e, struct weston_surface, layer_link) == surface;
890 move_surface_to_workspace(struct desktop_shell *shell,
891 struct weston_surface *surface,
894 struct workspace *from;
895 struct workspace *to;
896 struct weston_seat *seat;
897 struct weston_surface *focus;
899 assert(weston_surface_get_main_surface(surface) == surface);
901 if (workspace == shell->workspaces.current)
904 if (workspace >= shell->workspaces.num)
905 workspace = shell->workspaces.num - 1;
907 from = get_current_workspace(shell);
908 to = get_workspace(shell, workspace);
910 wl_list_remove(&surface->layer_link);
911 wl_list_insert(&to->layer.surface_list, &surface->layer_link);
913 drop_focus_state(shell, from, surface);
914 wl_list_for_each(seat, &shell->compositor->seat_list, link) {
918 focus = weston_surface_get_main_surface(seat->keyboard->focus);
919 if (focus == surface)
920 weston_keyboard_set_focus(seat->keyboard, NULL);
923 weston_surface_damage_below(surface);
927 take_surface_to_workspace_by_seat(struct desktop_shell *shell,
928 struct weston_seat *seat,
931 struct weston_surface *surface;
932 struct shell_surface *shsurf;
933 struct workspace *from;
934 struct workspace *to;
935 struct focus_state *state;
937 surface = weston_surface_get_main_surface(seat->keyboard->focus);
938 if (surface == NULL ||
939 index == shell->workspaces.current)
942 from = get_current_workspace(shell);
943 to = get_workspace(shell, index);
945 wl_list_remove(&surface->layer_link);
946 wl_list_insert(&to->layer.surface_list, &surface->layer_link);
948 replace_focus_state(shell, to, seat);
949 drop_focus_state(shell, from, surface);
951 if (shell->workspaces.anim_from == to &&
952 shell->workspaces.anim_to == from) {
953 wl_list_remove(&to->layer.link);
954 wl_list_insert(from->layer.link.prev, &to->layer.link);
956 reverse_workspace_change_animation(shell, index, from, to);
957 broadcast_current_workspace_state(shell);
962 if (shell->workspaces.anim_to != NULL)
963 finish_workspace_change_animation(shell,
964 shell->workspaces.anim_from,
965 shell->workspaces.anim_to);
967 if (workspace_is_empty(from) &&
968 workspace_has_only(to, surface))
969 update_workspace(shell, index, from, to);
971 shsurf = get_shell_surface(surface);
972 if (wl_list_empty(&shsurf->workspace_transform.link))
973 wl_list_insert(&shell->workspaces.anim_sticky_list,
974 &shsurf->workspace_transform.link);
976 animate_workspace_change(shell, index, from, to);
979 broadcast_current_workspace_state(shell);
981 state = ensure_focus_state(shell, seat);
983 state->keyboard_focus = surface;
987 workspace_manager_move_surface(struct wl_client *client,
988 struct wl_resource *resource,
989 struct wl_resource *surface_resource,
992 struct desktop_shell *shell = resource->data;
993 struct weston_surface *surface =
994 (struct weston_surface *) surface_resource;
995 struct weston_surface *main_surface;
997 main_surface = weston_surface_get_main_surface(surface);
998 move_surface_to_workspace(shell, main_surface, workspace);
1001 static const struct workspace_manager_interface workspace_manager_implementation = {
1002 workspace_manager_move_surface,
1006 unbind_resource(struct wl_resource *resource)
1008 wl_list_remove(&resource->link);
1013 bind_workspace_manager(struct wl_client *client,
1014 void *data, uint32_t version, uint32_t id)
1016 struct desktop_shell *shell = data;
1017 struct wl_resource *resource;
1019 resource = wl_client_add_object(client, &workspace_manager_interface,
1020 &workspace_manager_implementation,
1023 if (resource == NULL) {
1024 weston_log("couldn't add workspace manager object");
1028 resource->destroy = unbind_resource;
1029 wl_list_insert(&shell->workspaces.client_list, &resource->link);
1031 workspace_manager_send_state(resource,
1032 shell->workspaces.current,
1033 shell->workspaces.num);
1037 noop_grab_focus(struct weston_pointer_grab *grab)
1042 move_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
1044 struct weston_move_grab *move = (struct weston_move_grab *) grab;
1045 struct weston_pointer *pointer = grab->pointer;
1046 struct shell_surface *shsurf = move->base.shsurf;
1047 struct weston_surface *es;
1048 int dx = wl_fixed_to_int(pointer->x + move->dx);
1049 int dy = wl_fixed_to_int(pointer->y + move->dy);
1054 es = shsurf->surface;
1056 weston_surface_configure(es, dx, dy,
1057 es->geometry.width, es->geometry.height);
1059 weston_compositor_schedule_repaint(es->compositor);
1063 move_grab_button(struct weston_pointer_grab *grab,
1064 uint32_t time, uint32_t button, uint32_t state_w)
1066 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
1068 struct weston_pointer *pointer = grab->pointer;
1069 enum wl_pointer_button_state state = state_w;
1071 if (pointer->button_count == 0 &&
1072 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1073 shell_grab_end(shell_grab);
1078 static const struct weston_pointer_grab_interface move_grab_interface = {
1085 surface_move(struct shell_surface *shsurf, struct weston_seat *seat)
1087 struct weston_move_grab *move;
1092 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1095 move = malloc(sizeof *move);
1099 move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
1100 seat->pointer->grab_x;
1101 move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
1102 seat->pointer->grab_y;
1104 shell_grab_start(&move->base, &move_grab_interface, shsurf,
1105 seat->pointer, DESKTOP_SHELL_CURSOR_MOVE);
1111 shell_surface_move(struct wl_client *client, struct wl_resource *resource,
1112 struct wl_resource *seat_resource, uint32_t serial)
1114 struct weston_seat *seat = seat_resource->data;
1115 struct shell_surface *shsurf = resource->data;
1116 struct weston_surface *surface;
1118 surface = weston_surface_get_main_surface(seat->pointer->focus);
1119 if (seat->pointer->button_count == 0 ||
1120 seat->pointer->grab_serial != serial ||
1121 surface != shsurf->surface)
1124 if (surface_move(shsurf, seat) < 0)
1125 wl_resource_post_no_memory(resource);
1128 struct weston_resize_grab {
1129 struct shell_grab base;
1131 int32_t width, height;
1135 resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
1137 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1138 struct weston_pointer *pointer = grab->pointer;
1139 struct shell_surface *shsurf = resize->base.shsurf;
1140 int32_t width, height;
1141 wl_fixed_t from_x, from_y;
1142 wl_fixed_t to_x, to_y;
1147 weston_surface_from_global_fixed(shsurf->surface,
1148 pointer->grab_x, pointer->grab_y,
1150 weston_surface_from_global_fixed(shsurf->surface,
1151 pointer->x, pointer->y, &to_x, &to_y);
1153 width = resize->width;
1154 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
1155 width += wl_fixed_to_int(from_x - to_x);
1156 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
1157 width += wl_fixed_to_int(to_x - from_x);
1160 height = resize->height;
1161 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
1162 height += wl_fixed_to_int(from_y - to_y);
1163 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
1164 height += wl_fixed_to_int(to_y - from_y);
1167 shsurf->client->send_configure(shsurf->surface,
1168 resize->edges, width, height);
1172 send_configure(struct weston_surface *surface,
1173 uint32_t edges, int32_t width, int32_t height)
1175 struct shell_surface *shsurf = get_shell_surface(surface);
1177 wl_shell_surface_send_configure(&shsurf->resource,
1178 edges, width, height);
1181 static const struct weston_shell_client shell_client = {
1186 resize_grab_button(struct weston_pointer_grab *grab,
1187 uint32_t time, uint32_t button, uint32_t state_w)
1189 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1190 struct weston_pointer *pointer = grab->pointer;
1191 enum wl_pointer_button_state state = state_w;
1193 if (pointer->button_count == 0 &&
1194 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1195 shell_grab_end(&resize->base);
1200 static const struct weston_pointer_grab_interface resize_grab_interface = {
1207 * Returns the bounding box of a surface and all its sub-surfaces,
1208 * in the surface coordinates system. */
1210 surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x,
1211 int32_t *y, int32_t *w, int32_t *h) {
1212 pixman_region32_t region;
1213 pixman_box32_t *box;
1214 struct weston_subsurface *subsurface;
1216 pixman_region32_init_rect(®ion, 0, 0,
1217 surface->geometry.width,
1218 surface->geometry.height);
1220 wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
1221 pixman_region32_union_rect(®ion, ®ion,
1222 subsurface->position.x,
1223 subsurface->position.y,
1224 subsurface->surface->geometry.width,
1225 subsurface->surface->geometry.height);
1228 box = pixman_region32_extents(®ion);
1234 *w = box->x2 - box->x1;
1236 *h = box->y2 - box->y1;
1238 pixman_region32_fini(®ion);
1242 surface_resize(struct shell_surface *shsurf,
1243 struct weston_seat *seat, uint32_t edges)
1245 struct weston_resize_grab *resize;
1247 if (shsurf->type == SHELL_SURFACE_FULLSCREEN ||
1248 shsurf->type == SHELL_SURFACE_MAXIMIZED)
1251 if (edges == 0 || edges > 15 ||
1252 (edges & 3) == 3 || (edges & 12) == 12)
1255 resize = malloc(sizeof *resize);
1259 resize->edges = edges;
1260 surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL,
1261 &resize->width, &resize->height);
1263 shell_grab_start(&resize->base, &resize_grab_interface, shsurf,
1264 seat->pointer, edges);
1270 shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
1271 struct wl_resource *seat_resource, uint32_t serial,
1274 struct weston_seat *seat = seat_resource->data;
1275 struct shell_surface *shsurf = resource->data;
1276 struct weston_surface *surface;
1278 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1281 surface = weston_surface_get_main_surface(seat->pointer->focus);
1282 if (seat->pointer->button_count == 0 ||
1283 seat->pointer->grab_serial != serial ||
1284 surface != shsurf->surface)
1287 if (surface_resize(shsurf, seat, edges) < 0)
1288 wl_resource_post_no_memory(resource);
1292 busy_cursor_grab_focus(struct weston_pointer_grab *base)
1294 struct shell_grab *grab = (struct shell_grab *) base;
1295 struct weston_pointer *pointer = base->pointer;
1296 struct weston_surface *surface;
1299 surface = weston_compositor_pick_surface(pointer->seat->compositor,
1300 pointer->x, pointer->y,
1303 if (!grab->shsurf || grab->shsurf->surface != surface) {
1304 shell_grab_end(grab);
1310 busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
1315 busy_cursor_grab_button(struct weston_pointer_grab *base,
1316 uint32_t time, uint32_t button, uint32_t state)
1318 struct shell_grab *grab = (struct shell_grab *) base;
1319 struct shell_surface *shsurf = grab->shsurf;
1320 struct weston_seat *seat = grab->grab.pointer->seat;
1322 if (shsurf && button == BTN_LEFT && state) {
1323 activate(shsurf->shell, shsurf->surface, seat);
1324 surface_move(shsurf, seat);
1325 } else if (shsurf && button == BTN_RIGHT && state) {
1326 activate(shsurf->shell, shsurf->surface, seat);
1327 surface_rotate(shsurf, seat);
1331 static const struct weston_pointer_grab_interface busy_cursor_grab_interface = {
1332 busy_cursor_grab_focus,
1333 busy_cursor_grab_motion,
1334 busy_cursor_grab_button,
1338 set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
1340 struct shell_grab *grab;
1342 grab = malloc(sizeof *grab);
1346 shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer,
1347 DESKTOP_SHELL_CURSOR_BUSY);
1351 end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
1353 struct shell_grab *grab = (struct shell_grab *) pointer->grab;
1355 if (grab->grab.interface == &busy_cursor_grab_interface &&
1356 grab->shsurf == shsurf) {
1357 shell_grab_end(grab);
1363 ping_timer_destroy(struct shell_surface *shsurf)
1365 if (!shsurf || !shsurf->ping_timer)
1368 if (shsurf->ping_timer->source)
1369 wl_event_source_remove(shsurf->ping_timer->source);
1371 free(shsurf->ping_timer);
1372 shsurf->ping_timer = NULL;
1376 ping_timeout_handler(void *data)
1378 struct shell_surface *shsurf = data;
1379 struct weston_seat *seat;
1381 /* Client is not responding */
1382 shsurf->unresponsive = 1;
1384 wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link)
1385 if (seat->pointer->focus == shsurf->surface)
1386 set_busy_cursor(shsurf, seat->pointer);
1392 ping_handler(struct weston_surface *surface, uint32_t serial)
1394 struct shell_surface *shsurf = get_shell_surface(surface);
1395 struct wl_event_loop *loop;
1396 int ping_timeout = 200;
1400 if (!shsurf->resource.client)
1403 if (shsurf->surface == shsurf->shell->grab_surface)
1406 if (!shsurf->ping_timer) {
1407 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
1408 if (!shsurf->ping_timer)
1411 shsurf->ping_timer->serial = serial;
1412 loop = wl_display_get_event_loop(surface->compositor->wl_display);
1413 shsurf->ping_timer->source =
1414 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
1415 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
1417 wl_shell_surface_send_ping(&shsurf->resource, serial);
1422 handle_pointer_focus(struct wl_listener *listener, void *data)
1424 struct weston_pointer *pointer = data;
1425 struct weston_surface *surface =
1426 (struct weston_surface *) pointer->focus;
1427 struct weston_compositor *compositor;
1428 struct shell_surface *shsurf;
1434 compositor = surface->compositor;
1435 shsurf = get_shell_surface(surface);
1437 if (shsurf && shsurf->unresponsive) {
1438 set_busy_cursor(shsurf, pointer);
1440 serial = wl_display_next_serial(compositor->wl_display);
1441 ping_handler(surface, serial);
1446 create_pointer_focus_listener(struct weston_seat *seat)
1448 struct wl_listener *listener;
1453 listener = malloc(sizeof *listener);
1454 listener->notify = handle_pointer_focus;
1455 wl_signal_add(&seat->pointer->focus_signal, listener);
1459 shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
1462 struct shell_surface *shsurf = resource->data;
1463 struct weston_seat *seat;
1464 struct weston_compositor *ec = shsurf->surface->compositor;
1466 if (shsurf->ping_timer == NULL)
1467 /* Just ignore unsolicited pong. */
1470 if (shsurf->ping_timer->serial == serial) {
1471 shsurf->unresponsive = 0;
1472 wl_list_for_each(seat, &ec->seat_list, link) {
1474 end_busy_cursor(shsurf, seat->pointer);
1476 ping_timer_destroy(shsurf);
1481 shell_surface_set_title(struct wl_client *client,
1482 struct wl_resource *resource, const char *title)
1484 struct shell_surface *shsurf = resource->data;
1486 free(shsurf->title);
1487 shsurf->title = strdup(title);
1491 shell_surface_set_class(struct wl_client *client,
1492 struct wl_resource *resource, const char *class)
1494 struct shell_surface *shsurf = resource->data;
1496 free(shsurf->class);
1497 shsurf->class = strdup(class);
1500 static struct weston_output *
1501 get_default_output(struct weston_compositor *compositor)
1503 return container_of(compositor->output_list.next,
1504 struct weston_output, link);
1508 shell_unset_fullscreen(struct shell_surface *shsurf)
1510 struct workspace *ws;
1511 /* undo all fullscreen things here */
1512 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1513 shell_surface_is_top_fullscreen(shsurf)) {
1514 weston_output_switch_mode(shsurf->fullscreen_output,
1515 shsurf->fullscreen_output->origin);
1517 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1518 shsurf->fullscreen.framerate = 0;
1519 wl_list_remove(&shsurf->fullscreen.transform.link);
1520 wl_list_init(&shsurf->fullscreen.transform.link);
1521 if (shsurf->fullscreen.black_surface)
1522 weston_surface_destroy(shsurf->fullscreen.black_surface);
1523 shsurf->fullscreen.black_surface = NULL;
1524 shsurf->fullscreen_output = NULL;
1525 weston_surface_set_position(shsurf->surface,
1526 shsurf->saved_x, shsurf->saved_y);
1527 if (shsurf->saved_rotation_valid) {
1528 wl_list_insert(&shsurf->surface->geometry.transformation_list,
1529 &shsurf->rotation.transform.link);
1530 shsurf->saved_rotation_valid = false;
1533 ws = get_current_workspace(shsurf->shell);
1534 wl_list_remove(&shsurf->surface->layer_link);
1535 wl_list_insert(&ws->layer.surface_list, &shsurf->surface->layer_link);
1539 shell_unset_maximized(struct shell_surface *shsurf)
1541 struct workspace *ws;
1542 /* undo all maximized things here */
1543 shsurf->output = get_default_output(shsurf->surface->compositor);
1544 weston_surface_set_position(shsurf->surface,
1548 if (shsurf->saved_rotation_valid) {
1549 wl_list_insert(&shsurf->surface->geometry.transformation_list,
1550 &shsurf->rotation.transform.link);
1551 shsurf->saved_rotation_valid = false;
1554 ws = get_current_workspace(shsurf->shell);
1555 wl_list_remove(&shsurf->surface->layer_link);
1556 wl_list_insert(&ws->layer.surface_list, &shsurf->surface->layer_link);
1560 reset_shell_surface_type(struct shell_surface *surface)
1562 switch (surface->type) {
1563 case SHELL_SURFACE_FULLSCREEN:
1564 shell_unset_fullscreen(surface);
1566 case SHELL_SURFACE_MAXIMIZED:
1567 shell_unset_maximized(surface);
1569 case SHELL_SURFACE_NONE:
1570 case SHELL_SURFACE_TOPLEVEL:
1571 case SHELL_SURFACE_TRANSIENT:
1572 case SHELL_SURFACE_POPUP:
1576 surface->type = SHELL_SURFACE_NONE;
1581 set_surface_type(struct shell_surface *shsurf)
1583 struct weston_surface *surface = shsurf->surface;
1584 struct weston_surface *pes = shsurf->parent;
1586 reset_shell_surface_type(shsurf);
1588 shsurf->type = shsurf->next_type;
1589 shsurf->next_type = SHELL_SURFACE_NONE;
1591 switch (shsurf->type) {
1592 case SHELL_SURFACE_TOPLEVEL:
1594 case SHELL_SURFACE_TRANSIENT:
1595 weston_surface_set_position(surface,
1596 pes->geometry.x + shsurf->transient.x,
1597 pes->geometry.y + shsurf->transient.y);
1600 case SHELL_SURFACE_MAXIMIZED:
1601 case SHELL_SURFACE_FULLSCREEN:
1602 shsurf->saved_x = surface->geometry.x;
1603 shsurf->saved_y = surface->geometry.y;
1604 shsurf->saved_position_valid = true;
1606 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
1607 wl_list_remove(&shsurf->rotation.transform.link);
1608 wl_list_init(&shsurf->rotation.transform.link);
1609 weston_surface_geometry_dirty(shsurf->surface);
1610 shsurf->saved_rotation_valid = true;
1620 set_toplevel(struct shell_surface *shsurf)
1622 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
1626 shell_surface_set_toplevel(struct wl_client *client,
1627 struct wl_resource *resource)
1629 struct shell_surface *surface = resource->data;
1631 set_toplevel(surface);
1635 set_transient(struct shell_surface *shsurf,
1636 struct weston_surface *parent, int x, int y, uint32_t flags)
1638 /* assign to parents output */
1639 shsurf->parent = parent;
1640 shsurf->transient.x = x;
1641 shsurf->transient.y = y;
1642 shsurf->transient.flags = flags;
1643 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
1647 shell_surface_set_transient(struct wl_client *client,
1648 struct wl_resource *resource,
1649 struct wl_resource *parent_resource,
1650 int x, int y, uint32_t flags)
1652 struct shell_surface *shsurf = resource->data;
1653 struct weston_surface *parent = parent_resource->data;
1655 set_transient(shsurf, parent, x, y, flags);
1658 static struct desktop_shell *
1659 shell_surface_get_shell(struct shell_surface *shsurf)
1661 return shsurf->shell;
1665 get_output_panel_height(struct desktop_shell *shell,
1666 struct weston_output *output)
1668 struct weston_surface *surface;
1669 int panel_height = 0;
1674 wl_list_for_each(surface, &shell->panel_layer.surface_list, layer_link) {
1675 if (surface->output == output) {
1676 panel_height = surface->geometry.height;
1681 return panel_height;
1685 shell_surface_set_maximized(struct wl_client *client,
1686 struct wl_resource *resource,
1687 struct wl_resource *output_resource )
1689 struct shell_surface *shsurf = resource->data;
1690 struct weston_surface *es = shsurf->surface;
1691 struct desktop_shell *shell = NULL;
1692 uint32_t edges = 0, panel_height = 0;
1694 /* get the default output, if the client set it as NULL
1695 check whether the ouput is available */
1696 if (output_resource)
1697 shsurf->output = output_resource->data;
1698 else if (es->output)
1699 shsurf->output = es->output;
1701 shsurf->output = get_default_output(es->compositor);
1703 shell = shell_surface_get_shell(shsurf);
1704 panel_height = get_output_panel_height(shell, shsurf->output);
1705 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
1707 shsurf->client->send_configure(shsurf->surface, edges,
1708 shsurf->output->width,
1709 shsurf->output->height - panel_height);
1711 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
1715 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height);
1717 static struct weston_surface *
1718 create_black_surface(struct weston_compositor *ec,
1719 struct weston_surface *fs_surface,
1720 float x, float y, int w, int h)
1722 struct weston_surface *surface = NULL;
1724 surface = weston_surface_create(ec);
1725 if (surface == NULL) {
1726 weston_log("no memory\n");
1730 surface->configure = black_surface_configure;
1731 surface->configure_private = fs_surface;
1732 weston_surface_configure(surface, x, y, w, h);
1733 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
1734 pixman_region32_fini(&surface->opaque);
1735 pixman_region32_init_rect(&surface->opaque, 0, 0, w, h);
1736 pixman_region32_fini(&surface->input);
1737 pixman_region32_init_rect(&surface->input, 0, 0, w, h);
1742 /* Create black surface and append it to the associated fullscreen surface.
1743 * Handle size dismatch and positioning according to the method. */
1745 shell_configure_fullscreen(struct shell_surface *shsurf)
1747 struct weston_output *output = shsurf->fullscreen_output;
1748 struct weston_surface *surface = shsurf->surface;
1749 struct weston_matrix *matrix;
1750 float scale, output_aspect, surface_aspect, x, y;
1751 int32_t surf_x, surf_y, surf_width, surf_height;
1753 if (!shsurf->fullscreen.black_surface)
1754 shsurf->fullscreen.black_surface =
1755 create_black_surface(surface->compositor,
1757 output->x, output->y,
1761 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
1762 wl_list_insert(&surface->layer_link,
1763 &shsurf->fullscreen.black_surface->layer_link);
1764 shsurf->fullscreen.black_surface->output = output;
1766 surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y,
1767 &surf_width, &surf_height);
1769 switch (shsurf->fullscreen.type) {
1770 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
1771 if (surface->buffer_ref.buffer)
1772 center_on_output(surface, shsurf->fullscreen_output);
1774 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
1775 /* 1:1 mapping between surface and output dimensions */
1776 if (output->width == surf_width &&
1777 output->height == surf_height) {
1778 weston_surface_set_position(surface, output->x - surf_x,
1779 output->y - surf_y);
1783 matrix = &shsurf->fullscreen.transform.matrix;
1784 weston_matrix_init(matrix);
1786 output_aspect = (float) output->width /
1787 (float) output->height;
1788 surface_aspect = (float) surface->geometry.width /
1789 (float) surface->geometry.height;
1790 if (output_aspect < surface_aspect)
1791 scale = (float) output->width /
1794 scale = (float) output->height /
1795 (float) surf_height;
1797 weston_matrix_scale(matrix, scale, scale, 1);
1798 wl_list_remove(&shsurf->fullscreen.transform.link);
1799 wl_list_insert(&surface->geometry.transformation_list,
1800 &shsurf->fullscreen.transform.link);
1801 x = output->x + (output->width - surf_width * scale) / 2 - surf_x;
1802 y = output->y + (output->height - surf_height * scale) / 2 - surf_y;
1803 weston_surface_set_position(surface, x, y);
1806 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
1807 if (shell_surface_is_top_fullscreen(shsurf)) {
1808 struct weston_mode mode = {0,
1811 shsurf->fullscreen.framerate};
1813 if (weston_output_switch_mode(output, &mode) == 0) {
1814 weston_surface_configure(shsurf->fullscreen.black_surface,
1823 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
1830 /* make the fullscreen and black surface at the top */
1832 shell_stack_fullscreen(struct shell_surface *shsurf)
1834 struct weston_output *output = shsurf->fullscreen_output;
1835 struct weston_surface *surface = shsurf->surface;
1836 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
1838 wl_list_remove(&surface->layer_link);
1839 wl_list_insert(&shell->fullscreen_layer.surface_list,
1840 &surface->layer_link);
1841 weston_surface_damage(surface);
1843 if (!shsurf->fullscreen.black_surface)
1844 shsurf->fullscreen.black_surface =
1845 create_black_surface(surface->compositor,
1847 output->x, output->y,
1851 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
1852 wl_list_insert(&surface->layer_link,
1853 &shsurf->fullscreen.black_surface->layer_link);
1854 weston_surface_damage(shsurf->fullscreen.black_surface);
1858 shell_map_fullscreen(struct shell_surface *shsurf)
1860 shell_stack_fullscreen(shsurf);
1861 shell_configure_fullscreen(shsurf);
1865 set_fullscreen(struct shell_surface *shsurf,
1868 struct weston_output *output)
1870 struct weston_surface *es = shsurf->surface;
1873 shsurf->output = output;
1874 else if (es->output)
1875 shsurf->output = es->output;
1877 shsurf->output = get_default_output(es->compositor);
1879 shsurf->fullscreen_output = shsurf->output;
1880 shsurf->fullscreen.type = method;
1881 shsurf->fullscreen.framerate = framerate;
1882 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
1884 shsurf->client->send_configure(shsurf->surface, 0,
1885 shsurf->output->width,
1886 shsurf->output->height);
1890 shell_surface_set_fullscreen(struct wl_client *client,
1891 struct wl_resource *resource,
1894 struct wl_resource *output_resource)
1896 struct shell_surface *shsurf = resource->data;
1897 struct weston_output *output;
1899 if (output_resource)
1900 output = output_resource->data;
1904 set_fullscreen(shsurf, method, framerate, output);
1907 static const struct weston_pointer_grab_interface popup_grab_interface;
1910 destroy_shell_seat(struct wl_listener *listener, void *data)
1912 struct shell_seat *shseat =
1913 container_of(listener,
1914 struct shell_seat, seat_destroy_listener);
1915 struct shell_surface *shsurf, *prev = NULL;
1917 if (shseat->popup_grab.grab.interface == &popup_grab_interface) {
1918 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
1919 shseat->popup_grab.client = NULL;
1921 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
1922 shsurf->popup.shseat = NULL;
1924 wl_list_init(&prev->popup.grab_link);
1928 wl_list_init(&prev->popup.grab_link);
1931 wl_list_remove(&shseat->seat_destroy_listener.link);
1935 static struct shell_seat *
1936 create_shell_seat(struct weston_seat *seat)
1938 struct shell_seat *shseat;
1940 shseat = calloc(1, sizeof *shseat);
1942 weston_log("no memory to allocate shell seat\n");
1946 shseat->seat = seat;
1947 wl_list_init(&shseat->popup_grab.surfaces_list);
1949 shseat->seat_destroy_listener.notify = destroy_shell_seat;
1950 wl_signal_add(&seat->destroy_signal,
1951 &shseat->seat_destroy_listener);
1956 static struct shell_seat *
1957 get_shell_seat(struct weston_seat *seat)
1959 struct wl_listener *listener;
1961 listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat);
1962 if (listener == NULL)
1963 return create_shell_seat(seat);
1965 return container_of(listener,
1966 struct shell_seat, seat_destroy_listener);
1970 popup_grab_focus(struct weston_pointer_grab *grab)
1972 struct weston_pointer *pointer = grab->pointer;
1973 struct weston_surface *surface;
1974 struct shell_seat *shseat =
1975 container_of(grab, struct shell_seat, popup_grab.grab);
1976 struct wl_client *client = shseat->popup_grab.client;
1979 surface = weston_compositor_pick_surface(pointer->seat->compositor,
1980 pointer->x, pointer->y,
1983 if (surface && surface->resource.client == client) {
1984 weston_pointer_set_focus(pointer, surface, sx, sy);
1986 weston_pointer_set_focus(pointer, NULL,
1987 wl_fixed_from_int(0),
1988 wl_fixed_from_int(0));
1993 popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
1995 struct weston_pointer *pointer = grab->pointer;
1998 if (pointer->focus_resource) {
1999 weston_surface_from_global_fixed(pointer->focus,
2000 pointer->x, pointer->y,
2002 wl_pointer_send_motion(pointer->focus_resource, time, sx, sy);
2007 popup_grab_button(struct weston_pointer_grab *grab,
2008 uint32_t time, uint32_t button, uint32_t state_w)
2010 struct wl_resource *resource;
2011 struct shell_seat *shseat =
2012 container_of(grab, struct shell_seat, popup_grab.grab);
2013 struct wl_display *display;
2014 enum wl_pointer_button_state state = state_w;
2017 resource = grab->pointer->focus_resource;
2019 display = wl_client_get_display(resource->client);
2020 serial = wl_display_get_serial(display);
2021 wl_pointer_send_button(resource, serial, time, button, state);
2022 } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
2023 (shseat->popup_grab.initial_up ||
2024 time - shseat->seat->pointer->grab_time > 500)) {
2025 popup_grab_end(grab->pointer);
2028 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
2029 shseat->popup_grab.initial_up = 1;
2032 static const struct weston_pointer_grab_interface popup_grab_interface = {
2039 popup_grab_end(struct weston_pointer *pointer)
2041 struct weston_pointer_grab *grab = pointer->grab;
2042 struct shell_seat *shseat =
2043 container_of(grab, struct shell_seat, popup_grab.grab);
2044 struct shell_surface *shsurf;
2045 struct shell_surface *prev = NULL;
2047 if (pointer->grab->interface == &popup_grab_interface) {
2048 weston_pointer_end_grab(grab->pointer);
2049 shseat->popup_grab.client = NULL;
2050 shseat->popup_grab.grab.interface = NULL;
2051 assert(!wl_list_empty(&shseat->popup_grab.surfaces_list));
2052 /* Send the popup_done event to all the popups open */
2053 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
2054 wl_shell_surface_send_popup_done(&shsurf->resource);
2055 shsurf->popup.shseat = NULL;
2057 wl_list_init(&prev->popup.grab_link);
2061 wl_list_init(&prev->popup.grab_link);
2062 wl_list_init(&shseat->popup_grab.surfaces_list);
2067 add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat)
2069 struct weston_seat *seat = shseat->seat;
2071 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
2072 shseat->popup_grab.client = shsurf->resource.client;
2073 shseat->popup_grab.grab.interface = &popup_grab_interface;
2074 /* We must make sure here that this popup was opened after
2075 * a mouse press, and not just by moving around with other
2076 * popups already open. */
2077 if (shseat->seat->pointer->button_count > 0)
2078 shseat->popup_grab.initial_up = 0;
2080 weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab);
2082 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
2086 remove_popup_grab(struct shell_surface *shsurf)
2088 struct shell_seat *shseat = shsurf->popup.shseat;
2090 wl_list_remove(&shsurf->popup.grab_link);
2091 wl_list_init(&shsurf->popup.grab_link);
2092 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
2093 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
2094 shseat->popup_grab.grab.interface = NULL;
2099 shell_map_popup(struct shell_surface *shsurf)
2101 struct shell_seat *shseat = shsurf->popup.shseat;
2102 struct weston_surface *es = shsurf->surface;
2103 struct weston_surface *parent = shsurf->parent;
2105 es->output = parent->output;
2107 weston_surface_set_transform_parent(es, parent);
2108 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
2109 weston_surface_update_transform(es);
2111 if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) {
2112 add_popup_grab(shsurf, shseat);
2114 wl_shell_surface_send_popup_done(&shsurf->resource);
2115 shseat->popup_grab.client = NULL;
2120 shell_surface_set_popup(struct wl_client *client,
2121 struct wl_resource *resource,
2122 struct wl_resource *seat_resource,
2124 struct wl_resource *parent_resource,
2125 int32_t x, int32_t y, uint32_t flags)
2127 struct shell_surface *shsurf = resource->data;
2129 shsurf->type = SHELL_SURFACE_POPUP;
2130 shsurf->parent = parent_resource->data;
2131 shsurf->popup.shseat = get_shell_seat(seat_resource->data);
2132 shsurf->popup.serial = serial;
2133 shsurf->popup.x = x;
2134 shsurf->popup.y = y;
2137 static const struct wl_shell_surface_interface shell_surface_implementation = {
2140 shell_surface_resize,
2141 shell_surface_set_toplevel,
2142 shell_surface_set_transient,
2143 shell_surface_set_fullscreen,
2144 shell_surface_set_popup,
2145 shell_surface_set_maximized,
2146 shell_surface_set_title,
2147 shell_surface_set_class
2151 destroy_shell_surface(struct shell_surface *shsurf)
2153 if (!wl_list_empty(&shsurf->popup.grab_link)) {
2154 remove_popup_grab(shsurf);
2157 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
2158 shell_surface_is_top_fullscreen(shsurf)) {
2159 weston_output_switch_mode(shsurf->fullscreen_output,
2160 shsurf->fullscreen_output->origin);
2163 if (shsurf->fullscreen.black_surface)
2164 weston_surface_destroy(shsurf->fullscreen.black_surface);
2166 /* As destroy_resource() use wl_list_for_each_safe(),
2167 * we can always remove the listener.
2169 wl_list_remove(&shsurf->surface_destroy_listener.link);
2170 shsurf->surface->configure = NULL;
2171 ping_timer_destroy(shsurf);
2172 free(shsurf->title);
2174 wl_list_remove(&shsurf->link);
2179 shell_destroy_shell_surface(struct wl_resource *resource)
2181 struct shell_surface *shsurf = resource->data;
2183 destroy_shell_surface(shsurf);
2187 shell_handle_surface_destroy(struct wl_listener *listener, void *data)
2189 struct shell_surface *shsurf = container_of(listener,
2190 struct shell_surface,
2191 surface_destroy_listener);
2193 if (shsurf->resource.client) {
2194 wl_resource_destroy(&shsurf->resource);
2196 wl_signal_emit(&shsurf->resource.destroy_signal,
2198 destroy_shell_surface(shsurf);
2203 shell_surface_configure(struct weston_surface *, int32_t, int32_t, int32_t, int32_t);
2205 static struct shell_surface *
2206 get_shell_surface(struct weston_surface *surface)
2208 if (surface->configure == shell_surface_configure)
2209 return surface->configure_private;
2214 static struct shell_surface *
2215 create_shell_surface(void *shell, struct weston_surface *surface,
2216 const struct weston_shell_client *client)
2218 struct shell_surface *shsurf;
2220 if (surface->configure) {
2221 weston_log("surface->configure already set\n");
2225 shsurf = calloc(1, sizeof *shsurf);
2227 weston_log("no memory to allocate shell surface\n");
2231 surface->configure = shell_surface_configure;
2232 surface->configure_private = shsurf;
2234 shsurf->shell = (struct desktop_shell *) shell;
2235 shsurf->unresponsive = 0;
2236 shsurf->saved_position_valid = false;
2237 shsurf->saved_rotation_valid = false;
2238 shsurf->surface = surface;
2239 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
2240 shsurf->fullscreen.framerate = 0;
2241 shsurf->fullscreen.black_surface = NULL;
2242 shsurf->ping_timer = NULL;
2243 wl_list_init(&shsurf->fullscreen.transform.link);
2245 wl_signal_init(&shsurf->resource.destroy_signal);
2246 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
2247 wl_signal_add(&surface->resource.destroy_signal,
2248 &shsurf->surface_destroy_listener);
2250 /* init link so its safe to always remove it in destroy_shell_surface */
2251 wl_list_init(&shsurf->link);
2252 wl_list_init(&shsurf->popup.grab_link);
2254 /* empty when not in use */
2255 wl_list_init(&shsurf->rotation.transform.link);
2256 weston_matrix_init(&shsurf->rotation.rotation);
2258 wl_list_init(&shsurf->workspace_transform.link);
2260 shsurf->type = SHELL_SURFACE_NONE;
2261 shsurf->next_type = SHELL_SURFACE_NONE;
2263 shsurf->client = client;
2269 shell_get_shell_surface(struct wl_client *client,
2270 struct wl_resource *resource,
2272 struct wl_resource *surface_resource)
2274 struct weston_surface *surface = surface_resource->data;
2275 struct desktop_shell *shell = resource->data;
2276 struct shell_surface *shsurf;
2278 if (get_shell_surface(surface)) {
2279 wl_resource_post_error(surface_resource,
2280 WL_DISPLAY_ERROR_INVALID_OBJECT,
2281 "desktop_shell::get_shell_surface already requested");
2285 shsurf = create_shell_surface(shell, surface, &shell_client);
2287 wl_resource_post_error(surface_resource,
2288 WL_DISPLAY_ERROR_INVALID_OBJECT,
2289 "surface->configure already set");
2293 shsurf->resource.destroy = shell_destroy_shell_surface;
2294 shsurf->resource.object.id = id;
2295 shsurf->resource.object.interface = &wl_shell_surface_interface;
2296 shsurf->resource.object.implementation =
2297 (void (**)(void)) &shell_surface_implementation;
2298 shsurf->resource.data = shsurf;
2300 wl_client_add_resource(client, &shsurf->resource);
2303 static const struct wl_shell_interface shell_implementation = {
2304 shell_get_shell_surface
2308 shell_fade(struct desktop_shell *shell, enum fade_type type);
2311 screensaver_timeout(void *data)
2313 struct desktop_shell *shell = data;
2315 shell_fade(shell, FADE_OUT);
2321 handle_screensaver_sigchld(struct weston_process *proc, int status)
2323 struct desktop_shell *shell =
2324 container_of(proc, struct desktop_shell, screensaver.process);
2329 weston_compositor_sleep(shell->compositor);
2333 launch_screensaver(struct desktop_shell *shell)
2335 if (shell->screensaver.binding)
2338 if (!shell->screensaver.path) {
2339 weston_compositor_sleep(shell->compositor);
2343 if (shell->screensaver.process.pid != 0) {
2344 weston_log("old screensaver still running\n");
2348 weston_client_launch(shell->compositor,
2349 &shell->screensaver.process,
2350 shell->screensaver.path,
2351 handle_screensaver_sigchld);
2355 terminate_screensaver(struct desktop_shell *shell)
2357 if (shell->screensaver.process.pid == 0)
2360 kill(shell->screensaver.process.pid, SIGTERM);
2364 configure_static_surface(struct weston_surface *es, struct weston_layer *layer, int32_t width, int32_t height)
2366 struct weston_surface *s, *next;
2371 wl_list_for_each_safe(s, next, &layer->surface_list, layer_link) {
2372 if (s->output == es->output && s != es) {
2373 weston_surface_unmap(s);
2374 s->configure = NULL;
2378 weston_surface_configure(es, es->output->x, es->output->y, width, height);
2380 if (wl_list_empty(&es->layer_link)) {
2381 wl_list_insert(&layer->surface_list, &es->layer_link);
2382 weston_compositor_schedule_repaint(es->compositor);
2387 background_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
2389 struct desktop_shell *shell = es->configure_private;
2391 configure_static_surface(es, &shell->background_layer, width, height);
2395 desktop_shell_set_background(struct wl_client *client,
2396 struct wl_resource *resource,
2397 struct wl_resource *output_resource,
2398 struct wl_resource *surface_resource)
2400 struct desktop_shell *shell = resource->data;
2401 struct weston_surface *surface = surface_resource->data;
2403 if (surface->configure) {
2404 wl_resource_post_error(surface_resource,
2405 WL_DISPLAY_ERROR_INVALID_OBJECT,
2406 "surface role already assigned");
2410 surface->configure = background_configure;
2411 surface->configure_private = shell;
2412 surface->output = output_resource->data;
2413 desktop_shell_send_configure(resource, 0,
2415 surface->output->width,
2416 surface->output->height);
2420 panel_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
2422 struct desktop_shell *shell = es->configure_private;
2424 configure_static_surface(es, &shell->panel_layer, width, height);
2428 desktop_shell_set_panel(struct wl_client *client,
2429 struct wl_resource *resource,
2430 struct wl_resource *output_resource,
2431 struct wl_resource *surface_resource)
2433 struct desktop_shell *shell = resource->data;
2434 struct weston_surface *surface = surface_resource->data;
2436 if (surface->configure) {
2437 wl_resource_post_error(surface_resource,
2438 WL_DISPLAY_ERROR_INVALID_OBJECT,
2439 "surface role already assigned");
2443 surface->configure = panel_configure;
2444 surface->configure_private = shell;
2445 surface->output = output_resource->data;
2446 desktop_shell_send_configure(resource, 0,
2448 surface->output->width,
2449 surface->output->height);
2453 lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
2455 struct desktop_shell *shell = surface->configure_private;
2460 surface->geometry.width = width;
2461 surface->geometry.height = height;
2462 center_on_output(surface, get_default_output(shell->compositor));
2464 if (!weston_surface_is_mapped(surface)) {
2465 wl_list_insert(&shell->lock_layer.surface_list,
2466 &surface->layer_link);
2467 weston_surface_update_transform(surface);
2468 shell_fade(shell, FADE_IN);
2473 handle_lock_surface_destroy(struct wl_listener *listener, void *data)
2475 struct desktop_shell *shell =
2476 container_of(listener, struct desktop_shell, lock_surface_listener);
2478 weston_log("lock surface gone\n");
2479 shell->lock_surface = NULL;
2483 desktop_shell_set_lock_surface(struct wl_client *client,
2484 struct wl_resource *resource,
2485 struct wl_resource *surface_resource)
2487 struct desktop_shell *shell = resource->data;
2488 struct weston_surface *surface = surface_resource->data;
2490 shell->prepare_event_sent = false;
2495 shell->lock_surface = surface;
2497 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
2498 wl_signal_add(&surface_resource->destroy_signal,
2499 &shell->lock_surface_listener);
2501 surface->configure = lock_surface_configure;
2502 surface->configure_private = shell;
2506 resume_desktop(struct desktop_shell *shell)
2508 struct workspace *ws = get_current_workspace(shell);
2510 terminate_screensaver(shell);
2512 wl_list_remove(&shell->lock_layer.link);
2513 wl_list_insert(&shell->compositor->cursor_layer.link,
2514 &shell->fullscreen_layer.link);
2515 wl_list_insert(&shell->fullscreen_layer.link,
2516 &shell->panel_layer.link);
2517 if (shell->showing_input_panels) {
2518 wl_list_insert(&shell->panel_layer.link,
2519 &shell->input_panel_layer.link);
2520 wl_list_insert(&shell->input_panel_layer.link,
2523 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
2526 restore_focus_state(shell, get_current_workspace(shell));
2528 shell->locked = false;
2529 shell_fade(shell, FADE_IN);
2530 weston_compositor_damage_all(shell->compositor);
2534 desktop_shell_unlock(struct wl_client *client,
2535 struct wl_resource *resource)
2537 struct desktop_shell *shell = resource->data;
2539 shell->prepare_event_sent = false;
2542 resume_desktop(shell);
2546 desktop_shell_set_grab_surface(struct wl_client *client,
2547 struct wl_resource *resource,
2548 struct wl_resource *surface_resource)
2550 struct desktop_shell *shell = resource->data;
2552 shell->grab_surface = surface_resource->data;
2556 desktop_shell_desktop_ready(struct wl_client *client,
2557 struct wl_resource *resource)
2559 struct desktop_shell *shell = resource->data;
2561 shell_fade_startup(shell);
2564 static const struct desktop_shell_interface desktop_shell_implementation = {
2565 desktop_shell_set_background,
2566 desktop_shell_set_panel,
2567 desktop_shell_set_lock_surface,
2568 desktop_shell_unlock,
2569 desktop_shell_set_grab_surface,
2570 desktop_shell_desktop_ready
2573 static enum shell_surface_type
2574 get_shell_surface_type(struct weston_surface *surface)
2576 struct shell_surface *shsurf;
2578 shsurf = get_shell_surface(surface);
2580 return SHELL_SURFACE_NONE;
2581 return shsurf->type;
2585 move_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
2587 struct weston_surface *focus =
2588 (struct weston_surface *) seat->pointer->focus;
2589 struct weston_surface *surface;
2590 struct shell_surface *shsurf;
2592 surface = weston_surface_get_main_surface(focus);
2593 if (surface == NULL)
2596 shsurf = get_shell_surface(surface);
2597 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
2598 shsurf->type == SHELL_SURFACE_MAXIMIZED)
2601 surface_move(shsurf, (struct weston_seat *) seat);
2605 resize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
2607 struct weston_surface *focus =
2608 (struct weston_surface *) seat->pointer->focus;
2609 struct weston_surface *surface;
2612 struct shell_surface *shsurf;
2614 surface = weston_surface_get_main_surface(focus);
2615 if (surface == NULL)
2618 shsurf = get_shell_surface(surface);
2619 if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
2620 shsurf->type == SHELL_SURFACE_MAXIMIZED)
2623 weston_surface_from_global(surface,
2624 wl_fixed_to_int(seat->pointer->grab_x),
2625 wl_fixed_to_int(seat->pointer->grab_y),
2628 if (x < surface->geometry.width / 3)
2629 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
2630 else if (x < 2 * surface->geometry.width / 3)
2633 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
2635 if (y < surface->geometry.height / 3)
2636 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
2637 else if (y < 2 * surface->geometry.height / 3)
2640 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
2642 surface_resize(shsurf, (struct weston_seat *) seat, edges);
2646 surface_opacity_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
2647 wl_fixed_t value, void *data)
2650 struct shell_surface *shsurf;
2651 struct weston_surface *focus =
2652 (struct weston_surface *) seat->pointer->focus;
2653 struct weston_surface *surface;
2655 /* XXX: broken for windows containing sub-surfaces */
2656 surface = weston_surface_get_main_surface(focus);
2657 if (surface == NULL)
2660 shsurf = get_shell_surface(surface);
2664 surface->alpha -= wl_fixed_to_double(value) * step;
2666 if (surface->alpha > 1.0)
2667 surface->alpha = 1.0;
2668 if (surface->alpha < step)
2669 surface->alpha = step;
2671 weston_surface_geometry_dirty(surface);
2672 weston_surface_damage(surface);
2676 do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
2679 struct weston_seat *ws = (struct weston_seat *) seat;
2680 struct weston_compositor *compositor = ws->compositor;
2681 struct weston_output *output;
2684 wl_list_for_each(output, &compositor->output_list, link) {
2685 if (pixman_region32_contains_point(&output->region,
2686 wl_fixed_to_double(seat->pointer->x),
2687 wl_fixed_to_double(seat->pointer->y),
2689 if (key == KEY_PAGEUP)
2690 increment = output->zoom.increment;
2691 else if (key == KEY_PAGEDOWN)
2692 increment = -output->zoom.increment;
2693 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
2694 /* For every pixel zoom 20th of a step */
2695 increment = output->zoom.increment *
2696 -wl_fixed_to_double(value) / 20.0;
2700 output->zoom.level += increment;
2702 if (output->zoom.level < 0.0)
2703 output->zoom.level = 0.0;
2704 else if (output->zoom.level > output->zoom.max_level)
2705 output->zoom.level = output->zoom.max_level;
2706 else if (!output->zoom.active) {
2707 output->zoom.active = 1;
2708 output->disable_planes++;
2711 output->zoom.spring_z.target = output->zoom.level;
2713 weston_output_update_zoom(output, output->zoom.type);
2719 zoom_axis_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
2720 wl_fixed_t value, void *data)
2722 do_zoom(seat, time, 0, axis, value);
2726 zoom_key_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
2729 do_zoom(seat, time, key, 0, 0);
2733 terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
2736 struct weston_compositor *compositor = data;
2738 wl_display_terminate(compositor->wl_display);
2742 rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
2744 struct rotate_grab *rotate =
2745 container_of(grab, struct rotate_grab, base.grab);
2746 struct weston_pointer *pointer = grab->pointer;
2747 struct shell_surface *shsurf = rotate->base.shsurf;
2748 struct weston_surface *surface;
2749 float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
2754 surface = shsurf->surface;
2756 cx = 0.5f * surface->geometry.width;
2757 cy = 0.5f * surface->geometry.height;
2759 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
2760 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
2761 r = sqrtf(dx * dx + dy * dy);
2763 wl_list_remove(&shsurf->rotation.transform.link);
2764 weston_surface_geometry_dirty(shsurf->surface);
2767 struct weston_matrix *matrix =
2768 &shsurf->rotation.transform.matrix;
2770 weston_matrix_init(&rotate->rotation);
2771 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
2773 weston_matrix_init(matrix);
2774 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
2775 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
2776 weston_matrix_multiply(matrix, &rotate->rotation);
2777 weston_matrix_translate(matrix, cx, cy, 0.0f);
2780 &shsurf->surface->geometry.transformation_list,
2781 &shsurf->rotation.transform.link);
2783 wl_list_init(&shsurf->rotation.transform.link);
2784 weston_matrix_init(&shsurf->rotation.rotation);
2785 weston_matrix_init(&rotate->rotation);
2788 /* We need to adjust the position of the surface
2789 * in case it was resized in a rotated state before */
2790 cposx = surface->geometry.x + cx;
2791 cposy = surface->geometry.y + cy;
2792 dposx = rotate->center.x - cposx;
2793 dposy = rotate->center.y - cposy;
2794 if (dposx != 0.0f || dposy != 0.0f) {
2795 weston_surface_set_position(surface,
2796 surface->geometry.x + dposx,
2797 surface->geometry.y + dposy);
2800 /* Repaint implies weston_surface_update_transform(), which
2801 * lazily applies the damage due to rotation update.
2803 weston_compositor_schedule_repaint(shsurf->surface->compositor);
2807 rotate_grab_button(struct weston_pointer_grab *grab,
2808 uint32_t time, uint32_t button, uint32_t state_w)
2810 struct rotate_grab *rotate =
2811 container_of(grab, struct rotate_grab, base.grab);
2812 struct weston_pointer *pointer = grab->pointer;
2813 struct shell_surface *shsurf = rotate->base.shsurf;
2814 enum wl_pointer_button_state state = state_w;
2816 if (pointer->button_count == 0 &&
2817 state == WL_POINTER_BUTTON_STATE_RELEASED) {
2819 weston_matrix_multiply(&shsurf->rotation.rotation,
2821 shell_grab_end(&rotate->base);
2826 static const struct weston_pointer_grab_interface rotate_grab_interface = {
2833 surface_rotate(struct shell_surface *surface, struct weston_seat *seat)
2835 struct rotate_grab *rotate;
2839 rotate = malloc(sizeof *rotate);
2843 weston_surface_to_global_float(surface->surface,
2844 surface->surface->geometry.width / 2,
2845 surface->surface->geometry.height / 2,
2846 &rotate->center.x, &rotate->center.y);
2848 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
2849 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
2850 r = sqrtf(dx * dx + dy * dy);
2852 struct weston_matrix inverse;
2854 weston_matrix_init(&inverse);
2855 weston_matrix_rotate_xy(&inverse, dx / r, -dy / r);
2856 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
2858 weston_matrix_init(&rotate->rotation);
2859 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
2861 weston_matrix_init(&surface->rotation.rotation);
2862 weston_matrix_init(&rotate->rotation);
2865 shell_grab_start(&rotate->base, &rotate_grab_interface, surface,
2866 seat->pointer, DESKTOP_SHELL_CURSOR_ARROW);
2870 rotate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
2873 struct weston_surface *focus =
2874 (struct weston_surface *) seat->pointer->focus;
2875 struct weston_surface *base_surface;
2876 struct shell_surface *surface;
2878 base_surface = weston_surface_get_main_surface(focus);
2879 if (base_surface == NULL)
2882 surface = get_shell_surface(base_surface);
2883 if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN ||
2884 surface->type == SHELL_SURFACE_MAXIMIZED)
2887 surface_rotate(surface, seat);
2891 lower_fullscreen_layer(struct desktop_shell *shell)
2893 struct workspace *ws;
2894 struct weston_surface *surface, *prev;
2896 ws = get_current_workspace(shell);
2897 wl_list_for_each_reverse_safe(surface, prev,
2898 &shell->fullscreen_layer.surface_list,
2900 weston_surface_restack(surface, &ws->layer.surface_list);
2904 activate(struct desktop_shell *shell, struct weston_surface *es,
2905 struct weston_seat *seat)
2907 struct weston_surface *main_surface;
2908 struct focus_state *state;
2909 struct workspace *ws;
2911 main_surface = weston_surface_get_main_surface(es);
2913 weston_surface_activate(es, seat);
2915 state = ensure_focus_state(shell, seat);
2919 state->keyboard_focus = es;
2920 wl_list_remove(&state->surface_destroy_listener.link);
2921 wl_signal_add(&es->resource.destroy_signal,
2922 &state->surface_destroy_listener);
2924 switch (get_shell_surface_type(main_surface)) {
2925 case SHELL_SURFACE_FULLSCREEN:
2926 /* should on top of panels */
2927 shell_stack_fullscreen(get_shell_surface(main_surface));
2928 shell_configure_fullscreen(get_shell_surface(main_surface));
2931 ws = get_current_workspace(shell);
2932 weston_surface_restack(main_surface, &ws->layer.surface_list);
2937 /* no-op func for checking black surface */
2939 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
2944 is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
2946 if (es->configure == black_surface_configure) {
2948 *fs_surface = (struct weston_surface *)es->configure_private;
2955 click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
2958 struct weston_seat *ws = (struct weston_seat *) seat;
2959 struct desktop_shell *shell = data;
2960 struct weston_surface *focus;
2961 struct weston_surface *main_surface;
2963 focus = (struct weston_surface *) seat->pointer->focus;
2967 if (is_black_surface(focus, &main_surface))
2968 focus = main_surface;
2970 main_surface = weston_surface_get_main_surface(focus);
2971 if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE)
2974 if (seat->pointer->grab == &seat->pointer->default_grab)
2975 activate(shell, focus, ws);
2979 lock(struct desktop_shell *shell)
2981 struct workspace *ws = get_current_workspace(shell);
2983 if (shell->locked) {
2984 weston_compositor_sleep(shell->compositor);
2988 shell->locked = true;
2990 /* Hide all surfaces by removing the fullscreen, panel and
2991 * toplevel layers. This way nothing else can show or receive
2992 * input events while we are locked. */
2994 wl_list_remove(&shell->panel_layer.link);
2995 wl_list_remove(&shell->fullscreen_layer.link);
2996 if (shell->showing_input_panels)
2997 wl_list_remove(&shell->input_panel_layer.link);
2998 wl_list_remove(&ws->layer.link);
2999 wl_list_insert(&shell->compositor->cursor_layer.link,
3000 &shell->lock_layer.link);
3002 launch_screensaver(shell);
3004 /* TODO: disable bindings that should not work while locked. */
3006 /* All this must be undone in resume_desktop(). */
3010 unlock(struct desktop_shell *shell)
3012 if (!shell->locked || shell->lock_surface) {
3013 shell_fade(shell, FADE_IN);
3017 /* If desktop-shell client has gone away, unlock immediately. */
3018 if (!shell->child.desktop_shell) {
3019 resume_desktop(shell);
3023 if (shell->prepare_event_sent)
3026 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
3027 shell->prepare_event_sent = true;
3031 shell_fade_done(struct weston_surface_animation *animation, void *data)
3033 struct desktop_shell *shell = data;
3035 shell->fade.animation = NULL;
3037 switch (shell->fade.type) {
3039 weston_surface_destroy(shell->fade.surface);
3040 shell->fade.surface = NULL;
3048 static struct weston_surface *
3049 shell_fade_create_surface(struct desktop_shell *shell)
3051 struct weston_compositor *compositor = shell->compositor;
3052 struct weston_surface *surface;
3054 surface = weston_surface_create(compositor);
3058 weston_surface_configure(surface, 0, 0, 8192, 8192);
3059 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
3060 wl_list_insert(&compositor->fade_layer.surface_list,
3061 &surface->layer_link);
3062 pixman_region32_init(&surface->input);
3068 shell_fade(struct desktop_shell *shell, enum fade_type type)
3080 weston_log("shell: invalid fade type\n");
3084 shell->fade.type = type;
3086 if (shell->fade.surface == NULL) {
3087 shell->fade.surface = shell_fade_create_surface(shell);
3088 if (!shell->fade.surface)
3091 shell->fade.surface->alpha = 1.0 - tint;
3092 weston_surface_update_transform(shell->fade.surface);
3095 if (shell->fade.animation)
3096 weston_fade_update(shell->fade.animation,
3097 shell->fade.surface->alpha, tint, 30.0);
3099 shell->fade.animation =
3100 weston_fade_run(shell->fade.surface,
3101 1.0 - tint, tint, 30.0,
3102 shell_fade_done, shell);
3106 do_shell_fade_startup(void *data)
3108 struct desktop_shell *shell = data;
3110 shell_fade(shell, FADE_IN);
3114 shell_fade_startup(struct desktop_shell *shell)
3116 struct wl_event_loop *loop;
3118 if (!shell->fade.startup_timer)
3121 wl_event_source_remove(shell->fade.startup_timer);
3122 shell->fade.startup_timer = NULL;
3124 loop = wl_display_get_event_loop(shell->compositor->wl_display);
3125 wl_event_loop_add_idle(loop, do_shell_fade_startup, shell);
3129 fade_startup_timeout(void *data)
3131 struct desktop_shell *shell = data;
3133 shell_fade_startup(shell);
3138 shell_fade_init(struct desktop_shell *shell)
3140 /* Make compositor output all black, and wait for the desktop-shell
3141 * client to signal it is ready, then fade in. The timer triggers a
3142 * fade-in, in case the desktop-shell client takes too long.
3145 struct wl_event_loop *loop;
3147 if (shell->fade.surface != NULL) {
3148 weston_log("%s: warning: fade surface already exists\n",
3153 shell->fade.surface = shell_fade_create_surface(shell);
3154 if (!shell->fade.surface)
3157 weston_surface_update_transform(shell->fade.surface);
3158 weston_surface_damage(shell->fade.surface);
3160 loop = wl_display_get_event_loop(shell->compositor->wl_display);
3161 shell->fade.startup_timer =
3162 wl_event_loop_add_timer(loop, fade_startup_timeout, shell);
3163 wl_event_source_timer_update(shell->fade.startup_timer, 15000);
3167 idle_handler(struct wl_listener *listener, void *data)
3169 struct desktop_shell *shell =
3170 container_of(listener, struct desktop_shell, idle_listener);
3172 shell_fade(shell, FADE_OUT);
3173 /* lock() is called from shell_fade_done() */
3177 wake_handler(struct wl_listener *listener, void *data)
3179 struct desktop_shell *shell =
3180 container_of(listener, struct desktop_shell, wake_listener);
3186 show_input_panels(struct wl_listener *listener, void *data)
3188 struct desktop_shell *shell =
3189 container_of(listener, struct desktop_shell,
3190 show_input_panel_listener);
3191 struct input_panel_surface *surface, *next;
3192 struct weston_surface *ws;
3194 shell->text_input.surface = (struct weston_surface*)data;
3196 if (shell->showing_input_panels)
3199 shell->showing_input_panels = true;
3202 wl_list_insert(&shell->panel_layer.link,
3203 &shell->input_panel_layer.link);
3205 wl_list_for_each_safe(surface, next,
3206 &shell->input_panel.surfaces, link) {
3207 ws = surface->surface;
3208 if (!ws->buffer_ref.buffer)
3210 wl_list_insert(&shell->input_panel_layer.surface_list,
3212 weston_surface_geometry_dirty(ws);
3213 weston_surface_update_transform(ws);
3214 weston_surface_damage(ws);
3215 weston_slide_run(ws, ws->geometry.height, 0, NULL, NULL);
3220 hide_input_panels(struct wl_listener *listener, void *data)
3222 struct desktop_shell *shell =
3223 container_of(listener, struct desktop_shell,
3224 hide_input_panel_listener);
3225 struct weston_surface *surface, *next;
3227 if (!shell->showing_input_panels)
3230 shell->showing_input_panels = false;
3233 wl_list_remove(&shell->input_panel_layer.link);
3235 wl_list_for_each_safe(surface, next,
3236 &shell->input_panel_layer.surface_list, layer_link)
3237 weston_surface_unmap(surface);
3241 update_input_panels(struct wl_listener *listener, void *data)
3243 struct desktop_shell *shell =
3244 container_of(listener, struct desktop_shell,
3245 update_input_panel_listener);
3247 memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t));
3251 center_on_output(struct weston_surface *surface, struct weston_output *output)
3253 int32_t surf_x, surf_y, width, height;
3256 surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y, &width, &height);
3258 x = output->x + (output->width - width) / 2 - surf_x / 2;
3259 y = output->y + (output->height - height) / 2 - surf_y / 2;
3261 weston_surface_configure(surface, x, y, width, height);
3265 weston_surface_set_initial_position (struct weston_surface *surface,
3266 struct desktop_shell *shell)
3268 struct weston_compositor *compositor = shell->compositor;
3270 int range_x, range_y;
3271 int dx, dy, x, y, panel_height;
3272 struct weston_output *output, *target_output = NULL;
3273 struct weston_seat *seat;
3275 /* As a heuristic place the new window on the same output as the
3276 * pointer. Falling back to the output containing 0, 0.
3278 * TODO: Do something clever for touch too?
3280 wl_list_for_each(seat, &compositor->seat_list, link) {
3281 if (seat->pointer) {
3282 ix = wl_fixed_to_int(seat->pointer->x);
3283 iy = wl_fixed_to_int(seat->pointer->y);
3288 wl_list_for_each(output, &compositor->output_list, link) {
3289 if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) {
3290 target_output = output;
3295 if (!target_output) {
3296 weston_surface_set_position(surface, 10 + random() % 400,
3297 10 + random() % 400);
3301 /* Valid range within output where the surface will still be onscreen.
3302 * If this is negative it means that the surface is bigger than
3305 panel_height = get_output_panel_height(shell, target_output);
3306 range_x = target_output->width - surface->geometry.width;
3307 range_y = (target_output->height - panel_height) -
3308 surface->geometry.height;
3311 dx = random() % range_x;
3316 dy = panel_height + random() % range_y;
3320 x = target_output->x + dx;
3321 y = target_output->y + dy;
3323 weston_surface_set_position (surface, x, y);
3327 map(struct desktop_shell *shell, struct weston_surface *surface,
3328 int32_t width, int32_t height, int32_t sx, int32_t sy)
3330 struct weston_compositor *compositor = shell->compositor;
3331 struct shell_surface *shsurf = get_shell_surface(surface);
3332 enum shell_surface_type surface_type = shsurf->type;
3333 struct weston_surface *parent;
3334 struct weston_seat *seat;
3335 struct workspace *ws;
3336 int panel_height = 0;
3337 int32_t surf_x, surf_y;
3339 surface->geometry.width = width;
3340 surface->geometry.height = height;
3341 weston_surface_geometry_dirty(surface);
3343 /* initial positioning, see also configure() */
3344 switch (surface_type) {
3345 case SHELL_SURFACE_TOPLEVEL:
3346 weston_surface_set_initial_position(surface, shell);
3348 case SHELL_SURFACE_FULLSCREEN:
3349 center_on_output(surface, shsurf->fullscreen_output);
3350 shell_map_fullscreen(shsurf);
3352 case SHELL_SURFACE_MAXIMIZED:
3353 /* use surface configure to set the geometry */
3354 panel_height = get_output_panel_height(shell,surface->output);
3355 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
3357 weston_surface_set_position(surface, shsurf->output->x - surf_x,
3358 shsurf->output->y + panel_height - surf_y);
3360 case SHELL_SURFACE_POPUP:
3361 shell_map_popup(shsurf);
3363 case SHELL_SURFACE_NONE:
3364 weston_surface_set_position(surface,
3365 surface->geometry.x + sx,
3366 surface->geometry.y + sy);
3372 /* surface stacking order, see also activate() */
3373 switch (surface_type) {
3374 case SHELL_SURFACE_POPUP:
3375 case SHELL_SURFACE_TRANSIENT:
3376 parent = shsurf->parent;
3377 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
3379 case SHELL_SURFACE_FULLSCREEN:
3380 case SHELL_SURFACE_NONE:
3383 ws = get_current_workspace(shell);
3384 wl_list_insert(&ws->layer.surface_list, &surface->layer_link);
3388 if (surface_type != SHELL_SURFACE_NONE) {
3389 weston_surface_update_transform(surface);
3390 if (surface_type == SHELL_SURFACE_MAXIMIZED)
3391 surface->output = shsurf->output;
3394 switch (surface_type) {
3395 case SHELL_SURFACE_TRANSIENT:
3396 if (shsurf->transient.flags ==
3397 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
3399 case SHELL_SURFACE_TOPLEVEL:
3400 case SHELL_SURFACE_FULLSCREEN:
3401 case SHELL_SURFACE_MAXIMIZED:
3402 if (!shell->locked) {
3403 wl_list_for_each(seat, &compositor->seat_list, link)
3404 activate(shell, surface, seat);
3411 if (surface_type == SHELL_SURFACE_TOPLEVEL)
3413 switch (shell->win_animation_type) {
3414 case ANIMATION_FADE:
3415 weston_fade_run(surface, 0.0, 1.0, 200.0, NULL, NULL);
3417 case ANIMATION_ZOOM:
3418 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
3427 configure(struct desktop_shell *shell, struct weston_surface *surface,
3428 float x, float y, int32_t width, int32_t height)
3430 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
3431 struct shell_surface *shsurf;
3432 int32_t surf_x, surf_y;
3434 shsurf = get_shell_surface(surface);
3436 surface_type = shsurf->type;
3438 weston_surface_configure(surface, x, y, width, height);
3440 switch (surface_type) {
3441 case SHELL_SURFACE_FULLSCREEN:
3442 shell_stack_fullscreen(shsurf);
3443 shell_configure_fullscreen(shsurf);
3445 case SHELL_SURFACE_MAXIMIZED:
3446 /* setting x, y and using configure to change that geometry */
3447 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
3449 surface->geometry.x = surface->output->x - surf_x;
3450 surface->geometry.y = surface->output->y +
3451 get_output_panel_height(shell,surface->output) - surf_y;
3453 case SHELL_SURFACE_TOPLEVEL:
3459 /* XXX: would a fullscreen surface need the same handling? */
3460 if (surface->output) {
3461 weston_surface_update_transform(surface);
3463 if (surface_type == SHELL_SURFACE_MAXIMIZED)
3464 surface->output = shsurf->output;
3469 shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
3471 struct shell_surface *shsurf = get_shell_surface(es);
3472 struct desktop_shell *shell = shsurf->shell;
3474 int type_changed = 0;
3476 if (!weston_surface_is_mapped(es) && !wl_list_empty(&shsurf->popup.grab_link)) {
3477 remove_popup_grab(shsurf);
3483 if (shsurf->next_type != SHELL_SURFACE_NONE &&
3484 shsurf->type != shsurf->next_type) {
3485 set_surface_type(shsurf);
3489 if (!weston_surface_is_mapped(es)) {
3490 map(shell, es, width, height, sx, sy);
3491 } else if (type_changed || sx != 0 || sy != 0 ||
3492 es->geometry.width != width ||
3493 es->geometry.height != height) {
3494 float from_x, from_y;
3497 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
3498 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
3499 configure(shell, es,
3500 es->geometry.x + to_x - from_x,
3501 es->geometry.y + to_y - from_y,
3506 static void launch_desktop_shell_process(void *data);
3509 desktop_shell_sigchld(struct weston_process *process, int status)
3512 struct desktop_shell *shell =
3513 container_of(process, struct desktop_shell, child.process);
3515 shell->child.process.pid = 0;
3516 shell->child.client = NULL; /* already destroyed by wayland */
3518 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
3519 time = weston_compositor_get_time();
3520 if (time - shell->child.deathstamp > 30000) {
3521 shell->child.deathstamp = time;
3522 shell->child.deathcount = 0;
3525 shell->child.deathcount++;
3526 if (shell->child.deathcount > 5) {
3527 weston_log("weston-desktop-shell died, giving up.\n");
3531 weston_log("weston-desktop-shell died, respawning...\n");
3532 launch_desktop_shell_process(shell);
3533 shell_fade_startup(shell);
3537 launch_desktop_shell_process(void *data)
3539 struct desktop_shell *shell = data;
3540 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
3542 shell->child.client = weston_client_launch(shell->compositor,
3543 &shell->child.process,
3545 desktop_shell_sigchld);
3547 if (!shell->child.client)
3548 weston_log("not able to start %s\n", shell_exe);
3552 bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
3554 struct desktop_shell *shell = data;
3556 wl_client_add_object(client, &wl_shell_interface,
3557 &shell_implementation, id, shell);
3561 unbind_desktop_shell(struct wl_resource *resource)
3563 struct desktop_shell *shell = resource->data;
3566 resume_desktop(shell);
3568 shell->child.desktop_shell = NULL;
3569 shell->prepare_event_sent = false;
3574 bind_desktop_shell(struct wl_client *client,
3575 void *data, uint32_t version, uint32_t id)
3577 struct desktop_shell *shell = data;
3578 struct wl_resource *resource;
3580 resource = wl_client_add_object(client, &desktop_shell_interface,
3581 &desktop_shell_implementation,
3584 if (client == shell->child.client) {
3585 resource->destroy = unbind_desktop_shell;
3586 shell->child.desktop_shell = resource;
3589 shell_fade_startup(shell);
3594 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
3595 "permission to bind desktop_shell denied");
3596 wl_resource_destroy(resource);
3600 screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
3602 struct desktop_shell *shell = surface->configure_private;
3607 /* XXX: starting weston-screensaver beforehand does not work */
3611 center_on_output(surface, surface->output);
3613 if (wl_list_empty(&surface->layer_link)) {
3614 wl_list_insert(shell->lock_layer.surface_list.prev,
3615 &surface->layer_link);
3616 weston_surface_update_transform(surface);
3617 wl_event_source_timer_update(shell->screensaver.timer,
3618 shell->screensaver.duration);
3619 shell_fade(shell, FADE_IN);
3624 screensaver_set_surface(struct wl_client *client,
3625 struct wl_resource *resource,
3626 struct wl_resource *surface_resource,
3627 struct wl_resource *output_resource)
3629 struct desktop_shell *shell = resource->data;
3630 struct weston_surface *surface = surface_resource->data;
3631 struct weston_output *output = output_resource->data;
3633 surface->configure = screensaver_configure;
3634 surface->configure_private = shell;
3635 surface->output = output;
3638 static const struct screensaver_interface screensaver_implementation = {
3639 screensaver_set_surface
3643 unbind_screensaver(struct wl_resource *resource)
3645 struct desktop_shell *shell = resource->data;
3647 shell->screensaver.binding = NULL;
3652 bind_screensaver(struct wl_client *client,
3653 void *data, uint32_t version, uint32_t id)
3655 struct desktop_shell *shell = data;
3656 struct wl_resource *resource;
3658 resource = wl_client_add_object(client, &screensaver_interface,
3659 &screensaver_implementation,
3662 if (shell->screensaver.binding == NULL) {
3663 resource->destroy = unbind_screensaver;
3664 shell->screensaver.binding = resource;
3668 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
3669 "interface object already bound");
3670 wl_resource_destroy(resource);
3674 input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
3676 struct input_panel_surface *ip_surface = surface->configure_private;
3677 struct desktop_shell *shell = ip_surface->shell;
3678 struct weston_mode *mode;
3680 uint32_t show_surface = 0;
3685 if (!weston_surface_is_mapped(surface)) {
3686 if (!shell->showing_input_panels)
3692 fprintf(stderr, "%s panel: %d, output: %p\n", __FUNCTION__, ip_surface->panel, ip_surface->output);
3694 if (ip_surface->panel) {
3695 x = shell->text_input.surface->geometry.x + shell->text_input.cursor_rectangle.x2;
3696 y = shell->text_input.surface->geometry.y + shell->text_input.cursor_rectangle.y2;
3698 mode = ip_surface->output->current;
3700 x = ip_surface->output->x + (mode->width - width) / 2;
3701 y = ip_surface->output->y + mode->height - height;
3704 weston_surface_configure(surface,
3709 wl_list_insert(&shell->input_panel_layer.surface_list,
3710 &surface->layer_link);
3711 weston_surface_update_transform(surface);
3712 weston_surface_damage(surface);
3713 weston_slide_run(surface, surface->geometry.height, 0, NULL, NULL);
3718 destroy_input_panel_surface(struct input_panel_surface *input_panel_surface)
3720 wl_list_remove(&input_panel_surface->surface_destroy_listener.link);
3721 wl_list_remove(&input_panel_surface->link);
3723 input_panel_surface->surface->configure = NULL;
3725 free(input_panel_surface);
3728 static struct input_panel_surface *
3729 get_input_panel_surface(struct weston_surface *surface)
3731 if (surface->configure == input_panel_configure) {
3732 return surface->configure_private;
3739 input_panel_handle_surface_destroy(struct wl_listener *listener, void *data)
3741 struct input_panel_surface *ipsurface = container_of(listener,
3742 struct input_panel_surface,
3743 surface_destroy_listener);
3745 if (ipsurface->resource.client) {
3746 wl_resource_destroy(&ipsurface->resource);
3748 wl_signal_emit(&ipsurface->resource.destroy_signal,
3749 &ipsurface->resource);
3750 destroy_input_panel_surface(ipsurface);
3753 static struct input_panel_surface *
3754 create_input_panel_surface(struct desktop_shell *shell,
3755 struct weston_surface *surface)
3757 struct input_panel_surface *input_panel_surface;
3759 input_panel_surface = calloc(1, sizeof *input_panel_surface);
3760 if (!input_panel_surface)
3763 surface->configure = input_panel_configure;
3764 surface->configure_private = input_panel_surface;
3766 input_panel_surface->shell = shell;
3768 input_panel_surface->surface = surface;
3770 wl_signal_init(&input_panel_surface->resource.destroy_signal);
3771 input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy;
3772 wl_signal_add(&surface->resource.destroy_signal,
3773 &input_panel_surface->surface_destroy_listener);
3775 wl_list_init(&input_panel_surface->link);
3777 return input_panel_surface;
3781 input_panel_surface_set_toplevel(struct wl_client *client,
3782 struct wl_resource *resource,
3783 struct wl_resource *output_resource,
3786 struct input_panel_surface *input_panel_surface = resource->data;
3787 struct desktop_shell *shell = input_panel_surface->shell;
3789 wl_list_insert(&shell->input_panel.surfaces,
3790 &input_panel_surface->link);
3792 input_panel_surface->output = output_resource->data;
3793 input_panel_surface->panel = 0;
3795 fprintf(stderr, "%s panel: %d, output: %p\n", __FUNCTION__,
3796 input_panel_surface->panel,
3797 input_panel_surface->output);
3801 input_panel_surface_set_overlay_panel(struct wl_client *client,
3802 struct wl_resource *resource)
3804 struct input_panel_surface *input_panel_surface = resource->data;
3805 struct desktop_shell *shell = input_panel_surface->shell;
3807 wl_list_insert(&shell->input_panel.surfaces,
3808 &input_panel_surface->link);
3810 input_panel_surface->panel = 1;
3813 static const struct wl_input_panel_surface_interface input_panel_surface_implementation = {
3814 input_panel_surface_set_toplevel,
3815 input_panel_surface_set_overlay_panel
3819 destroy_input_panel_surface_resource(struct wl_resource *resource)
3821 struct input_panel_surface *ipsurf = resource->data;
3823 destroy_input_panel_surface(ipsurf);
3827 input_panel_get_input_panel_surface(struct wl_client *client,
3828 struct wl_resource *resource,
3830 struct wl_resource *surface_resource)
3832 struct weston_surface *surface = surface_resource->data;
3833 struct desktop_shell *shell = resource->data;
3834 struct input_panel_surface *ipsurf;
3836 if (get_input_panel_surface(surface)) {
3837 wl_resource_post_error(surface_resource,
3838 WL_DISPLAY_ERROR_INVALID_OBJECT,
3839 "wl_input_panel::get_input_panel_surface already requested");
3843 ipsurf = create_input_panel_surface(shell, surface);
3845 wl_resource_post_error(surface_resource,
3846 WL_DISPLAY_ERROR_INVALID_OBJECT,
3847 "surface->configure already set");
3851 ipsurf->resource.destroy = destroy_input_panel_surface_resource;
3852 ipsurf->resource.object.id = id;
3853 ipsurf->resource.object.interface = &wl_input_panel_surface_interface;
3854 ipsurf->resource.object.implementation =
3855 (void (**)(void)) &input_panel_surface_implementation;
3856 ipsurf->resource.data = ipsurf;
3858 wl_client_add_resource(client, &ipsurf->resource);
3861 static const struct wl_input_panel_interface input_panel_implementation = {
3862 input_panel_get_input_panel_surface
3866 unbind_input_panel(struct wl_resource *resource)
3868 struct desktop_shell *shell = resource->data;
3870 shell->input_panel.binding = NULL;
3875 bind_input_panel(struct wl_client *client,
3876 void *data, uint32_t version, uint32_t id)
3878 struct desktop_shell *shell = data;
3879 struct wl_resource *resource;
3881 resource = wl_client_add_object(client, &wl_input_panel_interface,
3882 &input_panel_implementation,
3885 if (shell->input_panel.binding == NULL) {
3886 resource->destroy = unbind_input_panel;
3887 shell->input_panel.binding = resource;
3891 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
3892 "interface object already bound");
3893 wl_resource_destroy(resource);
3897 struct desktop_shell *shell;
3898 struct weston_surface *current;
3899 struct wl_listener listener;
3900 struct weston_keyboard_grab grab;
3904 switcher_next(struct switcher *switcher)
3906 struct weston_surface *surface;
3907 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
3908 struct shell_surface *shsurf;
3909 struct workspace *ws = get_current_workspace(switcher->shell);
3911 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
3912 switch (get_shell_surface_type(surface)) {
3913 case SHELL_SURFACE_TOPLEVEL:
3914 case SHELL_SURFACE_FULLSCREEN:
3915 case SHELL_SURFACE_MAXIMIZED:
3918 if (prev == switcher->current)
3921 surface->alpha = 0.25;
3922 weston_surface_geometry_dirty(surface);
3923 weston_surface_damage(surface);
3929 if (is_black_surface(surface, NULL)) {
3930 surface->alpha = 0.25;
3931 weston_surface_geometry_dirty(surface);
3932 weston_surface_damage(surface);
3942 wl_list_remove(&switcher->listener.link);
3943 wl_signal_add(&next->resource.destroy_signal, &switcher->listener);
3945 switcher->current = next;
3948 shsurf = get_shell_surface(switcher->current);
3949 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
3950 shsurf->fullscreen.black_surface->alpha = 1.0;
3954 switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
3956 struct switcher *switcher =
3957 container_of(listener, struct switcher, listener);
3959 switcher_next(switcher);
3963 switcher_destroy(struct switcher *switcher)
3965 struct weston_surface *surface;
3966 struct weston_keyboard *keyboard = switcher->grab.keyboard;
3967 struct workspace *ws = get_current_workspace(switcher->shell);
3969 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
3970 surface->alpha = 1.0;
3971 weston_surface_damage(surface);
3974 if (switcher->current)
3975 activate(switcher->shell, switcher->current,
3976 (struct weston_seat *) keyboard->seat);
3977 wl_list_remove(&switcher->listener.link);
3978 weston_keyboard_end_grab(keyboard);
3979 if (keyboard->input_method_resource)
3980 keyboard->grab = &keyboard->input_method_grab;
3985 switcher_key(struct weston_keyboard_grab *grab,
3986 uint32_t time, uint32_t key, uint32_t state_w)
3988 struct switcher *switcher = container_of(grab, struct switcher, grab);
3989 enum wl_keyboard_key_state state = state_w;
3991 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
3992 switcher_next(switcher);
3996 switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
3997 uint32_t mods_depressed, uint32_t mods_latched,
3998 uint32_t mods_locked, uint32_t group)
4000 struct switcher *switcher = container_of(grab, struct switcher, grab);
4001 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
4003 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0)
4004 switcher_destroy(switcher);
4007 static const struct weston_keyboard_grab_interface switcher_grab = {
4013 switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
4016 struct desktop_shell *shell = data;
4017 struct switcher *switcher;
4019 switcher = malloc(sizeof *switcher);
4020 switcher->shell = shell;
4021 switcher->current = NULL;
4022 switcher->listener.notify = switcher_handle_surface_destroy;
4023 wl_list_init(&switcher->listener.link);
4025 lower_fullscreen_layer(switcher->shell);
4026 switcher->grab.interface = &switcher_grab;
4027 weston_keyboard_start_grab(seat->keyboard, &switcher->grab);
4028 weston_keyboard_set_focus(seat->keyboard, NULL);
4029 switcher_next(switcher);
4033 backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
4036 struct weston_compositor *compositor = data;
4037 struct weston_output *output;
4038 long backlight_new = 0;
4040 /* TODO: we're limiting to simple use cases, where we assume just
4041 * control on the primary display. We'd have to extend later if we
4042 * ever get support for setting backlights on random desktop LCD
4044 output = get_default_output(compositor);
4048 if (!output->set_backlight)
4051 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
4052 backlight_new = output->backlight_current - 25;
4053 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
4054 backlight_new = output->backlight_current + 25;
4056 if (backlight_new < 5)
4058 if (backlight_new > 255)
4059 backlight_new = 255;
4061 output->backlight_current = backlight_new;
4062 output->set_backlight(output, output->backlight_current);
4065 struct debug_binding_grab {
4066 struct weston_keyboard_grab grab;
4067 struct weston_seat *seat;
4069 int key_released[2];
4073 debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
4074 uint32_t key, uint32_t state)
4076 struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
4077 struct wl_resource *resource;
4078 struct wl_display *display;
4080 int send = 0, terminate = 0;
4081 int check_binding = 1;
4084 if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
4085 /* Do not run bindings on key releases */
4088 for (i = 0; i < 2; i++)
4089 if (key == db->key[i])
4090 db->key_released[i] = 1;
4092 if (db->key_released[0] && db->key_released[1]) {
4093 /* All key releases been swalled so end the grab */
4095 } else if (key != db->key[0] && key != db->key[1]) {
4096 /* Should not swallow release of other keys */
4099 } else if (key == db->key[0] && !db->key_released[0]) {
4100 /* Do not check bindings for the first press of the binding
4101 * key. This allows it to be used as a debug shortcut.
4102 * We still need to swallow this event. */
4104 } else if (db->key[1]) {
4105 /* If we already ran a binding don't process another one since
4106 * we can't keep track of all the binding keys that were
4107 * pressed in order to swallow the release events. */
4112 if (check_binding) {
4113 struct weston_compositor *ec = db->seat->compositor;
4115 if (weston_compositor_run_debug_binding(ec, db->seat, time,
4117 /* We ran a binding so swallow the press and keep the
4118 * grab to swallow the released too. */
4123 /* Terminate the grab since the key pressed is not a
4124 * debug binding key. */
4131 resource = grab->keyboard->focus_resource;
4134 display = wl_client_get_display(resource->client);
4135 serial = wl_display_next_serial(display);
4136 wl_keyboard_send_key(resource, serial, time, key, state);
4141 weston_keyboard_end_grab(grab->keyboard);
4142 if (grab->keyboard->input_method_resource)
4143 grab->keyboard->grab = &grab->keyboard->input_method_grab;
4149 debug_binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial,
4150 uint32_t mods_depressed, uint32_t mods_latched,
4151 uint32_t mods_locked, uint32_t group)
4153 struct wl_resource *resource;
4155 resource = grab->keyboard->focus_resource;
4159 wl_keyboard_send_modifiers(resource, serial, mods_depressed,
4160 mods_latched, mods_locked, group);
4163 struct weston_keyboard_grab_interface debug_binding_keyboard_grab = {
4165 debug_binding_modifiers
4169 debug_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
4171 struct debug_binding_grab *grab;
4173 grab = calloc(1, sizeof *grab);
4177 grab->seat = (struct weston_seat *) seat;
4179 grab->grab.interface = &debug_binding_keyboard_grab;
4180 weston_keyboard_start_grab(seat->keyboard, &grab->grab);
4184 force_kill_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
4187 struct weston_surface *focus_surface;
4188 struct wl_client *client;
4189 struct desktop_shell *shell = data;
4190 struct weston_compositor *compositor = shell->compositor;
4193 focus_surface = seat->keyboard->focus;
4197 wl_signal_emit(&compositor->kill_signal, focus_surface);
4199 client = focus_surface->resource.client;
4200 wl_client_get_credentials(client, &pid, NULL, NULL);
4202 /* Skip clients that we launched ourselves (the credentials of
4203 * the socketpair is ours) */
4204 if (pid == getpid())
4211 workspace_up_binding(struct weston_seat *seat, uint32_t time,
4212 uint32_t key, void *data)
4214 struct desktop_shell *shell = data;
4215 unsigned int new_index = shell->workspaces.current;
4222 change_workspace(shell, new_index);
4226 workspace_down_binding(struct weston_seat *seat, uint32_t time,
4227 uint32_t key, void *data)
4229 struct desktop_shell *shell = data;
4230 unsigned int new_index = shell->workspaces.current;
4234 if (new_index < shell->workspaces.num - 1)
4237 change_workspace(shell, new_index);
4241 workspace_f_binding(struct weston_seat *seat, uint32_t time,
4242 uint32_t key, void *data)
4244 struct desktop_shell *shell = data;
4245 unsigned int new_index;
4249 new_index = key - KEY_F1;
4250 if (new_index >= shell->workspaces.num)
4251 new_index = shell->workspaces.num - 1;
4253 change_workspace(shell, new_index);
4257 workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time,
4258 uint32_t key, void *data)
4260 struct desktop_shell *shell = data;
4261 unsigned int new_index = shell->workspaces.current;
4269 take_surface_to_workspace_by_seat(shell, seat, new_index);
4273 workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time,
4274 uint32_t key, void *data)
4276 struct desktop_shell *shell = data;
4277 unsigned int new_index = shell->workspaces.current;
4282 if (new_index < shell->workspaces.num - 1)
4285 take_surface_to_workspace_by_seat(shell, seat, new_index);
4289 shell_destroy(struct wl_listener *listener, void *data)
4291 struct desktop_shell *shell =
4292 container_of(listener, struct desktop_shell, destroy_listener);
4293 struct workspace **ws;
4295 if (shell->child.client)
4296 wl_client_destroy(shell->child.client);
4298 wl_list_remove(&shell->idle_listener.link);
4299 wl_list_remove(&shell->wake_listener.link);
4300 wl_list_remove(&shell->show_input_panel_listener.link);
4301 wl_list_remove(&shell->hide_input_panel_listener.link);
4303 wl_array_for_each(ws, &shell->workspaces.array)
4304 workspace_destroy(*ws);
4305 wl_array_release(&shell->workspaces.array);
4307 free(shell->screensaver.path);
4312 shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
4315 int i, num_workspace_bindings;
4317 /* fixed bindings */
4318 weston_compositor_add_key_binding(ec, KEY_BACKSPACE,
4319 MODIFIER_CTRL | MODIFIER_ALT,
4320 terminate_binding, ec);
4321 weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
4322 click_to_activate_binding,
4324 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
4325 MODIFIER_SUPER | MODIFIER_ALT,
4326 surface_opacity_binding, NULL);
4327 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
4328 MODIFIER_SUPER, zoom_axis_binding,
4331 /* configurable bindings */
4332 mod = shell->binding_modifier;
4333 weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod,
4334 zoom_key_binding, NULL);
4335 weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod,
4336 zoom_key_binding, NULL);
4337 weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding,
4339 weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod,
4340 resize_binding, shell);
4342 if (ec->capabilities & WESTON_CAP_ROTATION_ANY)
4343 weston_compositor_add_button_binding(ec, BTN_RIGHT, mod,
4344 rotate_binding, NULL);
4346 weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding,
4348 weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding,
4350 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0,
4351 backlight_binding, ec);
4352 weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding,
4354 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0,
4355 backlight_binding, ec);
4356 weston_compositor_add_key_binding(ec, KEY_K, mod,
4357 force_kill_binding, shell);
4358 weston_compositor_add_key_binding(ec, KEY_UP, mod,
4359 workspace_up_binding, shell);
4360 weston_compositor_add_key_binding(ec, KEY_DOWN, mod,
4361 workspace_down_binding, shell);
4362 weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT,
4363 workspace_move_surface_up_binding,
4365 weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT,
4366 workspace_move_surface_down_binding,
4369 /* Add bindings for mod+F[1-6] for workspace 1 to 6. */
4370 if (shell->workspaces.num > 1) {
4371 num_workspace_bindings = shell->workspaces.num;
4372 if (num_workspace_bindings > 6)
4373 num_workspace_bindings = 6;
4374 for (i = 0; i < num_workspace_bindings; i++)
4375 weston_compositor_add_key_binding(ec, KEY_F1 + i, mod,
4376 workspace_f_binding,
4380 /* Debug bindings */
4381 weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT,
4382 debug_binding, shell);
4386 module_init(struct weston_compositor *ec,
4387 int *argc, char *argv[])
4389 struct weston_seat *seat;
4390 struct desktop_shell *shell;
4391 struct workspace **pws;
4393 struct wl_event_loop *loop;
4395 shell = malloc(sizeof *shell);
4399 memset(shell, 0, sizeof *shell);
4400 shell->compositor = ec;
4402 shell->destroy_listener.notify = shell_destroy;
4403 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
4404 shell->idle_listener.notify = idle_handler;
4405 wl_signal_add(&ec->idle_signal, &shell->idle_listener);
4406 shell->wake_listener.notify = wake_handler;
4407 wl_signal_add(&ec->wake_signal, &shell->wake_listener);
4408 shell->show_input_panel_listener.notify = show_input_panels;
4409 wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener);
4410 shell->hide_input_panel_listener.notify = hide_input_panels;
4411 wl_signal_add(&ec->hide_input_panel_signal, &shell->hide_input_panel_listener);
4412 shell->update_input_panel_listener.notify = update_input_panels;
4413 wl_signal_add(&ec->update_input_panel_signal, &shell->update_input_panel_listener);
4414 ec->ping_handler = ping_handler;
4415 ec->shell_interface.shell = shell;
4416 ec->shell_interface.create_shell_surface = create_shell_surface;
4417 ec->shell_interface.set_toplevel = set_toplevel;
4418 ec->shell_interface.set_transient = set_transient;
4419 ec->shell_interface.set_fullscreen = set_fullscreen;
4420 ec->shell_interface.move = surface_move;
4421 ec->shell_interface.resize = surface_resize;
4423 wl_list_init(&shell->input_panel.surfaces);
4425 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
4426 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
4427 weston_layer_init(&shell->background_layer, &shell->panel_layer.link);
4428 weston_layer_init(&shell->lock_layer, NULL);
4429 weston_layer_init(&shell->input_panel_layer, NULL);
4431 wl_array_init(&shell->workspaces.array);
4432 wl_list_init(&shell->workspaces.client_list);
4434 shell_configuration(shell, ec->config_fd);
4436 for (i = 0; i < shell->workspaces.num; i++) {
4437 pws = wl_array_add(&shell->workspaces.array, sizeof *pws);
4441 *pws = workspace_create();
4445 activate_workspace(shell, 0);
4447 wl_list_init(&shell->workspaces.anim_sticky_list);
4448 wl_list_init(&shell->workspaces.animation.link);
4449 shell->workspaces.animation.frame = animate_workspace_change_frame;
4451 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
4452 shell, bind_shell) == NULL)
4455 if (wl_display_add_global(ec->wl_display,
4456 &desktop_shell_interface,
4457 shell, bind_desktop_shell) == NULL)
4460 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
4461 shell, bind_screensaver) == NULL)
4464 if (wl_display_add_global(ec->wl_display, &wl_input_panel_interface,
4465 shell, bind_input_panel) == NULL)
4468 if (wl_display_add_global(ec->wl_display, &workspace_manager_interface,
4469 shell, bind_workspace_manager) == NULL)
4472 shell->child.deathstamp = weston_compositor_get_time();
4474 loop = wl_display_get_event_loop(ec->wl_display);
4475 wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell);
4477 shell->screensaver.timer =
4478 wl_event_loop_add_timer(loop, screensaver_timeout, shell);
4480 wl_list_for_each(seat, &ec->seat_list, link)
4481 create_pointer_focus_listener(seat);
4483 shell_add_bindings(ec, shell);
4485 shell_fade_init(shell);