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>
34 #include <wayland-server.h>
35 #include "compositor.h"
36 #include "desktop-shell-server-protocol.h"
37 #include "../shared/config-parser.h"
46 struct desktop_shell {
47 struct weston_compositor *compositor;
49 struct wl_listener lock_listener;
50 struct wl_listener unlock_listener;
51 struct wl_listener destroy_listener;
53 struct weston_layer fullscreen_layer;
54 struct weston_layer panel_layer;
55 struct weston_layer toplevel_layer;
56 struct weston_layer background_layer;
57 struct weston_layer lock_layer;
60 struct weston_process process;
61 struct wl_client *client;
62 struct wl_resource *desktop_shell;
69 bool prepare_event_sent;
71 struct shell_surface *lock_surface;
72 struct wl_listener lock_surface_listener;
74 struct wl_list backgrounds;
75 struct wl_list panels;
80 struct wl_resource *binding;
81 struct wl_list surfaces;
82 struct weston_process process;
85 uint32_t binding_modifier;
86 enum animation_type win_animation_type;
87 struct weston_surface *debug_repaint_surface;
90 enum shell_surface_type {
94 SHELL_SURFACE_BACKGROUND,
96 SHELL_SURFACE_SCREENSAVER,
98 SHELL_SURFACE_TOPLEVEL,
99 SHELL_SURFACE_TRANSIENT,
100 SHELL_SURFACE_FULLSCREEN,
101 SHELL_SURFACE_MAXIMIZED,
106 struct wl_event_source *source;
110 struct shell_surface {
111 struct wl_resource resource;
113 struct weston_surface *surface;
114 struct wl_listener surface_destroy_listener;
115 struct shell_surface *parent;
116 struct desktop_shell *shell;
118 enum shell_surface_type type, next_type;
120 int32_t saved_x, saved_y;
121 bool saved_position_valid;
122 bool saved_rotation_valid;
126 struct weston_transform transform;
127 struct weston_matrix rotation;
131 struct wl_pointer_grab grab;
133 struct weston_transform parent_transform;
135 struct wl_input_device *device;
140 enum wl_shell_surface_fullscreen_method type;
141 struct weston_transform transform; /* matrix from x, y */
143 struct weston_surface *black_surface;
146 struct ping_timer *ping_timer;
149 struct weston_animation current;
153 } unresponsive_animation;
155 struct weston_output *fullscreen_output;
156 struct weston_output *output;
161 struct wl_pointer_grab grab;
162 struct shell_surface *shsurf;
163 struct wl_listener shsurf_destroy_listener;
166 struct weston_move_grab {
167 struct shell_grab base;
172 struct shell_grab base;
173 struct weston_matrix rotation;
180 static struct shell_surface *
181 get_shell_surface(struct weston_surface *surface);
183 static struct desktop_shell *
184 shell_surface_get_shell(struct shell_surface *shsurf);
187 shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
189 struct desktop_shell *shell;
190 struct weston_surface *top_fs_es;
192 shell = shell_surface_get_shell(shsurf);
194 if (wl_list_empty(&shell->fullscreen_layer.surface_list))
197 top_fs_es = container_of(shell->fullscreen_layer.surface_list.next,
198 struct weston_surface,
200 return (shsurf == get_shell_surface(top_fs_es));
204 destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
206 struct shell_grab *grab;
208 grab = container_of(listener, struct shell_grab,
209 shsurf_destroy_listener);
215 shell_grab_init(struct shell_grab *grab,
216 const struct wl_pointer_grab_interface *interface,
217 struct shell_surface *shsurf)
219 grab->grab.interface = interface;
220 grab->shsurf = shsurf;
221 grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
222 wl_signal_add(&shsurf->resource.destroy_signal,
223 &grab->shsurf_destroy_listener);
228 shell_grab_finish(struct shell_grab *grab)
230 wl_list_remove(&grab->shsurf_destroy_listener.link);
234 center_on_output(struct weston_surface *surface,
235 struct weston_output *output);
238 get_modifier(char *modifier)
241 return MODIFIER_SUPER;
243 if (!strcmp("ctrl", modifier))
244 return MODIFIER_CTRL;
245 else if (!strcmp("alt", modifier))
247 else if (!strcmp("super", modifier))
248 return MODIFIER_SUPER;
250 return MODIFIER_SUPER;
253 static enum animation_type
254 get_animation_type(char *animation)
257 return ANIMATION_NONE;
259 if (!strcmp("zoom", animation))
260 return ANIMATION_ZOOM;
261 else if (!strcmp("fade", animation))
262 return ANIMATION_FADE;
264 return ANIMATION_NONE;
268 shell_configuration(struct desktop_shell *shell)
273 char *modifier = NULL;
274 char *win_animation = NULL;
276 struct config_key shell_keys[] = {
277 { "binding-modifier", CONFIG_KEY_STRING, &modifier },
278 { "animation", CONFIG_KEY_STRING, &win_animation},
281 struct config_key saver_keys[] = {
282 { "path", CONFIG_KEY_STRING, &path },
283 { "duration", CONFIG_KEY_INTEGER, &duration },
286 struct config_section cs[] = {
287 { "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL },
288 { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL },
291 config_file = config_file_path("weston.ini");
292 parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell);
295 shell->screensaver.path = path;
296 shell->screensaver.duration = duration;
297 shell->binding_modifier = get_modifier(modifier);
298 shell->win_animation_type = get_animation_type(win_animation);
302 noop_grab_focus(struct wl_pointer_grab *grab,
303 struct wl_surface *surface, int32_t x, int32_t y)
309 move_grab_motion(struct wl_pointer_grab *grab,
310 uint32_t time, int32_t x, int32_t y)
312 struct weston_move_grab *move = (struct weston_move_grab *) grab;
313 struct wl_input_device *device = grab->input_device;
314 struct shell_surface *shsurf = move->base.shsurf;
315 struct weston_surface *es;
320 es = shsurf->surface;
322 weston_surface_configure(es,
323 device->x + move->dx,
324 device->y + move->dy,
325 es->geometry.width, es->geometry.height);
329 move_grab_button(struct wl_pointer_grab *grab,
330 uint32_t time, uint32_t button, uint32_t state)
332 struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
334 struct wl_input_device *device = grab->input_device;
336 if (device->button_count == 0 && state == 0) {
337 shell_grab_finish(shell_grab);
338 wl_input_device_end_pointer_grab(device);
343 static const struct wl_pointer_grab_interface move_grab_interface = {
350 unresponsive_surface_fade(struct shell_surface *shsurf, bool reverse)
352 shsurf->unresponsive_animation.fading_in = reverse ? 0 : 1;
354 if(!shsurf->unresponsive_animation.exists) {
355 wl_list_insert(&shsurf->surface->compositor->animation_list,
356 &shsurf->unresponsive_animation.current.link);
357 shsurf->unresponsive_animation.exists = 1;
358 shsurf->unresponsive_animation.timestamp = weston_compositor_get_time();
359 weston_surface_damage(shsurf->surface);
364 unresponsive_fade_frame(struct weston_animation *animation,
365 struct weston_output *output, uint32_t msecs)
367 struct shell_surface *shsurf =
368 container_of(animation, struct shell_surface, unresponsive_animation.current);
369 struct weston_surface *surface = shsurf->surface;
370 unsigned int step = 8;
372 if (!surface || !shsurf)
375 if (shsurf->unresponsive_animation.fading_in) {
376 while (step < msecs - shsurf->unresponsive_animation.timestamp) {
377 if (surface->saturation > 1)
378 surface->saturation -= 5;
379 if (surface->brightness > 200)
380 surface->brightness--;
382 shsurf->unresponsive_animation.timestamp += step;
385 if (surface->saturation <= 1 && surface->brightness <= 200) {
386 wl_list_remove(&shsurf->unresponsive_animation.current.link);
387 shsurf->unresponsive_animation.exists = 0;
391 while (step < msecs - shsurf->unresponsive_animation.timestamp) {
392 if (surface->saturation < 255)
393 surface->saturation += 5;
394 if (surface->brightness < 255)
395 surface->brightness++;
397 shsurf->unresponsive_animation.timestamp += step;
400 if (surface->saturation >= 255 && surface->brightness >= 255) {
401 surface->saturation = surface->brightness = 255;
402 wl_list_remove(&shsurf->unresponsive_animation.current.link);
403 shsurf->unresponsive_animation.exists = 0;
407 surface->geometry.dirty = 1;
408 weston_surface_damage(surface);
412 ping_timer_destroy(struct shell_surface *shsurf)
414 if (!shsurf || !shsurf->ping_timer)
417 if (shsurf->ping_timer->source)
418 wl_event_source_remove(shsurf->ping_timer->source);
420 free(shsurf->ping_timer);
421 shsurf->ping_timer = NULL;
425 ping_timeout_handler(void *data)
427 struct shell_surface *shsurf = data;
429 /* Client is not responding */
430 shsurf->unresponsive = 1;
431 unresponsive_surface_fade(shsurf, false);
437 ping_handler(struct weston_surface *surface, uint32_t serial)
439 struct shell_surface *shsurf;
440 shsurf = get_shell_surface(surface);
441 struct wl_event_loop *loop;
442 int ping_timeout = 2500;
446 if (!shsurf->resource.client)
449 if (!shsurf->ping_timer) {
450 shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer);
451 if (!shsurf->ping_timer)
454 shsurf->ping_timer->serial = serial;
455 loop = wl_display_get_event_loop(surface->compositor->wl_display);
456 shsurf->ping_timer->source =
457 wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
458 wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
460 wl_shell_surface_send_ping(&shsurf->resource, serial);
465 shell_surface_pong(struct wl_client *client, struct wl_resource *resource,
468 struct shell_surface *shsurf = resource->data;
470 if (shsurf->ping_timer->serial == serial) {
471 if (shsurf->unresponsive) {
472 /* Received pong from previously unresponsive client */
473 unresponsive_surface_fade(shsurf, true);
475 shsurf->unresponsive = 0;
476 ping_timer_destroy(shsurf);
481 shell_surface_set_title(struct wl_client *client,
482 struct wl_resource *resource, const char *title)
484 struct shell_surface *shsurf = resource->data;
487 shsurf->title = strdup(title);
491 shell_surface_set_class(struct wl_client *client,
492 struct wl_resource *resource, const char *class)
494 struct shell_surface *shsurf = resource->data;
497 shsurf->class = strdup(class);
501 weston_surface_move(struct weston_surface *es,
502 struct weston_input_device *wd)
504 struct weston_move_grab *move;
505 struct shell_surface *shsurf = get_shell_surface(es);
510 move = malloc(sizeof *move);
514 shell_grab_init(&move->base, &move_grab_interface, shsurf);
516 move->dx = es->geometry.x - wd->input_device.grab_x;
517 move->dy = es->geometry.y - wd->input_device.grab_y;
519 wl_input_device_start_pointer_grab(&wd->input_device,
522 wl_input_device_set_pointer_focus(&wd->input_device, NULL, 0, 0);
528 shell_surface_move(struct wl_client *client, struct wl_resource *resource,
529 struct wl_resource *input_resource, uint32_t serial)
531 struct weston_input_device *wd = input_resource->data;
532 struct shell_surface *shsurf = resource->data;
534 if (wd->input_device.button_count == 0 ||
535 wd->input_device.grab_serial != serial ||
536 wd->input_device.pointer_focus != &shsurf->surface->surface)
539 if (weston_surface_move(shsurf->surface, wd) < 0)
540 wl_resource_post_no_memory(resource);
543 struct weston_resize_grab {
544 struct shell_grab base;
546 int32_t width, height;
550 resize_grab_motion(struct wl_pointer_grab *grab,
551 uint32_t time, int32_t x, int32_t y)
553 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
554 struct wl_input_device *device = grab->input_device;
555 int32_t width, height;
556 int32_t from_x, from_y;
559 if (!resize->base.shsurf)
562 weston_surface_from_global(resize->base.shsurf->surface,
563 device->grab_x, device->grab_y,
565 weston_surface_from_global(resize->base.shsurf->surface,
566 device->x, device->y, &to_x, &to_y);
568 if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
569 width = resize->width + from_x - to_x;
570 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) {
571 width = resize->width + to_x - from_x;
573 width = resize->width;
576 if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) {
577 height = resize->height + from_y - to_y;
578 } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) {
579 height = resize->height + to_y - from_y;
581 height = resize->height;
584 wl_shell_surface_send_configure(&resize->base.shsurf->resource,
585 resize->edges, width, height);
589 resize_grab_button(struct wl_pointer_grab *grab,
590 uint32_t time, uint32_t button, uint32_t state)
592 struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
593 struct wl_input_device *device = grab->input_device;
595 if (device->button_count == 0 && state == 0) {
596 shell_grab_finish(&resize->base);
597 wl_input_device_end_pointer_grab(device);
602 static const struct wl_pointer_grab_interface resize_grab_interface = {
609 weston_surface_resize(struct shell_surface *shsurf,
610 struct weston_input_device *wd, uint32_t edges)
612 struct weston_resize_grab *resize;
614 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
617 if (edges == 0 || edges > 15 ||
618 (edges & 3) == 3 || (edges & 12) == 12)
621 resize = malloc(sizeof *resize);
625 shell_grab_init(&resize->base, &resize_grab_interface, shsurf);
627 resize->edges = edges;
628 resize->width = shsurf->surface->geometry.width;
629 resize->height = shsurf->surface->geometry.height;
631 wl_input_device_start_pointer_grab(&wd->input_device,
634 wl_input_device_set_pointer_focus(&wd->input_device, NULL, 0, 0);
640 shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
641 struct wl_resource *input_resource, uint32_t serial,
644 struct weston_input_device *wd = input_resource->data;
645 struct shell_surface *shsurf = resource->data;
647 if (shsurf->type == SHELL_SURFACE_FULLSCREEN)
650 if (wd->input_device.button_count == 0 ||
651 wd->input_device.grab_serial != serial ||
652 wd->input_device.pointer_focus != &shsurf->surface->surface)
655 if (weston_surface_resize(shsurf, wd, edges) < 0)
656 wl_resource_post_no_memory(resource);
659 static struct weston_output *
660 get_default_output(struct weston_compositor *compositor)
662 return container_of(compositor->output_list.next,
663 struct weston_output, link);
667 shell_unset_fullscreen(struct shell_surface *shsurf)
669 /* undo all fullscreen things here */
670 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
671 shell_surface_is_top_fullscreen(shsurf)) {
672 weston_output_switch_mode(shsurf->fullscreen_output,
673 shsurf->fullscreen_output->origin);
675 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
676 shsurf->fullscreen.framerate = 0;
677 wl_list_remove(&shsurf->fullscreen.transform.link);
678 wl_list_init(&shsurf->fullscreen.transform.link);
679 if (shsurf->fullscreen.black_surface)
680 weston_surface_destroy(shsurf->fullscreen.black_surface);
681 shsurf->fullscreen.black_surface = NULL;
682 shsurf->fullscreen_output = NULL;
683 weston_surface_set_position(shsurf->surface,
684 shsurf->saved_x, shsurf->saved_y);
685 if (shsurf->saved_rotation_valid) {
686 wl_list_insert(&shsurf->surface->geometry.transformation_list,
687 &shsurf->rotation.transform.link);
688 shsurf->saved_rotation_valid = false;
693 reset_shell_surface_type(struct shell_surface *surface)
695 switch (surface->type) {
696 case SHELL_SURFACE_FULLSCREEN:
697 shell_unset_fullscreen(surface);
699 case SHELL_SURFACE_MAXIMIZED:
700 surface->output = get_default_output(surface->surface->compositor);
701 weston_surface_set_position(surface->surface,
705 case SHELL_SURFACE_PANEL:
706 case SHELL_SURFACE_BACKGROUND:
707 wl_list_remove(&surface->link);
708 wl_list_init(&surface->link);
710 case SHELL_SURFACE_SCREENSAVER:
711 case SHELL_SURFACE_LOCK:
712 wl_resource_post_error(&surface->resource,
713 WL_DISPLAY_ERROR_INVALID_METHOD,
714 "cannot reassign surface type");
716 case SHELL_SURFACE_NONE:
717 case SHELL_SURFACE_TOPLEVEL:
718 case SHELL_SURFACE_TRANSIENT:
719 case SHELL_SURFACE_POPUP:
723 surface->type = SHELL_SURFACE_NONE;
728 set_surface_type(struct shell_surface *shsurf)
730 struct weston_surface *surface = shsurf->surface;
731 struct shell_surface *pshsurf = shsurf->parent;
732 struct weston_surface *pes;
733 struct shell_surface *priv;
734 struct desktop_shell *shell = shsurf->shell;
736 reset_shell_surface_type(shsurf);
738 shsurf->type = shsurf->next_type;
739 shsurf->next_type = SHELL_SURFACE_NONE;
741 switch (shsurf->type) {
742 case SHELL_SURFACE_TOPLEVEL:
744 case SHELL_SURFACE_TRANSIENT:
745 pes = pshsurf->surface;
746 weston_surface_set_position(surface,
747 pes->geometry.x + shsurf->popup.x,
748 pes->geometry.y + shsurf->popup.y);
751 case SHELL_SURFACE_MAXIMIZED:
752 shsurf->saved_x = surface->geometry.x;
753 shsurf->saved_y = surface->geometry.y;
754 shsurf->saved_position_valid = true;
757 case SHELL_SURFACE_FULLSCREEN:
758 shsurf->saved_x = surface->geometry.x;
759 shsurf->saved_y = surface->geometry.y;
760 shsurf->saved_position_valid = true;
762 if (!wl_list_empty(&shsurf->rotation.transform.link)) {
763 wl_list_remove(&shsurf->rotation.transform.link);
764 wl_list_init(&shsurf->rotation.transform.link);
765 shsurf->surface->geometry.dirty = 1;
766 shsurf->saved_rotation_valid = true;
770 case SHELL_SURFACE_BACKGROUND:
771 wl_list_for_each(priv, &shell->backgrounds, link) {
772 if (priv->output == shsurf->output) {
773 priv->surface->output = NULL;
774 wl_list_remove(&priv->surface->layer_link);
775 wl_list_remove(&priv->link);
780 wl_list_insert(&shell->backgrounds, &shsurf->link);
782 weston_surface_set_position(surface, shsurf->output->x,
786 case SHELL_SURFACE_PANEL:
787 wl_list_for_each(priv, &shell->panels, link) {
788 if (priv->output == shsurf->output) {
789 priv->surface->output = NULL;
790 wl_list_remove(&priv->surface->layer_link);
791 wl_list_remove(&priv->link);
796 wl_list_insert(&shell->panels, &shsurf->link);
798 weston_surface_set_position(surface, shsurf->output->x,
808 set_toplevel(struct shell_surface *shsurf)
810 shsurf->next_type = SHELL_SURFACE_TOPLEVEL;
814 shell_surface_set_toplevel(struct wl_client *client,
815 struct wl_resource *resource)
817 struct shell_surface *surface = resource->data;
819 set_toplevel(surface);
823 shell_surface_set_transient(struct wl_client *client,
824 struct wl_resource *resource,
825 struct wl_resource *parent_resource,
826 int x, int y, uint32_t flags)
828 struct shell_surface *shsurf = resource->data;
830 /* assign to parents output */
831 shsurf->parent = parent_resource->data;
834 shsurf->next_type = SHELL_SURFACE_TRANSIENT;
837 static struct desktop_shell *
838 shell_surface_get_shell(struct shell_surface *shsurf)
840 return shsurf->shell;
844 get_output_panel_height(struct desktop_shell *shell,
845 struct weston_output *output)
847 struct shell_surface *priv;
848 int panel_height = 0;
853 wl_list_for_each(priv, &shell->panels, link) {
854 if (priv->output == output) {
855 panel_height = priv->surface->geometry.height;
863 shell_surface_set_maximized(struct wl_client *client,
864 struct wl_resource *resource,
865 struct wl_resource *output_resource )
867 struct shell_surface *shsurf = resource->data;
868 struct weston_surface *es = shsurf->surface;
869 struct desktop_shell *shell = NULL;
870 uint32_t edges = 0, panel_height = 0;
872 /* get the default output, if the client set it as NULL
873 check whether the ouput is available */
875 shsurf->output = output_resource->data;
877 shsurf->output = get_default_output(es->compositor);
879 shell = shell_surface_get_shell(shsurf);
880 panel_height = get_output_panel_height(shell, es->output);
881 edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT;
883 wl_shell_surface_send_configure(&shsurf->resource, edges,
884 es->output->current->width,
885 es->output->current->height - panel_height);
887 shsurf->next_type = SHELL_SURFACE_MAXIMIZED;
891 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy);
893 static struct weston_surface *
894 create_black_surface(struct weston_compositor *ec,
895 struct weston_surface *fs_surface,
896 GLfloat x, GLfloat y, int w, int h)
898 struct weston_surface *surface = NULL;
900 surface = weston_surface_create(ec);
901 if (surface == NULL) {
902 fprintf(stderr, "no memory\n");
906 surface->configure = black_surface_configure;
907 surface->private = fs_surface;
908 weston_surface_configure(surface, x, y, w, h);
909 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
913 /* Create black surface and append it to the associated fullscreen surface.
914 * Handle size dismatch and positioning according to the method. */
916 shell_configure_fullscreen(struct shell_surface *shsurf)
918 struct weston_output *output = shsurf->fullscreen_output;
919 struct weston_surface *surface = shsurf->surface;
920 struct weston_matrix *matrix;
923 center_on_output(surface, output);
925 if (!shsurf->fullscreen.black_surface)
926 shsurf->fullscreen.black_surface =
927 create_black_surface(surface->compositor,
929 output->x, output->y,
930 output->current->width,
931 output->current->height);
933 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
934 wl_list_insert(&surface->layer_link,
935 &shsurf->fullscreen.black_surface->layer_link);
936 shsurf->fullscreen.black_surface->output = output;
938 switch (shsurf->fullscreen.type) {
939 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT:
941 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE:
942 matrix = &shsurf->fullscreen.transform.matrix;
943 weston_matrix_init(matrix);
944 scale = (float)output->current->width/(float)surface->geometry.width;
945 weston_matrix_scale(matrix, scale, scale, 1);
946 wl_list_remove(&shsurf->fullscreen.transform.link);
947 wl_list_insert(surface->geometry.transformation_list.prev,
948 &shsurf->fullscreen.transform.link);
949 weston_surface_set_position(surface, output->x, output->y);
951 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
952 if (shell_surface_is_top_fullscreen(shsurf)) {
953 struct weston_mode mode = {0,
954 surface->geometry.width,
955 surface->geometry.height,
956 shsurf->fullscreen.framerate};
958 if (weston_output_switch_mode(output, &mode) == 0) {
959 weston_surface_configure(shsurf->fullscreen.black_surface,
960 output->x, output->y,
961 output->current->width,
962 output->current->height);
963 weston_surface_set_position(surface, output->x, output->y);
968 case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
975 /* make the fullscreen and black surface at the top */
977 shell_stack_fullscreen(struct shell_surface *shsurf)
979 struct weston_output *output = shsurf->fullscreen_output;
980 struct weston_surface *surface = shsurf->surface;
981 struct desktop_shell *shell = shell_surface_get_shell(shsurf);
983 wl_list_remove(&surface->layer_link);
984 wl_list_insert(&shell->fullscreen_layer.surface_list,
985 &surface->layer_link);
986 weston_surface_damage(surface);
988 if (!shsurf->fullscreen.black_surface)
989 shsurf->fullscreen.black_surface =
990 create_black_surface(surface->compositor,
992 output->x, output->y,
993 output->current->width,
994 output->current->height);
996 wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
997 wl_list_insert(&surface->layer_link,
998 &shsurf->fullscreen.black_surface->layer_link);
999 weston_surface_damage(shsurf->fullscreen.black_surface);
1003 shell_map_fullscreen(struct shell_surface *shsurf)
1005 shell_stack_fullscreen(shsurf);
1006 shell_configure_fullscreen(shsurf);
1010 shell_surface_set_fullscreen(struct wl_client *client,
1011 struct wl_resource *resource,
1014 struct wl_resource *output_resource)
1016 struct shell_surface *shsurf = resource->data;
1017 struct weston_surface *es = shsurf->surface;
1019 if (output_resource)
1020 shsurf->output = output_resource->data;
1022 shsurf->output = get_default_output(es->compositor);
1024 shsurf->fullscreen_output = shsurf->output;
1025 shsurf->fullscreen.type = method;
1026 shsurf->fullscreen.framerate = framerate;
1027 shsurf->next_type = SHELL_SURFACE_FULLSCREEN;
1029 wl_shell_surface_send_configure(&shsurf->resource, 0,
1030 shsurf->output->current->width,
1031 shsurf->output->current->height);
1035 popup_grab_focus(struct wl_pointer_grab *grab,
1036 struct wl_surface *surface, int32_t x, int32_t y)
1038 struct wl_input_device *device = grab->input_device;
1039 struct shell_surface *priv =
1040 container_of(grab, struct shell_surface, popup.grab);
1041 struct wl_client *client = priv->surface->surface.resource.client;
1043 if (surface && surface->resource.client == client) {
1044 wl_input_device_set_pointer_focus(device, surface, x, y);
1045 grab->focus = surface;
1047 wl_input_device_set_pointer_focus(device, NULL, 0, 0);
1053 popup_grab_motion(struct wl_pointer_grab *grab,
1054 uint32_t time, int32_t sx, int32_t sy)
1056 struct wl_resource *resource;
1058 resource = grab->input_device->pointer_focus_resource;
1060 wl_input_device_send_motion(resource, time, sx, sy);
1064 popup_grab_button(struct wl_pointer_grab *grab,
1065 uint32_t time, uint32_t button, uint32_t state)
1067 struct wl_resource *resource;
1068 struct shell_surface *shsurf =
1069 container_of(grab, struct shell_surface, popup.grab);
1070 struct wl_display *display;
1073 resource = grab->input_device->pointer_focus_resource;
1075 display = wl_client_get_display(resource->client);
1076 serial = wl_display_get_serial(display);
1077 wl_input_device_send_button(resource, serial,
1078 time, button, state);
1079 } else if (state == 0 &&
1080 (shsurf->popup.initial_up ||
1081 time - shsurf->popup.device->grab_time > 500)) {
1082 wl_shell_surface_send_popup_done(&shsurf->resource);
1083 wl_input_device_end_pointer_grab(grab->input_device);
1084 shsurf->popup.grab.input_device = NULL;
1088 shsurf->popup.initial_up = 1;
1091 static const struct wl_pointer_grab_interface popup_grab_interface = {
1098 shell_map_popup(struct shell_surface *shsurf)
1100 struct wl_input_device *device = shsurf->popup.device;
1101 struct weston_surface *es = shsurf->surface;
1102 struct weston_surface *parent = shsurf->parent->surface;
1104 es->output = parent->output;
1105 shsurf->popup.grab.interface = &popup_grab_interface;
1107 weston_surface_update_transform(parent);
1108 if (parent->transform.enabled) {
1109 shsurf->popup.parent_transform.matrix =
1110 parent->transform.matrix;
1112 /* construct x, y translation matrix */
1113 weston_matrix_init(&shsurf->popup.parent_transform.matrix);
1114 shsurf->popup.parent_transform.matrix.d[12] =
1116 shsurf->popup.parent_transform.matrix.d[13] =
1119 wl_list_insert(es->geometry.transformation_list.prev,
1120 &shsurf->popup.parent_transform.link);
1121 weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);
1123 shsurf->popup.initial_up = 0;
1125 /* We don't require the grab to still be active, but if another
1126 * grab has started in the meantime, we end the popup now. */
1127 if (device->grab_serial == shsurf->popup.serial) {
1128 wl_input_device_start_pointer_grab(device,
1129 &shsurf->popup.grab);
1131 wl_shell_surface_send_popup_done(&shsurf->resource);
1136 shell_surface_set_popup(struct wl_client *client,
1137 struct wl_resource *resource,
1138 struct wl_resource *input_device_resource,
1140 struct wl_resource *parent_resource,
1141 int32_t x, int32_t y, uint32_t flags)
1143 struct shell_surface *shsurf = resource->data;
1145 shsurf->type = SHELL_SURFACE_POPUP;
1146 shsurf->parent = parent_resource->data;
1147 shsurf->popup.device = input_device_resource->data;
1148 shsurf->popup.serial = serial;
1149 shsurf->popup.x = x;
1150 shsurf->popup.y = y;
1153 static const struct wl_shell_surface_interface shell_surface_implementation = {
1156 shell_surface_resize,
1157 shell_surface_set_toplevel,
1158 shell_surface_set_transient,
1159 shell_surface_set_fullscreen,
1160 shell_surface_set_popup,
1161 shell_surface_set_maximized,
1162 shell_surface_set_title,
1163 shell_surface_set_class
1167 destroy_shell_surface(struct shell_surface *shsurf)
1169 if (shsurf->popup.grab.input_device)
1170 wl_input_device_end_pointer_grab(shsurf->popup.grab.input_device);
1172 if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
1173 shell_surface_is_top_fullscreen(shsurf)) {
1174 weston_output_switch_mode(shsurf->fullscreen_output,
1175 shsurf->fullscreen_output->origin);
1178 if (shsurf->fullscreen.black_surface)
1179 weston_surface_destroy(shsurf->fullscreen.black_surface);
1181 /* As destroy_resource() use wl_list_for_each_safe(),
1182 * we can always remove the listener.
1184 wl_list_remove(&shsurf->surface_destroy_listener.link);
1185 shsurf->surface->configure = NULL;
1186 ping_timer_destroy(shsurf);
1188 wl_list_remove(&shsurf->link);
1193 shell_destroy_shell_surface(struct wl_resource *resource)
1195 struct shell_surface *shsurf = resource->data;
1197 destroy_shell_surface(shsurf);
1201 shell_handle_surface_destroy(struct wl_listener *listener, void *data)
1203 struct shell_surface *shsurf = container_of(listener,
1204 struct shell_surface,
1205 surface_destroy_listener);
1207 /* tricky way to check if resource was in fact created */
1208 if (shsurf->resource.object.implementation != 0)
1209 wl_resource_destroy(&shsurf->resource);
1211 destroy_shell_surface(shsurf);
1214 static struct shell_surface *
1215 get_shell_surface(struct weston_surface *surface)
1217 struct wl_listener *listener;
1219 listener = wl_signal_get(&surface->surface.resource.destroy_signal,
1220 shell_handle_surface_destroy);
1222 return container_of(listener, struct shell_surface,
1223 surface_destroy_listener);
1229 shell_surface_configure(struct weston_surface *, int32_t, int32_t);
1232 create_shell_surface(void *shell, struct weston_surface *surface,
1233 struct shell_surface **ret)
1235 struct shell_surface *shsurf;
1237 if (surface->configure) {
1238 fprintf(stderr, "surface->configure already set\n");
1242 shsurf = calloc(1, sizeof *shsurf);
1244 fprintf(stderr, "no memory to allocate shell surface\n");
1248 surface->configure = shell_surface_configure;
1249 surface->compositor->shell_interface.shell = shell;
1251 shsurf->shell = (struct desktop_shell *) shell;
1252 shsurf->unresponsive = 0;
1253 shsurf->unresponsive_animation.exists = 0;
1254 shsurf->unresponsive_animation.fading_in = 0;
1255 shsurf->unresponsive_animation.current.frame = unresponsive_fade_frame;
1256 shsurf->saved_position_valid = false;
1257 shsurf->saved_rotation_valid = false;
1258 shsurf->surface = surface;
1259 shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
1260 shsurf->fullscreen.framerate = 0;
1261 shsurf->fullscreen.black_surface = NULL;
1262 shsurf->ping_timer = NULL;
1263 wl_list_init(&shsurf->fullscreen.transform.link);
1265 wl_signal_init(&shsurf->resource.destroy_signal);
1266 shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
1267 wl_signal_add(&surface->surface.resource.destroy_signal,
1268 &shsurf->surface_destroy_listener);
1270 /* init link so its safe to always remove it in destroy_shell_surface */
1271 wl_list_init(&shsurf->link);
1273 /* empty when not in use */
1274 wl_list_init(&shsurf->rotation.transform.link);
1275 weston_matrix_init(&shsurf->rotation.rotation);
1277 shsurf->type = SHELL_SURFACE_NONE;
1278 shsurf->next_type = SHELL_SURFACE_NONE;
1284 shell_get_shell_surface(struct wl_client *client,
1285 struct wl_resource *resource,
1287 struct wl_resource *surface_resource)
1289 struct weston_surface *surface = surface_resource->data;
1290 struct desktop_shell *shell = resource->data;
1291 struct shell_surface *shsurf;
1293 if (get_shell_surface(surface)) {
1294 wl_resource_post_error(surface_resource,
1295 WL_DISPLAY_ERROR_INVALID_OBJECT,
1296 "desktop_shell::get_shell_surface already requested");
1300 create_shell_surface(shell, surface, &shsurf);
1302 wl_resource_post_error(surface_resource,
1303 WL_DISPLAY_ERROR_INVALID_OBJECT,
1304 "surface->configure already set");
1308 shsurf->resource.destroy = shell_destroy_shell_surface;
1309 shsurf->resource.object.id = id;
1310 shsurf->resource.object.interface = &wl_shell_surface_interface;
1311 shsurf->resource.object.implementation =
1312 (void (**)(void)) &shell_surface_implementation;
1313 shsurf->resource.data = shsurf;
1315 wl_client_add_resource(client, &shsurf->resource);
1318 static const struct wl_shell_interface shell_implementation = {
1319 shell_get_shell_surface
1323 handle_screensaver_sigchld(struct weston_process *proc, int status)
1329 launch_screensaver(struct desktop_shell *shell)
1331 if (shell->screensaver.binding)
1334 if (!shell->screensaver.path)
1337 if (shell->screensaver.process.pid != 0) {
1338 fprintf(stderr, "old screensaver still running\n");
1342 weston_client_launch(shell->compositor,
1343 &shell->screensaver.process,
1344 shell->screensaver.path,
1345 handle_screensaver_sigchld);
1349 terminate_screensaver(struct desktop_shell *shell)
1351 if (shell->screensaver.process.pid == 0)
1354 kill(shell->screensaver.process.pid, SIGTERM);
1358 show_screensaver(struct desktop_shell *shell, struct shell_surface *surface)
1360 struct wl_list *list;
1362 if (shell->lock_surface)
1363 list = &shell->lock_surface->surface->layer_link;
1365 list = &shell->lock_layer.surface_list;
1367 wl_list_remove(&surface->surface->layer_link);
1368 wl_list_insert(list, &surface->surface->layer_link);
1369 surface->surface->output = surface->output;
1370 weston_surface_damage(surface->surface);
1374 hide_screensaver(struct desktop_shell *shell, struct shell_surface *surface)
1376 wl_list_remove(&surface->surface->layer_link);
1377 wl_list_init(&surface->surface->layer_link);
1378 surface->surface->output = NULL;
1382 desktop_shell_set_background(struct wl_client *client,
1383 struct wl_resource *resource,
1384 struct wl_resource *output_resource,
1385 struct wl_resource *surface_resource)
1387 struct shell_surface *shsurf = surface_resource->data;
1389 shsurf->next_type = SHELL_SURFACE_BACKGROUND;
1390 shsurf->output = output_resource->data;
1392 desktop_shell_send_configure(resource, 0,
1394 shsurf->output->current->width,
1395 shsurf->output->current->height);
1399 desktop_shell_set_panel(struct wl_client *client,
1400 struct wl_resource *resource,
1401 struct wl_resource *output_resource,
1402 struct wl_resource *surface_resource)
1404 struct shell_surface *shsurf = surface_resource->data;
1406 shsurf->next_type = SHELL_SURFACE_PANEL;
1407 shsurf->output = output_resource->data;
1409 desktop_shell_send_configure(resource, 0,
1411 shsurf->output->current->width,
1412 shsurf->output->current->height);
1416 handle_lock_surface_destroy(struct wl_listener *listener, void *data)
1418 struct desktop_shell *shell =
1419 container_of(listener, struct desktop_shell, lock_surface_listener);
1421 fprintf(stderr, "lock surface gone\n");
1422 shell->lock_surface = NULL;
1426 desktop_shell_set_lock_surface(struct wl_client *client,
1427 struct wl_resource *resource,
1428 struct wl_resource *surface_resource)
1430 struct desktop_shell *shell = resource->data;
1431 struct shell_surface *surface = surface_resource->data;
1433 shell->prepare_event_sent = false;
1438 shell->lock_surface = surface;
1440 shell->lock_surface_listener.notify = handle_lock_surface_destroy;
1441 wl_signal_add(&surface_resource->destroy_signal,
1442 &shell->lock_surface_listener);
1444 shell->lock_surface->next_type = SHELL_SURFACE_LOCK;
1448 resume_desktop(struct desktop_shell *shell)
1450 struct shell_surface *tmp;
1452 wl_list_for_each(tmp, &shell->screensaver.surfaces, link)
1453 hide_screensaver(shell, tmp);
1455 terminate_screensaver(shell);
1457 wl_list_remove(&shell->lock_layer.link);
1458 wl_list_insert(&shell->compositor->cursor_layer.link,
1459 &shell->fullscreen_layer.link);
1460 wl_list_insert(&shell->fullscreen_layer.link,
1461 &shell->panel_layer.link);
1462 wl_list_insert(&shell->panel_layer.link, &shell->toplevel_layer.link);
1464 shell->locked = false;
1465 shell->compositor->idle_time = shell->compositor->option_idle_time;
1466 weston_compositor_wake(shell->compositor);
1467 weston_compositor_damage_all(shell->compositor);
1471 desktop_shell_unlock(struct wl_client *client,
1472 struct wl_resource *resource)
1474 struct desktop_shell *shell = resource->data;
1476 shell->prepare_event_sent = false;
1479 resume_desktop(shell);
1482 static const struct desktop_shell_interface desktop_shell_implementation = {
1483 desktop_shell_set_background,
1484 desktop_shell_set_panel,
1485 desktop_shell_set_lock_surface,
1486 desktop_shell_unlock
1489 static enum shell_surface_type
1490 get_shell_surface_type(struct weston_surface *surface)
1492 struct shell_surface *shsurf;
1494 shsurf = get_shell_surface(surface);
1496 return SHELL_SURFACE_NONE;
1497 return shsurf->type;
1501 move_binding(struct wl_input_device *device, uint32_t time,
1502 uint32_t key, uint32_t button, uint32_t axis, int32_t value,
1505 struct weston_surface *surface =
1506 (struct weston_surface *) device->pointer_focus;
1508 if (surface == NULL)
1511 switch (get_shell_surface_type(surface)) {
1512 case SHELL_SURFACE_PANEL:
1513 case SHELL_SURFACE_BACKGROUND:
1514 case SHELL_SURFACE_FULLSCREEN:
1515 case SHELL_SURFACE_SCREENSAVER:
1521 weston_surface_move(surface, (struct weston_input_device *) device);
1525 resize_binding(struct wl_input_device *device, uint32_t time,
1526 uint32_t key, uint32_t button, uint32_t axis, int32_t value,
1529 struct weston_surface *surface =
1530 (struct weston_surface *) device->pointer_focus;
1533 struct shell_surface *shsurf;
1535 if (surface == NULL)
1538 shsurf = get_shell_surface(surface);
1542 switch (shsurf->type) {
1543 case SHELL_SURFACE_PANEL:
1544 case SHELL_SURFACE_BACKGROUND:
1545 case SHELL_SURFACE_FULLSCREEN:
1546 case SHELL_SURFACE_SCREENSAVER:
1552 weston_surface_from_global(surface,
1553 device->grab_x, device->grab_y, &x, &y);
1555 if (x < surface->geometry.width / 3)
1556 edges |= WL_SHELL_SURFACE_RESIZE_LEFT;
1557 else if (x < 2 * surface->geometry.width / 3)
1560 edges |= WL_SHELL_SURFACE_RESIZE_RIGHT;
1562 if (y < surface->geometry.height / 3)
1563 edges |= WL_SHELL_SURFACE_RESIZE_TOP;
1564 else if (y < 2 * surface->geometry.height / 3)
1567 edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM;
1569 weston_surface_resize(shsurf, (struct weston_input_device *) device,
1574 surface_opacity_binding(struct wl_input_device *device, uint32_t time,
1575 uint32_t key, uint32_t button, uint32_t axis,
1576 int32_t value, void *data)
1579 struct shell_surface *shsurf;
1580 struct weston_surface *surface =
1581 (struct weston_surface *) device->pointer_focus;
1583 if (surface == NULL)
1586 shsurf = get_shell_surface(surface);
1590 switch (shsurf->type) {
1591 case SHELL_SURFACE_BACKGROUND:
1592 case SHELL_SURFACE_SCREENSAVER:
1598 surface->alpha += value * step;
1600 if (surface->alpha > 255)
1601 surface->alpha = 255;
1602 if (surface->alpha < step)
1603 surface->alpha = step;
1605 surface->geometry.dirty = 1;
1606 weston_surface_damage(surface);
1610 zoom_binding(struct wl_input_device *device, uint32_t time,
1611 uint32_t key, uint32_t button, uint32_t axis, int32_t value,
1614 struct weston_input_device *wd = (struct weston_input_device *) device;
1615 struct weston_compositor *compositor = wd->compositor;
1616 struct weston_output *output;
1618 wl_list_for_each(output, &compositor->output_list, link) {
1619 if (pixman_region32_contains_point(&output->region,
1620 device->x, device->y, NULL)) {
1621 output->zoom.active = 1;
1622 output->zoom.level += output->zoom.increment * -value;
1624 if (output->zoom.level >= 1.0) {
1625 output->zoom.active = 0;
1626 output->zoom.level = 1.0;
1629 if (output->zoom.level < output->zoom.increment)
1630 output->zoom.level = output->zoom.increment;
1632 weston_output_update_zoom(output, device->x, device->y);
1638 terminate_binding(struct wl_input_device *device, uint32_t time,
1639 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
1641 struct weston_compositor *compositor = data;
1644 wl_display_terminate(compositor->wl_display);
1648 rotate_grab_motion(struct wl_pointer_grab *grab,
1649 uint32_t time, int32_t x, int32_t y)
1651 struct rotate_grab *rotate =
1652 container_of(grab, struct rotate_grab, base.grab);
1653 struct wl_input_device *device = grab->input_device;
1654 struct shell_surface *shsurf = rotate->base.shsurf;
1655 struct weston_surface *surface;
1656 GLfloat cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
1661 surface = shsurf->surface;
1663 cx = 0.5f * surface->geometry.width;
1664 cy = 0.5f * surface->geometry.height;
1666 dx = device->x - rotate->center.x;
1667 dy = device->y - rotate->center.y;
1668 r = sqrtf(dx * dx + dy * dy);
1670 wl_list_remove(&shsurf->rotation.transform.link);
1671 shsurf->surface->geometry.dirty = 1;
1674 struct weston_matrix *matrix =
1675 &shsurf->rotation.transform.matrix;
1677 weston_matrix_init(&rotate->rotation);
1678 rotate->rotation.d[0] = dx / r;
1679 rotate->rotation.d[4] = -dy / r;
1680 rotate->rotation.d[1] = -rotate->rotation.d[4];
1681 rotate->rotation.d[5] = rotate->rotation.d[0];
1683 weston_matrix_init(matrix);
1684 weston_matrix_translate(matrix, -cx, -cy, 0.0f);
1685 weston_matrix_multiply(matrix, &shsurf->rotation.rotation);
1686 weston_matrix_multiply(matrix, &rotate->rotation);
1687 weston_matrix_translate(matrix, cx, cy, 0.0f);
1690 &shsurf->surface->geometry.transformation_list,
1691 &shsurf->rotation.transform.link);
1693 wl_list_init(&shsurf->rotation.transform.link);
1694 weston_matrix_init(&shsurf->rotation.rotation);
1695 weston_matrix_init(&rotate->rotation);
1698 /* We need to adjust the position of the surface
1699 * in case it was resized in a rotated state before */
1700 cposx = surface->geometry.x + cx;
1701 cposy = surface->geometry.y + cy;
1702 dposx = rotate->center.x - cposx;
1703 dposy = rotate->center.y - cposy;
1704 if (dposx != 0.0f || dposy != 0.0f) {
1705 weston_surface_set_position(surface,
1706 surface->geometry.x + dposx,
1707 surface->geometry.y + dposy);
1710 /* Repaint implies weston_surface_update_transform(), which
1711 * lazily applies the damage due to rotation update.
1713 weston_compositor_schedule_repaint(shsurf->surface->compositor);
1717 rotate_grab_button(struct wl_pointer_grab *grab,
1718 uint32_t time, uint32_t button, uint32_t state)
1720 struct rotate_grab *rotate =
1721 container_of(grab, struct rotate_grab, base.grab);
1722 struct wl_input_device *device = grab->input_device;
1723 struct shell_surface *shsurf = rotate->base.shsurf;
1725 if (device->button_count == 0 && state == 0) {
1727 weston_matrix_multiply(&shsurf->rotation.rotation,
1729 shell_grab_finish(&rotate->base);
1730 wl_input_device_end_pointer_grab(device);
1735 static const struct wl_pointer_grab_interface rotate_grab_interface = {
1742 rotate_binding(struct wl_input_device *device, uint32_t time,
1743 uint32_t key, uint32_t button, uint32_t axis, int32_t value,
1746 struct weston_surface *base_surface =
1747 (struct weston_surface *) device->pointer_focus;
1748 struct shell_surface *surface;
1749 struct rotate_grab *rotate;
1753 if (base_surface == NULL)
1756 surface = get_shell_surface(base_surface);
1760 switch (surface->type) {
1761 case SHELL_SURFACE_PANEL:
1762 case SHELL_SURFACE_BACKGROUND:
1763 case SHELL_SURFACE_FULLSCREEN:
1764 case SHELL_SURFACE_SCREENSAVER:
1770 rotate = malloc(sizeof *rotate);
1774 shell_grab_init(&rotate->base, &rotate_grab_interface, surface);
1776 weston_surface_to_global(surface->surface,
1777 surface->surface->geometry.width / 2,
1778 surface->surface->geometry.height / 2,
1779 &rotate->center.x, &rotate->center.y);
1781 wl_input_device_start_pointer_grab(device, &rotate->base.grab);
1783 dx = device->x - rotate->center.x;
1784 dy = device->y - rotate->center.y;
1785 r = sqrtf(dx * dx + dy * dy);
1787 struct weston_matrix inverse;
1789 weston_matrix_init(&inverse);
1790 inverse.d[0] = dx / r;
1791 inverse.d[4] = dy / r;
1792 inverse.d[1] = -inverse.d[4];
1793 inverse.d[5] = inverse.d[0];
1794 weston_matrix_multiply(&surface->rotation.rotation, &inverse);
1796 weston_matrix_init(&rotate->rotation);
1797 rotate->rotation.d[0] = dx / r;
1798 rotate->rotation.d[4] = -dy / r;
1799 rotate->rotation.d[1] = -rotate->rotation.d[4];
1800 rotate->rotation.d[5] = rotate->rotation.d[0];
1802 weston_matrix_init(&surface->rotation.rotation);
1803 weston_matrix_init(&rotate->rotation);
1806 wl_input_device_set_pointer_focus(device, NULL, 0, 0);
1810 activate(struct desktop_shell *shell, struct weston_surface *es,
1811 struct weston_input_device *device)
1813 struct weston_surface *surf, *prev;
1815 weston_surface_activate(es, device);
1817 switch (get_shell_surface_type(es)) {
1818 case SHELL_SURFACE_BACKGROUND:
1819 case SHELL_SURFACE_PANEL:
1820 case SHELL_SURFACE_LOCK:
1823 case SHELL_SURFACE_SCREENSAVER:
1824 /* always below lock surface */
1825 if (shell->lock_surface)
1826 weston_surface_restack(es,
1827 &shell->lock_surface->surface->layer_link);
1829 case SHELL_SURFACE_FULLSCREEN:
1830 /* should on top of panels */
1831 shell_stack_fullscreen(get_shell_surface(es));
1832 shell_configure_fullscreen(get_shell_surface(es));
1835 /* move the fullscreen surfaces down into the toplevel layer */
1836 if (!wl_list_empty(&shell->fullscreen_layer.surface_list)) {
1837 wl_list_for_each_reverse_safe(surf,
1839 &shell->fullscreen_layer.surface_list,
1841 weston_surface_restack(surf,
1842 &shell->toplevel_layer.surface_list);
1845 weston_surface_restack(es,
1846 &shell->toplevel_layer.surface_list);
1851 /* no-op func for checking black surface */
1853 black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
1858 is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface)
1860 if (es->configure == black_surface_configure) {
1862 *fs_surface = (struct weston_surface *)es->private;
1869 click_to_activate_binding(struct wl_input_device *device,
1870 uint32_t time, uint32_t key,
1871 uint32_t button, uint32_t axis, int32_t state, void *data)
1873 struct weston_input_device *wd = (struct weston_input_device *) device;
1874 struct desktop_shell *shell = data;
1875 struct weston_surface *focus;
1876 struct weston_surface *upper;
1878 focus = (struct weston_surface *) device->pointer_focus;
1882 if (is_black_surface(focus, &upper))
1885 if (state && device->pointer_grab == &device->default_pointer_grab)
1886 activate(shell, focus, wd);
1890 lock(struct wl_listener *listener, void *data)
1892 struct desktop_shell *shell =
1893 container_of(listener, struct desktop_shell, lock_listener);
1894 struct weston_input_device *device;
1895 struct shell_surface *shsurf;
1896 struct weston_output *output;
1898 if (shell->locked) {
1899 wl_list_for_each(output, &shell->compositor->output_list, link)
1900 /* TODO: find a way to jump to other DPMS levels */
1901 if (output->set_dpms)
1902 output->set_dpms(output, WESTON_DPMS_STANDBY);
1906 shell->locked = true;
1908 /* Hide all surfaces by removing the fullscreen, panel and
1909 * toplevel layers. This way nothing else can show or receive
1910 * input events while we are locked. */
1912 wl_list_remove(&shell->panel_layer.link);
1913 wl_list_remove(&shell->toplevel_layer.link);
1914 wl_list_remove(&shell->fullscreen_layer.link);
1915 wl_list_insert(&shell->compositor->cursor_layer.link,
1916 &shell->lock_layer.link);
1918 launch_screensaver(shell);
1920 wl_list_for_each(shsurf, &shell->screensaver.surfaces, link)
1921 show_screensaver(shell, shsurf);
1923 if (!wl_list_empty(&shell->screensaver.surfaces)) {
1924 shell->compositor->idle_time = shell->screensaver.duration;
1925 weston_compositor_wake(shell->compositor);
1926 shell->compositor->state = WESTON_COMPOSITOR_IDLE;
1929 /* reset pointer foci */
1930 weston_compositor_schedule_repaint(shell->compositor);
1932 /* reset keyboard foci */
1933 wl_list_for_each(device, &shell->compositor->input_device_list, link) {
1934 wl_input_device_set_keyboard_focus(&device->input_device,
1938 /* TODO: disable bindings that should not work while locked. */
1940 /* All this must be undone in resume_desktop(). */
1944 unlock(struct wl_listener *listener, void *data)
1946 struct desktop_shell *shell =
1947 container_of(listener, struct desktop_shell, unlock_listener);
1949 if (!shell->locked || shell->lock_surface) {
1950 weston_compositor_wake(shell->compositor);
1954 /* If desktop-shell client has gone away, unlock immediately. */
1955 if (!shell->child.desktop_shell) {
1956 resume_desktop(shell);
1960 if (shell->prepare_event_sent)
1963 desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell);
1964 shell->prepare_event_sent = true;
1968 center_on_output(struct weston_surface *surface, struct weston_output *output)
1970 struct weston_mode *mode = output->current;
1971 GLfloat x = (mode->width - surface->geometry.width) / 2;
1972 GLfloat y = (mode->height - surface->geometry.height) / 2;
1974 weston_surface_set_position(surface, output->x + x, output->y + y);
1978 map(struct desktop_shell *shell, struct weston_surface *surface,
1979 int32_t width, int32_t height, int32_t sx, int32_t sy)
1981 struct weston_compositor *compositor = shell->compositor;
1982 struct shell_surface *shsurf;
1983 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
1984 struct weston_surface *parent;
1985 int panel_height = 0;
1987 shsurf = get_shell_surface(surface);
1989 surface_type = shsurf->type;
1991 surface->geometry.width = width;
1992 surface->geometry.height = height;
1993 surface->geometry.dirty = 1;
1995 /* initial positioning, see also configure() */
1996 switch (surface_type) {
1997 case SHELL_SURFACE_TOPLEVEL:
1998 weston_surface_set_position(surface, 10 + random() % 400,
1999 10 + random() % 400);
2001 case SHELL_SURFACE_SCREENSAVER:
2002 center_on_output(surface, shsurf->fullscreen_output);
2004 case SHELL_SURFACE_FULLSCREEN:
2005 shell_map_fullscreen(shsurf);
2007 case SHELL_SURFACE_MAXIMIZED:
2008 /* use surface configure to set the geometry */
2009 panel_height = get_output_panel_height(shell,surface->output);
2010 weston_surface_set_position(surface, surface->output->x,
2011 surface->output->y + panel_height);
2013 case SHELL_SURFACE_LOCK:
2014 center_on_output(surface, get_default_output(compositor));
2016 case SHELL_SURFACE_POPUP:
2017 shell_map_popup(shsurf);
2018 case SHELL_SURFACE_NONE:
2019 weston_surface_set_position(surface,
2020 surface->geometry.x + sx,
2021 surface->geometry.y + sy);
2027 /* surface stacking order, see also activate() */
2028 switch (surface_type) {
2029 case SHELL_SURFACE_BACKGROUND:
2030 /* background always visible, at the bottom */
2031 wl_list_insert(&shell->background_layer.surface_list,
2032 &surface->layer_link);
2034 case SHELL_SURFACE_PANEL:
2035 /* panel always on top, hidden while locked */
2036 wl_list_insert(&shell->panel_layer.surface_list,
2037 &surface->layer_link);
2039 case SHELL_SURFACE_LOCK:
2040 /* lock surface always visible, on top */
2041 wl_list_insert(&shell->lock_layer.surface_list,
2042 &surface->layer_link);
2043 weston_compositor_wake(compositor);
2045 case SHELL_SURFACE_SCREENSAVER:
2046 /* If locked, show it. */
2047 if (shell->locked) {
2048 show_screensaver(shell, shsurf);
2049 compositor->idle_time = shell->screensaver.duration;
2050 weston_compositor_wake(compositor);
2051 if (!shell->lock_surface)
2052 compositor->state = WESTON_COMPOSITOR_IDLE;
2055 case SHELL_SURFACE_POPUP:
2056 case SHELL_SURFACE_TRANSIENT:
2057 parent = shsurf->parent->surface;
2058 wl_list_insert(parent->layer_link.prev, &surface->layer_link);
2060 case SHELL_SURFACE_FULLSCREEN:
2061 case SHELL_SURFACE_NONE:
2064 wl_list_insert(&shell->toplevel_layer.surface_list,
2065 &surface->layer_link);
2069 if (surface_type != SHELL_SURFACE_NONE) {
2070 weston_surface_assign_output(surface);
2071 if (surface_type == SHELL_SURFACE_MAXIMIZED)
2072 surface->output = shsurf->output;
2075 switch (surface_type) {
2076 case SHELL_SURFACE_TOPLEVEL:
2077 case SHELL_SURFACE_TRANSIENT:
2078 case SHELL_SURFACE_FULLSCREEN:
2079 case SHELL_SURFACE_MAXIMIZED:
2081 activate(shell, surface,
2082 (struct weston_input_device *)
2083 compositor->input_device);
2089 if (surface_type == SHELL_SURFACE_TOPLEVEL)
2091 switch (shell->win_animation_type) {
2092 case ANIMATION_FADE:
2093 weston_fade_run(surface, NULL, NULL);
2095 case ANIMATION_ZOOM:
2096 weston_zoom_run(surface, 0.8, 1.0, NULL, NULL);
2105 configure(struct desktop_shell *shell, struct weston_surface *surface,
2106 GLfloat x, GLfloat y, int32_t width, int32_t height)
2108 enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
2109 struct shell_surface *shsurf;
2111 shsurf = get_shell_surface(surface);
2113 surface_type = shsurf->type;
2115 surface->geometry.x = x;
2116 surface->geometry.y = y;
2117 surface->geometry.width = width;
2118 surface->geometry.height = height;
2119 surface->geometry.dirty = 1;
2121 switch (surface_type) {
2122 case SHELL_SURFACE_SCREENSAVER:
2123 center_on_output(surface, shsurf->fullscreen_output);
2125 case SHELL_SURFACE_FULLSCREEN:
2126 shell_stack_fullscreen(shsurf);
2127 shell_configure_fullscreen(shsurf);
2129 case SHELL_SURFACE_MAXIMIZED:
2130 /* setting x, y and using configure to change that geometry */
2131 surface->geometry.x = surface->output->x;
2132 surface->geometry.y = surface->output->y +
2133 get_output_panel_height(shell,surface->output);
2135 case SHELL_SURFACE_TOPLEVEL:
2141 /* XXX: would a fullscreen surface need the same handling? */
2142 if (surface->output) {
2143 weston_surface_assign_output(surface);
2145 if (surface_type == SHELL_SURFACE_SCREENSAVER)
2146 surface->output = shsurf->output;
2147 else if (surface_type == SHELL_SURFACE_MAXIMIZED)
2148 surface->output = shsurf->output;
2153 shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
2155 struct shell_surface *shsurf = get_shell_surface(es);
2156 struct desktop_shell *shell = shsurf->shell;
2157 int type_changed = 0;
2159 if (shsurf->next_type != SHELL_SURFACE_NONE &&
2160 shsurf->type != shsurf->next_type) {
2161 set_surface_type(shsurf);
2165 if (!weston_surface_is_mapped(es)) {
2166 map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
2167 } else if (type_changed || sx != 0 || sy != 0 ||
2168 es->geometry.width != es->buffer->width ||
2169 es->geometry.height != es->buffer->height) {
2170 GLfloat from_x, from_y;
2173 weston_surface_to_global_float(es, 0, 0, &from_x, &from_y);
2174 weston_surface_to_global_float(es, sx, sy, &to_x, &to_y);
2175 configure(shell, es,
2176 es->geometry.x + to_x - from_x,
2177 es->geometry.y + to_y - from_y,
2178 es->buffer->width, es->buffer->height);
2182 static int launch_desktop_shell_process(struct desktop_shell *shell);
2185 desktop_shell_sigchld(struct weston_process *process, int status)
2188 struct desktop_shell *shell =
2189 container_of(process, struct desktop_shell, child.process);
2191 shell->child.process.pid = 0;
2192 shell->child.client = NULL; /* already destroyed by wayland */
2194 /* if desktop-shell dies more than 5 times in 30 seconds, give up */
2195 time = weston_compositor_get_time();
2196 if (time - shell->child.deathstamp > 30000) {
2197 shell->child.deathstamp = time;
2198 shell->child.deathcount = 0;
2201 shell->child.deathcount++;
2202 if (shell->child.deathcount > 5) {
2203 fprintf(stderr, "weston-desktop-shell died, giving up.\n");
2207 fprintf(stderr, "weston-desktop-shell died, respawning...\n");
2208 launch_desktop_shell_process(shell);
2212 launch_desktop_shell_process(struct desktop_shell *shell)
2214 const char *shell_exe = LIBEXECDIR "/weston-desktop-shell";
2216 shell->child.client = weston_client_launch(shell->compositor,
2217 &shell->child.process,
2219 desktop_shell_sigchld);
2221 if (!shell->child.client)
2227 bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
2229 struct desktop_shell *shell = data;
2231 wl_client_add_object(client, &wl_shell_interface,
2232 &shell_implementation, id, shell);
2236 unbind_desktop_shell(struct wl_resource *resource)
2238 struct desktop_shell *shell = resource->data;
2241 resume_desktop(shell);
2243 shell->child.desktop_shell = NULL;
2244 shell->prepare_event_sent = false;
2249 bind_desktop_shell(struct wl_client *client,
2250 void *data, uint32_t version, uint32_t id)
2252 struct desktop_shell *shell = data;
2253 struct wl_resource *resource;
2255 resource = wl_client_add_object(client, &desktop_shell_interface,
2256 &desktop_shell_implementation,
2259 if (client == shell->child.client) {
2260 resource->destroy = unbind_desktop_shell;
2261 shell->child.desktop_shell = resource;
2265 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2266 "permission to bind desktop_shell denied");
2267 wl_resource_destroy(resource);
2271 screensaver_set_surface(struct wl_client *client,
2272 struct wl_resource *resource,
2273 struct wl_resource *shell_surface_resource,
2274 struct wl_resource *output_resource)
2276 struct desktop_shell *shell = resource->data;
2277 struct shell_surface *surface = shell_surface_resource->data;
2278 struct weston_output *output = output_resource->data;
2280 surface->next_type = SHELL_SURFACE_SCREENSAVER;
2282 surface->fullscreen_output = output;
2283 surface->output = output;
2284 wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
2287 static const struct screensaver_interface screensaver_implementation = {
2288 screensaver_set_surface
2292 unbind_screensaver(struct wl_resource *resource)
2294 struct desktop_shell *shell = resource->data;
2296 shell->screensaver.binding = NULL;
2301 bind_screensaver(struct wl_client *client,
2302 void *data, uint32_t version, uint32_t id)
2304 struct desktop_shell *shell = data;
2305 struct wl_resource *resource;
2307 resource = wl_client_add_object(client, &screensaver_interface,
2308 &screensaver_implementation,
2311 if (shell->screensaver.binding == NULL) {
2312 resource->destroy = unbind_screensaver;
2313 shell->screensaver.binding = resource;
2317 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
2318 "interface object already bound");
2319 wl_resource_destroy(resource);
2323 struct desktop_shell *shell;
2324 struct weston_surface *current;
2325 struct wl_listener listener;
2326 struct wl_keyboard_grab grab;
2330 switcher_next(struct switcher *switcher)
2332 struct weston_compositor *compositor = switcher->shell->compositor;
2333 struct weston_surface *surface;
2334 struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
2335 struct shell_surface *shsurf;
2337 wl_list_for_each(surface, &compositor->surface_list, link) {
2338 switch (get_shell_surface_type(surface)) {
2339 case SHELL_SURFACE_TOPLEVEL:
2340 case SHELL_SURFACE_FULLSCREEN:
2341 case SHELL_SURFACE_MAXIMIZED:
2344 if (prev == switcher->current)
2347 surface->alpha = 64;
2348 surface->geometry.dirty = 1;
2349 weston_surface_damage(surface);
2355 if (is_black_surface(surface, NULL)) {
2356 surface->alpha = 64;
2357 surface->geometry.dirty = 1;
2358 weston_surface_damage(surface);
2368 wl_list_remove(&switcher->listener.link);
2369 wl_signal_add(&next->surface.resource.destroy_signal,
2370 &switcher->listener);
2372 switcher->current = next;
2375 shsurf = get_shell_surface(switcher->current);
2376 if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN)
2377 shsurf->fullscreen.black_surface->alpha = 255;
2381 switcher_handle_surface_destroy(struct wl_listener *listener, void *data)
2383 struct switcher *switcher =
2384 container_of(listener, struct switcher, listener);
2386 switcher_next(switcher);
2390 switcher_destroy(struct switcher *switcher, uint32_t time)
2392 struct weston_compositor *compositor = switcher->shell->compositor;
2393 struct weston_surface *surface;
2394 struct weston_input_device *device =
2395 (struct weston_input_device *) switcher->grab.input_device;
2397 wl_list_for_each(surface, &compositor->surface_list, link) {
2398 surface->alpha = 255;
2399 weston_surface_damage(surface);
2402 if (switcher->current)
2403 activate(switcher->shell, switcher->current, device);
2404 wl_list_remove(&switcher->listener.link);
2405 wl_input_device_end_keyboard_grab(&device->input_device);
2410 switcher_key(struct wl_keyboard_grab *grab,
2411 uint32_t time, uint32_t key, uint32_t state)
2413 struct switcher *switcher = container_of(grab, struct switcher, grab);
2414 struct weston_input_device *device =
2415 (struct weston_input_device *) grab->input_device;
2417 if ((device->modifier_state & switcher->shell->binding_modifier) == 0) {
2418 switcher_destroy(switcher, time);
2419 } else if (key == KEY_TAB && state) {
2420 switcher_next(switcher);
2424 static const struct wl_keyboard_grab_interface switcher_grab = {
2429 switcher_binding(struct wl_input_device *device, uint32_t time,
2430 uint32_t key, uint32_t button, uint32_t axis,
2431 int32_t value, void *data)
2433 struct desktop_shell *shell = data;
2434 struct switcher *switcher;
2436 switcher = malloc(sizeof *switcher);
2437 switcher->shell = shell;
2438 switcher->current = NULL;
2439 switcher->listener.notify = switcher_handle_surface_destroy;
2440 wl_list_init(&switcher->listener.link);
2442 switcher->grab.interface = &switcher_grab;
2443 wl_input_device_start_keyboard_grab(device, &switcher->grab);
2444 wl_input_device_set_keyboard_focus(device, NULL);
2445 switcher_next(switcher);
2449 backlight_binding(struct wl_input_device *device, uint32_t time,
2450 uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
2452 struct weston_compositor *compositor = data;
2453 struct weston_output *output;
2454 long backlight_new = 0;
2456 /* TODO: we're limiting to simple use cases, where we assume just
2457 * control on the primary display. We'd have to extend later if we
2458 * ever get support for setting backlights on random desktop LCD
2460 output = get_default_output(compositor);
2464 if (!output->set_backlight)
2467 if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN)
2468 backlight_new = output->backlight_current - 25;
2469 else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP)
2470 backlight_new = output->backlight_current + 25;
2472 if (backlight_new < 5)
2474 if (backlight_new > 255)
2475 backlight_new = 255;
2477 output->backlight_current = backlight_new;
2478 output->set_backlight(output, output->backlight_current);
2482 debug_repaint_binding(struct wl_input_device *device, uint32_t time,
2483 uint32_t key, uint32_t button, uint32_t axis,
2484 int32_t value, void *data)
2486 struct desktop_shell *shell = data;
2487 struct weston_compositor *compositor = shell->compositor;
2488 struct weston_surface *surface;
2490 if (shell->debug_repaint_surface) {
2491 weston_surface_destroy(shell->debug_repaint_surface);
2492 shell->debug_repaint_surface = NULL;
2494 surface = weston_surface_create(compositor);
2495 weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2);
2496 weston_surface_configure(surface, 0, 0, 8192, 8192);
2497 wl_list_insert(&compositor->fade_layer.surface_list,
2498 &surface->layer_link);
2499 weston_surface_assign_output(surface);
2500 pixman_region32_init(&surface->input);
2502 /* Here's the dirty little trick that makes the
2503 * repaint debugging work: we force an
2504 * update_transform first to update dependent state
2505 * and clear the geometry.dirty bit. Then we clear
2506 * the surface damage so it only gets repainted
2507 * piecewise as we repaint other things. */
2509 weston_surface_update_transform(surface);
2510 pixman_region32_fini(&surface->damage);
2511 pixman_region32_init(&surface->damage);
2512 shell->debug_repaint_surface = surface;
2517 shell_destroy(struct wl_listener *listener, void *data)
2519 struct desktop_shell *shell =
2520 container_of(listener, struct desktop_shell, destroy_listener);
2522 if (shell->child.client)
2523 wl_client_destroy(shell->child.client);
2525 free(shell->screensaver.path);
2530 shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell)
2534 /* fixed bindings */
2535 weston_compositor_add_binding(ec, KEY_BACKSPACE, 0, 0,
2536 MODIFIER_CTRL | MODIFIER_ALT,
2537 terminate_binding, ec);
2538 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, 0,
2539 click_to_activate_binding, shell);
2540 weston_compositor_add_binding(ec, 0, 0,
2541 WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL,
2542 MODIFIER_SUPER | MODIFIER_ALT,
2543 surface_opacity_binding, NULL);
2544 weston_compositor_add_binding(ec, 0, 0,
2545 WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL,
2546 MODIFIER_SUPER, zoom_binding, NULL);
2548 /* configurable bindings */
2549 mod = shell->binding_modifier;
2550 weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, mod,
2551 move_binding, shell);
2552 weston_compositor_add_binding(ec, 0, BTN_MIDDLE, 0, mod,
2553 resize_binding, shell);
2554 weston_compositor_add_binding(ec, 0, BTN_RIGHT, 0, mod,
2555 rotate_binding, NULL);
2556 weston_compositor_add_binding(ec, KEY_TAB, 0, 0, mod,
2557 switcher_binding, shell);
2558 weston_compositor_add_binding(ec, KEY_F9, 0, 0, mod,
2559 backlight_binding, ec);
2560 weston_compositor_add_binding(ec, KEY_BRIGHTNESSDOWN, 0, 0, 0,
2561 backlight_binding, ec);
2562 weston_compositor_add_binding(ec, KEY_F10, 0, 0, mod,
2563 backlight_binding, ec);
2564 weston_compositor_add_binding(ec, KEY_BRIGHTNESSUP, 0, 0, 0,
2565 backlight_binding, ec);
2566 weston_compositor_add_binding(ec, KEY_SPACE, 0, 0, mod,
2567 debug_repaint_binding, shell);
2571 shell_init(struct weston_compositor *ec);
2574 shell_init(struct weston_compositor *ec)
2576 struct desktop_shell *shell;
2578 shell = malloc(sizeof *shell);
2582 memset(shell, 0, sizeof *shell);
2583 shell->compositor = ec;
2585 shell->destroy_listener.notify = shell_destroy;
2586 wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
2587 shell->lock_listener.notify = lock;
2588 wl_signal_add(&ec->lock_signal, &shell->lock_listener);
2589 shell->unlock_listener.notify = unlock;
2590 wl_signal_add(&ec->unlock_signal, &shell->unlock_listener);
2591 ec->ping_handler = ping_handler;
2592 ec->shell_interface.create_shell_surface = create_shell_surface;
2593 ec->shell_interface.set_toplevel = set_toplevel;
2595 wl_list_init(&shell->backgrounds);
2596 wl_list_init(&shell->panels);
2597 wl_list_init(&shell->screensaver.surfaces);
2599 weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
2600 weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
2601 weston_layer_init(&shell->toplevel_layer, &shell->panel_layer.link);
2602 weston_layer_init(&shell->background_layer,
2603 &shell->toplevel_layer.link);
2604 wl_list_init(&shell->lock_layer.surface_list);
2606 shell_configuration(shell);
2608 if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
2609 shell, bind_shell) == NULL)
2612 if (wl_display_add_global(ec->wl_display,
2613 &desktop_shell_interface,
2614 shell, bind_desktop_shell) == NULL)
2617 if (wl_display_add_global(ec->wl_display, &screensaver_interface,
2618 shell, bind_screensaver) == NULL)
2621 shell->child.deathstamp = weston_compositor_get_time();
2622 if (launch_desktop_shell_process(shell) != 0)
2625 shell_add_bindings(ec, shell);