2 * Copyright © 2010-2012 Intel Corporation
3 * Copyright © 2011-2012 Collabora, Ltd.
4 * Copyright © 2013 TOYOTA MOTOR CORPORATION.
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.
30 #include <linux/input.h>
34 #include <sys/types.h>
36 #include <wayland-server.h>
37 #include <weston/compositor.h>
38 #include "desktop-shell-server-protocol.h"
39 #include "input-method-server-protocol.h"
40 #include "workspaces-server-protocol.h"
41 #include <weston/config-parser.h>
42 #include "ico_ivi_shell.h"
44 #define DEFAULT_NUM_WORKSPACES 1
45 #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200
60 struct weston_seat *seat;
62 struct weston_surface *keyboard_focus;
64 struct wl_listener seat_destroy_listener;
65 struct wl_listener surface_destroy_listener;
69 struct weston_layer layer;
71 struct wl_list focus_list;
72 struct wl_listener seat_destroyed_listener;
75 struct input_panel_surface {
76 struct wl_resource *resource;
77 struct wl_signal destroy_signal;
79 struct desktop_shell *shell;
82 struct weston_surface *surface;
83 struct wl_listener surface_destroy_listener;
85 struct weston_output *output;
89 struct desktop_shell {
90 struct weston_compositor *compositor;
92 struct wl_listener idle_listener;
93 struct wl_listener wake_listener;
94 struct wl_listener destroy_listener;
95 struct wl_listener show_input_panel_listener;
96 struct wl_listener hide_input_panel_listener;
97 struct wl_listener update_input_panel_listener;
99 struct weston_layer fullscreen_layer;
100 struct weston_layer panel_layer;
101 struct weston_layer background_layer;
102 struct weston_layer lock_layer;
103 struct weston_layer input_panel_layer;
105 struct wl_listener pointer_focus_listener;
106 struct weston_surface *grab_surface;
109 struct weston_process process;
110 struct wl_client *client;
111 struct wl_resource *desktop_shell;
118 bool showing_input_panels;
119 bool prepare_event_sent;
122 struct weston_surface *surface;
123 pixman_box32_t cursor_rectangle;
126 struct weston_surface *lock_surface;
127 struct wl_listener lock_surface_listener;
130 struct wl_array array;
131 unsigned int current;
134 struct wl_list client_list;
136 struct weston_animation animation;
137 struct wl_list anim_sticky_list;
139 uint32_t anim_timestamp;
141 struct workspace *anim_from;
142 struct workspace *anim_to;
148 struct wl_resource *binding;
149 struct weston_process process;
150 struct wl_event_source *timer;
154 struct wl_resource *binding;
155 struct wl_list surfaces;
159 struct weston_surface *surface;
160 struct weston_surface_animation *animation;
162 struct wl_event_source *startup_timer;
165 uint32_t binding_modifier;
166 enum animation_type win_animation_type;
169 enum shell_surface_type {
171 SHELL_SURFACE_TOPLEVEL,
172 SHELL_SURFACE_TRANSIENT,
173 SHELL_SURFACE_FULLSCREEN,
174 SHELL_SURFACE_MAXIMIZED,
176 SHELL_SURFACE_XWAYLAND
180 struct wl_event_source *source;
184 struct shell_surface {
185 struct wl_resource *resource;
186 struct wl_signal destroy_signal;
188 struct weston_surface *surface;
189 struct wl_listener surface_destroy_listener;
190 struct weston_surface *parent;
191 struct desktop_shell *shell;
193 enum shell_surface_type type, next_type;
195 int32_t saved_x, saved_y;
196 bool saved_position_valid;
197 bool saved_rotation_valid;
201 struct weston_transform transform;
202 struct weston_matrix rotation;
206 struct wl_list grab_link;
208 struct shell_seat *shseat;
218 enum wl_shell_surface_fullscreen_method type;
219 struct weston_transform transform; /* matrix from x, y */
221 struct weston_surface *black_surface;
224 struct ping_timer *ping_timer;
226 struct weston_transform workspace_transform;
228 struct weston_output *fullscreen_output;
229 struct weston_output *output;
232 const struct weston_shell_client *client;
236 struct weston_pointer_grab grab;
237 struct shell_surface *shsurf;
238 struct wl_listener shsurf_destroy_listener;
241 struct shell_touch_grab {
242 struct weston_touch_grab grab;
243 struct shell_surface *shsurf;
244 struct wl_listener shsurf_destroy_listener;
245 struct weston_touch *touch;
248 struct weston_move_grab {
249 struct shell_grab base;
253 struct weston_touch_move_grab {
254 struct shell_touch_grab base;
259 struct shell_grab base;
260 struct weston_matrix rotation;
268 struct weston_seat *seat;
269 struct wl_listener seat_destroy_listener;
272 struct weston_pointer_grab grab;
273 struct wl_list surfaces_list;
274 struct wl_client *client;
280 activate(struct desktop_shell *shell, struct weston_surface *es,
281 struct weston_seat *seat);
283 static struct workspace *
284 get_current_workspace(struct desktop_shell *shell);
286 static struct shell_surface *
287 get_shell_surface(struct weston_surface *surface);
289 static struct desktop_shell *
290 shell_surface_get_shell(struct shell_surface *shsurf);
293 surface_rotate(struct shell_surface *surface, struct weston_seat *seat);
296 shell_fade_startup(struct desktop_shell *shell);
298 /* shell management table */
299 static struct desktop_shell *_ico_ivi_shell = NULL;
300 /* shell program path for ico-ivi */
301 static char *shell_exe = NULL;
302 #define DEFAULT_DEBUG_LEVEL 4
303 static int ico_debug_level = DEFAULT_DEBUG_LEVEL; /* Debug Level */
305 /* debug log macros */
306 #define uifw_debug(fmt,...) \
307 { if (ico_debug_level >= 5) {weston_log("DBG>"fmt" (%s:%d)\n",##__VA_ARGS__,__FILE__,__LINE__);} }
308 #define uifw_trace(fmt,...) \
309 { if (ico_debug_level >= 4) {weston_log("TRC>"fmt" (%s:%d)\n",##__VA_ARGS__,__FILE__,__LINE__);} }
310 #define uifw_info(fmt,...) \
311 { if (ico_debug_level >= 3) {weston_log("INF>"fmt" (%s:%d)\n",##__VA_ARGS__,__FILE__,__LINE__);} }
312 #define uifw_warn(fmt,...) \
313 { if (ico_debug_level >= 2) {weston_log("WRN>"fmt" (%s:%d)\n",##__VA_ARGS__,__FILE__,__LINE__);} }
314 #define uifw_error(fmt,...) \
315 { if (ico_debug_level >= 1) {weston_log("ERR>"fmt" (%s:%d)\n",##__VA_ARGS__,__FILE__,__LINE__);} }
318 static void (*shell_hook_bind)(struct wl_client *client, void *shell) = NULL;
319 static void (*shell_hook_unbind)(struct wl_client *client) = NULL;
320 static void (*shell_hook_create)(struct wl_client *client, struct wl_resource *resource,
321 struct weston_surface *surface,
322 struct shell_surface *shsurf) = NULL;
323 static void (*shell_hook_destroy)(struct weston_surface *surface) = NULL;
324 static void (*shell_hook_map)(struct weston_surface *surface, int32_t *width,
325 int32_t *height, int32_t *sx, int32_t *sy) = NULL;
326 static void (*shell_hook_configure)(struct weston_surface *surface) = NULL;
327 static void (*shell_hook_select)(struct weston_surface *surface) = NULL;
328 static void (*shell_hook_title)(struct weston_surface *surface, const char *title) = NULL;
329 static void (*shell_hook_move)(struct weston_surface *surface, int *dx, int *dy) = NULL;
332 shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
334 struct desktop_shell *shell;
335 struct weston_surface *top_fs_es;
337 shell = shell_surface_get_shell(shsurf);
339 if (wl_list_empty(&shell->fullscreen_layer.surface_list))
342 top_fs_es = container_of(shell->fullscreen_layer.surface_list.next,
343 struct weston_surface,
345 return (shsurf == get_shell_surface(top_fs_es));
349 destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
351 struct shell_grab *grab;
353 grab = container_of(listener, struct shell_grab,
354 shsurf_destroy_listener);
360 popup_grab_end(struct weston_pointer *pointer);
363 shell_grab_start(struct shell_grab *grab,
364 const struct weston_pointer_grab_interface *interface,
365 struct shell_surface *shsurf,
366 struct weston_pointer *pointer,
367 enum desktop_shell_cursor cursor)
369 struct desktop_shell *shell = shsurf->shell;
371 /* if ico_window_mgr hook, not change grab */
372 if (shell_hook_select) {
376 popup_grab_end(pointer);
378 grab->grab.interface = interface;
379 grab->shsurf = shsurf;
380 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
381 wl_signal_add(&shsurf->destroy_signal,
382 &grab->shsurf_destroy_listener);
384 weston_pointer_start_grab(pointer, &grab->grab);
385 if (shell->child.desktop_shell) {
386 desktop_shell_send_grab_cursor(shell->child.desktop_shell,
388 weston_pointer_set_focus(pointer, shell->grab_surface,
389 wl_fixed_from_int(0),
390 wl_fixed_from_int(0));
395 shell_grab_end(struct shell_grab *grab)
398 wl_list_remove(&grab->shsurf_destroy_listener.link);
400 weston_pointer_end_grab(grab->grab.pointer);
404 shell_touch_grab_start(struct shell_touch_grab *grab,
405 const struct weston_touch_grab_interface *interface,
406 struct shell_surface *shsurf,
407 struct weston_touch *touch)
409 struct desktop_shell *shell = shsurf->shell;
411 grab->grab.interface = interface;
412 grab->shsurf = shsurf;
413 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
414 wl_signal_add(&shsurf->destroy_signal,
415 &grab->shsurf_destroy_listener);
419 weston_touch_start_grab(touch, &grab->grab);
420 if (shell->child.desktop_shell)
421 weston_touch_set_focus(touch->seat, shell->grab_surface);
425 shell_touch_grab_end(struct shell_touch_grab *grab)
428 wl_list_remove(&grab->shsurf_destroy_listener.link);
430 weston_touch_end_grab(grab->touch);
434 center_on_output(struct weston_surface *surface,
435 struct weston_output *output);
437 static enum weston_keyboard_modifier
438 get_modifier(char *modifier)
441 return MODIFIER_SUPER;
443 if (!strcmp("ctrl", modifier))
444 return MODIFIER_CTRL;
445 else if (!strcmp("alt", modifier))
447 else if (!strcmp("super", modifier))
448 return MODIFIER_SUPER;
450 return MODIFIER_SUPER;
453 static enum animation_type
454 get_animation_type(char *animation)
457 return ANIMATION_NONE;
459 if (!strcmp("zoom", animation))
460 return ANIMATION_ZOOM;
461 else if (!strcmp("fade", animation))
462 return ANIMATION_FADE;
464 return ANIMATION_NONE;
468 shell_configuration(struct desktop_shell *shell)
470 struct weston_config_section *section;
474 section = weston_config_get_section(shell->compositor->config,
475 "screensaver", NULL, NULL);
476 weston_config_section_get_string(section,
477 "path", &shell->screensaver.path, NULL);
478 weston_config_section_get_int(section, "duration", &duration, 60);
479 shell->screensaver.duration = duration * 1000;
481 section = weston_config_get_section(shell->compositor->config,
482 "shell", NULL, NULL);
483 weston_config_section_get_string(section,
484 "binding-modifier", &s, "super");
485 shell->binding_modifier = get_modifier(s);
487 weston_config_section_get_string(section, "animation", &s, "none");
488 shell->win_animation_type = get_animation_type(s);
490 weston_config_section_get_uint(section, "num-workspaces",
491 &shell->workspaces.num,
492 DEFAULT_NUM_WORKSPACES);
493 /* shell program path for ico-ivi */
494 weston_config_section_get_string(section, "shell-exe", &shell_exe,
495 LIBEXECDIR "/weston-desktop-shell");
496 weston_log("ws=%d exe=%s\n", shell->workspaces.num, shell_exe);
498 /* get debug level for ivi debug */
499 section = weston_config_get_section(shell->compositor->config, "ivi-debug", NULL, NULL);
501 weston_config_section_get_int(section, "log",
502 &ico_debug_level, DEFAULT_DEBUG_LEVEL);
507 focus_state_destroy(struct focus_state *state)
509 wl_list_remove(&state->seat_destroy_listener.link);
510 wl_list_remove(&state->surface_destroy_listener.link);
515 focus_state_seat_destroy(struct wl_listener *listener, void *data)
517 struct focus_state *state = container_of(listener,
519 seat_destroy_listener);
521 wl_list_remove(&state->link);
522 focus_state_destroy(state);
526 focus_state_surface_destroy(struct wl_listener *listener, void *data)
528 struct focus_state *state = container_of(listener,
530 surface_destroy_listener);
531 struct desktop_shell *shell;
532 struct weston_surface *main_surface;
533 struct weston_surface *surface, *next;
535 main_surface = weston_surface_get_main_surface(state->keyboard_focus);
538 wl_list_for_each(surface, &state->ws->layer.surface_list, layer_link) {
539 if (surface == main_surface)
546 /* if the focus was a sub-surface, activate its main surface */
547 if (main_surface != state->keyboard_focus)
551 shell = state->seat->compositor->shell_interface.shell;
552 activate(shell, next, state->seat);
554 wl_list_remove(&state->link);
555 focus_state_destroy(state);
559 static struct focus_state *
560 focus_state_create(struct weston_seat *seat, struct workspace *ws)
562 struct focus_state *state;
564 state = malloc(sizeof *state);
570 wl_list_insert(&ws->focus_list, &state->link);
572 state->seat_destroy_listener.notify = focus_state_seat_destroy;
573 state->surface_destroy_listener.notify = focus_state_surface_destroy;
574 wl_signal_add(&seat->destroy_signal,
575 &state->seat_destroy_listener);
576 wl_list_init(&state->surface_destroy_listener.link);
581 static struct focus_state *
582 ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat)
584 struct workspace *ws = get_current_workspace(shell);
585 struct focus_state *state;
587 wl_list_for_each(state, &ws->focus_list, link)
588 if (state->seat == seat)
591 if (&state->link == &ws->focus_list)
592 state = focus_state_create(seat, ws);
598 restore_focus_state(struct desktop_shell *shell, struct workspace *ws)
600 struct focus_state *state, *next;
601 struct weston_surface *surface;
603 wl_list_for_each_safe(state, next, &ws->focus_list, link) {
604 surface = state->keyboard_focus;
606 weston_keyboard_set_focus(state->seat->keyboard, surface);
611 replace_focus_state(struct desktop_shell *shell, struct workspace *ws,
612 struct weston_seat *seat)
614 struct focus_state *state;
615 struct weston_surface *surface;
617 wl_list_for_each(state, &ws->focus_list, link) {
618 if (state->seat == seat) {
619 surface = seat->keyboard->focus;
620 state->keyboard_focus = surface;
627 drop_focus_state(struct desktop_shell *shell, struct workspace *ws,
628 struct weston_surface *surface)
630 struct focus_state *state;
632 wl_list_for_each(state, &ws->focus_list, link)
633 if (state->keyboard_focus == surface)
634 state->keyboard_focus = NULL;
638 workspace_destroy(struct workspace *ws)
640 struct focus_state *state, *next;
642 wl_list_for_each_safe(state, next, &ws->focus_list, link)
643 focus_state_destroy(state);
649 seat_destroyed(struct wl_listener *listener, void *data)
651 struct weston_seat *seat = data;
652 struct focus_state *state, *next;
653 struct workspace *ws = container_of(listener,
655 seat_destroyed_listener);
657 wl_list_for_each_safe(state, next, &ws->focus_list, link)
658 if (state->seat == seat)
659 wl_list_remove(&state->link);
662 static struct workspace *
663 workspace_create(void)
665 struct workspace *ws = malloc(sizeof *ws);
669 weston_layer_init(&ws->layer, NULL);
671 wl_list_init(&ws->focus_list);
672 wl_list_init(&ws->seat_destroyed_listener.link);
673 ws->seat_destroyed_listener.notify = seat_destroyed;
679 workspace_is_empty(struct workspace *ws)
681 return wl_list_empty(&ws->layer.surface_list);
684 static struct workspace *
685 get_workspace(struct desktop_shell *shell, unsigned int index)
687 struct workspace **pws = shell->workspaces.array.data;
688 assert(index < shell->workspaces.num);
693 static struct workspace *
694 get_current_workspace(struct desktop_shell *shell)
696 return get_workspace(shell, shell->workspaces.current);
700 activate_workspace(struct desktop_shell *shell, unsigned int index)
702 struct workspace *ws;
704 ws = get_workspace(shell, index);
705 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
707 shell->workspaces.current = index;
711 get_output_height(struct weston_output *output)
713 return abs(output->region.extents.y1 - output->region.extents.y2);
717 surface_translate(struct weston_surface *surface, double d)
719 struct shell_surface *shsurf = get_shell_surface(surface);
720 struct weston_transform *transform;
722 transform = &shsurf->workspace_transform;
723 if (wl_list_empty(&transform->link))
724 wl_list_insert(surface->geometry.transformation_list.prev,
725 &shsurf->workspace_transform.link);
727 weston_matrix_init(&shsurf->workspace_transform.matrix);
728 weston_matrix_translate(&shsurf->workspace_transform.matrix,
730 weston_surface_geometry_dirty(surface);
734 workspace_translate_out(struct workspace *ws, double fraction)
736 struct weston_surface *surface;
740 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
741 height = get_output_height(surface->output);
742 d = height * fraction;
744 surface_translate(surface, d);
749 workspace_translate_in(struct workspace *ws, double fraction)
751 struct weston_surface *surface;
755 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
756 height = get_output_height(surface->output);
759 d = -(height - height * fraction);
761 d = height + height * fraction;
763 surface_translate(surface, d);
768 broadcast_current_workspace_state(struct desktop_shell *shell)
770 struct wl_list *link;
772 for (link = shell->workspaces.client_list.next;
773 link != &shell->workspaces.client_list;
775 workspace_manager_send_state(wl_resource_from_link(link),
776 shell->workspaces.current,
777 shell->workspaces.num);
782 reverse_workspace_change_animation(struct desktop_shell *shell,
784 struct workspace *from,
785 struct workspace *to)
787 shell->workspaces.current = index;
789 shell->workspaces.anim_to = to;
790 shell->workspaces.anim_from = from;
791 shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir;
792 shell->workspaces.anim_timestamp = 0;
794 weston_compositor_schedule_repaint(shell->compositor);
798 workspace_deactivate_transforms(struct workspace *ws)
800 struct weston_surface *surface;
801 struct shell_surface *shsurf;
803 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
804 shsurf = get_shell_surface(surface);
805 if (!wl_list_empty(&shsurf->workspace_transform.link)) {
806 wl_list_remove(&shsurf->workspace_transform.link);
807 wl_list_init(&shsurf->workspace_transform.link);
809 weston_surface_geometry_dirty(surface);
814 finish_workspace_change_animation(struct desktop_shell *shell,
815 struct workspace *from,
816 struct workspace *to)
818 weston_compositor_schedule_repaint(shell->compositor);
820 wl_list_remove(&shell->workspaces.animation.link);
821 workspace_deactivate_transforms(from);
822 workspace_deactivate_transforms(to);
823 shell->workspaces.anim_to = NULL;
825 wl_list_remove(&shell->workspaces.anim_from->layer.link);
829 animate_workspace_change_frame(struct weston_animation *animation,
830 struct weston_output *output, uint32_t msecs)
832 struct desktop_shell *shell =
833 container_of(animation, struct desktop_shell,
834 workspaces.animation);
835 struct workspace *from = shell->workspaces.anim_from;
836 struct workspace *to = shell->workspaces.anim_to;
840 if (workspace_is_empty(from) && workspace_is_empty(to)) {
841 finish_workspace_change_animation(shell, from, to);
845 if (shell->workspaces.anim_timestamp == 0) {
846 if (shell->workspaces.anim_current == 0.0)
847 shell->workspaces.anim_timestamp = msecs;
849 shell->workspaces.anim_timestamp =
851 /* Invers of movement function 'y' below. */
852 (asin(1.0 - shell->workspaces.anim_current) *
853 DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH *
857 t = msecs - shell->workspaces.anim_timestamp;
863 x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2;
866 if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) {
867 weston_compositor_schedule_repaint(shell->compositor);
869 workspace_translate_out(from, shell->workspaces.anim_dir * y);
870 workspace_translate_in(to, shell->workspaces.anim_dir * y);
871 shell->workspaces.anim_current = y;
873 weston_compositor_schedule_repaint(shell->compositor);
876 finish_workspace_change_animation(shell, from, to);
880 animate_workspace_change(struct desktop_shell *shell,
882 struct workspace *from,
883 struct workspace *to)
885 struct weston_output *output;
889 if (index > shell->workspaces.current)
894 shell->workspaces.current = index;
896 shell->workspaces.anim_dir = dir;
897 shell->workspaces.anim_from = from;
898 shell->workspaces.anim_to = to;
899 shell->workspaces.anim_current = 0.0;
900 shell->workspaces.anim_timestamp = 0;
902 output = container_of(shell->compositor->output_list.next,
903 struct weston_output, link);
904 wl_list_insert(&output->animation_list,
905 &shell->workspaces.animation.link);
907 wl_list_insert(from->layer.link.prev, &to->layer.link);
909 workspace_translate_in(to, 0);
911 restore_focus_state(shell, to);
913 weston_compositor_schedule_repaint(shell->compositor);
917 update_workspace(struct desktop_shell *shell, unsigned int index,
918 struct workspace *from, struct workspace *to)
920 shell->workspaces.current = index;
921 wl_list_insert(&from->layer.link, &to->layer.link);
922 wl_list_remove(&from->layer.link);
926 change_workspace(struct desktop_shell *shell, unsigned int index)
928 struct workspace *from;
929 struct workspace *to;
931 if (index == shell->workspaces.current)
934 /* Don't change workspace when there is any fullscreen surfaces. */
935 if (!wl_list_empty(&shell->fullscreen_layer.surface_list))
938 from = get_current_workspace(shell);
939 to = get_workspace(shell, index);
941 if (shell->workspaces.anim_from == to &&
942 shell->workspaces.anim_to == from) {
943 restore_focus_state(shell, to);
944 reverse_workspace_change_animation(shell, index, from, to);
945 broadcast_current_workspace_state(shell);
949 if (shell->workspaces.anim_to != NULL)
950 finish_workspace_change_animation(shell,
951 shell->workspaces.anim_from,
952 shell->workspaces.anim_to);
954 restore_focus_state(shell, to);
956 if (workspace_is_empty(to) && workspace_is_empty(from))
957 update_workspace(shell, index, from, to);
959 animate_workspace_change(shell, index, from, to);
961 broadcast_current_workspace_state(shell);
965 workspace_has_only(struct workspace *ws, struct weston_surface *surface)
967 struct wl_list *list = &ws->layer.surface_list;
970 if (wl_list_empty(list))
978 return container_of(e, struct weston_surface, layer_link) == surface;
982 move_surface_to_workspace(struct desktop_shell *shell,
983 struct weston_surface *surface,
986 struct workspace *from;
987 struct workspace *to;
988 struct weston_seat *seat;
989 struct weston_surface *focus;
991 assert(weston_surface_get_main_surface(surface) == surface);
993 if (workspace == shell->workspaces.current)
996 if (workspace >= shell->workspaces.num)
997 workspace = shell->workspaces.num - 1;
999 from = get_current_workspace(shell);
1000 to = get_workspace(shell, workspace);
1002 wl_list_remove(&surface->layer_link);
1003 wl_list_insert(&to->layer.surface_list, &surface->layer_link);
1005 drop_focus_state(shell, from, surface);
1006 wl_list_for_each(seat, &shell->compositor->seat_list, link) {
1007 if (!seat->keyboard)
1010 focus = weston_surface_get_main_surface(seat->keyboard->focus);
1011 if (focus == surface)
1012 weston_keyboard_set_focus(seat->keyboard, NULL);
1015 weston_surface_damage_below(surface);
1019 take_surface_to_workspace_by_seat(struct desktop_shell *shell,
1020 struct weston_seat *seat,
1023 struct weston_surface *surface;
1024 struct shell_surface *shsurf;
1025 struct workspace *from;
1026 struct workspace *to;
1027 struct focus_state *state;
1029 surface = weston_surface_get_main_surface(seat->keyboard->focus);
1030 if (surface == NULL ||
1031 index == shell->workspaces.current)
1034 from = get_current_workspace(shell);
1035 to = get_workspace(shell, index);
1037 wl_list_remove(&surface->layer_link);
1038 wl_list_insert(&to->layer.surface_list, &surface->layer_link);
1040 replace_focus_state(shell, to, seat);
1041 drop_focus_state(shell, from, surface);
1043 if (shell->workspaces.anim_from == to &&
1044 shell->workspaces.anim_to == from) {
1045 wl_list_remove(&to->layer.link);
1046 wl_list_insert(from->layer.link.prev, &to->layer.link);
1048 reverse_workspace_change_animation(shell, index, from, to);
1049 broadcast_current_workspace_state(shell);
1054 if (shell->workspaces.anim_to != NULL)
1055 finish_workspace_change_animation(shell,
1056 shell->workspaces.anim_from,
1057 shell->workspaces.anim_to);
1059 if (workspace_is_empty(from) &&
1060 workspace_has_only(to, surface))
1061 update_workspace(shell, index, from, to);
1063 shsurf = get_shell_surface(surface);
1064 if (wl_list_empty(&shsurf->workspace_transform.link))
1065 wl_list_insert(&shell->workspaces.anim_sticky_list,
1066 &shsurf->workspace_transform.link);
1068 animate_workspace_change(shell, index, from, to);
1071 broadcast_current_workspace_state(shell);
1073 state = ensure_focus_state(shell, seat);
1075 state->keyboard_focus = surface;
1079 workspace_manager_move_surface(struct wl_client *client,
1080 struct wl_resource *resource,
1081 struct wl_resource *surface_resource,
1084 struct desktop_shell *shell = wl_resource_get_user_data(resource);
1085 struct weston_surface *surface =
1086 wl_resource_get_user_data(surface_resource);
1087 struct weston_surface *main_surface;
1089 main_surface = weston_surface_get_main_surface(surface);
1090 move_surface_to_workspace(shell, main_surface, workspace);
1093 static const struct workspace_manager_interface workspace_manager_implementation = {
1094 workspace_manager_move_surface,
1098 unbind_resource(struct wl_resource *resource)
1100 wl_list_remove(wl_resource_get_link(resource));
1104 bind_workspace_manager(struct wl_client *client,
1105 void *data, uint32_t version, uint32_t id)
1107 struct desktop_shell *shell = data;
1108 struct wl_resource *resource;
1110 resource = wl_resource_create(client,
1111 &workspace_manager_interface, 1, id);
1113 if (resource == NULL) {
1114 weston_log("couldn't add workspace manager object");
1118 wl_resource_set_implementation(resource,
1119 &workspace_manager_implementation,
1120 shell, unbind_resource);
1121 wl_list_insert(&shell->workspaces.client_list,
1122 wl_resource_get_link(resource));
1124 workspace_manager_send_state(resource,
1125 shell->workspaces.current,
1126 shell->workspaces.num);
1130 touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time,
1131 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1136 touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id)
1138 struct shell_touch_grab *shell_grab = container_of(grab,
1139 struct shell_touch_grab,
1141 shell_touch_grab_end(shell_grab);
1145 touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time,
1146 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1148 struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab;
1149 struct shell_surface *shsurf = move->base.shsurf;
1150 struct weston_surface *es;
1151 int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx);
1152 int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy);
1157 es = shsurf->surface;
1159 weston_surface_configure(es, dx, dy,
1160 es->geometry.width, es->geometry.height);
1162 weston_compositor_schedule_repaint(es->compositor);
1165 static const struct weston_touch_grab_interface touch_move_grab_interface = {
1166 touch_move_grab_down,
1168 touch_move_grab_motion,
1172 surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat)
1174 struct weston_touch_move_grab *move;
1179 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1182 move = malloc(sizeof *move);
1186 move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
1187 seat->touch->grab_x;
1188 move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
1189 seat->touch->grab_y;
1191 shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf,
1198 noop_grab_focus(struct weston_pointer_grab *grab)
1203 move_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
1205 struct weston_move_grab *move = (struct weston_move_grab *) grab;
1206 struct weston_pointer *pointer = grab->pointer;
1207 struct shell_surface *shsurf = move->base.shsurf;
1208 struct weston_surface *es;
1209 int dx = wl_fixed_to_int(pointer->x + move->dx);
1210 int dy = wl_fixed_to_int(pointer->y + move->dy);
1215 es = shsurf->surface;
1217 /* ico-ivi-shell hook move */
1218 if (shell_hook_move) {
1219 (*shell_hook_move)(shsurf->surface, &dx, &dy);
1221 weston_surface_configure(es, dx, dy,
1222 es->geometry.width, es->geometry.height);
1224 weston_compositor_schedule_repaint(es->compositor);
1228 move_grab_button(struct weston_pointer_grab *grab,
1229 uint32_t time, uint32_t button, uint32_t state_w)
1231 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
1233 struct weston_pointer *pointer = grab->pointer;
1234 enum wl_pointer_button_state state = state_w;
1236 if (pointer->button_count == 0 &&
1237 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1238 shell_grab_end(shell_grab);
1243 static const struct weston_pointer_grab_interface move_grab_interface = {
1250 surface_move(struct shell_surface *shsurf, struct weston_seat *seat)
1252 struct weston_move_grab *move;
1257 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1260 move = malloc(sizeof *move);
1264 move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
1265 seat->pointer->grab_x;
1266 move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
1267 seat->pointer->grab_y;
1269 shell_grab_start(&move->base, &move_grab_interface, shsurf,
1270 seat->pointer, DESKTOP_SHELL_CURSOR_MOVE);
1276 shell_surface_move(struct wl_client *client, struct wl_resource *resource,
1277 struct wl_resource *seat_resource, uint32_t serial)
1279 struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
1280 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1281 struct weston_surface *surface;
1283 surface = weston_surface_get_main_surface(seat->pointer->focus);
1284 if (seat->pointer->button_count > 0 && seat->pointer->grab_serial == serial) {
1285 surface = weston_surface_get_main_surface(seat->pointer->focus);
1286 if ((surface == shsurf->surface) &&
1287 (surface_move(shsurf, seat) < 0))
1288 wl_resource_post_no_memory(resource);
1289 } else if (seat->touch->grab_serial == serial) {
1290 surface = weston_surface_get_main_surface(seat->touch->focus);
1291 if ((surface == shsurf->surface) &&
1292 (surface_touch_move(shsurf, seat) < 0))
1293 wl_resource_post_no_memory(resource);
1297 struct weston_resize_grab {
1298 struct shell_grab base;
1300 int32_t width, height;
1304 resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
1306 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1307 struct weston_pointer *pointer = grab->pointer;
1308 struct shell_surface *shsurf = resize->base.shsurf;
1309 int32_t width, height;
1310 wl_fixed_t from_x, from_y;
1311 wl_fixed_t to_x, to_y;
1316 weston_surface_from_global_fixed(shsurf->surface,
1317 pointer->grab_x, pointer->grab_y,
1319 weston_surface_from_global_fixed(shsurf->surface,
1320 pointer->x, pointer->y, &to_x, &to_y);
1322 width = resize->width;
1323 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
1324 width += wl_fixed_to_int(from_x - to_x);
1325 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
1326 width += wl_fixed_to_int(to_x - from_x);
1329 height = resize->height;
1330 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
1331 height += wl_fixed_to_int(from_y - to_y);
1332 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
1333 height += wl_fixed_to_int(to_y - from_y);
1336 uifw_trace("resize_grab_motion: send configure %08x %x w/h=%d/%d",
1337 (int)shsurf->surface, resize->edges, width, height);
1338 shsurf->client->send_configure(shsurf->surface,
1339 resize->edges, width, height);
1343 send_configure(struct weston_surface *surface,
1344 uint32_t edges, int32_t width, int32_t height)
1346 struct shell_surface *shsurf = get_shell_surface(surface);
1348 uifw_trace("send_configure: send %08x %x w/h=%d/%d",
1349 (int)shsurf->surface, edges, width, height);
1350 wl_shell_surface_send_configure(shsurf->resource,
1351 edges, width, height);
1354 static const struct weston_shell_client shell_client = {
1359 resize_grab_button(struct weston_pointer_grab *grab,
1360 uint32_t time, uint32_t button, uint32_t state_w)
1362 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1363 struct weston_pointer *pointer = grab->pointer;
1364 enum wl_pointer_button_state state = state_w;
1366 if (pointer->button_count == 0 &&
1367 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1368 shell_grab_end(&resize->base);
1373 static const struct weston_pointer_grab_interface resize_grab_interface = {
1380 * Returns the bounding box of a surface and all its sub-surfaces,
1381 * in the surface coordinates system. */
1383 surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x,
1384 int32_t *y, int32_t *w, int32_t *h) {
1385 pixman_region32_t region;
1386 pixman_box32_t *box;
1387 struct weston_subsurface *subsurface;
1389 pixman_region32_init_rect(®ion, 0, 0,
1390 surface->geometry.width,
1391 surface->geometry.height);
1393 wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
1394 pixman_region32_union_rect(®ion, ®ion,
1395 subsurface->position.x,
1396 subsurface->position.y,
1397 subsurface->surface->geometry.width,
1398 subsurface->surface->geometry.height);
1401 box = pixman_region32_extents(®ion);
1407 *w = box->x2 - box->x1;
1409 *h = box->y2 - box->y1;
1411 pixman_region32_fini(®ion);
1415 surface_resize(struct shell_surface *shsurf,
1416 struct weston_seat *seat, uint32_t edges)
1418 struct weston_resize_grab *resize;
1420 if (shsurf->type == SHELL_SURFACE_FULLSCREEN ||
1421 shsurf->type == SHELL_SURFACE_MAXIMIZED)
1424 if (edges == 0 || edges > 15 ||
1425 (edges & 3) == 3 || (edges & 12) == 12)
1428 resize = malloc(sizeof *resize);
1432 resize->edges = edges;
1433 surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL,
1434 &resize->width, &resize->height);
1436 shell_grab_start(&resize->base, &resize_grab_interface, shsurf,
1437 seat->pointer, edges);
1443 shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
1444 struct wl_resource *seat_resource, uint32_t serial,
1447 struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
1448 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1449 struct weston_surface *surface;
1451 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1454 surface = weston_surface_get_main_surface(seat->pointer->focus);
1455 if (seat->pointer->button_count == 0 ||
1456 seat->pointer->grab_serial != serial ||
1457 surface != shsurf->surface)
1460 if (surface_resize(shsurf, seat, edges) < 0)
1461 wl_resource_post_no_memory(resource);
1465 end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer);
1468 busy_cursor_grab_focus(struct weston_pointer_grab *base)
1470 struct shell_grab *grab = (struct shell_grab *) base;
1471 struct weston_pointer *pointer = base->pointer;
1472 struct weston_surface *surface;
1475 surface = weston_compositor_pick_surface(pointer->seat->compositor,
1476 pointer->x, pointer->y,
1479 if (!grab->shsurf || grab->shsurf->surface != surface)
1480 end_busy_cursor(grab->shsurf, pointer);
1484 busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
1489 busy_cursor_grab_button(struct weston_pointer_grab *base,
1490 uint32_t time, uint32_t button, uint32_t state)
1492 struct shell_grab *grab = (struct shell_grab *) base;
1493 struct shell_surface *shsurf = grab->shsurf;
1494 struct weston_seat *seat = grab->grab.pointer->seat;
1496 if (shsurf && button == BTN_LEFT && state) {
1497 activate(shsurf->shell, shsurf->surface, seat);
1498 surface_move(shsurf, seat);
1499 } else if (shsurf && button == BTN_RIGHT && state) {
1500 activate(shsurf->shell, shsurf->surface, seat);
1501 surface_rotate(shsurf, seat);
1505 static const struct weston_pointer_grab_interface busy_cursor_grab_interface = {
1506 busy_cursor_grab_focus,
1507 busy_cursor_grab_motion,
1508 busy_cursor_grab_button,
1512 set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
1514 struct shell_grab *grab;
1516 grab = malloc(sizeof *grab);
1520 shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer,
1521 DESKTOP_SHELL_CURSOR_BUSY);
1525 end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
1527 struct shell_grab *grab = (struct shell_grab *) pointer->grab;
1529 if (grab->grab.interface == &busy_cursor_grab_interface &&
1530 grab->shsurf == shsurf) {
1531 shell_grab_end(grab);
1537 ping_timer_destroy(struct shell_surface *shsurf)
1539 if (!shsurf || !shsurf->ping_timer)
1542 if (shsurf->ping_timer->source)
1543 wl_event_source_remove(shsurf->ping_timer->source);
1545 free(shsurf->ping_timer);
1546 shsurf->ping_timer = NULL;
1550 ping_timeout_handler(void *data)
1552 struct shell_surface *shsurf = data;
1553 struct weston_seat *seat;
1555 /* Client is not responding */
1556 shsurf->unresponsive = 1;
1558 wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link)
1559 if (seat->pointer->focus == shsurf->surface)
1560 set_busy_cursor(shsurf, seat->pointer);
1566 ping_handler(struct weston_surface *surface, uint32_t serial)
1568 struct shell_surface *shsurf = get_shell_surface(surface);
1569 struct wl_event_loop *loop;
1570 int ping_timeout = 200;
1574 if (!shsurf->resource)
1577 if (shsurf->surface == shsurf->shell->grab_surface)
1580 if (!shsurf->ping_timer) {
1581 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
1582 if (!shsurf->ping_timer)
1585 shsurf->ping_timer->serial = serial;
1586 loop = wl_display_get_event_loop(surface->compositor->wl_display);
1587 shsurf->ping_timer->source =
1588 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
1589 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
1591 wl_shell_surface_send_ping(shsurf->resource, serial);
1596 handle_pointer_focus(struct wl_listener *listener, void *data)
1598 struct weston_pointer *pointer = data;
1599 struct weston_surface *surface = pointer->focus;
1600 struct weston_compositor *compositor;
1601 struct shell_surface *shsurf;
1607 compositor = surface->compositor;
1608 shsurf = get_shell_surface(surface);
1610 if (shsurf && shsurf->unresponsive) {
1611 set_busy_cursor(shsurf, pointer);
1613 serial = wl_display_next_serial(compositor->wl_display);
1614 ping_handler(surface, serial);
1619 create_pointer_focus_listener(struct weston_seat *seat)
1621 struct wl_listener *listener;
1626 listener = malloc(sizeof *listener);
1627 listener->notify = handle_pointer_focus;
1628 wl_signal_add(&seat->pointer->focus_signal, listener);
1632 shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
1635 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1636 struct weston_seat *seat;
1637 struct weston_compositor *ec = shsurf->surface->compositor;
1639 if (shsurf->ping_timer == NULL)
1640 /* Just ignore unsolicited pong. */
1643 if (shsurf->ping_timer->serial == serial) {
1644 shsurf->unresponsive = 0;
1645 wl_list_for_each(seat, &ec->seat_list, link) {
1647 end_busy_cursor(shsurf, seat->pointer);
1649 ping_timer_destroy(shsurf);
1654 shell_surface_set_title(struct wl_client *client,
1655 struct wl_resource *resource, const char *title)
1657 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1659 free(shsurf->title);
1660 shsurf->title = strdup(title);
1662 /* if ico_window_mgr hook, call hook routine */
1663 if (shell_hook_title) {
1664 (*shell_hook_title)(shsurf->surface, shsurf->title);
1669 shell_surface_set_class(struct wl_client *client,
1670 struct wl_resource *resource, const char *class)
1672 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1674 free(shsurf->class);
1675 shsurf->class = strdup(class);
1678 static struct weston_output *
1679 get_default_output(struct weston_compositor *compositor)
1681 return container_of(compositor->output_list.next,
1682 struct weston_output, link);
1686 restore_output_mode(struct weston_output *output)
1688 if (output->current != output->origin ||
1689 (int32_t)output->scale != output->origin_scale)
1690 weston_output_switch_mode(output,
1692 output->origin_scale);
1696 restore_all_output_modes(struct weston_compositor *compositor)
1698 struct weston_output *output;
1700 wl_list_for_each(output, &compositor->output_list, link)
1701 restore_output_mode(output);
1705 shell_unset_fullscreen(struct shell_surface *shsurf)
1707 struct workspace *ws;
1708 /* undo all fullscreen things here */
1709 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1710 shell_surface_is_top_fullscreen(shsurf)) {
1711 restore_output_mode(shsurf->fullscreen_output);
1713 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1714 shsurf->fullscreen.framerate = 0;
1715 wl_list_remove(&shsurf->fullscreen.transform.link);
1716 wl_list_init(&shsurf->fullscreen.transform.link);
1717 if (shsurf->fullscreen.black_surface)
1718 weston_surface_destroy(shsurf->fullscreen.black_surface);
1719 shsurf->fullscreen.black_surface = NULL;
1720 shsurf->fullscreen_output = NULL;
1721 weston_surface_set_position(shsurf->surface,
1722 shsurf->saved_x, shsurf->saved_y);
1723 if (shsurf->saved_rotation_valid) {
1724 wl_list_insert(&shsurf->surface->geometry.transformation_list,
1725 &shsurf->rotation.transform.link);
1726 shsurf->saved_rotation_valid = false;
1729 ws = get_current_workspace(shsurf->shell);
1730 wl_list_remove(&shsurf->surface->layer_link);
1731 wl_list_insert(&ws->layer.surface_list, &shsurf->surface->layer_link);
1735 shell_unset_maximized(struct shell_surface *shsurf)
1737 struct workspace *ws;
1738 /* undo all maximized things here */
1739 shsurf->output = get_default_output(shsurf->surface->compositor);
1740 weston_surface_set_position(shsurf->surface,
1744 if (shsurf->saved_rotation_valid) {
1745 wl_list_insert(&shsurf->surface->geometry.transformation_list,
1746 &shsurf->rotation.transform.link);
1747 shsurf->saved_rotation_valid = false;
1750 ws = get_current_workspace(shsurf->shell);
1751 wl_list_remove(&shsurf->surface->layer_link);
1752 wl_list_insert(&ws->layer.surface_list, &shsurf->surface->layer_link);
1756 reset_shell_surface_type(struct shell_surface *surface)
1758 switch (surface->type) {
1759 case SHELL_SURFACE_FULLSCREEN:
1760 shell_unset_fullscreen(surface);
1762 case SHELL_SURFACE_MAXIMIZED:
1763 shell_unset_maximized(surface);
1765 case SHELL_SURFACE_NONE:
1766 case SHELL_SURFACE_TOPLEVEL:
1767 case SHELL_SURFACE_TRANSIENT:
1768 case SHELL_SURFACE_POPUP:
1769 case SHELL_SURFACE_XWAYLAND:
1773 surface->type = SHELL_SURFACE_NONE;
1778 set_surface_type(struct shell_surface *shsurf)
1780 struct weston_surface *surface = shsurf->surface;
1781 struct weston_surface *pes = shsurf->parent;
1783 reset_shell_surface_type(shsurf);
1785 shsurf->type = shsurf->next_type;
1786 shsurf->next_type = SHELL_SURFACE_NONE;
1788 switch (shsurf->type) {
1789 case SHELL_SURFACE_TOPLEVEL:
1791 case SHELL_SURFACE_TRANSIENT:
1792 weston_surface_set_position(surface,
1793 pes->geometry.x + shsurf->transient.x,
1794 pes->geometry.y + shsurf->transient.y);
1797 case SHELL_SURFACE_MAXIMIZED:
1798 case SHELL_SURFACE_FULLSCREEN:
1799 shsurf->saved_x = surface->geometry.x;
1800 shsurf->saved_y = surface->geometry.y;
1801 shsurf->saved_position_valid = true;
1803 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
1804 wl_list_remove(&shsurf->rotation.transform.link);
1805 wl_list_init(&shsurf->rotation.transform.link);
1806 weston_surface_geometry_dirty(shsurf->surface);
1807 shsurf->saved_rotation_valid = true;
1811 case SHELL_SURFACE_XWAYLAND:
1812 weston_surface_set_position(surface, shsurf->transient.x,
1813 shsurf->transient.y);
1822 set_toplevel(struct shell_surface *shsurf)
1824 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
1828 shell_surface_set_toplevel(struct wl_client *client,
1829 struct wl_resource *resource)
1831 struct shell_surface *surface = wl_resource_get_user_data(resource);
1833 set_toplevel(surface);
1837 set_transient(struct shell_surface *shsurf,
1838 struct weston_surface *parent, int x, int y, uint32_t flags)
1840 /* assign to parents output */
1841 shsurf->parent = parent;
1842 shsurf->transient.x = x;
1843 shsurf->transient.y = y;
1844 shsurf->transient.flags = flags;
1845 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
1849 shell_surface_set_transient(struct wl_client *client,
1850 struct wl_resource *resource,
1851 struct wl_resource *parent_resource,
1852 int x, int y, uint32_t flags)
1854 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1855 struct weston_surface *parent =
1856 wl_resource_get_user_data(parent_resource);
1858 set_transient(shsurf, parent, x, y, flags);
1861 static struct desktop_shell *
1862 shell_surface_get_shell(struct shell_surface *shsurf)
1864 return shsurf->shell;
1868 get_output_panel_height(struct desktop_shell *shell,
1869 struct weston_output *output)
1871 struct weston_surface *surface;
1872 int panel_height = 0;
1877 wl_list_for_each(surface, &shell->panel_layer.surface_list, layer_link) {
1878 if (surface->output == output) {
1879 panel_height = surface->geometry.height;
1884 return panel_height;
1888 shell_surface_set_maximized(struct wl_client *client,
1889 struct wl_resource *resource,
1890 struct wl_resource *output_resource )
1892 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1893 struct weston_surface *es = shsurf->surface;
1894 struct desktop_shell *shell = NULL;
1895 uint32_t edges = 0, panel_height = 0;
1897 /* get the default output, if the client set it as NULL
1898 check whether the ouput is available */
1899 if (output_resource)
1900 shsurf->output = wl_resource_get_user_data(output_resource);
1901 else if (es->output)
1902 shsurf->output = es->output;
1904 shsurf->output = get_default_output(es->compositor);
1906 shell = shell_surface_get_shell(shsurf);
1907 panel_height = get_output_panel_height(shell, shsurf->output);
1908 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
1910 uifw_trace("shell_surface_set_maximized: send %08x %x w/h=%d/%d",
1911 (int)shsurf->surface, edges, shsurf->output->width,
1912 shsurf->output->height - panel_height);
1913 shsurf->client->send_configure(shsurf->surface, edges,
1914 shsurf->output->width,
1915 shsurf->output->height - panel_height);
1917 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
1921 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height);
1923 static struct weston_surface *
1924 create_black_surface(struct weston_compositor *ec,
1925 struct weston_surface *fs_surface,
1926 float x, float y, int w, int h)
1928 struct weston_surface *surface = NULL;
1930 surface = weston_surface_create(ec);
1931 if (surface == NULL) {
1932 weston_log("no memory\n");
1936 surface->configure = black_surface_configure;
1937 surface->configure_private = fs_surface;
1938 uifw_trace("create_black_surface: configure %08x x/y=%d/%d w/h=%d/%d",
1939 (int)surface, (int)x, (int)y, w, h);
1940 weston_surface_configure(surface, x, y, w, h);
1941 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
1942 pixman_region32_fini(&surface->opaque);
1943 pixman_region32_init_rect(&surface->opaque, 0, 0, w, h);
1944 pixman_region32_fini(&surface->input);
1945 pixman_region32_init_rect(&surface->input, 0, 0, w, h);
1950 /* Create black surface and append it to the associated fullscreen surface.
1951 * Handle size dismatch and positioning according to the method. */
1953 shell_configure_fullscreen(struct shell_surface *shsurf)
1955 struct weston_output *output = shsurf->fullscreen_output;
1956 struct weston_surface *surface = shsurf->surface;
1957 struct weston_matrix *matrix;
1958 float scale, output_aspect, surface_aspect, x, y;
1959 int32_t surf_x, surf_y, surf_width, surf_height;
1961 if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER)
1962 restore_output_mode(output);
1964 if (!shsurf->fullscreen.black_surface)
1965 shsurf->fullscreen.black_surface =
1966 create_black_surface(surface->compositor,
1968 output->x, output->y,
1972 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
1973 wl_list_insert(&surface->layer_link,
1974 &shsurf->fullscreen.black_surface->layer_link);
1975 shsurf->fullscreen.black_surface->output = output;
1977 surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y,
1978 &surf_width, &surf_height);
1980 switch (shsurf->fullscreen.type) {
1981 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
1982 if (surface->buffer_ref.buffer)
1983 center_on_output(surface, shsurf->fullscreen_output);
1985 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
1986 /* 1:1 mapping between surface and output dimensions */
1987 if (output->width == surf_width &&
1988 output->height == surf_height) {
1989 weston_surface_set_position(surface, output->x - surf_x,
1990 output->y - surf_y);
1994 matrix = &shsurf->fullscreen.transform.matrix;
1995 weston_matrix_init(matrix);
1997 output_aspect = (float) output->width /
1998 (float) output->height;
1999 surface_aspect = (float) surface->geometry.width /
2000 (float) surface->geometry.height;
2001 if (output_aspect < surface_aspect)
2002 scale = (float) output->width /
2005 scale = (float) output->height /
2006 (float) surf_height;
2008 weston_matrix_scale(matrix, scale, scale, 1);
2009 wl_list_remove(&shsurf->fullscreen.transform.link);
2010 wl_list_insert(&surface->geometry.transformation_list,
2011 &shsurf->fullscreen.transform.link);
2012 x = output->x + (output->width - surf_width * scale) / 2 - surf_x;
2013 y = output->y + (output->height - surf_height * scale) / 2 - surf_y;
2014 weston_surface_set_position(surface, x, y);
2017 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
2018 if (shell_surface_is_top_fullscreen(shsurf)) {
2019 struct weston_mode mode = {0,
2020 surf_width * surface->buffer_scale,
2021 surf_height * surface->buffer_scale,
2022 shsurf->fullscreen.framerate};
2024 if (weston_output_switch_mode(output, &mode, surface->buffer_scale) == 0) {
2025 weston_surface_set_position(surface,
2027 output->y - surf_y);
2028 uifw_trace("shell_configure_fullscreen: configure %08x x/y=%d/%d w/h=%d/%d",
2029 (int)shsurf->fullscreen.black_surface, (int)(output->x - surf_x),
2030 (int)(output->y - surf_y), output->width, output->height);
2031 weston_surface_configure(shsurf->fullscreen.black_surface,
2038 restore_output_mode(output);
2039 center_on_output(surface, output);
2043 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
2044 center_on_output(surface, output);
2051 /* make the fullscreen and black surface at the top */
2053 shell_stack_fullscreen(struct shell_surface *shsurf)
2055 struct weston_output *output = shsurf->fullscreen_output;
2056 struct weston_surface *surface = shsurf->surface;
2057 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
2059 wl_list_remove(&surface->layer_link);
2060 wl_list_insert(&shell->fullscreen_layer.surface_list,
2061 &surface->layer_link);
2062 weston_surface_damage(surface);
2064 if (!shsurf->fullscreen.black_surface)
2065 shsurf->fullscreen.black_surface =
2066 create_black_surface(surface->compositor,
2068 output->x, output->y,
2072 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
2073 wl_list_insert(&surface->layer_link,
2074 &shsurf->fullscreen.black_surface->layer_link);
2075 weston_surface_damage(shsurf->fullscreen.black_surface);
2079 shell_map_fullscreen(struct shell_surface *shsurf)
2081 shell_stack_fullscreen(shsurf);
2082 shell_configure_fullscreen(shsurf);
2086 set_fullscreen(struct shell_surface *shsurf,
2089 struct weston_output *output)
2091 struct weston_surface *es = shsurf->surface;
2094 shsurf->output = output;
2095 else if (es->output)
2096 shsurf->output = es->output;
2098 shsurf->output = get_default_output(es->compositor);
2100 shsurf->fullscreen_output = shsurf->output;
2101 shsurf->fullscreen.type = method;
2102 shsurf->fullscreen.framerate = framerate;
2103 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
2105 uifw_trace("set_fullscreen: send %08x 0 w/h=%d/%d",
2106 (int)shsurf->surface, shsurf->output->width, shsurf->output->height);
2107 shsurf->client->send_configure(shsurf->surface, 0,
2108 shsurf->output->width,
2109 shsurf->output->height);
2113 shell_surface_set_fullscreen(struct wl_client *client,
2114 struct wl_resource *resource,
2117 struct wl_resource *output_resource)
2119 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2120 struct weston_output *output;
2122 if (output_resource)
2123 output = wl_resource_get_user_data(output_resource);
2127 set_fullscreen(shsurf, method, framerate, output);
2131 set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags)
2133 /* XXX: using the same fields for transient type */
2134 shsurf->transient.x = x;
2135 shsurf->transient.y = y;
2136 shsurf->transient.flags = flags;
2137 shsurf->next_type = SHELL_SURFACE_XWAYLAND;
2140 static const struct weston_pointer_grab_interface popup_grab_interface;
2143 destroy_shell_seat(struct wl_listener *listener, void *data)
2145 struct shell_seat *shseat =
2146 container_of(listener,
2147 struct shell_seat, seat_destroy_listener);
2148 struct shell_surface *shsurf, *prev = NULL;
2150 if (shseat->popup_grab.grab.interface == &popup_grab_interface) {
2151 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
2152 shseat->popup_grab.client = NULL;
2154 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
2155 shsurf->popup.shseat = NULL;
2157 wl_list_init(&prev->popup.grab_link);
2161 wl_list_init(&prev->popup.grab_link);
2164 wl_list_remove(&shseat->seat_destroy_listener.link);
2168 static struct shell_seat *
2169 create_shell_seat(struct weston_seat *seat)
2171 struct shell_seat *shseat;
2173 shseat = calloc(1, sizeof *shseat);
2175 weston_log("no memory to allocate shell seat\n");
2179 shseat->seat = seat;
2180 wl_list_init(&shseat->popup_grab.surfaces_list);
2182 shseat->seat_destroy_listener.notify = destroy_shell_seat;
2183 wl_signal_add(&seat->destroy_signal,
2184 &shseat->seat_destroy_listener);
2189 static struct shell_seat *
2190 get_shell_seat(struct weston_seat *seat)
2192 struct wl_listener *listener;
2194 listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat);
2195 if (listener == NULL)
2196 return create_shell_seat(seat);
2198 return container_of(listener,
2199 struct shell_seat, seat_destroy_listener);
2203 popup_grab_focus(struct weston_pointer_grab *grab)
2205 struct weston_pointer *pointer = grab->pointer;
2206 struct weston_surface *surface;
2207 struct shell_seat *shseat =
2208 container_of(grab, struct shell_seat, popup_grab.grab);
2209 struct wl_client *client = shseat->popup_grab.client;
2212 surface = weston_compositor_pick_surface(pointer->seat->compositor,
2213 pointer->x, pointer->y,
2216 if (surface && wl_resource_get_client(surface->resource) == client) {
2217 weston_pointer_set_focus(pointer, surface, sx, sy);
2219 weston_pointer_set_focus(pointer, NULL,
2220 wl_fixed_from_int(0),
2221 wl_fixed_from_int(0));
2226 popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
2228 struct weston_pointer *pointer = grab->pointer;
2231 if (pointer->focus_resource) {
2232 weston_surface_from_global_fixed(pointer->focus,
2233 pointer->x, pointer->y,
2235 wl_pointer_send_motion(pointer->focus_resource, time, sx, sy);
2240 popup_grab_button(struct weston_pointer_grab *grab,
2241 uint32_t time, uint32_t button, uint32_t state_w)
2243 struct wl_resource *resource;
2244 struct shell_seat *shseat =
2245 container_of(grab, struct shell_seat, popup_grab.grab);
2246 struct wl_display *display;
2247 enum wl_pointer_button_state state = state_w;
2250 resource = grab->pointer->focus_resource;
2252 display = wl_client_get_display(wl_resource_get_client(resource));
2253 serial = wl_display_get_serial(display);
2254 wl_pointer_send_button(resource, serial, time, button, state);
2255 } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
2256 (shseat->popup_grab.initial_up ||
2257 time - shseat->seat->pointer->grab_time > 500)) {
2258 popup_grab_end(grab->pointer);
2261 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
2262 shseat->popup_grab.initial_up = 1;
2265 static const struct weston_pointer_grab_interface popup_grab_interface = {
2272 popup_grab_end(struct weston_pointer *pointer)
2274 struct weston_pointer_grab *grab = pointer->grab;
2275 struct shell_seat *shseat =
2276 container_of(grab, struct shell_seat, popup_grab.grab);
2277 struct shell_surface *shsurf;
2278 struct shell_surface *prev = NULL;
2280 if (pointer->grab->interface == &popup_grab_interface) {
2281 weston_pointer_end_grab(grab->pointer);
2282 shseat->popup_grab.client = NULL;
2283 shseat->popup_grab.grab.interface = NULL;
2284 assert(!wl_list_empty(&shseat->popup_grab.surfaces_list));
2285 /* Send the popup_done event to all the popups open */
2286 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
2287 wl_shell_surface_send_popup_done(shsurf->resource);
2288 shsurf->popup.shseat = NULL;
2290 wl_list_init(&prev->popup.grab_link);
2294 wl_list_init(&prev->popup.grab_link);
2295 wl_list_init(&shseat->popup_grab.surfaces_list);
2300 add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat)
2302 struct weston_seat *seat = shseat->seat;
2304 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
2305 shseat->popup_grab.client = wl_resource_get_client(shsurf->resource);
2306 shseat->popup_grab.grab.interface = &popup_grab_interface;
2307 /* We must make sure here that this popup was opened after
2308 * a mouse press, and not just by moving around with other
2309 * popups already open. */
2310 if (shseat->seat->pointer->button_count > 0)
2311 shseat->popup_grab.initial_up = 0;
2313 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
2314 weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab);
2316 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
2321 remove_popup_grab(struct shell_surface *shsurf)
2323 struct shell_seat *shseat = shsurf->popup.shseat;
2325 wl_list_remove(&shsurf->popup.grab_link);
2326 wl_list_init(&shsurf->popup.grab_link);
2327 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
2328 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
2329 shseat->popup_grab.grab.interface = NULL;
2334 shell_map_popup(struct shell_surface *shsurf)
2336 struct shell_seat *shseat = shsurf->popup.shseat;
2337 struct weston_surface *es = shsurf->surface;
2338 struct weston_surface *parent = shsurf->parent;
2340 es->output = parent->output;
2342 weston_surface_set_transform_parent(es, parent);
2343 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
2344 weston_surface_update_transform(es);
2346 if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) {
2347 add_popup_grab(shsurf, shseat);
2349 wl_shell_surface_send_popup_done(shsurf->resource);
2350 shseat->popup_grab.client = NULL;
2355 shell_surface_set_popup(struct wl_client *client,
2356 struct wl_resource *resource,
2357 struct wl_resource *seat_resource,
2359 struct wl_resource *parent_resource,
2360 int32_t x, int32_t y, uint32_t flags)
2362 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2364 shsurf->type = SHELL_SURFACE_POPUP;
2365 shsurf->parent = wl_resource_get_user_data(parent_resource);
2366 shsurf->popup.shseat = get_shell_seat(wl_resource_get_user_data(seat_resource));
2367 shsurf->popup.serial = serial;
2368 shsurf->popup.x = x;
2369 shsurf->popup.y = y;
2372 static const struct wl_shell_surface_interface shell_surface_implementation = {
2375 shell_surface_resize,
2376 shell_surface_set_toplevel,
2377 shell_surface_set_transient,
2378 shell_surface_set_fullscreen,
2379 shell_surface_set_popup,
2380 shell_surface_set_maximized,
2381 shell_surface_set_title,
2382 shell_surface_set_class
2386 destroy_shell_surface(struct shell_surface *shsurf)
2388 wl_signal_emit(&shsurf->destroy_signal, shsurf);
2390 /* if ico_window_mgr hook, call hook routine */
2391 if (shell_hook_destroy) {
2392 (*shell_hook_destroy)(shsurf->surface);
2395 if (!wl_list_empty(&shsurf->popup.grab_link)) {
2396 remove_popup_grab(shsurf);
2399 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
2400 shell_surface_is_top_fullscreen(shsurf))
2401 restore_output_mode (shsurf->fullscreen_output);
2403 if (shsurf->fullscreen.black_surface)
2404 weston_surface_destroy(shsurf->fullscreen.black_surface);
2406 /* As destroy_resource() use wl_list_for_each_safe(),
2407 * we can always remove the listener.
2409 wl_list_remove(&shsurf->surface_destroy_listener.link);
2410 shsurf->surface->configure = NULL;
2411 ping_timer_destroy(shsurf);
2412 free(shsurf->title);
2414 wl_list_remove(&shsurf->link);
2419 shell_destroy_shell_surface(struct wl_resource *resource)
2421 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2423 destroy_shell_surface(shsurf);
2427 shell_handle_surface_destroy(struct wl_listener *listener, void *data)
2429 struct shell_surface *shsurf = container_of(listener,
2430 struct shell_surface,
2431 surface_destroy_listener);
2433 if (shsurf->resource)
2434 wl_resource_destroy(shsurf->resource);
2436 destroy_shell_surface(shsurf);
2440 shell_surface_configure(struct weston_surface *, int32_t, int32_t, int32_t, int32_t);
2442 static struct shell_surface *
2443 get_shell_surface(struct weston_surface *surface)
2445 if (surface->configure == shell_surface_configure)
2446 return surface->configure_private;
2451 static struct shell_surface *
2452 create_shell_surface(void *shell, struct weston_surface *surface,
2453 const struct weston_shell_client *client)
2455 struct shell_surface *shsurf;
2457 if (surface->configure) {
2458 weston_log("surface->configure already set\n");
2462 shsurf = calloc(1, sizeof *shsurf);
2464 weston_log("no memory to allocate shell surface\n");
2468 surface->configure = shell_surface_configure;
2469 surface->configure_private = shsurf;
2471 shsurf->shell = (struct desktop_shell *) shell;
2472 shsurf->unresponsive = 0;
2473 shsurf->saved_position_valid = false;
2474 shsurf->saved_rotation_valid = false;
2475 shsurf->surface = surface;
2476 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
2477 shsurf->fullscreen.framerate = 0;
2478 shsurf->fullscreen.black_surface = NULL;
2479 shsurf->ping_timer = NULL;
2480 wl_list_init(&shsurf->fullscreen.transform.link);
2482 wl_signal_init(&shsurf->destroy_signal);
2483 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
2484 wl_signal_add(&surface->destroy_signal,
2485 &shsurf->surface_destroy_listener);
2487 /* init link so its safe to always remove it in destroy_shell_surface */
2488 wl_list_init(&shsurf->link);
2489 wl_list_init(&shsurf->popup.grab_link);
2491 /* empty when not in use */
2492 wl_list_init(&shsurf->rotation.transform.link);
2493 weston_matrix_init(&shsurf->rotation.rotation);
2495 wl_list_init(&shsurf->workspace_transform.link);
2497 shsurf->type = SHELL_SURFACE_NONE;
2498 shsurf->next_type = SHELL_SURFACE_NONE;
2500 shsurf->client = client;
2506 shell_get_shell_surface(struct wl_client *client,
2507 struct wl_resource *resource,
2509 struct wl_resource *surface_resource)
2511 struct weston_surface *surface =
2512 wl_resource_get_user_data(surface_resource);
2513 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2514 struct shell_surface *shsurf;
2516 if (get_shell_surface(surface)) {
2517 wl_resource_post_error(surface_resource,
2518 WL_DISPLAY_ERROR_INVALID_OBJECT,
2519 "desktop_shell::get_shell_surface already requested");
2523 shsurf = create_shell_surface(shell, surface, &shell_client);
2525 wl_resource_post_error(surface_resource,
2526 WL_DISPLAY_ERROR_INVALID_OBJECT,
2527 "surface->configure already set");
2532 wl_resource_create(client,
2533 &wl_shell_surface_interface, 1, id);
2534 wl_resource_set_implementation(shsurf->resource,
2535 &shell_surface_implementation,
2536 shsurf, shell_destroy_shell_surface);
2538 /* if ico_window_mgr hook, call hook routine */
2539 if (shell_hook_create) {
2540 (*shell_hook_create)(client, resource, surface, shsurf);
2544 static const struct wl_shell_interface shell_implementation = {
2545 shell_get_shell_surface
2549 shell_fade(struct desktop_shell *shell, enum fade_type type);
2552 screensaver_timeout(void *data)
2554 struct desktop_shell *shell = data;
2556 shell_fade(shell, FADE_OUT);
2562 handle_screensaver_sigchld(struct weston_process *proc, int status)
2564 struct desktop_shell *shell =
2565 container_of(proc, struct desktop_shell, screensaver.process);
2570 weston_compositor_sleep(shell->compositor);
2574 launch_screensaver(struct desktop_shell *shell)
2576 if (shell->screensaver.binding)
2579 if (!shell->screensaver.path) {
2580 weston_compositor_sleep(shell->compositor);
2584 if (shell->screensaver.process.pid != 0) {
2585 weston_log("old screensaver still running\n");
2589 weston_client_launch(shell->compositor,
2590 &shell->screensaver.process,
2591 shell->screensaver.path,
2592 handle_screensaver_sigchld);
2596 terminate_screensaver(struct desktop_shell *shell)
2598 if (shell->screensaver.process.pid == 0)
2601 kill(shell->screensaver.process.pid, SIGTERM);
2605 configure_static_surface(struct weston_surface *es, struct weston_layer *layer, int32_t width, int32_t height)
2607 struct weston_surface *s, *next;
2612 wl_list_for_each_safe(s, next, &layer->surface_list, layer_link) {
2613 if (s->output == es->output && s != es) {
2614 weston_surface_unmap(s);
2615 s->configure = NULL;
2619 uifw_trace("configure_static_surface: configure %08x x/y=%d/%d w/h=%d/%d",
2620 (int)es, (int)es->output->x, (int)es->output->y, width, height);
2621 weston_surface_configure(es, es->output->x, es->output->y, width, height);
2623 if (wl_list_empty(&es->layer_link)) {
2624 wl_list_insert(&layer->surface_list, &es->layer_link);
2625 weston_compositor_schedule_repaint(es->compositor);
2628 /* if ico_window_mgr hook, call hook routine */
2629 if (shell_hook_configure) {
2630 (*shell_hook_configure)(es);
2635 background_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
2637 struct desktop_shell *shell = es->configure_private;
2639 configure_static_surface(es, &shell->background_layer, width, height);
2643 desktop_shell_set_background(struct wl_client *client,
2644 struct wl_resource *resource,
2645 struct wl_resource *output_resource,
2646 struct wl_resource *surface_resource)
2648 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2649 struct weston_surface *surface =
2650 wl_resource_get_user_data(surface_resource);
2652 if (surface->configure) {
2653 wl_resource_post_error(surface_resource,
2654 WL_DISPLAY_ERROR_INVALID_OBJECT,
2655 "surface role already assigned");
2659 surface->configure = background_configure;
2660 surface->configure_private = shell;
2661 surface->output = wl_resource_get_user_data(output_resource);
2662 uifw_trace("desktop_shell_set_background: send %08x 0 w/h=%d/%d",
2663 (int)surface, surface->output->width, surface->output->height);
2664 desktop_shell_send_configure(resource, 0,
2666 surface->output->width,
2667 surface->output->height);
2671 panel_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
2673 struct desktop_shell *shell = es->configure_private;
2675 configure_static_surface(es, &shell->panel_layer, width, height);
2679 desktop_shell_set_panel(struct wl_client *client,
2680 struct wl_resource *resource,
2681 struct wl_resource *output_resource,
2682 struct wl_resource *surface_resource)
2684 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2685 struct weston_surface *surface =
2686 wl_resource_get_user_data(surface_resource);
2688 if (surface->configure) {
2689 wl_resource_post_error(surface_resource,
2690 WL_DISPLAY_ERROR_INVALID_OBJECT,
2691 "surface role already assigned");
2695 surface->configure = panel_configure;
2696 surface->configure_private = shell;
2697 surface->output = wl_resource_get_user_data(output_resource);
2698 uifw_trace("desktop_shell_set_panel: send %08x 0 w/h=%d/%d",
2699 (int)surface, surface->output->width, surface->output->height);
2700 desktop_shell_send_configure(resource, 0,
2702 surface->output->width,
2703 surface->output->height);
2707 lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
2709 struct desktop_shell *shell = surface->configure_private;
2714 uifw_trace("lock_surface_configure: change %08x w/h=%d/%d", (int)surface, width, height);
2715 surface->geometry.width = width;
2716 surface->geometry.height = height;
2717 center_on_output(surface, get_default_output(shell->compositor));
2719 if (!weston_surface_is_mapped(surface)) {
2720 wl_list_insert(&shell->lock_layer.surface_list,
2721 &surface->layer_link);
2722 weston_surface_update_transform(surface);
2723 shell_fade(shell, FADE_IN);
2728 handle_lock_surface_destroy(struct wl_listener *listener, void *data)
2730 struct desktop_shell *shell =
2731 container_of(listener, struct desktop_shell, lock_surface_listener);
2733 weston_log("lock surface gone\n");
2734 shell->lock_surface = NULL;
2738 desktop_shell_set_lock_surface(struct wl_client *client,
2739 struct wl_resource *resource,
2740 struct wl_resource *surface_resource)
2742 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2743 struct weston_surface *surface =
2744 wl_resource_get_user_data(surface_resource);
2746 shell->prepare_event_sent = false;
2751 shell->lock_surface = surface;
2753 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
2754 wl_signal_add(&surface->destroy_signal,
2755 &shell->lock_surface_listener);
2757 surface->configure = lock_surface_configure;
2758 surface->configure_private = shell;
2762 resume_desktop(struct desktop_shell *shell)
2764 struct workspace *ws = get_current_workspace(shell);
2766 terminate_screensaver(shell);
2768 wl_list_remove(&shell->lock_layer.link);
2769 wl_list_insert(&shell->compositor->cursor_layer.link,
2770 &shell->fullscreen_layer.link);
2771 wl_list_insert(&shell->fullscreen_layer.link,
2772 &shell->panel_layer.link);
2773 if (shell->showing_input_panels) {
2774 wl_list_insert(&shell->panel_layer.link,
2775 &shell->input_panel_layer.link);
2776 wl_list_insert(&shell->input_panel_layer.link,
2779 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
2782 restore_focus_state(shell, get_current_workspace(shell));
2784 shell->locked = false;
2785 shell_fade(shell, FADE_IN);
2786 weston_compositor_damage_all(shell->compositor);
2790 desktop_shell_unlock(struct wl_client *client,
2791 struct wl_resource *resource)
2793 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2795 shell->prepare_event_sent = false;
2798 resume_desktop(shell);
2802 desktop_shell_set_grab_surface(struct wl_client *client,
2803 struct wl_resource *resource,
2804 struct wl_resource *surface_resource)
2806 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2808 shell->grab_surface = wl_resource_get_user_data(surface_resource);
2812 desktop_shell_desktop_ready(struct wl_client *client,
2813 struct wl_resource *resource)
2815 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2817 shell_fade_startup(shell);
2820 static const struct desktop_shell_interface desktop_shell_implementation = {
2821 desktop_shell_set_background,
2822 desktop_shell_set_panel,
2823 desktop_shell_set_lock_surface,
2824 desktop_shell_unlock,
2825 desktop_shell_set_grab_surface,
2826 desktop_shell_desktop_ready
2829 static enum shell_surface_type
2830 get_shell_surface_type(struct weston_surface *surface)
2832 struct shell_surface *shsurf;
2834 shsurf = get_shell_surface(surface);
2836 return SHELL_SURFACE_NONE;
2837 return shsurf->type;
2841 move_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
2843 struct weston_surface *focus =
2844 (struct weston_surface *) seat->pointer->focus;
2845 struct weston_surface *surface;
2846 struct shell_surface *shsurf;
2848 surface = weston_surface_get_main_surface(focus);
2849 if (surface == NULL)
2852 shsurf = get_shell_surface(surface);
2853 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
2854 shsurf->type == SHELL_SURFACE_MAXIMIZED)
2857 surface_move(shsurf, (struct weston_seat *) seat);
2861 resize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
2863 struct weston_surface *focus =
2864 (struct weston_surface *) seat->pointer->focus;
2865 struct weston_surface *surface;
2868 struct shell_surface *shsurf;
2870 surface = weston_surface_get_main_surface(focus);
2871 if (surface == NULL)
2874 shsurf = get_shell_surface(surface);
2875 if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
2876 shsurf->type == SHELL_SURFACE_MAXIMIZED)
2879 weston_surface_from_global(surface,
2880 wl_fixed_to_int(seat->pointer->grab_x),
2881 wl_fixed_to_int(seat->pointer->grab_y),
2884 if (x < surface->geometry.width / 3)
2885 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
2886 else if (x < 2 * surface->geometry.width / 3)
2889 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
2891 if (y < surface->geometry.height / 3)
2892 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
2893 else if (y < 2 * surface->geometry.height / 3)
2896 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
2898 surface_resize(shsurf, (struct weston_seat *) seat, edges);
2902 surface_opacity_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
2903 wl_fixed_t value, void *data)
2906 struct shell_surface *shsurf;
2907 struct weston_surface *focus =
2908 (struct weston_surface *) seat->pointer->focus;
2909 struct weston_surface *surface;
2911 /* XXX: broken for windows containing sub-surfaces */
2912 surface = weston_surface_get_main_surface(focus);
2913 if (surface == NULL)
2916 shsurf = get_shell_surface(surface);
2920 surface->alpha -= wl_fixed_to_double(value) * step;
2922 if (surface->alpha > 1.0)
2923 surface->alpha = 1.0;
2924 if (surface->alpha < step)
2925 surface->alpha = step;
2927 weston_surface_geometry_dirty(surface);
2928 weston_surface_damage(surface);
2932 do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
2935 struct weston_seat *ws = (struct weston_seat *) seat;
2936 struct weston_compositor *compositor = ws->compositor;
2937 struct weston_output *output;
2940 wl_list_for_each(output, &compositor->output_list, link) {
2941 if (pixman_region32_contains_point(&output->region,
2942 wl_fixed_to_double(seat->pointer->x),
2943 wl_fixed_to_double(seat->pointer->y),
2945 if (key == KEY_PAGEUP)
2946 increment = output->zoom.increment;
2947 else if (key == KEY_PAGEDOWN)
2948 increment = -output->zoom.increment;
2949 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
2950 /* For every pixel zoom 20th of a step */
2951 increment = output->zoom.increment *
2952 -wl_fixed_to_double(value) / 20.0;
2956 output->zoom.level += increment;
2958 if (output->zoom.level < 0.0)
2959 output->zoom.level = 0.0;
2960 else if (output->zoom.level > output->zoom.max_level)
2961 output->zoom.level = output->zoom.max_level;
2962 else if (!output->zoom.active) {
2963 output->zoom.active = 1;
2964 output->disable_planes++;
2967 output->zoom.spring_z.target = output->zoom.level;
2969 weston_output_update_zoom(output, output->zoom.type);
2975 zoom_axis_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
2976 wl_fixed_t value, void *data)
2978 do_zoom(seat, time, 0, axis, value);
2982 zoom_key_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
2985 do_zoom(seat, time, key, 0, 0);
2989 terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
2992 struct weston_compositor *compositor = data;
2994 wl_display_terminate(compositor->wl_display);
2998 rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
3000 struct rotate_grab *rotate =
3001 container_of(grab, struct rotate_grab, base.grab);
3002 struct weston_pointer *pointer = grab->pointer;
3003 struct shell_surface *shsurf = rotate->base.shsurf;
3004 struct weston_surface *surface;
3005 float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
3010 surface = shsurf->surface;
3012 cx = 0.5f * surface->geometry.width;
3013 cy = 0.5f * surface->geometry.height;
3015 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
3016 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
3017 r = sqrtf(dx * dx + dy * dy);
3019 wl_list_remove(&shsurf->rotation.transform.link);
3020 weston_surface_geometry_dirty(shsurf->surface);
3023 struct weston_matrix *matrix =
3024 &shsurf->rotation.transform.matrix;
3026 weston_matrix_init(&rotate->rotation);
3027 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
3029 weston_matrix_init(matrix);
3030 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
3031 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
3032 weston_matrix_multiply(matrix, &rotate->rotation);
3033 weston_matrix_translate(matrix, cx, cy, 0.0f);
3036 &shsurf->surface->geometry.transformation_list,
3037 &shsurf->rotation.transform.link);
3039 wl_list_init(&shsurf->rotation.transform.link);
3040 weston_matrix_init(&shsurf->rotation.rotation);
3041 weston_matrix_init(&rotate->rotation);
3044 /* We need to adjust the position of the surface
3045 * in case it was resized in a rotated state before */
3046 cposx = surface->geometry.x + cx;
3047 cposy = surface->geometry.y + cy;
3048 dposx = rotate->center.x - cposx;
3049 dposy = rotate->center.y - cposy;
3050 if (dposx != 0.0f || dposy != 0.0f) {
3051 weston_surface_set_position(surface,
3052 surface->geometry.x + dposx,
3053 surface->geometry.y + dposy);
3056 /* Repaint implies weston_surface_update_transform(), which
3057 * lazily applies the damage due to rotation update.
3059 weston_compositor_schedule_repaint(shsurf->surface->compositor);
3063 rotate_grab_button(struct weston_pointer_grab *grab,
3064 uint32_t time, uint32_t button, uint32_t state_w)
3066 struct rotate_grab *rotate =
3067 container_of(grab, struct rotate_grab, base.grab);
3068 struct weston_pointer *pointer = grab->pointer;
3069 struct shell_surface *shsurf = rotate->base.shsurf;
3070 enum wl_pointer_button_state state = state_w;
3072 if (pointer->button_count == 0 &&
3073 state == WL_POINTER_BUTTON_STATE_RELEASED) {
3075 weston_matrix_multiply(&shsurf->rotation.rotation,
3077 shell_grab_end(&rotate->base);
3082 static const struct weston_pointer_grab_interface rotate_grab_interface = {
3089 surface_rotate(struct shell_surface *surface, struct weston_seat *seat)
3091 struct rotate_grab *rotate;
3095 rotate = malloc(sizeof *rotate);
3099 weston_surface_to_global_float(surface->surface,
3100 surface->surface->geometry.width * 0.5f,
3101 surface->surface->geometry.height * 0.5f,
3102 &rotate->center.x, &rotate->center.y);
3104 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
3105 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
3106 r = sqrtf(dx * dx + dy * dy);
3108 struct weston_matrix inverse;
3110 weston_matrix_init(&inverse);
3111 weston_matrix_rotate_xy(&inverse, dx / r, -dy / r);
3112 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
3114 weston_matrix_init(&rotate->rotation);
3115 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
3117 weston_matrix_init(&surface->rotation.rotation);
3118 weston_matrix_init(&rotate->rotation);
3121 shell_grab_start(&rotate->base, &rotate_grab_interface, surface,
3122 seat->pointer, DESKTOP_SHELL_CURSOR_ARROW);
3126 rotate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
3129 struct weston_surface *focus =
3130 (struct weston_surface *) seat->pointer->focus;
3131 struct weston_surface *base_surface;
3132 struct shell_surface *surface;
3134 base_surface = weston_surface_get_main_surface(focus);
3135 if (base_surface == NULL)
3138 surface = get_shell_surface(base_surface);
3139 if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN ||
3140 surface->type == SHELL_SURFACE_MAXIMIZED)
3143 surface_rotate(surface, seat);
3147 lower_fullscreen_layer(struct desktop_shell *shell)
3149 struct workspace *ws;
3150 struct weston_surface *surface, *prev;
3152 ws = get_current_workspace(shell);
3153 wl_list_for_each_reverse_safe(surface, prev,
3154 &shell->fullscreen_layer.surface_list,
3156 weston_surface_restack(surface, &ws->layer.surface_list);
3160 activate(struct desktop_shell *shell, struct weston_surface *es,
3161 struct weston_seat *seat)
3163 struct weston_surface *main_surface;
3164 struct focus_state *state;
3165 struct workspace *ws;
3167 main_surface = weston_surface_get_main_surface(es);
3169 weston_surface_activate(es, seat);
3171 state = ensure_focus_state(shell, seat);
3175 state->keyboard_focus = es;
3176 wl_list_remove(&state->surface_destroy_listener.link);
3177 wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener);
3179 /* if ico_window_mgr hook, not change surface stack */
3180 if (shell_hook_select) {
3184 switch (get_shell_surface_type(main_surface)) {
3185 case SHELL_SURFACE_FULLSCREEN:
3186 /* should on top of panels */
3187 shell_stack_fullscreen(get_shell_surface(main_surface));
3188 shell_configure_fullscreen(get_shell_surface(main_surface));
3191 restore_all_output_modes(shell->compositor);
3192 ws = get_current_workspace(shell);
3193 weston_surface_restack(main_surface, &ws->layer.surface_list);
3198 /* no-op func for checking black surface */
3200 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
3205 is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
3207 if (es->configure == black_surface_configure) {
3209 *fs_surface = (struct weston_surface *)es->configure_private;
3216 click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
3219 struct weston_seat *ws = (struct weston_seat *) seat;
3220 struct desktop_shell *shell = data;
3221 struct weston_surface *focus;
3222 struct weston_surface *main_surface;
3224 if (button == BTN_LEFT)
3225 focus = (struct weston_surface *) seat->pointer->focus;
3227 focus = (struct weston_surface *) seat->touch->focus;
3231 if (is_black_surface(focus, &main_surface))
3232 focus = main_surface;
3234 main_surface = weston_surface_get_main_surface(focus);
3235 if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE)
3238 if (seat->pointer->grab == &seat->pointer->default_grab)
3239 activate(shell, focus, ws);
3241 /* if ico_window_mgr hook, call hook routine */
3242 if (shell_hook_select) {
3243 (*shell_hook_select)(focus);
3248 lock(struct desktop_shell *shell)
3250 struct workspace *ws = get_current_workspace(shell);
3252 if (shell->locked) {
3253 weston_compositor_sleep(shell->compositor);
3257 shell->locked = true;
3259 /* Hide all surfaces by removing the fullscreen, panel and
3260 * toplevel layers. This way nothing else can show or receive
3261 * input events while we are locked. */
3263 wl_list_remove(&shell->panel_layer.link);
3264 wl_list_remove(&shell->fullscreen_layer.link);
3265 if (shell->showing_input_panels)
3266 wl_list_remove(&shell->input_panel_layer.link);
3267 wl_list_remove(&ws->layer.link);
3268 wl_list_insert(&shell->compositor->cursor_layer.link,
3269 &shell->lock_layer.link);
3271 launch_screensaver(shell);
3273 /* TODO: disable bindings that should not work while locked. */
3275 /* All this must be undone in resume_desktop(). */
3279 unlock(struct desktop_shell *shell)
3281 if (!shell->locked || shell->lock_surface) {
3282 shell_fade(shell, FADE_IN);
3286 /* If desktop-shell client has gone away, unlock immediately. */
3287 if (!shell->child.desktop_shell) {
3288 resume_desktop(shell);
3292 if (shell->prepare_event_sent)
3295 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
3296 shell->prepare_event_sent = true;
3300 shell_fade_done(struct weston_surface_animation *animation, void *data)
3302 struct desktop_shell *shell = data;
3304 shell->fade.animation = NULL;
3306 switch (shell->fade.type) {
3308 weston_surface_destroy(shell->fade.surface);
3309 shell->fade.surface = NULL;
3317 static struct weston_surface *
3318 shell_fade_create_surface(struct desktop_shell *shell)
3320 struct weston_compositor *compositor = shell->compositor;
3321 struct weston_surface *surface;
3323 surface = weston_surface_create(compositor);
3327 uifw_trace("shell_fade_create_surface: configure %08x x/y=%d/%d w/h=%d/%d",
3328 (int)surface, 0, 0, 8192, 8192);
3329 weston_surface_configure(surface, 0, 0, 8192, 8192);
3330 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
3331 wl_list_insert(&compositor->fade_layer.surface_list,
3332 &surface->layer_link);
3333 pixman_region32_init(&surface->input);
3339 shell_fade(struct desktop_shell *shell, enum fade_type type)
3351 weston_log("shell: invalid fade type\n");
3355 shell->fade.type = type;
3357 if (shell->fade.surface == NULL) {
3358 shell->fade.surface = shell_fade_create_surface(shell);
3359 if (!shell->fade.surface)
3362 shell->fade.surface->alpha = 1.0 - tint;
3363 weston_surface_update_transform(shell->fade.surface);
3366 if (shell->fade.animation)
3367 weston_fade_update(shell->fade.animation, tint);
3369 shell->fade.animation =
3370 weston_fade_run(shell->fade.surface,
3371 1.0 - tint, tint, 300.0,
3372 shell_fade_done, shell);
3376 do_shell_fade_startup(void *data)
3378 struct desktop_shell *shell = data;
3380 shell_fade(shell, FADE_IN);
3384 shell_fade_startup(struct desktop_shell *shell)
3386 struct wl_event_loop *loop;
3388 if (!shell->fade.startup_timer)
3391 wl_event_source_remove(shell->fade.startup_timer);
3392 shell->fade.startup_timer = NULL;
3394 loop = wl_display_get_event_loop(shell->compositor->wl_display);
3395 wl_event_loop_add_idle(loop, do_shell_fade_startup, shell);
3399 fade_startup_timeout(void *data)
3401 struct desktop_shell *shell = data;
3403 shell_fade_startup(shell);
3408 shell_fade_init(struct desktop_shell *shell)
3410 /* Make compositor output all black, and wait for the desktop-shell
3411 * client to signal it is ready, then fade in. The timer triggers a
3412 * fade-in, in case the desktop-shell client takes too long.
3415 struct wl_event_loop *loop;
3417 if (shell->fade.surface != NULL) {
3418 weston_log("%s: warning: fade surface already exists\n",
3423 shell->fade.surface = shell_fade_create_surface(shell);
3424 if (!shell->fade.surface)
3427 weston_surface_update_transform(shell->fade.surface);
3428 weston_surface_damage(shell->fade.surface);
3430 loop = wl_display_get_event_loop(shell->compositor->wl_display);
3431 shell->fade.startup_timer =
3432 wl_event_loop_add_timer(loop, fade_startup_timeout, shell);
3433 wl_event_source_timer_update(shell->fade.startup_timer, 15000);
3437 idle_handler(struct wl_listener *listener, void *data)
3439 struct desktop_shell *shell =
3440 container_of(listener, struct desktop_shell, idle_listener);
3442 shell_fade(shell, FADE_OUT);
3443 /* lock() is called from shell_fade_done() */
3447 wake_handler(struct wl_listener *listener, void *data)
3449 struct desktop_shell *shell =
3450 container_of(listener, struct desktop_shell, wake_listener);
3456 show_input_panels(struct wl_listener *listener, void *data)
3458 struct desktop_shell *shell =
3459 container_of(listener, struct desktop_shell,
3460 show_input_panel_listener);
3461 struct input_panel_surface *surface, *next;
3462 struct weston_surface *ws;
3464 shell->text_input.surface = (struct weston_surface*)data;
3466 if (shell->showing_input_panels)
3469 shell->showing_input_panels = true;
3472 wl_list_insert(&shell->panel_layer.link,
3473 &shell->input_panel_layer.link);
3475 wl_list_for_each_safe(surface, next,
3476 &shell->input_panel.surfaces, link) {
3477 ws = surface->surface;
3478 if (!ws->buffer_ref.buffer)
3480 wl_list_insert(&shell->input_panel_layer.surface_list,
3482 weston_surface_geometry_dirty(ws);
3483 weston_surface_update_transform(ws);
3484 weston_surface_damage(ws);
3485 weston_slide_run(ws, ws->geometry.height, 0, NULL, NULL);
3490 hide_input_panels(struct wl_listener *listener, void *data)
3492 struct desktop_shell *shell =
3493 container_of(listener, struct desktop_shell,
3494 hide_input_panel_listener);
3495 struct weston_surface *surface, *next;
3497 if (!shell->showing_input_panels)
3500 shell->showing_input_panels = false;
3503 wl_list_remove(&shell->input_panel_layer.link);
3505 wl_list_for_each_safe(surface, next,
3506 &shell->input_panel_layer.surface_list, layer_link)
3507 weston_surface_unmap(surface);
3511 update_input_panels(struct wl_listener *listener, void *data)
3513 struct desktop_shell *shell =
3514 container_of(listener, struct desktop_shell,
3515 update_input_panel_listener);
3517 memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t));
3521 center_on_output(struct weston_surface *surface, struct weston_output *output)
3523 int32_t surf_x, surf_y, width, height;
3526 surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y, &width, &height);
3528 x = output->x + (output->width - width) / 2 - surf_x / 2;
3529 y = output->y + (output->height - height) / 2 - surf_y / 2;
3531 uifw_trace("center_on_output: %08x x/y=%d/%d w/h=%d/%d",
3532 (int)output, (int)x, (int)y, width, height);
3533 weston_surface_configure(surface, x, y, width, height);
3537 weston_surface_set_initial_position (struct weston_surface *surface,
3538 struct desktop_shell *shell)
3540 struct weston_compositor *compositor = shell->compositor;
3542 int range_x, range_y;
3543 int dx, dy, x, y, panel_height;
3544 struct weston_output *output, *target_output = NULL;
3545 struct weston_seat *seat;
3547 /* As a heuristic place the new window on the same output as the
3548 * pointer. Falling back to the output containing 0, 0.
3550 * TODO: Do something clever for touch too?
3552 wl_list_for_each(seat, &compositor->seat_list, link) {
3553 if (seat->pointer) {
3554 ix = wl_fixed_to_int(seat->pointer->x);
3555 iy = wl_fixed_to_int(seat->pointer->y);
3560 wl_list_for_each(output, &compositor->output_list, link) {
3561 if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) {
3562 target_output = output;
3567 if (!target_output) {
3568 weston_surface_set_position(surface, 10 + random() % 400,
3569 10 + random() % 400);
3573 /* Valid range within output where the surface will still be onscreen.
3574 * If this is negative it means that the surface is bigger than
3577 panel_height = get_output_panel_height(shell, target_output);
3578 range_x = target_output->width - surface->geometry.width;
3579 range_y = (target_output->height - panel_height) -
3580 surface->geometry.height;
3583 dx = random() % range_x;
3588 dy = panel_height + random() % range_y;
3592 x = target_output->x + dx;
3593 y = target_output->y + dy;
3595 weston_surface_set_position (surface, x, y);
3599 map(struct desktop_shell *shell, struct weston_surface *surface,
3600 int32_t width, int32_t height, int32_t sx, int32_t sy)
3602 struct weston_compositor *compositor = shell->compositor;
3603 struct shell_surface *shsurf = get_shell_surface(surface);
3604 enum shell_surface_type surface_type = shsurf->type;
3605 struct weston_surface *parent;
3606 struct weston_seat *seat;
3607 struct workspace *ws;
3608 int panel_height = 0;
3609 int32_t surf_x, surf_y;
3611 uifw_trace("map: %08x sx/sy=%d/%d w/h=%d/%d", (int)surface, sx, sy, width, height);
3612 surface->geometry.width = width;
3613 surface->geometry.height = height;
3614 weston_surface_geometry_dirty(surface);
3616 /* initial positioning, see also configure() */
3617 switch (surface_type) {
3618 case SHELL_SURFACE_TOPLEVEL:
3619 weston_surface_set_initial_position(surface, shell);
3621 case SHELL_SURFACE_FULLSCREEN:
3622 center_on_output(surface, shsurf->fullscreen_output);
3623 shell_map_fullscreen(shsurf);
3625 case SHELL_SURFACE_MAXIMIZED:
3626 /* use surface configure to set the geometry */
3627 panel_height = get_output_panel_height(shell,surface->output);
3628 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
3630 weston_surface_set_position(surface, shsurf->output->x - surf_x,
3631 shsurf->output->y + panel_height - surf_y);
3633 case SHELL_SURFACE_POPUP:
3634 shell_map_popup(shsurf);
3636 case SHELL_SURFACE_NONE:
3637 weston_surface_set_position(surface,
3638 surface->geometry.x + sx,
3639 surface->geometry.y + sy);
3645 /* surface stacking order, see also activate() */
3646 switch (surface_type) {
3647 case SHELL_SURFACE_POPUP:
3648 case SHELL_SURFACE_TRANSIENT:
3649 parent = shsurf->parent;
3650 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
3652 case SHELL_SURFACE_FULLSCREEN:
3653 case SHELL_SURFACE_NONE:
3655 case SHELL_SURFACE_XWAYLAND:
3657 ws = get_current_workspace(shell);
3658 wl_list_insert(&ws->layer.surface_list, &surface->layer_link);
3662 if (surface_type != SHELL_SURFACE_NONE) {
3663 weston_surface_update_transform(surface);
3664 if (surface_type == SHELL_SURFACE_MAXIMIZED)
3665 surface->output = shsurf->output;
3668 switch (surface_type) {
3669 /* XXX: xwayland's using the same fields for transient type */
3670 case SHELL_SURFACE_XWAYLAND:
3671 case SHELL_SURFACE_TRANSIENT:
3672 if (shsurf->transient.flags ==
3673 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
3675 case SHELL_SURFACE_TOPLEVEL:
3676 case SHELL_SURFACE_FULLSCREEN:
3677 case SHELL_SURFACE_MAXIMIZED:
3678 if (!shell->locked) {
3679 wl_list_for_each(seat, &compositor->seat_list, link)
3680 activate(shell, surface, seat);
3687 if (surface_type == SHELL_SURFACE_TOPLEVEL)
3689 switch (shell->win_animation_type) {
3690 case ANIMATION_FADE:
3691 weston_fade_run(surface, 0.0, 1.0, 300.0, NULL, NULL);
3693 case ANIMATION_ZOOM:
3694 weston_zoom_run(surface, 0.5, 1.0, NULL, NULL);
3701 /* if ico_window_mgr hook, call hook routine */
3702 if (shell_hook_map) {
3703 (*shell_hook_map)(surface, &width, &height, &sx, &sy);
3705 if (shell_hook_configure) {
3706 (*shell_hook_configure)(surface); /* send event to manager */
3711 configure(struct desktop_shell *shell, struct weston_surface *surface,
3712 float x, float y, int32_t width, int32_t height)
3714 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
3715 struct shell_surface *shsurf;
3716 int32_t surf_x, surf_y;
3718 shsurf = get_shell_surface(surface);
3720 surface_type = shsurf->type;
3722 uifw_trace("configure: %08x x/y=%d/%d w/h=%d/%d",
3723 (int)surface, (int)x, (int)y, width, height);
3724 weston_surface_configure(surface, x, y, width, height);
3726 switch (surface_type) {
3727 case SHELL_SURFACE_FULLSCREEN:
3728 shell_stack_fullscreen(shsurf);
3729 shell_configure_fullscreen(shsurf);
3731 case SHELL_SURFACE_MAXIMIZED:
3732 /* setting x, y and using configure to change that geometry */
3733 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
3735 surface->geometry.x = surface->output->x - surf_x;
3736 surface->geometry.y = surface->output->y +
3737 get_output_panel_height(shell,surface->output) - surf_y;
3739 case SHELL_SURFACE_TOPLEVEL:
3745 /* XXX: would a fullscreen surface need the same handling? */
3746 if (surface->output) {
3747 weston_surface_update_transform(surface);
3749 if (surface_type == SHELL_SURFACE_MAXIMIZED)
3750 surface->output = shsurf->output;
3753 /* if ico_window_mgr hook, call hook routine */
3754 if (shell_hook_configure) {
3755 (*shell_hook_configure)(surface);
3760 shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
3762 struct shell_surface *shsurf = get_shell_surface(es);
3763 struct desktop_shell *shell = shsurf->shell;
3765 int type_changed = 0;
3767 if (!weston_surface_is_mapped(es) &&
3768 !wl_list_empty(&shsurf->popup.grab_link)) {
3769 remove_popup_grab(shsurf);
3775 if (shsurf->next_type != SHELL_SURFACE_NONE &&
3776 shsurf->type != shsurf->next_type) {
3777 set_surface_type(shsurf);
3781 if (!weston_surface_is_mapped(es)) {
3782 map(shell, es, width, height, sx, sy);
3783 } else if (type_changed || sx != 0 || sy != 0 ||
3784 es->geometry.width != width ||
3785 es->geometry.height != height) {
3786 float from_x, from_y;
3789 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
3790 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
3791 uifw_trace("shell_surface_configure: configure %08x x/y=%d/%d w/h=%d/%d",
3792 (int)es, (int)(es->geometry.x + to_x - from_x),
3793 (int)(es->geometry.y + to_y - from_y), width, height);
3794 configure(shell, es,
3795 es->geometry.x + to_x - from_x,
3796 es->geometry.y + to_y - from_y,
3801 static void launch_desktop_shell_process(void *data);
3804 desktop_shell_sigchld(struct weston_process *process, int status)
3807 struct desktop_shell *shell =
3808 container_of(process, struct desktop_shell, child.process);
3810 shell->child.process.pid = 0;
3811 shell->child.client = NULL; /* already destroyed by wayland */
3813 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
3814 time = weston_compositor_get_time();
3815 if (time - shell->child.deathstamp > 30000) {
3816 shell->child.deathstamp = time;
3817 shell->child.deathcount = 0;
3820 shell->child.deathcount++;
3821 if (shell->child.deathcount > 5) {
3822 weston_log("%s died, giving up.\n", shell_exe);
3826 weston_log("%s died, respawning...\n", shell_exe);
3827 launch_desktop_shell_process(shell);
3828 shell_fade_startup(shell);
3832 launch_desktop_shell_process(void *data)
3834 struct desktop_shell *shell = data;
3835 /* shell program path configurable for ico-ivi */
3836 /* const char *shell_exe = LIBEXECDIR "/weston-desktop-shell"; */
3838 if ((shell_exe[0] == 0) || (shell_exe[0] == ' ')) {
3839 weston_log("no shell program\n");
3842 shell->child.client = weston_client_launch(shell->compositor,
3843 &shell->child.process,
3845 desktop_shell_sigchld);
3847 if (!shell->child.client)
3848 weston_log("not able to start %s\n", shell_exe);
3850 weston_log("shell %s started\n", shell_exe);
3855 bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
3857 struct desktop_shell *shell = data;
3858 struct wl_resource *resource;
3860 resource = wl_resource_create(client, &wl_shell_interface, 1, id);
3862 wl_resource_set_implementation(resource, &shell_implementation,
3865 /* if ico_window_mgr hook, call hook routine */
3866 if (shell_hook_bind) {
3867 (*shell_hook_bind)(client, data);
3872 unbind_desktop_shell(struct wl_resource *resource)
3874 struct desktop_shell *shell = wl_resource_get_user_data(resource);
3876 /* if ico_window_mgr hook, call hook routine */
3877 if (shell_hook_unbind) {
3878 (*shell_hook_unbind)(resource->client);
3882 resume_desktop(shell);
3884 shell->child.desktop_shell = NULL;
3885 shell->prepare_event_sent = false;
3889 bind_desktop_shell(struct wl_client *client,
3890 void *data, uint32_t version, uint32_t id)
3892 struct desktop_shell *shell = data;
3893 struct wl_resource *resource;
3895 resource = wl_resource_create(client, &desktop_shell_interface,
3896 MIN(version, 2), id);
3898 if (client == shell->child.client) {
3899 wl_resource_set_implementation(resource,
3900 &desktop_shell_implementation,
3901 shell, unbind_desktop_shell);
3902 shell->child.desktop_shell = resource;
3905 shell_fade_startup(shell);
3910 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
3911 "permission to bind desktop_shell denied");
3912 wl_resource_destroy(resource);
3916 screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
3918 struct desktop_shell *shell = surface->configure_private;
3923 /* XXX: starting weston-screensaver beforehand does not work */
3927 center_on_output(surface, surface->output);
3929 if (wl_list_empty(&surface->layer_link)) {
3930 wl_list_insert(shell->lock_layer.surface_list.prev,
3931 &surface->layer_link);
3932 weston_surface_update_transform(surface);
3933 wl_event_source_timer_update(shell->screensaver.timer,
3934 shell->screensaver.duration);
3935 shell_fade(shell, FADE_IN);
3940 screensaver_set_surface(struct wl_client *client,
3941 struct wl_resource *resource,
3942 struct wl_resource *surface_resource,
3943 struct wl_resource *output_resource)
3945 struct desktop_shell *shell = wl_resource_get_user_data(resource);
3946 struct weston_surface *surface =
3947 wl_resource_get_user_data(surface_resource);
3948 struct weston_output *output = wl_resource_get_user_data(output_resource);
3950 surface->configure = screensaver_configure;
3951 surface->configure_private = shell;
3952 surface->output = output;
3955 static const struct screensaver_interface screensaver_implementation = {
3956 screensaver_set_surface
3960 unbind_screensaver(struct wl_resource *resource)
3962 struct desktop_shell *shell = wl_resource_get_user_data(resource);
3964 shell->screensaver.binding = NULL;
3968 bind_screensaver(struct wl_client *client,
3969 void *data, uint32_t version, uint32_t id)
3971 struct desktop_shell *shell = data;
3972 struct wl_resource *resource;
3974 resource = wl_resource_create(client, &screensaver_interface, 1, id);
3976 if (shell->screensaver.binding == NULL) {
3977 wl_resource_set_implementation(resource,
3978 &screensaver_implementation,
3979 shell, unbind_screensaver);
3980 shell->screensaver.binding = resource;
3984 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
3985 "interface object already bound");
3986 wl_resource_destroy(resource);
3990 input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
3992 struct input_panel_surface *ip_surface = surface->configure_private;
3993 struct desktop_shell *shell = ip_surface->shell;
3995 uint32_t show_surface = 0;
4000 if (!weston_surface_is_mapped(surface)) {
4001 if (!shell->showing_input_panels)
4007 fprintf(stderr, "%s panel: %d, output: %p\n", __FUNCTION__, ip_surface->panel, ip_surface->output);
4009 if (ip_surface->panel) {
4010 x = shell->text_input.surface->geometry.x + shell->text_input.cursor_rectangle.x2;
4011 y = shell->text_input.surface->geometry.y + shell->text_input.cursor_rectangle.y2;
4013 x = ip_surface->output->x + (ip_surface->output->width - width) / 2;
4014 y = ip_surface->output->y + ip_surface->output->height - height;
4017 uifw_trace("input_panel_configure: configure %08x x/y=%d/%d w/h=%d/%d",
4018 (int)surface, (int)x, (int)y, width, height);
4019 weston_surface_configure(surface,
4024 wl_list_insert(&shell->input_panel_layer.surface_list,
4025 &surface->layer_link);
4026 weston_surface_update_transform(surface);
4027 weston_surface_damage(surface);
4028 weston_slide_run(surface, surface->geometry.height, 0, NULL, NULL);
4033 destroy_input_panel_surface(struct input_panel_surface *input_panel_surface)
4035 wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface);
4037 wl_list_remove(&input_panel_surface->surface_destroy_listener.link);
4038 wl_list_remove(&input_panel_surface->link);
4040 input_panel_surface->surface->configure = NULL;
4042 free(input_panel_surface);
4045 static struct input_panel_surface *
4046 get_input_panel_surface(struct weston_surface *surface)
4048 if (surface->configure == input_panel_configure) {
4049 return surface->configure_private;
4056 input_panel_handle_surface_destroy(struct wl_listener *listener, void *data)
4058 struct input_panel_surface *ipsurface = container_of(listener,
4059 struct input_panel_surface,
4060 surface_destroy_listener);
4062 if (ipsurface->resource) {
4063 wl_resource_destroy(ipsurface->resource);
4065 destroy_input_panel_surface(ipsurface);
4069 static struct input_panel_surface *
4070 create_input_panel_surface(struct desktop_shell *shell,
4071 struct weston_surface *surface)
4073 struct input_panel_surface *input_panel_surface;
4075 input_panel_surface = calloc(1, sizeof *input_panel_surface);
4076 if (!input_panel_surface)
4079 surface->configure = input_panel_configure;
4080 surface->configure_private = input_panel_surface;
4082 input_panel_surface->shell = shell;
4084 input_panel_surface->surface = surface;
4086 wl_signal_init(&input_panel_surface->destroy_signal);
4087 input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy;
4088 wl_signal_add(&surface->destroy_signal,
4089 &input_panel_surface->surface_destroy_listener);
4091 wl_list_init(&input_panel_surface->link);
4093 return input_panel_surface;
4097 input_panel_surface_set_toplevel(struct wl_client *client,
4098 struct wl_resource *resource,
4099 struct wl_resource *output_resource,
4102 struct input_panel_surface *input_panel_surface =
4103 wl_resource_get_user_data(resource);
4104 struct desktop_shell *shell = input_panel_surface->shell;
4106 wl_list_insert(&shell->input_panel.surfaces,
4107 &input_panel_surface->link);
4109 input_panel_surface->output = wl_resource_get_user_data(output_resource);
4110 input_panel_surface->panel = 0;
4114 input_panel_surface_set_overlay_panel(struct wl_client *client,
4115 struct wl_resource *resource)
4117 struct input_panel_surface *input_panel_surface =
4118 wl_resource_get_user_data(resource);
4119 struct desktop_shell *shell = input_panel_surface->shell;
4121 wl_list_insert(&shell->input_panel.surfaces,
4122 &input_panel_surface->link);
4124 input_panel_surface->panel = 1;
4127 static const struct wl_input_panel_surface_interface input_panel_surface_implementation = {
4128 input_panel_surface_set_toplevel,
4129 input_panel_surface_set_overlay_panel
4133 destroy_input_panel_surface_resource(struct wl_resource *resource)
4135 struct input_panel_surface *ipsurf =
4136 wl_resource_get_user_data(resource);
4138 destroy_input_panel_surface(ipsurf);
4142 input_panel_get_input_panel_surface(struct wl_client *client,
4143 struct wl_resource *resource,
4145 struct wl_resource *surface_resource)
4147 struct weston_surface *surface =
4148 wl_resource_get_user_data(surface_resource);
4149 struct desktop_shell *shell = wl_resource_get_user_data(resource);
4150 struct input_panel_surface *ipsurf;
4152 if (get_input_panel_surface(surface)) {
4153 wl_resource_post_error(surface_resource,
4154 WL_DISPLAY_ERROR_INVALID_OBJECT,
4155 "wl_input_panel::get_input_panel_surface already requested");
4159 ipsurf = create_input_panel_surface(shell, surface);
4161 wl_resource_post_error(surface_resource,
4162 WL_DISPLAY_ERROR_INVALID_OBJECT,
4163 "surface->configure already set");
4168 wl_resource_create(client,
4169 &wl_input_panel_surface_interface, 1, id);
4170 wl_resource_set_implementation(ipsurf->resource,
4171 &input_panel_surface_implementation,
4173 destroy_input_panel_surface_resource);
4176 static const struct wl_input_panel_interface input_panel_implementation = {
4177 input_panel_get_input_panel_surface
4181 unbind_input_panel(struct wl_resource *resource)
4183 struct desktop_shell *shell = wl_resource_get_user_data(resource);
4185 shell->input_panel.binding = NULL;
4189 bind_input_panel(struct wl_client *client,
4190 void *data, uint32_t version, uint32_t id)
4192 struct desktop_shell *shell = data;
4193 struct wl_resource *resource;
4195 resource = wl_resource_create(client,
4196 &wl_input_panel_interface, 1, id);
4198 if (shell->input_panel.binding == NULL) {
4199 wl_resource_set_implementation(resource,
4200 &input_panel_implementation,
4201 shell, unbind_input_panel);
4202 shell->input_panel.binding = resource;
4206 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
4207 "interface object already bound");
4208 wl_resource_destroy(resource);
4212 struct desktop_shell *shell;
4213 struct weston_surface *current;
4214 struct wl_listener listener;
4215 struct weston_keyboard_grab grab;
4219 switcher_next(struct switcher *switcher)
4221 struct weston_surface *surface;
4222 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
4223 struct shell_surface *shsurf;
4224 struct workspace *ws = get_current_workspace(switcher->shell);
4226 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
4227 switch (get_shell_surface_type(surface)) {
4228 case SHELL_SURFACE_TOPLEVEL:
4229 case SHELL_SURFACE_FULLSCREEN:
4230 case SHELL_SURFACE_MAXIMIZED:
4233 if (prev == switcher->current)
4236 surface->alpha = 0.25;
4237 weston_surface_geometry_dirty(surface);
4238 weston_surface_damage(surface);
4244 if (is_black_surface(surface, NULL)) {
4245 surface->alpha = 0.25;
4246 weston_surface_geometry_dirty(surface);
4247 weston_surface_damage(surface);
4257 wl_list_remove(&switcher->listener.link);
4258 wl_signal_add(&next->destroy_signal, &switcher->listener);
4260 switcher->current = next;
4263 shsurf = get_shell_surface(switcher->current);
4264 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
4265 shsurf->fullscreen.black_surface->alpha = 1.0;
4269 switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
4271 struct switcher *switcher =
4272 container_of(listener, struct switcher, listener);
4274 switcher_next(switcher);
4278 switcher_destroy(struct switcher *switcher)
4280 struct weston_surface *surface;
4281 struct weston_keyboard *keyboard = switcher->grab.keyboard;
4282 struct workspace *ws = get_current_workspace(switcher->shell);
4284 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
4285 surface->alpha = 1.0;
4286 weston_surface_damage(surface);
4289 if (switcher->current)
4290 activate(switcher->shell, switcher->current,
4291 (struct weston_seat *) keyboard->seat);
4292 wl_list_remove(&switcher->listener.link);
4293 weston_keyboard_end_grab(keyboard);
4294 if (keyboard->input_method_resource)
4295 keyboard->grab = &keyboard->input_method_grab;
4300 switcher_key(struct weston_keyboard_grab *grab,
4301 uint32_t time, uint32_t key, uint32_t state_w)
4303 struct switcher *switcher = container_of(grab, struct switcher, grab);
4304 enum wl_keyboard_key_state state = state_w;
4306 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
4307 switcher_next(switcher);
4311 switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
4312 uint32_t mods_depressed, uint32_t mods_latched,
4313 uint32_t mods_locked, uint32_t group)
4315 struct switcher *switcher = container_of(grab, struct switcher, grab);
4316 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
4318 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0)
4319 switcher_destroy(switcher);
4322 static const struct weston_keyboard_grab_interface switcher_grab = {
4328 switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
4331 struct desktop_shell *shell = data;
4332 struct switcher *switcher;
4334 switcher = malloc(sizeof *switcher);
4335 switcher->shell = shell;
4336 switcher->current = NULL;
4337 switcher->listener.notify = switcher_handle_surface_destroy;
4338 wl_list_init(&switcher->listener.link);
4340 restore_all_output_modes(shell->compositor);
4341 lower_fullscreen_layer(switcher->shell);
4342 switcher->grab.interface = &switcher_grab;
4343 weston_keyboard_start_grab(seat->keyboard, &switcher->grab);
4344 weston_keyboard_set_focus(seat->keyboard, NULL);
4345 switcher_next(switcher);
4349 backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
4352 struct weston_compositor *compositor = data;
4353 struct weston_output *output;
4354 long backlight_new = 0;
4356 /* TODO: we're limiting to simple use cases, where we assume just
4357 * control on the primary display. We'd have to extend later if we
4358 * ever get support for setting backlights on random desktop LCD
4360 output = get_default_output(compositor);
4364 if (!output->set_backlight)
4367 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
4368 backlight_new = output->backlight_current - 25;
4369 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
4370 backlight_new = output->backlight_current + 25;
4372 if (backlight_new < 5)
4374 if (backlight_new > 255)
4375 backlight_new = 255;
4377 output->backlight_current = backlight_new;
4378 output->set_backlight(output, output->backlight_current);
4381 struct debug_binding_grab {
4382 struct weston_keyboard_grab grab;
4383 struct weston_seat *seat;
4385 int key_released[2];
4389 debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
4390 uint32_t key, uint32_t state)
4392 struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
4393 struct wl_resource *resource;
4394 struct wl_display *display;
4396 int send = 0, terminate = 0;
4397 int check_binding = 1;
4400 if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
4401 /* Do not run bindings on key releases */
4404 for (i = 0; i < 2; i++)
4405 if (key == db->key[i])
4406 db->key_released[i] = 1;
4408 if (db->key_released[0] && db->key_released[1]) {
4409 /* All key releases been swalled so end the grab */
4411 } else if (key != db->key[0] && key != db->key[1]) {
4412 /* Should not swallow release of other keys */
4415 } else if (key == db->key[0] && !db->key_released[0]) {
4416 /* Do not check bindings for the first press of the binding
4417 * key. This allows it to be used as a debug shortcut.
4418 * We still need to swallow this event. */
4420 } else if (db->key[1]) {
4421 /* If we already ran a binding don't process another one since
4422 * we can't keep track of all the binding keys that were
4423 * pressed in order to swallow the release events. */
4428 if (check_binding) {
4429 struct weston_compositor *ec = db->seat->compositor;
4431 if (weston_compositor_run_debug_binding(ec, db->seat, time,
4433 /* We ran a binding so swallow the press and keep the
4434 * grab to swallow the released too. */
4439 /* Terminate the grab since the key pressed is not a
4440 * debug binding key. */
4447 resource = grab->keyboard->focus_resource;
4450 display = wl_client_get_display(wl_resource_get_client(resource));
4451 serial = wl_display_next_serial(display);
4452 wl_keyboard_send_key(resource, serial, time, key, state);
4457 weston_keyboard_end_grab(grab->keyboard);
4458 if (grab->keyboard->input_method_resource)
4459 grab->keyboard->grab = &grab->keyboard->input_method_grab;
4465 debug_binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial,
4466 uint32_t mods_depressed, uint32_t mods_latched,
4467 uint32_t mods_locked, uint32_t group)
4469 struct wl_resource *resource;
4471 resource = grab->keyboard->focus_resource;
4475 wl_keyboard_send_modifiers(resource, serial, mods_depressed,
4476 mods_latched, mods_locked, group);
4479 struct weston_keyboard_grab_interface debug_binding_keyboard_grab = {
4481 debug_binding_modifiers
4485 debug_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
4487 struct debug_binding_grab *grab;
4489 grab = calloc(1, sizeof *grab);
4493 grab->seat = (struct weston_seat *) seat;
4495 grab->grab.interface = &debug_binding_keyboard_grab;
4496 weston_keyboard_start_grab(seat->keyboard, &grab->grab);
4500 force_kill_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
4503 struct weston_surface *focus_surface;
4504 struct wl_client *client;
4505 struct desktop_shell *shell = data;
4506 struct weston_compositor *compositor = shell->compositor;
4509 focus_surface = seat->keyboard->focus;
4513 wl_signal_emit(&compositor->kill_signal, focus_surface);
4515 client = wl_resource_get_client(focus_surface->resource);
4516 wl_client_get_credentials(client, &pid, NULL, NULL);
4518 /* Skip clients that we launched ourselves (the credentials of
4519 * the socketpair is ours) */
4520 if (pid == getpid())
4527 workspace_up_binding(struct weston_seat *seat, uint32_t time,
4528 uint32_t key, void *data)
4530 struct desktop_shell *shell = data;
4531 unsigned int new_index = shell->workspaces.current;
4538 change_workspace(shell, new_index);
4542 workspace_down_binding(struct weston_seat *seat, uint32_t time,
4543 uint32_t key, void *data)
4545 struct desktop_shell *shell = data;
4546 unsigned int new_index = shell->workspaces.current;
4550 if (new_index < shell->workspaces.num - 1)
4553 change_workspace(shell, new_index);
4557 workspace_f_binding(struct weston_seat *seat, uint32_t time,
4558 uint32_t key, void *data)
4560 struct desktop_shell *shell = data;
4561 unsigned int new_index;
4565 new_index = key - KEY_F1;
4566 if (new_index >= shell->workspaces.num)
4567 new_index = shell->workspaces.num - 1;
4569 change_workspace(shell, new_index);
4573 workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time,
4574 uint32_t key, void *data)
4576 struct desktop_shell *shell = data;
4577 unsigned int new_index = shell->workspaces.current;
4585 take_surface_to_workspace_by_seat(shell, seat, new_index);
4589 workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time,
4590 uint32_t key, void *data)
4592 struct desktop_shell *shell = data;
4593 unsigned int new_index = shell->workspaces.current;
4598 if (new_index < shell->workspaces.num - 1)
4601 take_surface_to_workspace_by_seat(shell, seat, new_index);
4605 shell_destroy(struct wl_listener *listener, void *data)
4607 struct desktop_shell *shell =
4608 container_of(listener, struct desktop_shell, destroy_listener);
4609 struct workspace **ws;
4611 if (shell->child.client)
4612 wl_client_destroy(shell->child.client);
4614 wl_list_remove(&shell->idle_listener.link);
4615 wl_list_remove(&shell->wake_listener.link);
4616 wl_list_remove(&shell->show_input_panel_listener.link);
4617 wl_list_remove(&shell->hide_input_panel_listener.link);
4619 wl_array_for_each(ws, &shell->workspaces.array)
4620 workspace_destroy(*ws);
4621 wl_array_release(&shell->workspaces.array);
4623 free(shell->screensaver.path);
4628 shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
4631 int i, num_workspace_bindings;
4633 /* fixed bindings */
4634 weston_compositor_add_key_binding(ec, KEY_BACKSPACE,
4635 MODIFIER_CTRL | MODIFIER_ALT,
4636 terminate_binding, ec);
4637 weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
4638 click_to_activate_binding,
4640 weston_compositor_add_button_binding(ec, BTN_TOUCH, 0,
4641 click_to_activate_binding,
4643 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
4644 MODIFIER_SUPER | MODIFIER_ALT,
4645 surface_opacity_binding, NULL);
4646 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
4647 MODIFIER_SUPER, zoom_axis_binding,
4650 /* configurable bindings */
4651 mod = shell->binding_modifier;
4652 weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod,
4653 zoom_key_binding, NULL);
4654 weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod,
4655 zoom_key_binding, NULL);
4656 weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding,
4658 weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod,
4659 resize_binding, shell);
4661 if (ec->capabilities & WESTON_CAP_ROTATION_ANY)
4662 weston_compositor_add_button_binding(ec, BTN_RIGHT, mod,
4663 rotate_binding, NULL);
4665 weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding,
4667 weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding,
4669 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0,
4670 backlight_binding, ec);
4671 weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding,
4673 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0,
4674 backlight_binding, ec);
4675 weston_compositor_add_key_binding(ec, KEY_K, mod,
4676 force_kill_binding, shell);
4677 weston_compositor_add_key_binding(ec, KEY_UP, mod,
4678 workspace_up_binding, shell);
4679 weston_compositor_add_key_binding(ec, KEY_DOWN, mod,
4680 workspace_down_binding, shell);
4681 weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT,
4682 workspace_move_surface_up_binding,
4684 weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT,
4685 workspace_move_surface_down_binding,
4688 /* Add bindings for mod+F[1-6] for workspace 1 to 6. */
4689 if (shell->workspaces.num > 1) {
4690 num_workspace_bindings = shell->workspaces.num;
4691 if (num_workspace_bindings > 6)
4692 num_workspace_bindings = 6;
4693 for (i = 0; i < num_workspace_bindings; i++)
4694 weston_compositor_add_key_binding(ec, KEY_F1 + i, mod,
4695 workspace_f_binding,
4699 /* Debug bindings */
4700 weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT,
4701 debug_binding, shell);
4705 module_init(struct weston_compositor *ec,
4706 int *argc, char *argv[])
4708 struct weston_seat *seat;
4709 struct desktop_shell *shell;
4710 struct workspace **pws;
4712 struct wl_event_loop *loop;
4714 shell = malloc(sizeof *shell);
4718 /* save shell management table for other plugin */
4719 _ico_ivi_shell = shell;
4721 memset(shell, 0, sizeof *shell);
4722 shell->compositor = ec;
4724 shell->destroy_listener.notify = shell_destroy;
4725 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
4726 shell->idle_listener.notify = idle_handler;
4727 wl_signal_add(&ec->idle_signal, &shell->idle_listener);
4728 shell->wake_listener.notify = wake_handler;
4729 wl_signal_add(&ec->wake_signal, &shell->wake_listener);
4730 shell->show_input_panel_listener.notify = show_input_panels;
4731 wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener);
4732 shell->hide_input_panel_listener.notify = hide_input_panels;
4733 wl_signal_add(&ec->hide_input_panel_signal, &shell->hide_input_panel_listener);
4734 shell->update_input_panel_listener.notify = update_input_panels;
4735 wl_signal_add(&ec->update_input_panel_signal, &shell->update_input_panel_listener);
4736 ec->ping_handler = ping_handler;
4737 ec->shell_interface.shell = shell;
4738 ec->shell_interface.create_shell_surface = create_shell_surface;
4739 ec->shell_interface.set_toplevel = set_toplevel;
4740 ec->shell_interface.set_transient = set_transient;
4741 ec->shell_interface.set_fullscreen = set_fullscreen;
4742 ec->shell_interface.set_xwayland = set_xwayland;
4743 ec->shell_interface.move = surface_move;
4744 ec->shell_interface.resize = surface_resize;
4746 wl_list_init(&shell->input_panel.surfaces);
4748 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
4749 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
4750 weston_layer_init(&shell->background_layer, &shell->panel_layer.link);
4751 weston_layer_init(&shell->lock_layer, NULL);
4752 weston_layer_init(&shell->input_panel_layer, NULL);
4754 wl_array_init(&shell->workspaces.array);
4755 wl_list_init(&shell->workspaces.client_list);
4757 shell_configuration(shell);
4759 for (i = 0; i < shell->workspaces.num; i++) {
4760 pws = wl_array_add(&shell->workspaces.array, sizeof *pws);
4764 *pws = workspace_create();
4768 activate_workspace(shell, 0);
4770 wl_list_init(&shell->workspaces.anim_sticky_list);
4771 wl_list_init(&shell->workspaces.animation.link);
4772 shell->workspaces.animation.frame = animate_workspace_change_frame;
4774 if (wl_global_create(ec->wl_display, &wl_shell_interface, 1,
4775 shell, bind_shell) == NULL)
4778 if (wl_global_create(ec->wl_display,
4779 &desktop_shell_interface, 2,
4780 shell, bind_desktop_shell) == NULL)
4783 if (wl_global_create(ec->wl_display, &screensaver_interface, 1,
4784 shell, bind_screensaver) == NULL)
4787 if (wl_global_create(ec->wl_display, &wl_input_panel_interface, 1,
4788 shell, bind_input_panel) == NULL)
4791 if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1,
4792 shell, bind_workspace_manager) == NULL)
4795 shell->child.deathstamp = weston_compositor_get_time();
4797 loop = wl_display_get_event_loop(ec->wl_display);
4798 wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell);
4800 shell->screensaver.timer =
4801 wl_event_loop_add_timer(loop, screensaver_timeout, shell);
4803 wl_list_for_each(seat, &ec->seat_list, link)
4804 create_pointer_focus_listener(seat);
4806 shell_add_bindings(ec, shell);
4808 shell_fade_init(shell);
4813 /*--------------------------------------------------------------------------*/
4815 * @brief ico_ivi_shell_current_layer: get current weston layer
4818 * @return current weston layer
4819 * @retval !=NULL success(current weston layer)
4820 * @retval ==NULL error(no layer)
4822 /*--------------------------------------------------------------------------*/
4823 /* API for other plugin */
4824 WL_EXPORT struct weston_layer *
4825 ico_ivi_shell_current_layer(void)
4827 struct workspace *ws = get_current_workspace(_ico_ivi_shell);
4829 return (ws != NULL) ? &ws->layer : NULL;
4832 /*--------------------------------------------------------------------------*/
4834 * @brief ico_ivi_shell_set_toplevel: set surface to TopLevel
4836 * @param[in] shsurf shell surface
4839 /*--------------------------------------------------------------------------*/
4841 ico_ivi_shell_set_toplevel(struct shell_surface *shsurf)
4843 set_toplevel(shsurf);
4846 /*--------------------------------------------------------------------------*/
4848 * @brief ico_ivi_shell_set_surface_type: set surface type
4850 * @param[in] shsurf shell surface
4853 /*--------------------------------------------------------------------------*/
4855 ico_ivi_shell_set_surface_type(struct shell_surface *shsurf)
4857 set_surface_type(shsurf);
4860 /*--------------------------------------------------------------------------*/
4862 * @brief ico_ivi_shell_send_configure: send configure event to client application
4864 * @param[in] surface weston surface
4865 * @param[in] edges surface resize position
4866 * @param[in] width surface width
4867 * @param[in] height surface height
4870 /*--------------------------------------------------------------------------*/
4872 ico_ivi_shell_send_configure(struct weston_surface *surface,
4873 const uint32_t edges, const int width, const int height)
4875 send_configure(surface, edges, width, height);
4878 /*--------------------------------------------------------------------------*/
4880 * @brief ico_ivi_shell_startup: start shell surface fade
4882 * @param[in] shell shell table address
4885 /*--------------------------------------------------------------------------*/
4887 ico_ivi_shell_startup(void *shell)
4889 shell_fade_startup((struct desktop_shell *)shell);
4892 /*--------------------------------------------------------------------------*/
4894 * @brief ico_ivi_shell_hook_bind: regist hook function for shell bind
4896 * @param[in] hook_bind hook function(if NULL, reset hook function)
4899 /*--------------------------------------------------------------------------*/
4901 ico_ivi_shell_hook_bind(void (*hook_bind)(struct wl_client *client, void *shell))
4903 shell_hook_bind = hook_bind;
4906 /*--------------------------------------------------------------------------*/
4908 * @brief ico_ivi_shell_hook_unbind: regist hook function for shell unbind
4910 * @param[in] hook_unbind hook function(if NULL, reset hook function)
4913 /*--------------------------------------------------------------------------*/
4915 ico_ivi_shell_hook_unbind(void (*hook_unbind)(struct wl_client *client))
4917 shell_hook_unbind = hook_unbind;
4920 /*--------------------------------------------------------------------------*/
4922 * @brief ico_ivi_shell_hook_create: regist hook function for create shell surface
4924 * @param[in] hook_create hook function(if NULL, reset hook function)
4927 /*--------------------------------------------------------------------------*/
4929 ico_ivi_shell_hook_create(void (*hook_create)(struct wl_client *client,
4930 struct wl_resource *resource,
4931 struct weston_surface *surface,
4932 struct shell_surface *shsurf))
4934 shell_hook_create = hook_create;
4937 /*--------------------------------------------------------------------------*/
4939 * @brief ico_ivi_shell_hook_destroy: regist hook function for destroy shell surface
4941 * @param[in] hook_destroy hook function(if NULL, reset hook function)
4944 /*--------------------------------------------------------------------------*/
4946 ico_ivi_shell_hook_destroy(void (*hook_destroy)(struct weston_surface *surface))
4948 shell_hook_destroy = hook_destroy;
4951 /*--------------------------------------------------------------------------*/
4953 * @brief ico_ivi_shell_hook_map: regist hook function for map shell surface
4955 * @param[in] hook_map hook function(if NULL, reset hook function)
4958 /*--------------------------------------------------------------------------*/
4960 ico_ivi_shell_hook_map(void (*hook_map)(struct weston_surface *surface,
4961 int32_t *width, int32_t *height,
4962 int32_t *sx, int32_t *sy))
4964 shell_hook_map = hook_map;
4967 /*--------------------------------------------------------------------------*/
4969 * @brief ico_ivi_shell_hook_configure: regist hook function for configure shell surface
4971 * @param[in] hook_configure hook function(if NULL, reset hook function)
4974 /*--------------------------------------------------------------------------*/
4976 ico_ivi_shell_hook_configure(void (*hook_configure)(struct weston_surface *surface))
4978 shell_hook_configure = hook_configure;
4981 /*--------------------------------------------------------------------------*/
4983 * @brief ico_ivi_shell_hook_select: regist hook function for select(active) shell surface
4985 * @param[in] hook_select hook function(if NULL, reset hook function)
4988 /*--------------------------------------------------------------------------*/
4990 ico_ivi_shell_hook_select(void (*hook_select)(struct weston_surface *surface))
4992 shell_hook_select = hook_select;
4995 /*--------------------------------------------------------------------------*/
4997 * @brief ico_ivi_shell_hook_title: regist hook function for select(active) shell surface
4999 * @param[in] hook_title hook function(if NULL, reset hook function)
5002 /*--------------------------------------------------------------------------*/
5004 ico_ivi_shell_hook_title(void (*hook_title)(struct weston_surface *surface,
5007 shell_hook_title = hook_title;
5010 /*--------------------------------------------------------------------------*/
5012 * @brief ico_ivi_shell_hook_move: regist hook function for move grab
5014 * @param[in] hook_move hook function(if NULL, reset hook function)
5015 * @param[in/out] dx new X coordinate
5016 * @param[in/out] dy new Y coordinate
5019 /*--------------------------------------------------------------------------*/
5021 ico_ivi_shell_hook_move(void (*hook_move)(struct weston_surface *surface, int *dx, int *dy))
5023 shell_hook_move = hook_move;