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_private.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;
167 enum animation_type startup_animation_type;
170 #if 0 /* move to ico_ivi_shell.h */
171 enum shell_surface_type {
173 SHELL_SURFACE_TOPLEVEL,
174 SHELL_SURFACE_TRANSIENT,
175 SHELL_SURFACE_FULLSCREEN,
176 SHELL_SURFACE_MAXIMIZED,
178 SHELL_SURFACE_XWAYLAND
183 struct wl_event_source *source;
187 struct shell_surface {
188 struct wl_resource *resource;
189 struct wl_signal destroy_signal;
191 struct weston_surface *surface;
192 struct wl_listener surface_destroy_listener;
193 struct weston_surface *parent;
194 struct desktop_shell *shell;
196 enum shell_surface_type type, next_type;
198 int32_t saved_x, saved_y;
199 bool saved_position_valid;
200 bool saved_rotation_valid;
201 char layertype; /* surface layer type */
205 struct weston_transform transform;
206 struct weston_matrix rotation;
210 struct wl_list grab_link;
212 struct shell_seat *shseat;
222 enum wl_shell_surface_fullscreen_method type;
223 struct weston_transform transform; /* matrix from x, y */
225 struct weston_surface *black_surface;
228 struct ping_timer *ping_timer;
230 struct weston_transform workspace_transform;
232 struct weston_output *fullscreen_output;
233 struct weston_output *output;
236 const struct weston_shell_client *client;
240 struct weston_pointer_grab grab;
241 struct shell_surface *shsurf;
242 struct wl_listener shsurf_destroy_listener;
245 struct shell_touch_grab {
246 struct weston_touch_grab grab;
247 struct shell_surface *shsurf;
248 struct wl_listener shsurf_destroy_listener;
249 struct weston_touch *touch;
252 struct weston_move_grab {
253 struct shell_grab base;
257 struct weston_touch_move_grab {
258 struct shell_touch_grab base;
263 struct shell_grab base;
264 struct weston_matrix rotation;
272 struct weston_seat *seat;
273 struct wl_listener seat_destroy_listener;
276 struct weston_pointer_grab grab;
277 struct wl_list surfaces_list;
278 struct wl_client *client;
284 activate(struct desktop_shell *shell, struct weston_surface *es,
285 struct weston_seat *seat);
287 static struct workspace *
288 get_current_workspace(struct desktop_shell *shell);
290 static struct shell_surface *
291 get_shell_surface(struct weston_surface *surface);
293 static struct desktop_shell *
294 shell_surface_get_shell(struct shell_surface *shsurf);
297 surface_rotate(struct shell_surface *surface, struct weston_seat *seat);
300 shell_fade_startup(struct desktop_shell *shell);
302 /* shell management table */
303 static struct desktop_shell *_ico_ivi_shell = NULL;
305 /* shell program path for ico-ivi */
306 static char *shell_exe = NULL;
307 #define DEFAULT_DEBUG_LEVEL 4
308 static int ico_debug_level = DEFAULT_DEBUG_LEVEL; /* Debug Level */
310 /* default display */
311 static struct weston_output *default_inputpanel = NULL;
313 /* debug log macros */
314 #define uifw_debug(fmt,...) \
315 { if (ico_debug_level >= 5) {weston_log("DBG>"fmt" (%s:%d)\n",##__VA_ARGS__,__FILE__,__LINE__);} }
316 #define uifw_trace(fmt,...) \
317 { if (ico_debug_level >= 4) {weston_log("TRC>"fmt" (%s:%d)\n",##__VA_ARGS__,__FILE__,__LINE__);} }
318 #define uifw_info(fmt,...) \
319 { if (ico_debug_level >= 3) {weston_log("INF>"fmt" (%s:%d)\n",##__VA_ARGS__,__FILE__,__LINE__);} }
320 #define uifw_warn(fmt,...) \
321 { if (ico_debug_level >= 2) {weston_log("WRN>"fmt" (%s:%d)\n",##__VA_ARGS__,__FILE__,__LINE__);} }
322 #define uifw_error(fmt,...) \
323 { if (ico_debug_level >= 1) {weston_log("ERR>"fmt" (%s:%d)\n",##__VA_ARGS__,__FILE__,__LINE__);} }
326 static void (*shell_hook_bind)(struct wl_client *client, void *shell) = NULL;
327 static void (*shell_hook_unbind)(struct wl_client *client) = NULL;
328 static void (*shell_hook_create)(int layertype,
329 struct wl_client *client, struct wl_resource *resource,
330 struct weston_surface *surface,
331 struct shell_surface *shsurf) = NULL;
332 static void (*shell_hook_destroy)(struct weston_surface *surface) = NULL;
333 static void (*shell_hook_map)(struct weston_surface *surface, int32_t *width,
334 int32_t *height, int32_t *sx, int32_t *sy) = NULL;
335 static void (*shell_hook_configure)(struct weston_surface *surface) = NULL;
336 static void (*shell_hook_select)(struct weston_surface *surface) = NULL;
337 static char *(*shell_hook_title)(struct weston_surface *surface, const char *title) = NULL;
338 static void (*shell_hook_move)(struct weston_surface *surface, int *dx, int *dy) = NULL;
339 static void (*shell_hook_show_layer)(int layertype, int show, void *data) = NULL;
340 static int (*shell_hook_fullscreen)(int event, struct weston_surface *surface) = NULL;
343 shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
345 if (shell_hook_fullscreen) {
346 return (*shell_hook_fullscreen)(SHELL_FULLSCREEN_ISTOP, shsurf->surface);
349 struct desktop_shell *shell;
350 struct weston_surface *top_fs_es;
352 shell = shell_surface_get_shell(shsurf);
354 uifw_debug("shell_surface_is_top_fullscreen: ");
355 if (wl_list_empty(&shell->fullscreen_layer.surface_list))
358 top_fs_es = container_of(shell->fullscreen_layer.surface_list.next,
359 struct weston_surface,
361 return (shsurf == get_shell_surface(top_fs_es));
365 destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
367 struct shell_grab *grab;
369 grab = container_of(listener, struct shell_grab,
370 shsurf_destroy_listener);
376 popup_grab_end(struct weston_pointer *pointer);
379 shell_grab_start(struct shell_grab *grab,
380 const struct weston_pointer_grab_interface *interface,
381 struct shell_surface *shsurf,
382 struct weston_pointer *pointer,
383 enum desktop_shell_cursor cursor)
385 struct desktop_shell *shell = shsurf->shell;
387 /* if ico_window_mgr hook, not change grab */
388 if (shell_hook_select) {
392 popup_grab_end(pointer);
394 grab->grab.interface = interface;
395 grab->shsurf = shsurf;
396 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
397 wl_signal_add(&shsurf->destroy_signal,
398 &grab->shsurf_destroy_listener);
400 weston_pointer_start_grab(pointer, &grab->grab);
401 if (shell->child.desktop_shell) {
402 desktop_shell_send_grab_cursor(shell->child.desktop_shell,
404 weston_pointer_set_focus(pointer, shell->grab_surface,
405 wl_fixed_from_int(0),
406 wl_fixed_from_int(0));
411 shell_grab_end(struct shell_grab *grab)
414 wl_list_remove(&grab->shsurf_destroy_listener.link);
416 weston_pointer_end_grab(grab->grab.pointer);
420 shell_touch_grab_start(struct shell_touch_grab *grab,
421 const struct weston_touch_grab_interface *interface,
422 struct shell_surface *shsurf,
423 struct weston_touch *touch)
425 struct desktop_shell *shell = shsurf->shell;
427 grab->grab.interface = interface;
428 grab->shsurf = shsurf;
429 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
430 wl_signal_add(&shsurf->destroy_signal,
431 &grab->shsurf_destroy_listener);
435 weston_touch_start_grab(touch, &grab->grab);
436 if (shell->child.desktop_shell)
437 weston_touch_set_focus(touch->seat, shell->grab_surface);
441 shell_touch_grab_end(struct shell_touch_grab *grab)
444 wl_list_remove(&grab->shsurf_destroy_listener.link);
446 weston_touch_end_grab(grab->touch);
450 center_on_output(struct weston_surface *surface,
451 struct weston_output *output);
453 static enum weston_keyboard_modifier
454 get_modifier(char *modifier)
457 return MODIFIER_SUPER;
459 if (!strcmp("ctrl", modifier))
460 return MODIFIER_CTRL;
461 else if (!strcmp("alt", modifier))
463 else if (!strcmp("super", modifier))
464 return MODIFIER_SUPER;
466 return MODIFIER_SUPER;
469 static enum animation_type
470 get_animation_type(char *animation)
472 if (!strcmp("zoom", animation))
473 return ANIMATION_ZOOM;
474 else if (!strcmp("fade", animation))
475 return ANIMATION_FADE;
477 return ANIMATION_NONE;
481 shell_configuration(struct desktop_shell *shell)
483 struct weston_config_section *section;
487 section = weston_config_get_section(shell->compositor->config,
488 "screensaver", NULL, NULL);
489 weston_config_section_get_string(section,
490 "path", &shell->screensaver.path, NULL);
491 weston_config_section_get_int(section, "duration", &duration, 60);
492 shell->screensaver.duration = duration * 1000;
494 section = weston_config_get_section(shell->compositor->config,
495 "shell", NULL, NULL);
496 weston_config_section_get_string(section,
497 "binding-modifier", &s, "super");
498 shell->binding_modifier = get_modifier(s);
500 weston_config_section_get_string(section, "animation", &s, "none");
501 shell->win_animation_type = get_animation_type(s);
503 weston_config_section_get_string(section,
504 "startup-animation", &s, "fade");
505 shell->startup_animation_type = get_animation_type(s);
507 if (shell->startup_animation_type == ANIMATION_ZOOM)
508 shell->startup_animation_type = ANIMATION_NONE;
510 weston_config_section_get_uint(section, "num-workspaces",
511 &shell->workspaces.num,
512 DEFAULT_NUM_WORKSPACES);
513 /* shell program path for ico-ivi */
514 weston_config_section_get_string(section, "shell-exe", &shell_exe,
515 LIBEXECDIR "/weston-desktop-shell");
516 weston_log("ws=%d exe=%s\n", shell->workspaces.num, shell_exe);
518 /* get debug level for ivi debug */
519 section = weston_config_get_section(shell->compositor->config, "ivi-option", NULL, NULL);
521 weston_config_section_get_int(section, "log",
522 &ico_debug_level, DEFAULT_DEBUG_LEVEL);
523 ico_debug_level &= 0x0ffff;
528 focus_state_destroy(struct focus_state *state)
530 wl_list_remove(&state->seat_destroy_listener.link);
531 wl_list_remove(&state->surface_destroy_listener.link);
536 focus_state_seat_destroy(struct wl_listener *listener, void *data)
538 struct focus_state *state = container_of(listener,
540 seat_destroy_listener);
542 wl_list_remove(&state->link);
543 focus_state_destroy(state);
547 focus_state_surface_destroy(struct wl_listener *listener, void *data)
549 struct focus_state *state = container_of(listener,
551 surface_destroy_listener);
552 struct desktop_shell *shell;
553 struct weston_surface *main_surface;
554 struct weston_surface *surface, *next;
556 main_surface = weston_surface_get_main_surface(state->keyboard_focus);
559 wl_list_for_each(surface, &state->ws->layer.surface_list, layer_link) {
560 if (surface == main_surface)
567 /* if the focus was a sub-surface, activate its main surface */
568 if (main_surface != state->keyboard_focus)
572 shell = state->seat->compositor->shell_interface.shell;
573 activate(shell, next, state->seat);
575 wl_list_remove(&state->link);
576 focus_state_destroy(state);
580 static struct focus_state *
581 focus_state_create(struct weston_seat *seat, struct workspace *ws)
583 struct focus_state *state;
585 state = malloc(sizeof *state);
591 wl_list_insert(&ws->focus_list, &state->link);
593 state->seat_destroy_listener.notify = focus_state_seat_destroy;
594 state->surface_destroy_listener.notify = focus_state_surface_destroy;
595 wl_signal_add(&seat->destroy_signal,
596 &state->seat_destroy_listener);
597 wl_list_init(&state->surface_destroy_listener.link);
602 static struct focus_state *
603 ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat)
605 struct workspace *ws = get_current_workspace(shell);
606 struct focus_state *state;
608 wl_list_for_each(state, &ws->focus_list, link)
609 if (state->seat == seat)
612 if (&state->link == &ws->focus_list)
613 state = focus_state_create(seat, ws);
619 restore_focus_state(struct desktop_shell *shell, struct workspace *ws)
621 struct focus_state *state, *next;
622 struct weston_surface *surface;
624 wl_list_for_each_safe(state, next, &ws->focus_list, link) {
625 surface = state->keyboard_focus;
627 weston_keyboard_set_focus(state->seat->keyboard, surface);
632 replace_focus_state(struct desktop_shell *shell, struct workspace *ws,
633 struct weston_seat *seat)
635 struct focus_state *state;
636 struct weston_surface *surface;
638 wl_list_for_each(state, &ws->focus_list, link) {
639 if (state->seat == seat) {
640 surface = seat->keyboard->focus;
641 state->keyboard_focus = surface;
648 drop_focus_state(struct desktop_shell *shell, struct workspace *ws,
649 struct weston_surface *surface)
651 struct focus_state *state;
653 wl_list_for_each(state, &ws->focus_list, link)
654 if (state->keyboard_focus == surface)
655 state->keyboard_focus = NULL;
659 workspace_destroy(struct workspace *ws)
661 struct focus_state *state, *next;
663 wl_list_for_each_safe(state, next, &ws->focus_list, link)
664 focus_state_destroy(state);
670 seat_destroyed(struct wl_listener *listener, void *data)
672 struct weston_seat *seat = data;
673 struct focus_state *state, *next;
674 struct workspace *ws = container_of(listener,
676 seat_destroyed_listener);
678 wl_list_for_each_safe(state, next, &ws->focus_list, link)
679 if (state->seat == seat)
680 wl_list_remove(&state->link);
683 static struct workspace *
684 workspace_create(void)
686 struct workspace *ws = malloc(sizeof *ws);
690 weston_layer_init(&ws->layer, NULL);
692 wl_list_init(&ws->focus_list);
693 wl_list_init(&ws->seat_destroyed_listener.link);
694 ws->seat_destroyed_listener.notify = seat_destroyed;
700 workspace_is_empty(struct workspace *ws)
702 return wl_list_empty(&ws->layer.surface_list);
705 static struct workspace *
706 get_workspace(struct desktop_shell *shell, unsigned int index)
708 struct workspace **pws = shell->workspaces.array.data;
709 assert(index < shell->workspaces.num);
714 static struct workspace *
715 get_current_workspace(struct desktop_shell *shell)
717 return get_workspace(shell, shell->workspaces.current);
721 activate_workspace(struct desktop_shell *shell, unsigned int index)
723 struct workspace *ws;
725 ws = get_workspace(shell, index);
726 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
728 shell->workspaces.current = index;
732 get_output_height(struct weston_output *output)
734 return abs(output->region.extents.y1 - output->region.extents.y2);
738 surface_translate(struct weston_surface *surface, double d)
740 struct shell_surface *shsurf = get_shell_surface(surface);
741 struct weston_transform *transform;
743 transform = &shsurf->workspace_transform;
744 if (wl_list_empty(&transform->link))
745 wl_list_insert(surface->geometry.transformation_list.prev,
746 &shsurf->workspace_transform.link);
748 weston_matrix_init(&shsurf->workspace_transform.matrix);
749 weston_matrix_translate(&shsurf->workspace_transform.matrix,
751 weston_surface_geometry_dirty(surface);
755 workspace_translate_out(struct workspace *ws, double fraction)
757 struct weston_surface *surface;
761 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
762 height = get_output_height(surface->output);
763 d = height * fraction;
765 surface_translate(surface, d);
770 workspace_translate_in(struct workspace *ws, double fraction)
772 struct weston_surface *surface;
776 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
777 height = get_output_height(surface->output);
780 d = -(height - height * fraction);
782 d = height + height * fraction;
784 surface_translate(surface, d);
789 broadcast_current_workspace_state(struct desktop_shell *shell)
791 struct wl_resource *resource;
793 wl_resource_for_each(resource, &shell->workspaces.client_list)
794 workspace_manager_send_state(resource,
795 shell->workspaces.current,
796 shell->workspaces.num);
800 reverse_workspace_change_animation(struct desktop_shell *shell,
802 struct workspace *from,
803 struct workspace *to)
805 shell->workspaces.current = index;
807 shell->workspaces.anim_to = to;
808 shell->workspaces.anim_from = from;
809 shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir;
810 shell->workspaces.anim_timestamp = 0;
812 weston_compositor_schedule_repaint(shell->compositor);
816 workspace_deactivate_transforms(struct workspace *ws)
818 struct weston_surface *surface;
819 struct shell_surface *shsurf;
821 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
822 shsurf = get_shell_surface(surface);
823 if (!wl_list_empty(&shsurf->workspace_transform.link)) {
824 wl_list_remove(&shsurf->workspace_transform.link);
825 wl_list_init(&shsurf->workspace_transform.link);
827 weston_surface_geometry_dirty(surface);
832 finish_workspace_change_animation(struct desktop_shell *shell,
833 struct workspace *from,
834 struct workspace *to)
836 weston_compositor_schedule_repaint(shell->compositor);
838 wl_list_remove(&shell->workspaces.animation.link);
839 workspace_deactivate_transforms(from);
840 workspace_deactivate_transforms(to);
841 shell->workspaces.anim_to = NULL;
843 wl_list_remove(&shell->workspaces.anim_from->layer.link);
847 animate_workspace_change_frame(struct weston_animation *animation,
848 struct weston_output *output, uint32_t msecs)
850 struct desktop_shell *shell =
851 container_of(animation, struct desktop_shell,
852 workspaces.animation);
853 struct workspace *from = shell->workspaces.anim_from;
854 struct workspace *to = shell->workspaces.anim_to;
858 if (workspace_is_empty(from) && workspace_is_empty(to)) {
859 finish_workspace_change_animation(shell, from, to);
863 if (shell->workspaces.anim_timestamp == 0) {
864 if (shell->workspaces.anim_current == 0.0)
865 shell->workspaces.anim_timestamp = msecs;
867 shell->workspaces.anim_timestamp =
869 /* Invers of movement function 'y' below. */
870 (asin(1.0 - shell->workspaces.anim_current) *
871 DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH *
875 t = msecs - shell->workspaces.anim_timestamp;
881 x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2;
884 if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) {
885 weston_compositor_schedule_repaint(shell->compositor);
887 workspace_translate_out(from, shell->workspaces.anim_dir * y);
888 workspace_translate_in(to, shell->workspaces.anim_dir * y);
889 shell->workspaces.anim_current = y;
891 weston_compositor_schedule_repaint(shell->compositor);
894 finish_workspace_change_animation(shell, from, to);
898 animate_workspace_change(struct desktop_shell *shell,
900 struct workspace *from,
901 struct workspace *to)
903 struct weston_output *output;
907 if (index > shell->workspaces.current)
912 shell->workspaces.current = index;
914 shell->workspaces.anim_dir = dir;
915 shell->workspaces.anim_from = from;
916 shell->workspaces.anim_to = to;
917 shell->workspaces.anim_current = 0.0;
918 shell->workspaces.anim_timestamp = 0;
920 output = container_of(shell->compositor->output_list.next,
921 struct weston_output, link);
922 wl_list_insert(&output->animation_list,
923 &shell->workspaces.animation.link);
925 wl_list_insert(from->layer.link.prev, &to->layer.link);
927 workspace_translate_in(to, 0);
929 restore_focus_state(shell, to);
931 weston_compositor_schedule_repaint(shell->compositor);
935 update_workspace(struct desktop_shell *shell, unsigned int index,
936 struct workspace *from, struct workspace *to)
938 shell->workspaces.current = index;
939 wl_list_insert(&from->layer.link, &to->layer.link);
940 wl_list_remove(&from->layer.link);
944 change_workspace(struct desktop_shell *shell, unsigned int index)
946 struct workspace *from;
947 struct workspace *to;
949 if (index == shell->workspaces.current)
952 /* Don't change workspace when there is any fullscreen surfaces. */
953 if (!wl_list_empty(&shell->fullscreen_layer.surface_list))
956 from = get_current_workspace(shell);
957 to = get_workspace(shell, index);
959 if (shell->workspaces.anim_from == to &&
960 shell->workspaces.anim_to == from) {
961 restore_focus_state(shell, to);
962 reverse_workspace_change_animation(shell, index, from, to);
963 broadcast_current_workspace_state(shell);
967 if (shell->workspaces.anim_to != NULL)
968 finish_workspace_change_animation(shell,
969 shell->workspaces.anim_from,
970 shell->workspaces.anim_to);
972 restore_focus_state(shell, to);
974 if (workspace_is_empty(to) && workspace_is_empty(from))
975 update_workspace(shell, index, from, to);
977 animate_workspace_change(shell, index, from, to);
979 broadcast_current_workspace_state(shell);
983 workspace_has_only(struct workspace *ws, struct weston_surface *surface)
985 struct wl_list *list = &ws->layer.surface_list;
988 if (wl_list_empty(list))
996 return container_of(e, struct weston_surface, layer_link) == surface;
1000 move_surface_to_workspace(struct desktop_shell *shell,
1001 struct weston_surface *surface,
1004 struct workspace *from;
1005 struct workspace *to;
1006 struct weston_seat *seat;
1007 struct weston_surface *focus;
1009 assert(weston_surface_get_main_surface(surface) == surface);
1011 if (workspace == shell->workspaces.current)
1014 if (workspace >= shell->workspaces.num)
1015 workspace = shell->workspaces.num - 1;
1017 from = get_current_workspace(shell);
1018 to = get_workspace(shell, workspace);
1020 wl_list_remove(&surface->layer_link);
1021 wl_list_insert(&to->layer.surface_list, &surface->layer_link);
1023 drop_focus_state(shell, from, surface);
1024 wl_list_for_each(seat, &shell->compositor->seat_list, link) {
1025 if (!seat->keyboard)
1028 focus = weston_surface_get_main_surface(seat->keyboard->focus);
1029 if (focus == surface)
1030 weston_keyboard_set_focus(seat->keyboard, NULL);
1033 weston_surface_damage_below(surface);
1037 take_surface_to_workspace_by_seat(struct desktop_shell *shell,
1038 struct weston_seat *seat,
1041 struct weston_surface *surface;
1042 struct shell_surface *shsurf;
1043 struct workspace *from;
1044 struct workspace *to;
1045 struct focus_state *state;
1047 surface = weston_surface_get_main_surface(seat->keyboard->focus);
1048 if (surface == NULL ||
1049 index == shell->workspaces.current)
1052 from = get_current_workspace(shell);
1053 to = get_workspace(shell, index);
1055 wl_list_remove(&surface->layer_link);
1056 wl_list_insert(&to->layer.surface_list, &surface->layer_link);
1058 replace_focus_state(shell, to, seat);
1059 drop_focus_state(shell, from, surface);
1061 if (shell->workspaces.anim_from == to &&
1062 shell->workspaces.anim_to == from) {
1063 wl_list_remove(&to->layer.link);
1064 wl_list_insert(from->layer.link.prev, &to->layer.link);
1066 reverse_workspace_change_animation(shell, index, from, to);
1067 broadcast_current_workspace_state(shell);
1072 if (shell->workspaces.anim_to != NULL)
1073 finish_workspace_change_animation(shell,
1074 shell->workspaces.anim_from,
1075 shell->workspaces.anim_to);
1077 if (workspace_is_empty(from) &&
1078 workspace_has_only(to, surface))
1079 update_workspace(shell, index, from, to);
1081 shsurf = get_shell_surface(surface);
1082 if (wl_list_empty(&shsurf->workspace_transform.link))
1083 wl_list_insert(&shell->workspaces.anim_sticky_list,
1084 &shsurf->workspace_transform.link);
1086 animate_workspace_change(shell, index, from, to);
1089 broadcast_current_workspace_state(shell);
1091 state = ensure_focus_state(shell, seat);
1093 state->keyboard_focus = surface;
1097 workspace_manager_move_surface(struct wl_client *client,
1098 struct wl_resource *resource,
1099 struct wl_resource *surface_resource,
1102 struct desktop_shell *shell = wl_resource_get_user_data(resource);
1103 struct weston_surface *surface =
1104 wl_resource_get_user_data(surface_resource);
1105 struct weston_surface *main_surface;
1107 main_surface = weston_surface_get_main_surface(surface);
1108 move_surface_to_workspace(shell, main_surface, workspace);
1111 static const struct workspace_manager_interface workspace_manager_implementation = {
1112 workspace_manager_move_surface,
1116 unbind_resource(struct wl_resource *resource)
1118 wl_list_remove(wl_resource_get_link(resource));
1122 bind_workspace_manager(struct wl_client *client,
1123 void *data, uint32_t version, uint32_t id)
1125 struct desktop_shell *shell = data;
1126 struct wl_resource *resource;
1128 resource = wl_resource_create(client,
1129 &workspace_manager_interface, 1, id);
1131 if (resource == NULL) {
1132 weston_log("couldn't add workspace manager object");
1136 wl_resource_set_implementation(resource,
1137 &workspace_manager_implementation,
1138 shell, unbind_resource);
1139 wl_list_insert(&shell->workspaces.client_list,
1140 wl_resource_get_link(resource));
1142 workspace_manager_send_state(resource,
1143 shell->workspaces.current,
1144 shell->workspaces.num);
1148 touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time,
1149 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1154 touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id)
1156 struct weston_touch_move_grab *move =
1157 (struct weston_touch_move_grab *) container_of(
1158 grab, struct shell_touch_grab, grab);
1160 if (grab->touch->seat->num_tp == 0) {
1161 shell_touch_grab_end(&move->base);
1167 touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time,
1168 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
1170 struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab;
1171 struct shell_surface *shsurf = move->base.shsurf;
1172 struct weston_surface *es;
1173 int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx);
1174 int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy);
1179 es = shsurf->surface;
1181 weston_surface_configure(es, dx, dy,
1182 es->geometry.width, es->geometry.height);
1184 weston_compositor_schedule_repaint(es->compositor);
1188 touch_move_grab_cancel(struct weston_touch_grab *grab)
1190 struct weston_touch_move_grab *move =
1191 (struct weston_touch_move_grab *) container_of(
1192 grab, struct shell_touch_grab, grab);
1194 shell_touch_grab_end(&move->base);
1198 static const struct weston_touch_grab_interface touch_move_grab_interface = {
1199 touch_move_grab_down,
1201 touch_move_grab_motion,
1202 touch_move_grab_cancel,
1206 surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat)
1208 struct weston_touch_move_grab *move;
1213 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1216 move = malloc(sizeof *move);
1220 move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
1221 seat->touch->grab_x;
1222 move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
1223 seat->touch->grab_y;
1225 shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf,
1232 noop_grab_focus(struct weston_pointer_grab *grab)
1237 move_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
1239 struct weston_move_grab *move = (struct weston_move_grab *) grab;
1240 struct weston_pointer *pointer = grab->pointer;
1241 struct shell_surface *shsurf = move->base.shsurf;
1242 struct weston_surface *es;
1243 int dx = wl_fixed_to_int(pointer->x + move->dx);
1244 int dy = wl_fixed_to_int(pointer->y + move->dy);
1249 es = shsurf->surface;
1251 /* ico-ivi-shell hook move */
1252 if (shell_hook_move) {
1253 (*shell_hook_move)(shsurf->surface, &dx, &dy);
1255 weston_surface_configure(es, dx, dy,
1256 es->geometry.width, es->geometry.height);
1258 weston_compositor_schedule_repaint(es->compositor);
1262 move_grab_button(struct weston_pointer_grab *grab,
1263 uint32_t time, uint32_t button, uint32_t state_w)
1265 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
1267 struct weston_pointer *pointer = grab->pointer;
1268 enum wl_pointer_button_state state = state_w;
1270 if (pointer->button_count == 0 &&
1271 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1272 shell_grab_end(shell_grab);
1278 move_grab_cancel(struct weston_pointer_grab *grab)
1280 struct shell_grab *shell_grab =
1281 container_of(grab, struct shell_grab, grab);
1283 shell_grab_end(shell_grab);
1287 static const struct weston_pointer_grab_interface move_grab_interface = {
1295 surface_move(struct shell_surface *shsurf, struct weston_seat *seat)
1297 struct weston_move_grab *move;
1302 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1305 move = malloc(sizeof *move);
1309 move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
1310 seat->pointer->grab_x;
1311 move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
1312 seat->pointer->grab_y;
1314 shell_grab_start(&move->base, &move_grab_interface, shsurf,
1315 seat->pointer, DESKTOP_SHELL_CURSOR_MOVE);
1321 shell_surface_move(struct wl_client *client, struct wl_resource *resource,
1322 struct wl_resource *seat_resource, uint32_t serial)
1324 struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
1325 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1326 struct weston_surface *surface;
1328 if (seat->pointer &&
1329 seat->pointer->button_count > 0 &&
1330 seat->pointer->grab_serial == serial) {
1331 surface = weston_surface_get_main_surface(seat->pointer->focus);
1332 if ((surface == shsurf->surface) &&
1333 (surface_move(shsurf, seat) < 0))
1334 wl_resource_post_no_memory(resource);
1335 } else if (seat->touch &&
1336 seat->touch->grab_serial == serial) {
1337 surface = weston_surface_get_main_surface(seat->touch->focus);
1338 if ((surface == shsurf->surface) &&
1339 (surface_touch_move(shsurf, seat) < 0))
1340 wl_resource_post_no_memory(resource);
1344 struct weston_resize_grab {
1345 struct shell_grab base;
1347 int32_t width, height;
1351 resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
1353 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1354 struct weston_pointer *pointer = grab->pointer;
1355 struct shell_surface *shsurf = resize->base.shsurf;
1356 int32_t width, height;
1357 wl_fixed_t from_x, from_y;
1358 wl_fixed_t to_x, to_y;
1363 weston_surface_from_global_fixed(shsurf->surface,
1364 pointer->grab_x, pointer->grab_y,
1366 weston_surface_from_global_fixed(shsurf->surface,
1367 pointer->x, pointer->y, &to_x, &to_y);
1369 width = resize->width;
1370 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
1371 width += wl_fixed_to_int(from_x - to_x);
1372 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
1373 width += wl_fixed_to_int(to_x - from_x);
1376 height = resize->height;
1377 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
1378 height += wl_fixed_to_int(from_y - to_y);
1379 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
1380 height += wl_fixed_to_int(to_y - from_y);
1383 uifw_debug("resize_grab_motion: send configure %08x %x w/h=%d/%d",
1384 (int)shsurf->surface, resize->edges, width, height);
1385 shsurf->client->send_configure(shsurf->surface,
1386 resize->edges, width, height);
1390 send_configure(struct weston_surface *surface,
1391 uint32_t edges, int32_t width, int32_t height)
1393 struct shell_surface *shsurf = get_shell_surface(surface);
1395 uifw_trace("send_configure: send %08x %x w/h=%d/%d",
1396 (int)shsurf->surface, edges, width, height);
1397 wl_shell_surface_send_configure(shsurf->resource,
1398 edges, width, height);
1401 static const struct weston_shell_client shell_client = {
1406 resize_grab_button(struct weston_pointer_grab *grab,
1407 uint32_t time, uint32_t button, uint32_t state_w)
1409 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1410 struct weston_pointer *pointer = grab->pointer;
1411 enum wl_pointer_button_state state = state_w;
1413 if (pointer->button_count == 0 &&
1414 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1415 shell_grab_end(&resize->base);
1421 resize_grab_cancel(struct weston_pointer_grab *grab)
1423 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
1425 shell_grab_end(&resize->base);
1429 static const struct weston_pointer_grab_interface resize_grab_interface = {
1437 * Returns the bounding box of a surface and all its sub-surfaces,
1438 * in the surface coordinates system. */
1440 surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x,
1441 int32_t *y, int32_t *w, int32_t *h) {
1442 pixman_region32_t region;
1443 pixman_box32_t *box;
1444 struct weston_subsurface *subsurface;
1446 pixman_region32_init_rect(®ion, 0, 0,
1447 surface->geometry.width,
1448 surface->geometry.height);
1450 wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
1451 pixman_region32_union_rect(®ion, ®ion,
1452 subsurface->position.x,
1453 subsurface->position.y,
1454 subsurface->surface->geometry.width,
1455 subsurface->surface->geometry.height);
1458 box = pixman_region32_extents(®ion);
1464 *w = box->x2 - box->x1;
1466 *h = box->y2 - box->y1;
1468 pixman_region32_fini(®ion);
1472 surface_resize(struct shell_surface *shsurf,
1473 struct weston_seat *seat, uint32_t edges)
1475 struct weston_resize_grab *resize;
1477 if (shsurf->type == SHELL_SURFACE_FULLSCREEN ||
1478 shsurf->type == SHELL_SURFACE_MAXIMIZED)
1481 if (edges == 0 || edges > 15 ||
1482 (edges & 3) == 3 || (edges & 12) == 12)
1485 resize = malloc(sizeof *resize);
1489 resize->edges = edges;
1490 surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL,
1491 &resize->width, &resize->height);
1493 shell_grab_start(&resize->base, &resize_grab_interface, shsurf,
1494 seat->pointer, edges);
1500 shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
1501 struct wl_resource *seat_resource, uint32_t serial,
1504 struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
1505 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1506 struct weston_surface *surface;
1508 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
1511 surface = weston_surface_get_main_surface(seat->pointer->focus);
1512 if (seat->pointer->button_count == 0 ||
1513 seat->pointer->grab_serial != serial ||
1514 surface != shsurf->surface)
1517 if (surface_resize(shsurf, seat, edges) < 0)
1518 wl_resource_post_no_memory(resource);
1522 end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer);
1525 busy_cursor_grab_focus(struct weston_pointer_grab *base)
1527 struct shell_grab *grab = (struct shell_grab *) base;
1528 struct weston_pointer *pointer = base->pointer;
1529 struct weston_surface *surface;
1532 surface = weston_compositor_pick_surface(pointer->seat->compositor,
1533 pointer->x, pointer->y,
1536 if (!grab->shsurf || grab->shsurf->surface != surface)
1537 end_busy_cursor(grab->shsurf, pointer);
1541 busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
1546 busy_cursor_grab_button(struct weston_pointer_grab *base,
1547 uint32_t time, uint32_t button, uint32_t state)
1549 struct shell_grab *grab = (struct shell_grab *) base;
1550 struct shell_surface *shsurf = grab->shsurf;
1551 struct weston_seat *seat = grab->grab.pointer->seat;
1553 if (shsurf && button == BTN_LEFT && state) {
1554 activate(shsurf->shell, shsurf->surface, seat);
1555 surface_move(shsurf, seat);
1556 } else if (shsurf && button == BTN_RIGHT && state) {
1557 activate(shsurf->shell, shsurf->surface, seat);
1558 surface_rotate(shsurf, seat);
1563 busy_cursor_grab_cancel(struct weston_pointer_grab *base)
1565 struct shell_grab *grab = (struct shell_grab *) base;
1567 shell_grab_end(grab);
1571 static const struct weston_pointer_grab_interface busy_cursor_grab_interface = {
1572 busy_cursor_grab_focus,
1573 busy_cursor_grab_motion,
1574 busy_cursor_grab_button,
1575 busy_cursor_grab_cancel,
1579 set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
1581 struct shell_grab *grab;
1583 grab = malloc(sizeof *grab);
1587 shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer,
1588 DESKTOP_SHELL_CURSOR_BUSY);
1592 end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer)
1594 struct shell_grab *grab = (struct shell_grab *) pointer->grab;
1596 if (grab->grab.interface == &busy_cursor_grab_interface &&
1597 grab->shsurf == shsurf) {
1598 shell_grab_end(grab);
1604 ping_timer_destroy(struct shell_surface *shsurf)
1606 if (!shsurf || !shsurf->ping_timer)
1609 if (shsurf->ping_timer->source)
1610 wl_event_source_remove(shsurf->ping_timer->source);
1612 free(shsurf->ping_timer);
1613 shsurf->ping_timer = NULL;
1617 ping_timeout_handler(void *data)
1619 struct shell_surface *shsurf = data;
1620 struct weston_seat *seat;
1622 /* Client is not responding */
1623 shsurf->unresponsive = 1;
1625 wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link)
1626 if (seat->pointer->focus == shsurf->surface)
1627 set_busy_cursor(shsurf, seat->pointer);
1633 ping_handler(struct weston_surface *surface, uint32_t serial)
1635 struct shell_surface *shsurf = get_shell_surface(surface);
1636 struct wl_event_loop *loop;
1637 int ping_timeout = 200;
1641 if (!shsurf->resource)
1644 if (shsurf->surface == shsurf->shell->grab_surface)
1647 if (!shsurf->ping_timer) {
1648 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
1649 if (!shsurf->ping_timer)
1652 shsurf->ping_timer->serial = serial;
1653 loop = wl_display_get_event_loop(surface->compositor->wl_display);
1654 shsurf->ping_timer->source =
1655 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
1656 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
1658 wl_shell_surface_send_ping(shsurf->resource, serial);
1663 handle_pointer_focus(struct wl_listener *listener, void *data)
1665 struct weston_pointer *pointer = data;
1666 struct weston_surface *surface = pointer->focus;
1667 struct weston_compositor *compositor;
1668 struct shell_surface *shsurf;
1674 compositor = surface->compositor;
1675 shsurf = get_shell_surface(surface);
1677 if (shsurf && shsurf->unresponsive) {
1678 set_busy_cursor(shsurf, pointer);
1680 serial = wl_display_next_serial(compositor->wl_display);
1681 ping_handler(surface, serial);
1686 create_pointer_focus_listener(struct weston_seat *seat)
1688 struct wl_listener *listener;
1693 listener = malloc(sizeof *listener);
1694 listener->notify = handle_pointer_focus;
1695 wl_signal_add(&seat->pointer->focus_signal, listener);
1699 shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
1702 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1703 struct weston_seat *seat;
1704 struct weston_compositor *ec = shsurf->surface->compositor;
1706 if (shsurf->ping_timer == NULL)
1707 /* Just ignore unsolicited pong. */
1710 if (shsurf->ping_timer->serial == serial) {
1711 shsurf->unresponsive = 0;
1712 wl_list_for_each(seat, &ec->seat_list, link) {
1714 end_busy_cursor(shsurf, seat->pointer);
1716 ping_timer_destroy(shsurf);
1721 set_title(struct shell_surface *shsurf, const char *title)
1725 /* if ico_window_mgr hook, call hook routine */
1726 if (shell_hook_title) {
1727 p = (*shell_hook_title)(shsurf->surface, title);
1729 free(shsurf->title);
1730 shsurf->title = strdup(p);
1734 free(shsurf->title);
1735 shsurf->title = strdup(title);
1740 shell_surface_set_title(struct wl_client *client,
1741 struct wl_resource *resource, const char *title)
1743 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1745 set_title(shsurf, title);
1749 shell_surface_set_class(struct wl_client *client,
1750 struct wl_resource *resource, const char *class)
1752 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1754 free(shsurf->class);
1755 shsurf->class = strdup(class);
1758 static struct weston_output *
1759 get_default_output(struct weston_compositor *compositor)
1761 /* support multi display, default fullscreen output display */
1762 if (default_inputpanel) {
1763 return default_inputpanel;
1765 return container_of(compositor->output_list.next,
1766 struct weston_output, link);
1770 restore_output_mode(struct weston_output *output)
1772 if (output->current_mode != output->original_mode ||
1773 (int32_t)output->current_scale != output->original_scale)
1774 weston_output_switch_mode(output,
1775 output->original_mode,
1776 output->original_scale,
1777 WESTON_MODE_SWITCH_RESTORE_NATIVE);
1781 restore_all_output_modes(struct weston_compositor *compositor)
1783 struct weston_output *output;
1785 wl_list_for_each(output, &compositor->output_list, link)
1786 restore_output_mode(output);
1790 shell_unset_fullscreen(struct shell_surface *shsurf)
1792 struct workspace *ws;
1794 uifw_debug("shell_unset_fullscreen: ");
1796 /* undo all fullscreen things here */
1797 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1798 shell_surface_is_top_fullscreen(shsurf)) {
1799 restore_output_mode(shsurf->fullscreen_output);
1801 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1802 shsurf->fullscreen.framerate = 0;
1803 wl_list_remove(&shsurf->fullscreen.transform.link);
1804 wl_list_init(&shsurf->fullscreen.transform.link);
1805 if (shsurf->fullscreen.black_surface)
1806 weston_surface_destroy(shsurf->fullscreen.black_surface);
1807 shsurf->fullscreen.black_surface = NULL;
1808 shsurf->fullscreen_output = NULL;
1809 weston_surface_set_position(shsurf->surface,
1810 shsurf->saved_x, shsurf->saved_y);
1811 if (shsurf->saved_rotation_valid) {
1812 wl_list_insert(&shsurf->surface->geometry.transformation_list,
1813 &shsurf->rotation.transform.link);
1814 shsurf->saved_rotation_valid = false;
1817 ws = get_current_workspace(shsurf->shell);
1818 wl_list_remove(&shsurf->surface->layer_link);
1819 wl_list_insert(&ws->layer.surface_list, &shsurf->surface->layer_link);
1823 shell_unset_maximized(struct shell_surface *shsurf)
1825 struct workspace *ws;
1827 uifw_debug("shell_unset_maximized: ");
1829 /* undo all maximized things here */
1830 shsurf->output = get_default_output(shsurf->surface->compositor);
1831 weston_surface_set_position(shsurf->surface,
1835 if (shsurf->saved_rotation_valid) {
1836 wl_list_insert(&shsurf->surface->geometry.transformation_list,
1837 &shsurf->rotation.transform.link);
1838 shsurf->saved_rotation_valid = false;
1841 ws = get_current_workspace(shsurf->shell);
1842 wl_list_remove(&shsurf->surface->layer_link);
1843 wl_list_insert(&ws->layer.surface_list, &shsurf->surface->layer_link);
1847 reset_shell_surface_type(struct shell_surface *surface)
1849 switch (surface->type) {
1850 case SHELL_SURFACE_FULLSCREEN:
1851 shell_unset_fullscreen(surface);
1853 case SHELL_SURFACE_MAXIMIZED:
1854 shell_unset_maximized(surface);
1856 case SHELL_SURFACE_NONE:
1857 case SHELL_SURFACE_TOPLEVEL:
1858 case SHELL_SURFACE_TRANSIENT:
1859 case SHELL_SURFACE_POPUP:
1860 case SHELL_SURFACE_XWAYLAND:
1864 surface->type = SHELL_SURFACE_NONE;
1869 set_surface_type(struct shell_surface *shsurf)
1871 struct weston_surface *surface = shsurf->surface;
1872 struct weston_surface *pes = shsurf->parent;
1874 reset_shell_surface_type(shsurf);
1876 shsurf->type = shsurf->next_type;
1877 shsurf->next_type = SHELL_SURFACE_NONE;
1879 switch (shsurf->type) {
1880 case SHELL_SURFACE_TOPLEVEL:
1882 case SHELL_SURFACE_TRANSIENT:
1883 weston_surface_set_position(surface,
1884 pes->geometry.x + shsurf->transient.x,
1885 pes->geometry.y + shsurf->transient.y);
1888 case SHELL_SURFACE_MAXIMIZED:
1889 case SHELL_SURFACE_FULLSCREEN:
1890 shsurf->saved_x = surface->geometry.x;
1891 shsurf->saved_y = surface->geometry.y;
1892 shsurf->saved_position_valid = true;
1894 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
1895 wl_list_remove(&shsurf->rotation.transform.link);
1896 wl_list_init(&shsurf->rotation.transform.link);
1897 weston_surface_geometry_dirty(shsurf->surface);
1898 shsurf->saved_rotation_valid = true;
1900 if (shsurf->type == SHELL_SURFACE_FULLSCREEN) {
1901 uifw_debug("set_surface_type: set fullscreen");
1902 if (shell_hook_fullscreen) {
1903 (*shell_hook_fullscreen)(SHELL_FULLSCREEN_SET, surface);
1908 case SHELL_SURFACE_XWAYLAND:
1909 weston_surface_set_position(surface, shsurf->transient.x,
1910 shsurf->transient.y);
1919 set_toplevel(struct shell_surface *shsurf)
1921 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
1925 shell_surface_set_toplevel(struct wl_client *client,
1926 struct wl_resource *resource)
1928 struct shell_surface *surface = wl_resource_get_user_data(resource);
1930 set_toplevel(surface);
1934 set_transient(struct shell_surface *shsurf,
1935 struct weston_surface *parent, int x, int y, uint32_t flags)
1937 /* assign to parents output */
1938 shsurf->parent = parent;
1939 shsurf->transient.x = x;
1940 shsurf->transient.y = y;
1941 shsurf->transient.flags = flags;
1942 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
1946 shell_surface_set_transient(struct wl_client *client,
1947 struct wl_resource *resource,
1948 struct wl_resource *parent_resource,
1949 int x, int y, uint32_t flags)
1951 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1952 struct weston_surface *parent =
1953 wl_resource_get_user_data(parent_resource);
1955 set_transient(shsurf, parent, x, y, flags);
1958 static struct desktop_shell *
1959 shell_surface_get_shell(struct shell_surface *shsurf)
1961 return shsurf->shell;
1965 get_output_panel_height(struct desktop_shell *shell,
1966 struct weston_output *output)
1968 struct weston_surface *surface;
1969 int panel_height = 0;
1974 wl_list_for_each(surface, &shell->panel_layer.surface_list, layer_link) {
1975 if (surface->output == output) {
1976 panel_height = surface->geometry.height;
1981 return panel_height;
1985 shell_surface_set_maximized(struct wl_client *client,
1986 struct wl_resource *resource,
1987 struct wl_resource *output_resource )
1989 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
1990 struct weston_surface *es = shsurf->surface;
1991 struct desktop_shell *shell = NULL;
1992 uint32_t edges = 0, panel_height = 0;
1994 /* get the default output, if the client set it as NULL
1995 check whether the ouput is available */
1996 if (output_resource)
1997 shsurf->output = wl_resource_get_user_data(output_resource);
1998 else if (es->output)
1999 shsurf->output = es->output;
2001 shsurf->output = get_default_output(es->compositor);
2003 shell = shell_surface_get_shell(shsurf);
2004 panel_height = get_output_panel_height(shell, shsurf->output);
2005 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
2007 uifw_debug("shell_surface_set_maximized: send %08x %x w/h=%d/%d",
2008 (int)shsurf->surface, edges, shsurf->output->width,
2009 shsurf->output->height - panel_height);
2010 shsurf->client->send_configure(shsurf->surface, edges,
2011 shsurf->output->width,
2012 shsurf->output->height - panel_height);
2014 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
2018 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height);
2020 static struct weston_surface *
2021 create_black_surface(struct weston_compositor *ec,
2022 struct weston_surface *fs_surface,
2023 float x, float y, int w, int h)
2025 struct weston_surface *surface = NULL;
2027 uifw_debug("create_black_surface: fullscreen");
2028 surface = weston_surface_create(ec);
2029 if (surface == NULL) {
2030 weston_log("no memory\n");
2034 surface->configure = black_surface_configure;
2035 surface->configure_private = fs_surface;
2036 uifw_debug("create_black_surface: configure %08x x/y=%d/%d w/h=%d/%d",
2037 (int)surface, (int)x, (int)y, w, h);
2038 weston_surface_configure(surface, x, y, w, h);
2039 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
2040 pixman_region32_fini(&surface->opaque);
2041 pixman_region32_init_rect(&surface->opaque, 0, 0, w, h);
2042 pixman_region32_fini(&surface->input);
2043 pixman_region32_init_rect(&surface->input, 0, 0, w, h);
2048 /* Create black surface and append it to the associated fullscreen surface.
2049 * Handle size dismatch and positioning according to the method. */
2051 shell_configure_fullscreen(struct shell_surface *shsurf)
2053 uifw_debug("shell_configure_fullscreen: ");
2055 if (shell_hook_fullscreen) {
2056 (*shell_hook_fullscreen)(SHELL_FULLSCREEN_CONF, shsurf->surface);
2060 struct weston_output *output = shsurf->fullscreen_output;
2061 struct weston_surface *surface = shsurf->surface;
2062 struct weston_matrix *matrix;
2063 float scale, output_aspect, surface_aspect, x, y;
2064 int32_t surf_x, surf_y, surf_width, surf_height;
2066 if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER)
2067 restore_output_mode(output);
2069 if (!shsurf->fullscreen.black_surface)
2070 shsurf->fullscreen.black_surface =
2071 create_black_surface(surface->compositor,
2073 output->x, output->y,
2077 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
2078 wl_list_insert(&surface->layer_link,
2079 &shsurf->fullscreen.black_surface->layer_link);
2080 shsurf->fullscreen.black_surface->output = output;
2082 surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y,
2083 &surf_width, &surf_height);
2085 switch (shsurf->fullscreen.type) {
2086 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
2087 if (surface->buffer_ref.buffer)
2088 center_on_output(surface, shsurf->fullscreen_output);
2090 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
2091 /* 1:1 mapping between surface and output dimensions */
2092 if (output->width == surf_width &&
2093 output->height == surf_height) {
2094 weston_surface_set_position(surface, output->x - surf_x,
2095 output->y - surf_y);
2099 matrix = &shsurf->fullscreen.transform.matrix;
2100 weston_matrix_init(matrix);
2102 output_aspect = (float) output->width /
2103 (float) output->height;
2104 surface_aspect = (float) surface->geometry.width /
2105 (float) surface->geometry.height;
2106 if (output_aspect < surface_aspect)
2107 scale = (float) output->width /
2110 scale = (float) output->height /
2111 (float) surf_height;
2113 weston_matrix_scale(matrix, scale, scale, 1);
2114 wl_list_remove(&shsurf->fullscreen.transform.link);
2115 wl_list_insert(&surface->geometry.transformation_list,
2116 &shsurf->fullscreen.transform.link);
2117 x = output->x + (output->width - surf_width * scale) / 2 - surf_x;
2118 y = output->y + (output->height - surf_height * scale) / 2 - surf_y;
2119 weston_surface_set_position(surface, x, y);
2122 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
2123 if (shell_surface_is_top_fullscreen(shsurf)) {
2124 struct weston_mode mode = {0,
2125 surf_width * surface->buffer_scale,
2126 surf_height * surface->buffer_scale,
2127 shsurf->fullscreen.framerate};
2129 if (weston_output_switch_mode(output, &mode, surface->buffer_scale,
2130 WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) {
2131 weston_surface_set_position(surface,
2133 output->y - surf_y);
2134 uifw_debug("shell_configure_fullscreen: configure %08x x/y=%d/%d w/h=%d/%d",
2135 (int)shsurf->fullscreen.black_surface, (int)(output->x - surf_x),
2136 (int)(output->y - surf_y), output->width, output->height);
2137 weston_surface_configure(shsurf->fullscreen.black_surface,
2144 restore_output_mode(output);
2145 center_on_output(surface, output);
2149 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
2150 center_on_output(surface, output);
2157 /* make the fullscreen and black surface at the top */
2159 shell_stack_fullscreen(struct shell_surface *shsurf)
2161 uifw_debug("shell_stack_fullscreen: ");
2163 if (shell_hook_fullscreen) {
2164 (*shell_hook_fullscreen)(SHELL_FULLSCREEN_STACK, shsurf->surface);
2168 struct weston_output *output = shsurf->fullscreen_output;
2169 struct weston_surface *surface = shsurf->surface;
2170 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
2172 wl_list_remove(&surface->layer_link);
2173 wl_list_insert(&shell->fullscreen_layer.surface_list,
2174 &surface->layer_link);
2175 weston_surface_damage(surface);
2177 if (!shsurf->fullscreen.black_surface)
2178 shsurf->fullscreen.black_surface =
2179 create_black_surface(surface->compositor,
2181 output->x, output->y,
2185 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
2186 wl_list_insert(&surface->layer_link,
2187 &shsurf->fullscreen.black_surface->layer_link);
2188 weston_surface_damage(shsurf->fullscreen.black_surface);
2192 shell_map_fullscreen(struct shell_surface *shsurf)
2194 uifw_debug("shell_map_fullscreen: ");
2195 shell_stack_fullscreen(shsurf);
2196 shell_configure_fullscreen(shsurf);
2200 set_fullscreen(struct shell_surface *shsurf,
2203 struct weston_output *output)
2205 struct weston_surface *es = shsurf->surface;
2207 uifw_debug("set_fullscreen: ");
2210 shsurf->output = output;
2211 else if (es->output)
2212 shsurf->output = es->output;
2214 shsurf->output = get_default_output(es->compositor);
2216 shsurf->fullscreen_output = shsurf->output;
2217 shsurf->fullscreen.type = method;
2218 shsurf->fullscreen.framerate = framerate;
2219 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
2221 shsurf->client->send_configure(shsurf->surface, 0,
2222 shsurf->output->width,
2223 shsurf->output->height);
2227 shell_surface_set_fullscreen(struct wl_client *client,
2228 struct wl_resource *resource,
2231 struct wl_resource *output_resource)
2233 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2234 struct weston_output *output;
2236 uifw_debug("shell_surface_set_fullscreen: ");
2238 if (output_resource)
2239 output = wl_resource_get_user_data(output_resource);
2243 set_fullscreen(shsurf, method, framerate, output);
2247 set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags)
2249 /* XXX: using the same fields for transient type */
2250 shsurf->transient.x = x;
2251 shsurf->transient.y = y;
2252 shsurf->transient.flags = flags;
2253 shsurf->next_type = SHELL_SURFACE_XWAYLAND;
2256 static const struct weston_pointer_grab_interface popup_grab_interface;
2259 destroy_shell_seat(struct wl_listener *listener, void *data)
2261 struct shell_seat *shseat =
2262 container_of(listener,
2263 struct shell_seat, seat_destroy_listener);
2264 struct shell_surface *shsurf, *prev = NULL;
2266 if (shseat->popup_grab.grab.interface == &popup_grab_interface) {
2267 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
2268 shseat->popup_grab.client = NULL;
2270 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
2271 shsurf->popup.shseat = NULL;
2273 wl_list_init(&prev->popup.grab_link);
2277 wl_list_init(&prev->popup.grab_link);
2280 wl_list_remove(&shseat->seat_destroy_listener.link);
2284 static struct shell_seat *
2285 create_shell_seat(struct weston_seat *seat)
2287 struct shell_seat *shseat;
2289 shseat = calloc(1, sizeof *shseat);
2291 weston_log("no memory to allocate shell seat\n");
2295 shseat->seat = seat;
2296 wl_list_init(&shseat->popup_grab.surfaces_list);
2298 shseat->seat_destroy_listener.notify = destroy_shell_seat;
2299 wl_signal_add(&seat->destroy_signal,
2300 &shseat->seat_destroy_listener);
2305 static struct shell_seat *
2306 get_shell_seat(struct weston_seat *seat)
2308 struct wl_listener *listener;
2310 listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat);
2311 if (listener == NULL)
2312 return create_shell_seat(seat);
2314 return container_of(listener,
2315 struct shell_seat, seat_destroy_listener);
2319 popup_grab_focus(struct weston_pointer_grab *grab)
2321 struct weston_pointer *pointer = grab->pointer;
2322 struct weston_surface *surface;
2323 struct shell_seat *shseat =
2324 container_of(grab, struct shell_seat, popup_grab.grab);
2325 struct wl_client *client = shseat->popup_grab.client;
2328 surface = weston_compositor_pick_surface(pointer->seat->compositor,
2329 pointer->x, pointer->y,
2332 if (surface && wl_resource_get_client(surface->resource) == client) {
2333 weston_pointer_set_focus(pointer, surface, sx, sy);
2335 weston_pointer_set_focus(pointer, NULL,
2336 wl_fixed_from_int(0),
2337 wl_fixed_from_int(0));
2342 popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
2344 struct weston_pointer *pointer = grab->pointer;
2345 struct wl_resource *resource;
2348 wl_resource_for_each(resource, &pointer->focus_resource_list) {
2349 weston_surface_from_global_fixed(pointer->focus,
2350 pointer->x, pointer->y,
2352 wl_pointer_send_motion(resource, time, sx, sy);
2357 popup_grab_button(struct weston_pointer_grab *grab,
2358 uint32_t time, uint32_t button, uint32_t state_w)
2360 struct wl_resource *resource;
2361 struct shell_seat *shseat =
2362 container_of(grab, struct shell_seat, popup_grab.grab);
2363 struct wl_display *display = shseat->seat->compositor->wl_display;
2364 enum wl_pointer_button_state state = state_w;
2366 struct wl_list *resource_list;
2368 resource_list = &grab->pointer->focus_resource_list;
2369 if (!wl_list_empty(resource_list)) {
2370 serial = wl_display_get_serial(display);
2371 wl_resource_for_each(resource, resource_list) {
2372 wl_pointer_send_button(resource, serial,
2373 time, button, state);
2375 } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
2376 (shseat->popup_grab.initial_up ||
2377 time - shseat->seat->pointer->grab_time > 500)) {
2378 popup_grab_end(grab->pointer);
2381 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
2382 shseat->popup_grab.initial_up = 1;
2386 popup_grab_cancel(struct weston_pointer_grab *grab)
2388 popup_grab_end(grab->pointer);
2391 static const struct weston_pointer_grab_interface popup_grab_interface = {
2399 popup_grab_end(struct weston_pointer *pointer)
2401 struct weston_pointer_grab *grab = pointer->grab;
2402 struct shell_seat *shseat =
2403 container_of(grab, struct shell_seat, popup_grab.grab);
2404 struct shell_surface *shsurf;
2405 struct shell_surface *prev = NULL;
2407 if (pointer->grab->interface == &popup_grab_interface) {
2408 weston_pointer_end_grab(grab->pointer);
2409 shseat->popup_grab.client = NULL;
2410 shseat->popup_grab.grab.interface = NULL;
2411 assert(!wl_list_empty(&shseat->popup_grab.surfaces_list));
2412 /* Send the popup_done event to all the popups open */
2413 wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
2414 wl_shell_surface_send_popup_done(shsurf->resource);
2415 shsurf->popup.shseat = NULL;
2417 wl_list_init(&prev->popup.grab_link);
2421 wl_list_init(&prev->popup.grab_link);
2422 wl_list_init(&shseat->popup_grab.surfaces_list);
2427 add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat)
2429 struct weston_seat *seat = shseat->seat;
2431 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
2432 shseat->popup_grab.client = wl_resource_get_client(shsurf->resource);
2433 shseat->popup_grab.grab.interface = &popup_grab_interface;
2434 /* We must make sure here that this popup was opened after
2435 * a mouse press, and not just by moving around with other
2436 * popups already open. */
2437 if (shseat->seat->pointer->button_count > 0)
2438 shseat->popup_grab.initial_up = 0;
2440 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
2441 weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab);
2443 wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link);
2448 remove_popup_grab(struct shell_surface *shsurf)
2450 struct shell_seat *shseat = shsurf->popup.shseat;
2452 wl_list_remove(&shsurf->popup.grab_link);
2453 wl_list_init(&shsurf->popup.grab_link);
2454 if (wl_list_empty(&shseat->popup_grab.surfaces_list)) {
2455 weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
2456 shseat->popup_grab.grab.interface = NULL;
2461 shell_map_popup(struct shell_surface *shsurf)
2463 struct shell_seat *shseat = shsurf->popup.shseat;
2464 struct weston_surface *es = shsurf->surface;
2465 struct weston_surface *parent = shsurf->parent;
2467 es->output = parent->output;
2469 weston_surface_set_transform_parent(es, parent);
2470 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
2471 weston_surface_update_transform(es);
2473 if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) {
2474 add_popup_grab(shsurf, shseat);
2476 wl_shell_surface_send_popup_done(shsurf->resource);
2477 shseat->popup_grab.client = NULL;
2482 shell_surface_set_popup(struct wl_client *client,
2483 struct wl_resource *resource,
2484 struct wl_resource *seat_resource,
2486 struct wl_resource *parent_resource,
2487 int32_t x, int32_t y, uint32_t flags)
2489 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2491 shsurf->type = SHELL_SURFACE_POPUP;
2492 shsurf->parent = wl_resource_get_user_data(parent_resource);
2493 shsurf->popup.shseat = get_shell_seat(wl_resource_get_user_data(seat_resource));
2494 shsurf->popup.serial = serial;
2495 shsurf->popup.x = x;
2496 shsurf->popup.y = y;
2499 static const struct wl_shell_surface_interface shell_surface_implementation = {
2502 shell_surface_resize,
2503 shell_surface_set_toplevel,
2504 shell_surface_set_transient,
2505 shell_surface_set_fullscreen,
2506 shell_surface_set_popup,
2507 shell_surface_set_maximized,
2508 shell_surface_set_title,
2509 shell_surface_set_class
2513 destroy_shell_surface(struct shell_surface *shsurf)
2515 wl_signal_emit(&shsurf->destroy_signal, shsurf);
2517 /* if ico_window_mgr hook, call hook routine */
2518 if (shell_hook_destroy) {
2519 (*shell_hook_destroy)(shsurf->surface);
2522 if (!wl_list_empty(&shsurf->popup.grab_link)) {
2523 remove_popup_grab(shsurf);
2526 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
2527 shell_surface_is_top_fullscreen(shsurf))
2528 restore_output_mode (shsurf->fullscreen_output);
2530 if (shsurf->fullscreen.black_surface)
2531 weston_surface_destroy(shsurf->fullscreen.black_surface);
2533 /* As destroy_resource() use wl_list_for_each_safe(),
2534 * we can always remove the listener.
2536 wl_list_remove(&shsurf->surface_destroy_listener.link);
2537 shsurf->surface->configure = NULL;
2538 ping_timer_destroy(shsurf);
2539 free(shsurf->title);
2541 wl_list_remove(&shsurf->link);
2546 shell_destroy_shell_surface(struct wl_resource *resource)
2548 struct shell_surface *shsurf = wl_resource_get_user_data(resource);
2550 destroy_shell_surface(shsurf);
2554 shell_handle_surface_destroy(struct wl_listener *listener, void *data)
2556 struct shell_surface *shsurf = container_of(listener,
2557 struct shell_surface,
2558 surface_destroy_listener);
2560 if (shsurf->resource)
2561 wl_resource_destroy(shsurf->resource);
2563 destroy_shell_surface(shsurf);
2567 shell_surface_configure(struct weston_surface *, int32_t, int32_t, int32_t, int32_t);
2569 static struct shell_surface *
2570 get_shell_surface(struct weston_surface *surface)
2572 if (surface->configure == shell_surface_configure)
2573 return surface->configure_private;
2578 static struct shell_surface *
2579 create_shell_surface(void *shell, struct weston_surface *surface,
2580 const struct weston_shell_client *client)
2582 struct shell_surface *shsurf;
2584 if (surface->configure) {
2585 weston_log("surface->configure already set\n");
2589 shsurf = calloc(1, sizeof *shsurf);
2591 weston_log("no memory to allocate shell surface\n");
2595 surface->configure = shell_surface_configure;
2596 surface->configure_private = shsurf;
2598 shsurf->shell = (struct desktop_shell *) shell;
2599 shsurf->unresponsive = 0;
2600 shsurf->saved_position_valid = false;
2601 shsurf->saved_rotation_valid = false;
2602 shsurf->surface = surface;
2603 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
2604 shsurf->fullscreen.framerate = 0;
2605 shsurf->fullscreen.black_surface = NULL;
2606 shsurf->ping_timer = NULL;
2608 /* set default color and shader because weston original bug(some time crash weston) */
2609 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
2611 wl_list_init(&shsurf->fullscreen.transform.link);
2613 wl_signal_init(&shsurf->destroy_signal);
2614 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
2615 wl_signal_add(&surface->destroy_signal,
2616 &shsurf->surface_destroy_listener);
2618 /* init link so its safe to always remove it in destroy_shell_surface */
2619 wl_list_init(&shsurf->link);
2620 wl_list_init(&shsurf->popup.grab_link);
2622 /* empty when not in use */
2623 wl_list_init(&shsurf->rotation.transform.link);
2624 weston_matrix_init(&shsurf->rotation.rotation);
2626 wl_list_init(&shsurf->workspace_transform.link);
2628 shsurf->type = SHELL_SURFACE_NONE;
2629 shsurf->next_type = SHELL_SURFACE_NONE;
2631 shsurf->client = client;
2637 shell_get_shell_surface_layertype(int layertype, struct wl_client *client,
2638 struct wl_resource *resource,
2640 struct wl_resource *surface_resource)
2642 struct weston_surface *surface =
2643 wl_resource_get_user_data(surface_resource);
2644 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2645 struct shell_surface *shsurf;
2647 if (get_shell_surface(surface)) {
2648 wl_resource_post_error(surface_resource,
2649 WL_DISPLAY_ERROR_INVALID_OBJECT,
2650 "desktop_shell::get_shell_surface already requested");
2654 shsurf = create_shell_surface(shell, surface, &shell_client);
2656 wl_resource_post_error(surface_resource,
2657 WL_DISPLAY_ERROR_INVALID_OBJECT,
2658 "surface->configure already set");
2661 shsurf->layertype = layertype;
2663 wl_resource_create(client,
2664 &wl_shell_surface_interface, 1, id);
2665 wl_resource_set_implementation(shsurf->resource,
2666 &shell_surface_implementation,
2667 shsurf, shell_destroy_shell_surface);
2669 /* if ico_window_mgr hook, call hook routine */
2670 if (shell_hook_create) {
2671 (*shell_hook_create)(layertype, client, resource, surface, shsurf);
2676 shell_get_shell_surface(struct wl_client *client,
2677 struct wl_resource *resource,
2679 struct wl_resource *surface_resource)
2681 shell_get_shell_surface_layertype(LAYER_TYPE_PANEL,
2682 client, resource, id, surface_resource);
2685 static const struct wl_shell_interface shell_implementation = {
2686 shell_get_shell_surface
2690 shell_fade(struct desktop_shell *shell, enum fade_type type);
2693 screensaver_timeout(void *data)
2695 struct desktop_shell *shell = data;
2697 shell_fade(shell, FADE_OUT);
2703 handle_screensaver_sigchld(struct weston_process *proc, int status)
2705 struct desktop_shell *shell =
2706 container_of(proc, struct desktop_shell, screensaver.process);
2711 weston_compositor_sleep(shell->compositor);
2715 launch_screensaver(struct desktop_shell *shell)
2717 if (shell->screensaver.binding)
2720 if (!shell->screensaver.path) {
2721 weston_compositor_sleep(shell->compositor);
2725 if (shell->screensaver.process.pid != 0) {
2726 weston_log("old screensaver still running\n");
2730 uifw_trace("launch_screensaver: launch %s", shell->screensaver.path);
2731 weston_client_launch(shell->compositor,
2732 &shell->screensaver.process,
2733 shell->screensaver.path,
2734 handle_screensaver_sigchld);
2738 terminate_screensaver(struct desktop_shell *shell)
2740 if (shell->screensaver.process.pid == 0)
2743 kill(shell->screensaver.process.pid, SIGTERM);
2747 configure_static_surface(struct weston_surface *es, struct weston_layer *layer, int32_t width, int32_t height)
2749 struct weston_surface *s, *next;
2754 wl_list_for_each_safe(s, next, &layer->surface_list, layer_link) {
2755 if (s->output == es->output && s != es) {
2756 weston_surface_unmap(s);
2757 s->configure = NULL;
2761 uifw_debug("configure_static_surface: configure %08x x/y=%d/%d w/h=%d/%d",
2762 (int)es, (int)es->output->x, (int)es->output->y, width, height);
2763 weston_surface_configure(es, es->output->x, es->output->y, width, height);
2765 if (wl_list_empty(&es->layer_link)) {
2766 wl_list_insert(&layer->surface_list, &es->layer_link);
2767 weston_compositor_schedule_repaint(es->compositor);
2770 /* if ico_window_mgr hook, call hook routine */
2771 if (shell_hook_configure) {
2772 (*shell_hook_configure)(es);
2777 background_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
2779 struct desktop_shell *shell = es->configure_private;
2781 configure_static_surface(es, &shell->background_layer, width, height);
2785 desktop_shell_set_background(struct wl_client *client,
2786 struct wl_resource *resource,
2787 struct wl_resource *output_resource,
2788 struct wl_resource *surface_resource)
2790 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2791 struct weston_surface *surface =
2792 wl_resource_get_user_data(surface_resource);
2794 if (surface->configure) {
2795 wl_resource_post_error(surface_resource,
2796 WL_DISPLAY_ERROR_INVALID_OBJECT,
2797 "surface role already assigned");
2801 surface->configure = background_configure;
2802 surface->configure_private = shell;
2803 surface->output = wl_resource_get_user_data(output_resource);
2804 uifw_debug("desktop_shell_set_background: send %08x 0 w/h=%d/%d",
2805 (int)surface, surface->output->width, surface->output->height);
2806 desktop_shell_send_configure(resource, 0,
2808 surface->output->width,
2809 surface->output->height);
2813 panel_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
2815 struct desktop_shell *shell = es->configure_private;
2817 configure_static_surface(es, &shell->panel_layer, width, height);
2821 desktop_shell_set_panel(struct wl_client *client,
2822 struct wl_resource *resource,
2823 struct wl_resource *output_resource,
2824 struct wl_resource *surface_resource)
2826 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2827 struct weston_surface *surface =
2828 wl_resource_get_user_data(surface_resource);
2830 if (surface->configure) {
2831 wl_resource_post_error(surface_resource,
2832 WL_DISPLAY_ERROR_INVALID_OBJECT,
2833 "surface role already assigned");
2837 surface->configure = panel_configure;
2838 surface->configure_private = shell;
2839 surface->output = wl_resource_get_user_data(output_resource);
2840 uifw_debug("desktop_shell_set_panel: send %08x 0 w/h=%d/%d",
2841 (int)surface, surface->output->width, surface->output->height);
2842 desktop_shell_send_configure(resource, 0,
2844 surface->output->width,
2845 surface->output->height);
2849 lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
2851 struct desktop_shell *shell = surface->configure_private;
2856 uifw_debug("lock_surface_configure: change %08x w/h=%d/%d", (int)surface, width, height);
2857 surface->geometry.width = width;
2858 surface->geometry.height = height;
2859 center_on_output(surface, get_default_output(shell->compositor));
2861 if (!weston_surface_is_mapped(surface)) {
2862 wl_list_insert(&shell->lock_layer.surface_list,
2863 &surface->layer_link);
2864 weston_surface_update_transform(surface);
2865 shell_fade(shell, FADE_IN);
2870 handle_lock_surface_destroy(struct wl_listener *listener, void *data)
2872 struct desktop_shell *shell =
2873 container_of(listener, struct desktop_shell, lock_surface_listener);
2875 weston_log("lock surface gone\n");
2876 shell->lock_surface = NULL;
2880 desktop_shell_set_lock_surface(struct wl_client *client,
2881 struct wl_resource *resource,
2882 struct wl_resource *surface_resource)
2884 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2885 struct weston_surface *surface =
2886 wl_resource_get_user_data(surface_resource);
2888 shell->prepare_event_sent = false;
2893 shell->lock_surface = surface;
2895 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
2896 wl_signal_add(&surface->destroy_signal,
2897 &shell->lock_surface_listener);
2899 surface->configure = lock_surface_configure;
2900 surface->configure_private = shell;
2904 resume_desktop(struct desktop_shell *shell)
2906 struct workspace *ws = get_current_workspace(shell);
2908 terminate_screensaver(shell);
2910 wl_list_remove(&shell->lock_layer.link);
2911 wl_list_insert(&shell->compositor->cursor_layer.link,
2912 &shell->fullscreen_layer.link);
2913 wl_list_insert(&shell->fullscreen_layer.link,
2914 &shell->panel_layer.link);
2915 if ((! shell_hook_configure) &&
2916 (shell->showing_input_panels)) {
2917 wl_list_insert(&shell->panel_layer.link,
2918 &shell->input_panel_layer.link);
2919 wl_list_insert(&shell->input_panel_layer.link,
2922 wl_list_insert(&shell->panel_layer.link, &ws->layer.link);
2925 restore_focus_state(shell, get_current_workspace(shell));
2927 shell->locked = false;
2928 shell_fade(shell, FADE_IN);
2929 weston_compositor_damage_all(shell->compositor);
2933 desktop_shell_unlock(struct wl_client *client,
2934 struct wl_resource *resource)
2936 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2938 shell->prepare_event_sent = false;
2941 resume_desktop(shell);
2945 desktop_shell_set_grab_surface(struct wl_client *client,
2946 struct wl_resource *resource,
2947 struct wl_resource *surface_resource)
2949 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2951 shell->grab_surface = wl_resource_get_user_data(surface_resource);
2955 desktop_shell_desktop_ready(struct wl_client *client,
2956 struct wl_resource *resource)
2958 struct desktop_shell *shell = wl_resource_get_user_data(resource);
2960 shell_fade_startup(shell);
2963 static const struct desktop_shell_interface desktop_shell_implementation = {
2964 desktop_shell_set_background,
2965 desktop_shell_set_panel,
2966 desktop_shell_set_lock_surface,
2967 desktop_shell_unlock,
2968 desktop_shell_set_grab_surface,
2969 desktop_shell_desktop_ready
2972 static enum shell_surface_type
2973 get_shell_surface_type(struct weston_surface *surface)
2975 struct shell_surface *shsurf;
2977 shsurf = get_shell_surface(surface);
2979 return SHELL_SURFACE_NONE;
2980 return shsurf->type;
2984 move_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
2986 struct weston_surface *focus =
2987 (struct weston_surface *) seat->pointer->focus;
2988 struct weston_surface *surface;
2989 struct shell_surface *shsurf;
2991 surface = weston_surface_get_main_surface(focus);
2992 if (surface == NULL)
2995 shsurf = get_shell_surface(surface);
2996 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
2997 shsurf->type == SHELL_SURFACE_MAXIMIZED)
3000 surface_move(shsurf, (struct weston_seat *) seat);
3004 touch_move_binding(struct weston_seat *seat, uint32_t time, void *data)
3006 struct weston_surface *focus =
3007 (struct weston_surface *) seat->touch->focus;
3008 struct weston_surface *surface;
3009 struct shell_surface *shsurf;
3011 surface = weston_surface_get_main_surface(focus);
3012 if (surface == NULL)
3015 shsurf = get_shell_surface(surface);
3016 if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
3017 shsurf->type == SHELL_SURFACE_MAXIMIZED)
3020 surface_touch_move(shsurf, (struct weston_seat *) seat);
3024 resize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data)
3026 struct weston_surface *focus =
3027 (struct weston_surface *) seat->pointer->focus;
3028 struct weston_surface *surface;
3031 struct shell_surface *shsurf;
3033 surface = weston_surface_get_main_surface(focus);
3034 if (surface == NULL)
3037 shsurf = get_shell_surface(surface);
3038 if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN ||
3039 shsurf->type == SHELL_SURFACE_MAXIMIZED)
3042 weston_surface_from_global(surface,
3043 wl_fixed_to_int(seat->pointer->grab_x),
3044 wl_fixed_to_int(seat->pointer->grab_y),
3047 if (x < surface->geometry.width / 3)
3048 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
3049 else if (x < 2 * surface->geometry.width / 3)
3052 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
3054 if (y < surface->geometry.height / 3)
3055 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
3056 else if (y < 2 * surface->geometry.height / 3)
3059 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
3061 surface_resize(shsurf, (struct weston_seat *) seat, edges);
3065 surface_opacity_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
3066 wl_fixed_t value, void *data)
3069 struct shell_surface *shsurf;
3070 struct weston_surface *focus =
3071 (struct weston_surface *) seat->pointer->focus;
3072 struct weston_surface *surface;
3074 /* XXX: broken for windows containing sub-surfaces */
3075 surface = weston_surface_get_main_surface(focus);
3076 if (surface == NULL)
3079 shsurf = get_shell_surface(surface);
3083 surface->alpha -= wl_fixed_to_double(value) * step;
3085 if (surface->alpha > 1.0)
3086 surface->alpha = 1.0;
3087 if (surface->alpha < step)
3088 surface->alpha = step;
3090 weston_surface_geometry_dirty(surface);
3091 weston_surface_damage(surface);
3095 do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
3098 struct weston_seat *ws = (struct weston_seat *) seat;
3099 struct weston_compositor *compositor = ws->compositor;
3100 struct weston_output *output;
3103 wl_list_for_each(output, &compositor->output_list, link) {
3104 if (pixman_region32_contains_point(&output->region,
3105 wl_fixed_to_double(seat->pointer->x),
3106 wl_fixed_to_double(seat->pointer->y),
3108 if (key == KEY_PAGEUP)
3109 increment = output->zoom.increment;
3110 else if (key == KEY_PAGEDOWN)
3111 increment = -output->zoom.increment;
3112 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
3113 /* For every pixel zoom 20th of a step */
3114 increment = output->zoom.increment *
3115 -wl_fixed_to_double(value) / 20.0;
3119 output->zoom.level += increment;
3121 if (output->zoom.level < 0.0)
3122 output->zoom.level = 0.0;
3123 else if (output->zoom.level > output->zoom.max_level)
3124 output->zoom.level = output->zoom.max_level;
3125 else if (!output->zoom.active) {
3126 output->zoom.active = 1;
3127 output->disable_planes++;
3130 output->zoom.spring_z.target = output->zoom.level;
3132 weston_output_update_zoom(output, output->zoom.type);
3138 zoom_axis_binding(struct weston_seat *seat, uint32_t time, uint32_t axis,
3139 wl_fixed_t value, void *data)
3141 do_zoom(seat, time, 0, axis, value);
3145 zoom_key_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
3148 do_zoom(seat, time, key, 0, 0);
3152 terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
3155 struct weston_compositor *compositor = data;
3157 wl_display_terminate(compositor->wl_display);
3161 rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time)
3163 struct rotate_grab *rotate =
3164 container_of(grab, struct rotate_grab, base.grab);
3165 struct weston_pointer *pointer = grab->pointer;
3166 struct shell_surface *shsurf = rotate->base.shsurf;
3167 struct weston_surface *surface;
3168 float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
3173 surface = shsurf->surface;
3175 cx = 0.5f * surface->geometry.width;
3176 cy = 0.5f * surface->geometry.height;
3178 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
3179 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
3180 r = sqrtf(dx * dx + dy * dy);
3182 wl_list_remove(&shsurf->rotation.transform.link);
3183 weston_surface_geometry_dirty(shsurf->surface);
3186 struct weston_matrix *matrix =
3187 &shsurf->rotation.transform.matrix;
3189 weston_matrix_init(&rotate->rotation);
3190 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
3192 weston_matrix_init(matrix);
3193 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
3194 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
3195 weston_matrix_multiply(matrix, &rotate->rotation);
3196 weston_matrix_translate(matrix, cx, cy, 0.0f);
3199 &shsurf->surface->geometry.transformation_list,
3200 &shsurf->rotation.transform.link);
3202 wl_list_init(&shsurf->rotation.transform.link);
3203 weston_matrix_init(&shsurf->rotation.rotation);
3204 weston_matrix_init(&rotate->rotation);
3207 /* We need to adjust the position of the surface
3208 * in case it was resized in a rotated state before */
3209 cposx = surface->geometry.x + cx;
3210 cposy = surface->geometry.y + cy;
3211 dposx = rotate->center.x - cposx;
3212 dposy = rotate->center.y - cposy;
3213 if (dposx != 0.0f || dposy != 0.0f) {
3214 weston_surface_set_position(surface,
3215 surface->geometry.x + dposx,
3216 surface->geometry.y + dposy);
3219 /* Repaint implies weston_surface_update_transform(), which
3220 * lazily applies the damage due to rotation update.
3222 weston_compositor_schedule_repaint(shsurf->surface->compositor);
3226 rotate_grab_button(struct weston_pointer_grab *grab,
3227 uint32_t time, uint32_t button, uint32_t state_w)
3229 struct rotate_grab *rotate =
3230 container_of(grab, struct rotate_grab, base.grab);
3231 struct weston_pointer *pointer = grab->pointer;
3232 struct shell_surface *shsurf = rotate->base.shsurf;
3233 enum wl_pointer_button_state state = state_w;
3235 if (pointer->button_count == 0 &&
3236 state == WL_POINTER_BUTTON_STATE_RELEASED) {
3238 weston_matrix_multiply(&shsurf->rotation.rotation,
3240 shell_grab_end(&rotate->base);
3246 rotate_grab_cancel(struct weston_pointer_grab *grab)
3248 struct rotate_grab *rotate =
3249 container_of(grab, struct rotate_grab, base.grab);
3251 shell_grab_end(&rotate->base);
3255 static const struct weston_pointer_grab_interface rotate_grab_interface = {
3263 surface_rotate(struct shell_surface *surface, struct weston_seat *seat)
3265 struct rotate_grab *rotate;
3269 rotate = malloc(sizeof *rotate);
3273 weston_surface_to_global_float(surface->surface,
3274 surface->surface->geometry.width * 0.5f,
3275 surface->surface->geometry.height * 0.5f,
3276 &rotate->center.x, &rotate->center.y);
3278 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
3279 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
3280 r = sqrtf(dx * dx + dy * dy);
3282 struct weston_matrix inverse;
3284 weston_matrix_init(&inverse);
3285 weston_matrix_rotate_xy(&inverse, dx / r, -dy / r);
3286 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
3288 weston_matrix_init(&rotate->rotation);
3289 weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r);
3291 weston_matrix_init(&surface->rotation.rotation);
3292 weston_matrix_init(&rotate->rotation);
3295 shell_grab_start(&rotate->base, &rotate_grab_interface, surface,
3296 seat->pointer, DESKTOP_SHELL_CURSOR_ARROW);
3300 rotate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
3303 struct weston_surface *focus =
3304 (struct weston_surface *) seat->pointer->focus;
3305 struct weston_surface *base_surface;
3306 struct shell_surface *surface;
3308 base_surface = weston_surface_get_main_surface(focus);
3309 if (base_surface == NULL)
3312 surface = get_shell_surface(base_surface);
3313 if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN ||
3314 surface->type == SHELL_SURFACE_MAXIMIZED)
3317 surface_rotate(surface, seat);
3321 lower_fullscreen_layer(struct desktop_shell *shell)
3323 if (shell_hook_fullscreen) {
3324 (*shell_hook_fullscreen)(SHELL_FULLSCREEN_HIDEALL, NULL);
3328 struct workspace *ws;
3329 struct weston_surface *surface, *prev;
3331 ws = get_current_workspace(shell);
3332 wl_list_for_each_reverse_safe(surface, prev,
3333 &shell->fullscreen_layer.surface_list,
3335 weston_surface_restack(surface, &ws->layer.surface_list);
3339 activate(struct desktop_shell *shell, struct weston_surface *es,
3340 struct weston_seat *seat)
3342 struct weston_surface *main_surface;
3343 struct focus_state *state;
3344 struct workspace *ws;
3346 main_surface = weston_surface_get_main_surface(es);
3348 weston_surface_activate(es, seat);
3350 state = ensure_focus_state(shell, seat);
3354 state->keyboard_focus = es;
3355 wl_list_remove(&state->surface_destroy_listener.link);
3356 wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener);
3358 /* if ico_window_mgr hook, not change surface stack */
3359 if (shell_hook_select) {
3363 switch (get_shell_surface_type(main_surface)) {
3364 case SHELL_SURFACE_FULLSCREEN:
3365 /* should on top of panels */
3366 shell_stack_fullscreen(get_shell_surface(main_surface));
3367 shell_configure_fullscreen(get_shell_surface(main_surface));
3370 restore_all_output_modes(shell->compositor);
3371 ws = get_current_workspace(shell);
3372 weston_surface_restack(main_surface, &ws->layer.surface_list);
3377 /* no-op func for checking black surface */
3379 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
3384 is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
3386 if (es->configure == black_surface_configure) {
3388 *fs_surface = (struct weston_surface *)es->configure_private;
3395 activate_binding(struct weston_seat *seat,
3396 struct desktop_shell *shell,
3397 struct weston_surface *focus)
3399 struct weston_surface *main_surface;
3404 if (is_black_surface(focus, &main_surface))
3405 focus = main_surface;
3407 main_surface = weston_surface_get_main_surface(focus);
3408 if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE)
3411 activate(shell, focus, seat);
3413 /* if ico_window_mgr hook, call hook routine */
3414 if (shell_hook_select) {
3415 (*shell_hook_select)(focus);
3420 click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button,
3423 if (seat->pointer->grab != &seat->pointer->default_grab)
3426 activate_binding(seat, data,
3427 (struct weston_surface *) seat->pointer->focus);
3431 touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data)
3433 if (seat->touch->grab != &seat->touch->default_grab)
3436 activate_binding(seat, data,
3437 (struct weston_surface *) seat->touch->focus);
3441 lock(struct desktop_shell *shell)
3443 struct workspace *ws = get_current_workspace(shell);
3445 if (shell->locked) {
3446 weston_compositor_sleep(shell->compositor);
3450 shell->locked = true;
3452 /* Hide all surfaces by removing the fullscreen, panel and
3453 * toplevel layers. This way nothing else can show or receive
3454 * input events while we are locked. */
3456 wl_list_remove(&shell->panel_layer.link);
3457 wl_list_remove(&shell->fullscreen_layer.link);
3458 if ((! shell_hook_configure) &&
3459 (shell->showing_input_panels))
3460 wl_list_remove(&shell->input_panel_layer.link);
3461 wl_list_remove(&ws->layer.link);
3462 wl_list_insert(&shell->compositor->cursor_layer.link,
3463 &shell->lock_layer.link);
3465 launch_screensaver(shell);
3467 /* TODO: disable bindings that should not work while locked. */
3469 /* All this must be undone in resume_desktop(). */
3473 unlock(struct desktop_shell *shell)
3475 if (!shell->locked || shell->lock_surface) {
3476 shell_fade(shell, FADE_IN);
3480 /* If desktop-shell client has gone away, unlock immediately. */
3481 if (!shell->child.desktop_shell) {
3482 resume_desktop(shell);
3486 if (shell->prepare_event_sent)
3489 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
3490 shell->prepare_event_sent = true;
3494 shell_fade_done(struct weston_surface_animation *animation, void *data)
3496 struct desktop_shell *shell = data;
3498 shell->fade.animation = NULL;
3500 switch (shell->fade.type) {
3502 weston_surface_destroy(shell->fade.surface);
3503 shell->fade.surface = NULL;
3511 static struct weston_surface *
3512 shell_fade_create_surface(struct desktop_shell *shell)
3514 struct weston_compositor *compositor = shell->compositor;
3515 struct weston_surface *surface;
3517 surface = weston_surface_create(compositor);
3521 uifw_debug("shell_fade_create_surface: configure %08x x/y=%d/%d w/h=%d/%d",
3522 (int)surface, 0, 0, 8192, 8192);
3523 weston_surface_configure(surface, 0, 0, 8192, 8192);
3524 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0);
3525 wl_list_insert(&compositor->fade_layer.surface_list,
3526 &surface->layer_link);
3527 pixman_region32_init(&surface->input);
3533 shell_fade(struct desktop_shell *shell, enum fade_type type)
3545 weston_log("shell: invalid fade type\n");
3549 shell->fade.type = type;
3551 if (shell->fade.surface == NULL) {
3552 shell->fade.surface = shell_fade_create_surface(shell);
3553 if (!shell->fade.surface)
3556 shell->fade.surface->alpha = 1.0 - tint;
3557 weston_surface_update_transform(shell->fade.surface);
3560 if (shell->fade.animation)
3561 weston_fade_update(shell->fade.animation, tint);
3563 shell->fade.animation =
3564 weston_fade_run(shell->fade.surface,
3565 1.0 - tint, tint, 300.0,
3566 shell_fade_done, shell);
3570 do_shell_fade_startup(void *data)
3572 struct desktop_shell *shell = data;
3574 if (shell->startup_animation_type == ANIMATION_FADE)
3575 shell_fade(shell, FADE_IN);
3576 else if (shell->startup_animation_type == ANIMATION_NONE) {
3577 weston_surface_destroy(shell->fade.surface);
3578 shell->fade.surface = NULL;
3583 shell_fade_startup(struct desktop_shell *shell)
3585 struct wl_event_loop *loop;
3587 if (!shell->fade.startup_timer)
3590 wl_event_source_remove(shell->fade.startup_timer);
3591 shell->fade.startup_timer = NULL;
3593 loop = wl_display_get_event_loop(shell->compositor->wl_display);
3594 wl_event_loop_add_idle(loop, do_shell_fade_startup, shell);
3598 fade_startup_timeout(void *data)
3600 struct desktop_shell *shell = data;
3602 shell_fade_startup(shell);
3607 shell_fade_init(struct desktop_shell *shell)
3609 /* Make compositor output all black, and wait for the desktop-shell
3610 * client to signal it is ready, then fade in. The timer triggers a
3611 * fade-in, in case the desktop-shell client takes too long.
3614 struct wl_event_loop *loop;
3616 if (shell->fade.surface != NULL) {
3617 weston_log("%s: warning: fade surface already exists\n",
3622 shell->fade.surface = shell_fade_create_surface(shell);
3623 if (!shell->fade.surface)
3626 weston_surface_update_transform(shell->fade.surface);
3627 weston_surface_damage(shell->fade.surface);
3629 loop = wl_display_get_event_loop(shell->compositor->wl_display);
3630 shell->fade.startup_timer =
3631 wl_event_loop_add_timer(loop, fade_startup_timeout, shell);
3632 wl_event_source_timer_update(shell->fade.startup_timer, 15000);
3636 idle_handler(struct wl_listener *listener, void *data)
3638 struct desktop_shell *shell =
3639 container_of(listener, struct desktop_shell, idle_listener);
3641 shell_fade(shell, FADE_OUT);
3642 /* lock() is called from shell_fade_done() */
3646 wake_handler(struct wl_listener *listener, void *data)
3648 struct desktop_shell *shell =
3649 container_of(listener, struct desktop_shell, wake_listener);
3655 show_input_panels(struct wl_listener *listener, void *data)
3657 struct desktop_shell *shell =
3658 container_of(listener, struct desktop_shell,
3659 show_input_panel_listener);
3660 struct input_panel_surface *surface, *next;
3661 struct weston_surface *ws;
3663 shell->text_input.surface = (struct weston_surface*)data;
3665 if (shell->showing_input_panels)
3668 uifw_debug("show_input_panels: input.surface=%08x", (int)shell->text_input.surface);
3670 shell->showing_input_panels = true;
3672 /* if ico_window_mgr hook, call hook routine */
3673 if (shell_hook_show_layer) {
3674 (*shell_hook_show_layer)(LAYER_TYPE_INPUTPANEL, 1, data);
3678 wl_list_insert(&shell->panel_layer.link,
3679 &shell->input_panel_layer.link);
3681 wl_list_for_each_safe(surface, next,
3682 &shell->input_panel.surfaces, link) {
3683 ws = surface->surface;
3684 if (!ws->buffer_ref.buffer)
3686 if (! shell_hook_configure) {
3687 wl_list_insert(&shell->input_panel_layer.surface_list,
3690 weston_surface_geometry_dirty(ws);
3691 weston_surface_update_transform(ws);
3692 weston_surface_damage(ws);
3693 weston_slide_run(ws, ws->geometry.height, 0, NULL, NULL);
3698 hide_input_panels(struct wl_listener *listener, void *data)
3700 struct desktop_shell *shell =
3701 container_of(listener, struct desktop_shell,
3702 hide_input_panel_listener);
3703 struct weston_surface *surface, *next;
3705 if (!shell->showing_input_panels)
3708 uifw_debug("hide_input_panels: input.surface=%08x", (int)shell->text_input.surface);
3710 shell->showing_input_panels = false;
3712 /* if ico_window_mgr hook, call hook routine */
3713 if (shell_hook_show_layer) {
3714 (*shell_hook_show_layer)(LAYER_TYPE_INPUTPANEL, 0, NULL);
3719 wl_list_remove(&shell->input_panel_layer.link);
3721 wl_list_for_each_safe(surface, next,
3722 &shell->input_panel_layer.surface_list, layer_link)
3723 weston_surface_unmap(surface);
3727 update_input_panels(struct wl_listener *listener, void *data)
3729 struct desktop_shell *shell =
3730 container_of(listener, struct desktop_shell,
3731 update_input_panel_listener);
3733 memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t));
3737 center_on_output(struct weston_surface *surface, struct weston_output *output)
3739 int32_t surf_x, surf_y, width, height;
3742 surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y, &width, &height);
3744 x = output->x + (output->width - width) / 2 - surf_x / 2;
3745 y = output->y + (output->height - height) / 2 - surf_y / 2;
3747 uifw_debug("center_on_output: %08x x/y=%d/%d w/h=%d/%d",
3748 (int)output, (int)x, (int)y, width, height);
3749 weston_surface_configure(surface, x, y, width, height);
3753 weston_surface_set_initial_position (struct weston_surface *surface,
3754 struct desktop_shell *shell)
3756 struct weston_compositor *compositor = shell->compositor;
3758 int range_x, range_y;
3759 int dx, dy, x, y, panel_height;
3760 struct weston_output *output, *target_output = NULL;
3761 struct weston_seat *seat;
3763 /* As a heuristic place the new window on the same output as the
3764 * pointer. Falling back to the output containing 0, 0.
3766 * TODO: Do something clever for touch too?
3768 wl_list_for_each(seat, &compositor->seat_list, link) {
3769 if (seat->pointer) {
3770 ix = wl_fixed_to_int(seat->pointer->x);
3771 iy = wl_fixed_to_int(seat->pointer->y);
3776 wl_list_for_each(output, &compositor->output_list, link) {
3777 if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) {
3778 target_output = output;
3783 if (!target_output) {
3784 weston_surface_set_position(surface, 10 + random() % 400,
3785 10 + random() % 400);
3786 uifw_debug("weston_surface_set_initial_position: no tagret");
3790 /* Valid range within output where the surface will still be onscreen.
3791 * If this is negative it means that the surface is bigger than
3794 panel_height = get_output_panel_height(shell, target_output);
3795 range_x = target_output->width - surface->geometry.width;
3796 range_y = (target_output->height - panel_height) -
3797 surface->geometry.height;
3800 dx = random() % range_x;
3806 dy = panel_height + random() % range_y;
3811 x = target_output->x + dx;
3812 y = target_output->y + dy;
3814 weston_surface_set_position (surface, x, y);
3818 map(struct desktop_shell *shell, struct weston_surface *surface,
3819 int32_t width, int32_t height, int32_t sx, int32_t sy)
3821 struct weston_compositor *compositor = shell->compositor;
3822 struct shell_surface *shsurf = get_shell_surface(surface);
3823 enum shell_surface_type surface_type = shsurf->type;
3824 struct weston_surface *parent;
3825 struct weston_seat *seat;
3826 struct workspace *ws;
3827 int panel_height = 0;
3828 int32_t surf_x, surf_y;
3830 uifw_trace("map: %08x sx/sy=%d/%d w/h=%d/%d type=%d",
3831 (int)surface, sx, sy, width, height, (int)surface_type);
3833 surface->geometry.width = width;
3834 surface->geometry.height = height;
3835 weston_surface_geometry_dirty(surface);
3837 /* initial positioning, see also configure() */
3839 switch (surface_type) {
3840 case SHELL_SURFACE_TOPLEVEL:
3841 uifw_debug("map: surface TOPLEVEL");
3842 weston_surface_set_initial_position(surface, shell);
3844 case SHELL_SURFACE_FULLSCREEN:
3845 uifw_debug("map: surface FULLSCREEN");
3846 center_on_output(surface, shsurf->fullscreen_output);
3847 shell_map_fullscreen(shsurf);
3849 case SHELL_SURFACE_MAXIMIZED:
3850 uifw_debug("map: surface MAXIMIZED");
3851 /* use surface configure to set the geometry */
3852 panel_height = get_output_panel_height(shell,surface->output);
3853 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
3855 weston_surface_set_position(surface, shsurf->output->x - surf_x,
3856 shsurf->output->y + panel_height - surf_y);
3858 case SHELL_SURFACE_POPUP:
3859 uifw_debug("map: surface POPUP");
3860 shell_map_popup(shsurf);
3862 case SHELL_SURFACE_NONE:
3863 uifw_debug("map: surface NONE");
3864 if (shsurf->layertype == LAYER_TYPE_INPUTPANEL) {
3865 weston_surface_set_initial_position(surface, shell);
3868 weston_surface_set_position(surface,
3869 surface->geometry.x + sx,
3870 surface->geometry.y + sy);
3874 uifw_debug("map: surface unknown type(%d)", surface_type);
3878 /* surface stacking order, see also activate() */
3879 switch (surface_type) {
3880 case SHELL_SURFACE_POPUP:
3881 case SHELL_SURFACE_TRANSIENT:
3882 parent = shsurf->parent;
3883 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
3885 case SHELL_SURFACE_FULLSCREEN:
3886 case SHELL_SURFACE_NONE:
3888 case SHELL_SURFACE_XWAYLAND:
3890 ws = get_current_workspace(shell);
3891 wl_list_insert(&ws->layer.surface_list, &surface->layer_link);
3895 if (surface_type != SHELL_SURFACE_NONE) {
3896 weston_surface_update_transform(surface);
3897 if (surface_type == SHELL_SURFACE_MAXIMIZED)
3898 surface->output = shsurf->output;
3901 switch (surface_type) {
3902 /* XXX: xwayland's using the same fields for transient type */
3903 case SHELL_SURFACE_XWAYLAND:
3904 case SHELL_SURFACE_TRANSIENT:
3905 if (shsurf->transient.flags ==
3906 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
3908 case SHELL_SURFACE_TOPLEVEL:
3909 case SHELL_SURFACE_FULLSCREEN:
3910 case SHELL_SURFACE_MAXIMIZED:
3911 if (!shell->locked) {
3912 wl_list_for_each(seat, &compositor->seat_list, link)
3913 activate(shell, surface, seat);
3920 if (surface_type == SHELL_SURFACE_TOPLEVEL)
3922 switch (shell->win_animation_type) {
3923 case ANIMATION_FADE:
3924 weston_fade_run(surface, 0.0, 1.0, 300.0, NULL, NULL);
3926 case ANIMATION_ZOOM:
3927 weston_zoom_run(surface, 0.5, 1.0, NULL, NULL);
3934 /* if ico_window_mgr hook, call hook routine */
3935 if (shell_hook_map) {
3936 sx = surface->geometry.x;
3937 sy = surface->geometry.y;
3938 (*shell_hook_map)(surface, &width, &height, &sx, &sy);
3940 if (shell_hook_configure) {
3941 (*shell_hook_configure)(surface); /* send event to manager */
3946 configure(struct desktop_shell *shell, struct weston_surface *surface,
3947 float x, float y, int32_t width, int32_t height)
3949 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
3950 struct shell_surface *shsurf;
3951 int32_t surf_x, surf_y;
3953 shsurf = get_shell_surface(surface);
3955 surface_type = shsurf->type;
3957 uifw_trace("configure: %08x x/y=%d/%d w/h=%d/%d",
3958 (int)surface, (int)x, (int)y, width, height);
3959 weston_surface_configure(surface, x, y, width, height);
3961 switch (surface_type) {
3962 case SHELL_SURFACE_FULLSCREEN:
3963 shell_stack_fullscreen(shsurf);
3964 shell_configure_fullscreen(shsurf);
3966 case SHELL_SURFACE_MAXIMIZED:
3967 /* setting x, y and using configure to change that geometry */
3968 surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y,
3970 surface->geometry.x = surface->output->x - surf_x;
3971 surface->geometry.y = surface->output->y +
3972 get_output_panel_height(shell,surface->output) - surf_y;
3974 case SHELL_SURFACE_TOPLEVEL:
3980 /* XXX: would a fullscreen surface need the same handling? */
3981 if (surface->output) {
3982 weston_surface_update_transform(surface);
3984 if (surface_type == SHELL_SURFACE_MAXIMIZED)
3985 surface->output = shsurf->output;
3988 /* if ico_window_mgr hook, call hook routine */
3989 if (shell_hook_configure) {
3990 (*shell_hook_configure)(surface);
3995 shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height)
3997 struct shell_surface *shsurf = get_shell_surface(es);
3998 struct desktop_shell *shell = shsurf->shell;
4000 int type_changed = 0;
4002 if (!weston_surface_is_mapped(es) &&
4003 !wl_list_empty(&shsurf->popup.grab_link)) {
4004 remove_popup_grab(shsurf);
4010 if (shsurf->next_type != SHELL_SURFACE_NONE &&
4011 shsurf->type != shsurf->next_type) {
4012 set_surface_type(shsurf);
4016 if (!weston_surface_is_mapped(es)) {
4017 map(shell, es, width, height, sx, sy);
4018 } else if (type_changed || sx != 0 || sy != 0 ||
4019 es->geometry.width != width ||
4020 es->geometry.height != height) {
4021 float from_x, from_y;
4024 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
4025 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
4026 uifw_trace("shell_surface_configure: configure %08x x/y=%d/%d w/h=%d/%d",
4027 (int)es, (int)(es->geometry.x + to_x - from_x),
4028 (int)(es->geometry.y + to_y - from_y), width, height);
4029 configure(shell, es,
4030 es->geometry.x + to_x - from_x,
4031 es->geometry.y + to_y - from_y,
4036 static void launch_desktop_shell_process(void *data);
4039 desktop_shell_sigchld(struct weston_process *process, int status)
4042 struct desktop_shell *shell =
4043 container_of(process, struct desktop_shell, child.process);
4045 shell->child.process.pid = 0;
4046 shell->child.client = NULL; /* already destroyed by wayland */
4048 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
4049 time = weston_compositor_get_time();
4050 if (time - shell->child.deathstamp > 30000) {
4051 shell->child.deathstamp = time;
4052 shell->child.deathcount = 0;
4055 shell->child.deathcount++;
4056 if (shell->child.deathcount > 5) {
4057 weston_log("%s died, giving up.\n", shell_exe);
4061 weston_log("%s died, respawning...\n", shell_exe);
4062 launch_desktop_shell_process(shell);
4063 shell_fade_startup(shell);
4067 launch_desktop_shell_process(void *data)
4069 struct desktop_shell *shell = data;
4070 /* shell program path configurable for ico-ivi */
4071 /* const char *shell_exe = LIBEXECDIR "/weston-desktop-shell"; */
4073 if ((shell_exe[0] == 0) || (shell_exe[0] == ' ')) {
4074 weston_log("no shell program\n");
4077 uifw_trace("launch_desktop_shell_process: launch %s", shell_exe);
4078 shell->child.client = weston_client_launch(shell->compositor,
4079 &shell->child.process,
4081 desktop_shell_sigchld);
4083 if (!shell->child.client)
4084 weston_log("not able to start %s\n", shell_exe);
4086 weston_log("shell %s started\n", shell_exe);
4091 bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
4093 struct desktop_shell *shell = data;
4094 struct wl_resource *resource;
4096 resource = wl_resource_create(client, &wl_shell_interface, 1, id);
4098 wl_resource_set_implementation(resource, &shell_implementation,
4101 /* if ico_window_mgr hook, call hook routine */
4102 if (shell_hook_bind) {
4103 (*shell_hook_bind)(client, data);
4108 unbind_desktop_shell(struct wl_resource *resource)
4110 struct desktop_shell *shell = wl_resource_get_user_data(resource);
4112 /* if ico_window_mgr hook, call hook routine */
4113 if (shell_hook_unbind) {
4114 (*shell_hook_unbind)(resource->client);
4118 resume_desktop(shell);
4120 shell->child.desktop_shell = NULL;
4121 shell->prepare_event_sent = false;
4125 bind_desktop_shell(struct wl_client *client,
4126 void *data, uint32_t version, uint32_t id)
4128 struct desktop_shell *shell = data;
4129 struct wl_resource *resource;
4131 resource = wl_resource_create(client, &desktop_shell_interface,
4132 MIN(version, 2), id);
4134 if (client == shell->child.client) {
4135 wl_resource_set_implementation(resource,
4136 &desktop_shell_implementation,
4137 shell, unbind_desktop_shell);
4138 shell->child.desktop_shell = resource;
4141 shell_fade_startup(shell);
4145 weston_log("bind_desktop_shell: client=%08x shell=%08x\n", (int)client, (int)shell->child.client);
4147 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
4148 "permission to bind desktop_shell denied");
4149 wl_resource_destroy(resource);
4153 screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
4155 struct desktop_shell *shell = surface->configure_private;
4160 /* XXX: starting weston-screensaver beforehand does not work */
4164 center_on_output(surface, surface->output);
4166 if (wl_list_empty(&surface->layer_link)) {
4167 wl_list_insert(shell->lock_layer.surface_list.prev,
4168 &surface->layer_link);
4169 weston_surface_update_transform(surface);
4170 wl_event_source_timer_update(shell->screensaver.timer,
4171 shell->screensaver.duration);
4172 shell_fade(shell, FADE_IN);
4177 screensaver_set_surface(struct wl_client *client,
4178 struct wl_resource *resource,
4179 struct wl_resource *surface_resource,
4180 struct wl_resource *output_resource)
4182 struct desktop_shell *shell = wl_resource_get_user_data(resource);
4183 struct weston_surface *surface =
4184 wl_resource_get_user_data(surface_resource);
4185 struct weston_output *output = wl_resource_get_user_data(output_resource);
4187 surface->configure = screensaver_configure;
4188 surface->configure_private = shell;
4189 surface->output = output;
4192 static const struct screensaver_interface screensaver_implementation = {
4193 screensaver_set_surface
4197 unbind_screensaver(struct wl_resource *resource)
4199 struct desktop_shell *shell = wl_resource_get_user_data(resource);
4201 shell->screensaver.binding = NULL;
4205 bind_screensaver(struct wl_client *client,
4206 void *data, uint32_t version, uint32_t id)
4208 struct desktop_shell *shell = data;
4209 struct wl_resource *resource;
4211 resource = wl_resource_create(client, &screensaver_interface, 1, id);
4213 if (shell->screensaver.binding == NULL) {
4214 wl_resource_set_implementation(resource,
4215 &screensaver_implementation,
4216 shell, unbind_screensaver);
4217 shell->screensaver.binding = resource;
4221 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
4222 "interface object already bound");
4223 wl_resource_destroy(resource);
4227 input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
4229 struct input_panel_surface *ip_surface = surface->configure_private;
4230 struct desktop_shell *shell = ip_surface->shell;
4232 uint32_t show_surface = 0;
4235 uifw_debug("input_panel_configure: configure %08x width=0, Skip", (int)surface);
4238 if (!weston_surface_is_mapped(surface)) {
4239 if (!shell->showing_input_panels) {
4240 uifw_debug("input_panel_configure: configure %08x not show, Skip", (int)surface);
4246 if (ip_surface->panel) {
4247 x = shell->text_input.surface->geometry.x + shell->text_input.cursor_rectangle.x2;
4248 y = shell->text_input.surface->geometry.y + shell->text_input.cursor_rectangle.y2;
4250 x = ip_surface->output->x + (ip_surface->output->width - width) / 2;
4251 y = ip_surface->output->y + ip_surface->output->height - height;
4252 if (! shell_hook_map) {
4257 uifw_debug("input_panel_configure: configure %08x x/y=%d/%d w/h=%d/%d",
4258 (int)surface, (int)x, (int)y, width, height);
4259 weston_surface_configure(surface,
4264 /* if ico_window_mgr hook, call hook routine */
4265 if (! shell_hook_configure) {
4266 wl_list_insert(&shell->input_panel_layer.surface_list,
4267 &surface->layer_link);
4269 weston_surface_update_transform(surface);
4270 weston_surface_damage(surface);
4271 weston_slide_run(surface, surface->geometry.height, 0, NULL, NULL);
4274 /* if ico_window_mgr hook, call hook routine */
4275 /* set default color and shader because weston original bug(some time crash weston) */
4276 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
4277 if (shell_hook_map) {
4281 (*shell_hook_map)(surface, &width, &height, &wx, &wy);
4283 if (shell_hook_configure) {
4284 (*shell_hook_configure)(surface);
4289 destroy_input_panel_surface(struct input_panel_surface *input_panel_surface)
4291 uifw_debug("destroy_input_panel_surface: ");
4292 if (shell_hook_create) {
4296 wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface);
4298 wl_list_remove(&input_panel_surface->surface_destroy_listener.link);
4299 wl_list_remove(&input_panel_surface->link);
4301 input_panel_surface->surface->configure = NULL;
4303 free(input_panel_surface);
4306 static struct input_panel_surface *
4307 get_input_panel_surface(struct weston_surface *surface)
4309 if (surface->configure == input_panel_configure) {
4310 return surface->configure_private;
4317 input_panel_handle_surface_destroy(struct wl_listener *listener, void *data)
4319 uifw_debug("input_panel_handle_surface_destroy: ");
4320 if (shell_hook_create) {
4324 struct input_panel_surface *ipsurface = container_of(listener,
4325 struct input_panel_surface,
4326 surface_destroy_listener);
4328 if (ipsurface->resource) {
4329 wl_resource_destroy(ipsurface->resource);
4331 destroy_input_panel_surface(ipsurface);
4335 static struct input_panel_surface *
4336 create_input_panel_surface(struct desktop_shell *shell,
4337 struct weston_surface *surface)
4339 uifw_debug("create_input_panel_surface: ");
4340 if (shell_hook_create) {
4344 struct input_panel_surface *input_panel_surface;
4346 input_panel_surface = calloc(1, sizeof *input_panel_surface);
4347 if (!input_panel_surface)
4350 surface->configure = input_panel_configure;
4351 surface->configure_private = input_panel_surface;
4353 input_panel_surface->shell = shell;
4355 input_panel_surface->surface = surface;
4357 wl_signal_init(&input_panel_surface->destroy_signal);
4358 input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy;
4359 wl_signal_add(&surface->destroy_signal,
4360 &input_panel_surface->surface_destroy_listener);
4362 wl_list_init(&input_panel_surface->link);
4364 return input_panel_surface;
4368 input_panel_surface_set_toplevel(struct wl_client *client,
4369 struct wl_resource *resource,
4370 struct wl_resource *output_resource,
4373 uifw_debug("input_panel_surface_set_toplevel: ");
4374 if (shell_hook_create) {
4378 struct input_panel_surface *input_panel_surface =
4379 wl_resource_get_user_data(resource);
4380 struct desktop_shell *shell = input_panel_surface->shell;
4382 wl_list_insert(&shell->input_panel.surfaces,
4383 &input_panel_surface->link);
4385 input_panel_surface->output = wl_resource_get_user_data(output_resource);
4386 input_panel_surface->panel = 0;
4390 input_panel_surface_set_overlay_panel(struct wl_client *client,
4391 struct wl_resource *resource)
4393 uifw_debug("input_panel_surface_set_overlay_panel: ");
4394 if (shell_hook_create) {
4398 struct input_panel_surface *input_panel_surface =
4399 wl_resource_get_user_data(resource);
4400 struct desktop_shell *shell = input_panel_surface->shell;
4402 wl_list_insert(&shell->input_panel.surfaces,
4403 &input_panel_surface->link);
4405 input_panel_surface->panel = 1;
4408 static const struct wl_input_panel_surface_interface input_panel_surface_implementation = {
4409 input_panel_surface_set_toplevel,
4410 input_panel_surface_set_overlay_panel
4414 destroy_input_panel_surface_resource(struct wl_resource *resource)
4416 struct input_panel_surface *ipsurf =
4417 wl_resource_get_user_data(resource);
4419 destroy_input_panel_surface(ipsurf);
4423 input_panel_get_input_panel_surface(struct wl_client *client,
4424 struct wl_resource *resource,
4426 struct wl_resource *surface_resource)
4428 if (shell_hook_create) {
4429 uifw_debug("input_panel_get_input_panel_surface: weston_surface=%08x",
4430 (int)wl_resource_get_user_data(surface_resource));
4432 shell_get_shell_surface_layertype(LAYER_TYPE_INPUTPANEL,
4433 client, resource, id, surface_resource);
4436 struct weston_surface *surface =
4437 wl_resource_get_user_data(surface_resource);
4438 struct desktop_shell *shell = wl_resource_get_user_data(resource);
4439 struct input_panel_surface *ipsurf;
4441 if (get_input_panel_surface(surface)) {
4442 wl_resource_post_error(surface_resource,
4443 WL_DISPLAY_ERROR_INVALID_OBJECT,
4444 "wl_input_panel::get_input_panel_surface already requested");
4448 ipsurf = create_input_panel_surface(shell, surface);
4450 wl_resource_post_error(surface_resource,
4451 WL_DISPLAY_ERROR_INVALID_OBJECT,
4452 "surface->configure already set");
4455 uifw_debug("input_panel_get_input_panel_surface: weston_surface=%08x", (int)surface);
4458 wl_resource_create(client,
4459 &wl_input_panel_surface_interface, 1, id);
4460 wl_resource_set_implementation(ipsurf->resource,
4461 &input_panel_surface_implementation,
4463 destroy_input_panel_surface_resource);
4467 static const struct wl_input_panel_interface input_panel_implementation = {
4468 input_panel_get_input_panel_surface
4472 unbind_input_panel(struct wl_resource *resource)
4474 struct desktop_shell *shell = wl_resource_get_user_data(resource);
4476 shell->input_panel.binding = NULL;
4480 bind_input_panel(struct wl_client *client,
4481 void *data, uint32_t version, uint32_t id)
4483 struct desktop_shell *shell = data;
4484 struct wl_resource *resource;
4486 resource = wl_resource_create(client,
4487 &wl_input_panel_interface, 1, id);
4489 if (shell->input_panel.binding == NULL) {
4490 wl_resource_set_implementation(resource,
4491 &input_panel_implementation,
4492 shell, unbind_input_panel);
4493 shell->input_panel.binding = resource;
4497 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
4498 "interface object already bound");
4499 wl_resource_destroy(resource);
4503 struct desktop_shell *shell;
4504 struct weston_surface *current;
4505 struct wl_listener listener;
4506 struct weston_keyboard_grab grab;
4510 switcher_next(struct switcher *switcher)
4512 struct weston_surface *surface;
4513 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
4514 struct shell_surface *shsurf;
4515 struct workspace *ws = get_current_workspace(switcher->shell);
4517 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
4518 switch (get_shell_surface_type(surface)) {
4519 case SHELL_SURFACE_TOPLEVEL:
4520 case SHELL_SURFACE_FULLSCREEN:
4521 case SHELL_SURFACE_MAXIMIZED:
4524 if (prev == switcher->current)
4527 surface->alpha = 0.25;
4528 weston_surface_geometry_dirty(surface);
4529 weston_surface_damage(surface);
4535 if (is_black_surface(surface, NULL)) {
4536 surface->alpha = 0.25;
4537 weston_surface_geometry_dirty(surface);
4538 weston_surface_damage(surface);
4548 wl_list_remove(&switcher->listener.link);
4549 wl_signal_add(&next->destroy_signal, &switcher->listener);
4551 switcher->current = next;
4554 shsurf = get_shell_surface(switcher->current);
4555 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
4556 shsurf->fullscreen.black_surface->alpha = 1.0;
4560 switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
4562 struct switcher *switcher =
4563 container_of(listener, struct switcher, listener);
4565 switcher_next(switcher);
4569 switcher_destroy(struct switcher *switcher)
4571 struct weston_surface *surface;
4572 struct weston_keyboard *keyboard = switcher->grab.keyboard;
4573 struct workspace *ws = get_current_workspace(switcher->shell);
4575 wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {
4576 surface->alpha = 1.0;
4577 weston_surface_damage(surface);
4580 if (switcher->current)
4581 activate(switcher->shell, switcher->current,
4582 (struct weston_seat *) keyboard->seat);
4583 wl_list_remove(&switcher->listener.link);
4584 weston_keyboard_end_grab(keyboard);
4585 if (keyboard->input_method_resource)
4586 keyboard->grab = &keyboard->input_method_grab;
4591 switcher_key(struct weston_keyboard_grab *grab,
4592 uint32_t time, uint32_t key, uint32_t state_w)
4594 struct switcher *switcher = container_of(grab, struct switcher, grab);
4595 enum wl_keyboard_key_state state = state_w;
4597 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
4598 switcher_next(switcher);
4602 switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial,
4603 uint32_t mods_depressed, uint32_t mods_latched,
4604 uint32_t mods_locked, uint32_t group)
4606 struct switcher *switcher = container_of(grab, struct switcher, grab);
4607 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
4609 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0)
4610 switcher_destroy(switcher);
4614 switcher_cancel(struct weston_keyboard_grab *grab)
4616 struct switcher *switcher = container_of(grab, struct switcher, grab);
4618 switcher_destroy(switcher);
4621 static const struct weston_keyboard_grab_interface switcher_grab = {
4628 switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
4631 struct desktop_shell *shell = data;
4632 struct switcher *switcher;
4634 switcher = malloc(sizeof *switcher);
4635 switcher->shell = shell;
4636 switcher->current = NULL;
4637 switcher->listener.notify = switcher_handle_surface_destroy;
4638 wl_list_init(&switcher->listener.link);
4640 restore_all_output_modes(shell->compositor);
4641 lower_fullscreen_layer(switcher->shell);
4642 switcher->grab.interface = &switcher_grab;
4643 weston_keyboard_start_grab(seat->keyboard, &switcher->grab);
4644 weston_keyboard_set_focus(seat->keyboard, NULL);
4645 switcher_next(switcher);
4649 backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
4652 struct weston_compositor *compositor = data;
4653 struct weston_output *output;
4654 long backlight_new = 0;
4656 /* TODO: we're limiting to simple use cases, where we assume just
4657 * control on the primary display. We'd have to extend later if we
4658 * ever get support for setting backlights on random desktop LCD
4660 output = get_default_output(compositor);
4664 if (!output->set_backlight)
4667 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
4668 backlight_new = output->backlight_current - 25;
4669 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
4670 backlight_new = output->backlight_current + 25;
4672 if (backlight_new < 5)
4674 if (backlight_new > 255)
4675 backlight_new = 255;
4677 output->backlight_current = backlight_new;
4678 output->set_backlight(output, output->backlight_current);
4681 struct debug_binding_grab {
4682 struct weston_keyboard_grab grab;
4683 struct weston_seat *seat;
4685 int key_released[2];
4689 debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time,
4690 uint32_t key, uint32_t state)
4692 struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
4693 struct weston_compositor *ec = db->seat->compositor;
4694 struct wl_display *display = ec->wl_display;
4695 struct wl_resource *resource;
4697 int send = 0, terminate = 0;
4698 int check_binding = 1;
4700 struct wl_list *resource_list;
4702 if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
4703 /* Do not run bindings on key releases */
4706 for (i = 0; i < 2; i++)
4707 if (key == db->key[i])
4708 db->key_released[i] = 1;
4710 if (db->key_released[0] && db->key_released[1]) {
4711 /* All key releases been swalled so end the grab */
4713 } else if (key != db->key[0] && key != db->key[1]) {
4714 /* Should not swallow release of other keys */
4717 } else if (key == db->key[0] && !db->key_released[0]) {
4718 /* Do not check bindings for the first press of the binding
4719 * key. This allows it to be used as a debug shortcut.
4720 * We still need to swallow this event. */
4722 } else if (db->key[1]) {
4723 /* If we already ran a binding don't process another one since
4724 * we can't keep track of all the binding keys that were
4725 * pressed in order to swallow the release events. */
4730 if (check_binding) {
4731 if (weston_compositor_run_debug_binding(ec, db->seat, time,
4733 /* We ran a binding so swallow the press and keep the
4734 * grab to swallow the released too. */
4739 /* Terminate the grab since the key pressed is not a
4740 * debug binding key. */
4747 serial = wl_display_next_serial(display);
4748 resource_list = &grab->keyboard->focus_resource_list;
4749 wl_resource_for_each(resource, resource_list) {
4750 wl_keyboard_send_key(resource, serial, time, key, state);
4755 weston_keyboard_end_grab(grab->keyboard);
4756 if (grab->keyboard->input_method_resource)
4757 grab->keyboard->grab = &grab->keyboard->input_method_grab;
4763 debug_binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial,
4764 uint32_t mods_depressed, uint32_t mods_latched,
4765 uint32_t mods_locked, uint32_t group)
4767 struct wl_resource *resource;
4768 struct wl_list *resource_list;
4770 resource_list = &grab->keyboard->focus_resource_list;
4772 wl_resource_for_each(resource, resource_list) {
4773 wl_keyboard_send_modifiers(resource, serial, mods_depressed,
4774 mods_latched, mods_locked, group);
4779 debug_binding_cancel(struct weston_keyboard_grab *grab)
4781 struct debug_binding_grab *db = (struct debug_binding_grab *) grab;
4783 weston_keyboard_end_grab(grab->keyboard);
4787 struct weston_keyboard_grab_interface debug_binding_keyboard_grab = {
4789 debug_binding_modifiers,
4790 debug_binding_cancel,
4794 debug_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
4796 struct debug_binding_grab *grab;
4798 grab = calloc(1, sizeof *grab);
4802 grab->seat = (struct weston_seat *) seat;
4804 grab->grab.interface = &debug_binding_keyboard_grab;
4805 weston_keyboard_start_grab(seat->keyboard, &grab->grab);
4809 force_kill_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
4812 struct weston_surface *focus_surface;
4813 struct wl_client *client;
4814 struct desktop_shell *shell = data;
4815 struct weston_compositor *compositor = shell->compositor;
4818 focus_surface = seat->keyboard->focus;
4822 wl_signal_emit(&compositor->kill_signal, focus_surface);
4824 client = wl_resource_get_client(focus_surface->resource);
4825 wl_client_get_credentials(client, &pid, NULL, NULL);
4827 /* Skip clients that we launched ourselves (the credentials of
4828 * the socketpair is ours) */
4829 if (pid == getpid())
4836 workspace_up_binding(struct weston_seat *seat, uint32_t time,
4837 uint32_t key, void *data)
4839 struct desktop_shell *shell = data;
4840 unsigned int new_index = shell->workspaces.current;
4847 change_workspace(shell, new_index);
4851 workspace_down_binding(struct weston_seat *seat, uint32_t time,
4852 uint32_t key, void *data)
4854 struct desktop_shell *shell = data;
4855 unsigned int new_index = shell->workspaces.current;
4859 if (new_index < shell->workspaces.num - 1)
4862 change_workspace(shell, new_index);
4866 workspace_f_binding(struct weston_seat *seat, uint32_t time,
4867 uint32_t key, void *data)
4869 struct desktop_shell *shell = data;
4870 unsigned int new_index;
4874 new_index = key - KEY_F1;
4875 if (new_index >= shell->workspaces.num)
4876 new_index = shell->workspaces.num - 1;
4878 change_workspace(shell, new_index);
4882 workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time,
4883 uint32_t key, void *data)
4885 struct desktop_shell *shell = data;
4886 unsigned int new_index = shell->workspaces.current;
4894 take_surface_to_workspace_by_seat(shell, seat, new_index);
4898 workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time,
4899 uint32_t key, void *data)
4901 struct desktop_shell *shell = data;
4902 unsigned int new_index = shell->workspaces.current;
4907 if (new_index < shell->workspaces.num - 1)
4910 take_surface_to_workspace_by_seat(shell, seat, new_index);
4914 shell_destroy(struct wl_listener *listener, void *data)
4916 struct desktop_shell *shell =
4917 container_of(listener, struct desktop_shell, destroy_listener);
4918 struct workspace **ws;
4920 if (shell->child.client)
4921 wl_client_destroy(shell->child.client);
4923 wl_list_remove(&shell->idle_listener.link);
4924 wl_list_remove(&shell->wake_listener.link);
4925 wl_list_remove(&shell->show_input_panel_listener.link);
4926 wl_list_remove(&shell->hide_input_panel_listener.link);
4928 wl_array_for_each(ws, &shell->workspaces.array)
4929 workspace_destroy(*ws);
4930 wl_array_release(&shell->workspaces.array);
4932 free(shell->screensaver.path);
4937 shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
4940 int i, num_workspace_bindings;
4942 /* fixed bindings */
4943 weston_compositor_add_key_binding(ec, KEY_BACKSPACE,
4944 MODIFIER_CTRL | MODIFIER_ALT,
4945 terminate_binding, ec);
4946 weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
4947 click_to_activate_binding,
4949 weston_compositor_add_touch_binding(ec, 0,
4950 touch_to_activate_binding,
4952 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
4953 MODIFIER_SUPER | MODIFIER_ALT,
4954 surface_opacity_binding, NULL);
4955 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
4956 MODIFIER_SUPER, zoom_axis_binding,
4959 /* configurable bindings */
4960 mod = shell->binding_modifier;
4961 weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod,
4962 zoom_key_binding, NULL);
4963 weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod,
4964 zoom_key_binding, NULL);
4965 weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding,
4967 weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell);
4968 weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod,
4969 resize_binding, shell);
4971 if (ec->capabilities & WESTON_CAP_ROTATION_ANY)
4972 weston_compositor_add_button_binding(ec, BTN_RIGHT, mod,
4973 rotate_binding, NULL);
4975 weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding,
4977 weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding,
4979 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0,
4980 backlight_binding, ec);
4981 weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding,
4983 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0,
4984 backlight_binding, ec);
4985 weston_compositor_add_key_binding(ec, KEY_K, mod,
4986 force_kill_binding, shell);
4987 weston_compositor_add_key_binding(ec, KEY_UP, mod,
4988 workspace_up_binding, shell);
4989 weston_compositor_add_key_binding(ec, KEY_DOWN, mod,
4990 workspace_down_binding, shell);
4991 weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT,
4992 workspace_move_surface_up_binding,
4994 weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT,
4995 workspace_move_surface_down_binding,
4998 /* Add bindings for mod+F[1-6] for workspace 1 to 6. */
4999 if (shell->workspaces.num > 1) {
5000 num_workspace_bindings = shell->workspaces.num;
5001 if (num_workspace_bindings > 6)
5002 num_workspace_bindings = 6;
5003 for (i = 0; i < num_workspace_bindings; i++)
5004 weston_compositor_add_key_binding(ec, KEY_F1 + i, mod,
5005 workspace_f_binding,
5009 /* Debug bindings */
5010 weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT,
5011 debug_binding, shell);
5015 module_init(struct weston_compositor *ec,
5016 int *argc, char *argv[])
5018 struct weston_seat *seat;
5019 struct desktop_shell *shell;
5020 struct workspace **pws;
5022 struct wl_event_loop *loop;
5024 shell = zalloc(sizeof *shell);
5028 /* save shell management table for other plugin */
5029 _ico_ivi_shell = shell;
5031 shell->compositor = ec;
5033 shell->destroy_listener.notify = shell_destroy;
5034 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
5035 shell->idle_listener.notify = idle_handler;
5036 wl_signal_add(&ec->idle_signal, &shell->idle_listener);
5037 shell->wake_listener.notify = wake_handler;
5038 wl_signal_add(&ec->wake_signal, &shell->wake_listener);
5039 shell->show_input_panel_listener.notify = show_input_panels;
5040 wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener);
5041 shell->hide_input_panel_listener.notify = hide_input_panels;
5042 wl_signal_add(&ec->hide_input_panel_signal, &shell->hide_input_panel_listener);
5043 shell->update_input_panel_listener.notify = update_input_panels;
5044 wl_signal_add(&ec->update_input_panel_signal, &shell->update_input_panel_listener);
5045 ec->ping_handler = ping_handler;
5046 ec->shell_interface.shell = shell;
5047 ec->shell_interface.create_shell_surface = create_shell_surface;
5048 ec->shell_interface.set_toplevel = set_toplevel;
5049 ec->shell_interface.set_transient = set_transient;
5050 ec->shell_interface.set_fullscreen = set_fullscreen;
5051 ec->shell_interface.set_xwayland = set_xwayland;
5052 ec->shell_interface.move = surface_move;
5053 ec->shell_interface.resize = surface_resize;
5054 ec->shell_interface.set_title = set_title;
5056 wl_list_init(&shell->input_panel.surfaces);
5058 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
5059 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
5060 weston_layer_init(&shell->background_layer, &shell->panel_layer.link);
5061 weston_layer_init(&shell->lock_layer, NULL);
5062 weston_layer_init(&shell->input_panel_layer, NULL);
5064 wl_array_init(&shell->workspaces.array);
5065 wl_list_init(&shell->workspaces.client_list);
5067 shell_configuration(shell);
5069 for (i = 0; i < shell->workspaces.num; i++) {
5070 pws = wl_array_add(&shell->workspaces.array, sizeof *pws);
5074 *pws = workspace_create();
5078 activate_workspace(shell, 0);
5080 wl_list_init(&shell->workspaces.anim_sticky_list);
5081 wl_list_init(&shell->workspaces.animation.link);
5082 shell->workspaces.animation.frame = animate_workspace_change_frame;
5084 if (wl_global_create(ec->wl_display, &wl_shell_interface, 1,
5085 shell, bind_shell) == NULL)
5088 if (wl_global_create(ec->wl_display,
5089 &desktop_shell_interface, 2,
5090 shell, bind_desktop_shell) == NULL)
5093 if (wl_global_create(ec->wl_display, &screensaver_interface, 1,
5094 shell, bind_screensaver) == NULL)
5097 if (wl_global_create(ec->wl_display, &wl_input_panel_interface, 1,
5098 shell, bind_input_panel) == NULL)
5101 if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1,
5102 shell, bind_workspace_manager) == NULL)
5105 shell->child.deathstamp = weston_compositor_get_time();
5107 loop = wl_display_get_event_loop(ec->wl_display);
5108 wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell);
5110 shell->screensaver.timer =
5111 wl_event_loop_add_timer(loop, screensaver_timeout, shell);
5113 wl_list_for_each(seat, &ec->seat_list, link)
5114 create_pointer_focus_listener(seat);
5116 shell_add_bindings(ec, shell);
5118 shell_fade_init(shell);
5123 /*--------------------------------------------------------------------------*/
5125 * @brief ico_ivi_shell_weston_layer: get weston layer
5128 * @return current weston layer
5129 * @retval !=NULL success(current weston layer)
5130 * @retval ==NULL error(no layer)
5132 /*--------------------------------------------------------------------------*/
5133 /* API for other plugin */
5134 WL_EXPORT struct weston_layer *
5135 ico_ivi_shell_weston_layer(void)
5137 return(&_ico_ivi_shell->panel_layer);
5140 /*--------------------------------------------------------------------------*/
5142 * @brief ico_ivi_shell_set_toplevel: set surface to TopLevel
5144 * @param[in] shsurf shell surface
5147 /*--------------------------------------------------------------------------*/
5149 ico_ivi_shell_set_toplevel(struct shell_surface *shsurf)
5151 set_toplevel(shsurf);
5154 /*--------------------------------------------------------------------------*/
5156 * @brief ico_ivi_shell_get_surfacetype: get surface type
5158 * @param[in] shsurf shell surface
5159 * @return surface type
5161 /*--------------------------------------------------------------------------*/
5163 ico_ivi_shell_get_surfacetype(struct shell_surface *shsurf)
5165 return (shsurf ? (int)shsurf->type : -1);
5168 /*--------------------------------------------------------------------------*/
5170 * @brief ico_ivi_shell_set_surface_type: set surface type
5172 * @param[in] shsurf shell surface
5175 /*--------------------------------------------------------------------------*/
5177 ico_ivi_shell_set_surface_type(struct shell_surface *shsurf)
5179 set_surface_type(shsurf);
5182 /*--------------------------------------------------------------------------*/
5184 * @brief ico_ivi_shell_send_configure: send configure event to client application
5186 * @param[in] surface weston surface
5187 * @param[in] edges surface resize position
5188 * @param[in] width surface width
5189 * @param[in] height surface height
5192 /*--------------------------------------------------------------------------*/
5194 ico_ivi_shell_send_configure(struct weston_surface *surface,
5195 const uint32_t edges, const int width, const int height)
5197 send_configure(surface, edges, width, height);
5200 /*--------------------------------------------------------------------------*/
5202 * @brief ico_ivi_shell_startup: start shell surface fade
5204 * @param[in] shell shell table address
5207 /*--------------------------------------------------------------------------*/
5209 ico_ivi_shell_startup(void *shell)
5211 shell_fade_startup((struct desktop_shell *)shell);
5214 /*--------------------------------------------------------------------------*/
5216 * @brief ico_ivi_shell_layertype: get layer type
5218 * @param[in] surface weston surface
5219 * @return layer type
5221 /*--------------------------------------------------------------------------*/
5223 ico_ivi_shell_layertype(struct weston_surface *surface)
5225 if (surface->configure == shell_surface_configure) {
5226 return ((struct shell_surface *)surface->configure_private)->layertype;
5228 return LAYER_TYPE_UNKNOWN;
5231 /*--------------------------------------------------------------------------*/
5233 * @brief ivi_shell_set_surface_initial_position: initialize surface position
5235 * @param[in] surface weston surface
5238 /*--------------------------------------------------------------------------*/
5240 ivi_shell_set_surface_initial_position(struct weston_surface *surface)
5242 weston_surface_set_initial_position (surface, _ico_ivi_shell);
5244 /*--------------------------------------------------------------------------*/
5246 * @brief ivi_shell_set_default_display: set default display
5248 * @param[in] inputpanel default display of input panel surface
5251 /*--------------------------------------------------------------------------*/
5253 ivi_shell_set_default_display(struct weston_output *inputpanel)
5255 default_inputpanel = inputpanel;
5258 /*--------------------------------------------------------------------------*/
5260 * @brief ico_ivi_shell_hook_bind: regist hook function for shell bind
5262 * @param[in] hook_bind hook function(if NULL, reset hook function)
5265 /*--------------------------------------------------------------------------*/
5267 ico_ivi_shell_hook_bind(void (*hook_bind)(struct wl_client *client, void *shell))
5269 shell_hook_bind = hook_bind;
5272 /*--------------------------------------------------------------------------*/
5274 * @brief ico_ivi_shell_hook_unbind: regist hook function for shell unbind
5276 * @param[in] hook_unbind hook function(if NULL, reset hook function)
5279 /*--------------------------------------------------------------------------*/
5281 ico_ivi_shell_hook_unbind(void (*hook_unbind)(struct wl_client *client))
5283 shell_hook_unbind = hook_unbind;
5286 /*--------------------------------------------------------------------------*/
5288 * @brief ico_ivi_shell_hook_create: regist hook function for create shell surface
5290 * @param[in] hook_create hook function(if NULL, reset hook function)
5293 /*--------------------------------------------------------------------------*/
5295 ico_ivi_shell_hook_create(void (*hook_create)(int layertype,
5296 struct wl_client *client,
5297 struct wl_resource *resource,
5298 struct weston_surface *surface,
5299 struct shell_surface *shsurf))
5301 shell_hook_create = hook_create;
5304 /*--------------------------------------------------------------------------*/
5306 * @brief ico_ivi_shell_hook_destroy: regist hook function for destroy shell surface
5308 * @param[in] hook_destroy hook function(if NULL, reset hook function)
5311 /*--------------------------------------------------------------------------*/
5313 ico_ivi_shell_hook_destroy(void (*hook_destroy)(struct weston_surface *surface))
5315 shell_hook_destroy = hook_destroy;
5318 /*--------------------------------------------------------------------------*/
5320 * @brief ico_ivi_shell_hook_map: regist hook function for map shell surface
5322 * @param[in] hook_map hook function(if NULL, reset hook function)
5325 /*--------------------------------------------------------------------------*/
5327 ico_ivi_shell_hook_map(void (*hook_map)(struct weston_surface *surface,
5328 int32_t *width, int32_t *height,
5329 int32_t *sx, int32_t *sy))
5331 shell_hook_map = hook_map;
5334 /*--------------------------------------------------------------------------*/
5336 * @brief ico_ivi_shell_hook_configure: regist hook function for configure shell surface
5338 * @param[in] hook_configure hook function(if NULL, reset hook function)
5341 /*--------------------------------------------------------------------------*/
5343 ico_ivi_shell_hook_configure(void (*hook_configure)(struct weston_surface *surface))
5345 shell_hook_configure = hook_configure;
5348 /*--------------------------------------------------------------------------*/
5350 * @brief ico_ivi_shell_hook_select: regist hook function for select(active) shell surface
5352 * @param[in] hook_select hook function(if NULL, reset hook function)
5355 /*--------------------------------------------------------------------------*/
5357 ico_ivi_shell_hook_select(void (*hook_select)(struct weston_surface *surface))
5359 shell_hook_select = hook_select;
5362 /*--------------------------------------------------------------------------*/
5364 * @brief ico_ivi_shell_hook_title: regist hook function for select(active) shell surface
5366 * @param[in] hook_title hook function(if NULL, reset hook function)
5369 /*--------------------------------------------------------------------------*/
5371 ico_ivi_shell_hook_title(char *(*hook_title)(struct weston_surface *surface,
5374 shell_hook_title = hook_title;
5377 /*--------------------------------------------------------------------------*/
5379 * @brief ico_ivi_shell_hook_move: regist hook function for move grab
5381 * @param[in] hook_move hook function(if NULL, reset hook function)
5382 * @param[in/out] dx new X coordinate
5383 * @param[in/out] dy new Y coordinate
5386 /*--------------------------------------------------------------------------*/
5388 ico_ivi_shell_hook_move(void (*hook_move)(struct weston_surface *surface, int *dx, int *dy))
5390 shell_hook_move = hook_move;
5393 /*--------------------------------------------------------------------------*/
5395 * @brief ico_ivi_shell_hook_show_layer: layer visible control
5397 * @param[in] hook_show hook function(if NULL, reset hook function)
5400 /*--------------------------------------------------------------------------*/
5402 ico_ivi_shell_hook_show_layer(void (*hook_show)(int layertype, int show, void *data))
5404 shell_hook_show_layer = hook_show;
5407 /*--------------------------------------------------------------------------*/
5409 * @brief ico_ivi_shell_hook_fullscreen: fullscreen surface control
5411 * @param[in] hook_fullscreen hook function(if NULL, reset hook function)
5414 /*--------------------------------------------------------------------------*/
5416 ico_ivi_shell_hook_fullscreen(int (*hook_fullscreen)
5417 (int event, struct weston_surface *surface))
5419 shell_hook_fullscreen = hook_fullscreen;