2 * Copyright © 2010-2012 Intel Corporation
3 * Copyright © 2011-2012 Collabora, Ltd.
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 #include <linux/input.h>
33 #include <sys/types.h>
35 #include <wayland-server.h>
36 #include "compositor.h"
37 #include "desktop-shell-server-protocol.h"
38 #include "../shared/config-parser.h"
47 struct desktop_shell {
48 struct weston_compositor *compositor;
50 struct wl_listener lock_listener;
51 struct wl_listener unlock_listener;
52 struct wl_listener destroy_listener;
54 struct weston_layer fullscreen_layer;
55 struct weston_layer panel_layer;
56 struct weston_layer toplevel_layer;
57 struct weston_layer background_layer;
58 struct weston_layer lock_layer;
60 struct wl_listener pointer_focus_listener;
61 struct weston_surface *busy_surface;
64 struct weston_process process;
65 struct wl_client *client;
66 struct wl_resource *desktop_shell;
73 bool prepare_event_sent;
75 struct shell_surface *lock_surface;
76 struct wl_listener lock_surface_listener;
78 struct wl_list backgrounds;
79 struct wl_list panels;
84 struct wl_resource *binding;
85 struct wl_list surfaces;
86 struct weston_process process;
89 uint32_t binding_modifier;
90 enum animation_type win_animation_type;
91 struct weston_surface *debug_repaint_surface;
94 enum shell_surface_type {
98 SHELL_SURFACE_BACKGROUND,
100 SHELL_SURFACE_SCREENSAVER,
102 SHELL_SURFACE_TOPLEVEL,
103 SHELL_SURFACE_TRANSIENT,
104 SHELL_SURFACE_FULLSCREEN,
105 SHELL_SURFACE_MAXIMIZED,
110 struct wl_event_source *source;
114 struct shell_surface {
115 struct wl_resource resource;
117 struct weston_surface *surface;
118 struct wl_listener surface_destroy_listener;
119 struct shell_surface *parent;
120 struct desktop_shell *shell;
122 enum shell_surface_type type, next_type;
124 int32_t saved_x, saved_y;
125 bool saved_position_valid;
126 bool saved_rotation_valid;
130 struct weston_transform transform;
131 struct weston_matrix rotation;
135 struct wl_pointer_grab grab;
137 struct weston_transform parent_transform;
139 struct wl_seat *seat;
149 enum wl_shell_surface_fullscreen_method type;
150 struct weston_transform transform; /* matrix from x, y */
152 struct weston_surface *black_surface;
155 struct ping_timer *ping_timer;
157 struct weston_output *fullscreen_output;
158 struct weston_output *output;
161 const struct weston_shell_client *client;
165 struct wl_pointer_grab grab;
166 struct shell_surface *shsurf;
167 struct wl_listener shsurf_destroy_listener;
170 struct weston_move_grab {
171 struct shell_grab base;
176 struct shell_grab base;
177 struct weston_matrix rotation;
184 static struct shell_surface *
185 get_shell_surface(struct weston_surface *surface);
187 static struct desktop_shell *
188 shell_surface_get_shell(struct shell_surface *shsurf);
191 shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
193 struct desktop_shell *shell;
194 struct weston_surface *top_fs_es;
196 shell = shell_surface_get_shell(shsurf);
198 if (wl_list_empty(&shell->fullscreen_layer.surface_list))
201 top_fs_es = container_of(shell->fullscreen_layer.surface_list.next,
202 struct weston_surface,
204 return (shsurf == get_shell_surface(top_fs_es));
208 destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
210 struct shell_grab *grab;
212 grab = container_of(listener, struct shell_grab,
213 shsurf_destroy_listener);
219 shell_grab_init(struct shell_grab *grab,
220 const struct wl_pointer_grab_interface *interface,
221 struct shell_surface *shsurf)
223 grab->grab.interface = interface;
224 grab->shsurf = shsurf;
225 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
226 wl_signal_add(&shsurf->resource.destroy_signal,
227 &grab->shsurf_destroy_listener);
232 shell_grab_finish(struct shell_grab *grab)
235 wl_list_remove(&grab->shsurf_destroy_listener.link);
239 center_on_output(struct weston_surface *surface,
240 struct weston_output *output);
242 static enum weston_keyboard_modifier
243 get_modifier(char *modifier)
246 return MODIFIER_SUPER;
248 if (!strcmp("ctrl", modifier))
249 return MODIFIER_CTRL;
250 else if (!strcmp("alt", modifier))
252 else if (!strcmp("super", modifier))
253 return MODIFIER_SUPER;
255 return MODIFIER_SUPER;
258 static enum animation_type
259 get_animation_type(char *animation)
262 return ANIMATION_NONE;
264 if (!strcmp("zoom", animation))
265 return ANIMATION_ZOOM;
266 else if (!strcmp("fade", animation))
267 return ANIMATION_FADE;
269 return ANIMATION_NONE;
273 shell_configuration(struct desktop_shell *shell)
278 char *modifier = NULL;
279 char *win_animation = NULL;
281 struct config_key shell_keys[] = {
282 { "binding-modifier", CONFIG_KEY_STRING, &modifier },
283 { "animation", CONFIG_KEY_STRING, &win_animation},
286 struct config_key saver_keys[] = {
287 { "path", CONFIG_KEY_STRING, &path },
288 { "duration", CONFIG_KEY_INTEGER, &duration },
291 struct config_section cs[] = {
292 { "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL },
293 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
296 config_file = config_file_path("weston.ini");
297 parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell);
300 shell->screensaver.path = path;
301 shell->screensaver.duration = duration;
302 shell->binding_modifier = get_modifier(modifier);
303 shell->win_animation_type = get_animation_type(win_animation);
307 noop_grab_focus(struct wl_pointer_grab *grab,
308 struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
314 move_grab_motion(struct wl_pointer_grab *grab,
315 uint32_t time, wl_fixed_t x, wl_fixed_t y)
317 struct weston_move_grab *move = (struct weston_move_grab *) grab;
318 struct wl_pointer *pointer = grab->pointer;
319 struct shell_surface *shsurf = move->base.shsurf;
320 struct weston_surface *es;
321 int dx = wl_fixed_to_int(pointer->x + move->dx);
322 int dy = wl_fixed_to_int(pointer->y + move->dy);
327 es = shsurf->surface;
329 weston_surface_configure(es, dx, dy,
330 es->geometry.width, es->geometry.height);
334 move_grab_button(struct wl_pointer_grab *grab,
335 uint32_t time, uint32_t button, uint32_t state_w)
337 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
339 struct wl_pointer *pointer = grab->pointer;
340 enum wl_pointer_button_state state = state_w;
342 if (pointer->button_count == 0 &&
343 state == WL_POINTER_BUTTON_STATE_RELEASED) {
344 shell_grab_finish(shell_grab);
345 wl_pointer_end_grab(pointer);
350 static const struct wl_pointer_grab_interface move_grab_interface = {
357 busy_cursor_grab_focus(struct wl_pointer_grab *base,
358 struct wl_surface *surface, int32_t x, int32_t y)
360 struct shell_grab *grab = (struct shell_grab *) base;
361 struct wl_pointer *pointer = base->pointer;
363 if (grab->grab.focus != surface) {
364 shell_grab_finish(grab);
365 wl_pointer_end_grab(pointer);
371 busy_cursor_grab_motion(struct wl_pointer_grab *grab,
372 uint32_t time, int32_t x, int32_t y)
377 busy_cursor_grab_button(struct wl_pointer_grab *grab,
378 uint32_t time, uint32_t button, uint32_t state)
382 static const struct wl_pointer_grab_interface busy_cursor_grab_interface = {
383 busy_cursor_grab_focus,
384 busy_cursor_grab_motion,
385 busy_cursor_grab_button,
389 set_busy_cursor(struct shell_surface *shsurf, struct wl_pointer *pointer)
391 struct shell_grab *grab;
392 struct desktop_shell *shell = shsurf->shell;
393 struct weston_seat *seat = (struct weston_seat *) pointer->seat;
394 struct weston_surface *sprite;
396 grab = malloc(sizeof *grab);
400 shell_grab_init(grab, &busy_cursor_grab_interface, shsurf);
401 grab->grab.focus = &shsurf->surface->surface;
402 wl_pointer_start_grab(pointer, &grab->grab);
403 wl_pointer_set_focus(pointer, &shell->busy_surface->surface, 0, 0);
405 sprite = (struct weston_surface *) seat->sprite;
406 shell->busy_surface->output = sprite->output;
410 end_busy_cursor(struct shell_surface *shsurf, struct wl_pointer *pointer)
412 struct shell_grab *grab = (struct shell_grab *) pointer->grab;
414 if (grab->grab.interface == &busy_cursor_grab_interface) {
415 shell_grab_finish(grab);
416 wl_pointer_end_grab(pointer);
422 ping_timer_destroy(struct shell_surface *shsurf)
424 if (!shsurf || !shsurf->ping_timer)
427 if (shsurf->ping_timer->source)
428 wl_event_source_remove(shsurf->ping_timer->source);
430 free(shsurf->ping_timer);
431 shsurf->ping_timer = NULL;
435 ping_timeout_handler(void *data)
437 struct shell_surface *shsurf = data;
438 struct weston_seat *seat;
440 /* Client is not responding */
441 shsurf->unresponsive = 1;
443 wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link)
444 if (seat->seat.pointer->focus == &shsurf->surface->surface)
445 set_busy_cursor(shsurf, seat->seat.pointer);
451 ping_handler(struct weston_surface *surface, uint32_t serial)
453 struct shell_surface *shsurf = get_shell_surface(surface);
454 struct wl_event_loop *loop;
455 int ping_timeout = 200;
459 if (!shsurf->resource.client)
462 if (!shsurf->ping_timer) {
463 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
464 if (!shsurf->ping_timer)
467 shsurf->ping_timer->serial = serial;
468 loop = wl_display_get_event_loop(surface->compositor->wl_display);
469 shsurf->ping_timer->source =
470 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
471 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
473 wl_shell_surface_send_ping(&shsurf->resource, serial);
478 handle_pointer_focus(struct wl_listener *listener, void *data)
480 struct wl_pointer *pointer = data;
481 struct weston_surface *surface =
482 (struct weston_surface *) pointer->focus;
483 struct weston_compositor *compositor;
484 struct shell_surface *shsurf;
490 compositor = surface->compositor;
491 shsurf = get_shell_surface(surface);
493 if (shsurf && shsurf->unresponsive) {
494 set_busy_cursor(shsurf, pointer);
496 serial = wl_display_next_serial(compositor->wl_display);
497 ping_handler(surface, serial);
502 shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
505 struct shell_surface *shsurf = resource->data;
506 struct desktop_shell *shell = shsurf->shell;
507 struct weston_seat *seat;
508 struct weston_compositor *ec = shsurf->surface->compositor;
509 struct wl_pointer *pointer;
510 int was_unresponsive;
512 if (shsurf->ping_timer->serial == serial) {
513 was_unresponsive = shsurf->unresponsive;
514 shsurf->unresponsive = 0;
515 if (was_unresponsive) {
516 /* Received pong from previously unresponsive client */
517 wl_list_for_each(seat, &ec->seat_list, link) {
518 pointer = seat->seat.pointer;
519 if (pointer->focus ==
520 &shell->busy_surface->surface &&
522 &shsurf->surface->surface)
523 end_busy_cursor(shsurf, pointer);
526 ping_timer_destroy(shsurf);
531 shell_surface_set_title(struct wl_client *client,
532 struct wl_resource *resource, const char *title)
534 struct shell_surface *shsurf = resource->data;
537 shsurf->title = strdup(title);
541 shell_surface_set_class(struct wl_client *client,
542 struct wl_resource *resource, const char *class)
544 struct shell_surface *shsurf = resource->data;
547 shsurf->class = strdup(class);
551 surface_move(struct shell_surface *shsurf, struct weston_seat *ws)
553 struct weston_move_grab *move;
558 move = malloc(sizeof *move);
562 shell_grab_init(&move->base, &move_grab_interface, shsurf);
564 move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) -
565 ws->seat.pointer->grab_x;
566 move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) -
567 ws->seat.pointer->grab_y;
569 wl_pointer_start_grab(ws->seat.pointer, &move->base.grab);
571 wl_pointer_set_focus(ws->seat.pointer, NULL,
572 wl_fixed_from_int(0),
573 wl_fixed_from_int(0));
579 shell_surface_move(struct wl_client *client, struct wl_resource *resource,
580 struct wl_resource *seat_resource, uint32_t serial)
582 struct weston_seat *ws = seat_resource->data;
583 struct shell_surface *shsurf = resource->data;
585 if (ws->seat.pointer->button_count == 0 ||
586 ws->seat.pointer->grab_serial != serial ||
587 ws->seat.pointer->focus != &shsurf->surface->surface)
590 if (surface_move(shsurf, ws) < 0)
591 wl_resource_post_no_memory(resource);
594 struct weston_resize_grab {
595 struct shell_grab base;
597 int32_t width, height;
601 resize_grab_motion(struct wl_pointer_grab *grab,
602 uint32_t time, wl_fixed_t x, wl_fixed_t y)
604 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
605 struct wl_pointer *pointer = grab->pointer;
606 struct shell_surface *shsurf = resize->base.shsurf;
607 int32_t width, height;
608 wl_fixed_t from_x, from_y;
609 wl_fixed_t to_x, to_y;
614 weston_surface_from_global_fixed(shsurf->surface,
615 pointer->grab_x, pointer->grab_y,
617 weston_surface_from_global_fixed(shsurf->surface,
618 pointer->x, pointer->y, &to_x, &to_y);
620 width = resize->width;
621 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
622 width += wl_fixed_to_int(from_x - to_x);
623 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
624 width += wl_fixed_to_int(to_x - from_x);
627 height = resize->height;
628 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
629 height += wl_fixed_to_int(from_y - to_y);
630 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
631 height += wl_fixed_to_int(to_y - from_y);
634 shsurf->client->send_configure(shsurf->surface,
635 resize->edges, width, height);
639 send_configure(struct weston_surface *surface,
640 uint32_t edges, int32_t width, int32_t height)
642 struct shell_surface *shsurf = get_shell_surface(surface);
644 wl_shell_surface_send_configure(&shsurf->resource,
645 edges, width, height);
648 static const struct weston_shell_client shell_client = {
653 resize_grab_button(struct wl_pointer_grab *grab,
654 uint32_t time, uint32_t button, uint32_t state_w)
656 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
657 struct wl_pointer *pointer = grab->pointer;
658 enum wl_pointer_button_state state = state_w;
660 if (pointer->button_count == 0 &&
661 state == WL_POINTER_BUTTON_STATE_RELEASED) {
662 shell_grab_finish(&resize->base);
663 wl_pointer_end_grab(pointer);
668 static const struct wl_pointer_grab_interface resize_grab_interface = {
675 surface_resize(struct shell_surface *shsurf,
676 struct weston_seat *ws, uint32_t edges)
678 struct weston_resize_grab *resize;
680 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
683 if (edges == 0 || edges > 15 ||
684 (edges & 3) == 3 || (edges & 12) == 12)
687 resize = malloc(sizeof *resize);
691 shell_grab_init(&resize->base, &resize_grab_interface, shsurf);
693 resize->edges = edges;
694 resize->width = shsurf->surface->geometry.width;
695 resize->height = shsurf->surface->geometry.height;
697 wl_pointer_start_grab(ws->seat.pointer, &resize->base.grab);
699 wl_pointer_set_focus(ws->seat.pointer, NULL,
700 wl_fixed_from_int(0),
701 wl_fixed_from_int(0));
707 shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
708 struct wl_resource *seat_resource, uint32_t serial,
711 struct weston_seat *ws = seat_resource->data;
712 struct shell_surface *shsurf = resource->data;
714 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
717 if (ws->seat.pointer->button_count == 0 ||
718 ws->seat.pointer->grab_serial != serial ||
719 ws->seat.pointer->focus != &shsurf->surface->surface)
722 if (surface_resize(shsurf, ws, edges) < 0)
723 wl_resource_post_no_memory(resource);
726 static struct weston_output *
727 get_default_output(struct weston_compositor *compositor)
729 return container_of(compositor->output_list.next,
730 struct weston_output, link);
734 shell_unset_fullscreen(struct shell_surface *shsurf)
736 /* undo all fullscreen things here */
737 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
738 shell_surface_is_top_fullscreen(shsurf)) {
739 weston_output_switch_mode(shsurf->fullscreen_output,
740 shsurf->fullscreen_output->origin);
742 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
743 shsurf->fullscreen.framerate = 0;
744 wl_list_remove(&shsurf->fullscreen.transform.link);
745 wl_list_init(&shsurf->fullscreen.transform.link);
746 if (shsurf->fullscreen.black_surface)
747 weston_surface_destroy(shsurf->fullscreen.black_surface);
748 shsurf->fullscreen.black_surface = NULL;
749 shsurf->fullscreen_output = NULL;
750 weston_surface_set_position(shsurf->surface,
751 shsurf->saved_x, shsurf->saved_y);
752 if (shsurf->saved_rotation_valid) {
753 wl_list_insert(&shsurf->surface->geometry.transformation_list,
754 &shsurf->rotation.transform.link);
755 shsurf->saved_rotation_valid = false;
760 reset_shell_surface_type(struct shell_surface *surface)
762 switch (surface->type) {
763 case SHELL_SURFACE_FULLSCREEN:
764 shell_unset_fullscreen(surface);
766 case SHELL_SURFACE_MAXIMIZED:
767 surface->output = get_default_output(surface->surface->compositor);
768 weston_surface_set_position(surface->surface,
772 case SHELL_SURFACE_PANEL:
773 case SHELL_SURFACE_BACKGROUND:
774 wl_list_remove(&surface->link);
775 wl_list_init(&surface->link);
777 case SHELL_SURFACE_SCREENSAVER:
778 case SHELL_SURFACE_LOCK:
779 wl_resource_post_error(&surface->resource,
780 WL_DISPLAY_ERROR_INVALID_METHOD,
781 "cannot reassign surface type");
783 case SHELL_SURFACE_NONE:
784 case SHELL_SURFACE_TOPLEVEL:
785 case SHELL_SURFACE_TRANSIENT:
786 case SHELL_SURFACE_POPUP:
790 surface->type = SHELL_SURFACE_NONE;
795 set_surface_type(struct shell_surface *shsurf)
797 struct weston_surface *surface = shsurf->surface;
798 struct shell_surface *pshsurf = shsurf->parent;
799 struct weston_surface *pes;
800 struct shell_surface *priv;
801 struct desktop_shell *shell = shsurf->shell;
803 reset_shell_surface_type(shsurf);
805 shsurf->type = shsurf->next_type;
806 shsurf->next_type = SHELL_SURFACE_NONE;
808 switch (shsurf->type) {
809 case SHELL_SURFACE_TOPLEVEL:
811 case SHELL_SURFACE_TRANSIENT:
812 pes = pshsurf->surface;
813 weston_surface_set_position(surface,
814 pes->geometry.x + shsurf->transient.x,
815 pes->geometry.y + shsurf->transient.y);
818 case SHELL_SURFACE_MAXIMIZED:
819 shsurf->saved_x = surface->geometry.x;
820 shsurf->saved_y = surface->geometry.y;
821 shsurf->saved_position_valid = true;
824 case SHELL_SURFACE_FULLSCREEN:
825 shsurf->saved_x = surface->geometry.x;
826 shsurf->saved_y = surface->geometry.y;
827 shsurf->saved_position_valid = true;
829 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
830 wl_list_remove(&shsurf->rotation.transform.link);
831 wl_list_init(&shsurf->rotation.transform.link);
832 shsurf->surface->geometry.dirty = 1;
833 shsurf->saved_rotation_valid = true;
837 case SHELL_SURFACE_BACKGROUND:
838 wl_list_for_each(priv, &shell->backgrounds, link) {
839 if (priv->output == shsurf->output) {
840 priv->surface->output = NULL;
841 wl_list_remove(&priv->surface->layer_link);
842 wl_list_remove(&priv->link);
847 wl_list_insert(&shell->backgrounds, &shsurf->link);
849 weston_surface_set_position(surface, shsurf->output->x,
853 case SHELL_SURFACE_PANEL:
854 wl_list_for_each(priv, &shell->panels, link) {
855 if (priv->output == shsurf->output) {
856 priv->surface->output = NULL;
857 wl_list_remove(&priv->surface->layer_link);
858 wl_list_remove(&priv->link);
863 wl_list_insert(&shell->panels, &shsurf->link);
865 weston_surface_set_position(surface, shsurf->output->x,
875 set_toplevel(struct shell_surface *shsurf)
877 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
881 shell_surface_set_toplevel(struct wl_client *client,
882 struct wl_resource *resource)
884 struct shell_surface *surface = resource->data;
886 set_toplevel(surface);
890 set_transient(struct shell_surface *shsurf,
891 struct shell_surface *pshsurf, int x, int y, uint32_t flags)
893 /* assign to parents output */
894 shsurf->parent = pshsurf;
895 shsurf->transient.x = x;
896 shsurf->transient.y = y;
897 shsurf->transient.flags = flags;
898 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
902 shell_surface_set_transient(struct wl_client *client,
903 struct wl_resource *resource,
904 struct wl_resource *parent_resource,
905 int x, int y, uint32_t flags)
907 struct shell_surface *shsurf = resource->data;
908 struct shell_surface *pshsurf = parent_resource->data;
910 set_transient(shsurf, pshsurf, x, y, flags);
913 static struct desktop_shell *
914 shell_surface_get_shell(struct shell_surface *shsurf)
916 return shsurf->shell;
920 get_output_panel_height(struct desktop_shell *shell,
921 struct weston_output *output)
923 struct shell_surface *priv;
924 int panel_height = 0;
929 wl_list_for_each(priv, &shell->panels, link) {
930 if (priv->output == output) {
931 panel_height = priv->surface->geometry.height;
939 shell_surface_set_maximized(struct wl_client *client,
940 struct wl_resource *resource,
941 struct wl_resource *output_resource )
943 struct shell_surface *shsurf = resource->data;
944 struct weston_surface *es = shsurf->surface;
945 struct desktop_shell *shell = NULL;
946 uint32_t edges = 0, panel_height = 0;
948 /* get the default output, if the client set it as NULL
949 check whether the ouput is available */
951 shsurf->output = output_resource->data;
953 shsurf->output = get_default_output(es->compositor);
955 shell = shell_surface_get_shell(shsurf);
956 panel_height = get_output_panel_height(shell, es->output);
957 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
959 shsurf->client->send_configure(shsurf->surface, edges,
960 es->output->current->width,
961 es->output->current->height - panel_height);
963 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
967 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy);
969 static struct weston_surface *
970 create_black_surface(struct weston_compositor *ec,
971 struct weston_surface *fs_surface,
972 GLfloat x, GLfloat y, int w, int h)
974 struct weston_surface *surface = NULL;
976 surface = weston_surface_create(ec);
977 if (surface == NULL) {
978 fprintf(stderr, "no memory\n");
982 surface->configure = black_surface_configure;
983 surface->private = fs_surface;
984 weston_surface_configure(surface, x, y, w, h);
985 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
989 /* Create black surface and append it to the associated fullscreen surface.
990 * Handle size dismatch and positioning according to the method. */
992 shell_configure_fullscreen(struct shell_surface *shsurf)
994 struct weston_output *output = shsurf->fullscreen_output;
995 struct weston_surface *surface = shsurf->surface;
996 struct weston_matrix *matrix;
999 center_on_output(surface, output);
1001 if (!shsurf->fullscreen.black_surface)
1002 shsurf->fullscreen.black_surface =
1003 create_black_surface(surface->compositor,
1005 output->x, output->y,
1006 output->current->width,
1007 output->current->height);
1009 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
1010 wl_list_insert(&surface->layer_link,
1011 &shsurf->fullscreen.black_surface->layer_link);
1012 shsurf->fullscreen.black_surface->output = output;
1014 switch (shsurf->fullscreen.type) {
1015 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
1017 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
1018 matrix = &shsurf->fullscreen.transform.matrix;
1019 weston_matrix_init(matrix);
1020 scale = (float)output->current->width/(float)surface->geometry.width;
1021 weston_matrix_scale(matrix, scale, scale, 1);
1022 wl_list_remove(&shsurf->fullscreen.transform.link);
1023 wl_list_insert(surface->geometry.transformation_list.prev,
1024 &shsurf->fullscreen.transform.link);
1025 weston_surface_set_position(surface, output->x, output->y);
1027 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
1028 if (shell_surface_is_top_fullscreen(shsurf)) {
1029 struct weston_mode mode = {0,
1030 surface->geometry.width,
1031 surface->geometry.height,
1032 shsurf->fullscreen.framerate};
1034 if (weston_output_switch_mode(output, &mode) == 0) {
1035 weston_surface_configure(shsurf->fullscreen.black_surface,
1036 output->x, output->y,
1037 output->current->width,
1038 output->current->height);
1039 weston_surface_set_position(surface, output->x, output->y);
1044 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
1051 /* make the fullscreen and black surface at the top */
1053 shell_stack_fullscreen(struct shell_surface *shsurf)
1055 struct weston_output *output = shsurf->fullscreen_output;
1056 struct weston_surface *surface = shsurf->surface;
1057 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
1059 wl_list_remove(&surface->layer_link);
1060 wl_list_insert(&shell->fullscreen_layer.surface_list,
1061 &surface->layer_link);
1062 weston_surface_damage(surface);
1064 if (!shsurf->fullscreen.black_surface)
1065 shsurf->fullscreen.black_surface =
1066 create_black_surface(surface->compositor,
1068 output->x, output->y,
1069 output->current->width,
1070 output->current->height);
1072 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
1073 wl_list_insert(&surface->layer_link,
1074 &shsurf->fullscreen.black_surface->layer_link);
1075 weston_surface_damage(shsurf->fullscreen.black_surface);
1079 shell_map_fullscreen(struct shell_surface *shsurf)
1081 shell_stack_fullscreen(shsurf);
1082 shell_configure_fullscreen(shsurf);
1086 shell_surface_set_fullscreen(struct wl_client *client,
1087 struct wl_resource *resource,
1090 struct wl_resource *output_resource)
1092 struct shell_surface *shsurf = resource->data;
1093 struct weston_surface *es = shsurf->surface;
1095 if (output_resource)
1096 shsurf->output = output_resource->data;
1098 shsurf->output = get_default_output(es->compositor);
1100 shsurf->fullscreen_output = shsurf->output;
1101 shsurf->fullscreen.type = method;
1102 shsurf->fullscreen.framerate = framerate;
1103 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
1105 shsurf->client->send_configure(shsurf->surface, 0,
1106 shsurf->output->current->width,
1107 shsurf->output->current->height);
1111 popup_grab_focus(struct wl_pointer_grab *grab,
1112 struct wl_surface *surface,
1116 struct wl_pointer *pointer = grab->pointer;
1117 struct shell_surface *priv =
1118 container_of(grab, struct shell_surface, popup.grab);
1119 struct wl_client *client = priv->surface->surface.resource.client;
1121 if (surface && surface->resource.client == client) {
1122 wl_pointer_set_focus(pointer, surface, x, y);
1123 grab->focus = surface;
1125 wl_pointer_set_focus(pointer, NULL,
1126 wl_fixed_from_int(0),
1127 wl_fixed_from_int(0));
1133 popup_grab_motion(struct wl_pointer_grab *grab,
1134 uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
1136 struct wl_resource *resource;
1138 resource = grab->pointer->focus_resource;
1140 wl_pointer_send_motion(resource, time, sx, sy);
1144 popup_grab_button(struct wl_pointer_grab *grab,
1145 uint32_t time, uint32_t button, uint32_t state_w)
1147 struct wl_resource *resource;
1148 struct shell_surface *shsurf =
1149 container_of(grab, struct shell_surface, popup.grab);
1150 struct wl_display *display;
1151 enum wl_pointer_button_state state = state_w;
1154 resource = grab->pointer->focus_resource;
1156 display = wl_client_get_display(resource->client);
1157 serial = wl_display_get_serial(display);
1158 wl_pointer_send_button(resource, serial, time, button, state);
1159 } else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
1160 (shsurf->popup.initial_up ||
1161 time - shsurf->popup.seat->pointer->grab_time > 500)) {
1162 wl_shell_surface_send_popup_done(&shsurf->resource);
1163 wl_pointer_end_grab(grab->pointer);
1164 shsurf->popup.grab.pointer = NULL;
1167 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
1168 shsurf->popup.initial_up = 1;
1171 static const struct wl_pointer_grab_interface popup_grab_interface = {
1178 shell_map_popup(struct shell_surface *shsurf)
1180 struct wl_seat *seat = shsurf->popup.seat;
1181 struct weston_surface *es = shsurf->surface;
1182 struct weston_surface *parent = shsurf->parent->surface;
1184 es->output = parent->output;
1185 shsurf->popup.grab.interface = &popup_grab_interface;
1187 weston_surface_update_transform(parent);
1188 if (parent->transform.enabled) {
1189 shsurf->popup.parent_transform.matrix =
1190 parent->transform.matrix;
1192 /* construct x, y translation matrix */
1193 weston_matrix_init(&shsurf->popup.parent_transform.matrix);
1194 shsurf->popup.parent_transform.matrix.d[12] =
1196 shsurf->popup.parent_transform.matrix.d[13] =
1199 wl_list_insert(es->geometry.transformation_list.prev,
1200 &shsurf->popup.parent_transform.link);
1201 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
1203 shsurf->popup.initial_up = 0;
1205 /* We don't require the grab to still be active, but if another
1206 * grab has started in the meantime, we end the popup now. */
1207 if (seat->pointer->grab_serial == shsurf->popup.serial) {
1208 wl_pointer_start_grab(seat->pointer, &shsurf->popup.grab);
1210 wl_shell_surface_send_popup_done(&shsurf->resource);
1215 shell_surface_set_popup(struct wl_client *client,
1216 struct wl_resource *resource,
1217 struct wl_resource *seat_resource,
1219 struct wl_resource *parent_resource,
1220 int32_t x, int32_t y, uint32_t flags)
1222 struct shell_surface *shsurf = resource->data;
1224 shsurf->type = SHELL_SURFACE_POPUP;
1225 shsurf->parent = parent_resource->data;
1226 shsurf->popup.seat = seat_resource->data;
1227 shsurf->popup.serial = serial;
1228 shsurf->popup.x = x;
1229 shsurf->popup.y = y;
1232 static const struct wl_shell_surface_interface shell_surface_implementation = {
1235 shell_surface_resize,
1236 shell_surface_set_toplevel,
1237 shell_surface_set_transient,
1238 shell_surface_set_fullscreen,
1239 shell_surface_set_popup,
1240 shell_surface_set_maximized,
1241 shell_surface_set_title,
1242 shell_surface_set_class
1246 destroy_shell_surface(struct shell_surface *shsurf)
1248 if (shsurf->popup.grab.pointer)
1249 wl_pointer_end_grab(shsurf->popup.grab.pointer);
1251 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1252 shell_surface_is_top_fullscreen(shsurf)) {
1253 weston_output_switch_mode(shsurf->fullscreen_output,
1254 shsurf->fullscreen_output->origin);
1257 if (shsurf->fullscreen.black_surface)
1258 weston_surface_destroy(shsurf->fullscreen.black_surface);
1260 /* As destroy_resource() use wl_list_for_each_safe(),
1261 * we can always remove the listener.
1263 wl_list_remove(&shsurf->surface_destroy_listener.link);
1264 shsurf->surface->configure = NULL;
1265 ping_timer_destroy(shsurf);
1267 wl_list_remove(&shsurf->link);
1272 shell_destroy_shell_surface(struct wl_resource *resource)
1274 struct shell_surface *shsurf = resource->data;
1276 destroy_shell_surface(shsurf);
1280 shell_handle_surface_destroy(struct wl_listener *listener, void *data)
1282 struct shell_surface *shsurf = container_of(listener,
1283 struct shell_surface,
1284 surface_destroy_listener);
1286 /* tricky way to check if resource was in fact created */
1287 if (shsurf->resource.object.implementation != 0)
1288 wl_resource_destroy(&shsurf->resource);
1290 destroy_shell_surface(shsurf);
1293 static struct shell_surface *
1294 get_shell_surface(struct weston_surface *surface)
1296 struct wl_listener *listener;
1298 listener = wl_signal_get(&surface->surface.resource.destroy_signal,
1299 shell_handle_surface_destroy);
1301 return container_of(listener, struct shell_surface,
1302 surface_destroy_listener);
1308 shell_surface_configure(struct weston_surface *, int32_t, int32_t);
1310 static struct shell_surface *
1311 create_shell_surface(void *shell, struct weston_surface *surface,
1312 const struct weston_shell_client *client)
1314 struct shell_surface *shsurf;
1316 if (surface->configure) {
1317 fprintf(stderr, "surface->configure already set\n");
1321 shsurf = calloc(1, sizeof *shsurf);
1323 fprintf(stderr, "no memory to allocate shell surface\n");
1327 surface->configure = shell_surface_configure;
1328 surface->compositor->shell_interface.shell = shell;
1330 shsurf->shell = (struct desktop_shell *) shell;
1331 shsurf->unresponsive = 0;
1332 shsurf->saved_position_valid = false;
1333 shsurf->saved_rotation_valid = false;
1334 shsurf->surface = surface;
1335 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1336 shsurf->fullscreen.framerate = 0;
1337 shsurf->fullscreen.black_surface = NULL;
1338 shsurf->ping_timer = NULL;
1339 wl_list_init(&shsurf->fullscreen.transform.link);
1341 wl_signal_init(&shsurf->resource.destroy_signal);
1342 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
1343 wl_signal_add(&surface->surface.resource.destroy_signal,
1344 &shsurf->surface_destroy_listener);
1346 /* init link so its safe to always remove it in destroy_shell_surface */
1347 wl_list_init(&shsurf->link);
1349 /* empty when not in use */
1350 wl_list_init(&shsurf->rotation.transform.link);
1351 weston_matrix_init(&shsurf->rotation.rotation);
1353 shsurf->type = SHELL_SURFACE_NONE;
1354 shsurf->next_type = SHELL_SURFACE_NONE;
1356 shsurf->client = client;
1362 shell_get_shell_surface(struct wl_client *client,
1363 struct wl_resource *resource,
1365 struct wl_resource *surface_resource)
1367 struct weston_surface *surface = surface_resource->data;
1368 struct desktop_shell *shell = resource->data;
1369 struct shell_surface *shsurf;
1371 if (get_shell_surface(surface)) {
1372 wl_resource_post_error(surface_resource,
1373 WL_DISPLAY_ERROR_INVALID_OBJECT,
1374 "desktop_shell::get_shell_surface already requested");
1378 shsurf = create_shell_surface(shell, surface, &shell_client);
1380 wl_resource_post_error(surface_resource,
1381 WL_DISPLAY_ERROR_INVALID_OBJECT,
1382 "surface->configure already set");
1386 shsurf->resource.destroy = shell_destroy_shell_surface;
1387 shsurf->resource.object.id = id;
1388 shsurf->resource.object.interface = &wl_shell_surface_interface;
1389 shsurf->resource.object.implementation =
1390 (void (**)(void)) &shell_surface_implementation;
1391 shsurf->resource.data = shsurf;
1393 wl_client_add_resource(client, &shsurf->resource);
1396 static const struct wl_shell_interface shell_implementation = {
1397 shell_get_shell_surface
1401 handle_screensaver_sigchld(struct weston_process *proc, int status)
1407 launch_screensaver(struct desktop_shell *shell)
1409 if (shell->screensaver.binding)
1412 if (!shell->screensaver.path)
1415 if (shell->screensaver.process.pid != 0) {
1416 fprintf(stderr, "old screensaver still running\n");
1420 weston_client_launch(shell->compositor,
1421 &shell->screensaver.process,
1422 shell->screensaver.path,
1423 handle_screensaver_sigchld);
1427 terminate_screensaver(struct desktop_shell *shell)
1429 if (shell->screensaver.process.pid == 0)
1432 kill(shell->screensaver.process.pid, SIGTERM);
1436 show_screensaver(struct desktop_shell *shell, struct shell_surface *surface)
1438 struct wl_list *list;
1440 if (shell->lock_surface)
1441 list = &shell->lock_surface->surface->layer_link;
1443 list = &shell->lock_layer.surface_list;
1445 wl_list_remove(&surface->surface->layer_link);
1446 wl_list_insert(list, &surface->surface->layer_link);
1447 surface->surface->output = surface->output;
1448 weston_surface_damage(surface->surface);
1452 hide_screensaver(struct desktop_shell *shell, struct shell_surface *surface)
1454 wl_list_remove(&surface->surface->layer_link);
1455 wl_list_init(&surface->surface->layer_link);
1456 surface->surface->output = NULL;
1460 desktop_shell_set_background(struct wl_client *client,
1461 struct wl_resource *resource,
1462 struct wl_resource *output_resource,
1463 struct wl_resource *surface_resource)
1465 struct shell_surface *shsurf = surface_resource->data;
1467 shsurf->next_type = SHELL_SURFACE_BACKGROUND;
1468 shsurf->output = output_resource->data;
1470 desktop_shell_send_configure(resource, 0,
1472 shsurf->output->current->width,
1473 shsurf->output->current->height);
1477 desktop_shell_set_panel(struct wl_client *client,
1478 struct wl_resource *resource,
1479 struct wl_resource *output_resource,
1480 struct wl_resource *surface_resource)
1482 struct shell_surface *shsurf = surface_resource->data;
1484 shsurf->next_type = SHELL_SURFACE_PANEL;
1485 shsurf->output = output_resource->data;
1487 desktop_shell_send_configure(resource, 0,
1489 shsurf->output->current->width,
1490 shsurf->output->current->height);
1494 handle_lock_surface_destroy(struct wl_listener *listener, void *data)
1496 struct desktop_shell *shell =
1497 container_of(listener, struct desktop_shell, lock_surface_listener);
1499 fprintf(stderr, "lock surface gone\n");
1500 shell->lock_surface = NULL;
1504 desktop_shell_set_lock_surface(struct wl_client *client,
1505 struct wl_resource *resource,
1506 struct wl_resource *surface_resource)
1508 struct desktop_shell *shell = resource->data;
1509 struct shell_surface *surface = surface_resource->data;
1511 shell->prepare_event_sent = false;
1516 shell->lock_surface = surface;
1518 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
1519 wl_signal_add(&surface_resource->destroy_signal,
1520 &shell->lock_surface_listener);
1522 shell->lock_surface->next_type = SHELL_SURFACE_LOCK;
1526 resume_desktop(struct desktop_shell *shell)
1528 struct shell_surface *tmp;
1530 wl_list_for_each(tmp, &shell->screensaver.surfaces, link)
1531 hide_screensaver(shell, tmp);
1533 terminate_screensaver(shell);
1535 wl_list_remove(&shell->lock_layer.link);
1536 wl_list_insert(&shell->compositor->cursor_layer.link,
1537 &shell->fullscreen_layer.link);
1538 wl_list_insert(&shell->fullscreen_layer.link,
1539 &shell->panel_layer.link);
1540 wl_list_insert(&shell->panel_layer.link, &shell->toplevel_layer.link);
1542 shell->locked = false;
1543 shell->compositor->idle_time = shell->compositor->option_idle_time;
1544 weston_compositor_wake(shell->compositor);
1545 weston_compositor_damage_all(shell->compositor);
1549 desktop_shell_unlock(struct wl_client *client,
1550 struct wl_resource *resource)
1552 struct desktop_shell *shell = resource->data;
1554 shell->prepare_event_sent = false;
1557 resume_desktop(shell);
1561 desktop_shell_set_busy_surface(struct wl_client *client,
1562 struct wl_resource *resource,
1563 struct wl_resource *surface_resource)
1565 struct desktop_shell *shell = resource->data;
1567 shell->busy_surface = surface_resource->data;
1570 static const struct desktop_shell_interface desktop_shell_implementation = {
1571 desktop_shell_set_background,
1572 desktop_shell_set_panel,
1573 desktop_shell_set_lock_surface,
1574 desktop_shell_unlock,
1575 desktop_shell_set_busy_surface
1578 static enum shell_surface_type
1579 get_shell_surface_type(struct weston_surface *surface)
1581 struct shell_surface *shsurf;
1583 shsurf = get_shell_surface(surface);
1585 return SHELL_SURFACE_NONE;
1586 return shsurf->type;
1590 move_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data)
1592 struct weston_surface *surface =
1593 (struct weston_surface *) seat->pointer->focus;
1594 struct shell_surface *shsurf;
1596 if (surface == NULL)
1599 shsurf = get_shell_surface(surface);
1603 switch (shsurf->type) {
1604 case SHELL_SURFACE_PANEL:
1605 case SHELL_SURFACE_BACKGROUND:
1606 case SHELL_SURFACE_FULLSCREEN:
1607 case SHELL_SURFACE_SCREENSAVER:
1613 surface_move(shsurf, (struct weston_seat *) seat);
1617 resize_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data)
1619 struct weston_surface *surface =
1620 (struct weston_surface *) seat->pointer->focus;
1623 struct shell_surface *shsurf;
1625 if (surface == NULL)
1628 shsurf = get_shell_surface(surface);
1632 switch (shsurf->type) {
1633 case SHELL_SURFACE_PANEL:
1634 case SHELL_SURFACE_BACKGROUND:
1635 case SHELL_SURFACE_FULLSCREEN:
1636 case SHELL_SURFACE_SCREENSAVER:
1642 weston_surface_from_global(surface,
1643 wl_fixed_to_int(seat->pointer->grab_x),
1644 wl_fixed_to_int(seat->pointer->grab_y),
1647 if (x < surface->geometry.width / 3)
1648 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
1649 else if (x < 2 * surface->geometry.width / 3)
1652 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
1654 if (y < surface->geometry.height / 3)
1655 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
1656 else if (y < 2 * surface->geometry.height / 3)
1659 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
1661 surface_resize(shsurf, (struct weston_seat *) seat, edges);
1665 surface_opacity_binding(struct wl_seat *seat, uint32_t time, uint32_t axis,
1666 wl_fixed_t value, void *data)
1669 struct shell_surface *shsurf;
1670 struct weston_surface *surface =
1671 (struct weston_surface *) seat->pointer->focus;
1673 if (surface == NULL)
1676 shsurf = get_shell_surface(surface);
1680 switch (shsurf->type) {
1681 case SHELL_SURFACE_BACKGROUND:
1682 case SHELL_SURFACE_SCREENSAVER:
1688 surface->alpha += wl_fixed_to_double(value) * step;
1690 if (surface->alpha > 1.0)
1691 surface->alpha = 1.0;
1692 if (surface->alpha < step)
1693 surface->alpha = step;
1695 surface->geometry.dirty = 1;
1696 weston_surface_damage(surface);
1700 do_zoom(struct wl_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
1703 struct weston_seat *ws = (struct weston_seat *) seat;
1704 struct weston_compositor *compositor = ws->compositor;
1705 struct weston_output *output;
1706 float maximum_level, increment;
1708 wl_list_for_each(output, &compositor->output_list, link) {
1709 if (pixman_region32_contains_point(&output->region,
1710 wl_fixed_to_double(seat->pointer->x),
1711 wl_fixed_to_double(seat->pointer->y),
1713 if (key == KEY_PAGEUP)
1714 increment = output->zoom.increment;
1715 else if (key == KEY_PAGEDOWN)
1716 increment = -output->zoom.increment;
1717 else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
1718 increment = output->zoom.increment *
1719 wl_fixed_to_double(value);
1723 output->zoom.active = 1;
1724 output->zoom.level += increment;
1726 if (output->zoom.level <= 0.0) {
1727 output->zoom.active = 0;
1728 output->zoom.level = 0.0;
1731 maximum_level = 1 - output->zoom.increment;
1733 if (output->zoom.level > maximum_level)
1734 output->zoom.level = maximum_level;
1736 weston_output_update_zoom(output,
1745 zoom_axis_binding(struct wl_seat *seat, uint32_t time, uint32_t axis,
1746 wl_fixed_t value, void *data)
1748 do_zoom(seat, time, 0, axis, value);
1752 zoom_key_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
1755 do_zoom(seat, time, key, 0, 0);
1759 terminate_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
1762 struct weston_compositor *compositor = data;
1764 wl_display_terminate(compositor->wl_display);
1768 rotate_grab_motion(struct wl_pointer_grab *grab,
1769 uint32_t time, wl_fixed_t x, wl_fixed_t y)
1771 struct rotate_grab *rotate =
1772 container_of(grab, struct rotate_grab, base.grab);
1773 struct wl_pointer *pointer = grab->pointer;
1774 struct shell_surface *shsurf = rotate->base.shsurf;
1775 struct weston_surface *surface;
1776 GLfloat cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
1781 surface = shsurf->surface;
1783 cx = 0.5f * surface->geometry.width;
1784 cy = 0.5f * surface->geometry.height;
1786 dx = wl_fixed_to_double(pointer->x) - rotate->center.x;
1787 dy = wl_fixed_to_double(pointer->y) - rotate->center.y;
1788 r = sqrtf(dx * dx + dy * dy);
1790 wl_list_remove(&shsurf->rotation.transform.link);
1791 shsurf->surface->geometry.dirty = 1;
1794 struct weston_matrix *matrix =
1795 &shsurf->rotation.transform.matrix;
1797 weston_matrix_init(&rotate->rotation);
1798 rotate->rotation.d[0] = dx / r;
1799 rotate->rotation.d[4] = -dy / r;
1800 rotate->rotation.d[1] = -rotate->rotation.d[4];
1801 rotate->rotation.d[5] = rotate->rotation.d[0];
1803 weston_matrix_init(matrix);
1804 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
1805 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
1806 weston_matrix_multiply(matrix, &rotate->rotation);
1807 weston_matrix_translate(matrix, cx, cy, 0.0f);
1810 &shsurf->surface->geometry.transformation_list,
1811 &shsurf->rotation.transform.link);
1813 wl_list_init(&shsurf->rotation.transform.link);
1814 weston_matrix_init(&shsurf->rotation.rotation);
1815 weston_matrix_init(&rotate->rotation);
1818 /* We need to adjust the position of the surface
1819 * in case it was resized in a rotated state before */
1820 cposx = surface->geometry.x + cx;
1821 cposy = surface->geometry.y + cy;
1822 dposx = rotate->center.x - cposx;
1823 dposy = rotate->center.y - cposy;
1824 if (dposx != 0.0f || dposy != 0.0f) {
1825 weston_surface_set_position(surface,
1826 surface->geometry.x + dposx,
1827 surface->geometry.y + dposy);
1830 /* Repaint implies weston_surface_update_transform(), which
1831 * lazily applies the damage due to rotation update.
1833 weston_compositor_schedule_repaint(shsurf->surface->compositor);
1837 rotate_grab_button(struct wl_pointer_grab *grab,
1838 uint32_t time, uint32_t button, uint32_t state_w)
1840 struct rotate_grab *rotate =
1841 container_of(grab, struct rotate_grab, base.grab);
1842 struct wl_pointer *pointer = grab->pointer;
1843 struct shell_surface *shsurf = rotate->base.shsurf;
1844 enum wl_pointer_button_state state = state_w;
1846 if (pointer->button_count == 0 &&
1847 state == WL_POINTER_BUTTON_STATE_RELEASED) {
1849 weston_matrix_multiply(&shsurf->rotation.rotation,
1851 shell_grab_finish(&rotate->base);
1852 wl_pointer_end_grab(pointer);
1857 static const struct wl_pointer_grab_interface rotate_grab_interface = {
1864 rotate_binding(struct wl_seat *seat, uint32_t time, uint32_t button,
1867 struct weston_surface *base_surface =
1868 (struct weston_surface *) seat->pointer->focus;
1869 struct shell_surface *surface;
1870 struct rotate_grab *rotate;
1874 if (base_surface == NULL)
1877 surface = get_shell_surface(base_surface);
1881 switch (surface->type) {
1882 case SHELL_SURFACE_PANEL:
1883 case SHELL_SURFACE_BACKGROUND:
1884 case SHELL_SURFACE_FULLSCREEN:
1885 case SHELL_SURFACE_SCREENSAVER:
1891 rotate = malloc(sizeof *rotate);
1895 shell_grab_init(&rotate->base, &rotate_grab_interface, surface);
1897 weston_surface_to_global(surface->surface,
1898 surface->surface->geometry.width / 2,
1899 surface->surface->geometry.height / 2,
1900 &rotate->center.x, &rotate->center.y);
1902 wl_pointer_start_grab(seat->pointer, &rotate->base.grab);
1904 dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x;
1905 dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y;
1906 r = sqrtf(dx * dx + dy * dy);
1908 struct weston_matrix inverse;
1910 weston_matrix_init(&inverse);
1911 inverse.d[0] = dx / r;
1912 inverse.d[4] = dy / r;
1913 inverse.d[1] = -inverse.d[4];
1914 inverse.d[5] = inverse.d[0];
1915 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
1917 weston_matrix_init(&rotate->rotation);
1918 rotate->rotation.d[0] = dx / r;
1919 rotate->rotation.d[4] = -dy / r;
1920 rotate->rotation.d[1] = -rotate->rotation.d[4];
1921 rotate->rotation.d[5] = rotate->rotation.d[0];
1923 weston_matrix_init(&surface->rotation.rotation);
1924 weston_matrix_init(&rotate->rotation);
1927 wl_pointer_set_focus(seat->pointer, NULL,
1928 wl_fixed_from_int(0),
1929 wl_fixed_from_int(0));
1933 activate(struct desktop_shell *shell, struct weston_surface *es,
1934 struct weston_seat *seat)
1936 struct weston_surface *surf, *prev;
1938 weston_surface_activate(es, seat);
1940 switch (get_shell_surface_type(es)) {
1941 case SHELL_SURFACE_BACKGROUND:
1942 case SHELL_SURFACE_PANEL:
1943 case SHELL_SURFACE_LOCK:
1946 case SHELL_SURFACE_SCREENSAVER:
1947 /* always below lock surface */
1948 if (shell->lock_surface)
1949 weston_surface_restack(es,
1950 &shell->lock_surface->surface->layer_link);
1952 case SHELL_SURFACE_FULLSCREEN:
1953 /* should on top of panels */
1954 shell_stack_fullscreen(get_shell_surface(es));
1955 shell_configure_fullscreen(get_shell_surface(es));
1958 /* move the fullscreen surfaces down into the toplevel layer */
1959 if (!wl_list_empty(&shell->fullscreen_layer.surface_list)) {
1960 wl_list_for_each_reverse_safe(surf,
1962 &shell->fullscreen_layer.surface_list,
1964 weston_surface_restack(surf,
1965 &shell->toplevel_layer.surface_list);
1968 weston_surface_restack(es,
1969 &shell->toplevel_layer.surface_list);
1974 /* no-op func for checking black surface */
1976 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1981 is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
1983 if (es->configure == black_surface_configure) {
1985 *fs_surface = (struct weston_surface *)es->private;
1992 click_to_activate_binding(struct wl_seat *seat, uint32_t time, uint32_t button,
1995 struct weston_seat *ws = (struct weston_seat *) seat;
1996 struct desktop_shell *shell = data;
1997 struct weston_surface *focus;
1998 struct weston_surface *upper;
2000 focus = (struct weston_surface *) seat->pointer->focus;
2004 if (is_black_surface(focus, &upper))
2007 if (seat->pointer->grab == &seat->pointer->default_grab)
2008 activate(shell, focus, ws);
2012 lock(struct wl_listener *listener, void *data)
2014 struct desktop_shell *shell =
2015 container_of(listener, struct desktop_shell, lock_listener);
2016 struct weston_seat *seat;
2017 struct shell_surface *shsurf;
2018 struct weston_output *output;
2020 if (shell->locked) {
2021 wl_list_for_each(output, &shell->compositor->output_list, link)
2022 /* TODO: find a way to jump to other DPMS levels */
2023 if (output->set_dpms)
2024 output->set_dpms(output, WESTON_DPMS_STANDBY);
2028 shell->locked = true;
2030 /* Hide all surfaces by removing the fullscreen, panel and
2031 * toplevel layers. This way nothing else can show or receive
2032 * input events while we are locked. */
2034 wl_list_remove(&shell->panel_layer.link);
2035 wl_list_remove(&shell->toplevel_layer.link);
2036 wl_list_remove(&shell->fullscreen_layer.link);
2037 wl_list_insert(&shell->compositor->cursor_layer.link,
2038 &shell->lock_layer.link);
2040 launch_screensaver(shell);
2042 wl_list_for_each(shsurf, &shell->screensaver.surfaces, link)
2043 show_screensaver(shell, shsurf);
2045 if (!wl_list_empty(&shell->screensaver.surfaces)) {
2046 shell->compositor->idle_time = shell->screensaver.duration;
2047 weston_compositor_wake(shell->compositor);
2048 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
2051 /* reset pointer foci */
2052 weston_compositor_schedule_repaint(shell->compositor);
2054 /* reset keyboard foci */
2055 wl_list_for_each(seat, &shell->compositor->seat_list, link) {
2056 wl_keyboard_set_focus(seat->seat.keyboard, NULL);
2059 /* TODO: disable bindings that should not work while locked. */
2061 /* All this must be undone in resume_desktop(). */
2065 unlock(struct wl_listener *listener, void *data)
2067 struct desktop_shell *shell =
2068 container_of(listener, struct desktop_shell, unlock_listener);
2070 if (!shell->locked || shell->lock_surface) {
2071 weston_compositor_wake(shell->compositor);
2075 /* If desktop-shell client has gone away, unlock immediately. */
2076 if (!shell->child.desktop_shell) {
2077 resume_desktop(shell);
2081 if (shell->prepare_event_sent)
2084 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
2085 shell->prepare_event_sent = true;
2089 center_on_output(struct weston_surface *surface, struct weston_output *output)
2091 struct weston_mode *mode = output->current;
2092 GLfloat x = (mode->width - surface->geometry.width) / 2;
2093 GLfloat y = (mode->height - surface->geometry.height) / 2;
2095 weston_surface_set_position(surface, output->x + x, output->y + y);
2099 map(struct desktop_shell *shell, struct weston_surface *surface,
2100 int32_t width, int32_t height, int32_t sx, int32_t sy)
2102 struct weston_compositor *compositor = shell->compositor;
2103 struct shell_surface *shsurf;
2104 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
2105 struct weston_surface *parent;
2106 struct weston_seat *seat;
2107 int panel_height = 0;
2109 shsurf = get_shell_surface(surface);
2111 surface_type = shsurf->type;
2113 surface->geometry.width = width;
2114 surface->geometry.height = height;
2115 surface->geometry.dirty = 1;
2117 /* initial positioning, see also configure() */
2118 switch (surface_type) {
2119 case SHELL_SURFACE_TOPLEVEL:
2120 weston_surface_set_position(surface, 10 + random() % 400,
2121 10 + random() % 400);
2123 case SHELL_SURFACE_SCREENSAVER:
2124 center_on_output(surface, shsurf->fullscreen_output);
2126 case SHELL_SURFACE_FULLSCREEN:
2127 shell_map_fullscreen(shsurf);
2129 case SHELL_SURFACE_MAXIMIZED:
2130 /* use surface configure to set the geometry */
2131 panel_height = get_output_panel_height(shell,surface->output);
2132 weston_surface_set_position(surface, surface->output->x,
2133 surface->output->y + panel_height);
2135 case SHELL_SURFACE_LOCK:
2136 center_on_output(surface, get_default_output(compositor));
2138 case SHELL_SURFACE_POPUP:
2139 shell_map_popup(shsurf);
2140 case SHELL_SURFACE_NONE:
2141 weston_surface_set_position(surface,
2142 surface->geometry.x + sx,
2143 surface->geometry.y + sy);
2149 /* surface stacking order, see also activate() */
2150 switch (surface_type) {
2151 case SHELL_SURFACE_BACKGROUND:
2152 /* background always visible, at the bottom */
2153 wl_list_insert(&shell->background_layer.surface_list,
2154 &surface->layer_link);
2156 case SHELL_SURFACE_PANEL:
2157 /* panel always on top, hidden while locked */
2158 wl_list_insert(&shell->panel_layer.surface_list,
2159 &surface->layer_link);
2161 case SHELL_SURFACE_LOCK:
2162 /* lock surface always visible, on top */
2163 wl_list_insert(&shell->lock_layer.surface_list,
2164 &surface->layer_link);
2165 weston_compositor_wake(compositor);
2167 case SHELL_SURFACE_SCREENSAVER:
2168 /* If locked, show it. */
2169 if (shell->locked) {
2170 show_screensaver(shell, shsurf);
2171 compositor->idle_time = shell->screensaver.duration;
2172 weston_compositor_wake(compositor);
2173 if (!shell->lock_surface)
2174 compositor->state = WESTON_COMPOSITOR_IDLE;
2177 case SHELL_SURFACE_POPUP:
2178 case SHELL_SURFACE_TRANSIENT:
2179 parent = shsurf->parent->surface;
2180 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
2182 case SHELL_SURFACE_FULLSCREEN:
2183 case SHELL_SURFACE_NONE:
2186 wl_list_insert(&shell->toplevel_layer.surface_list,
2187 &surface->layer_link);
2191 if (surface_type != SHELL_SURFACE_NONE) {
2192 weston_surface_assign_output(surface);
2193 if (surface_type == SHELL_SURFACE_MAXIMIZED)
2194 surface->output = shsurf->output;
2197 switch (surface_type) {
2198 case SHELL_SURFACE_TRANSIENT:
2199 if (shsurf->transient.flags ==
2200 WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
2202 case SHELL_SURFACE_TOPLEVEL:
2203 case SHELL_SURFACE_FULLSCREEN:
2204 case SHELL_SURFACE_MAXIMIZED:
2205 if (!shell->locked) {
2206 wl_list_for_each(seat, &compositor->seat_list, link)
2207 activate(shell, surface, seat);
2214 if (surface_type == SHELL_SURFACE_TOPLEVEL)
2216 switch (shell->win_animation_type) {
2217 case ANIMATION_FADE:
2218 weston_fade_run(surface, NULL, NULL);
2220 case ANIMATION_ZOOM:
2221 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
2230 configure(struct desktop_shell *shell, struct weston_surface *surface,
2231 GLfloat x, GLfloat y, int32_t width, int32_t height)
2233 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
2234 struct shell_surface *shsurf;
2236 shsurf = get_shell_surface(surface);
2238 surface_type = shsurf->type;
2240 surface->geometry.x = x;
2241 surface->geometry.y = y;
2242 surface->geometry.width = width;
2243 surface->geometry.height = height;
2244 surface->geometry.dirty = 1;
2246 switch (surface_type) {
2247 case SHELL_SURFACE_SCREENSAVER:
2248 center_on_output(surface, shsurf->fullscreen_output);
2250 case SHELL_SURFACE_FULLSCREEN:
2251 shell_stack_fullscreen(shsurf);
2252 shell_configure_fullscreen(shsurf);
2254 case SHELL_SURFACE_MAXIMIZED:
2255 /* setting x, y and using configure to change that geometry */
2256 surface->geometry.x = surface->output->x;
2257 surface->geometry.y = surface->output->y +
2258 get_output_panel_height(shell,surface->output);
2260 case SHELL_SURFACE_TOPLEVEL:
2266 /* XXX: would a fullscreen surface need the same handling? */
2267 if (surface->output) {
2268 weston_surface_assign_output(surface);
2270 if (surface_type == SHELL_SURFACE_SCREENSAVER)
2271 surface->output = shsurf->output;
2272 else if (surface_type == SHELL_SURFACE_MAXIMIZED)
2273 surface->output = shsurf->output;
2278 shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
2280 struct shell_surface *shsurf = get_shell_surface(es);
2281 struct desktop_shell *shell = shsurf->shell;
2282 int type_changed = 0;
2284 if (shsurf->next_type != SHELL_SURFACE_NONE &&
2285 shsurf->type != shsurf->next_type) {
2286 set_surface_type(shsurf);
2290 if (!weston_surface_is_mapped(es)) {
2291 map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
2292 } else if (type_changed || sx != 0 || sy != 0 ||
2293 es->geometry.width != es->buffer->width ||
2294 es->geometry.height != es->buffer->height) {
2295 GLfloat from_x, from_y;
2298 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
2299 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
2300 configure(shell, es,
2301 es->geometry.x + to_x - from_x,
2302 es->geometry.y + to_y - from_y,
2303 es->buffer->width, es->buffer->height);
2307 static int launch_desktop_shell_process(struct desktop_shell *shell);
2310 desktop_shell_sigchld(struct weston_process *process, int status)
2313 struct desktop_shell *shell =
2314 container_of(process, struct desktop_shell, child.process);
2316 shell->child.process.pid = 0;
2317 shell->child.client = NULL; /* already destroyed by wayland */
2319 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
2320 time = weston_compositor_get_time();
2321 if (time - shell->child.deathstamp > 30000) {
2322 shell->child.deathstamp = time;
2323 shell->child.deathcount = 0;
2326 shell->child.deathcount++;
2327 if (shell->child.deathcount > 5) {
2328 fprintf(stderr, "weston-desktop-shell died, giving up.\n");
2332 fprintf(stderr, "weston-desktop-shell died, respawning...\n");
2333 launch_desktop_shell_process(shell);
2337 launch_desktop_shell_process(struct desktop_shell *shell)
2339 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
2341 shell->child.client = weston_client_launch(shell->compositor,
2342 &shell->child.process,
2344 desktop_shell_sigchld);
2346 if (!shell->child.client)
2352 bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
2354 struct desktop_shell *shell = data;
2356 wl_client_add_object(client, &wl_shell_interface,
2357 &shell_implementation, id, shell);
2361 unbind_desktop_shell(struct wl_resource *resource)
2363 struct desktop_shell *shell = resource->data;
2366 resume_desktop(shell);
2368 shell->child.desktop_shell = NULL;
2369 shell->prepare_event_sent = false;
2374 bind_desktop_shell(struct wl_client *client,
2375 void *data, uint32_t version, uint32_t id)
2377 struct desktop_shell *shell = data;
2378 struct wl_resource *resource;
2380 resource = wl_client_add_object(client, &desktop_shell_interface,
2381 &desktop_shell_implementation,
2384 if (client == shell->child.client) {
2385 resource->destroy = unbind_desktop_shell;
2386 shell->child.desktop_shell = resource;
2390 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2391 "permission to bind desktop_shell denied");
2392 wl_resource_destroy(resource);
2396 screensaver_set_surface(struct wl_client *client,
2397 struct wl_resource *resource,
2398 struct wl_resource *shell_surface_resource,
2399 struct wl_resource *output_resource)
2401 struct desktop_shell *shell = resource->data;
2402 struct shell_surface *surface = shell_surface_resource->data;
2403 struct weston_output *output = output_resource->data;
2405 surface->next_type = SHELL_SURFACE_SCREENSAVER;
2407 surface->fullscreen_output = output;
2408 surface->output = output;
2409 wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
2412 static const struct screensaver_interface screensaver_implementation = {
2413 screensaver_set_surface
2417 unbind_screensaver(struct wl_resource *resource)
2419 struct desktop_shell *shell = resource->data;
2421 shell->screensaver.binding = NULL;
2426 bind_screensaver(struct wl_client *client,
2427 void *data, uint32_t version, uint32_t id)
2429 struct desktop_shell *shell = data;
2430 struct wl_resource *resource;
2432 resource = wl_client_add_object(client, &screensaver_interface,
2433 &screensaver_implementation,
2436 if (shell->screensaver.binding == NULL) {
2437 resource->destroy = unbind_screensaver;
2438 shell->screensaver.binding = resource;
2442 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2443 "interface object already bound");
2444 wl_resource_destroy(resource);
2448 struct desktop_shell *shell;
2449 struct weston_surface *current;
2450 struct wl_listener listener;
2451 struct wl_keyboard_grab grab;
2455 switcher_next(struct switcher *switcher)
2457 struct weston_compositor *compositor = switcher->shell->compositor;
2458 struct weston_surface *surface;
2459 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
2460 struct shell_surface *shsurf;
2462 wl_list_for_each(surface, &compositor->surface_list, link) {
2463 switch (get_shell_surface_type(surface)) {
2464 case SHELL_SURFACE_TOPLEVEL:
2465 case SHELL_SURFACE_FULLSCREEN:
2466 case SHELL_SURFACE_MAXIMIZED:
2469 if (prev == switcher->current)
2472 surface->alpha = 0.25;
2473 surface->geometry.dirty = 1;
2474 weston_surface_damage(surface);
2480 if (is_black_surface(surface, NULL)) {
2481 surface->alpha = 0.25;
2482 surface->geometry.dirty = 1;
2483 weston_surface_damage(surface);
2493 wl_list_remove(&switcher->listener.link);
2494 wl_signal_add(&next->surface.resource.destroy_signal,
2495 &switcher->listener);
2497 switcher->current = next;
2500 shsurf = get_shell_surface(switcher->current);
2501 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
2502 shsurf->fullscreen.black_surface->alpha = 1.0;
2506 switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
2508 struct switcher *switcher =
2509 container_of(listener, struct switcher, listener);
2511 switcher_next(switcher);
2515 switcher_destroy(struct switcher *switcher)
2517 struct weston_compositor *compositor = switcher->shell->compositor;
2518 struct weston_surface *surface;
2519 struct wl_keyboard *keyboard = switcher->grab.keyboard;
2521 wl_list_for_each(surface, &compositor->surface_list, link) {
2522 surface->alpha = 1.0;
2523 weston_surface_damage(surface);
2526 if (switcher->current)
2527 activate(switcher->shell, switcher->current,
2528 (struct weston_seat *) keyboard->seat);
2529 wl_list_remove(&switcher->listener.link);
2530 wl_keyboard_end_grab(keyboard);
2535 switcher_key(struct wl_keyboard_grab *grab,
2536 uint32_t time, uint32_t key, uint32_t state_w)
2538 struct switcher *switcher = container_of(grab, struct switcher, grab);
2539 enum wl_keyboard_key_state state = state_w;
2541 if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED)
2542 switcher_next(switcher);
2546 switcher_modifier(struct wl_keyboard_grab *grab, uint32_t serial,
2547 uint32_t mods_depressed, uint32_t mods_latched,
2548 uint32_t mods_locked, uint32_t group)
2550 struct switcher *switcher = container_of(grab, struct switcher, grab);
2551 struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat;
2553 if ((seat->modifier_state & switcher->shell->binding_modifier) == 0)
2554 switcher_destroy(switcher);
2557 static const struct wl_keyboard_grab_interface switcher_grab = {
2563 switcher_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
2566 struct desktop_shell *shell = data;
2567 struct switcher *switcher;
2569 switcher = malloc(sizeof *switcher);
2570 switcher->shell = shell;
2571 switcher->current = NULL;
2572 switcher->listener.notify = switcher_handle_surface_destroy;
2573 wl_list_init(&switcher->listener.link);
2575 switcher->grab.interface = &switcher_grab;
2576 wl_keyboard_start_grab(seat->keyboard, &switcher->grab);
2577 wl_keyboard_set_focus(seat->keyboard, NULL);
2578 switcher_next(switcher);
2582 backlight_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
2585 struct weston_compositor *compositor = data;
2586 struct weston_output *output;
2587 long backlight_new = 0;
2589 /* TODO: we're limiting to simple use cases, where we assume just
2590 * control on the primary display. We'd have to extend later if we
2591 * ever get support for setting backlights on random desktop LCD
2593 output = get_default_output(compositor);
2597 if (!output->set_backlight)
2600 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
2601 backlight_new = output->backlight_current - 25;
2602 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
2603 backlight_new = output->backlight_current + 25;
2605 if (backlight_new < 5)
2607 if (backlight_new > 255)
2608 backlight_new = 255;
2610 output->backlight_current = backlight_new;
2611 output->set_backlight(output, output->backlight_current);
2615 debug_repaint_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
2618 struct desktop_shell *shell = data;
2619 struct weston_compositor *compositor = shell->compositor;
2620 struct weston_surface *surface;
2622 if (shell->debug_repaint_surface) {
2623 weston_surface_destroy(shell->debug_repaint_surface);
2624 shell->debug_repaint_surface = NULL;
2626 surface = weston_surface_create(compositor);
2627 weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2);
2628 weston_surface_configure(surface, 0, 0, 8192, 8192);
2629 wl_list_insert(&compositor->fade_layer.surface_list,
2630 &surface->layer_link);
2631 weston_surface_assign_output(surface);
2632 pixman_region32_init(&surface->input);
2634 /* Here's the dirty little trick that makes the
2635 * repaint debugging work: we force an
2636 * update_transform first to update dependent state
2637 * and clear the geometry.dirty bit. Then we clear
2638 * the surface damage so it only gets repainted
2639 * piecewise as we repaint other things. */
2641 weston_surface_update_transform(surface);
2642 pixman_region32_fini(&surface->damage);
2643 pixman_region32_init(&surface->damage);
2644 shell->debug_repaint_surface = surface;
2649 force_kill_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
2652 struct wl_client *client;
2657 client = seat->keyboard->focus->resource.client;
2658 wl_client_get_credentials(client, &pid, &uid, &gid);
2664 shell_destroy(struct wl_listener *listener, void *data)
2666 struct desktop_shell *shell =
2667 container_of(listener, struct desktop_shell, destroy_listener);
2669 if (shell->child.client)
2670 wl_client_destroy(shell->child.client);
2672 wl_list_remove(&shell->lock_listener.link);
2673 wl_list_remove(&shell->unlock_listener.link);
2675 free(shell->screensaver.path);
2680 shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
2684 /* fixed bindings */
2685 weston_compositor_add_key_binding(ec, KEY_BACKSPACE,
2686 MODIFIER_CTRL | MODIFIER_ALT,
2687 terminate_binding, ec);
2688 weston_compositor_add_button_binding(ec, BTN_LEFT, 0,
2689 click_to_activate_binding,
2691 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
2692 MODIFIER_SUPER | MODIFIER_ALT,
2693 surface_opacity_binding, NULL);
2694 weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL,
2695 MODIFIER_SUPER, zoom_axis_binding,
2698 /* configurable bindings */
2699 mod = shell->binding_modifier;
2700 weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod,
2701 zoom_key_binding, NULL);
2702 weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod,
2703 zoom_key_binding, NULL);
2704 weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding,
2706 weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod,
2707 resize_binding, shell);
2708 weston_compositor_add_button_binding(ec, BTN_RIGHT, mod,
2709 rotate_binding, NULL);
2710 weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding,
2712 weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding,
2714 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0,
2715 backlight_binding, ec);
2716 weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding,
2718 weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0,
2719 backlight_binding, ec);
2720 weston_compositor_add_key_binding(ec, KEY_SPACE, mod,
2721 debug_repaint_binding, shell);
2722 weston_compositor_add_key_binding(ec, KEY_K, mod,
2723 force_kill_binding, shell);
2727 shell_init(struct weston_compositor *ec);
2730 shell_init(struct weston_compositor *ec)
2732 struct desktop_shell *shell;
2734 shell = malloc(sizeof *shell);
2738 memset(shell, 0, sizeof *shell);
2739 shell->compositor = ec;
2741 shell->destroy_listener.notify = shell_destroy;
2742 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
2743 shell->lock_listener.notify = lock;
2744 wl_signal_add(&ec->lock_signal, &shell->lock_listener);
2745 shell->unlock_listener.notify = unlock;
2746 wl_signal_add(&ec->unlock_signal, &shell->unlock_listener);
2747 ec->ping_handler = ping_handler;
2748 ec->shell_interface.create_shell_surface = create_shell_surface;
2749 ec->shell_interface.set_toplevel = set_toplevel;
2750 ec->shell_interface.set_transient = set_transient;
2751 ec->shell_interface.move = surface_move;
2752 ec->shell_interface.resize = surface_resize;
2754 wl_list_init(&shell->backgrounds);
2755 wl_list_init(&shell->panels);
2756 wl_list_init(&shell->screensaver.surfaces);
2758 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
2759 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
2760 weston_layer_init(&shell->toplevel_layer, &shell->panel_layer.link);
2761 weston_layer_init(&shell->background_layer,
2762 &shell->toplevel_layer.link);
2763 wl_list_init(&shell->lock_layer.surface_list);
2765 shell_configuration(shell);
2767 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
2768 shell, bind_shell) == NULL)
2771 if (wl_display_add_global(ec->wl_display,
2772 &desktop_shell_interface,
2773 shell, bind_desktop_shell) == NULL)
2776 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
2777 shell, bind_screensaver) == NULL)
2780 shell->child.deathstamp = weston_compositor_get_time();
2781 if (launch_desktop_shell_process(shell) != 0)
2784 shell->pointer_focus_listener.notify = handle_pointer_focus;
2785 if (ec->seat->seat.pointer)
2786 wl_signal_add(&ec->seat->seat.pointer->focus_signal,
2787 &shell->pointer_focus_listener);
2789 shell_add_bindings(ec, shell);