2 * Copyright © 2010-2012 Intel Corporation
3 * Copyright © 2011-2012 Collabora, Ltd.
4 * Copyright © 2013 Raspberry Pi Foundation
6 * Permission to use, copy, modify, distribute, and sell this software and
7 * its documentation for any purpose is hereby granted without fee, provided
8 * that the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of the copyright holders not be used in
11 * advertising or publicity pertaining to distribution of the software
12 * without specific, written prior permission. The copyright holders make
13 * no representations about the suitability of this software for any
14 * purpose. It is provided "as is" without express or implied warranty.
16 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
21 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 #include <linux/input.h>
36 #include <sys/types.h>
38 #include "compositor.h"
39 #include "desktop-shell-server-protocol.h"
40 #include "input-method-server-protocol.h"
41 #include "workspaces-server-protocol.h"
42 #include "../shared/config-parser.h"
44 #define DEFAULT_NUM_WORKSPACES 1
45 #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200
60 enum exposay_target_state {
61 EXPOSAY_TARGET_OVERVIEW, /* show all windows */
62 EXPOSAY_TARGET_CANCEL, /* return to normal, same focus */
63 EXPOSAY_TARGET_SWITCH, /* return to normal, switch focus */
66 enum exposay_layout_state {
67 EXPOSAY_LAYOUT_INACTIVE = 0, /* normal desktop */
68 EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE, /* in transition to normal */
69 EXPOSAY_LAYOUT_OVERVIEW, /* show all windows */
70 EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW, /* in transition to all windows */
74 struct weston_seat *seat;
76 struct weston_surface *keyboard_focus;
78 struct wl_listener seat_destroy_listener;
79 struct wl_listener surface_destroy_listener;
82 struct focus_surface {
83 struct weston_surface *surface;
84 struct weston_view *view;
85 struct weston_transform workspace_transform;
89 struct weston_layer layer;
91 struct wl_list focus_list;
92 struct wl_listener seat_destroyed_listener;
94 struct focus_surface *fsurf_front;
95 struct focus_surface *fsurf_back;
96 struct weston_view_animation *focus_animation;
99 struct input_panel_surface {
100 struct wl_resource *resource;
101 struct wl_signal destroy_signal;
103 struct desktop_shell *shell;
106 struct weston_surface *surface;
107 struct weston_view *view;
108 struct wl_listener surface_destroy_listener;
110 struct weston_output *output;
114 struct shell_output {
115 struct desktop_shell *shell;
116 struct weston_output *output;
117 struct wl_listener destroy_listener;
121 struct desktop_shell {
122 struct weston_compositor *compositor;
124 struct wl_listener idle_listener;
125 struct wl_listener wake_listener;
126 struct wl_listener destroy_listener;
127 struct wl_listener show_input_panel_listener;
128 struct wl_listener hide_input_panel_listener;
129 struct wl_listener update_input_panel_listener;
131 struct weston_layer fullscreen_layer;
132 struct weston_layer panel_layer;
133 struct weston_layer background_layer;
134 struct weston_layer lock_layer;
135 struct weston_layer input_panel_layer;
137 struct wl_listener pointer_focus_listener;
138 struct weston_surface *grab_surface;
141 struct weston_process process;
142 struct wl_client *client;
143 struct wl_resource *desktop_shell;
150 bool showing_input_panels;
151 bool prepare_event_sent;
154 struct weston_surface *surface;
155 pixman_box32_t cursor_rectangle;
158 struct weston_surface *lock_surface;
159 struct wl_listener lock_surface_listener;
162 struct wl_array array;
163 unsigned int current;
166 struct wl_list client_list;
168 struct weston_animation animation;
169 struct wl_list anim_sticky_list;
171 uint32_t anim_timestamp;
173 struct workspace *anim_from;
174 struct workspace *anim_to;
180 struct wl_resource *binding;
181 struct weston_process process;
182 struct wl_event_source *timer;
186 struct wl_resource *binding;
187 struct wl_list surfaces;
191 struct weston_view *view;
192 struct weston_view_animation *animation;
194 struct wl_event_source *startup_timer;
198 /* XXX: Make these exposay_surfaces. */
199 struct weston_view *focus_prev;
200 struct weston_view *focus_current;
201 struct weston_view *clicked;
202 struct workspace *workspace;
203 struct weston_seat *seat;
204 struct wl_list surface_list;
206 struct weston_keyboard_grab grab_kbd;
207 struct weston_pointer_grab grab_ptr;
209 enum exposay_target_state state_target;
210 enum exposay_layout_state state_cur;
211 int in_flight; /* number of animations still running */
228 uint32_t binding_modifier;
229 enum animation_type win_animation_type;
230 enum animation_type startup_animation_type;
231 enum animation_type focus_animation_type;
233 struct wl_listener output_create_listener;
234 struct wl_list output_list;
239 enum shell_surface_type {
241 SHELL_SURFACE_TOPLEVEL,
242 SHELL_SURFACE_TRANSIENT,
243 SHELL_SURFACE_FULLSCREEN,
244 SHELL_SURFACE_MAXIMIZED,
246 SHELL_SURFACE_XWAYLAND
250 struct wl_event_source *source;
254 struct shell_surface {
255 struct wl_resource *resource;
256 struct wl_signal destroy_signal;
258 struct weston_surface *surface;
259 struct weston_view *view;
260 struct wl_listener surface_destroy_listener;
261 struct weston_surface *parent;
262 struct desktop_shell *shell;
264 enum shell_surface_type type, next_type;
266 int32_t saved_x, saved_y;
267 bool saved_position_valid;
268 bool saved_rotation_valid;
269 int unresponsive, grabbed;
272 struct weston_transform transform;
273 struct weston_matrix rotation;
277 struct wl_list grab_link;
279 struct shell_seat *shseat;
289 enum wl_shell_surface_fullscreen_method type;
290 struct weston_transform transform; /* matrix from x, y */
292 struct weston_view *black_view;
295 struct ping_timer *ping_timer;
297 struct weston_transform workspace_transform;
299 struct weston_output *fullscreen_output;
300 struct weston_output *output;
303 const struct weston_shell_client *client;
307 struct weston_pointer_grab grab;
308 struct shell_surface *shsurf;
309 struct wl_listener shsurf_destroy_listener;
312 struct shell_touch_grab {
313 struct weston_touch_grab grab;
314 struct shell_surface *shsurf;
315 struct wl_listener shsurf_destroy_listener;
316 struct weston_touch *touch;
319 struct weston_move_grab {
320 struct shell_grab base;
324 struct weston_touch_move_grab {
325 struct shell_touch_grab base;
330 struct shell_grab base;
331 struct weston_matrix rotation;
339 struct weston_seat *seat;
340 struct wl_listener seat_destroy_listener;
343 struct weston_pointer_grab grab;
344 struct wl_list surfaces_list;
345 struct wl_client *client;
351 activate(struct desktop_shell *shell, struct weston_surface *es,
352 struct weston_seat *seat);
354 static struct workspace *
355 get_current_workspace(struct desktop_shell *shell);
357 static struct shell_surface *
358 get_shell_surface(struct weston_surface *surface);
360 static struct desktop_shell *
361 shell_surface_get_shell(struct shell_surface *shsurf);
364 surface_rotate(struct shell_surface *surface, struct weston_seat *seat);
367 shell_fade_startup(struct desktop_shell *shell);
369 static struct shell_seat *
370 get_shell_seat(struct weston_seat *seat);
373 shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
375 struct desktop_shell *shell;
376 struct weston_view *top_fs_ev;
378 shell = shell_surface_get_shell(shsurf);
380 if (wl_list_empty(&shell->fullscreen_layer.view_list))
383 top_fs_ev = container_of(shell->fullscreen_layer.view_list.next,
386 return (shsurf == get_shell_surface(top_fs_ev->surface));
390 destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
392 struct shell_grab *grab;
394 grab = container_of(listener, struct shell_grab,
395 shsurf_destroy_listener);
400 static struct weston_view *
401 get_default_view(struct weston_surface *surface)
403 struct shell_surface *shsurf;
404 struct weston_view *view;
406 if (!surface || wl_list_empty(&surface->views))
409 shsurf = get_shell_surface(surface);
413 wl_list_for_each(view, &surface->views, surface_link)
414 if (weston_view_is_mapped(view))
417 return container_of(surface->views.next, struct weston_view, surface_link);
421 popup_grab_end(struct weston_pointer *pointer);
424 shell_grab_start(struct shell_grab *grab,
425 const struct weston_pointer_grab_interface *interface,
426 struct shell_surface *shsurf,
427 struct weston_pointer *pointer,
428 enum desktop_shell_cursor cursor)
430 struct desktop_shell *shell = shsurf->shell;
432 popup_grab_end(pointer);
434 grab->grab.interface = interface;
435 grab->shsurf = shsurf;
436 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
437 wl_signal_add(&shsurf->destroy_signal,
438 &grab->shsurf_destroy_listener);
441 weston_pointer_start_grab(pointer, &grab->grab);
442 if (shell->child.desktop_shell) {
443 desktop_shell_send_grab_cursor(shell->child.desktop_shell,
445 weston_pointer_set_focus(pointer,
446 get_default_view(shell->grab_surface),
447 wl_fixed_from_int(0),
448 wl_fixed_from_int(0));
453 shell_grab_end(struct shell_grab *grab)
456 wl_list_remove(&grab->shsurf_destroy_listener.link);
457 grab->shsurf->grabbed = 0;
460 weston_pointer_end_grab(grab->grab.pointer);
464 shell_touch_grab_start(struct shell_touch_grab *grab,
465 const struct weston_touch_grab_interface *interface,
466 struct shell_surface *shsurf,
467 struct weston_touch *touch)
469 struct desktop_shell *shell = shsurf->shell;
471 grab->grab.interface = interface;
472 grab->shsurf = shsurf;
473 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
474 wl_signal_add(&shsurf->destroy_signal,
475 &grab->shsurf_destroy_listener);
480 weston_touch_start_grab(touch, &grab->grab);
481 if (shell->child.desktop_shell)
482 weston_touch_set_focus(touch->seat,
483 get_default_view(shell->grab_surface));
487 shell_touch_grab_end(struct shell_touch_grab *grab)
490 wl_list_remove(&grab->shsurf_destroy_listener.link);
491 grab->shsurf->grabbed = 0;
494 weston_touch_end_grab(grab->touch);
498 center_on_output(struct weston_view *view,
499 struct weston_output *output);
501 static enum weston_keyboard_modifier
502 get_modifier(char *modifier)
505 return MODIFIER_SUPER;
507 if (!strcmp("ctrl", modifier))
508 return MODIFIER_CTRL;
509 else if (!strcmp("alt", modifier))
511 else if (!strcmp("super", modifier))
512 return MODIFIER_SUPER;
514 return MODIFIER_SUPER;
517 static enum animation_type
518 get_animation_type(char *animation)
520 if (!strcmp("zoom", animation))
521 return ANIMATION_ZOOM;
522 else if (!strcmp("fade", animation))
523 return ANIMATION_FADE;
524 else if (!strcmp("dim-layer", animation))
525 return ANIMATION_DIM_LAYER;
527 return ANIMATION_NONE;
531 shell_configuration(struct desktop_shell *shell)
533 struct weston_config_section *section;
537 section = weston_config_get_section(shell->compositor->config,
538 "screensaver", NULL, NULL);
539 weston_config_section_get_string(section,
540 "path", &shell->screensaver.path, NULL);
541 weston_config_section_get_int(section, "duration", &duration, 60);
542 shell->screensaver.duration = duration * 1000;
544 section = weston_config_get_section(shell->compositor->config,
545 "shell", NULL, NULL);
546 weston_config_section_get_string(section,
547 "client", &s, LIBEXECDIR "/weston-desktop-shell");
549 weston_config_section_get_string(section,
550 "binding-modifier", &s, "super");
551 shell->binding_modifier = get_modifier(s);
553 weston_config_section_get_string(section, "animation", &s, "none");
554 shell->win_animation_type = get_animation_type(s);
556 weston_config_section_get_string(section,
557 "startup-animation", &s, "fade");
558 shell->startup_animation_type = get_animation_type(s);
560 if (shell->startup_animation_type == ANIMATION_ZOOM)
561 shell->startup_animation_type = ANIMATION_NONE;
562 weston_config_section_get_string(section, "focus-animation", &s, "none");
563 shell->focus_animation_type = get_animation_type(s);
565 weston_config_section_get_uint(section, "num-workspaces",
566 &shell->workspaces.num,
567 DEFAULT_NUM_WORKSPACES);
570 static struct weston_output *
571 get_default_output(struct weston_compositor *compositor)
573 return container_of(compositor->output_list.next,
574 struct weston_output, link);
578 /* no-op func for checking focus surface */
580 focus_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy,
581 int32_t width, int32_t height)
585 static struct focus_surface *
586 get_focus_surface(struct weston_surface *surface)
588 if (surface->configure == focus_surface_configure)
589 return surface->configure_private;
595 is_focus_surface (struct weston_surface *es)
597 return (es->configure == focus_surface_configure);
601 is_focus_view (struct weston_view *view)
603 return is_focus_surface (view->surface);
606 static struct focus_surface *
607 create_focus_surface(struct weston_compositor *ec,
608 struct weston_output *output)
610 struct focus_surface *fsurf = NULL;
611 struct weston_surface *surface = NULL;
613 fsurf = malloc(sizeof *fsurf);
617 fsurf->surface = weston_surface_create(ec);
618 surface = fsurf->surface;
619 if (surface == NULL) {
624 surface->configure = focus_surface_configure;
625 surface->output = output;
626 surface->configure_private = fsurf;
628 fsurf->view = weston_view_create (surface);
629 fsurf->view->output = output;
631 weston_view_configure(fsurf->view, output->x, output->y,
632 output->width, output->height);
633 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
634 pixman_region32_fini(&surface->opaque);
635 pixman_region32_init_rect(&surface->opaque, output->x, output->y,
636 output->width, output->height);
637 pixman_region32_fini(&surface->input);
638 pixman_region32_init(&surface->input);
640 wl_list_init(&fsurf->workspace_transform.link);
646 focus_surface_destroy(struct focus_surface *fsurf)
648 weston_surface_destroy(fsurf->surface);
653 focus_animation_done(struct weston_view_animation *animation, void *data)
655 struct workspace *ws = data;
657 ws->focus_animation = NULL;
661 focus_state_destroy(struct focus_state *state)
663 wl_list_remove(&state->seat_destroy_listener.link);
664 wl_list_remove(&state->surface_destroy_listener.link);
669 focus_state_seat_destroy(struct wl_listener *listener, void *data)
671 struct focus_state *state = container_of(listener,
673 seat_destroy_listener);
675 wl_list_remove(&state->link);
676 focus_state_destroy(state);
680 focus_state_surface_destroy(struct wl_listener *listener, void *data)
682 struct focus_state *state = container_of(listener,
684 surface_destroy_listener);
685 struct desktop_shell *shell;
686 struct weston_surface *main_surface, *next;
687 struct weston_view *view;
689 main_surface = weston_surface_get_main_surface(state->keyboard_focus);
692 wl_list_for_each(view, &state->ws->layer.view_list, layer_link) {
693 if (view->surface == main_surface)
695 if (is_focus_view(view))
698 next = view->surface;
702 /* if the focus was a sub-surface, activate its main surface */
703 if (main_surface != state->keyboard_focus)
706 shell = state->seat->compositor->shell_interface.shell;
708 state->keyboard_focus = NULL;
709 activate(shell, next, state->seat);
711 if (shell->focus_animation_type == ANIMATION_DIM_LAYER) {
712 if (state->ws->focus_animation)
713 weston_view_animation_destroy(state->ws->focus_animation);
715 state->ws->focus_animation = weston_fade_run(
716 state->ws->fsurf_front->view,
717 state->ws->fsurf_front->view->alpha, 0.0, 300,
718 focus_animation_done, state->ws);
721 wl_list_remove(&state->link);
722 focus_state_destroy(state);
726 static struct focus_state *
727 focus_state_create(struct weston_seat *seat, struct workspace *ws)
729 struct focus_state *state;
731 state = malloc(sizeof *state);
735 state->keyboard_focus = NULL;
738 wl_list_insert(&ws->focus_list, &state->link);
740 state->seat_destroy_listener.notify = focus_state_seat_destroy;
741 state->surface_destroy_listener.notify = focus_state_surface_destroy;
742 wl_signal_add(&seat->destroy_signal,
743 &state->seat_destroy_listener);
744 wl_list_init(&state->surface_destroy_listener.link);
749 static struct focus_state *
750 ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat)
752 struct workspace *ws = get_current_workspace(shell);
753 struct focus_state *state;
755 wl_list_for_each(state, &ws->focus_list, link)
756 if (state->seat == seat)
759 if (&state->link == &ws->focus_list)
760 state = focus_state_create(seat, ws);
766 restore_focus_state(struct desktop_shell *shell, struct workspace *ws)
768 struct focus_state *state, *next;
769 struct weston_surface *surface;
771 wl_list_for_each_safe(state, next, &ws->focus_list, link) {
772 surface = state->keyboard_focus;
774 weston_keyboard_set_focus(state->seat->keyboard, surface);
779 replace_focus_state(struct desktop_shell *shell, struct workspace *ws,
780 struct weston_seat *seat)
782 struct focus_state *state;
783 struct weston_surface *surface;
785 wl_list_for_each(state, &ws->focus_list, link) {
786 if (state->seat == seat) {
787 surface = seat->keyboard->focus;
788 state->keyboard_focus = surface;
795 drop_focus_state(struct desktop_shell *shell, struct workspace *ws,
796 struct weston_surface *surface)
798 struct focus_state *state;
800 wl_list_for_each(state, &ws->focus_list, link)
801 if (state->keyboard_focus == surface)
802 state->keyboard_focus = NULL;
806 animate_focus_change(struct desktop_shell *shell, struct workspace *ws,
807 struct weston_view *from, struct weston_view *to)
809 struct weston_output *output;
810 bool focus_surface_created = false;
812 /* FIXME: Only support dim animation using two layers */
813 if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER)
816 output = get_default_output(shell->compositor);
817 if (ws->fsurf_front == NULL && (from || to)) {
818 ws->fsurf_front = create_focus_surface(shell->compositor, output);
819 ws->fsurf_back = create_focus_surface(shell->compositor, output);
820 ws->fsurf_front->view->alpha = 0.0;
821 ws->fsurf_back->view->alpha = 0.0;
822 focus_surface_created = true;
824 wl_list_remove(&ws->fsurf_front->view->layer_link);
825 wl_list_remove(&ws->fsurf_back->view->layer_link);
828 if (ws->focus_animation) {
829 weston_view_animation_destroy(ws->focus_animation);
830 ws->focus_animation = NULL;
834 wl_list_insert(&to->layer_link,
835 &ws->fsurf_front->view->layer_link);
837 wl_list_insert(&ws->layer.view_list,
838 &ws->fsurf_front->view->layer_link);
840 if (focus_surface_created) {
841 ws->focus_animation = weston_fade_run(
842 ws->fsurf_front->view,
843 ws->fsurf_front->view->alpha, 0.6, 300,
844 focus_animation_done, ws);
846 wl_list_insert(&from->layer_link,
847 &ws->fsurf_back->view->layer_link);
848 ws->focus_animation = weston_stable_fade_run(
849 ws->fsurf_front->view, 0.0,
850 ws->fsurf_back->view, 0.6,
851 focus_animation_done, ws);
853 wl_list_insert(&ws->layer.view_list,
854 &ws->fsurf_back->view->layer_link);
855 ws->focus_animation = weston_stable_fade_run(
856 ws->fsurf_front->view, 0.0,
857 ws->fsurf_back->view, 0.6,
858 focus_animation_done, ws);
863 workspace_destroy(struct workspace *ws)
865 struct focus_state *state, *next;
867 wl_list_for_each_safe(state, next, &ws->focus_list, link)
868 focus_state_destroy(state);
871 focus_surface_destroy(ws->fsurf_front);
873 focus_surface_destroy(ws->fsurf_back);
879 seat_destroyed(struct wl_listener *listener, void *data)
881 struct weston_seat *seat = data;
882 struct focus_state *state, *next;
883 struct workspace *ws = container_of(listener,
885 seat_destroyed_listener);
887 wl_list_for_each_safe(state, next, &ws->focus_list, link)
888 if (state->seat == seat)
889 wl_list_remove(&state->link);
892 static struct workspace *
893 workspace_create(void)
895 struct workspace *ws = malloc(sizeof *ws);
899 weston_layer_init(&ws->layer, NULL);
901 wl_list_init(&ws->focus_list);
902 wl_list_init(&ws->seat_destroyed_listener.link);
903 ws->seat_destroyed_listener.notify = seat_destroyed;
904 ws->fsurf_front = NULL;
905 ws->fsurf_back = NULL;
906 ws->focus_animation = NULL;
912 workspace_is_empty(struct workspace *ws)
914 return wl_list_empty(&ws->layer.view_list);
917 static struct workspace *
918 get_workspace(struct desktop_shell *shell, unsigned int index)
920 struct workspace **pws = shell->workspaces.array.data;
921 assert(index < shell->workspaces.num);
926 static struct workspace *
927 get_current_workspace(struct desktop_shell *shell)
929 return get_workspace(shell, shell->workspaces.current);
933 activate_workspace(struct desktop_shell *shell, unsigned int index)
935 struct workspace *ws;
937 ws = get_workspace(shell, index);
938 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
940 shell->workspaces.current = index;
944 get_output_height(struct weston_output *output)
946 return abs(output->region.extents.y1 - output->region.extents.y2);
950 view_translate(struct workspace *ws, struct weston_view *view, double d)
952 struct weston_transform *transform;
954 if (is_focus_view(view)) {
955 struct focus_surface *fsurf = get_focus_surface(view->surface);
956 transform = &fsurf->workspace_transform;
958 struct shell_surface *shsurf = get_shell_surface(view->surface);
959 transform = &shsurf->workspace_transform;
962 if (wl_list_empty(&transform->link))
963 wl_list_insert(view->geometry.transformation_list.prev,
966 weston_matrix_init(&transform->matrix);
967 weston_matrix_translate(&transform->matrix,
969 weston_view_geometry_dirty(view);
973 workspace_translate_out(struct workspace *ws, double fraction)
975 struct weston_view *view;
979 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
980 height = get_output_height(view->surface->output);
981 d = height * fraction;
983 view_translate(ws, view, d);
988 workspace_translate_in(struct workspace *ws, double fraction)
990 struct weston_view *view;
994 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
995 height = get_output_height(view->surface->output);
998 d = -(height - height * fraction);
1000 d = height + height * fraction;
1002 view_translate(ws, view, d);
1007 broadcast_current_workspace_state(struct desktop_shell *shell)
1009 struct wl_resource *resource;
1011 wl_resource_for_each(resource, &shell->workspaces.client_list)
1012 workspace_manager_send_state(resource,
1013 shell->workspaces.current,
1014 shell->workspaces.num);
1018 reverse_workspace_change_animation(struct desktop_shell *shell,
1020 struct workspace *from,
1021 struct workspace *to)
1023 shell->workspaces.current = index;
1025 shell->workspaces.anim_to = to;
1026 shell->workspaces.anim_from = from;
1027 shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir;
1028 shell->workspaces.anim_timestamp = 0;
1030 weston_compositor_schedule_repaint(shell->compositor);
1034 workspace_deactivate_transforms(struct workspace *ws)
1036 struct weston_view *view;
1037 struct weston_transform *transform;
1039 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
1040 if (is_focus_view(view)) {
1041 struct focus_surface *fsurf = get_focus_surface(view->surface);
1042 transform = &fsurf->workspace_transform;
1044 struct shell_surface *shsurf = get_shell_surface(view->surface);
1045 transform = &shsurf->workspace_transform;
1048 if (!wl_list_empty(&transform->link)) {
1049 wl_list_remove(&transform->link);
1050 wl_list_init(&transform->link);
1052 weston_view_geometry_dirty(view);
1057 finish_workspace_change_animation(struct desktop_shell *shell,
1058 struct workspace *from,
1059 struct workspace *to)
1061 weston_compositor_schedule_repaint(shell->compositor);
1063 wl_list_remove(&shell->workspaces.animation.link);
1064 workspace_deactivate_transforms(from);
1065 workspace_deactivate_transforms(to);
1066 shell->workspaces.anim_to = NULL;
1068 wl_list_remove(&shell->workspaces.anim_from->layer.link);
1072 animate_workspace_change_frame(struct weston_animation *animation,
1073 struct weston_output *output, uint32_t msecs)
1075 struct desktop_shell *shell =
1076 container_of(animation, struct desktop_shell,
1077 workspaces.animation);
1078 struct workspace *from = shell->workspaces.anim_from;
1079 struct workspace *to = shell->workspaces.anim_to;
1083 if (workspace_is_empty(from) && workspace_is_empty(to)) {
1084 finish_workspace_change_animation(shell, from, to);
1088 if (shell->workspaces.anim_timestamp == 0) {
1089 if (shell->workspaces.anim_current == 0.0)
1090 shell->workspaces.anim_timestamp = msecs;
1092 shell->workspaces.anim_timestamp =
1094 /* Invers of movement function 'y' below. */
1095 (asin(1.0 - shell->workspaces.anim_current) *
1096 DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH *
1100 t = msecs - shell->workspaces.anim_timestamp;
1106 x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2;
1109 if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) {
1110 weston_compositor_schedule_repaint(shell->compositor);
1112 workspace_translate_out(from, shell->workspaces.anim_dir * y);
1113 workspace_translate_in(to, shell->workspaces.anim_dir * y);
1114 shell->workspaces.anim_current = y;
1116 weston_compositor_schedule_repaint(shell->compositor);
1119 finish_workspace_change_animation(shell, from, to);
1123 animate_workspace_change(struct desktop_shell *shell,
1125 struct workspace *from,
1126 struct workspace *to)
1128 struct weston_output *output;
1132 if (index > shell->workspaces.current)
1137 shell->workspaces.current = index;
1139 shell->workspaces.anim_dir = dir;
1140 shell->workspaces.anim_from = from;
1141 shell->workspaces.anim_to = to;
1142 shell->workspaces.anim_current = 0.0;
1143 shell->workspaces.anim_timestamp = 0;
1145 output = container_of(shell->compositor->output_list.next,
1146 struct weston_output, link);
1147 wl_list_insert(&output->animation_list,
1148 &shell->workspaces.animation.link);
1150 wl_list_insert(from->layer.link.prev, &to->layer.link);
1152 workspace_translate_in(to, 0);
1154 restore_focus_state(shell, to);
1156 weston_compositor_schedule_repaint(shell->compositor);
1160 update_workspace(struct desktop_shell *shell, unsigned int index,
1161 struct workspace *from, struct workspace *to)
1163 shell->workspaces.current = index;
1164 wl_list_insert(&from->layer.link, &to->layer.link);
1165 wl_list_remove(&from->layer.link);
1169 change_workspace(struct desktop_shell *shell, unsigned int index)
1171 struct workspace *from;
1172 struct workspace *to;
1173 struct focus_state *state;
1175 if (index == shell->workspaces.current)
1178 /* Don't change workspace when there is any fullscreen surfaces. */
1179 if (!wl_list_empty(&shell->fullscreen_layer.view_list))
1182 from = get_current_workspace(shell);
1183 to = get_workspace(shell, index);
1185 if (shell->workspaces.anim_from == to &&
1186 shell->workspaces.anim_to == from) {
1187 restore_focus_state(shell, to);
1188 reverse_workspace_change_animation(shell, index, from, to);
1189 broadcast_current_workspace_state(shell);
1193 if (shell->workspaces.anim_to != NULL)
1194 finish_workspace_change_animation(shell,
1195 shell->workspaces.anim_from,
1196 shell->workspaces.anim_to);
1198 restore_focus_state(shell, to);
1200 if (shell->focus_animation_type != ANIMATION_NONE) {
1201 wl_list_for_each(state, &from->focus_list, link)
1202 if (state->keyboard_focus)
1203 animate_focus_change(shell, from,
1204 get_default_view(state->keyboard_focus), NULL);
1206 wl_list_for_each(state, &to->focus_list, link)
1207 if (state->keyboard_focus)
1208 animate_focus_change(shell, to,
1209 NULL, get_default_view(state->keyboard_focus));
1212 if (workspace_is_empty(to) && workspace_is_empty(from))
1213 update_workspace(shell, index, from, to);
1215 animate_workspace_change(shell, index, from, to);
1217 broadcast_current_workspace_state(shell);
1221 workspace_has_only(struct workspace *ws, struct weston_surface *surface)
1223 struct wl_list *list = &ws->layer.view_list;
1226 if (wl_list_empty(list))
1231 if (e->next != list)
1234 return container_of(e, struct weston_view, layer_link)->surface == surface;
1238 move_surface_to_workspace(struct desktop_shell *shell,
1239 struct shell_surface *shsurf,
1242 struct workspace *from;
1243 struct workspace *to;
1244 struct weston_seat *seat;
1245 struct weston_surface *focus;
1246 struct weston_view *view;
1248 if (workspace == shell->workspaces.current)
1251 view = get_default_view(shsurf->surface);
1255 assert(weston_surface_get_main_surface(view->surface) == view->surface);
1257 if (workspace >= shell->workspaces.num)
1258 workspace = shell->workspaces.num - 1;
1260 from = get_current_workspace(shell);
1261 to = get_workspace(shell, workspace);
1263 wl_list_remove(&view->layer_link);
1264 wl_list_insert(&to->layer.view_list, &view->layer_link);
1266 drop_focus_state(shell, from, view->surface);
1267 wl_list_for_each(seat, &shell->compositor->seat_list, link) {
1268 if (!seat->keyboard)
1271 focus = weston_surface_get_main_surface(seat->keyboard->focus);
1272 if (focus == view->surface)
1273 weston_keyboard_set_focus(seat->keyboard, NULL);
1276 weston_view_damage_below(view);
1280 take_surface_to_workspace_by_seat(struct desktop_shell *shell,
1281 struct weston_seat *seat,
1284 struct weston_surface *surface;
1285 struct weston_view *view;
1286 struct shell_surface *shsurf;
1287 struct workspace *from;
1288 struct workspace *to;
1289 struct focus_state *state;
1291 surface = weston_surface_get_main_surface(seat->keyboard->focus);
1292 view = get_default_view(surface);
1294 index == shell->workspaces.current ||
1295 is_focus_view(view))
1298 from = get_current_workspace(shell);
1299 to = get_workspace(shell, index);
1301 wl_list_remove(&view->layer_link);
1302 wl_list_insert(&to->layer.view_list, &view->layer_link);
1304 shsurf = get_shell_surface(surface);
1306 replace_focus_state(shell, to, seat);
1307 drop_focus_state(shell, from, surface);
1309 if (shell->workspaces.anim_from == to &&
1310 shell->workspaces.anim_to == from) {
1311 wl_list_remove(&to->layer.link);
1312 wl_list_insert(from->layer.link.prev, &to->layer.link);
1314 reverse_workspace_change_animation(shell, index, from, to);
1315 broadcast_current_workspace_state(shell);
1320 if (shell->workspaces.anim_to != NULL)
1321 finish_workspace_change_animation(shell,
1322 shell->workspaces.anim_from,
1323 shell->workspaces.anim_to);
1325 if (workspace_is_empty(from) &&
1326 workspace_has_only(to, surface))
1327 update_workspace(shell, index, from, to);
1329 if (wl_list_empty(&shsurf->workspace_transform.link))
1330 wl_list_insert(&shell->workspaces.anim_sticky_list,
1331 &shsurf->workspace_transform.link);
1333 animate_workspace_change(shell, index, from, to);
1336 broadcast_current_workspace_state(shell);
1338 state = ensure_focus_state(shell, seat);
1340 state->keyboard_focus = surface;
1344 workspace_manager_move_surface(struct wl_client *client,
1345 struct wl_resource *resource,
1346 struct wl_resource *surface_resource,
1349 struct desktop_shell *shell = wl_resource_get_user_data(resource);
1350 struct weston_surface *surface =
1351 wl_resource_get_user_data(surface_resource);
1352 struct weston_surface *main_surface;
1353 struct shell_surface *shell_surface;
1355 main_surface = weston_surface_get_main_surface(surface);
1356 shell_surface = get_shell_surface(main_surface);
1357 if (shell_surface == NULL)
1360 move_surface_to_workspace(shell, shell_surface, workspace);
1363 static const struct workspace_manager_interface workspace_manager_implementation = {
1364 workspace_manager_move_surface,
1368 unbind_resource(struct wl_resource *resource)
1370 wl_list_remove(wl_resource_get_link(resource));
1374 bind_workspace_manager(struct wl_client *client,
1375 void *data, uint32_t version, uint32_t id)
1377 struct desktop_shell *shell = data;
1378 struct wl_resource *resource;
1380 resource = wl_resource_create(client,
1381 &workspace_manager_interface, 1, id);
1383 if (resource == NULL) {
1384 weston_log("couldn't add workspace manager object");
1388 wl_resource_set_implementation(resource,
1389 &workspace_manager_implementation,
1390 shell, unbind_resource);
1391 wl_list_insert(&shell->workspaces.client_list,
1392 wl_resource_get_link(resource));
1394 workspace_manager_send_state(resource,
1395 shell->workspaces.current,
1396 shell->workspaces.num);
1400 touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time,
1401 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1406 touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id)
1408 struct weston_touch_move_grab *move =
1409 (struct weston_touch_move_grab *) container_of(
1410 grab, struct shell_touch_grab, grab);
1412 if (grab->touch->seat->num_tp == 0) {
1413 shell_touch_grab_end(&move->base);
1419 touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time,
1420 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1422 struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab;
1423 struct shell_surface *shsurf = move->base.shsurf;
1424 struct weston_surface *es;
1425 int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx);
1426 int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy);
1431 es = shsurf->surface;
1433 weston_view_configure(shsurf->view, dx, dy,
1434 shsurf->view->geometry.width,
1435 shsurf->view->geometry.height);
1437 weston_compositor_schedule_repaint(es->compositor);
1441 touch_move_grab_cancel(struct weston_touch_grab *grab)
1443 struct weston_touch_move_grab *move =
1444 (struct weston_touch_move_grab *) container_of(
1445 grab, struct shell_touch_grab, grab);
1447 shell_touch_grab_end(&move->base);
1451 static const struct weston_touch_grab_interface touch_move_grab_interface = {
1452 touch_move_grab_down,
1454 touch_move_grab_motion,
1455 touch_move_grab_cancel,
1459 surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat)
1461 struct weston_touch_move_grab *move;
1466 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1468 if (shsurf->grabbed)
1471 move = malloc(sizeof *move);
1475 move->dx = wl_fixed_from_double(shsurf->view->geometry.x) -
1476 seat->touch->grab_x;
1477 move->dy = wl_fixed_from_double(shsurf->view->geometry.y) -
1478 seat->touch->grab_y;
1480 shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf,
1487 noop_grab_focus(struct weston_pointer_grab *grab)
1492 move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
1493 wl_fixed_t x, wl_fixed_t y)
1495 struct weston_move_grab *move = (struct weston_move_grab *) grab;
1496 struct weston_pointer *pointer = grab->pointer;
1497 struct shell_surface *shsurf = move->base.shsurf;
1500 weston_pointer_move(pointer, x, y);
1501 dx = wl_fixed_to_int(pointer->x + move->dx);
1502 dy = wl_fixed_to_int(pointer->y + move->dy);
1507 weston_view_configure(shsurf->view, dx, dy,
1508 shsurf->view->geometry.width,
1509 shsurf->view->geometry.height);
1511 weston_compositor_schedule_repaint(shsurf->surface->compositor);
1515 move_grab_button(struct weston_pointer_grab *grab,
1516 uint32_t time, uint32_t button, uint32_t state_w)
1518 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
1520 struct weston_pointer *pointer = grab->pointer;
1521 enum wl_pointer_button_state state = state_w;
1523 if (pointer->button_count == 0 &&
1524 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1525 shell_grab_end(shell_grab);
1531 move_grab_cancel(struct weston_pointer_grab *grab)
1533 struct shell_grab *shell_grab =
1534 container_of(grab, struct shell_grab, grab);
1536 shell_grab_end(shell_grab);
1540 static const struct weston_pointer_grab_interface move_grab_interface = {
1548 surface_move(struct shell_surface *shsurf, struct weston_seat *seat)
1550 struct weston_move_grab *move;
1555 if (shsurf->grabbed)
1557 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1560 move = malloc(sizeof *move);
1564 move->dx = wl_fixed_from_double(shsurf->view->geometry.x) -
1565 seat->pointer->grab_x;
1566 move->dy = wl_fixed_from_double(shsurf->view->geometry.y) -
1567 seat->pointer->grab_y;
1569 shell_grab_start(&move->base, &move_grab_interface, shsurf,
1570 seat->pointer, DESKTOP_SHELL_CURSOR_MOVE);
1576 shell_surface_move(struct wl_client *client, struct wl_resource *resource,
1577 struct wl_resource *seat_resource, uint32_t serial)
1579 struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
1580 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1581 struct weston_surface *surface;
1583 if (seat->pointer &&
1584 seat->pointer->button_count > 0 &&
1585 seat->pointer->grab_serial == serial) {
1586 surface = weston_surface_get_main_surface(seat->pointer->focus->surface);
1587 if ((surface == shsurf->surface) &&
1588 (surface_move(shsurf, seat) < 0))
1589 wl_resource_post_no_memory(resource);
1590 } else if (seat->touch &&
1591 seat->touch->grab_serial == serial) {
1592 surface = weston_surface_get_main_surface(seat->touch->focus->surface);
1593 if ((surface == shsurf->surface) &&
1594 (surface_touch_move(shsurf, seat) < 0))
1595 wl_resource_post_no_memory(resource);
1599 struct weston_resize_grab {
1600 struct shell_grab base;
1602 int32_t width, height;
1606 resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
1607 wl_fixed_t x, wl_fixed_t y)
1609 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1610 struct weston_pointer *pointer = grab->pointer;
1611 struct shell_surface *shsurf = resize->base.shsurf;
1612 int32_t width, height;
1613 wl_fixed_t from_x, from_y;
1614 wl_fixed_t to_x, to_y;
1616 weston_pointer_move(pointer, x, y);
1621 weston_view_from_global_fixed(shsurf->view,
1622 pointer->grab_x, pointer->grab_y,
1624 weston_view_from_global_fixed(shsurf->view,
1625 pointer->x, pointer->y, &to_x, &to_y);
1627 width = resize->width;
1628 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
1629 width += wl_fixed_to_int(from_x - to_x);
1630 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
1631 width += wl_fixed_to_int(to_x - from_x);
1634 height = resize->height;
1635 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
1636 height += wl_fixed_to_int(from_y - to_y);
1637 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
1638 height += wl_fixed_to_int(to_y - from_y);
1641 shsurf->client->send_configure(shsurf->surface,
1642 resize->edges, width, height);
1646 send_configure(struct weston_surface *surface,
1647 uint32_t edges, int32_t width, int32_t height)
1649 struct shell_surface *shsurf = get_shell_surface(surface);
1651 wl_shell_surface_send_configure(shsurf->resource,
1652 edges, width, height);
1655 static const struct weston_shell_client shell_client = {
1660 resize_grab_button(struct weston_pointer_grab *grab,
1661 uint32_t time, uint32_t button, uint32_t state_w)
1663 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1664 struct weston_pointer *pointer = grab->pointer;
1665 enum wl_pointer_button_state state = state_w;
1667 if (pointer->button_count == 0 &&
1668 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1669 shell_grab_end(&resize->base);
1675 resize_grab_cancel(struct weston_pointer_grab *grab)
1677 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1679 shell_grab_end(&resize->base);
1683 static const struct weston_pointer_grab_interface resize_grab_interface = {
1691 * Returns the bounding box of a surface and all its sub-surfaces,
1692 * in the surface coordinates system. */
1694 surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x,
1695 int32_t *y, int32_t *w, int32_t *h) {
1696 pixman_region32_t region;
1697 pixman_box32_t *box;
1698 struct weston_subsurface *subsurface;
1700 pixman_region32_init_rect(®ion, 0, 0,
1704 wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
1705 pixman_region32_union_rect(®ion, ®ion,
1706 subsurface->position.x,
1707 subsurface->position.y,
1708 subsurface->surface->width,
1709 subsurface->surface->height);
1712 box = pixman_region32_extents(®ion);
1718 *w = box->x2 - box->x1;
1720 *h = box->y2 - box->y1;
1722 pixman_region32_fini(®ion);
1726 surface_resize(struct shell_surface *shsurf,
1727 struct weston_seat *seat, uint32_t edges)
1729 struct weston_resize_grab *resize;
1731 if (shsurf->type == SHELL_SURFACE_FULLSCREEN ||
1732 shsurf->type == SHELL_SURFACE_MAXIMIZED)
1735 if (edges == 0 || edges > 15 ||
1736 (edges & 3) == 3 || (edges & 12) == 12)
1739 resize = malloc(sizeof *resize);
1743 resize->edges = edges;
1744 surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL,
1745 &resize->width, &resize->height);
1747 shell_grab_start(&resize->base, &resize_grab_interface, shsurf,
1748 seat->pointer, edges);
1754 shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
1755 struct wl_resource *seat_resource, uint32_t serial,
1758 struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
1759 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1760 struct weston_surface *surface;
1762 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1765 surface = weston_surface_get_main_surface(seat->pointer->focus->surface);
1766 if (seat->pointer->button_count == 0 ||
1767 seat->pointer->grab_serial != serial ||
1768 surface != shsurf->surface)
1771 if (surface_resize(shsurf, seat, edges) < 0)
1772 wl_resource_post_no_memory(resource);
1776 end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer);
1779 busy_cursor_grab_focus(struct weston_pointer_grab *base)
1781 struct shell_grab *grab = (struct shell_grab *) base;
1782 struct weston_pointer *pointer = base->pointer;
1783 struct weston_view *view;
1786 view = weston_compositor_pick_view(pointer->seat->compositor,
1787 pointer->x, pointer->y,
1790 if (!grab->shsurf || grab->shsurf->surface != view->surface)
1791 end_busy_cursor(grab->shsurf, pointer);
1795 busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
1796 wl_fixed_t x, wl_fixed_t y)
1798 weston_pointer_move(grab->pointer, x, y);
1802 busy_cursor_grab_button(struct weston_pointer_grab *base,
1803 uint32_t time, uint32_t button, uint32_t state)
1805 struct shell_grab *grab = (struct shell_grab *) base;
1806 struct shell_surface *shsurf = grab->shsurf;
1807 struct weston_seat *seat = grab->grab.pointer->seat;
1809 if (shsurf && button == BTN_LEFT && state) {
1810 activate(shsurf->shell, shsurf->surface, seat);
1811 surface_move(shsurf, seat);
1812 } else if (shsurf && button == BTN_RIGHT && state) {
1813 activate(shsurf->shell, shsurf->surface, seat);
1814 surface_rotate(shsurf, seat);
1819 busy_cursor_grab_cancel(struct weston_pointer_grab *base)
1821 struct shell_grab *grab = (struct shell_grab *) base;
1823 shell_grab_end(grab);
1827 static const struct weston_pointer_grab_interface busy_cursor_grab_interface = {
1828 busy_cursor_grab_focus,
1829 busy_cursor_grab_motion,
1830 busy_cursor_grab_button,
1831 busy_cursor_grab_cancel,
1835 set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
1837 struct shell_grab *grab;
1839 grab = malloc(sizeof *grab);
1843 shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer,
1844 DESKTOP_SHELL_CURSOR_BUSY);
1848 end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
1850 struct shell_grab *grab = (struct shell_grab *) pointer->grab;
1852 if (grab->grab.interface == &busy_cursor_grab_interface &&
1853 grab->shsurf == shsurf) {
1854 shell_grab_end(grab);
1860 ping_timer_destroy(struct shell_surface *shsurf)
1862 if (!shsurf || !shsurf->ping_timer)
1865 if (shsurf->ping_timer->source)
1866 wl_event_source_remove(shsurf->ping_timer->source);
1868 free(shsurf->ping_timer);
1869 shsurf->ping_timer = NULL;
1873 ping_timeout_handler(void *data)
1875 struct shell_surface *shsurf = data;
1876 struct weston_seat *seat;
1878 /* Client is not responding */
1879 shsurf->unresponsive = 1;
1881 wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link)
1882 if (seat->pointer->focus &&
1883 seat->pointer->focus->surface == shsurf->surface)
1884 set_busy_cursor(shsurf, seat->pointer);
1890 ping_handler(struct weston_surface *surface, uint32_t serial)
1892 struct shell_surface *shsurf = get_shell_surface(surface);
1893 struct wl_event_loop *loop;
1894 int ping_timeout = 200;
1898 if (!shsurf->resource)
1901 if (shsurf->surface == shsurf->shell->grab_surface)
1904 if (!shsurf->ping_timer) {
1905 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
1906 if (!shsurf->ping_timer)
1909 shsurf->ping_timer->serial = serial;
1910 loop = wl_display_get_event_loop(surface->compositor->wl_display);
1911 shsurf->ping_timer->source =
1912 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
1913 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
1915 wl_shell_surface_send_ping(shsurf->resource, serial);
1920 handle_pointer_focus(struct wl_listener *listener, void *data)
1922 struct weston_pointer *pointer = data;
1923 struct weston_view *view = pointer->focus;
1924 struct weston_compositor *compositor;
1925 struct shell_surface *shsurf;
1931 compositor = view->surface->compositor;
1932 shsurf = get_shell_surface(view->surface);
1934 if (shsurf && shsurf->unresponsive) {
1935 set_busy_cursor(shsurf, pointer);
1937 serial = wl_display_next_serial(compositor->wl_display);
1938 ping_handler(view->surface, serial);
1943 create_pointer_focus_listener(struct weston_seat *seat)
1945 struct wl_listener *listener;
1950 listener = malloc(sizeof *listener);
1951 listener->notify = handle_pointer_focus;
1952 wl_signal_add(&seat->pointer->focus_signal, listener);
1956 shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
1959 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1960 struct weston_seat *seat;
1961 struct weston_compositor *ec = shsurf->surface->compositor;
1963 if (shsurf->ping_timer == NULL)
1964 /* Just ignore unsolicited pong. */
1967 if (shsurf->ping_timer->serial == serial) {
1968 shsurf->unresponsive = 0;
1969 wl_list_for_each(seat, &ec->seat_list, link) {
1971 end_busy_cursor(shsurf, seat->pointer);
1973 ping_timer_destroy(shsurf);
1978 set_title(struct shell_surface *shsurf, const char *title)
1980 free(shsurf->title);
1981 shsurf->title = strdup(title);
1985 shell_surface_set_title(struct wl_client *client,
1986 struct wl_resource *resource, const char *title)
1988 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1990 set_title(shsurf, title);
1994 shell_surface_set_class(struct wl_client *client,
1995 struct wl_resource *resource, const char *class)
1997 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1999 free(shsurf->class);
2000 shsurf->class = strdup(class);
2004 restore_output_mode(struct weston_output *output)
2006 if (output->current_mode != output->original_mode ||
2007 (int32_t)output->current_scale != output->original_scale)
2008 weston_output_switch_mode(output,
2009 output->original_mode,
2010 output->original_scale,
2011 WESTON_MODE_SWITCH_RESTORE_NATIVE);
2015 restore_all_output_modes(struct weston_compositor *compositor)
2017 struct weston_output *output;
2019 wl_list_for_each(output, &compositor->output_list, link)
2020 restore_output_mode(output);
2024 get_output_panel_height(struct desktop_shell *shell,
2025 struct weston_output *output)
2027 struct weston_view *view;
2028 int panel_height = 0;
2033 wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) {
2034 if (view->surface->output == output) {
2035 panel_height = view->geometry.height;
2040 return panel_height;
2044 shell_surface_set_parent(struct shell_surface *shsurf,
2045 struct weston_surface *parent)
2047 shsurf->parent = parent;
2051 shell_surface_set_output(struct shell_surface *shsurf,
2052 struct weston_output *output)
2054 struct weston_surface *es = shsurf->surface;
2056 /* get the default output, if the client set it as NULL
2057 check whether the ouput is available */
2059 shsurf->output = output;
2060 else if (es->output)
2061 shsurf->output = es->output;
2063 shsurf->output = get_default_output(es->compositor);
2067 set_toplevel(struct shell_surface *shsurf)
2069 shell_surface_set_parent(shsurf, NULL);
2071 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
2075 shell_surface_set_toplevel(struct wl_client *client,
2076 struct wl_resource *resource)
2078 struct shell_surface *surface = wl_resource_get_user_data(resource);
2080 set_toplevel(surface);
2084 set_transient(struct shell_surface *shsurf,
2085 struct weston_surface *parent, int x, int y, uint32_t flags)
2087 assert(parent != NULL);
2089 shsurf->transient.x = x;
2090 shsurf->transient.y = y;
2091 shsurf->transient.flags = flags;
2093 shell_surface_set_parent(shsurf, parent);
2095 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
2099 shell_surface_set_transient(struct wl_client *client,
2100 struct wl_resource *resource,
2101 struct wl_resource *parent_resource,
2102 int x, int y, uint32_t flags)
2104 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2105 struct weston_surface *parent =
2106 wl_resource_get_user_data(parent_resource);
2108 set_transient(shsurf, parent, x, y, flags);
2112 set_fullscreen(struct shell_surface *shsurf,
2115 struct weston_output *output)
2117 shell_surface_set_output(shsurf, output);
2119 shsurf->fullscreen_output = shsurf->output;
2120 shsurf->fullscreen.type = method;
2121 shsurf->fullscreen.framerate = framerate;
2123 shell_surface_set_parent(shsurf, NULL);
2125 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
2127 shsurf->client->send_configure(shsurf->surface, 0,
2128 shsurf->output->width,
2129 shsurf->output->height);
2133 unset_fullscreen(struct shell_surface *shsurf)
2135 struct workspace *ws;
2137 /* Unset the fullscreen output, driver configuration and transforms. */
2138 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
2139 shell_surface_is_top_fullscreen(shsurf)) {
2140 restore_output_mode(shsurf->fullscreen_output);
2142 shsurf->fullscreen_output = NULL;
2144 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
2145 shsurf->fullscreen.framerate = 0;
2147 wl_list_remove(&shsurf->fullscreen.transform.link);
2148 wl_list_init(&shsurf->fullscreen.transform.link);
2150 if (shsurf->fullscreen.black_view)
2151 weston_surface_destroy(shsurf->fullscreen.black_view->surface);
2152 shsurf->fullscreen.black_view = NULL;
2154 weston_view_set_position(shsurf->view,
2155 shsurf->saved_x, shsurf->saved_y);
2156 if (shsurf->saved_rotation_valid) {
2157 wl_list_insert(&shsurf->view->geometry.transformation_list,
2158 &shsurf->rotation.transform.link);
2159 shsurf->saved_rotation_valid = false;
2162 ws = get_current_workspace(shsurf->shell);
2163 wl_list_remove(&shsurf->view->layer_link);
2164 wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link);
2168 shell_surface_set_fullscreen(struct wl_client *client,
2169 struct wl_resource *resource,
2172 struct wl_resource *output_resource)
2174 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2175 struct weston_output *output;
2177 if (output_resource)
2178 output = wl_resource_get_user_data(output_resource);
2182 set_fullscreen(shsurf, method, framerate, output);
2186 set_popup(struct shell_surface *shsurf,
2187 struct weston_surface *parent,
2188 struct weston_seat *seat,
2193 assert(parent != NULL);
2195 shsurf->popup.shseat = get_shell_seat(seat);
2196 shsurf->popup.serial = serial;
2197 shsurf->popup.x = x;
2198 shsurf->popup.y = y;
2200 shell_surface_set_parent(shsurf, parent);
2202 shsurf->next_type = SHELL_SURFACE_POPUP;
2206 shell_surface_set_popup(struct wl_client *client,
2207 struct wl_resource *resource,
2208 struct wl_resource *seat_resource,
2210 struct wl_resource *parent_resource,
2211 int32_t x, int32_t y, uint32_t flags)
2213 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2216 wl_resource_get_user_data(parent_resource),
2217 wl_resource_get_user_data(seat_resource),
2222 set_maximized(struct shell_surface *shsurf,
2223 struct weston_output *output)
2225 struct desktop_shell *shell;
2226 uint32_t edges = 0, panel_height = 0;
2228 shell_surface_set_output(shsurf, output);
2230 shell = shell_surface_get_shell(shsurf);
2231 panel_height = get_output_panel_height(shell, shsurf->output);
2232 edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT;
2234 shsurf->client->send_configure(shsurf->surface, edges,
2235 shsurf->output->width,
2236 shsurf->output->height - panel_height);
2238 shell_surface_set_parent(shsurf, NULL);
2240 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
2244 unset_maximized(struct shell_surface *shsurf)
2246 struct workspace *ws;
2248 /* undo all maximized things here */
2249 shsurf->output = get_default_output(shsurf->surface->compositor);
2250 weston_view_set_position(shsurf->view,
2254 if (shsurf->saved_rotation_valid) {
2255 wl_list_insert(&shsurf->view->geometry.transformation_list,
2256 &shsurf->rotation.transform.link);
2257 shsurf->saved_rotation_valid = false;
2260 ws = get_current_workspace(shsurf->shell);
2261 wl_list_remove(&shsurf->view->layer_link);
2262 wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link);
2266 shell_surface_set_maximized(struct wl_client *client,
2267 struct wl_resource *resource,
2268 struct wl_resource *output_resource)
2270 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2271 struct weston_output *output;
2273 if (output_resource)
2274 output = wl_resource_get_user_data(output_resource);
2278 set_maximized(shsurf, output);
2282 reset_surface_type(struct shell_surface *surface)
2284 switch (surface->type) {
2285 case SHELL_SURFACE_FULLSCREEN:
2286 unset_fullscreen(surface);
2288 case SHELL_SURFACE_MAXIMIZED:
2289 unset_maximized(surface);
2291 case SHELL_SURFACE_NONE:
2292 case SHELL_SURFACE_TOPLEVEL:
2293 case SHELL_SURFACE_TRANSIENT:
2294 case SHELL_SURFACE_POPUP:
2295 case SHELL_SURFACE_XWAYLAND:
2300 surface->type = SHELL_SURFACE_NONE;
2305 set_surface_type(struct shell_surface *shsurf)
2307 struct weston_surface *pes = shsurf->parent;
2308 struct weston_view *pev = get_default_view(pes);
2310 reset_surface_type(shsurf);
2312 shsurf->type = shsurf->next_type;
2313 shsurf->next_type = SHELL_SURFACE_NONE;
2315 switch (shsurf->type) {
2316 case SHELL_SURFACE_TOPLEVEL:
2318 case SHELL_SURFACE_TRANSIENT:
2320 weston_view_set_position(shsurf->view,
2321 pev->geometry.x + shsurf->transient.x,
2322 pev->geometry.y + shsurf->transient.y);
2325 case SHELL_SURFACE_MAXIMIZED:
2326 case SHELL_SURFACE_FULLSCREEN:
2327 shsurf->saved_x = shsurf->view->geometry.x;
2328 shsurf->saved_y = shsurf->view->geometry.y;
2329 shsurf->saved_position_valid = true;
2331 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
2332 wl_list_remove(&shsurf->rotation.transform.link);
2333 wl_list_init(&shsurf->rotation.transform.link);
2334 weston_view_geometry_dirty(shsurf->view);
2335 shsurf->saved_rotation_valid = true;
2339 case SHELL_SURFACE_XWAYLAND:
2340 weston_view_set_position(shsurf->view, shsurf->transient.x,
2341 shsurf->transient.y);
2344 case SHELL_SURFACE_POPUP:
2345 case SHELL_SURFACE_NONE:
2351 static struct desktop_shell *
2352 shell_surface_get_shell(struct shell_surface *shsurf)
2354 return shsurf->shell;
2358 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height);
2360 static struct weston_view *
2361 create_black_surface(struct weston_compositor *ec,
2362 struct weston_surface *fs_surface,
2363 float x, float y, int w, int h)
2365 struct weston_surface *surface = NULL;
2366 struct weston_view *view;
2368 surface = weston_surface_create(ec);
2369 if (surface == NULL) {
2370 weston_log("no memory\n");
2373 view = weston_view_create(surface);
2374 if (surface == NULL) {
2375 weston_log("no memory\n");
2376 weston_surface_destroy(surface);
2380 surface->configure = black_surface_configure;
2381 surface->configure_private = fs_surface;
2382 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
2383 pixman_region32_fini(&surface->opaque);
2384 pixman_region32_init_rect(&surface->opaque, 0, 0, w, h);
2385 pixman_region32_fini(&surface->input);
2386 pixman_region32_init_rect(&surface->input, 0, 0, w, h);
2388 surface->height = h;
2390 weston_view_configure(view, x, y, w, h);
2395 /* Create black surface and append it to the associated fullscreen surface.
2396 * Handle size dismatch and positioning according to the method. */
2398 shell_configure_fullscreen(struct shell_surface *shsurf)
2400 struct weston_output *output = shsurf->fullscreen_output;
2401 struct weston_surface *surface = shsurf->surface;
2402 struct weston_matrix *matrix;
2403 float scale, output_aspect, surface_aspect, x, y;
2404 int32_t surf_x, surf_y, surf_width, surf_height;
2406 if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER)
2407 restore_output_mode(output);
2409 if (!shsurf->fullscreen.black_view)
2410 shsurf->fullscreen.black_view =
2411 create_black_surface(surface->compositor,
2413 output->x, output->y,
2417 wl_list_remove(&shsurf->fullscreen.black_view->layer_link);
2418 wl_list_insert(&shsurf->view->layer_link,
2419 &shsurf->fullscreen.black_view->layer_link);
2420 shsurf->fullscreen.black_view->surface->output = output;
2421 shsurf->fullscreen.black_view->output = output;
2423 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
2424 &surf_width, &surf_height);
2426 switch (shsurf->fullscreen.type) {
2427 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
2428 if (surface->buffer_ref.buffer)
2429 center_on_output(shsurf->view, shsurf->fullscreen_output);
2431 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
2432 /* 1:1 mapping between surface and output dimensions */
2433 if (output->width == surf_width &&
2434 output->height == surf_height) {
2435 weston_view_set_position(shsurf->view,
2437 output->y - surf_y);
2441 matrix = &shsurf->fullscreen.transform.matrix;
2442 weston_matrix_init(matrix);
2444 output_aspect = (float) output->width /
2445 (float) output->height;
2446 /* XXX: Use surf_width and surf_height here? */
2447 surface_aspect = (float) surface->width /
2448 (float) surface->height;
2449 if (output_aspect < surface_aspect)
2450 scale = (float) output->width /
2453 scale = (float) output->height /
2454 (float) surf_height;
2456 weston_matrix_scale(matrix, scale, scale, 1);
2457 wl_list_remove(&shsurf->fullscreen.transform.link);
2458 wl_list_insert(&shsurf->view->geometry.transformation_list,
2459 &shsurf->fullscreen.transform.link);
2460 x = output->x + (output->width - surf_width * scale) / 2 - surf_x;
2461 y = output->y + (output->height - surf_height * scale) / 2 - surf_y;
2462 weston_view_set_position(shsurf->view, x, y);
2465 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
2466 if (shell_surface_is_top_fullscreen(shsurf)) {
2467 struct weston_mode mode = {0,
2468 surf_width * surface->buffer_viewport.scale,
2469 surf_height * surface->buffer_viewport.scale,
2470 shsurf->fullscreen.framerate};
2472 if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale,
2473 WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) {
2474 weston_view_set_position(shsurf->view,
2476 output->y - surf_y);
2477 weston_view_configure(shsurf->fullscreen.black_view,
2484 restore_output_mode(output);
2485 center_on_output(shsurf->view, output);
2489 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
2490 center_on_output(shsurf->view, output);
2497 /* make the fullscreen and black surface at the top */
2499 shell_stack_fullscreen(struct shell_surface *shsurf)
2501 struct weston_output *output = shsurf->fullscreen_output;
2502 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
2504 wl_list_remove(&shsurf->view->layer_link);
2505 wl_list_insert(&shell->fullscreen_layer.view_list,
2506 &shsurf->view->layer_link);
2507 weston_surface_damage(shsurf->surface);
2509 if (!shsurf->fullscreen.black_view)
2510 shsurf->fullscreen.black_view =
2511 create_black_surface(shsurf->surface->compositor,
2513 output->x, output->y,
2517 wl_list_remove(&shsurf->fullscreen.black_view->layer_link);
2518 wl_list_insert(&shsurf->view->layer_link,
2519 &shsurf->fullscreen.black_view->layer_link);
2520 weston_surface_damage(shsurf->fullscreen.black_view->surface);
2524 shell_map_fullscreen(struct shell_surface *shsurf)
2526 shell_stack_fullscreen(shsurf);
2527 shell_configure_fullscreen(shsurf);
2531 set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags)
2533 /* XXX: using the same fields for transient type */
2534 shsurf->transient.x = x;
2535 shsurf->transient.y = y;
2536 shsurf->transient.flags = flags;
2538 shell_surface_set_parent(shsurf, NULL);
2540 shsurf->next_type = SHELL_SURFACE_XWAYLAND;
2543 static const struct weston_pointer_grab_interface popup_grab_interface;
2546 destroy_shell_seat(struct wl_listener *listener, void *data)
2548 struct shell_seat *shseat =
2549 container_of(listener,
2550 struct shell_seat, seat_destroy_listener);
2551 struct shell_surface *shsurf, *prev = NULL;
2553 if (shseat->popup_grab.grab.interface == &popup_grab_interface) {
2554 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
2555 shseat->popup_grab.client = NULL;
2557 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
2558 shsurf->popup.shseat = NULL;
2560 wl_list_init(&prev->popup.grab_link);
2564 wl_list_init(&prev->popup.grab_link);
2567 wl_list_remove(&shseat->seat_destroy_listener.link);
2571 static struct shell_seat *
2572 create_shell_seat(struct weston_seat *seat)
2574 struct shell_seat *shseat;
2576 shseat = calloc(1, sizeof *shseat);
2578 weston_log("no memory to allocate shell seat\n");
2582 shseat->seat = seat;
2583 wl_list_init(&shseat->popup_grab.surfaces_list);
2585 shseat->seat_destroy_listener.notify = destroy_shell_seat;
2586 wl_signal_add(&seat->destroy_signal,
2587 &shseat->seat_destroy_listener);
2592 static struct shell_seat *
2593 get_shell_seat(struct weston_seat *seat)
2595 struct wl_listener *listener;
2597 listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat);
2598 if (listener == NULL)
2599 return create_shell_seat(seat);
2601 return container_of(listener,
2602 struct shell_seat, seat_destroy_listener);
2606 popup_grab_focus(struct weston_pointer_grab *grab)
2608 struct weston_pointer *pointer = grab->pointer;
2609 struct weston_view *view;
2610 struct shell_seat *shseat =
2611 container_of(grab, struct shell_seat, popup_grab.grab);
2612 struct wl_client *client = shseat->popup_grab.client;
2615 view = weston_compositor_pick_view(pointer->seat->compositor,
2616 pointer->x, pointer->y,
2619 if (view && view->surface->resource &&
2620 wl_resource_get_client(view->surface->resource) == client) {
2621 weston_pointer_set_focus(pointer, view, sx, sy);
2623 weston_pointer_set_focus(pointer, NULL,
2624 wl_fixed_from_int(0),
2625 wl_fixed_from_int(0));
2630 popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
2631 wl_fixed_t x, wl_fixed_t y)
2633 struct weston_pointer *pointer = grab->pointer;
2634 struct wl_resource *resource;
2637 weston_pointer_move(pointer, x, y);
2639 wl_resource_for_each(resource, &pointer->focus_resource_list) {
2640 weston_view_from_global_fixed(pointer->focus,
2641 pointer->x, pointer->y,
2643 wl_pointer_send_motion(resource, time, sx, sy);
2648 popup_grab_button(struct weston_pointer_grab *grab,
2649 uint32_t time, uint32_t button, uint32_t state_w)
2651 struct wl_resource *resource;
2652 struct shell_seat *shseat =
2653 container_of(grab, struct shell_seat, popup_grab.grab);
2654 struct wl_display *display = shseat->seat->compositor->wl_display;
2655 enum wl_pointer_button_state state = state_w;
2657 struct wl_list *resource_list;
2659 resource_list = &grab->pointer->focus_resource_list;
2660 if (!wl_list_empty(resource_list)) {
2661 serial = wl_display_get_serial(display);
2662 wl_resource_for_each(resource, resource_list) {
2663 wl_pointer_send_button(resource, serial,
2664 time, button, state);
2666 } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
2667 (shseat->popup_grab.initial_up ||
2668 time - shseat->seat->pointer->grab_time > 500)) {
2669 popup_grab_end(grab->pointer);
2672 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
2673 shseat->popup_grab.initial_up = 1;
2677 popup_grab_cancel(struct weston_pointer_grab *grab)
2679 popup_grab_end(grab->pointer);
2682 static const struct weston_pointer_grab_interface popup_grab_interface = {
2690 popup_grab_end(struct weston_pointer *pointer)
2692 struct weston_pointer_grab *grab = pointer->grab;
2693 struct shell_seat *shseat =
2694 container_of(grab, struct shell_seat, popup_grab.grab);
2695 struct shell_surface *shsurf;
2696 struct shell_surface *prev = NULL;
2698 if (pointer->grab->interface == &popup_grab_interface) {
2699 weston_pointer_end_grab(grab->pointer);
2700 shseat->popup_grab.client = NULL;
2701 shseat->popup_grab.grab.interface = NULL;
2702 assert(!wl_list_empty(&shseat->popup_grab.surfaces_list));
2703 /* Send the popup_done event to all the popups open */
2704 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
2705 wl_shell_surface_send_popup_done(shsurf->resource);
2706 shsurf->popup.shseat = NULL;
2708 wl_list_init(&prev->popup.grab_link);
2712 wl_list_init(&prev->popup.grab_link);
2713 wl_list_init(&shseat->popup_grab.surfaces_list);
2718 add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat)
2720 struct weston_seat *seat = shseat->seat;
2722 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
2723 shseat->popup_grab.client = wl_resource_get_client(shsurf->resource);
2724 shseat->popup_grab.grab.interface = &popup_grab_interface;
2725 /* We must make sure here that this popup was opened after
2726 * a mouse press, and not just by moving around with other
2727 * popups already open. */
2728 if (shseat->seat->pointer->button_count > 0)
2729 shseat->popup_grab.initial_up = 0;
2731 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
2732 weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab);
2734 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
2739 remove_popup_grab(struct shell_surface *shsurf)
2741 struct shell_seat *shseat = shsurf->popup.shseat;
2743 wl_list_remove(&shsurf->popup.grab_link);
2744 wl_list_init(&shsurf->popup.grab_link);
2745 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
2746 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
2747 shseat->popup_grab.grab.interface = NULL;
2752 shell_map_popup(struct shell_surface *shsurf)
2754 struct shell_seat *shseat = shsurf->popup.shseat;
2755 struct weston_view *parent_view = get_default_view(shsurf->parent);
2757 shsurf->surface->output = parent_view->output;
2758 shsurf->view->output = parent_view->output;
2760 weston_view_set_transform_parent(shsurf->view, parent_view);
2761 weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y);
2762 weston_view_update_transform(shsurf->view);
2764 if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) {
2765 add_popup_grab(shsurf, shseat);
2767 wl_shell_surface_send_popup_done(shsurf->resource);
2768 shseat->popup_grab.client = NULL;
2772 static const struct wl_shell_surface_interface shell_surface_implementation = {
2775 shell_surface_resize,
2776 shell_surface_set_toplevel,
2777 shell_surface_set_transient,
2778 shell_surface_set_fullscreen,
2779 shell_surface_set_popup,
2780 shell_surface_set_maximized,
2781 shell_surface_set_title,
2782 shell_surface_set_class
2786 destroy_shell_surface(struct shell_surface *shsurf)
2788 wl_signal_emit(&shsurf->destroy_signal, shsurf);
2790 if (!wl_list_empty(&shsurf->popup.grab_link)) {
2791 remove_popup_grab(shsurf);
2794 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
2795 shell_surface_is_top_fullscreen(shsurf))
2796 restore_output_mode (shsurf->fullscreen_output);
2798 if (shsurf->fullscreen.black_view)
2799 weston_surface_destroy(shsurf->fullscreen.black_view->surface);
2801 /* As destroy_resource() use wl_list_for_each_safe(),
2802 * we can always remove the listener.
2804 wl_list_remove(&shsurf->surface_destroy_listener.link);
2805 shsurf->surface->configure = NULL;
2806 ping_timer_destroy(shsurf);
2807 free(shsurf->title);
2809 weston_view_destroy(shsurf->view);
2811 wl_list_remove(&shsurf->link);
2816 shell_destroy_shell_surface(struct wl_resource *resource)
2818 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2820 destroy_shell_surface(shsurf);
2824 shell_handle_surface_destroy(struct wl_listener *listener, void *data)
2826 struct shell_surface *shsurf = container_of(listener,
2827 struct shell_surface,
2828 surface_destroy_listener);
2830 if (shsurf->resource)
2831 wl_resource_destroy(shsurf->resource);
2833 destroy_shell_surface(shsurf);
2837 shell_surface_configure(struct weston_surface *, int32_t, int32_t, int32_t, int32_t);
2839 static struct shell_surface *
2840 get_shell_surface(struct weston_surface *surface)
2842 if (surface->configure == shell_surface_configure)
2843 return surface->configure_private;
2848 static struct shell_surface *
2849 create_shell_surface(void *shell, struct weston_surface *surface,
2850 const struct weston_shell_client *client)
2852 struct shell_surface *shsurf;
2854 if (surface->configure) {
2855 weston_log("surface->configure already set\n");
2859 shsurf = calloc(1, sizeof *shsurf);
2861 weston_log("no memory to allocate shell surface\n");
2865 shsurf->view = weston_view_create(surface);
2866 if (!shsurf->view) {
2867 weston_log("no memory to allocate shell surface\n");
2872 surface->configure = shell_surface_configure;
2873 surface->configure_private = shsurf;
2875 shsurf->shell = (struct desktop_shell *) shell;
2876 shsurf->unresponsive = 0;
2877 shsurf->saved_position_valid = false;
2878 shsurf->saved_rotation_valid = false;
2879 shsurf->surface = surface;
2880 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
2881 shsurf->fullscreen.framerate = 0;
2882 shsurf->fullscreen.black_view = NULL;
2883 shsurf->ping_timer = NULL;
2884 wl_list_init(&shsurf->fullscreen.transform.link);
2886 wl_signal_init(&shsurf->destroy_signal);
2887 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
2888 wl_signal_add(&surface->destroy_signal,
2889 &shsurf->surface_destroy_listener);
2891 /* init link so its safe to always remove it in destroy_shell_surface */
2892 wl_list_init(&shsurf->link);
2893 wl_list_init(&shsurf->popup.grab_link);
2895 /* empty when not in use */
2896 wl_list_init(&shsurf->rotation.transform.link);
2897 weston_matrix_init(&shsurf->rotation.rotation);
2899 wl_list_init(&shsurf->workspace_transform.link);
2901 shsurf->type = SHELL_SURFACE_NONE;
2902 shsurf->next_type = SHELL_SURFACE_NONE;
2904 shsurf->client = client;
2909 static struct weston_view *
2910 get_primary_view(void *shell, struct shell_surface *shsurf)
2912 return shsurf->view;
2916 shell_get_shell_surface(struct wl_client *client,
2917 struct wl_resource *resource,
2919 struct wl_resource *surface_resource)
2921 struct weston_surface *surface =
2922 wl_resource_get_user_data(surface_resource);
2923 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2924 struct shell_surface *shsurf;
2926 if (get_shell_surface(surface)) {
2927 wl_resource_post_error(surface_resource,
2928 WL_DISPLAY_ERROR_INVALID_OBJECT,
2929 "desktop_shell::get_shell_surface already requested");
2933 shsurf = create_shell_surface(shell, surface, &shell_client);
2935 wl_resource_post_error(surface_resource,
2936 WL_DISPLAY_ERROR_INVALID_OBJECT,
2937 "surface->configure already set");
2942 wl_resource_create(client,
2943 &wl_shell_surface_interface, 1, id);
2944 wl_resource_set_implementation(shsurf->resource,
2945 &shell_surface_implementation,
2946 shsurf, shell_destroy_shell_surface);
2949 static const struct wl_shell_interface shell_implementation = {
2950 shell_get_shell_surface
2954 shell_fade(struct desktop_shell *shell, enum fade_type type);
2957 screensaver_timeout(void *data)
2959 struct desktop_shell *shell = data;
2961 shell_fade(shell, FADE_OUT);
2967 handle_screensaver_sigchld(struct weston_process *proc, int status)
2969 struct desktop_shell *shell =
2970 container_of(proc, struct desktop_shell, screensaver.process);
2975 weston_compositor_sleep(shell->compositor);
2979 launch_screensaver(struct desktop_shell *shell)
2981 if (shell->screensaver.binding)
2984 if (!shell->screensaver.path) {
2985 weston_compositor_sleep(shell->compositor);
2989 if (shell->screensaver.process.pid != 0) {
2990 weston_log("old screensaver still running\n");
2994 weston_client_launch(shell->compositor,
2995 &shell->screensaver.process,
2996 shell->screensaver.path,
2997 handle_screensaver_sigchld);
3001 terminate_screensaver(struct desktop_shell *shell)
3003 if (shell->screensaver.process.pid == 0)
3006 kill(shell->screensaver.process.pid, SIGTERM);
3010 configure_static_view(struct weston_view *ev, struct weston_layer *layer, int32_t width, int32_t height)
3012 struct weston_view *v, *next;
3017 wl_list_for_each_safe(v, next, &layer->view_list, layer_link) {
3018 if (v->output == ev->output && v != ev) {
3019 weston_view_unmap(v);
3020 v->surface->configure = NULL;
3024 weston_view_configure(ev, ev->output->x, ev->output->y, width, height);
3026 if (wl_list_empty(&ev->layer_link)) {
3027 wl_list_insert(&layer->view_list, &ev->layer_link);
3028 weston_compositor_schedule_repaint(ev->surface->compositor);
3033 background_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
3035 struct desktop_shell *shell = es->configure_private;
3036 struct weston_view *view;
3038 view = container_of(es->views.next, struct weston_view, surface_link);
3040 configure_static_view(view, &shell->background_layer, width, height);
3044 desktop_shell_set_background(struct wl_client *client,
3045 struct wl_resource *resource,
3046 struct wl_resource *output_resource,
3047 struct wl_resource *surface_resource)
3049 struct desktop_shell *shell = wl_resource_get_user_data(resource);
3050 struct weston_surface *surface =
3051 wl_resource_get_user_data(surface_resource);
3052 struct weston_view *view, *next;
3054 if (surface->configure) {
3055 wl_resource_post_error(surface_resource,
3056 WL_DISPLAY_ERROR_INVALID_OBJECT,
3057 "surface role already assigned");
3061 wl_list_for_each_safe(view, next, &surface->views, surface_link)
3062 weston_view_destroy(view);
3063 view = weston_view_create(surface);
3065 surface->configure = background_configure;
3066 surface->configure_private = shell;
3067 surface->output = wl_resource_get_user_data(output_resource);
3068 view->output = surface->output;
3069 desktop_shell_send_configure(resource, 0,
3071 surface->output->width,
3072 surface->output->height);
3076 panel_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
3078 struct desktop_shell *shell = es->configure_private;
3079 struct weston_view *view;
3081 view = container_of(es->views.next, struct weston_view, surface_link);
3083 configure_static_view(view, &shell->panel_layer, width, height);
3087 desktop_shell_set_panel(struct wl_client *client,
3088 struct wl_resource *resource,
3089 struct wl_resource *output_resource,
3090 struct wl_resource *surface_resource)
3092 struct desktop_shell *shell = wl_resource_get_user_data(resource);
3093 struct weston_surface *surface =
3094 wl_resource_get_user_data(surface_resource);
3095 struct weston_view *view, *next;
3097 if (surface->configure) {
3098 wl_resource_post_error(surface_resource,
3099 WL_DISPLAY_ERROR_INVALID_OBJECT,
3100 "surface role already assigned");
3104 wl_list_for_each_safe(view, next, &surface->views, surface_link)
3105 weston_view_destroy(view);
3106 view = weston_view_create(surface);
3108 surface->configure = panel_configure;
3109 surface->configure_private = shell;
3110 surface->output = wl_resource_get_user_data(output_resource);
3111 view->output = surface->output;
3112 desktop_shell_send_configure(resource, 0,
3114 surface->output->width,
3115 surface->output->height);
3119 lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
3121 struct desktop_shell *shell = surface->configure_private;
3122 struct weston_view *view;
3124 view = container_of(surface->views.next, struct weston_view, surface_link);
3129 surface->width = width;
3130 surface->height = height;
3131 view->geometry.width = width;
3132 view->geometry.height = height;
3133 center_on_output(view, get_default_output(shell->compositor));
3135 if (!weston_surface_is_mapped(surface)) {
3136 wl_list_insert(&shell->lock_layer.view_list,
3138 weston_view_update_transform(view);
3139 shell_fade(shell, FADE_IN);
3144 handle_lock_surface_destroy(struct wl_listener *listener, void *data)
3146 struct desktop_shell *shell =
3147 container_of(listener, struct desktop_shell, lock_surface_listener);
3149 weston_log("lock surface gone\n");
3150 shell->lock_surface = NULL;
3154 desktop_shell_set_lock_surface(struct wl_client *client,
3155 struct wl_resource *resource,
3156 struct wl_resource *surface_resource)
3158 struct desktop_shell *shell = wl_resource_get_user_data(resource);
3159 struct weston_surface *surface =
3160 wl_resource_get_user_data(surface_resource);
3162 shell->prepare_event_sent = false;
3167 shell->lock_surface = surface;
3169 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
3170 wl_signal_add(&surface->destroy_signal,
3171 &shell->lock_surface_listener);
3173 weston_view_create(surface);
3174 surface->configure = lock_surface_configure;
3175 surface->configure_private = shell;
3179 resume_desktop(struct desktop_shell *shell)
3181 struct workspace *ws = get_current_workspace(shell);
3183 terminate_screensaver(shell);
3185 wl_list_remove(&shell->lock_layer.link);
3186 wl_list_insert(&shell->compositor->cursor_layer.link,
3187 &shell->fullscreen_layer.link);
3188 wl_list_insert(&shell->fullscreen_layer.link,
3189 &shell->panel_layer.link);
3190 if (shell->showing_input_panels) {
3191 wl_list_insert(&shell->panel_layer.link,
3192 &shell->input_panel_layer.link);
3193 wl_list_insert(&shell->input_panel_layer.link,
3196 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
3199 restore_focus_state(shell, get_current_workspace(shell));
3201 shell->locked = false;
3202 shell_fade(shell, FADE_IN);
3203 weston_compositor_damage_all(shell->compositor);
3207 desktop_shell_unlock(struct wl_client *client,
3208 struct wl_resource *resource)
3210 struct desktop_shell *shell = wl_resource_get_user_data(resource);
3212 shell->prepare_event_sent = false;
3215 resume_desktop(shell);
3219 desktop_shell_set_grab_surface(struct wl_client *client,
3220 struct wl_resource *resource,
3221 struct wl_resource *surface_resource)
3223 struct desktop_shell *shell = wl_resource_get_user_data(resource);
3225 shell->grab_surface = wl_resource_get_user_data(surface_resource);
3226 weston_view_create(shell->grab_surface);
3230 desktop_shell_desktop_ready(struct wl_client *client,
3231 struct wl_resource *resource)
3233 struct desktop_shell *shell = wl_resource_get_user_data(resource);
3235 shell_fade_startup(shell);
3238 static const struct desktop_shell_interface desktop_shell_implementation = {
3239 desktop_shell_set_background,
3240 desktop_shell_set_panel,
3241 desktop_shell_set_lock_surface,
3242 desktop_shell_unlock,
3243 desktop_shell_set_grab_surface,
3244 desktop_shell_desktop_ready
3247 static enum shell_surface_type
3248 get_shell_surface_type(struct weston_surface *surface)
3250 struct shell_surface *shsurf;
3252 shsurf = get_shell_surface(surface);
3254 return SHELL_SURFACE_NONE;
3255 return shsurf->type;
3259 move_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
3261 struct weston_surface *focus = seat->pointer->focus->surface;
3262 struct weston_surface *surface;
3263 struct shell_surface *shsurf;
3265 surface = weston_surface_get_main_surface(focus);
3266 if (surface == NULL)
3269 shsurf = get_shell_surface(surface);
3270 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
3271 shsurf->type == SHELL_SURFACE_MAXIMIZED)
3274 surface_move(shsurf, (struct weston_seat *) seat);
3278 touch_move_binding(struct weston_seat *seat, uint32_t time, void *data)
3280 struct weston_surface *focus = seat->touch->focus->surface;
3281 struct weston_surface *surface;
3282 struct shell_surface *shsurf;
3284 surface = weston_surface_get_main_surface(focus);
3285 if (surface == NULL)
3288 shsurf = get_shell_surface(surface);
3289 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
3290 shsurf->type == SHELL_SURFACE_MAXIMIZED)
3293 surface_touch_move(shsurf, (struct weston_seat *) seat);
3297 resize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
3299 struct weston_surface *focus = seat->pointer->focus->surface;
3300 struct weston_surface *surface;
3303 struct shell_surface *shsurf;
3305 surface = weston_surface_get_main_surface(focus);
3306 if (surface == NULL)
3309 shsurf = get_shell_surface(surface);
3310 if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
3311 shsurf->type == SHELL_SURFACE_MAXIMIZED)
3314 weston_view_from_global(shsurf->view,
3315 wl_fixed_to_int(seat->pointer->grab_x),
3316 wl_fixed_to_int(seat->pointer->grab_y),
3319 if (x < shsurf->view->geometry.width / 3)
3320 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
3321 else if (x < 2 * shsurf->view->geometry.width / 3)
3324 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
3326 if (y < shsurf->view->geometry.height / 3)
3327 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
3328 else if (y < 2 * shsurf->view->geometry.height / 3)
3331 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
3333 surface_resize(shsurf, (struct weston_seat *) seat, edges);
3337 surface_opacity_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
3338 wl_fixed_t value, void *data)
3341 struct shell_surface *shsurf;
3342 struct weston_surface *focus = seat->pointer->focus->surface;
3343 struct weston_surface *surface;
3345 /* XXX: broken for windows containing sub-surfaces */
3346 surface = weston_surface_get_main_surface(focus);
3347 if (surface == NULL)
3350 shsurf = get_shell_surface(surface);
3354 shsurf->view->alpha -= wl_fixed_to_double(value) * step;
3356 if (shsurf->view->alpha > 1.0)
3357 shsurf->view->alpha = 1.0;
3358 if (shsurf->view->alpha < step)
3359 shsurf->view->alpha = step;
3361 weston_view_geometry_dirty(shsurf->view);
3362 weston_surface_damage(surface);
3366 do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
3369 struct weston_seat *ws = (struct weston_seat *) seat;
3370 struct weston_compositor *compositor = ws->compositor;
3371 struct weston_output *output;
3374 wl_list_for_each(output, &compositor->output_list, link) {
3375 if (pixman_region32_contains_point(&output->region,
3376 wl_fixed_to_double(seat->pointer->x),
3377 wl_fixed_to_double(seat->pointer->y),
3379 if (key == KEY_PAGEUP)
3380 increment = output->zoom.increment;
3381 else if (key == KEY_PAGEDOWN)
3382 increment = -output->zoom.increment;
3383 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
3384 /* For every pixel zoom 20th of a step */
3385 increment = output->zoom.increment *
3386 -wl_fixed_to_double(value) / 20.0;
3390 output->zoom.level += increment;
3392 if (output->zoom.level < 0.0)
3393 output->zoom.level = 0.0;
3394 else if (output->zoom.level > output->zoom.max_level)
3395 output->zoom.level = output->zoom.max_level;
3396 else if (!output->zoom.active) {
3397 weston_output_activate_zoom(output);
3400 output->zoom.spring_z.target = output->zoom.level;
3402 weston_output_update_zoom(output);
3408 zoom_axis_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
3409 wl_fixed_t value, void *data)
3411 do_zoom(seat, time, 0, axis, value);
3415 zoom_key_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
3418 do_zoom(seat, time, key, 0, 0);
3422 terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
3425 struct weston_compositor *compositor = data;
3427 wl_display_terminate(compositor->wl_display);
3431 lower_fullscreen_layer(struct desktop_shell *shell);
3434 struct desktop_shell *shell;
3435 struct weston_keyboard_grab grab;
3437 struct wl_list *current;
3439 struct wl_list preview_list;
3442 struct alt_tab_preview {
3443 struct alt_tab *alt_tab;
3445 struct weston_view *view;
3446 struct weston_transform transform;
3448 struct wl_listener listener;
3450 struct wl_list link;
3454 alt_tab_next(struct alt_tab *alt_tab)
3456 alt_tab->current = alt_tab->current->next;
3458 /* Make sure we're not pointing to the list header e.g. after
3459 * cycling through the whole list. */
3460 if (alt_tab->current->next == alt_tab->preview_list.next)
3461 alt_tab->current = alt_tab->current->next;
3465 alt_tab_destroy(struct alt_tab *alt_tab)
3467 struct alt_tab_preview *preview, *next;
3468 struct weston_keyboard *keyboard = alt_tab->grab.keyboard;
3470 if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) {
3471 preview = wl_container_of(alt_tab->current, preview, link);
3473 activate(alt_tab->shell, preview->view->surface,
3474 (struct weston_seat *) keyboard->seat);
3477 wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) {
3478 wl_list_remove(&preview->link);
3479 wl_list_remove(&preview->listener.link);
3480 weston_view_destroy(preview->view);
3484 weston_keyboard_end_grab(keyboard);
3485 if (keyboard->input_method_resource)
3486 keyboard->grab = &keyboard->input_method_grab;
3492 alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data)
3494 struct alt_tab_preview *preview =
3495 container_of(listener, struct alt_tab_preview, listener);
3496 struct alt_tab *alt_tab = preview->alt_tab;
3499 /* If the preview that we're removing is the currently selected one,
3500 * we want to move to the next one. So we move to ->prev and then
3501 * call _next() after removing the preview. */
3502 if (alt_tab->current == &preview->link) {
3503 alt_tab->current = alt_tab->current->prev;
3507 wl_list_remove(&preview->listener.link);
3508 wl_list_remove(&preview->link);
3513 alt_tab_next(alt_tab);
3515 /* If the last preview goes away, stop the alt-tab */
3516 if (wl_list_empty(alt_tab->current))
3517 alt_tab_destroy(alt_tab);
3521 alt_tab_key(struct weston_keyboard_grab *grab,
3522 uint32_t time, uint32_t key, uint32_t state_w)
3524 struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab);
3525 enum wl_keyboard_key_state state = state_w;
3527 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
3528 alt_tab_next(alt_tab);
3532 alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
3533 uint32_t mods_depressed, uint32_t mods_latched,
3534 uint32_t mods_locked, uint32_t group)
3536 struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab);
3537 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
3539 if ((seat->modifier_state & MODIFIER_ALT) == 0)
3540 alt_tab_destroy(alt_tab);
3544 alt_tab_cancel(struct weston_keyboard_grab *grab)
3546 struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab);
3548 alt_tab_destroy(alt_tab);
3551 static const struct weston_keyboard_grab_interface alt_tab_grab = {
3558 view_for_alt_tab(struct weston_view *view)
3560 if (!get_shell_surface(view->surface))
3563 if (get_shell_surface_type(view->surface) == SHELL_SURFACE_TRANSIENT)
3566 if (view != get_default_view(view->surface))
3573 alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
3576 struct alt_tab *alt_tab;
3577 struct desktop_shell *shell = data;
3578 struct weston_output *output = get_default_output(shell->compositor);
3579 struct workspace *ws;
3580 struct weston_view *view;
3581 int num_surfaces = 0;
3582 int x, y, side, margin;
3584 wl_list_for_each(view, &shell->compositor->view_list, link) {
3586 if (view_for_alt_tab(view))
3593 alt_tab = malloc(sizeof *alt_tab);
3597 alt_tab->shell = shell;
3598 wl_list_init(&alt_tab->preview_list);
3599 alt_tab->current = &alt_tab->preview_list;
3601 restore_all_output_modes(shell->compositor);
3602 lower_fullscreen_layer(alt_tab->shell);
3604 alt_tab->grab.interface = &alt_tab_grab;
3605 weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab);
3606 weston_keyboard_set_focus(seat->keyboard, NULL);
3608 ws = get_current_workspace(shell);
3610 /* FIXME: add some visual candy e.g. prelight the selected view
3611 * and/or add a black surrounding background à la gnome-shell */
3613 /* Determine the size for each preview */
3614 side = output->width / num_surfaces;
3621 y = (output->height - side) / 2;
3623 /* Create a view for each surface */
3624 wl_list_for_each(view, &shell->compositor->view_list, link) {
3625 struct alt_tab_preview *preview;
3626 struct weston_view *v;
3629 if (!view_for_alt_tab(view))
3632 preview = malloc(sizeof *preview);
3634 alt_tab_destroy(alt_tab);
3638 preview->alt_tab = alt_tab;
3640 preview->view = v = weston_view_create(view->surface);
3641 v->output = view->output;
3642 weston_view_restack(v, &ws->layer.view_list);
3643 weston_view_configure(v, x, y, view->geometry.width, view->geometry.height);
3645 preview->listener.notify = alt_tab_handle_surface_destroy;
3646 wl_signal_add(&v->destroy_signal, &preview->listener);
3648 if (view->geometry.width > view->geometry.height)
3649 scale = side / (float) view->geometry.width;
3651 scale = side / (float) view->geometry.height;
3653 wl_list_insert(&v->geometry.transformation_list,
3654 &preview->transform.link);
3655 weston_matrix_init(&preview->transform.matrix);
3656 weston_matrix_scale(&preview->transform.matrix,
3657 scale, scale, 1.0f);
3659 weston_view_geometry_dirty(v);
3660 weston_compositor_schedule_repaint(v->surface->compositor);
3662 /* Insert at the end of the list */
3663 wl_list_insert(alt_tab->preview_list.prev, &preview->link);
3668 /* Start at the second preview so a simple <alt>tab changes window.
3669 * We set `current' to the first preview and not the second because
3670 * we're going to receive a key press callback for the initial
3671 * <alt>tab which will make `current' point to the second element. */
3672 alt_tab_next(alt_tab);
3676 rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
3677 wl_fixed_t x, wl_fixed_t y)
3679 struct rotate_grab *rotate =
3680 container_of(grab, struct rotate_grab, base.grab);
3681 struct weston_pointer *pointer = grab->pointer;
3682 struct shell_surface *shsurf = rotate->base.shsurf;
3683 float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
3685 weston_pointer_move(pointer, x, y);
3690 cx = 0.5f * shsurf->view->geometry.width;
3691 cy = 0.5f * shsurf->view->geometry.height;
3693 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
3694 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
3695 r = sqrtf(dx * dx + dy * dy);
3697 wl_list_remove(&shsurf->rotation.transform.link);
3698 weston_view_geometry_dirty(shsurf->view);
3701 struct weston_matrix *matrix =
3702 &shsurf->rotation.transform.matrix;
3704 weston_matrix_init(&rotate->rotation);
3705 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
3707 weston_matrix_init(matrix);
3708 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
3709 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
3710 weston_matrix_multiply(matrix, &rotate->rotation);
3711 weston_matrix_translate(matrix, cx, cy, 0.0f);
3714 &shsurf->view->geometry.transformation_list,
3715 &shsurf->rotation.transform.link);
3717 wl_list_init(&shsurf->rotation.transform.link);
3718 weston_matrix_init(&shsurf->rotation.rotation);
3719 weston_matrix_init(&rotate->rotation);
3722 /* We need to adjust the position of the surface
3723 * in case it was resized in a rotated state before */
3724 cposx = shsurf->view->geometry.x + cx;
3725 cposy = shsurf->view->geometry.y + cy;
3726 dposx = rotate->center.x - cposx;
3727 dposy = rotate->center.y - cposy;
3728 if (dposx != 0.0f || dposy != 0.0f) {
3729 weston_view_set_position(shsurf->view,
3730 shsurf->view->geometry.x + dposx,
3731 shsurf->view->geometry.y + dposy);
3734 /* Repaint implies weston_surface_update_transform(), which
3735 * lazily applies the damage due to rotation update.
3737 weston_compositor_schedule_repaint(shsurf->surface->compositor);
3741 rotate_grab_button(struct weston_pointer_grab *grab,
3742 uint32_t time, uint32_t button, uint32_t state_w)
3744 struct rotate_grab *rotate =
3745 container_of(grab, struct rotate_grab, base.grab);
3746 struct weston_pointer *pointer = grab->pointer;
3747 struct shell_surface *shsurf = rotate->base.shsurf;
3748 enum wl_pointer_button_state state = state_w;
3750 if (pointer->button_count == 0 &&
3751 state == WL_POINTER_BUTTON_STATE_RELEASED) {
3753 weston_matrix_multiply(&shsurf->rotation.rotation,
3755 shell_grab_end(&rotate->base);
3761 rotate_grab_cancel(struct weston_pointer_grab *grab)
3763 struct rotate_grab *rotate =
3764 container_of(grab, struct rotate_grab, base.grab);
3766 shell_grab_end(&rotate->base);
3770 static const struct weston_pointer_grab_interface rotate_grab_interface = {
3778 surface_rotate(struct shell_surface *surface, struct weston_seat *seat)
3780 struct rotate_grab *rotate;
3784 rotate = malloc(sizeof *rotate);
3788 weston_view_to_global_float(surface->view,
3789 surface->view->geometry.width * 0.5f,
3790 surface->view->geometry.height * 0.5f,
3791 &rotate->center.x, &rotate->center.y);
3793 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
3794 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
3795 r = sqrtf(dx * dx + dy * dy);
3797 struct weston_matrix inverse;
3799 weston_matrix_init(&inverse);
3800 weston_matrix_rotate_xy(&inverse, dx / r, -dy / r);
3801 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
3803 weston_matrix_init(&rotate->rotation);
3804 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
3806 weston_matrix_init(&surface->rotation.rotation);
3807 weston_matrix_init(&rotate->rotation);
3810 shell_grab_start(&rotate->base, &rotate_grab_interface, surface,
3811 seat->pointer, DESKTOP_SHELL_CURSOR_ARROW);
3815 rotate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
3818 struct weston_surface *focus = seat->pointer->focus->surface;
3819 struct weston_surface *base_surface;
3820 struct shell_surface *surface;
3822 base_surface = weston_surface_get_main_surface(focus);
3823 if (base_surface == NULL)
3826 surface = get_shell_surface(base_surface);
3827 if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN ||
3828 surface->type == SHELL_SURFACE_MAXIMIZED)
3831 surface_rotate(surface, seat);
3835 lower_fullscreen_layer(struct desktop_shell *shell)
3837 struct workspace *ws;
3838 struct weston_view *view, *prev;
3840 ws = get_current_workspace(shell);
3841 wl_list_for_each_reverse_safe(view, prev,
3842 &shell->fullscreen_layer.view_list,
3844 weston_view_restack(view, &ws->layer.view_list);
3848 activate(struct desktop_shell *shell, struct weston_surface *es,
3849 struct weston_seat *seat)
3851 struct weston_surface *main_surface;
3852 struct weston_view *main_view;
3853 struct focus_state *state;
3854 struct workspace *ws;
3855 struct weston_surface *old_es;
3857 main_surface = weston_surface_get_main_surface(es);
3859 weston_surface_activate(es, seat);
3861 state = ensure_focus_state(shell, seat);
3865 old_es = state->keyboard_focus;
3866 state->keyboard_focus = es;
3867 wl_list_remove(&state->surface_destroy_listener.link);
3868 wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener);
3870 switch (get_shell_surface_type(main_surface)) {
3871 case SHELL_SURFACE_FULLSCREEN:
3872 /* should on top of panels */
3873 shell_stack_fullscreen(get_shell_surface(main_surface));
3874 shell_configure_fullscreen(get_shell_surface(main_surface));
3876 case SHELL_SURFACE_TOPLEVEL:
3877 case SHELL_SURFACE_TRANSIENT:
3878 case SHELL_SURFACE_MAXIMIZED:
3879 case SHELL_SURFACE_POPUP:
3880 case SHELL_SURFACE_XWAYLAND:
3881 case SHELL_SURFACE_NONE:
3883 restore_all_output_modes(shell->compositor);
3884 ws = get_current_workspace(shell);
3885 main_view = get_default_view(main_surface);
3887 weston_view_restack(main_view, &ws->layer.view_list);
3891 if (shell->focus_animation_type != ANIMATION_NONE)
3892 animate_focus_change(shell, ws, get_default_view(old_es), get_default_view(es));
3895 /* no-op func for checking black surface */
3897 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
3902 is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
3904 if (es->configure == black_surface_configure) {
3906 *fs_surface = (struct weston_surface *)es->configure_private;
3913 activate_binding(struct weston_seat *seat,
3914 struct desktop_shell *shell,
3915 struct weston_surface *focus)
3917 struct weston_surface *main_surface;
3922 if (is_black_surface(focus, &main_surface))
3923 focus = main_surface;
3925 main_surface = weston_surface_get_main_surface(focus);
3926 if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE)
3929 activate(shell, focus, seat);
3933 click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
3936 if (seat->pointer->grab != &seat->pointer->default_grab)
3939 activate_binding(seat, data, seat->pointer->focus->surface);
3943 touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data)
3945 if (seat->touch->grab != &seat->touch->default_grab)
3948 activate_binding(seat, data, seat->touch->focus->surface);
3952 lock(struct desktop_shell *shell)
3954 struct workspace *ws = get_current_workspace(shell);
3956 if (shell->locked) {
3957 weston_compositor_sleep(shell->compositor);
3961 shell->locked = true;
3963 /* Hide all surfaces by removing the fullscreen, panel and
3964 * toplevel layers. This way nothing else can show or receive
3965 * input events while we are locked. */
3967 wl_list_remove(&shell->panel_layer.link);
3968 wl_list_remove(&shell->fullscreen_layer.link);
3969 if (shell->showing_input_panels)
3970 wl_list_remove(&shell->input_panel_layer.link);
3971 wl_list_remove(&ws->layer.link);
3972 wl_list_insert(&shell->compositor->cursor_layer.link,
3973 &shell->lock_layer.link);
3975 launch_screensaver(shell);
3977 /* TODO: disable bindings that should not work while locked. */
3979 /* All this must be undone in resume_desktop(). */
3983 unlock(struct desktop_shell *shell)
3985 if (!shell->locked || shell->lock_surface) {
3986 shell_fade(shell, FADE_IN);
3990 /* If desktop-shell client has gone away, unlock immediately. */
3991 if (!shell->child.desktop_shell) {
3992 resume_desktop(shell);
3996 if (shell->prepare_event_sent)
3999 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
4000 shell->prepare_event_sent = true;
4004 shell_fade_done(struct weston_view_animation *animation, void *data)
4006 struct desktop_shell *shell = data;
4008 shell->fade.animation = NULL;
4010 switch (shell->fade.type) {
4012 weston_surface_destroy(shell->fade.view->surface);
4013 shell->fade.view = NULL;
4023 static struct weston_view *
4024 shell_fade_create_surface(struct desktop_shell *shell)
4026 struct weston_compositor *compositor = shell->compositor;
4027 struct weston_surface *surface;
4028 struct weston_view *view;
4030 surface = weston_surface_create(compositor);
4034 view = weston_view_create(surface);
4036 weston_surface_destroy(surface);
4040 weston_view_configure(view, 0, 0, 8192, 8192);
4041 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
4042 wl_list_insert(&compositor->fade_layer.view_list,
4044 pixman_region32_init(&surface->input);
4050 shell_fade(struct desktop_shell *shell, enum fade_type type)
4062 weston_log("shell: invalid fade type\n");
4066 shell->fade.type = type;
4068 if (shell->fade.view == NULL) {
4069 shell->fade.view = shell_fade_create_surface(shell);
4070 if (!shell->fade.view)
4073 shell->fade.view->alpha = 1.0 - tint;
4074 weston_view_update_transform(shell->fade.view);
4077 if (shell->fade.animation)
4078 weston_fade_update(shell->fade.animation, tint);
4080 shell->fade.animation =
4081 weston_fade_run(shell->fade.view,
4082 1.0 - tint, tint, 300.0,
4083 shell_fade_done, shell);
4087 do_shell_fade_startup(void *data)
4089 struct desktop_shell *shell = data;
4091 if (shell->startup_animation_type == ANIMATION_FADE)
4092 shell_fade(shell, FADE_IN);
4093 else if (shell->startup_animation_type == ANIMATION_NONE) {
4094 weston_surface_destroy(shell->fade.view->surface);
4095 shell->fade.view = NULL;
4100 shell_fade_startup(struct desktop_shell *shell)
4102 struct wl_event_loop *loop;
4104 if (!shell->fade.startup_timer)
4107 wl_event_source_remove(shell->fade.startup_timer);
4108 shell->fade.startup_timer = NULL;
4110 loop = wl_display_get_event_loop(shell->compositor->wl_display);
4111 wl_event_loop_add_idle(loop, do_shell_fade_startup, shell);
4115 fade_startup_timeout(void *data)
4117 struct desktop_shell *shell = data;
4119 shell_fade_startup(shell);
4124 shell_fade_init(struct desktop_shell *shell)
4126 /* Make compositor output all black, and wait for the desktop-shell
4127 * client to signal it is ready, then fade in. The timer triggers a
4128 * fade-in, in case the desktop-shell client takes too long.
4131 struct wl_event_loop *loop;
4133 if (shell->fade.view != NULL) {
4134 weston_log("%s: warning: fade surface already exists\n",
4139 shell->fade.view = shell_fade_create_surface(shell);
4140 if (!shell->fade.view)
4143 weston_view_update_transform(shell->fade.view);
4144 weston_surface_damage(shell->fade.view->surface);
4146 loop = wl_display_get_event_loop(shell->compositor->wl_display);
4147 shell->fade.startup_timer =
4148 wl_event_loop_add_timer(loop, fade_startup_timeout, shell);
4149 wl_event_source_timer_update(shell->fade.startup_timer, 15000);
4153 idle_handler(struct wl_listener *listener, void *data)
4155 struct desktop_shell *shell =
4156 container_of(listener, struct desktop_shell, idle_listener);
4158 shell_fade(shell, FADE_OUT);
4159 /* lock() is called from shell_fade_done() */
4163 wake_handler(struct wl_listener *listener, void *data)
4165 struct desktop_shell *shell =
4166 container_of(listener, struct desktop_shell, wake_listener);
4172 show_input_panels(struct wl_listener *listener, void *data)
4174 struct desktop_shell *shell =
4175 container_of(listener, struct desktop_shell,
4176 show_input_panel_listener);
4177 struct input_panel_surface *ipsurf, *next;
4179 shell->text_input.surface = (struct weston_surface*)data;
4181 if (shell->showing_input_panels)
4184 shell->showing_input_panels = true;
4187 wl_list_insert(&shell->panel_layer.link,
4188 &shell->input_panel_layer.link);
4190 wl_list_for_each_safe(ipsurf, next,
4191 &shell->input_panel.surfaces, link) {
4192 if (!ipsurf->surface->buffer_ref.buffer)
4194 wl_list_insert(&shell->input_panel_layer.view_list,
4195 &ipsurf->view->layer_link);
4196 weston_view_geometry_dirty(ipsurf->view);
4197 weston_view_update_transform(ipsurf->view);
4198 weston_surface_damage(ipsurf->surface);
4199 weston_slide_run(ipsurf->view, ipsurf->view->geometry.height,
4205 hide_input_panels(struct wl_listener *listener, void *data)
4207 struct desktop_shell *shell =
4208 container_of(listener, struct desktop_shell,
4209 hide_input_panel_listener);
4210 struct weston_view *view, *next;
4212 if (!shell->showing_input_panels)
4215 shell->showing_input_panels = false;
4218 wl_list_remove(&shell->input_panel_layer.link);
4220 wl_list_for_each_safe(view, next,
4221 &shell->input_panel_layer.view_list, layer_link)
4222 weston_view_unmap(view);
4226 update_input_panels(struct wl_listener *listener, void *data)
4228 struct desktop_shell *shell =
4229 container_of(listener, struct desktop_shell,
4230 update_input_panel_listener);
4232 memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t));
4236 center_on_output(struct weston_view *view, struct weston_output *output)
4238 int32_t surf_x, surf_y, width, height;
4241 surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height);
4243 x = output->x + (output->width - width) / 2 - surf_x / 2;
4244 y = output->y + (output->height - height) / 2 - surf_y / 2;
4246 weston_view_configure(view, x, y, width, height);
4250 weston_view_set_initial_position(struct weston_view *view,
4251 struct desktop_shell *shell)
4253 struct weston_compositor *compositor = shell->compositor;
4255 int range_x, range_y;
4256 int dx, dy, x, y, panel_height;
4257 struct weston_output *output, *target_output = NULL;
4258 struct weston_seat *seat;
4260 /* As a heuristic place the new window on the same output as the
4261 * pointer. Falling back to the output containing 0, 0.
4263 * TODO: Do something clever for touch too?
4265 wl_list_for_each(seat, &compositor->seat_list, link) {
4266 if (seat->pointer) {
4267 ix = wl_fixed_to_int(seat->pointer->x);
4268 iy = wl_fixed_to_int(seat->pointer->y);
4273 wl_list_for_each(output, &compositor->output_list, link) {
4274 if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) {
4275 target_output = output;
4280 if (!target_output) {
4281 weston_view_set_position(view, 10 + random() % 400,
4282 10 + random() % 400);
4286 /* Valid range within output where the surface will still be onscreen.
4287 * If this is negative it means that the surface is bigger than
4290 panel_height = get_output_panel_height(shell, target_output);
4291 range_x = target_output->width - view->geometry.width;
4292 range_y = (target_output->height - panel_height) -
4293 view->geometry.height;
4296 dx = random() % range_x;
4301 dy = panel_height + random() % range_y;
4305 x = target_output->x + dx;
4306 y = target_output->y + dy;
4308 weston_view_set_position(view, x, y);
4312 map(struct desktop_shell *shell, struct shell_surface *shsurf,
4313 int32_t width, int32_t height, int32_t sx, int32_t sy)
4315 struct weston_compositor *compositor = shell->compositor;
4316 struct weston_view *parent;
4317 struct weston_seat *seat;
4318 struct workspace *ws;
4319 int panel_height = 0;
4320 int32_t surf_x, surf_y;
4322 shsurf->view->geometry.width = width;
4323 shsurf->view->geometry.height = height;
4324 weston_view_geometry_dirty(shsurf->view);
4326 /* initial positioning, see also configure() */
4327 switch (shsurf->type) {
4328 case SHELL_SURFACE_TOPLEVEL:
4329 weston_view_set_initial_position(shsurf->view, shell);
4331 case SHELL_SURFACE_FULLSCREEN:
4332 center_on_output(shsurf->view, shsurf->fullscreen_output);
4333 shell_map_fullscreen(shsurf);
4335 case SHELL_SURFACE_MAXIMIZED:
4336 /* use surface configure to set the geometry */
4337 panel_height = get_output_panel_height(shell, shsurf->output);
4338 surface_subsurfaces_boundingbox(shsurf->surface,
4339 &surf_x, &surf_y, NULL, NULL);
4340 weston_view_set_position(shsurf->view,
4341 shsurf->output->x - surf_x,
4342 shsurf->output->y + panel_height - surf_y);
4344 case SHELL_SURFACE_POPUP:
4345 shell_map_popup(shsurf);
4347 case SHELL_SURFACE_NONE:
4348 weston_view_set_position(shsurf->view,
4349 shsurf->view->geometry.x + sx,
4350 shsurf->view->geometry.y + sy);
4352 case SHELL_SURFACE_TRANSIENT:
4353 case SHELL_SURFACE_XWAYLAND:
4358 /* surface stacking order, see also activate() */
4359 switch (shsurf->type) {
4360 case SHELL_SURFACE_POPUP:
4361 case SHELL_SURFACE_TRANSIENT:
4362 /* TODO: Handle a parent with multiple views */
4363 parent = get_default_view(shsurf->parent);
4365 wl_list_remove(&shsurf->view->layer_link);
4366 wl_list_insert(parent->layer_link.prev,
4367 &shsurf->view->layer_link);
4370 case SHELL_SURFACE_FULLSCREEN:
4371 case SHELL_SURFACE_NONE:
4373 case SHELL_SURFACE_XWAYLAND:
4374 case SHELL_SURFACE_TOPLEVEL:
4375 case SHELL_SURFACE_MAXIMIZED:
4377 ws = get_current_workspace(shell);
4378 wl_list_remove(&shsurf->view->layer_link);
4379 wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link);
4383 if (shsurf->type != SHELL_SURFACE_NONE) {
4384 weston_view_update_transform(shsurf->view);
4385 if (shsurf->type == SHELL_SURFACE_MAXIMIZED) {
4386 shsurf->surface->output = shsurf->output;
4387 shsurf->view->output = shsurf->output;
4391 switch (shsurf->type) {
4392 /* XXX: xwayland's using the same fields for transient type */
4393 case SHELL_SURFACE_XWAYLAND:
4394 case SHELL_SURFACE_TRANSIENT:
4395 if (shsurf->transient.flags ==
4396 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
4398 case SHELL_SURFACE_TOPLEVEL:
4399 case SHELL_SURFACE_FULLSCREEN:
4400 case SHELL_SURFACE_MAXIMIZED:
4401 if (!shell->locked) {
4402 wl_list_for_each(seat, &compositor->seat_list, link)
4403 activate(shell, shsurf->surface, seat);
4406 case SHELL_SURFACE_POPUP:
4407 case SHELL_SURFACE_NONE:
4412 if (shsurf->type == SHELL_SURFACE_TOPLEVEL)
4414 switch (shell->win_animation_type) {
4415 case ANIMATION_FADE:
4416 weston_fade_run(shsurf->view, 0.0, 1.0, 300.0, NULL, NULL);
4418 case ANIMATION_ZOOM:
4419 weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL);
4421 case ANIMATION_NONE:
4429 configure(struct desktop_shell *shell, struct weston_surface *surface,
4430 float x, float y, int32_t width, int32_t height)
4432 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
4433 struct shell_surface *shsurf;
4434 struct weston_view *view;
4435 int32_t surf_x, surf_y;
4437 shsurf = get_shell_surface(surface);
4439 surface_type = shsurf->type;
4442 * This should probably be changed to be more shell_surface
4445 wl_list_for_each(view, &surface->views, surface_link)
4446 weston_view_configure(view, x, y, width, height);
4448 switch (surface_type) {
4449 case SHELL_SURFACE_FULLSCREEN:
4450 shell_stack_fullscreen(shsurf);
4451 shell_configure_fullscreen(shsurf);
4453 case SHELL_SURFACE_MAXIMIZED:
4454 /* setting x, y and using configure to change that geometry */
4455 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
4457 shsurf->view->geometry.x = shsurf->output->x - surf_x;
4458 shsurf->view->geometry.y = shsurf->output->y +
4459 get_output_panel_height(shell,shsurf->output) - surf_y;
4461 case SHELL_SURFACE_TOPLEVEL:
4462 case SHELL_SURFACE_TRANSIENT:
4463 case SHELL_SURFACE_POPUP:
4464 case SHELL_SURFACE_XWAYLAND:
4465 case SHELL_SURFACE_NONE:
4470 /* XXX: would a fullscreen surface need the same handling? */
4471 if (surface->output) {
4472 wl_list_for_each(view, &surface->views, surface_link)
4473 weston_view_update_transform(view);
4475 if (surface_type == SHELL_SURFACE_MAXIMIZED)
4476 surface->output = shsurf->output;
4481 shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
4483 struct shell_surface *shsurf = get_shell_surface(es);
4484 struct desktop_shell *shell = shsurf->shell;
4486 int type_changed = 0;
4488 if (!weston_surface_is_mapped(es) &&
4489 !wl_list_empty(&shsurf->popup.grab_link)) {
4490 remove_popup_grab(shsurf);
4496 if (shsurf->next_type != SHELL_SURFACE_NONE &&
4497 shsurf->type != shsurf->next_type) {
4498 set_surface_type(shsurf);
4502 if (!weston_surface_is_mapped(es)) {
4503 map(shell, shsurf, width, height, sx, sy);
4504 } else if (type_changed || sx != 0 || sy != 0 ||
4505 shsurf->view->geometry.width != width ||
4506 shsurf->view->geometry.height != height) {
4507 float from_x, from_y;
4510 weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y);
4511 weston_view_to_global_float(shsurf->view, sx, sy, &to_x, &to_y);
4512 configure(shell, es,
4513 shsurf->view->geometry.x + to_x - from_x,
4514 shsurf->view->geometry.y + to_y - from_y,
4519 static void launch_desktop_shell_process(void *data);
4522 desktop_shell_sigchld(struct weston_process *process, int status)
4525 struct desktop_shell *shell =
4526 container_of(process, struct desktop_shell, child.process);
4528 shell->child.process.pid = 0;
4529 shell->child.client = NULL; /* already destroyed by wayland */
4531 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
4532 time = weston_compositor_get_time();
4533 if (time - shell->child.deathstamp > 30000) {
4534 shell->child.deathstamp = time;
4535 shell->child.deathcount = 0;
4538 shell->child.deathcount++;
4539 if (shell->child.deathcount > 5) {
4540 weston_log("%s died, giving up.\n", shell->client);
4544 weston_log("%s died, respawning...\n", shell->client);
4545 launch_desktop_shell_process(shell);
4546 shell_fade_startup(shell);
4550 launch_desktop_shell_process(void *data)
4552 struct desktop_shell *shell = data;
4554 shell->child.client = weston_client_launch(shell->compositor,
4555 &shell->child.process,
4557 desktop_shell_sigchld);
4559 if (!shell->child.client)
4560 weston_log("not able to start %s\n", shell->client);
4564 bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
4566 struct desktop_shell *shell = data;
4567 struct wl_resource *resource;
4569 resource = wl_resource_create(client, &wl_shell_interface, 1, id);
4571 wl_resource_set_implementation(resource, &shell_implementation,
4576 unbind_desktop_shell(struct wl_resource *resource)
4578 struct desktop_shell *shell = wl_resource_get_user_data(resource);
4581 resume_desktop(shell);
4583 shell->child.desktop_shell = NULL;
4584 shell->prepare_event_sent = false;
4588 bind_desktop_shell(struct wl_client *client,
4589 void *data, uint32_t version, uint32_t id)
4591 struct desktop_shell *shell = data;
4592 struct wl_resource *resource;
4594 resource = wl_resource_create(client, &desktop_shell_interface,
4595 MIN(version, 2), id);
4597 if (client == shell->child.client) {
4598 wl_resource_set_implementation(resource,
4599 &desktop_shell_implementation,
4600 shell, unbind_desktop_shell);
4601 shell->child.desktop_shell = resource;
4604 shell_fade_startup(shell);
4609 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
4610 "permission to bind desktop_shell denied");
4611 wl_resource_destroy(resource);
4615 screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
4617 struct desktop_shell *shell = surface->configure_private;
4618 struct weston_view *view;
4623 /* XXX: starting weston-screensaver beforehand does not work */
4627 view = container_of(surface->views.next, struct weston_view, surface_link);
4628 center_on_output(view, surface->output);
4630 if (wl_list_empty(&view->layer_link)) {
4631 wl_list_insert(shell->lock_layer.view_list.prev,
4633 weston_view_update_transform(view);
4634 wl_event_source_timer_update(shell->screensaver.timer,
4635 shell->screensaver.duration);
4636 shell_fade(shell, FADE_IN);
4641 screensaver_set_surface(struct wl_client *client,
4642 struct wl_resource *resource,
4643 struct wl_resource *surface_resource,
4644 struct wl_resource *output_resource)
4646 struct desktop_shell *shell = wl_resource_get_user_data(resource);
4647 struct weston_surface *surface =
4648 wl_resource_get_user_data(surface_resource);
4649 struct weston_output *output = wl_resource_get_user_data(output_resource);
4650 struct weston_view *view, *next;
4652 /* Make sure we only have one view */
4653 wl_list_for_each_safe(view, next, &surface->views, surface_link)
4654 weston_view_destroy(view);
4655 weston_view_create(surface);
4657 surface->configure = screensaver_configure;
4658 surface->configure_private = shell;
4659 surface->output = output;
4662 static const struct screensaver_interface screensaver_implementation = {
4663 screensaver_set_surface
4667 unbind_screensaver(struct wl_resource *resource)
4669 struct desktop_shell *shell = wl_resource_get_user_data(resource);
4671 shell->screensaver.binding = NULL;
4675 bind_screensaver(struct wl_client *client,
4676 void *data, uint32_t version, uint32_t id)
4678 struct desktop_shell *shell = data;
4679 struct wl_resource *resource;
4681 resource = wl_resource_create(client, &screensaver_interface, 1, id);
4683 if (shell->screensaver.binding == NULL) {
4684 wl_resource_set_implementation(resource,
4685 &screensaver_implementation,
4686 shell, unbind_screensaver);
4687 shell->screensaver.binding = resource;
4691 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
4692 "interface object already bound");
4693 wl_resource_destroy(resource);
4697 input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
4699 struct input_panel_surface *ip_surface = surface->configure_private;
4700 struct desktop_shell *shell = ip_surface->shell;
4702 uint32_t show_surface = 0;
4707 if (!weston_surface_is_mapped(surface)) {
4708 if (!shell->showing_input_panels)
4714 fprintf(stderr, "%s panel: %d, output: %p\n", __FUNCTION__, ip_surface->panel, ip_surface->output);
4716 if (ip_surface->panel) {
4717 x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2;
4718 y = get_default_view(shell->text_input.surface)->geometry.y + shell->text_input.cursor_rectangle.y2;
4720 x = ip_surface->output->x + (ip_surface->output->width - width) / 2;
4721 y = ip_surface->output->y + ip_surface->output->height - height;
4724 weston_view_configure(ip_surface->view, x, y, width, height);
4727 wl_list_insert(&shell->input_panel_layer.view_list,
4728 &ip_surface->view->layer_link);
4729 weston_view_update_transform(ip_surface->view);
4730 weston_surface_damage(surface);
4731 weston_slide_run(ip_surface->view, ip_surface->view->geometry.height, 0, NULL, NULL);
4736 destroy_input_panel_surface(struct input_panel_surface *input_panel_surface)
4738 wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface);
4740 wl_list_remove(&input_panel_surface->surface_destroy_listener.link);
4741 wl_list_remove(&input_panel_surface->link);
4743 input_panel_surface->surface->configure = NULL;
4744 weston_view_destroy(input_panel_surface->view);
4746 free(input_panel_surface);
4749 static struct input_panel_surface *
4750 get_input_panel_surface(struct weston_surface *surface)
4752 if (surface->configure == input_panel_configure) {
4753 return surface->configure_private;
4760 input_panel_handle_surface_destroy(struct wl_listener *listener, void *data)
4762 struct input_panel_surface *ipsurface = container_of(listener,
4763 struct input_panel_surface,
4764 surface_destroy_listener);
4766 if (ipsurface->resource) {
4767 wl_resource_destroy(ipsurface->resource);
4769 destroy_input_panel_surface(ipsurface);
4773 static struct input_panel_surface *
4774 create_input_panel_surface(struct desktop_shell *shell,
4775 struct weston_surface *surface)
4777 struct input_panel_surface *input_panel_surface;
4779 input_panel_surface = calloc(1, sizeof *input_panel_surface);
4780 if (!input_panel_surface)
4783 surface->configure = input_panel_configure;
4784 surface->configure_private = input_panel_surface;
4786 input_panel_surface->shell = shell;
4788 input_panel_surface->surface = surface;
4789 input_panel_surface->view = weston_view_create(surface);
4791 wl_signal_init(&input_panel_surface->destroy_signal);
4792 input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy;
4793 wl_signal_add(&surface->destroy_signal,
4794 &input_panel_surface->surface_destroy_listener);
4796 wl_list_init(&input_panel_surface->link);
4798 return input_panel_surface;
4802 input_panel_surface_set_toplevel(struct wl_client *client,
4803 struct wl_resource *resource,
4804 struct wl_resource *output_resource,
4807 struct input_panel_surface *input_panel_surface =
4808 wl_resource_get_user_data(resource);
4809 struct desktop_shell *shell = input_panel_surface->shell;
4811 wl_list_insert(&shell->input_panel.surfaces,
4812 &input_panel_surface->link);
4814 input_panel_surface->output = wl_resource_get_user_data(output_resource);
4815 input_panel_surface->panel = 0;
4819 input_panel_surface_set_overlay_panel(struct wl_client *client,
4820 struct wl_resource *resource)
4822 struct input_panel_surface *input_panel_surface =
4823 wl_resource_get_user_data(resource);
4824 struct desktop_shell *shell = input_panel_surface->shell;
4826 wl_list_insert(&shell->input_panel.surfaces,
4827 &input_panel_surface->link);
4829 input_panel_surface->panel = 1;
4832 static const struct wl_input_panel_surface_interface input_panel_surface_implementation = {
4833 input_panel_surface_set_toplevel,
4834 input_panel_surface_set_overlay_panel
4838 destroy_input_panel_surface_resource(struct wl_resource *resource)
4840 struct input_panel_surface *ipsurf =
4841 wl_resource_get_user_data(resource);
4843 destroy_input_panel_surface(ipsurf);
4847 input_panel_get_input_panel_surface(struct wl_client *client,
4848 struct wl_resource *resource,
4850 struct wl_resource *surface_resource)
4852 struct weston_surface *surface =
4853 wl_resource_get_user_data(surface_resource);
4854 struct desktop_shell *shell = wl_resource_get_user_data(resource);
4855 struct input_panel_surface *ipsurf;
4857 if (get_input_panel_surface(surface)) {
4858 wl_resource_post_error(surface_resource,
4859 WL_DISPLAY_ERROR_INVALID_OBJECT,
4860 "wl_input_panel::get_input_panel_surface already requested");
4864 ipsurf = create_input_panel_surface(shell, surface);
4866 wl_resource_post_error(surface_resource,
4867 WL_DISPLAY_ERROR_INVALID_OBJECT,
4868 "surface->configure already set");
4873 wl_resource_create(client,
4874 &wl_input_panel_surface_interface, 1, id);
4875 wl_resource_set_implementation(ipsurf->resource,
4876 &input_panel_surface_implementation,
4878 destroy_input_panel_surface_resource);
4881 static const struct wl_input_panel_interface input_panel_implementation = {
4882 input_panel_get_input_panel_surface
4886 unbind_input_panel(struct wl_resource *resource)
4888 struct desktop_shell *shell = wl_resource_get_user_data(resource);
4890 shell->input_panel.binding = NULL;
4894 bind_input_panel(struct wl_client *client,
4895 void *data, uint32_t version, uint32_t id)
4897 struct desktop_shell *shell = data;
4898 struct wl_resource *resource;
4900 resource = wl_resource_create(client,
4901 &wl_input_panel_interface, 1, id);
4903 if (shell->input_panel.binding == NULL) {
4904 wl_resource_set_implementation(resource,
4905 &input_panel_implementation,
4906 shell, unbind_input_panel);
4907 shell->input_panel.binding = resource;
4911 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
4912 "interface object already bound");
4913 wl_resource_destroy(resource);
4917 struct desktop_shell *shell;
4918 struct weston_surface *current;
4919 struct wl_listener listener;
4920 struct weston_keyboard_grab grab;
4924 switcher_next(struct switcher *switcher)
4926 struct weston_view *view;
4927 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
4928 struct shell_surface *shsurf;
4929 struct workspace *ws = get_current_workspace(switcher->shell);
4931 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
4932 switch (get_shell_surface_type(view->surface)) {
4933 case SHELL_SURFACE_TOPLEVEL:
4934 case SHELL_SURFACE_FULLSCREEN:
4935 case SHELL_SURFACE_MAXIMIZED:
4937 first = view->surface;
4938 if (prev == switcher->current)
4939 next = view->surface;
4940 prev = view->surface;
4942 weston_view_geometry_dirty(view);
4943 weston_surface_damage(view->surface);
4945 case SHELL_SURFACE_TRANSIENT:
4946 case SHELL_SURFACE_POPUP:
4947 case SHELL_SURFACE_XWAYLAND:
4948 case SHELL_SURFACE_NONE:
4953 if (is_black_surface(view->surface, NULL)) {
4955 weston_view_geometry_dirty(view);
4956 weston_surface_damage(view->surface);
4966 wl_list_remove(&switcher->listener.link);
4967 wl_signal_add(&next->destroy_signal, &switcher->listener);
4969 switcher->current = next;
4970 wl_list_for_each(view, &next->views, surface_link)
4973 shsurf = get_shell_surface(switcher->current);
4974 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
4975 shsurf->fullscreen.black_view->alpha = 1.0;
4979 switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
4981 struct switcher *switcher =
4982 container_of(listener, struct switcher, listener);
4984 switcher_next(switcher);
4988 switcher_destroy(struct switcher *switcher)
4990 struct weston_view *view;
4991 struct weston_keyboard *keyboard = switcher->grab.keyboard;
4992 struct workspace *ws = get_current_workspace(switcher->shell);
4994 wl_list_for_each(view, &ws->layer.view_list, layer_link) {
4995 if (is_focus_view(view))
4999 weston_surface_damage(view->surface);
5002 if (switcher->current)
5003 activate(switcher->shell, switcher->current,
5004 (struct weston_seat *) keyboard->seat);
5005 wl_list_remove(&switcher->listener.link);
5006 weston_keyboard_end_grab(keyboard);
5007 if (keyboard->input_method_resource)
5008 keyboard->grab = &keyboard->input_method_grab;
5013 switcher_key(struct weston_keyboard_grab *grab,
5014 uint32_t time, uint32_t key, uint32_t state_w)
5016 struct switcher *switcher = container_of(grab, struct switcher, grab);
5017 enum wl_keyboard_key_state state = state_w;
5019 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
5020 switcher_next(switcher);
5024 switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
5025 uint32_t mods_depressed, uint32_t mods_latched,
5026 uint32_t mods_locked, uint32_t group)
5028 struct switcher *switcher = container_of(grab, struct switcher, grab);
5029 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
5031 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0)
5032 switcher_destroy(switcher);
5036 switcher_cancel(struct weston_keyboard_grab *grab)
5038 struct switcher *switcher = container_of(grab, struct switcher, grab);
5040 switcher_destroy(switcher);
5043 static const struct weston_keyboard_grab_interface switcher_grab = {
5050 switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
5053 struct desktop_shell *shell = data;
5054 struct switcher *switcher;
5056 switcher = malloc(sizeof *switcher);
5057 switcher->shell = shell;
5058 switcher->current = NULL;
5059 switcher->listener.notify = switcher_handle_surface_destroy;
5060 wl_list_init(&switcher->listener.link);
5062 restore_all_output_modes(shell->compositor);
5063 lower_fullscreen_layer(switcher->shell);
5064 switcher->grab.interface = &switcher_grab;
5065 weston_keyboard_start_grab(seat->keyboard, &switcher->grab);
5066 weston_keyboard_set_focus(seat->keyboard, NULL);
5067 switcher_next(switcher);
5070 struct exposay_surface {
5071 struct desktop_shell *shell;
5072 struct weston_surface *surface;
5073 struct weston_view *view;
5074 struct wl_list link;
5085 /* The animations only apply a transformation for their own lifetime,
5086 * and don't have an option to indefinitely maintain the
5087 * transformation in a steady state - so, we apply our own once the
5088 * animation has finished. */
5089 struct weston_transform transform;
5092 static void exposay_set_state(struct desktop_shell *shell,
5093 enum exposay_target_state state,
5094 struct weston_seat *seat);
5095 static void exposay_check_state(struct desktop_shell *shell);
5098 exposay_in_flight_inc(struct desktop_shell *shell)
5100 shell->exposay.in_flight++;
5104 exposay_in_flight_dec(struct desktop_shell *shell)
5106 if (--shell->exposay.in_flight > 0)
5109 exposay_check_state(shell);
5113 exposay_animate_in_done(struct weston_view_animation *animation, void *data)
5115 struct exposay_surface *esurface = data;
5117 wl_list_insert(&esurface->view->geometry.transformation_list,
5118 &esurface->transform.link);
5119 weston_matrix_init(&esurface->transform.matrix);
5120 weston_matrix_scale(&esurface->transform.matrix,
5121 esurface->scale, esurface->scale, 1.0f);
5122 weston_matrix_translate(&esurface->transform.matrix,
5123 esurface->x - esurface->view->geometry.x,
5124 esurface->y - esurface->view->geometry.y,
5127 weston_view_geometry_dirty(esurface->view);
5128 weston_compositor_schedule_repaint(esurface->view->surface->compositor);
5130 exposay_in_flight_dec(esurface->shell);
5134 exposay_animate_in(struct exposay_surface *esurface)
5136 exposay_in_flight_inc(esurface->shell);
5138 weston_move_scale_run(esurface->view,
5139 esurface->x - esurface->view->geometry.x,
5140 esurface->y - esurface->view->geometry.y,
5141 1.0, esurface->scale, 0,
5142 exposay_animate_in_done, esurface);
5146 exposay_animate_out_done(struct weston_view_animation *animation, void *data)
5148 struct exposay_surface *esurface = data;
5149 struct desktop_shell *shell = esurface->shell;
5151 wl_list_remove(&esurface->link);
5154 exposay_in_flight_dec(shell);
5158 exposay_animate_out(struct exposay_surface *esurface)
5160 exposay_in_flight_inc(esurface->shell);
5162 /* Remove the static transformation set up by
5163 * exposay_transform_in_done(). */
5164 wl_list_remove(&esurface->transform.link);
5165 weston_view_geometry_dirty(esurface->view);
5167 weston_move_scale_run(esurface->view,
5168 esurface->x - esurface->view->geometry.x,
5169 esurface->y - esurface->view->geometry.y,
5170 1.0, esurface->scale, 1,
5171 exposay_animate_out_done, esurface);
5175 exposay_highlight_surface(struct desktop_shell *shell,
5176 struct exposay_surface *esurface)
5178 struct weston_view *view = NULL;
5181 shell->exposay.row_current = esurface->row;
5182 shell->exposay.column_current = esurface->column;
5183 view = esurface->view;
5186 activate(shell, view->surface, shell->exposay.seat);
5187 shell->exposay.focus_current = view;
5191 exposay_is_animating(struct desktop_shell *shell)
5193 if (shell->exposay.state_cur == EXPOSAY_LAYOUT_INACTIVE ||
5194 shell->exposay.state_cur == EXPOSAY_LAYOUT_OVERVIEW)
5197 return (shell->exposay.in_flight > 0);
5201 exposay_pick(struct desktop_shell *shell, int x, int y)
5203 struct exposay_surface *esurface;
5205 if (exposay_is_animating(shell))
5208 wl_list_for_each(esurface, &shell->exposay.surface_list, link) {
5209 if (x < esurface->x || x > esurface->x + esurface->width)
5211 if (y < esurface->y || y > esurface->y + esurface->height)
5214 exposay_highlight_surface(shell, esurface);
5219 /* Pretty lame layout for now; just tries to make a square. Should take
5220 * aspect ratio into account really. Also needs to be notified of surface
5221 * addition and removal and adjust layout/animate accordingly. */
5222 static enum exposay_layout_state
5223 exposay_layout(struct desktop_shell *shell)
5225 struct workspace *workspace = shell->exposay.workspace;
5226 struct weston_compositor *compositor = shell->compositor;
5227 struct weston_output *output = get_default_output(compositor);
5228 struct weston_view *view;
5229 struct exposay_surface *esurface;
5232 int last_row_removed = 0;
5234 wl_list_init(&shell->exposay.surface_list);
5236 shell->exposay.num_surfaces = 0;
5237 wl_list_for_each(view, &workspace->layer.view_list, layer_link) {
5238 if (!get_shell_surface(view->surface))
5240 shell->exposay.num_surfaces++;
5243 if (shell->exposay.num_surfaces == 0) {
5244 shell->exposay.grid_size = 0;
5245 shell->exposay.hpadding_outer = 0;
5246 shell->exposay.vpadding_outer = 0;
5247 shell->exposay.padding_inner = 0;
5248 shell->exposay.surface_size = 0;
5249 return EXPOSAY_LAYOUT_OVERVIEW;
5252 /* Lay the grid out as square as possible, losing surfaces from the
5253 * bottom row if required. Start with fixed padding of a 10% margin
5254 * around the outside and 80px internal padding between surfaces, and
5255 * maximise the area made available to surfaces after this, but only
5256 * to a maximum of 1/3rd the total output size.
5258 * If we can't make a square grid, add one extra row at the bottom
5259 * which will have a smaller number of columns.
5261 * XXX: Surely there has to be a better way to express this maths,
5264 shell->exposay.grid_size = floor(sqrtf(shell->exposay.num_surfaces));
5265 if (pow(shell->exposay.grid_size, 2) != shell->exposay.num_surfaces)
5266 shell->exposay.grid_size++;
5267 last_row_removed = pow(shell->exposay.grid_size, 2) - shell->exposay.num_surfaces;
5269 shell->exposay.hpadding_outer = (output->width / 10);
5270 shell->exposay.vpadding_outer = (output->height / 10);
5271 shell->exposay.padding_inner = 80;
5273 w = output->width - (shell->exposay.hpadding_outer * 2);
5274 w -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1);
5275 w /= shell->exposay.grid_size;
5277 h = output->height - (shell->exposay.vpadding_outer * 2);
5278 h -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1);
5279 h /= shell->exposay.grid_size;
5281 shell->exposay.surface_size = (w < h) ? w : h;
5282 if (shell->exposay.surface_size > (output->width / 2))
5283 shell->exposay.surface_size = output->width / 2;
5284 if (shell->exposay.surface_size > (output->height / 2))
5285 shell->exposay.surface_size = output->height / 2;
5288 wl_list_for_each(view, &workspace->layer.view_list, layer_link) {
5291 pad = shell->exposay.surface_size + shell->exposay.padding_inner;
5293 if (!get_shell_surface(view->surface))
5296 esurface = malloc(sizeof(*esurface));
5298 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL,
5299 shell->exposay.seat);
5303 wl_list_insert(&shell->exposay.surface_list, &esurface->link);
5304 esurface->shell = shell;
5305 esurface->view = view;
5307 esurface->row = i / shell->exposay.grid_size;
5308 esurface->column = i % shell->exposay.grid_size;
5310 esurface->x = shell->exposay.hpadding_outer;
5311 esurface->x += pad * esurface->column;
5312 esurface->y = shell->exposay.vpadding_outer;
5313 esurface->y += pad * esurface->row;
5315 if (esurface->row == shell->exposay.grid_size - 1)
5316 esurface->x += (shell->exposay.surface_size + shell->exposay.padding_inner) * last_row_removed / 2;
5318 if (view->geometry.width > view->geometry.height)
5319 esurface->scale = shell->exposay.surface_size / (float) view->geometry.width;
5321 esurface->scale = shell->exposay.surface_size / (float) view->geometry.height;
5322 esurface->width = view->geometry.width * esurface->scale;
5323 esurface->height = view->geometry.height * esurface->scale;
5325 if (shell->exposay.focus_current == esurface->view)
5326 exposay_highlight_surface(shell, esurface);
5328 exposay_animate_in(esurface);
5333 weston_compositor_schedule_repaint(shell->compositor);
5335 return EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW;
5339 exposay_motion(struct weston_pointer_grab *grab, uint32_t time,
5340 wl_fixed_t x, wl_fixed_t y)
5342 struct desktop_shell *shell =
5343 container_of(grab, struct desktop_shell, exposay.grab_ptr);
5345 weston_pointer_move(grab->pointer, x, y);
5348 wl_fixed_to_int(grab->pointer->x),
5349 wl_fixed_to_int(grab->pointer->y));
5353 exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button,
5356 struct desktop_shell *shell =
5357 container_of(grab, struct desktop_shell, exposay.grab_ptr);
5358 struct weston_seat *seat = grab->pointer->seat;
5359 enum wl_pointer_button_state state = state_w;
5361 if (button != BTN_LEFT)
5364 /* Store the surface we clicked on, and don't do anything if we end up
5365 * releasing on a different surface. */
5366 if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
5367 shell->exposay.clicked = shell->exposay.focus_current;
5371 if (shell->exposay.focus_current == shell->exposay.clicked)
5372 exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat);
5374 shell->exposay.clicked = NULL;
5378 exposay_pointer_grab_cancel(struct weston_pointer_grab *grab)
5380 struct desktop_shell *shell =
5381 container_of(grab, struct desktop_shell, exposay.grab_ptr);
5383 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat);
5386 static const struct weston_pointer_grab_interface exposay_ptr_grab = {
5390 exposay_pointer_grab_cancel,
5394 exposay_maybe_move(struct desktop_shell *shell, int row, int column)
5396 struct exposay_surface *esurface;
5398 wl_list_for_each(esurface, &shell->exposay.surface_list, link) {
5399 if (esurface->row != row || esurface->column != column)
5402 exposay_highlight_surface(shell, esurface);
5410 exposay_key(struct weston_keyboard_grab *grab, uint32_t time, uint32_t key,
5413 struct weston_seat *seat = grab->keyboard->seat;
5414 struct desktop_shell *shell =
5415 container_of(grab, struct desktop_shell, exposay.grab_kbd);
5416 enum wl_keyboard_key_state state = state_w;
5418 if (state != WL_KEYBOARD_KEY_STATE_RELEASED)
5423 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat);
5426 exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat);
5429 exposay_maybe_move(shell, shell->exposay.row_current - 1,
5430 shell->exposay.column_current);
5433 /* Special case for trying to move to the bottom row when it
5434 * has fewer items than all the others. */
5435 if (!exposay_maybe_move(shell, shell->exposay.row_current + 1,
5436 shell->exposay.column_current) &&
5437 shell->exposay.row_current < (shell->exposay.grid_size - 1)) {
5438 exposay_maybe_move(shell, shell->exposay.row_current + 1,
5439 (shell->exposay.num_surfaces %
5440 shell->exposay.grid_size) - 1);
5444 exposay_maybe_move(shell, shell->exposay.row_current,
5445 shell->exposay.column_current - 1);
5448 exposay_maybe_move(shell, shell->exposay.row_current,
5449 shell->exposay.column_current + 1);
5452 /* Try to move right, then down (and to the leftmost column),
5453 * then if all else fails, to the top left. */
5454 if (!exposay_maybe_move(shell, shell->exposay.row_current,
5455 shell->exposay.column_current + 1) &&
5456 !exposay_maybe_move(shell, shell->exposay.row_current + 1, 0))
5457 exposay_maybe_move(shell, 0, 0);
5465 exposay_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
5466 uint32_t mods_depressed, uint32_t mods_latched,
5467 uint32_t mods_locked, uint32_t group)
5469 struct desktop_shell *shell =
5470 container_of(grab, struct desktop_shell, exposay.grab_kbd);
5471 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
5473 /* We want to know when mod has been pressed and released.
5474 * FIXME: There is a problem here: if mod is pressed, then a key
5475 * is pressed and released, then mod is released, we will treat that
5476 * as if only mod had been pressed and released. */
5477 if (seat->modifier_state) {
5478 if (seat->modifier_state == shell->binding_modifier) {
5479 shell->exposay.mod_pressed = true;
5481 shell->exposay.mod_invalid = true;
5484 if (shell->exposay.mod_pressed && !shell->exposay.mod_invalid)
5485 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat);
5487 shell->exposay.mod_invalid = false;
5488 shell->exposay.mod_pressed = false;
5495 exposay_cancel(struct weston_keyboard_grab *grab)
5497 struct desktop_shell *shell =
5498 container_of(grab, struct desktop_shell, exposay.grab_kbd);
5500 exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat);
5503 static const struct weston_keyboard_grab_interface exposay_kbd_grab = {
5510 * Called when the transition from overview -> inactive has completed.
5512 static enum exposay_layout_state
5513 exposay_set_inactive(struct desktop_shell *shell)
5515 struct weston_seat *seat = shell->exposay.seat;
5517 weston_keyboard_end_grab(seat->keyboard);
5518 weston_pointer_end_grab(seat->pointer);
5519 if (seat->keyboard->input_method_resource)
5520 seat->keyboard->grab = &seat->keyboard->input_method_grab;
5522 return EXPOSAY_LAYOUT_INACTIVE;
5526 * Begins the transition from overview to inactive. */
5527 static enum exposay_layout_state
5528 exposay_transition_inactive(struct desktop_shell *shell, int switch_focus)
5530 struct exposay_surface *esurface;
5532 /* Call activate() before we start the animations to avoid
5533 * animating back the old state and then immediately transitioning
5535 if (switch_focus && shell->exposay.focus_current)
5536 activate(shell, shell->exposay.focus_current->surface,
5537 shell->exposay.seat);
5538 else if (shell->exposay.focus_prev)
5539 activate(shell, shell->exposay.focus_prev->surface,
5540 shell->exposay.seat);
5542 wl_list_for_each(esurface, &shell->exposay.surface_list, link)
5543 exposay_animate_out(esurface);
5544 weston_compositor_schedule_repaint(shell->compositor);
5546 return EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE;
5549 static enum exposay_layout_state
5550 exposay_transition_active(struct desktop_shell *shell)
5552 struct weston_seat *seat = shell->exposay.seat;
5554 shell->exposay.workspace = get_current_workspace(shell);
5555 shell->exposay.focus_prev = get_default_view (seat->keyboard->focus);
5556 shell->exposay.focus_current = get_default_view (seat->keyboard->focus);
5557 shell->exposay.clicked = NULL;
5558 wl_list_init(&shell->exposay.surface_list);
5560 lower_fullscreen_layer(shell);
5561 shell->exposay.grab_kbd.interface = &exposay_kbd_grab;
5562 weston_keyboard_start_grab(seat->keyboard,
5563 &shell->exposay.grab_kbd);
5564 weston_keyboard_set_focus(seat->keyboard, NULL);
5566 shell->exposay.grab_ptr.interface = &exposay_ptr_grab;
5567 weston_pointer_start_grab(seat->pointer,
5568 &shell->exposay.grab_ptr);
5569 weston_pointer_set_focus(seat->pointer, NULL,
5570 seat->pointer->x, seat->pointer->y);
5572 return exposay_layout(shell);
5576 exposay_check_state(struct desktop_shell *shell)
5578 enum exposay_layout_state state_new = shell->exposay.state_cur;
5581 /* Don't do anything whilst animations are running, just store up
5582 * target state changes and only act on them when the animations have
5584 if (exposay_is_animating(shell))
5587 switch (shell->exposay.state_target) {
5588 case EXPOSAY_TARGET_OVERVIEW:
5589 switch (shell->exposay.state_cur) {
5590 case EXPOSAY_LAYOUT_OVERVIEW:
5592 case EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW:
5593 state_new = EXPOSAY_LAYOUT_OVERVIEW;
5596 state_new = exposay_transition_active(shell);
5601 case EXPOSAY_TARGET_SWITCH:
5602 do_switch = 1; /* fallthrough */
5603 case EXPOSAY_TARGET_CANCEL:
5604 switch (shell->exposay.state_cur) {
5605 case EXPOSAY_LAYOUT_INACTIVE:
5607 case EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE:
5608 state_new = exposay_set_inactive(shell);
5611 state_new = exposay_transition_inactive(shell, do_switch);
5619 shell->exposay.state_cur = state_new;
5623 exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state,
5624 struct weston_seat *seat)
5626 shell->exposay.state_target = state;
5627 shell->exposay.seat = seat;
5628 exposay_check_state(shell);
5632 exposay_binding(struct weston_seat *seat, enum weston_keyboard_modifier modifier,
5635 struct desktop_shell *shell = data;
5637 exposay_set_state(shell, EXPOSAY_TARGET_OVERVIEW, seat);
5641 backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
5644 struct weston_compositor *compositor = data;
5645 struct weston_output *output;
5646 long backlight_new = 0;
5648 /* TODO: we're limiting to simple use cases, where we assume just
5649 * control on the primary display. We'd have to extend later if we
5650 * ever get support for setting backlights on random desktop LCD
5652 output = get_default_output(compositor);
5656 if (!output->set_backlight)
5659 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
5660 backlight_new = output->backlight_current - 25;
5661 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
5662 backlight_new = output->backlight_current + 25;
5664 if (backlight_new < 5)
5666 if (backlight_new > 255)
5667 backlight_new = 255;
5669 output->backlight_current = backlight_new;
5670 output->set_backlight(output, output->backlight_current);
5673 struct debug_binding_grab {
5674 struct weston_keyboard_grab grab;
5675 struct weston_seat *seat;
5677 int key_released[2];
5681 debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
5682 uint32_t key, uint32_t state)
5684 struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
5685 struct weston_compositor *ec = db->seat->compositor;
5686 struct wl_display *display = ec->wl_display;
5687 struct wl_resource *resource;
5689 int send = 0, terminate = 0;
5690 int check_binding = 1;
5692 struct wl_list *resource_list;
5694 if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
5695 /* Do not run bindings on key releases */
5698 for (i = 0; i < 2; i++)
5699 if (key == db->key[i])
5700 db->key_released[i] = 1;
5702 if (db->key_released[0] && db->key_released[1]) {
5703 /* All key releases been swalled so end the grab */
5705 } else if (key != db->key[0] && key != db->key[1]) {
5706 /* Should not swallow release of other keys */
5709 } else if (key == db->key[0] && !db->key_released[0]) {
5710 /* Do not check bindings for the first press of the binding
5711 * key. This allows it to be used as a debug shortcut.
5712 * We still need to swallow this event. */
5714 } else if (db->key[1]) {
5715 /* If we already ran a binding don't process another one since
5716 * we can't keep track of all the binding keys that were
5717 * pressed in order to swallow the release events. */
5722 if (check_binding) {
5723 if (weston_compositor_run_debug_binding(ec, db->seat, time,
5725 /* We ran a binding so swallow the press and keep the
5726 * grab to swallow the released too. */
5731 /* Terminate the grab since the key pressed is not a
5732 * debug binding key. */
5739 serial = wl_display_next_serial(display);
5740 resource_list = &grab->keyboard->focus_resource_list;
5741 wl_resource_for_each(resource, resource_list) {
5742 wl_keyboard_send_key(resource, serial, time, key, state);
5747 weston_keyboard_end_grab(grab->keyboard);
5748 if (grab->keyboard->input_method_resource)
5749 grab->keyboard->grab = &grab->keyboard->input_method_grab;
5755 debug_binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial,
5756 uint32_t mods_depressed, uint32_t mods_latched,
5757 uint32_t mods_locked, uint32_t group)
5759 struct wl_resource *resource;
5760 struct wl_list *resource_list;
5762 resource_list = &grab->keyboard->focus_resource_list;
5764 wl_resource_for_each(resource, resource_list) {
5765 wl_keyboard_send_modifiers(resource, serial, mods_depressed,
5766 mods_latched, mods_locked, group);
5771 debug_binding_cancel(struct weston_keyboard_grab *grab)
5773 struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
5775 weston_keyboard_end_grab(grab->keyboard);
5779 struct weston_keyboard_grab_interface debug_binding_keyboard_grab = {
5781 debug_binding_modifiers,
5782 debug_binding_cancel,
5786 debug_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
5788 struct debug_binding_grab *grab;
5790 grab = calloc(1, sizeof *grab);
5794 grab->seat = (struct weston_seat *) seat;
5796 grab->grab.interface = &debug_binding_keyboard_grab;
5797 weston_keyboard_start_grab(seat->keyboard, &grab->grab);
5801 force_kill_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
5804 struct weston_surface *focus_surface;
5805 struct wl_client *client;
5806 struct desktop_shell *shell = data;
5807 struct weston_compositor *compositor = shell->compositor;
5810 focus_surface = seat->keyboard->focus;
5814 wl_signal_emit(&compositor->kill_signal, focus_surface);
5816 client = wl_resource_get_client(focus_surface->resource);
5817 wl_client_get_credentials(client, &pid, NULL, NULL);
5819 /* Skip clients that we launched ourselves (the credentials of
5820 * the socketpair is ours) */
5821 if (pid == getpid())
5828 workspace_up_binding(struct weston_seat *seat, uint32_t time,
5829 uint32_t key, void *data)
5831 struct desktop_shell *shell = data;
5832 unsigned int new_index = shell->workspaces.current;
5839 change_workspace(shell, new_index);
5843 workspace_down_binding(struct weston_seat *seat, uint32_t time,
5844 uint32_t key, void *data)
5846 struct desktop_shell *shell = data;
5847 unsigned int new_index = shell->workspaces.current;
5851 if (new_index < shell->workspaces.num - 1)
5854 change_workspace(shell, new_index);
5858 workspace_f_binding(struct weston_seat *seat, uint32_t time,
5859 uint32_t key, void *data)
5861 struct desktop_shell *shell = data;
5862 unsigned int new_index;
5866 new_index = key - KEY_F1;
5867 if (new_index >= shell->workspaces.num)
5868 new_index = shell->workspaces.num - 1;
5870 change_workspace(shell, new_index);
5874 workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time,
5875 uint32_t key, void *data)
5877 struct desktop_shell *shell = data;
5878 unsigned int new_index = shell->workspaces.current;
5886 take_surface_to_workspace_by_seat(shell, seat, new_index);
5890 workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time,
5891 uint32_t key, void *data)
5893 struct desktop_shell *shell = data;
5894 unsigned int new_index = shell->workspaces.current;
5899 if (new_index < shell->workspaces.num - 1)
5902 take_surface_to_workspace_by_seat(shell, seat, new_index);
5906 handle_output_destroy(struct wl_listener *listener, void *data)
5908 struct shell_output *output_listener =
5909 container_of(listener, struct shell_output, destroy_listener);
5911 wl_list_remove(&output_listener->destroy_listener.link);
5912 wl_list_remove(&output_listener->link);
5913 free(output_listener);
5917 create_shell_output(struct desktop_shell *shell,
5918 struct weston_output *output)
5920 struct shell_output *shell_output;
5922 shell_output = zalloc(sizeof *shell_output);
5923 if (shell_output == NULL)
5926 shell_output->output = output;
5927 shell_output->shell = shell;
5928 shell_output->destroy_listener.notify = handle_output_destroy;
5929 wl_signal_add(&output->destroy_signal,
5930 &shell_output->destroy_listener);
5931 wl_list_insert(shell->output_list.prev, &shell_output->link);
5935 handle_output_create(struct wl_listener *listener, void *data)
5937 struct desktop_shell *shell =
5938 container_of(listener, struct desktop_shell, output_create_listener);
5939 struct weston_output *output = (struct weston_output *)data;
5941 create_shell_output(shell, output);
5945 setup_output_destroy_handler(struct weston_compositor *ec,
5946 struct desktop_shell *shell)
5948 struct weston_output *output;
5950 wl_list_init(&shell->output_list);
5951 wl_list_for_each(output, &ec->output_list, link)
5952 create_shell_output(shell, output);
5954 shell->output_create_listener.notify = handle_output_create;
5955 wl_signal_add(&ec->output_created_signal,
5956 &shell->output_create_listener);
5960 shell_destroy(struct wl_listener *listener, void *data)
5962 struct desktop_shell *shell =
5963 container_of(listener, struct desktop_shell, destroy_listener);
5964 struct workspace **ws;
5965 struct shell_output *shell_output, *tmp;
5967 if (shell->child.client)
5968 wl_client_destroy(shell->child.client);
5970 wl_list_remove(&shell->idle_listener.link);
5971 wl_list_remove(&shell->wake_listener.link);
5972 wl_list_remove(&shell->show_input_panel_listener.link);
5973 wl_list_remove(&shell->hide_input_panel_listener.link);
5975 wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) {
5976 wl_list_remove(&shell_output->destroy_listener.link);
5977 wl_list_remove(&shell_output->link);
5981 wl_list_remove(&shell->output_create_listener.link);
5983 wl_array_for_each(ws, &shell->workspaces.array)
5984 workspace_destroy(*ws);
5985 wl_array_release(&shell->workspaces.array);
5987 free(shell->screensaver.path);
5988 free(shell->client);
5993 shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
5996 int i, num_workspace_bindings;
5998 /* fixed bindings */
5999 weston_compositor_add_key_binding(ec, KEY_BACKSPACE,
6000 MODIFIER_CTRL | MODIFIER_ALT,
6001 terminate_binding, ec);
6002 weston_compositor_add_key_binding(ec, KEY_TAB,
6004 alt_tab_binding, shell);
6005 weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
6006 click_to_activate_binding,
6008 weston_compositor_add_touch_binding(ec, 0,
6009 touch_to_activate_binding,
6011 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
6012 MODIFIER_SUPER | MODIFIER_ALT,
6013 surface_opacity_binding, NULL);
6014 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
6015 MODIFIER_SUPER, zoom_axis_binding,
6018 /* configurable bindings */
6019 mod = shell->binding_modifier;
6020 weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod,
6021 zoom_key_binding, NULL);
6022 weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod,
6023 zoom_key_binding, NULL);
6024 weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding,
6026 weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell);
6027 weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod,
6028 resize_binding, shell);
6030 if (ec->capabilities & WESTON_CAP_ROTATION_ANY)
6031 weston_compositor_add_button_binding(ec, BTN_RIGHT, mod,
6032 rotate_binding, NULL);
6034 weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding,
6036 weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding,
6038 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0,
6039 backlight_binding, ec);
6040 weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding,
6042 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0,
6043 backlight_binding, ec);
6044 weston_compositor_add_key_binding(ec, KEY_K, mod,
6045 force_kill_binding, shell);
6046 weston_compositor_add_key_binding(ec, KEY_UP, mod,
6047 workspace_up_binding, shell);
6048 weston_compositor_add_key_binding(ec, KEY_DOWN, mod,
6049 workspace_down_binding, shell);
6050 weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT,
6051 workspace_move_surface_up_binding,
6053 weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT,
6054 workspace_move_surface_down_binding,
6057 weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell);
6059 /* Add bindings for mod+F[1-6] for workspace 1 to 6. */
6060 if (shell->workspaces.num > 1) {
6061 num_workspace_bindings = shell->workspaces.num;
6062 if (num_workspace_bindings > 6)
6063 num_workspace_bindings = 6;
6064 for (i = 0; i < num_workspace_bindings; i++)
6065 weston_compositor_add_key_binding(ec, KEY_F1 + i, mod,
6066 workspace_f_binding,
6070 /* Debug bindings */
6071 weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT,
6072 debug_binding, shell);
6076 module_init(struct weston_compositor *ec,
6077 int *argc, char *argv[])
6079 struct weston_seat *seat;
6080 struct desktop_shell *shell;
6081 struct workspace **pws;
6083 struct wl_event_loop *loop;
6085 shell = zalloc(sizeof *shell);
6089 shell->compositor = ec;
6091 shell->destroy_listener.notify = shell_destroy;
6092 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
6093 shell->idle_listener.notify = idle_handler;
6094 wl_signal_add(&ec->idle_signal, &shell->idle_listener);
6095 shell->wake_listener.notify = wake_handler;
6096 wl_signal_add(&ec->wake_signal, &shell->wake_listener);
6097 shell->show_input_panel_listener.notify = show_input_panels;
6098 wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener);
6099 shell->hide_input_panel_listener.notify = hide_input_panels;
6100 wl_signal_add(&ec->hide_input_panel_signal, &shell->hide_input_panel_listener);
6101 shell->update_input_panel_listener.notify = update_input_panels;
6102 wl_signal_add(&ec->update_input_panel_signal, &shell->update_input_panel_listener);
6103 ec->ping_handler = ping_handler;
6104 ec->shell_interface.shell = shell;
6105 ec->shell_interface.create_shell_surface = create_shell_surface;
6106 ec->shell_interface.get_primary_view = get_primary_view;
6107 ec->shell_interface.set_toplevel = set_toplevel;
6108 ec->shell_interface.set_transient = set_transient;
6109 ec->shell_interface.set_fullscreen = set_fullscreen;
6110 ec->shell_interface.set_xwayland = set_xwayland;
6111 ec->shell_interface.move = surface_move;
6112 ec->shell_interface.resize = surface_resize;
6113 ec->shell_interface.set_title = set_title;
6115 wl_list_init(&shell->input_panel.surfaces);
6117 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
6118 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
6119 weston_layer_init(&shell->background_layer, &shell->panel_layer.link);
6120 weston_layer_init(&shell->lock_layer, NULL);
6121 weston_layer_init(&shell->input_panel_layer, NULL);
6123 wl_array_init(&shell->workspaces.array);
6124 wl_list_init(&shell->workspaces.client_list);
6126 shell_configuration(shell);
6128 shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE;
6129 shell->exposay.state_target = EXPOSAY_TARGET_CANCEL;
6131 for (i = 0; i < shell->workspaces.num; i++) {
6132 pws = wl_array_add(&shell->workspaces.array, sizeof *pws);
6136 *pws = workspace_create();
6140 activate_workspace(shell, 0);
6142 wl_list_init(&shell->workspaces.anim_sticky_list);
6143 wl_list_init(&shell->workspaces.animation.link);
6144 shell->workspaces.animation.frame = animate_workspace_change_frame;
6146 if (wl_global_create(ec->wl_display, &wl_shell_interface, 1,
6147 shell, bind_shell) == NULL)
6150 if (wl_global_create(ec->wl_display,
6151 &desktop_shell_interface, 2,
6152 shell, bind_desktop_shell) == NULL)
6155 if (wl_global_create(ec->wl_display, &screensaver_interface, 1,
6156 shell, bind_screensaver) == NULL)
6159 if (wl_global_create(ec->wl_display, &wl_input_panel_interface, 1,
6160 shell, bind_input_panel) == NULL)
6163 if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1,
6164 shell, bind_workspace_manager) == NULL)
6167 shell->child.deathstamp = weston_compositor_get_time();
6169 setup_output_destroy_handler(ec, shell);
6171 loop = wl_display_get_event_loop(ec->wl_display);
6172 wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell);
6174 shell->screensaver.timer =
6175 wl_event_loop_add_timer(loop, screensaver_timeout, shell);
6177 wl_list_for_each(seat, &ec->seat_list, link)
6178 create_pointer_focus_listener(seat);
6180 shell_add_bindings(ec, shell);
6182 shell_fade_init(shell);