Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2 | * Copyright © 2010-2012 Intel Corporation |
Pekka Paalanen | d581a8f | 2012-01-27 16:25:16 +0200 | [diff] [blame] | 3 | * Copyright © 2011-2012 Collabora, Ltd. |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 4 | * |
| 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. |
| 14 | * |
| 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. |
| 22 | */ |
| 23 | |
| 24 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 25 | #include <stdio.h> |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 26 | #include <stdbool.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 27 | #include <string.h> |
| 28 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 29 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 30 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 31 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 32 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 33 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 34 | |
Pekka Paalanen | 50719bc | 2011-11-22 14:18:50 +0200 | [diff] [blame] | 35 | #include <wayland-server.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 36 | #include "compositor.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 37 | #include "desktop-shell-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 38 | #include "workspaces-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 39 | #include "../shared/config-parser.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 40 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 41 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 42 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 43 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 44 | enum animation_type { |
| 45 | ANIMATION_NONE, |
| 46 | |
| 47 | ANIMATION_ZOOM, |
| 48 | ANIMATION_FADE |
| 49 | }; |
| 50 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 51 | struct focus_state { |
| 52 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 53 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 54 | struct weston_surface *keyboard_focus; |
| 55 | struct wl_list link; |
| 56 | struct wl_listener seat_destroy_listener; |
| 57 | struct wl_listener surface_destroy_listener; |
| 58 | }; |
| 59 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 60 | struct workspace { |
| 61 | struct weston_layer layer; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 62 | |
| 63 | struct wl_list focus_list; |
| 64 | struct wl_listener seat_destroyed_listener; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 65 | }; |
| 66 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 67 | struct input_panel_surface { |
| 68 | struct wl_list link; |
| 69 | struct weston_surface *surface; |
| 70 | struct wl_listener listener; |
| 71 | }; |
| 72 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 73 | struct desktop_shell { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 74 | struct weston_compositor *compositor; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 75 | |
| 76 | struct wl_listener lock_listener; |
| 77 | struct wl_listener unlock_listener; |
| 78 | struct wl_listener destroy_listener; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 79 | struct wl_listener show_input_panel_listener; |
| 80 | struct wl_listener hide_input_panel_listener; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 81 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 82 | struct weston_layer fullscreen_layer; |
| 83 | struct weston_layer panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 84 | struct weston_layer background_layer; |
| 85 | struct weston_layer lock_layer; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 86 | struct weston_layer input_panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 87 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 88 | struct wl_listener pointer_focus_listener; |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 89 | struct weston_surface *grab_surface; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 90 | |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 91 | struct { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 92 | struct weston_process process; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 93 | struct wl_client *client; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 94 | struct wl_resource *desktop_shell; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 95 | |
| 96 | unsigned deathcount; |
| 97 | uint32_t deathstamp; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 98 | } child; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 99 | |
| 100 | bool locked; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 101 | bool showing_input_panels; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 102 | bool prepare_event_sent; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 103 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 104 | struct weston_surface *lock_surface; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 105 | struct wl_listener lock_surface_listener; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 106 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 107 | struct { |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 108 | struct wl_array array; |
| 109 | unsigned int current; |
| 110 | unsigned int num; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 111 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 112 | struct wl_list client_list; |
| 113 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 114 | struct weston_animation animation; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 115 | struct wl_list anim_sticky_list; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 116 | int anim_dir; |
| 117 | uint32_t anim_timestamp; |
| 118 | double anim_current; |
| 119 | struct workspace *anim_from; |
| 120 | struct workspace *anim_to; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 121 | } workspaces; |
| 122 | |
| 123 | struct { |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 124 | char *path; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 125 | int duration; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 126 | struct wl_resource *binding; |
| 127 | struct wl_list surfaces; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 128 | struct weston_process process; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 129 | } screensaver; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 130 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 131 | struct { |
| 132 | struct wl_resource *binding; |
| 133 | struct wl_list surfaces; |
| 134 | } input_panel; |
| 135 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 136 | uint32_t binding_modifier; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 137 | enum animation_type win_animation_type; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 138 | struct weston_surface *debug_repaint_surface; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 139 | }; |
| 140 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 141 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 142 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 143 | SHELL_SURFACE_TOPLEVEL, |
| 144 | SHELL_SURFACE_TRANSIENT, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 145 | SHELL_SURFACE_FULLSCREEN, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 146 | SHELL_SURFACE_MAXIMIZED, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 147 | SHELL_SURFACE_POPUP |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 148 | }; |
| 149 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 150 | struct ping_timer { |
| 151 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 152 | uint32_t serial; |
| 153 | }; |
| 154 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 155 | struct shell_surface { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 156 | struct wl_resource resource; |
| 157 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 158 | struct weston_surface *surface; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 159 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 160 | struct weston_surface *parent; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 161 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 162 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 163 | enum shell_surface_type type, next_type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 164 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 165 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 166 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 167 | bool saved_rotation_valid; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 168 | int unresponsive; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 169 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 170 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 171 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 172 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 173 | } rotation; |
| 174 | |
| 175 | struct { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 176 | struct wl_pointer_grab grab; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 177 | int32_t x, y; |
Pekka Paalanen | 938269a | 2012-02-07 14:19:01 +0200 | [diff] [blame] | 178 | struct weston_transform parent_transform; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 179 | int32_t initial_up; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 180 | struct wl_seat *seat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 181 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 182 | } popup; |
| 183 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 184 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 185 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 186 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 187 | } transient; |
| 188 | |
| 189 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 190 | enum wl_shell_surface_fullscreen_method type; |
| 191 | struct weston_transform transform; /* matrix from x, y */ |
| 192 | uint32_t framerate; |
| 193 | struct weston_surface *black_surface; |
| 194 | } fullscreen; |
| 195 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 196 | struct ping_timer *ping_timer; |
| 197 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 198 | struct weston_transform workspace_transform; |
| 199 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 200 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 201 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 202 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 203 | |
| 204 | const struct weston_shell_client *client; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 205 | }; |
| 206 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 207 | struct shell_grab { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 208 | struct wl_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 209 | struct shell_surface *shsurf; |
| 210 | struct wl_listener shsurf_destroy_listener; |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 211 | struct wl_pointer *pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | struct weston_move_grab { |
| 215 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 216 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 217 | }; |
| 218 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 219 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 220 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 221 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 222 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 223 | float x; |
| 224 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 225 | } center; |
| 226 | }; |
| 227 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 228 | static void |
| 229 | activate(struct desktop_shell *shell, struct weston_surface *es, |
| 230 | struct weston_seat *seat); |
| 231 | |
| 232 | static struct workspace * |
| 233 | get_current_workspace(struct desktop_shell *shell); |
| 234 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 235 | static struct shell_surface * |
| 236 | get_shell_surface(struct weston_surface *surface); |
| 237 | |
| 238 | static struct desktop_shell * |
| 239 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 240 | |
| 241 | static bool |
| 242 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 243 | { |
| 244 | struct desktop_shell *shell; |
| 245 | struct weston_surface *top_fs_es; |
| 246 | |
| 247 | shell = shell_surface_get_shell(shsurf); |
| 248 | |
| 249 | if (wl_list_empty(&shell->fullscreen_layer.surface_list)) |
| 250 | return false; |
| 251 | |
| 252 | top_fs_es = container_of(shell->fullscreen_layer.surface_list.next, |
| 253 | struct weston_surface, |
| 254 | layer_link); |
| 255 | return (shsurf == get_shell_surface(top_fs_es)); |
| 256 | } |
| 257 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 258 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 259 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 260 | { |
| 261 | struct shell_grab *grab; |
| 262 | |
| 263 | grab = container_of(listener, struct shell_grab, |
| 264 | shsurf_destroy_listener); |
| 265 | |
| 266 | grab->shsurf = NULL; |
| 267 | } |
| 268 | |
| 269 | static void |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame^] | 270 | popup_grab_end(struct wl_pointer *pointer); |
| 271 | |
| 272 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 273 | shell_grab_start(struct shell_grab *grab, |
| 274 | const struct wl_pointer_grab_interface *interface, |
| 275 | struct shell_surface *shsurf, |
| 276 | struct wl_pointer *pointer, |
| 277 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 278 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 279 | struct desktop_shell *shell = shsurf->shell; |
| 280 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame^] | 281 | popup_grab_end(pointer); |
| 282 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 283 | grab->grab.interface = interface; |
| 284 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 285 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 286 | wl_signal_add(&shsurf->resource.destroy_signal, |
| 287 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 288 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 289 | grab->pointer = pointer; |
| 290 | grab->grab.focus = &shsurf->surface->surface; |
| 291 | |
| 292 | wl_pointer_start_grab(pointer, &grab->grab); |
| 293 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, cursor); |
| 294 | wl_pointer_set_focus(pointer, &shell->grab_surface->surface, |
| 295 | wl_fixed_from_int(0), wl_fixed_from_int(0)); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 299 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 300 | { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 301 | if (grab->shsurf) |
| 302 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 303 | |
| 304 | wl_pointer_end_grab(grab->pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | static void |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 308 | center_on_output(struct weston_surface *surface, |
| 309 | struct weston_output *output); |
| 310 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 311 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 312 | get_modifier(char *modifier) |
| 313 | { |
| 314 | if (!modifier) |
| 315 | return MODIFIER_SUPER; |
| 316 | |
| 317 | if (!strcmp("ctrl", modifier)) |
| 318 | return MODIFIER_CTRL; |
| 319 | else if (!strcmp("alt", modifier)) |
| 320 | return MODIFIER_ALT; |
| 321 | else if (!strcmp("super", modifier)) |
| 322 | return MODIFIER_SUPER; |
| 323 | else |
| 324 | return MODIFIER_SUPER; |
| 325 | } |
| 326 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 327 | static enum animation_type |
| 328 | get_animation_type(char *animation) |
| 329 | { |
| 330 | if (!animation) |
| 331 | return ANIMATION_NONE; |
| 332 | |
| 333 | if (!strcmp("zoom", animation)) |
| 334 | return ANIMATION_ZOOM; |
| 335 | else if (!strcmp("fade", animation)) |
| 336 | return ANIMATION_FADE; |
| 337 | else |
| 338 | return ANIMATION_NONE; |
| 339 | } |
| 340 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 341 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 342 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 343 | { |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 344 | char *config_file; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 345 | char *path = NULL; |
| 346 | int duration = 60; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 347 | unsigned int num_workspaces = DEFAULT_NUM_WORKSPACES; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 348 | char *modifier = NULL; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 349 | char *win_animation = NULL; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 350 | |
Kristian Høgsberg | a4e8b33 | 2012-04-20 16:48:21 -0400 | [diff] [blame] | 351 | struct config_key shell_keys[] = { |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 352 | { "binding-modifier", CONFIG_KEY_STRING, &modifier }, |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 353 | { "animation", CONFIG_KEY_STRING, &win_animation}, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 354 | { "num-workspaces", |
| 355 | CONFIG_KEY_UNSIGNED_INTEGER, &num_workspaces }, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 356 | }; |
| 357 | |
Kristian Høgsberg | a4e8b33 | 2012-04-20 16:48:21 -0400 | [diff] [blame] | 358 | struct config_key saver_keys[] = { |
| 359 | { "path", CONFIG_KEY_STRING, &path }, |
| 360 | { "duration", CONFIG_KEY_INTEGER, &duration }, |
| 361 | }; |
| 362 | |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 363 | struct config_section cs[] = { |
Kristian Høgsberg | a4e8b33 | 2012-04-20 16:48:21 -0400 | [diff] [blame] | 364 | { "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL }, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 365 | { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL }, |
| 366 | }; |
| 367 | |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 368 | config_file = config_file_path("weston.ini"); |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 369 | parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 370 | free(config_file); |
| 371 | |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 372 | shell->screensaver.path = path; |
| 373 | shell->screensaver.duration = duration; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 374 | shell->binding_modifier = get_modifier(modifier); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 375 | shell->win_animation_type = get_animation_type(win_animation); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 376 | shell->workspaces.num = num_workspaces > 0 ? num_workspaces : 1; |
| 377 | } |
| 378 | |
| 379 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 380 | focus_state_destroy(struct focus_state *state) |
| 381 | { |
| 382 | wl_list_remove(&state->seat_destroy_listener.link); |
| 383 | wl_list_remove(&state->surface_destroy_listener.link); |
| 384 | free(state); |
| 385 | } |
| 386 | |
| 387 | static void |
| 388 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 389 | { |
| 390 | struct focus_state *state = container_of(listener, |
| 391 | struct focus_state, |
| 392 | seat_destroy_listener); |
| 393 | |
| 394 | wl_list_remove(&state->link); |
| 395 | focus_state_destroy(state); |
| 396 | } |
| 397 | |
| 398 | static void |
| 399 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 400 | { |
| 401 | struct focus_state *state = container_of(listener, |
| 402 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 403 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 404 | struct desktop_shell *shell; |
| 405 | struct weston_surface *surface, *next; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 406 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 407 | next = NULL; |
| 408 | wl_list_for_each(surface, &state->ws->layer.surface_list, layer_link) { |
| 409 | if (surface == state->keyboard_focus) |
| 410 | continue; |
| 411 | |
| 412 | next = surface; |
| 413 | break; |
| 414 | } |
| 415 | |
| 416 | if (next) { |
| 417 | shell = state->seat->compositor->shell_interface.shell; |
| 418 | activate(shell, next, state->seat); |
| 419 | } else { |
| 420 | wl_list_remove(&state->link); |
| 421 | focus_state_destroy(state); |
| 422 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 426 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 427 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 428 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 429 | |
| 430 | state = malloc(sizeof *state); |
| 431 | if (state == NULL) |
| 432 | return NULL; |
| 433 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 434 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 435 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 436 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 437 | |
| 438 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 439 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
| 440 | wl_signal_add(&seat->seat.destroy_signal, |
| 441 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 442 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 443 | |
| 444 | return state; |
| 445 | } |
| 446 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 447 | static struct focus_state * |
| 448 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 449 | { |
| 450 | struct workspace *ws = get_current_workspace(shell); |
| 451 | struct focus_state *state; |
| 452 | |
| 453 | wl_list_for_each(state, &ws->focus_list, link) |
| 454 | if (state->seat == seat) |
| 455 | break; |
| 456 | |
| 457 | if (&state->link == &ws->focus_list) |
| 458 | state = focus_state_create(seat, ws); |
| 459 | |
| 460 | return state; |
| 461 | } |
| 462 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 463 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 464 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 465 | { |
| 466 | struct focus_state *state, *next; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 467 | struct wl_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 468 | |
| 469 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 470 | surface = state->keyboard_focus ? |
| 471 | &state->keyboard_focus->surface : NULL; |
| 472 | |
| 473 | wl_keyboard_set_focus(state->seat->seat.keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
| 477 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 478 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 479 | struct weston_seat *seat) |
| 480 | { |
| 481 | struct focus_state *state; |
| 482 | struct wl_surface *surface; |
| 483 | |
| 484 | wl_list_for_each(state, &ws->focus_list, link) { |
| 485 | if (state->seat == seat) { |
| 486 | surface = seat->seat.keyboard->focus; |
| 487 | state->keyboard_focus = |
| 488 | (struct weston_surface *) surface; |
| 489 | return; |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | static void |
| 495 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 496 | struct weston_surface *surface) |
| 497 | { |
| 498 | struct focus_state *state; |
| 499 | |
| 500 | wl_list_for_each(state, &ws->focus_list, link) |
| 501 | if (state->keyboard_focus == surface) |
| 502 | state->keyboard_focus = NULL; |
| 503 | } |
| 504 | |
| 505 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 506 | workspace_destroy(struct workspace *ws) |
| 507 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 508 | struct focus_state *state, *next; |
| 509 | |
| 510 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 511 | focus_state_destroy(state); |
| 512 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 513 | free(ws); |
| 514 | } |
| 515 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 516 | static void |
| 517 | seat_destroyed(struct wl_listener *listener, void *data) |
| 518 | { |
| 519 | struct weston_seat *seat = data; |
| 520 | struct focus_state *state, *next; |
| 521 | struct workspace *ws = container_of(listener, |
| 522 | struct workspace, |
| 523 | seat_destroyed_listener); |
| 524 | |
| 525 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 526 | if (state->seat == seat) |
| 527 | wl_list_remove(&state->link); |
| 528 | } |
| 529 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 530 | static struct workspace * |
| 531 | workspace_create(void) |
| 532 | { |
| 533 | struct workspace *ws = malloc(sizeof *ws); |
| 534 | if (ws == NULL) |
| 535 | return NULL; |
| 536 | |
| 537 | weston_layer_init(&ws->layer, NULL); |
| 538 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 539 | wl_list_init(&ws->focus_list); |
| 540 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 541 | ws->seat_destroyed_listener.notify = seat_destroyed; |
| 542 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 543 | return ws; |
| 544 | } |
| 545 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 546 | static int |
| 547 | workspace_is_empty(struct workspace *ws) |
| 548 | { |
| 549 | return wl_list_empty(&ws->layer.surface_list); |
| 550 | } |
| 551 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 552 | static struct workspace * |
| 553 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 554 | { |
| 555 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 556 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 557 | pws += index; |
| 558 | return *pws; |
| 559 | } |
| 560 | |
| 561 | static struct workspace * |
| 562 | get_current_workspace(struct desktop_shell *shell) |
| 563 | { |
| 564 | return get_workspace(shell, shell->workspaces.current); |
| 565 | } |
| 566 | |
| 567 | static void |
| 568 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 569 | { |
| 570 | struct workspace *ws; |
| 571 | |
| 572 | ws = get_workspace(shell, index); |
| 573 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 574 | |
| 575 | shell->workspaces.current = index; |
| 576 | } |
| 577 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 578 | static unsigned int |
| 579 | get_output_height(struct weston_output *output) |
| 580 | { |
| 581 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 582 | } |
| 583 | |
| 584 | static void |
| 585 | surface_translate(struct weston_surface *surface, double d) |
| 586 | { |
| 587 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 588 | struct weston_transform *transform; |
| 589 | |
| 590 | transform = &shsurf->workspace_transform; |
| 591 | if (wl_list_empty(&transform->link)) |
| 592 | wl_list_insert(surface->geometry.transformation_list.prev, |
| 593 | &shsurf->workspace_transform.link); |
| 594 | |
| 595 | weston_matrix_init(&shsurf->workspace_transform.matrix); |
| 596 | weston_matrix_translate(&shsurf->workspace_transform.matrix, |
| 597 | 0.0, d, 0.0); |
| 598 | surface->geometry.dirty = 1; |
| 599 | } |
| 600 | |
| 601 | static void |
| 602 | workspace_translate_out(struct workspace *ws, double fraction) |
| 603 | { |
| 604 | struct weston_surface *surface; |
| 605 | unsigned int height; |
| 606 | double d; |
| 607 | |
| 608 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
| 609 | height = get_output_height(surface->output); |
| 610 | d = height * fraction; |
| 611 | |
| 612 | surface_translate(surface, d); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | static void |
| 617 | workspace_translate_in(struct workspace *ws, double fraction) |
| 618 | { |
| 619 | struct weston_surface *surface; |
| 620 | unsigned int height; |
| 621 | double d; |
| 622 | |
| 623 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
| 624 | height = get_output_height(surface->output); |
| 625 | |
| 626 | if (fraction > 0) |
| 627 | d = -(height - height * fraction); |
| 628 | else |
| 629 | d = height + height * fraction; |
| 630 | |
| 631 | surface_translate(surface, d); |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 636 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 637 | { |
| 638 | struct wl_resource *resource; |
| 639 | |
| 640 | wl_list_for_each(resource, &shell->workspaces.client_list, link) |
| 641 | workspace_manager_send_state(resource, |
| 642 | shell->workspaces.current, |
| 643 | shell->workspaces.num); |
| 644 | } |
| 645 | |
| 646 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 647 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 648 | unsigned int index, |
| 649 | struct workspace *from, |
| 650 | struct workspace *to) |
| 651 | { |
| 652 | shell->workspaces.current = index; |
| 653 | |
| 654 | shell->workspaces.anim_to = to; |
| 655 | shell->workspaces.anim_from = from; |
| 656 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 657 | shell->workspaces.anim_timestamp = 0; |
| 658 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 659 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static void |
| 663 | workspace_deactivate_transforms(struct workspace *ws) |
| 664 | { |
| 665 | struct weston_surface *surface; |
| 666 | struct shell_surface *shsurf; |
| 667 | |
| 668 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
| 669 | shsurf = get_shell_surface(surface); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 670 | if (!wl_list_empty(&shsurf->workspace_transform.link)) { |
| 671 | wl_list_remove(&shsurf->workspace_transform.link); |
| 672 | wl_list_init(&shsurf->workspace_transform.link); |
| 673 | } |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 674 | shsurf->surface->geometry.dirty = 1; |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | static void |
| 679 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 680 | struct workspace *from, |
| 681 | struct workspace *to) |
| 682 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 683 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 684 | |
| 685 | wl_list_remove(&shell->workspaces.animation.link); |
| 686 | workspace_deactivate_transforms(from); |
| 687 | workspace_deactivate_transforms(to); |
| 688 | shell->workspaces.anim_to = NULL; |
| 689 | |
| 690 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 691 | } |
| 692 | |
| 693 | static void |
| 694 | animate_workspace_change_frame(struct weston_animation *animation, |
| 695 | struct weston_output *output, uint32_t msecs) |
| 696 | { |
| 697 | struct desktop_shell *shell = |
| 698 | container_of(animation, struct desktop_shell, |
| 699 | workspaces.animation); |
| 700 | struct workspace *from = shell->workspaces.anim_from; |
| 701 | struct workspace *to = shell->workspaces.anim_to; |
| 702 | uint32_t t; |
| 703 | double x, y; |
| 704 | |
| 705 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 706 | finish_workspace_change_animation(shell, from, to); |
| 707 | return; |
| 708 | } |
| 709 | |
| 710 | if (shell->workspaces.anim_timestamp == 0) { |
| 711 | if (shell->workspaces.anim_current == 0.0) |
| 712 | shell->workspaces.anim_timestamp = msecs; |
| 713 | else |
| 714 | shell->workspaces.anim_timestamp = |
| 715 | msecs - |
| 716 | /* Invers of movement function 'y' below. */ |
| 717 | (asin(1.0 - shell->workspaces.anim_current) * |
| 718 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 719 | M_2_PI); |
| 720 | } |
| 721 | |
| 722 | t = msecs - shell->workspaces.anim_timestamp; |
| 723 | |
| 724 | /* |
| 725 | * x = [0, π/2] |
| 726 | * y(x) = sin(x) |
| 727 | */ |
| 728 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 729 | y = sin(x); |
| 730 | |
| 731 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 732 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 733 | |
| 734 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 735 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 736 | shell->workspaces.anim_current = y; |
| 737 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 738 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 739 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 740 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 741 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | static void |
| 745 | animate_workspace_change(struct desktop_shell *shell, |
| 746 | unsigned int index, |
| 747 | struct workspace *from, |
| 748 | struct workspace *to) |
| 749 | { |
| 750 | struct weston_output *output; |
| 751 | |
| 752 | int dir; |
| 753 | |
| 754 | if (index > shell->workspaces.current) |
| 755 | dir = -1; |
| 756 | else |
| 757 | dir = 1; |
| 758 | |
| 759 | shell->workspaces.current = index; |
| 760 | |
| 761 | shell->workspaces.anim_dir = dir; |
| 762 | shell->workspaces.anim_from = from; |
| 763 | shell->workspaces.anim_to = to; |
| 764 | shell->workspaces.anim_current = 0.0; |
| 765 | shell->workspaces.anim_timestamp = 0; |
| 766 | |
| 767 | output = container_of(shell->compositor->output_list.next, |
| 768 | struct weston_output, link); |
| 769 | wl_list_insert(&output->animation_list, |
| 770 | &shell->workspaces.animation.link); |
| 771 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 772 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 773 | |
| 774 | workspace_translate_in(to, 0); |
| 775 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 776 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 777 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 778 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 779 | } |
| 780 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 781 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 782 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 783 | struct workspace *from, struct workspace *to) |
| 784 | { |
| 785 | shell->workspaces.current = index; |
| 786 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 787 | wl_list_remove(&from->layer.link); |
| 788 | } |
| 789 | |
| 790 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 791 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 792 | { |
| 793 | struct workspace *from; |
| 794 | struct workspace *to; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 795 | |
| 796 | if (index == shell->workspaces.current) |
| 797 | return; |
| 798 | |
| 799 | /* Don't change workspace when there is any fullscreen surfaces. */ |
| 800 | if (!wl_list_empty(&shell->fullscreen_layer.surface_list)) |
| 801 | return; |
| 802 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 803 | from = get_current_workspace(shell); |
| 804 | to = get_workspace(shell, index); |
| 805 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 806 | if (shell->workspaces.anim_from == to && |
| 807 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 808 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 809 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 810 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 811 | return; |
| 812 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 813 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 814 | if (shell->workspaces.anim_to != NULL) |
| 815 | finish_workspace_change_animation(shell, |
| 816 | shell->workspaces.anim_from, |
| 817 | shell->workspaces.anim_to); |
| 818 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 819 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 820 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 821 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 822 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 823 | else |
| 824 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 825 | |
| 826 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 827 | } |
| 828 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 829 | static bool |
| 830 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 831 | { |
| 832 | struct wl_list *list = &ws->layer.surface_list; |
| 833 | struct wl_list *e; |
| 834 | |
| 835 | if (wl_list_empty(list)) |
| 836 | return false; |
| 837 | |
| 838 | e = list->next; |
| 839 | |
| 840 | if (e->next != list) |
| 841 | return false; |
| 842 | |
| 843 | return container_of(e, struct weston_surface, layer_link) == surface; |
| 844 | } |
| 845 | |
| 846 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 847 | move_surface_to_workspace(struct desktop_shell *shell, |
| 848 | struct weston_surface *surface, |
| 849 | uint32_t workspace) |
| 850 | { |
| 851 | struct workspace *from; |
| 852 | struct workspace *to; |
| 853 | struct weston_seat *seat; |
| 854 | |
| 855 | if (workspace == shell->workspaces.current) |
| 856 | return; |
| 857 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 858 | if (workspace >= shell->workspaces.num) |
| 859 | workspace = shell->workspaces.num - 1; |
| 860 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 861 | from = get_current_workspace(shell); |
| 862 | to = get_workspace(shell, workspace); |
| 863 | |
| 864 | wl_list_remove(&surface->layer_link); |
| 865 | wl_list_insert(&to->layer.surface_list, &surface->layer_link); |
| 866 | |
| 867 | drop_focus_state(shell, from, surface); |
| 868 | wl_list_for_each(seat, &shell->compositor->seat_list, link) |
| 869 | if (seat->has_keyboard && |
| 870 | seat->keyboard.focus == &surface->surface) |
| 871 | wl_keyboard_set_focus(&seat->keyboard, NULL); |
| 872 | |
| 873 | weston_surface_damage_below(surface); |
| 874 | } |
| 875 | |
| 876 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 877 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 878 | struct wl_seat *wl_seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 879 | unsigned int index) |
| 880 | { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 881 | struct weston_seat *seat = (struct weston_seat *) wl_seat; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 882 | struct weston_surface *surface = |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 883 | (struct weston_surface *) wl_seat->keyboard->focus; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 884 | struct shell_surface *shsurf; |
| 885 | struct workspace *from; |
| 886 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 887 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 888 | |
| 889 | if (surface == NULL || |
| 890 | index == shell->workspaces.current) |
| 891 | return; |
| 892 | |
| 893 | from = get_current_workspace(shell); |
| 894 | to = get_workspace(shell, index); |
| 895 | |
| 896 | wl_list_remove(&surface->layer_link); |
| 897 | wl_list_insert(&to->layer.surface_list, &surface->layer_link); |
| 898 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 899 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 900 | drop_focus_state(shell, from, surface); |
| 901 | |
| 902 | if (shell->workspaces.anim_from == to && |
| 903 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 904 | wl_list_remove(&to->layer.link); |
| 905 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 906 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 907 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 908 | broadcast_current_workspace_state(shell); |
| 909 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 910 | return; |
| 911 | } |
| 912 | |
| 913 | if (shell->workspaces.anim_to != NULL) |
| 914 | finish_workspace_change_animation(shell, |
| 915 | shell->workspaces.anim_from, |
| 916 | shell->workspaces.anim_to); |
| 917 | |
| 918 | if (workspace_is_empty(from) && |
| 919 | workspace_has_only(to, surface)) |
| 920 | update_workspace(shell, index, from, to); |
| 921 | else { |
| 922 | shsurf = get_shell_surface(surface); |
| 923 | if (wl_list_empty(&shsurf->workspace_transform.link)) |
| 924 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 925 | &shsurf->workspace_transform.link); |
| 926 | |
| 927 | animate_workspace_change(shell, index, from, to); |
| 928 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 929 | |
| 930 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 931 | |
| 932 | state = ensure_focus_state(shell, seat); |
| 933 | if (state != NULL) |
| 934 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | static void |
| 938 | workspace_manager_move_surface(struct wl_client *client, |
| 939 | struct wl_resource *resource, |
| 940 | struct wl_resource *surface_resource, |
| 941 | uint32_t workspace) |
| 942 | { |
| 943 | struct desktop_shell *shell = resource->data; |
| 944 | struct weston_surface *surface = |
| 945 | (struct weston_surface *) surface_resource; |
| 946 | |
| 947 | move_surface_to_workspace(shell, surface, workspace); |
| 948 | } |
| 949 | |
| 950 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 951 | workspace_manager_move_surface, |
| 952 | }; |
| 953 | |
| 954 | static void |
| 955 | unbind_resource(struct wl_resource *resource) |
| 956 | { |
| 957 | wl_list_remove(&resource->link); |
| 958 | free(resource); |
| 959 | } |
| 960 | |
| 961 | static void |
| 962 | bind_workspace_manager(struct wl_client *client, |
| 963 | void *data, uint32_t version, uint32_t id) |
| 964 | { |
| 965 | struct desktop_shell *shell = data; |
| 966 | struct wl_resource *resource; |
| 967 | |
| 968 | resource = wl_client_add_object(client, &workspace_manager_interface, |
| 969 | &workspace_manager_implementation, |
| 970 | id, shell); |
| 971 | |
| 972 | if (resource == NULL) { |
| 973 | weston_log("couldn't add workspace manager object"); |
| 974 | return; |
| 975 | } |
| 976 | |
| 977 | resource->destroy = unbind_resource; |
| 978 | wl_list_insert(&shell->workspaces.client_list, &resource->link); |
| 979 | |
| 980 | workspace_manager_send_state(resource, |
| 981 | shell->workspaces.current, |
| 982 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 983 | } |
| 984 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 985 | static void |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 986 | noop_grab_focus(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 987 | struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 988 | { |
| 989 | grab->focus = NULL; |
| 990 | } |
| 991 | |
| 992 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 993 | move_grab_motion(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 994 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 995 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 996 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 997 | struct wl_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 998 | struct shell_surface *shsurf = move->base.shsurf; |
| 999 | struct weston_surface *es; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1000 | int dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1001 | int dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1002 | |
| 1003 | if (!shsurf) |
| 1004 | return; |
| 1005 | |
| 1006 | es = shsurf->surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1007 | |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1008 | weston_surface_configure(es, dx, dy, |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1009 | es->geometry.width, es->geometry.height); |
Kristian Høgsberg | 6c6fb99 | 2012-06-21 12:06:22 -0400 | [diff] [blame] | 1010 | |
| 1011 | weston_compositor_schedule_repaint(es->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1015 | move_grab_button(struct wl_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1016 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1017 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1018 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1019 | grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1020 | struct wl_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1021 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1022 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1023 | if (pointer->button_count == 0 && |
| 1024 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1025 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1026 | free(grab); |
| 1027 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1028 | } |
| 1029 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1030 | static const struct wl_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1031 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1032 | move_grab_motion, |
| 1033 | move_grab_button, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1034 | }; |
| 1035 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1036 | static int |
| 1037 | surface_move(struct shell_surface *shsurf, struct weston_seat *ws) |
| 1038 | { |
| 1039 | struct weston_move_grab *move; |
| 1040 | |
| 1041 | if (!shsurf) |
| 1042 | return -1; |
| 1043 | |
| 1044 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1045 | return 0; |
| 1046 | |
| 1047 | move = malloc(sizeof *move); |
| 1048 | if (!move) |
| 1049 | return -1; |
| 1050 | |
| 1051 | move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) - |
| 1052 | ws->seat.pointer->grab_x; |
| 1053 | move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) - |
| 1054 | ws->seat.pointer->grab_y; |
| 1055 | |
| 1056 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
| 1057 | ws->seat.pointer, DESKTOP_SHELL_CURSOR_MOVE); |
| 1058 | |
| 1059 | return 0; |
| 1060 | } |
| 1061 | |
| 1062 | static void |
| 1063 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1064 | struct wl_resource *seat_resource, uint32_t serial) |
| 1065 | { |
| 1066 | struct weston_seat *ws = seat_resource->data; |
| 1067 | struct shell_surface *shsurf = resource->data; |
| 1068 | |
| 1069 | if (ws->seat.pointer->button_count == 0 || |
| 1070 | ws->seat.pointer->grab_serial != serial || |
| 1071 | ws->seat.pointer->focus != &shsurf->surface->surface) |
| 1072 | return; |
| 1073 | |
| 1074 | if (surface_move(shsurf, ws) < 0) |
| 1075 | wl_resource_post_no_memory(resource); |
| 1076 | } |
| 1077 | |
| 1078 | struct weston_resize_grab { |
| 1079 | struct shell_grab base; |
| 1080 | uint32_t edges; |
| 1081 | int32_t width, height; |
| 1082 | }; |
| 1083 | |
| 1084 | static void |
| 1085 | resize_grab_motion(struct wl_pointer_grab *grab, |
| 1086 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
| 1087 | { |
| 1088 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1089 | struct wl_pointer *pointer = grab->pointer; |
| 1090 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1091 | int32_t width, height; |
| 1092 | wl_fixed_t from_x, from_y; |
| 1093 | wl_fixed_t to_x, to_y; |
| 1094 | |
| 1095 | if (!shsurf) |
| 1096 | return; |
| 1097 | |
| 1098 | weston_surface_from_global_fixed(shsurf->surface, |
| 1099 | pointer->grab_x, pointer->grab_y, |
| 1100 | &from_x, &from_y); |
| 1101 | weston_surface_from_global_fixed(shsurf->surface, |
| 1102 | pointer->x, pointer->y, &to_x, &to_y); |
| 1103 | |
| 1104 | width = resize->width; |
| 1105 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1106 | width += wl_fixed_to_int(from_x - to_x); |
| 1107 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1108 | width += wl_fixed_to_int(to_x - from_x); |
| 1109 | } |
| 1110 | |
| 1111 | height = resize->height; |
| 1112 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1113 | height += wl_fixed_to_int(from_y - to_y); |
| 1114 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1115 | height += wl_fixed_to_int(to_y - from_y); |
| 1116 | } |
| 1117 | |
| 1118 | shsurf->client->send_configure(shsurf->surface, |
| 1119 | resize->edges, width, height); |
| 1120 | } |
| 1121 | |
| 1122 | static void |
| 1123 | send_configure(struct weston_surface *surface, |
| 1124 | uint32_t edges, int32_t width, int32_t height) |
| 1125 | { |
| 1126 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1127 | |
| 1128 | wl_shell_surface_send_configure(&shsurf->resource, |
| 1129 | edges, width, height); |
| 1130 | } |
| 1131 | |
| 1132 | static const struct weston_shell_client shell_client = { |
| 1133 | send_configure |
| 1134 | }; |
| 1135 | |
| 1136 | static void |
| 1137 | resize_grab_button(struct wl_pointer_grab *grab, |
| 1138 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1139 | { |
| 1140 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1141 | struct wl_pointer *pointer = grab->pointer; |
| 1142 | enum wl_pointer_button_state state = state_w; |
| 1143 | |
| 1144 | if (pointer->button_count == 0 && |
| 1145 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1146 | shell_grab_end(&resize->base); |
| 1147 | free(grab); |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | static const struct wl_pointer_grab_interface resize_grab_interface = { |
| 1152 | noop_grab_focus, |
| 1153 | resize_grab_motion, |
| 1154 | resize_grab_button, |
| 1155 | }; |
| 1156 | |
| 1157 | static int |
| 1158 | surface_resize(struct shell_surface *shsurf, |
| 1159 | struct weston_seat *ws, uint32_t edges) |
| 1160 | { |
| 1161 | struct weston_resize_grab *resize; |
| 1162 | |
| 1163 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1164 | return 0; |
| 1165 | |
| 1166 | if (edges == 0 || edges > 15 || |
| 1167 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1168 | return 0; |
| 1169 | |
| 1170 | resize = malloc(sizeof *resize); |
| 1171 | if (!resize) |
| 1172 | return -1; |
| 1173 | |
| 1174 | resize->edges = edges; |
| 1175 | resize->width = shsurf->surface->geometry.width; |
| 1176 | resize->height = shsurf->surface->geometry.height; |
| 1177 | |
| 1178 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
| 1179 | ws->seat.pointer, edges); |
| 1180 | |
| 1181 | return 0; |
| 1182 | } |
| 1183 | |
| 1184 | static void |
| 1185 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1186 | struct wl_resource *seat_resource, uint32_t serial, |
| 1187 | uint32_t edges) |
| 1188 | { |
| 1189 | struct weston_seat *ws = seat_resource->data; |
| 1190 | struct shell_surface *shsurf = resource->data; |
| 1191 | |
| 1192 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1193 | return; |
| 1194 | |
| 1195 | if (ws->seat.pointer->button_count == 0 || |
| 1196 | ws->seat.pointer->grab_serial != serial || |
| 1197 | ws->seat.pointer->focus != &shsurf->surface->surface) |
| 1198 | return; |
| 1199 | |
| 1200 | if (surface_resize(shsurf, ws, edges) < 0) |
| 1201 | wl_resource_post_no_memory(resource); |
| 1202 | } |
| 1203 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1204 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1205 | busy_cursor_grab_focus(struct wl_pointer_grab *base, |
| 1206 | struct wl_surface *surface, int32_t x, int32_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1207 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1208 | struct shell_grab *grab = (struct shell_grab *) base; |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1209 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1210 | if (grab->grab.focus != surface) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1211 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1212 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1217 | busy_cursor_grab_motion(struct wl_pointer_grab *grab, |
| 1218 | uint32_t time, int32_t x, int32_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1219 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1220 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1221 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1222 | static void |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1223 | busy_cursor_grab_button(struct wl_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1224 | uint32_t time, uint32_t button, uint32_t state) |
| 1225 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1226 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1227 | struct shell_surface *shsurf; |
| 1228 | struct weston_surface *surface = |
| 1229 | (struct weston_surface *) grab->grab.pointer->current; |
| 1230 | struct weston_seat *seat = |
| 1231 | (struct weston_seat *) grab->grab.pointer->seat; |
| 1232 | |
| 1233 | shsurf = get_shell_surface(surface); |
| 1234 | if (shsurf && button == BTN_LEFT && state) { |
| 1235 | activate(shsurf->shell, shsurf->surface, seat); |
| 1236 | surface_move(shsurf, seat); |
| 1237 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | static const struct wl_pointer_grab_interface busy_cursor_grab_interface = { |
| 1241 | busy_cursor_grab_focus, |
| 1242 | busy_cursor_grab_motion, |
| 1243 | busy_cursor_grab_button, |
| 1244 | }; |
| 1245 | |
| 1246 | static void |
| 1247 | set_busy_cursor(struct shell_surface *shsurf, struct wl_pointer *pointer) |
| 1248 | { |
| 1249 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1250 | |
| 1251 | grab = malloc(sizeof *grab); |
| 1252 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1253 | return; |
| 1254 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1255 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1256 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1257 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1258 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1259 | static void |
| 1260 | end_busy_cursor(struct shell_surface *shsurf, struct wl_pointer *pointer) |
| 1261 | { |
| 1262 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1263 | |
| 1264 | if (grab->grab.interface == &busy_cursor_grab_interface) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1265 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1266 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1267 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1268 | } |
| 1269 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1270 | static void |
| 1271 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1272 | { |
| 1273 | if (!shsurf || !shsurf->ping_timer) |
| 1274 | return; |
| 1275 | |
| 1276 | if (shsurf->ping_timer->source) |
| 1277 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1278 | |
| 1279 | free(shsurf->ping_timer); |
| 1280 | shsurf->ping_timer = NULL; |
| 1281 | } |
| 1282 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1283 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1284 | ping_timeout_handler(void *data) |
| 1285 | { |
| 1286 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1287 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1288 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1289 | /* Client is not responding */ |
| 1290 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1291 | |
| 1292 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
| 1293 | if (seat->seat.pointer->focus == &shsurf->surface->surface) |
| 1294 | set_busy_cursor(shsurf, seat->seat.pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1295 | |
| 1296 | return 1; |
| 1297 | } |
| 1298 | |
| 1299 | static void |
| 1300 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1301 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1302 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1303 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1304 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1305 | |
| 1306 | if (!shsurf) |
| 1307 | return; |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1308 | if (!shsurf->resource.client) |
| 1309 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1310 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1311 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1312 | return; |
| 1313 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1314 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1315 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1316 | if (!shsurf->ping_timer) |
| 1317 | return; |
| 1318 | |
| 1319 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1320 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1321 | shsurf->ping_timer->source = |
| 1322 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1323 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1324 | |
| 1325 | wl_shell_surface_send_ping(&shsurf->resource, serial); |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1330 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1331 | { |
| 1332 | struct wl_pointer *pointer = data; |
| 1333 | struct weston_surface *surface = |
| 1334 | (struct weston_surface *) pointer->focus; |
| 1335 | struct weston_compositor *compositor; |
| 1336 | struct shell_surface *shsurf; |
| 1337 | uint32_t serial; |
| 1338 | |
| 1339 | if (!surface) |
| 1340 | return; |
| 1341 | |
| 1342 | compositor = surface->compositor; |
| 1343 | shsurf = get_shell_surface(surface); |
| 1344 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1345 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1346 | set_busy_cursor(shsurf, pointer); |
| 1347 | } else { |
| 1348 | serial = wl_display_next_serial(compositor->wl_display); |
| 1349 | ping_handler(surface, serial); |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1354 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1355 | { |
| 1356 | struct wl_listener *listener; |
| 1357 | |
| 1358 | if (!seat->seat.pointer) |
| 1359 | return; |
| 1360 | |
| 1361 | listener = malloc(sizeof *listener); |
| 1362 | listener->notify = handle_pointer_focus; |
| 1363 | wl_signal_add(&seat->seat.pointer->focus_signal, listener); |
| 1364 | } |
| 1365 | |
| 1366 | static void |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1367 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 1368 | uint32_t serial) |
| 1369 | { |
| 1370 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1371 | struct desktop_shell *shell = shsurf->shell; |
| 1372 | struct weston_seat *seat; |
| 1373 | struct weston_compositor *ec = shsurf->surface->compositor; |
| 1374 | struct wl_pointer *pointer; |
| 1375 | int was_unresponsive; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1376 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1377 | if (shsurf->ping_timer == NULL) |
| 1378 | /* Just ignore unsolicited pong. */ |
| 1379 | return; |
| 1380 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1381 | if (shsurf->ping_timer->serial == serial) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1382 | was_unresponsive = shsurf->unresponsive; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1383 | shsurf->unresponsive = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1384 | if (was_unresponsive) { |
| 1385 | /* Received pong from previously unresponsive client */ |
| 1386 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 1387 | pointer = seat->seat.pointer; |
| 1388 | if (pointer->focus == |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1389 | &shell->grab_surface->surface && |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1390 | pointer->current == |
| 1391 | &shsurf->surface->surface) |
| 1392 | end_busy_cursor(shsurf, pointer); |
| 1393 | } |
| 1394 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1395 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1396 | } |
| 1397 | } |
| 1398 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1399 | static void |
| 1400 | shell_surface_set_title(struct wl_client *client, |
| 1401 | struct wl_resource *resource, const char *title) |
| 1402 | { |
| 1403 | struct shell_surface *shsurf = resource->data; |
| 1404 | |
| 1405 | free(shsurf->title); |
| 1406 | shsurf->title = strdup(title); |
| 1407 | } |
| 1408 | |
| 1409 | static void |
| 1410 | shell_surface_set_class(struct wl_client *client, |
| 1411 | struct wl_resource *resource, const char *class) |
| 1412 | { |
| 1413 | struct shell_surface *shsurf = resource->data; |
| 1414 | |
| 1415 | free(shsurf->class); |
| 1416 | shsurf->class = strdup(class); |
| 1417 | } |
| 1418 | |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1419 | static struct weston_output * |
| 1420 | get_default_output(struct weston_compositor *compositor) |
| 1421 | { |
| 1422 | return container_of(compositor->output_list.next, |
| 1423 | struct weston_output, link); |
| 1424 | } |
| 1425 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1426 | static void |
| 1427 | shell_unset_fullscreen(struct shell_surface *shsurf) |
| 1428 | { |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 1429 | struct workspace *ws; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1430 | /* undo all fullscreen things here */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1431 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 1432 | shell_surface_is_top_fullscreen(shsurf)) { |
| 1433 | weston_output_switch_mode(shsurf->fullscreen_output, |
| 1434 | shsurf->fullscreen_output->origin); |
| 1435 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1436 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 1437 | shsurf->fullscreen.framerate = 0; |
| 1438 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 1439 | wl_list_init(&shsurf->fullscreen.transform.link); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1440 | if (shsurf->fullscreen.black_surface) |
| 1441 | weston_surface_destroy(shsurf->fullscreen.black_surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1442 | shsurf->fullscreen.black_surface = NULL; |
| 1443 | shsurf->fullscreen_output = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1444 | weston_surface_set_position(shsurf->surface, |
| 1445 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 1446 | if (shsurf->saved_rotation_valid) { |
| 1447 | wl_list_insert(&shsurf->surface->geometry.transformation_list, |
| 1448 | &shsurf->rotation.transform.link); |
| 1449 | shsurf->saved_rotation_valid = false; |
| 1450 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 1451 | |
| 1452 | ws = get_current_workspace(shsurf->shell); |
| 1453 | wl_list_remove(&shsurf->surface->layer_link); |
| 1454 | wl_list_insert(&ws->layer.surface_list, &shsurf->surface->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1455 | } |
| 1456 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1457 | static int |
| 1458 | reset_shell_surface_type(struct shell_surface *surface) |
| 1459 | { |
| 1460 | switch (surface->type) { |
| 1461 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1462 | shell_unset_fullscreen(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1463 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1464 | case SHELL_SURFACE_MAXIMIZED: |
| 1465 | surface->output = get_default_output(surface->surface->compositor); |
| 1466 | weston_surface_set_position(surface->surface, |
| 1467 | surface->saved_x, |
| 1468 | surface->saved_y); |
| 1469 | break; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1470 | case SHELL_SURFACE_NONE: |
| 1471 | case SHELL_SURFACE_TOPLEVEL: |
| 1472 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1473 | case SHELL_SURFACE_POPUP: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1474 | break; |
| 1475 | } |
| 1476 | |
| 1477 | surface->type = SHELL_SURFACE_NONE; |
| 1478 | return 0; |
| 1479 | } |
| 1480 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1481 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1482 | set_surface_type(struct shell_surface *shsurf) |
| 1483 | { |
| 1484 | struct weston_surface *surface = shsurf->surface; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1485 | struct weston_surface *pes = shsurf->parent; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1486 | |
| 1487 | reset_shell_surface_type(shsurf); |
| 1488 | |
| 1489 | shsurf->type = shsurf->next_type; |
| 1490 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 1491 | |
| 1492 | switch (shsurf->type) { |
| 1493 | case SHELL_SURFACE_TOPLEVEL: |
| 1494 | break; |
| 1495 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1496 | weston_surface_set_position(surface, |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 1497 | pes->geometry.x + shsurf->transient.x, |
| 1498 | pes->geometry.y + shsurf->transient.y); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1499 | break; |
| 1500 | |
| 1501 | case SHELL_SURFACE_MAXIMIZED: |
| 1502 | shsurf->saved_x = surface->geometry.x; |
| 1503 | shsurf->saved_y = surface->geometry.y; |
| 1504 | shsurf->saved_position_valid = true; |
| 1505 | break; |
| 1506 | |
| 1507 | case SHELL_SURFACE_FULLSCREEN: |
| 1508 | shsurf->saved_x = surface->geometry.x; |
| 1509 | shsurf->saved_y = surface->geometry.y; |
| 1510 | shsurf->saved_position_valid = true; |
| 1511 | |
| 1512 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 1513 | wl_list_remove(&shsurf->rotation.transform.link); |
| 1514 | wl_list_init(&shsurf->rotation.transform.link); |
| 1515 | shsurf->surface->geometry.dirty = 1; |
| 1516 | shsurf->saved_rotation_valid = true; |
| 1517 | } |
| 1518 | break; |
| 1519 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1520 | default: |
| 1521 | break; |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1526 | set_toplevel(struct shell_surface *shsurf) |
| 1527 | { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1528 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1532 | shell_surface_set_toplevel(struct wl_client *client, |
| 1533 | struct wl_resource *resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1534 | { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1535 | struct shell_surface *surface = resource->data; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1536 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1537 | set_toplevel(surface); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | static void |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 1541 | set_transient(struct shell_surface *shsurf, |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1542 | struct weston_surface *parent, int x, int y, uint32_t flags) |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 1543 | { |
| 1544 | /* assign to parents output */ |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1545 | shsurf->parent = parent; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 1546 | shsurf->transient.x = x; |
| 1547 | shsurf->transient.y = y; |
| 1548 | shsurf->transient.flags = flags; |
| 1549 | shsurf->next_type = SHELL_SURFACE_TRANSIENT; |
| 1550 | } |
| 1551 | |
| 1552 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1553 | shell_surface_set_transient(struct wl_client *client, |
| 1554 | struct wl_resource *resource, |
| 1555 | struct wl_resource *parent_resource, |
| 1556 | int x, int y, uint32_t flags) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1557 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1558 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1559 | struct weston_surface *parent = parent_resource->data; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1560 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1561 | set_transient(shsurf, parent, x, y, flags); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1562 | } |
| 1563 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1564 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1565 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 1566 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 1567 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | static int |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1571 | get_output_panel_height(struct desktop_shell *shell, |
| 1572 | struct weston_output *output) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1573 | { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1574 | struct weston_surface *surface; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1575 | int panel_height = 0; |
| 1576 | |
| 1577 | if (!output) |
| 1578 | return 0; |
| 1579 | |
Juan Zhao | 4ab9468 | 2012-07-09 22:24:09 -0700 | [diff] [blame] | 1580 | wl_list_for_each(surface, &shell->panel_layer.surface_list, layer_link) { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1581 | if (surface->output == output) { |
| 1582 | panel_height = surface->geometry.height; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1583 | break; |
| 1584 | } |
| 1585 | } |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1586 | |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1587 | return panel_height; |
| 1588 | } |
| 1589 | |
| 1590 | static void |
| 1591 | shell_surface_set_maximized(struct wl_client *client, |
| 1592 | struct wl_resource *resource, |
| 1593 | struct wl_resource *output_resource ) |
| 1594 | { |
| 1595 | struct shell_surface *shsurf = resource->data; |
| 1596 | struct weston_surface *es = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1597 | struct desktop_shell *shell = NULL; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1598 | uint32_t edges = 0, panel_height = 0; |
| 1599 | |
| 1600 | /* get the default output, if the client set it as NULL |
| 1601 | check whether the ouput is available */ |
| 1602 | if (output_resource) |
| 1603 | shsurf->output = output_resource->data; |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 1604 | else if (es->output) |
| 1605 | shsurf->output = es->output; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1606 | else |
| 1607 | shsurf->output = get_default_output(es->compositor); |
| 1608 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1609 | shell = shell_surface_get_shell(shsurf); |
Rob Bradford | 31b6862 | 2012-07-02 19:00:19 +0100 | [diff] [blame] | 1610 | panel_height = get_output_panel_height(shell, shsurf->output); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1611 | edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT; |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1612 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1613 | shsurf->client->send_configure(shsurf->surface, edges, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1614 | shsurf->output->width, |
| 1615 | shsurf->output->height - panel_height); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1616 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1617 | shsurf->next_type = SHELL_SURFACE_MAXIMIZED; |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 1618 | } |
| 1619 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1620 | static void |
| 1621 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy); |
| 1622 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1623 | static struct weston_surface * |
| 1624 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1625 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1626 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1627 | { |
| 1628 | struct weston_surface *surface = NULL; |
| 1629 | |
| 1630 | surface = weston_surface_create(ec); |
| 1631 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1632 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1633 | return NULL; |
| 1634 | } |
| 1635 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1636 | surface->configure = black_surface_configure; |
| 1637 | surface->private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1638 | weston_surface_configure(surface, x, y, w, h); |
| 1639 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 1640 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 1641 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
| 1642 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1643 | return surface; |
| 1644 | } |
| 1645 | |
| 1646 | /* Create black surface and append it to the associated fullscreen surface. |
| 1647 | * Handle size dismatch and positioning according to the method. */ |
| 1648 | static void |
| 1649 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 1650 | { |
| 1651 | struct weston_output *output = shsurf->fullscreen_output; |
| 1652 | struct weston_surface *surface = shsurf->surface; |
| 1653 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1654 | float scale, output_aspect, surface_aspect, x, y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1655 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1656 | if (!shsurf->fullscreen.black_surface) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1657 | shsurf->fullscreen.black_surface = |
| 1658 | create_black_surface(surface->compositor, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1659 | surface, |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1660 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1661 | output->width, |
| 1662 | output->height); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1663 | |
| 1664 | wl_list_remove(&shsurf->fullscreen.black_surface->layer_link); |
| 1665 | wl_list_insert(&surface->layer_link, |
| 1666 | &shsurf->fullscreen.black_surface->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1667 | shsurf->fullscreen.black_surface->output = output; |
| 1668 | |
| 1669 | switch (shsurf->fullscreen.type) { |
| 1670 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Kristian Høgsberg | a08b528 | 2012-07-20 15:30:36 -0400 | [diff] [blame] | 1671 | if (surface->buffer) |
| 1672 | center_on_output(surface, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1673 | break; |
| 1674 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
| 1675 | matrix = &shsurf->fullscreen.transform.matrix; |
| 1676 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1677 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1678 | output_aspect = (float) output->width / |
| 1679 | (float) output->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1680 | surface_aspect = (float) surface->geometry.width / |
| 1681 | (float) surface->geometry.height; |
| 1682 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1683 | scale = (float) output->width / |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1684 | (float) surface->geometry.width; |
| 1685 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1686 | scale = (float) output->height / |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1687 | (float) surface->geometry.height; |
| 1688 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1689 | weston_matrix_scale(matrix, scale, scale, 1); |
| 1690 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1691 | wl_list_insert(&surface->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1692 | &shsurf->fullscreen.transform.link); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1693 | x = output->x + (output->width - surface->geometry.width * scale) / 2; |
| 1694 | y = output->y + (output->height - surface->geometry.height * scale) / 2; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1695 | weston_surface_set_position(surface, x, y); |
| 1696 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1697 | break; |
| 1698 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1699 | if (shell_surface_is_top_fullscreen(shsurf)) { |
| 1700 | struct weston_mode mode = {0, |
| 1701 | surface->geometry.width, |
| 1702 | surface->geometry.height, |
| 1703 | shsurf->fullscreen.framerate}; |
| 1704 | |
| 1705 | if (weston_output_switch_mode(output, &mode) == 0) { |
| 1706 | weston_surface_configure(shsurf->fullscreen.black_surface, |
| 1707 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1708 | output->width, |
| 1709 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1710 | weston_surface_set_position(surface, output->x, output->y); |
| 1711 | break; |
| 1712 | } |
| 1713 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1714 | break; |
| 1715 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
| 1716 | break; |
| 1717 | default: |
| 1718 | break; |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | /* make the fullscreen and black surface at the top */ |
| 1723 | static void |
| 1724 | shell_stack_fullscreen(struct shell_surface *shsurf) |
| 1725 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1726 | struct weston_output *output = shsurf->fullscreen_output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1727 | struct weston_surface *surface = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1728 | struct desktop_shell *shell = shell_surface_get_shell(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1729 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1730 | wl_list_remove(&surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1731 | wl_list_insert(&shell->fullscreen_layer.surface_list, |
| 1732 | &surface->layer_link); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1733 | weston_surface_damage(surface); |
| 1734 | |
| 1735 | if (!shsurf->fullscreen.black_surface) |
| 1736 | shsurf->fullscreen.black_surface = |
| 1737 | create_black_surface(surface->compositor, |
| 1738 | surface, |
| 1739 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1740 | output->width, |
| 1741 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1742 | |
| 1743 | wl_list_remove(&shsurf->fullscreen.black_surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1744 | wl_list_insert(&surface->layer_link, |
| 1745 | &shsurf->fullscreen.black_surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1746 | weston_surface_damage(shsurf->fullscreen.black_surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | static void |
| 1750 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 1751 | { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1752 | shell_stack_fullscreen(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1753 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1754 | } |
| 1755 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1756 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1757 | shell_surface_set_fullscreen(struct wl_client *client, |
Kristian Høgsberg | f856fd2 | 2012-02-16 15:58:14 -0500 | [diff] [blame] | 1758 | struct wl_resource *resource, |
| 1759 | uint32_t method, |
| 1760 | uint32_t framerate, |
| 1761 | struct wl_resource *output_resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1762 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1763 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1764 | struct weston_surface *es = shsurf->surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1765 | |
| 1766 | if (output_resource) |
| 1767 | shsurf->output = output_resource->data; |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 1768 | else if (es->output) |
| 1769 | shsurf->output = es->output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1770 | else |
| 1771 | shsurf->output = get_default_output(es->compositor); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1772 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1773 | shsurf->fullscreen_output = shsurf->output; |
| 1774 | shsurf->fullscreen.type = method; |
| 1775 | shsurf->fullscreen.framerate = framerate; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1776 | shsurf->next_type = SHELL_SURFACE_FULLSCREEN; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1777 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1778 | shsurf->client->send_configure(shsurf->surface, 0, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1779 | shsurf->output->width, |
| 1780 | shsurf->output->height); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1781 | } |
| 1782 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1783 | static void |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1784 | popup_grab_focus(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1785 | struct wl_surface *surface, |
| 1786 | wl_fixed_t x, |
| 1787 | wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1788 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1789 | struct wl_pointer *pointer = grab->pointer; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1790 | struct shell_surface *priv = |
| 1791 | container_of(grab, struct shell_surface, popup.grab); |
| 1792 | struct wl_client *client = priv->surface->surface.resource.client; |
| 1793 | |
Pekka Paalanen | cb10843 | 2012-01-19 16:25:40 +0200 | [diff] [blame] | 1794 | if (surface && surface->resource.client == client) { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1795 | wl_pointer_set_focus(pointer, surface, x, y); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1796 | grab->focus = surface; |
| 1797 | } else { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1798 | wl_pointer_set_focus(pointer, NULL, |
| 1799 | wl_fixed_from_int(0), |
| 1800 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1801 | grab->focus = NULL; |
| 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1806 | popup_grab_motion(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1807 | uint32_t time, wl_fixed_t sx, wl_fixed_t sy) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1808 | { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1809 | struct wl_resource *resource; |
| 1810 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1811 | resource = grab->pointer->focus_resource; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1812 | if (resource) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1813 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1817 | popup_grab_button(struct wl_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1818 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1819 | { |
| 1820 | struct wl_resource *resource; |
| 1821 | struct shell_surface *shsurf = |
| 1822 | container_of(grab, struct shell_surface, popup.grab); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1823 | struct wl_display *display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1824 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1825 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1826 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1827 | resource = grab->pointer->focus_resource; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1828 | if (resource) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1829 | display = wl_client_get_display(resource->client); |
| 1830 | serial = wl_display_get_serial(display); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1831 | wl_pointer_send_button(resource, serial, time, button, state); |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1832 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1833 | (shsurf->popup.initial_up || |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1834 | time - shsurf->popup.seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame^] | 1835 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1836 | } |
| 1837 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1838 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1839 | shsurf->popup.initial_up = 1; |
| 1840 | } |
| 1841 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1842 | static const struct wl_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1843 | popup_grab_focus, |
| 1844 | popup_grab_motion, |
| 1845 | popup_grab_button, |
| 1846 | }; |
| 1847 | |
| 1848 | static void |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame^] | 1849 | popup_grab_end(struct wl_pointer *pointer) |
| 1850 | { |
| 1851 | struct wl_pointer_grab *grab = pointer->grab; |
| 1852 | struct shell_surface *shsurf = |
| 1853 | container_of(grab, struct shell_surface, popup.grab); |
| 1854 | |
| 1855 | if (pointer->grab->interface == &popup_grab_interface) { |
| 1856 | wl_shell_surface_send_popup_done(&shsurf->resource); |
| 1857 | wl_pointer_end_grab(grab->pointer); |
| 1858 | shsurf->popup.grab.pointer = NULL; |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1863 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1864 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1865 | struct wl_seat *seat = shsurf->popup.seat; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1866 | struct weston_surface *es = shsurf->surface; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1867 | struct weston_surface *parent = shsurf->parent; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1868 | |
| 1869 | es->output = parent->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1870 | shsurf->popup.grab.interface = &popup_grab_interface; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1871 | |
Pekka Paalanen | 938269a | 2012-02-07 14:19:01 +0200 | [diff] [blame] | 1872 | weston_surface_update_transform(parent); |
| 1873 | if (parent->transform.enabled) { |
| 1874 | shsurf->popup.parent_transform.matrix = |
| 1875 | parent->transform.matrix; |
| 1876 | } else { |
| 1877 | /* construct x, y translation matrix */ |
| 1878 | weston_matrix_init(&shsurf->popup.parent_transform.matrix); |
| 1879 | shsurf->popup.parent_transform.matrix.d[12] = |
| 1880 | parent->geometry.x; |
| 1881 | shsurf->popup.parent_transform.matrix.d[13] = |
| 1882 | parent->geometry.y; |
| 1883 | } |
| 1884 | wl_list_insert(es->geometry.transformation_list.prev, |
| 1885 | &shsurf->popup.parent_transform.link); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1886 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1887 | shsurf->popup.initial_up = 0; |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 1888 | weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y); |
| 1889 | weston_surface_update_transform(es); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1890 | |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1891 | /* We don't require the grab to still be active, but if another |
| 1892 | * grab has started in the meantime, we end the popup now. */ |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1893 | if (seat->pointer->grab_serial == shsurf->popup.serial) { |
| 1894 | wl_pointer_start_grab(seat->pointer, &shsurf->popup.grab); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1895 | } else { |
| 1896 | wl_shell_surface_send_popup_done(&shsurf->resource); |
| 1897 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | static void |
| 1901 | shell_surface_set_popup(struct wl_client *client, |
| 1902 | struct wl_resource *resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1903 | struct wl_resource *seat_resource, |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1904 | uint32_t serial, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1905 | struct wl_resource *parent_resource, |
| 1906 | int32_t x, int32_t y, uint32_t flags) |
| 1907 | { |
| 1908 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1909 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1910 | shsurf->type = SHELL_SURFACE_POPUP; |
| 1911 | shsurf->parent = parent_resource->data; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1912 | shsurf->popup.seat = seat_resource->data; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1913 | shsurf->popup.serial = serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1914 | shsurf->popup.x = x; |
| 1915 | shsurf->popup.y = y; |
| 1916 | } |
| 1917 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1918 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1919 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1920 | shell_surface_move, |
| 1921 | shell_surface_resize, |
| 1922 | shell_surface_set_toplevel, |
| 1923 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1924 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1925 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1926 | shell_surface_set_maximized, |
| 1927 | shell_surface_set_title, |
| 1928 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1929 | }; |
| 1930 | |
| 1931 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1932 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1933 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1934 | if (shsurf->popup.grab.pointer) |
| 1935 | wl_pointer_end_grab(shsurf->popup.grab.pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1936 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1937 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 1938 | shell_surface_is_top_fullscreen(shsurf)) { |
| 1939 | weston_output_switch_mode(shsurf->fullscreen_output, |
| 1940 | shsurf->fullscreen_output->origin); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1941 | } |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1942 | |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 1943 | if (shsurf->fullscreen.black_surface) |
| 1944 | weston_surface_destroy(shsurf->fullscreen.black_surface); |
| 1945 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1946 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 1947 | * we can always remove the listener. |
| 1948 | */ |
| 1949 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 1950 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1951 | ping_timer_destroy(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1952 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1953 | wl_list_remove(&shsurf->link); |
| 1954 | free(shsurf); |
| 1955 | } |
| 1956 | |
| 1957 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1958 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 1959 | { |
| 1960 | struct shell_surface *shsurf = resource->data; |
| 1961 | |
| 1962 | destroy_shell_surface(shsurf); |
| 1963 | } |
| 1964 | |
| 1965 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1966 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1967 | { |
| 1968 | struct shell_surface *shsurf = container_of(listener, |
| 1969 | struct shell_surface, |
| 1970 | surface_destroy_listener); |
| 1971 | |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 1972 | if (shsurf->resource.client) { |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1973 | wl_resource_destroy(&shsurf->resource); |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 1974 | } else { |
| 1975 | wl_signal_emit(&shsurf->resource.destroy_signal, |
| 1976 | &shsurf->resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1977 | destroy_shell_surface(shsurf); |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 1978 | } |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1979 | } |
| 1980 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 1981 | static void |
| 1982 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
| 1983 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1984 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1985 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1986 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 1987 | if (surface->configure == shell_surface_configure) |
| 1988 | return surface->private; |
| 1989 | else |
| 1990 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1991 | } |
| 1992 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 1993 | static struct shell_surface * |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1994 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 1995 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1996 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1997 | struct shell_surface *shsurf; |
| 1998 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1999 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2000 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2001 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2002 | } |
| 2003 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2004 | shsurf = calloc(1, sizeof *shsurf); |
| 2005 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2006 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2007 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2008 | } |
| 2009 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2010 | surface->configure = shell_surface_configure; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2011 | surface->private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2012 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2013 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2014 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2015 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2016 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2017 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2018 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2019 | shsurf->fullscreen.framerate = 0; |
| 2020 | shsurf->fullscreen.black_surface = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2021 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2022 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2023 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2024 | wl_signal_init(&shsurf->resource.destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2025 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
| 2026 | wl_signal_add(&surface->surface.resource.destroy_signal, |
| 2027 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2028 | |
| 2029 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 2030 | wl_list_init(&shsurf->link); |
| 2031 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2032 | /* empty when not in use */ |
| 2033 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2034 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2035 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2036 | wl_list_init(&shsurf->workspace_transform.link); |
| 2037 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2038 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2039 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2040 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2041 | shsurf->client = client; |
| 2042 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2043 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | static void |
| 2047 | shell_get_shell_surface(struct wl_client *client, |
| 2048 | struct wl_resource *resource, |
| 2049 | uint32_t id, |
| 2050 | struct wl_resource *surface_resource) |
| 2051 | { |
| 2052 | struct weston_surface *surface = surface_resource->data; |
| 2053 | struct desktop_shell *shell = resource->data; |
| 2054 | struct shell_surface *shsurf; |
| 2055 | |
| 2056 | if (get_shell_surface(surface)) { |
| 2057 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2058 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2059 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2060 | return; |
| 2061 | } |
| 2062 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2063 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2064 | if (!shsurf) { |
| 2065 | wl_resource_post_error(surface_resource, |
| 2066 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2067 | "surface->configure already set"); |
| 2068 | return; |
| 2069 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2070 | |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2071 | shsurf->resource.destroy = shell_destroy_shell_surface; |
| 2072 | shsurf->resource.object.id = id; |
| 2073 | shsurf->resource.object.interface = &wl_shell_surface_interface; |
| 2074 | shsurf->resource.object.implementation = |
| 2075 | (void (**)(void)) &shell_surface_implementation; |
| 2076 | shsurf->resource.data = shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2077 | |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2078 | wl_client_add_resource(client, &shsurf->resource); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 2082 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2083 | }; |
| 2084 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2085 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2086 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2087 | { |
| 2088 | proc->pid = 0; |
| 2089 | } |
| 2090 | |
| 2091 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2092 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2093 | { |
| 2094 | if (shell->screensaver.binding) |
| 2095 | return; |
| 2096 | |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2097 | if (!shell->screensaver.path) |
| 2098 | return; |
| 2099 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2100 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2101 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2102 | return; |
| 2103 | } |
| 2104 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2105 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2106 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2107 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2108 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2112 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2113 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2114 | if (shell->screensaver.process.pid == 0) |
| 2115 | return; |
| 2116 | |
| 2117 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2118 | } |
| 2119 | |
| 2120 | static void |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2121 | configure_static_surface(struct weston_surface *es, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2122 | { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2123 | struct weston_surface *s, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2124 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2125 | wl_list_for_each_safe(s, next, &layer->surface_list, layer_link) { |
| 2126 | if (s->output == es->output && s != es) { |
| 2127 | weston_surface_unmap(s); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2128 | s->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2129 | } |
| 2130 | } |
| 2131 | |
| 2132 | weston_surface_configure(es, es->output->x, es->output->y, |
| 2133 | es->buffer->width, es->buffer->height); |
| 2134 | |
| 2135 | if (wl_list_empty(&es->layer_link)) { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2136 | wl_list_insert(&layer->surface_list, &es->layer_link); |
Kristian Høgsberg | c7cd626 | 2012-06-28 13:46:09 -0400 | [diff] [blame] | 2137 | weston_compositor_schedule_repaint(es->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2138 | } |
| 2139 | } |
| 2140 | |
| 2141 | static void |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2142 | background_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 2143 | { |
| 2144 | struct desktop_shell *shell = es->private; |
| 2145 | |
| 2146 | configure_static_surface(es, &shell->background_layer); |
| 2147 | } |
| 2148 | |
| 2149 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2150 | desktop_shell_set_background(struct wl_client *client, |
| 2151 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2152 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2153 | struct wl_resource *surface_resource) |
| 2154 | { |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2155 | struct desktop_shell *shell = resource->data; |
| 2156 | struct weston_surface *surface = surface_resource->data; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2157 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2158 | if (surface->configure) { |
| 2159 | wl_resource_post_error(surface_resource, |
| 2160 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2161 | "surface role already assigned"); |
| 2162 | return; |
| 2163 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2164 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2165 | surface->configure = background_configure; |
| 2166 | surface->private = shell; |
| 2167 | surface->output = output_resource->data; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2168 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2169 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2170 | surface->output->width, |
| 2171 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | static void |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2175 | panel_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 2176 | { |
| 2177 | struct desktop_shell *shell = es->private; |
| 2178 | |
| 2179 | configure_static_surface(es, &shell->panel_layer); |
| 2180 | } |
| 2181 | |
| 2182 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2183 | desktop_shell_set_panel(struct wl_client *client, |
| 2184 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2185 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2186 | struct wl_resource *surface_resource) |
| 2187 | { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2188 | struct desktop_shell *shell = resource->data; |
| 2189 | struct weston_surface *surface = surface_resource->data; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2190 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2191 | if (surface->configure) { |
| 2192 | wl_resource_post_error(surface_resource, |
| 2193 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2194 | "surface role already assigned"); |
| 2195 | return; |
| 2196 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2197 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2198 | surface->configure = panel_configure; |
| 2199 | surface->private = shell; |
| 2200 | surface->output = output_resource->data; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2201 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2202 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2203 | surface->output->width, |
| 2204 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2205 | } |
| 2206 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2207 | static void |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2208 | lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
| 2209 | { |
| 2210 | struct desktop_shell *shell = surface->private; |
| 2211 | |
| 2212 | center_on_output(surface, get_default_output(shell->compositor)); |
| 2213 | |
| 2214 | if (!weston_surface_is_mapped(surface)) { |
| 2215 | wl_list_insert(&shell->lock_layer.surface_list, |
| 2216 | &surface->layer_link); |
Ander Conselvan de Oliveira | 231ba17 | 2012-09-14 16:12:04 +0300 | [diff] [blame] | 2217 | weston_surface_update_transform(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2218 | weston_compositor_wake(shell->compositor); |
| 2219 | } |
| 2220 | } |
| 2221 | |
| 2222 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2223 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 2224 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2225 | struct desktop_shell *shell = |
| 2226 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 2227 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2228 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 2229 | shell->lock_surface = NULL; |
| 2230 | } |
| 2231 | |
| 2232 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2233 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 2234 | struct wl_resource *resource, |
| 2235 | struct wl_resource *surface_resource) |
| 2236 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2237 | struct desktop_shell *shell = resource->data; |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2238 | struct weston_surface *surface = surface_resource->data; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2239 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2240 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 2241 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2242 | if (!shell->locked) |
| 2243 | return; |
| 2244 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2245 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2246 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2247 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
| 2248 | wl_signal_add(&surface_resource->destroy_signal, |
| 2249 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2250 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2251 | surface->configure = lock_surface_configure; |
| 2252 | surface->private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2256 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2257 | { |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 2258 | struct weston_surface *surface; |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 2259 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2260 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 2261 | wl_list_for_each(surface, &shell->screensaver.surfaces, link) |
| 2262 | weston_surface_unmap(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2263 | |
| 2264 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2265 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2266 | wl_list_remove(&shell->lock_layer.link); |
| 2267 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 2268 | &shell->fullscreen_layer.link); |
| 2269 | wl_list_insert(&shell->fullscreen_layer.link, |
| 2270 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 2271 | if (shell->showing_input_panels) { |
| 2272 | wl_list_insert(&shell->panel_layer.link, |
| 2273 | &shell->input_panel_layer.link); |
| 2274 | wl_list_insert(&shell->input_panel_layer.link, |
| 2275 | &ws->layer.link); |
| 2276 | } else { |
| 2277 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 2278 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2279 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 2280 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 2281 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2282 | shell->locked = false; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 2283 | shell->compositor->idle_time = shell->compositor->option_idle_time; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2284 | weston_compositor_wake(shell->compositor); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 2285 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | static void |
| 2289 | desktop_shell_unlock(struct wl_client *client, |
| 2290 | struct wl_resource *resource) |
| 2291 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2292 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2293 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2294 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2295 | |
| 2296 | if (shell->locked) |
| 2297 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2298 | } |
| 2299 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2300 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2301 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2302 | struct wl_resource *resource, |
| 2303 | struct wl_resource *surface_resource) |
| 2304 | { |
| 2305 | struct desktop_shell *shell = resource->data; |
| 2306 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2307 | shell->grab_surface = surface_resource->data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2308 | } |
| 2309 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2310 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 2311 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2312 | desktop_shell_set_panel, |
| 2313 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2314 | desktop_shell_unlock, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2315 | desktop_shell_set_grab_surface |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2316 | }; |
| 2317 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2318 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2319 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2320 | { |
| 2321 | struct shell_surface *shsurf; |
| 2322 | |
| 2323 | shsurf = get_shell_surface(surface); |
| 2324 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2325 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2326 | return shsurf->type; |
| 2327 | } |
| 2328 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2329 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2330 | move_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2331 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2332 | struct weston_surface *surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2333 | (struct weston_surface *) seat->pointer->focus; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2334 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 2335 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2336 | if (surface == NULL) |
| 2337 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2338 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2339 | shsurf = get_shell_surface(surface); |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2340 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2341 | return; |
| 2342 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2343 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2347 | resize_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2348 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2349 | struct weston_surface *surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2350 | (struct weston_surface *) seat->pointer->focus; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2351 | uint32_t edges = 0; |
| 2352 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2353 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 2354 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2355 | if (surface == NULL) |
| 2356 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2357 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2358 | shsurf = get_shell_surface(surface); |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2359 | if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2360 | return; |
| 2361 | |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 2362 | weston_surface_from_global(surface, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2363 | wl_fixed_to_int(seat->pointer->grab_x), |
| 2364 | wl_fixed_to_int(seat->pointer->grab_y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 2365 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2366 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2367 | if (x < surface->geometry.width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2368 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2369 | else if (x < 2 * surface->geometry.width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2370 | edges |= 0; |
| 2371 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2372 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2373 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2374 | if (y < surface->geometry.height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2375 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2376 | else if (y < 2 * surface->geometry.height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2377 | edges |= 0; |
| 2378 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2379 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2380 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 2381 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2385 | surface_opacity_binding(struct wl_seat *seat, uint32_t time, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 2386 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2387 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 2388 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2389 | struct shell_surface *shsurf; |
| 2390 | struct weston_surface *surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2391 | (struct weston_surface *) seat->pointer->focus; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2392 | |
| 2393 | if (surface == NULL) |
| 2394 | return; |
| 2395 | |
| 2396 | shsurf = get_shell_surface(surface); |
| 2397 | if (!shsurf) |
| 2398 | return; |
| 2399 | |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 2400 | surface->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2401 | |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 2402 | if (surface->alpha > 1.0) |
| 2403 | surface->alpha = 1.0; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2404 | if (surface->alpha < step) |
| 2405 | surface->alpha = step; |
| 2406 | |
| 2407 | surface->geometry.dirty = 1; |
| 2408 | weston_surface_damage(surface); |
| 2409 | } |
| 2410 | |
| 2411 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2412 | do_zoom(struct wl_seat *seat, uint32_t time, uint32_t key, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 2413 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2414 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2415 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 2416 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2417 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2418 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2419 | |
| 2420 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2421 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2422 | wl_fixed_to_double(seat->pointer->x), |
| 2423 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 2424 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2425 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2426 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2427 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2428 | increment = -output->zoom.increment; |
| 2429 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 2430 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 2431 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 2432 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2433 | else |
| 2434 | increment = 0; |
| 2435 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2436 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 2437 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2438 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 2439 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2440 | else if (output->zoom.level > output->zoom.max_level) |
| 2441 | output->zoom.level = output->zoom.max_level; |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 2442 | else { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2443 | output->zoom.active = 1; |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 2444 | output->disable_planes++; |
| 2445 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2446 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2447 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2448 | |
Scott Moreau | 8dacaab | 2012-06-17 18:10:58 -0600 | [diff] [blame] | 2449 | weston_output_update_zoom(output, output->zoom.type); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2450 | } |
| 2451 | } |
| 2452 | } |
| 2453 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2454 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2455 | zoom_axis_binding(struct wl_seat *seat, uint32_t time, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 2456 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2457 | { |
| 2458 | do_zoom(seat, time, 0, axis, value); |
| 2459 | } |
| 2460 | |
| 2461 | static void |
| 2462 | zoom_key_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 2463 | void *data) |
| 2464 | { |
| 2465 | do_zoom(seat, time, key, 0, 0); |
| 2466 | } |
| 2467 | |
| 2468 | static void |
| 2469 | terminate_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 2470 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2471 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2472 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2473 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2474 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2475 | } |
| 2476 | |
| 2477 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 2478 | rotate_grab_motion(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 2479 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2480 | { |
| 2481 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2482 | container_of(grab, struct rotate_grab, base.grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2483 | struct wl_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2484 | struct shell_surface *shsurf = rotate->base.shsurf; |
| 2485 | struct weston_surface *surface; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2486 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2487 | |
| 2488 | if (!shsurf) |
| 2489 | return; |
| 2490 | |
| 2491 | surface = shsurf->surface; |
| 2492 | |
| 2493 | cx = 0.5f * surface->geometry.width; |
| 2494 | cy = 0.5f * surface->geometry.height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2495 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2496 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 2497 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2498 | r = sqrtf(dx * dx + dy * dy); |
| 2499 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2500 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2501 | shsurf->surface->geometry.dirty = 1; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2502 | |
| 2503 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2504 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2505 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2506 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2507 | weston_matrix_init(&rotate->rotation); |
| 2508 | rotate->rotation.d[0] = dx / r; |
| 2509 | rotate->rotation.d[4] = -dy / r; |
| 2510 | rotate->rotation.d[1] = -rotate->rotation.d[4]; |
| 2511 | rotate->rotation.d[5] = rotate->rotation.d[0]; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2512 | |
| 2513 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 2514 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2515 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2516 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 2517 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2518 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 2519 | wl_list_insert( |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2520 | &shsurf->surface->geometry.transformation_list, |
| 2521 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2522 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2523 | wl_list_init(&shsurf->rotation.transform.link); |
| 2524 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2525 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2526 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 2527 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2528 | /* We need to adjust the position of the surface |
| 2529 | * in case it was resized in a rotated state before */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2530 | cposx = surface->geometry.x + cx; |
| 2531 | cposy = surface->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2532 | dposx = rotate->center.x - cposx; |
| 2533 | dposy = rotate->center.y - cposy; |
| 2534 | if (dposx != 0.0f || dposy != 0.0f) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2535 | weston_surface_set_position(surface, |
| 2536 | surface->geometry.x + dposx, |
| 2537 | surface->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2538 | } |
| 2539 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 2540 | /* Repaint implies weston_surface_update_transform(), which |
| 2541 | * lazily applies the damage due to rotation update. |
| 2542 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2543 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 2547 | rotate_grab_button(struct wl_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2548 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2549 | { |
| 2550 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2551 | container_of(grab, struct rotate_grab, base.grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2552 | struct wl_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2553 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2554 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2555 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2556 | if (pointer->button_count == 0 && |
| 2557 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2558 | if (shsurf) |
| 2559 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 2560 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2561 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2562 | free(rotate); |
| 2563 | } |
| 2564 | } |
| 2565 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 2566 | static const struct wl_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2567 | noop_grab_focus, |
| 2568 | rotate_grab_motion, |
| 2569 | rotate_grab_button, |
| 2570 | }; |
| 2571 | |
| 2572 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2573 | rotate_binding(struct wl_seat *seat, uint32_t time, uint32_t button, |
Daniel Stone | e5a0120 | 2012-05-04 11:21:57 +0100 | [diff] [blame] | 2574 | void *data) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2575 | { |
| 2576 | struct weston_surface *base_surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2577 | (struct weston_surface *) seat->pointer->focus; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2578 | struct shell_surface *surface; |
| 2579 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2580 | float dx, dy; |
| 2581 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2582 | |
| 2583 | if (base_surface == NULL) |
| 2584 | return; |
| 2585 | |
| 2586 | surface = get_shell_surface(base_surface); |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2587 | if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2588 | return; |
| 2589 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2590 | rotate = malloc(sizeof *rotate); |
| 2591 | if (!rotate) |
| 2592 | return; |
| 2593 | |
Kristian Høgsberg | b2af93e | 2012-06-07 20:10:23 -0400 | [diff] [blame] | 2594 | weston_surface_to_global_float(surface->surface, |
| 2595 | surface->surface->geometry.width / 2, |
| 2596 | surface->surface->geometry.height / 2, |
| 2597 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2598 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2599 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 2600 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2601 | r = sqrtf(dx * dx + dy * dy); |
| 2602 | if (r > 20.0f) { |
| 2603 | struct weston_matrix inverse; |
| 2604 | |
| 2605 | weston_matrix_init(&inverse); |
| 2606 | inverse.d[0] = dx / r; |
| 2607 | inverse.d[4] = dy / r; |
| 2608 | inverse.d[1] = -inverse.d[4]; |
| 2609 | inverse.d[5] = inverse.d[0]; |
| 2610 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2611 | |
| 2612 | weston_matrix_init(&rotate->rotation); |
| 2613 | rotate->rotation.d[0] = dx / r; |
| 2614 | rotate->rotation.d[4] = -dy / r; |
| 2615 | rotate->rotation.d[1] = -rotate->rotation.d[4]; |
| 2616 | rotate->rotation.d[5] = rotate->rotation.d[0]; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2617 | } else { |
| 2618 | weston_matrix_init(&surface->rotation.rotation); |
| 2619 | weston_matrix_init(&rotate->rotation); |
| 2620 | } |
| 2621 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2622 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 2623 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 2627 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 2628 | { |
| 2629 | struct workspace *ws; |
| 2630 | struct weston_surface *surface, *prev; |
| 2631 | |
| 2632 | ws = get_current_workspace(shell); |
| 2633 | wl_list_for_each_reverse_safe(surface, prev, |
| 2634 | &shell->fullscreen_layer.surface_list, |
| 2635 | layer_link) |
| 2636 | weston_surface_restack(surface, &ws->layer.surface_list); |
| 2637 | } |
| 2638 | |
| 2639 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2640 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2641 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2642 | { |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 2643 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 2644 | struct workspace *ws; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2645 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2646 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2647 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 2648 | state = ensure_focus_state(shell, seat); |
| 2649 | if (state == NULL) |
| 2650 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 2651 | |
| 2652 | state->keyboard_focus = es; |
| 2653 | wl_list_remove(&state->surface_destroy_listener.link); |
| 2654 | wl_signal_add(&es->surface.resource.destroy_signal, |
| 2655 | &state->surface_destroy_listener); |
| 2656 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2657 | switch (get_shell_surface_type(es)) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2658 | case SHELL_SURFACE_FULLSCREEN: |
| 2659 | /* should on top of panels */ |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2660 | shell_stack_fullscreen(get_shell_surface(es)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2661 | shell_configure_fullscreen(get_shell_surface(es)); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2662 | break; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2663 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2664 | ws = get_current_workspace(shell); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 2665 | lower_fullscreen_layer(shell); |
| 2666 | weston_surface_restack(es, &ws->layer.surface_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2667 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2668 | } |
| 2669 | } |
| 2670 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2671 | /* no-op func for checking black surface */ |
| 2672 | static void |
| 2673 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 2674 | { |
| 2675 | } |
| 2676 | |
| 2677 | static bool |
| 2678 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 2679 | { |
| 2680 | if (es->configure == black_surface_configure) { |
| 2681 | if (fs_surface) |
| 2682 | *fs_surface = (struct weston_surface *)es->private; |
| 2683 | return true; |
| 2684 | } |
| 2685 | return false; |
| 2686 | } |
| 2687 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2688 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2689 | click_to_activate_binding(struct wl_seat *seat, uint32_t time, uint32_t button, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2690 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2691 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2692 | struct weston_seat *ws = (struct weston_seat *) seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2693 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2694 | struct weston_surface *focus; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2695 | struct weston_surface *upper; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2696 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2697 | focus = (struct weston_surface *) seat->pointer->focus; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 2698 | if (!focus) |
| 2699 | return; |
| 2700 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2701 | if (is_black_surface(focus, &upper)) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2702 | focus = upper; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2703 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2704 | if (get_shell_surface_type(focus) == SHELL_SURFACE_NONE) |
| 2705 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 2706 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2707 | if (seat->pointer->grab == &seat->pointer->default_grab) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2708 | activate(shell, focus, ws); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2712 | lock(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2713 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2714 | struct desktop_shell *shell = |
| 2715 | container_of(listener, struct desktop_shell, lock_listener); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2716 | struct weston_output *output; |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 2717 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2718 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2719 | if (shell->locked) { |
| 2720 | wl_list_for_each(output, &shell->compositor->output_list, link) |
| 2721 | /* TODO: find a way to jump to other DPMS levels */ |
| 2722 | if (output->set_dpms) |
| 2723 | output->set_dpms(output, WESTON_DPMS_STANDBY); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2724 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2725 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2726 | |
| 2727 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2728 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2729 | /* Hide all surfaces by removing the fullscreen, panel and |
| 2730 | * toplevel layers. This way nothing else can show or receive |
| 2731 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2732 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2733 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2734 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 2735 | if (shell->showing_input_panels) |
| 2736 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 2737 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2738 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 2739 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2740 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2741 | launch_screensaver(shell); |
| 2742 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2743 | /* TODO: disable bindings that should not work while locked. */ |
| 2744 | |
| 2745 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2746 | } |
| 2747 | |
| 2748 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2749 | unlock(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2750 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2751 | struct desktop_shell *shell = |
| 2752 | container_of(listener, struct desktop_shell, unlock_listener); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2753 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 2754 | if (!shell->locked || shell->lock_surface) { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2755 | weston_compositor_wake(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2756 | return; |
| 2757 | } |
| 2758 | |
| 2759 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 2760 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2761 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2762 | return; |
| 2763 | } |
| 2764 | |
| 2765 | if (shell->prepare_event_sent) |
| 2766 | return; |
| 2767 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2768 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2769 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2773 | show_input_panels(struct wl_listener *listener, void *data) |
| 2774 | { |
| 2775 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 2776 | container_of(listener, struct desktop_shell, |
| 2777 | show_input_panel_listener); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 2778 | struct input_panel_surface *surface, *next; |
| 2779 | struct weston_surface *ws; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2780 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 2781 | shell->showing_input_panels = true; |
| 2782 | |
| 2783 | wl_list_insert(&shell->panel_layer.link, |
| 2784 | &shell->input_panel_layer.link); |
| 2785 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2786 | wl_list_for_each_safe(surface, next, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 2787 | &shell->input_panel.surfaces, link) { |
| 2788 | ws = surface->surface; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 2789 | wl_list_insert(&shell->input_panel_layer.surface_list, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 2790 | &ws->layer_link); |
Jan Arne Petersen | 1428b8c | 2012-09-26 14:39:45 +0200 | [diff] [blame] | 2791 | ws->geometry.dirty = 1; |
Ander Conselvan de Oliveira | 231ba17 | 2012-09-14 16:12:04 +0300 | [diff] [blame] | 2792 | weston_surface_update_transform(ws); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 2793 | weston_surface_damage(ws); |
| 2794 | weston_slide_run(ws, ws->geometry.height, 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | static void |
| 2799 | hide_input_panels(struct wl_listener *listener, void *data) |
| 2800 | { |
| 2801 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 2802 | container_of(listener, struct desktop_shell, |
| 2803 | hide_input_panel_listener); |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2804 | struct weston_surface *surface, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2805 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 2806 | shell->showing_input_panels = false; |
| 2807 | |
| 2808 | wl_list_remove(&shell->input_panel_layer.link); |
| 2809 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2810 | wl_list_for_each_safe(surface, next, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 2811 | &shell->input_panel_layer.surface_list, layer_link) |
| 2812 | weston_surface_unmap(surface); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2816 | center_on_output(struct weston_surface *surface, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2817 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2818 | float x = (output->width - surface->buffer->width) / 2; |
| 2819 | float y = (output->height - surface->buffer->height) / 2; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2820 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2821 | weston_surface_configure(surface, output->x + x, output->y + y, |
| 2822 | surface->buffer->width, |
| 2823 | surface->buffer->height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | static void |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 2827 | weston_surface_set_initial_position (struct weston_surface *surface, |
| 2828 | struct desktop_shell *shell) |
| 2829 | { |
| 2830 | struct weston_compositor *compositor = shell->compositor; |
| 2831 | int ix = 0, iy = 0; |
| 2832 | int range_x, range_y; |
| 2833 | int dx, dy, x, y, panel_height; |
| 2834 | struct weston_output *output, *target_output = NULL; |
| 2835 | struct weston_seat *seat; |
| 2836 | |
| 2837 | /* As a heuristic place the new window on the same output as the |
| 2838 | * pointer. Falling back to the output containing 0, 0. |
| 2839 | * |
| 2840 | * TODO: Do something clever for touch too? |
| 2841 | */ |
| 2842 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 2843 | if (seat->has_pointer) { |
| 2844 | ix = wl_fixed_to_int(seat->pointer.x); |
| 2845 | iy = wl_fixed_to_int(seat->pointer.y); |
| 2846 | break; |
| 2847 | } |
| 2848 | } |
| 2849 | |
| 2850 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2851 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 2852 | target_output = output; |
| 2853 | break; |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | if (!target_output) { |
| 2858 | weston_surface_set_position(surface, 10 + random() % 400, |
| 2859 | 10 + random() % 400); |
| 2860 | return; |
| 2861 | } |
| 2862 | |
| 2863 | /* Valid range within output where the surface will still be onscreen. |
| 2864 | * If this is negative it means that the surface is bigger than |
| 2865 | * output. |
| 2866 | */ |
| 2867 | panel_height = get_output_panel_height(shell, target_output); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2868 | range_x = target_output->width - surface->geometry.width; |
| 2869 | range_y = (target_output->height - panel_height) - |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 2870 | surface->geometry.height; |
| 2871 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 2872 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 2873 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 2874 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 2875 | dx = 0; |
| 2876 | |
| 2877 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 2878 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 2879 | else |
| 2880 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 2881 | |
| 2882 | x = target_output->x + dx; |
| 2883 | y = target_output->y + dy; |
| 2884 | |
| 2885 | weston_surface_set_position (surface, x, y); |
| 2886 | } |
| 2887 | |
| 2888 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2889 | map(struct desktop_shell *shell, struct weston_surface *surface, |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 2890 | int32_t width, int32_t height, int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2891 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2892 | struct weston_compositor *compositor = shell->compositor; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2893 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 2894 | enum shell_surface_type surface_type = shsurf->type; |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 2895 | struct weston_surface *parent; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 2896 | struct weston_seat *seat; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2897 | struct workspace *ws; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2898 | int panel_height = 0; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2899 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2900 | surface->geometry.width = width; |
| 2901 | surface->geometry.height = height; |
| 2902 | surface->geometry.dirty = 1; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2903 | |
| 2904 | /* initial positioning, see also configure() */ |
| 2905 | switch (surface_type) { |
| 2906 | case SHELL_SURFACE_TOPLEVEL: |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 2907 | weston_surface_set_initial_position(surface, shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2908 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2909 | case SHELL_SURFACE_FULLSCREEN: |
Kristian Høgsberg | e4d3a2b | 2012-07-09 21:43:22 -0400 | [diff] [blame] | 2910 | center_on_output(surface, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2911 | shell_map_fullscreen(shsurf); |
| 2912 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2913 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2914 | /* use surface configure to set the geometry */ |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2915 | panel_height = get_output_panel_height(shell,surface->output); |
Rob Bradford | 31b6862 | 2012-07-02 19:00:19 +0100 | [diff] [blame] | 2916 | weston_surface_set_position(surface, shsurf->output->x, |
| 2917 | shsurf->output->y + panel_height); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2918 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 2919 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2920 | shell_map_popup(shsurf); |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 2921 | case SHELL_SURFACE_NONE: |
| 2922 | weston_surface_set_position(surface, |
| 2923 | surface->geometry.x + sx, |
| 2924 | surface->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 2925 | break; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2926 | default: |
| 2927 | ; |
| 2928 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2929 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 2930 | /* surface stacking order, see also activate() */ |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2931 | switch (surface_type) { |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 2932 | case SHELL_SURFACE_POPUP: |
| 2933 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2934 | parent = shsurf->parent; |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 2935 | wl_list_insert(parent->layer_link.prev, &surface->layer_link); |
| 2936 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2937 | case SHELL_SURFACE_FULLSCREEN: |
Ander Conselvan de Oliveira | a1ff53b | 2012-02-15 17:02:54 +0200 | [diff] [blame] | 2938 | case SHELL_SURFACE_NONE: |
| 2939 | break; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2940 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2941 | ws = get_current_workspace(shell); |
| 2942 | wl_list_insert(&ws->layer.surface_list, &surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2943 | break; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2944 | } |
| 2945 | |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 2946 | if (surface_type != SHELL_SURFACE_NONE) { |
Ander Conselvan de Oliveira | 231ba17 | 2012-09-14 16:12:04 +0300 | [diff] [blame] | 2947 | weston_surface_update_transform(surface); |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 2948 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
| 2949 | surface->output = shsurf->output; |
| 2950 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 2951 | |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 2952 | switch (surface_type) { |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 2953 | case SHELL_SURFACE_TRANSIENT: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 2954 | if (shsurf->transient.flags == |
| 2955 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 2956 | break; |
| 2957 | case SHELL_SURFACE_TOPLEVEL: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 2958 | case SHELL_SURFACE_FULLSCREEN: |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2959 | case SHELL_SURFACE_MAXIMIZED: |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 2960 | if (!shell->locked) { |
| 2961 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 2962 | activate(shell, surface, seat); |
| 2963 | } |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 2964 | break; |
| 2965 | default: |
| 2966 | break; |
| 2967 | } |
| 2968 | |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 2969 | if (surface_type == SHELL_SURFACE_TOPLEVEL) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 2970 | { |
| 2971 | switch (shell->win_animation_type) { |
| 2972 | case ANIMATION_FADE: |
| 2973 | weston_fade_run(surface, NULL, NULL); |
| 2974 | break; |
| 2975 | case ANIMATION_ZOOM: |
| 2976 | weston_zoom_run(surface, 0.8, 1.0, NULL, NULL); |
| 2977 | break; |
| 2978 | default: |
| 2979 | break; |
| 2980 | } |
| 2981 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2985 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2986 | float x, float y, int32_t width, int32_t height) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 2987 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2988 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
| 2989 | struct shell_surface *shsurf; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 2990 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2991 | shsurf = get_shell_surface(surface); |
| 2992 | if (shsurf) |
| 2993 | surface_type = shsurf->type; |
| 2994 | |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 2995 | surface->geometry.x = x; |
| 2996 | surface->geometry.y = y; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2997 | surface->geometry.width = width; |
| 2998 | surface->geometry.height = height; |
| 2999 | surface->geometry.dirty = 1; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3000 | |
| 3001 | switch (surface_type) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3002 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3003 | shell_stack_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3004 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3005 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3006 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3007 | /* setting x, y and using configure to change that geometry */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 3008 | surface->geometry.x = surface->output->x; |
| 3009 | surface->geometry.y = surface->output->y + |
| 3010 | get_output_panel_height(shell,surface->output); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3011 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3012 | case SHELL_SURFACE_TOPLEVEL: |
| 3013 | break; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3014 | default: |
| 3015 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 3016 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 3017 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3018 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 3019 | if (surface->output) { |
Ander Conselvan de Oliveira | 231ba17 | 2012-09-14 16:12:04 +0300 | [diff] [blame] | 3020 | weston_surface_update_transform(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3021 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 3022 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3023 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3024 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3025 | } |
| 3026 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3027 | static void |
| 3028 | shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 3029 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 3030 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3031 | struct desktop_shell *shell = shsurf->shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 3032 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3033 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 3034 | if (shsurf->next_type != SHELL_SURFACE_NONE && |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 3035 | shsurf->type != shsurf->next_type) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 3036 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 3037 | type_changed = 1; |
| 3038 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 3039 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3040 | if (!weston_surface_is_mapped(es)) { |
| 3041 | map(shell, es, es->buffer->width, es->buffer->height, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 3042 | } else if (type_changed || sx != 0 || sy != 0 || |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3043 | es->geometry.width != es->buffer->width || |
| 3044 | es->geometry.height != es->buffer->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3045 | float from_x, from_y; |
| 3046 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3047 | |
| 3048 | weston_surface_to_global_float(es, 0, 0, &from_x, &from_y); |
| 3049 | weston_surface_to_global_float(es, sx, sy, &to_x, &to_y); |
| 3050 | configure(shell, es, |
| 3051 | es->geometry.x + to_x - from_x, |
| 3052 | es->geometry.y + to_y - from_y, |
| 3053 | es->buffer->width, es->buffer->height); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3054 | } |
| 3055 | } |
| 3056 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 3057 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 3058 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3059 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3060 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3061 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 3062 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3063 | struct desktop_shell *shell = |
| 3064 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3065 | |
| 3066 | shell->child.process.pid = 0; |
| 3067 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 3068 | |
| 3069 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 3070 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 3071 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 3072 | shell->child.deathstamp = time; |
| 3073 | shell->child.deathcount = 0; |
| 3074 | } |
| 3075 | |
| 3076 | shell->child.deathcount++; |
| 3077 | if (shell->child.deathcount > 5) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3078 | weston_log("weston-desktop-shell died, giving up.\n"); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 3079 | return; |
| 3080 | } |
| 3081 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3082 | weston_log("weston-desktop-shell died, respawning...\n"); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 3083 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3084 | } |
| 3085 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 3086 | static void |
| 3087 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3088 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 3089 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 9724b51 | 2012-01-03 14:35:49 -0500 | [diff] [blame] | 3090 | const char *shell_exe = LIBEXECDIR "/weston-desktop-shell"; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3091 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3092 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 3093 | &shell->child.process, |
| 3094 | shell_exe, |
| 3095 | desktop_shell_sigchld); |
| 3096 | |
| 3097 | if (!shell->child.client) |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 3098 | weston_log("not able to start %s\n", shell_exe); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3102 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 3103 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3104 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3105 | |
| 3106 | wl_client_add_object(client, &wl_shell_interface, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3107 | &shell_implementation, id, shell); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3108 | } |
| 3109 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3110 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3111 | unbind_desktop_shell(struct wl_resource *resource) |
| 3112 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3113 | struct desktop_shell *shell = resource->data; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3114 | |
| 3115 | if (shell->locked) |
| 3116 | resume_desktop(shell); |
| 3117 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3118 | shell->child.desktop_shell = NULL; |
| 3119 | shell->prepare_event_sent = false; |
| 3120 | free(resource); |
| 3121 | } |
| 3122 | |
| 3123 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3124 | bind_desktop_shell(struct wl_client *client, |
| 3125 | void *data, uint32_t version, uint32_t id) |
| 3126 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3127 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 3128 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3129 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 3130 | resource = wl_client_add_object(client, &desktop_shell_interface, |
| 3131 | &desktop_shell_implementation, |
| 3132 | id, shell); |
| 3133 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3134 | if (client == shell->child.client) { |
| 3135 | resource->destroy = unbind_desktop_shell; |
| 3136 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 3137 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3138 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 3139 | |
| 3140 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3141 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3142 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3143 | } |
| 3144 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3145 | static void |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 3146 | screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
| 3147 | { |
| 3148 | struct desktop_shell *shell = surface->private; |
| 3149 | |
| 3150 | if (!shell->locked) |
| 3151 | return; |
| 3152 | |
| 3153 | center_on_output(surface, surface->output); |
| 3154 | |
| 3155 | if (wl_list_empty(&surface->layer_link)) { |
| 3156 | wl_list_insert(shell->lock_layer.surface_list.prev, |
| 3157 | &surface->layer_link); |
Ander Conselvan de Oliveira | 231ba17 | 2012-09-14 16:12:04 +0300 | [diff] [blame] | 3158 | weston_surface_update_transform(surface); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 3159 | shell->compositor->idle_time = shell->screensaver.duration; |
| 3160 | weston_compositor_wake(shell->compositor); |
| 3161 | shell->compositor->state = WESTON_COMPOSITOR_IDLE; |
| 3162 | } |
| 3163 | } |
| 3164 | |
| 3165 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3166 | screensaver_set_surface(struct wl_client *client, |
| 3167 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 3168 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3169 | struct wl_resource *output_resource) |
| 3170 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3171 | struct desktop_shell *shell = resource->data; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 3172 | struct weston_surface *surface = surface_resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3173 | struct weston_output *output = output_resource->data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3174 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 3175 | surface->configure = screensaver_configure; |
| 3176 | surface->private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3177 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3178 | } |
| 3179 | |
| 3180 | static const struct screensaver_interface screensaver_implementation = { |
| 3181 | screensaver_set_surface |
| 3182 | }; |
| 3183 | |
| 3184 | static void |
| 3185 | unbind_screensaver(struct wl_resource *resource) |
| 3186 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3187 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3188 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3189 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3190 | free(resource); |
| 3191 | } |
| 3192 | |
| 3193 | static void |
| 3194 | bind_screensaver(struct wl_client *client, |
| 3195 | void *data, uint32_t version, uint32_t id) |
| 3196 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3197 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3198 | struct wl_resource *resource; |
| 3199 | |
| 3200 | resource = wl_client_add_object(client, &screensaver_interface, |
| 3201 | &screensaver_implementation, |
| 3202 | id, shell); |
| 3203 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3204 | if (shell->screensaver.binding == NULL) { |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3205 | resource->destroy = unbind_screensaver; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3206 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3207 | return; |
| 3208 | } |
| 3209 | |
| 3210 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3211 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3212 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3213 | } |
| 3214 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3215 | static void |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3216 | input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
| 3217 | { |
| 3218 | struct weston_mode *mode = surface->output->current; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3219 | float x = (mode->width - surface->buffer->width) / 2; |
| 3220 | float y = mode->height - surface->buffer->height; |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3221 | |
| 3222 | /* Don't map the input panel here, wait for |
| 3223 | * show_input_panels signal. */ |
| 3224 | |
| 3225 | weston_surface_configure(surface, |
| 3226 | surface->output->x + x, |
| 3227 | surface->output->y + y, |
| 3228 | surface->buffer->width, |
| 3229 | surface->buffer->height); |
| 3230 | } |
| 3231 | |
| 3232 | static void |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3233 | destroy_input_panel_surface(struct wl_listener *listener, |
| 3234 | void *data) |
| 3235 | { |
| 3236 | struct input_panel_surface *input_panel_surface = |
| 3237 | container_of(listener, struct input_panel_surface, listener); |
| 3238 | |
| 3239 | wl_list_remove(&listener->link); |
| 3240 | wl_list_remove(&input_panel_surface->link); |
| 3241 | |
| 3242 | free(input_panel_surface); |
| 3243 | } |
| 3244 | |
| 3245 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3246 | input_panel_set_surface(struct wl_client *client, |
| 3247 | struct wl_resource *resource, |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3248 | struct wl_resource *surface_resource, |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3249 | struct wl_resource *output_resource) |
| 3250 | { |
| 3251 | struct desktop_shell *shell = resource->data; |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3252 | struct weston_surface *surface = surface_resource->data; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3253 | struct weston_output *output = output_resource->data; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3254 | struct input_panel_surface *input_panel_surface; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3255 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3256 | surface->configure = input_panel_configure; |
| 3257 | surface->private = shell; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3258 | surface->output = output; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3259 | |
| 3260 | input_panel_surface = malloc(sizeof *input_panel_surface); |
| 3261 | if (!input_panel_surface) { |
| 3262 | wl_resource_post_no_memory(resource); |
| 3263 | return; |
| 3264 | } |
| 3265 | |
| 3266 | input_panel_surface->surface = surface; |
| 3267 | input_panel_surface->listener.notify = destroy_input_panel_surface; |
| 3268 | |
| 3269 | wl_signal_add(&surface_resource->destroy_signal, |
| 3270 | &input_panel_surface->listener); |
| 3271 | |
| 3272 | wl_list_insert(&shell->input_panel.surfaces, |
| 3273 | &input_panel_surface->link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3274 | } |
| 3275 | |
| 3276 | static const struct input_panel_interface input_panel_implementation = { |
| 3277 | input_panel_set_surface |
| 3278 | }; |
| 3279 | |
| 3280 | static void |
| 3281 | unbind_input_panel(struct wl_resource *resource) |
| 3282 | { |
| 3283 | struct desktop_shell *shell = resource->data; |
| 3284 | |
| 3285 | shell->input_panel.binding = NULL; |
| 3286 | free(resource); |
| 3287 | } |
| 3288 | |
| 3289 | static void |
| 3290 | bind_input_panel(struct wl_client *client, |
| 3291 | void *data, uint32_t version, uint32_t id) |
| 3292 | { |
| 3293 | struct desktop_shell *shell = data; |
| 3294 | struct wl_resource *resource; |
| 3295 | |
| 3296 | resource = wl_client_add_object(client, &input_panel_interface, |
| 3297 | &input_panel_implementation, |
| 3298 | id, shell); |
| 3299 | |
| 3300 | if (shell->input_panel.binding == NULL) { |
| 3301 | resource->destroy = unbind_input_panel; |
| 3302 | shell->input_panel.binding = resource; |
| 3303 | return; |
| 3304 | } |
| 3305 | |
| 3306 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3307 | "interface object already bound"); |
| 3308 | wl_resource_destroy(resource); |
| 3309 | } |
| 3310 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3311 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3312 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3313 | struct weston_surface *current; |
| 3314 | struct wl_listener listener; |
| 3315 | struct wl_keyboard_grab grab; |
| 3316 | }; |
| 3317 | |
| 3318 | static void |
| 3319 | switcher_next(struct switcher *switcher) |
| 3320 | { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3321 | struct weston_surface *surface; |
| 3322 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 3323 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3324 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3325 | |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3326 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3327 | switch (get_shell_surface_type(surface)) { |
| 3328 | case SHELL_SURFACE_TOPLEVEL: |
| 3329 | case SHELL_SURFACE_FULLSCREEN: |
| 3330 | case SHELL_SURFACE_MAXIMIZED: |
| 3331 | if (first == NULL) |
| 3332 | first = surface; |
| 3333 | if (prev == switcher->current) |
| 3334 | next = surface; |
| 3335 | prev = surface; |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 3336 | surface->alpha = 0.25; |
Kristian Høgsberg | cacb7cd | 2012-02-28 09:20:21 -0500 | [diff] [blame] | 3337 | surface->geometry.dirty = 1; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3338 | weston_surface_damage(surface); |
| 3339 | break; |
| 3340 | default: |
| 3341 | break; |
| 3342 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 3343 | |
| 3344 | if (is_black_surface(surface, NULL)) { |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 3345 | surface->alpha = 0.25; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 3346 | surface->geometry.dirty = 1; |
| 3347 | weston_surface_damage(surface); |
| 3348 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3349 | } |
| 3350 | |
| 3351 | if (next == NULL) |
| 3352 | next = first; |
| 3353 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 3354 | if (next == NULL) |
| 3355 | return; |
| 3356 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3357 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3358 | wl_signal_add(&next->surface.resource.destroy_signal, |
| 3359 | &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3360 | |
| 3361 | switcher->current = next; |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 3362 | next->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 3363 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 3364 | shsurf = get_shell_surface(switcher->current); |
| 3365 | if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN) |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 3366 | shsurf->fullscreen.black_surface->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3367 | } |
| 3368 | |
| 3369 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3370 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3371 | { |
| 3372 | struct switcher *switcher = |
| 3373 | container_of(listener, struct switcher, listener); |
| 3374 | |
| 3375 | switcher_next(switcher); |
| 3376 | } |
| 3377 | |
| 3378 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 3379 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3380 | { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3381 | struct weston_surface *surface; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3382 | struct wl_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3383 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3384 | |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3385 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 3386 | surface->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3387 | weston_surface_damage(surface); |
| 3388 | } |
| 3389 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 3390 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3391 | activate(switcher->shell, switcher->current, |
| 3392 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3393 | wl_list_remove(&switcher->listener.link); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3394 | wl_keyboard_end_grab(keyboard); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3395 | free(switcher); |
| 3396 | } |
| 3397 | |
| 3398 | static void |
| 3399 | switcher_key(struct wl_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 3400 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3401 | { |
| 3402 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 3403 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 3404 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 3405 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 3406 | switcher_next(switcher); |
| 3407 | } |
| 3408 | |
| 3409 | static void |
| 3410 | switcher_modifier(struct wl_keyboard_grab *grab, uint32_t serial, |
| 3411 | uint32_t mods_depressed, uint32_t mods_latched, |
| 3412 | uint32_t mods_locked, uint32_t group) |
| 3413 | { |
| 3414 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3415 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3416 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 3417 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 3418 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 3419 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3420 | |
| 3421 | static const struct wl_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 3422 | switcher_key, |
| 3423 | switcher_modifier, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3424 | }; |
| 3425 | |
| 3426 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3427 | switcher_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 3428 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3429 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3430 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3431 | struct switcher *switcher; |
| 3432 | |
| 3433 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 3434 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3435 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3436 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3437 | wl_list_init(&switcher->listener.link); |
| 3438 | |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3439 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3440 | switcher->grab.interface = &switcher_grab; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3441 | wl_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 3442 | wl_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3443 | switcher_next(switcher); |
| 3444 | } |
| 3445 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 3446 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3447 | backlight_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 3448 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3449 | { |
| 3450 | struct weston_compositor *compositor = data; |
| 3451 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 3452 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3453 | |
| 3454 | /* TODO: we're limiting to simple use cases, where we assume just |
| 3455 | * control on the primary display. We'd have to extend later if we |
| 3456 | * ever get support for setting backlights on random desktop LCD |
| 3457 | * panels though */ |
| 3458 | output = get_default_output(compositor); |
| 3459 | if (!output) |
| 3460 | return; |
| 3461 | |
| 3462 | if (!output->set_backlight) |
| 3463 | return; |
| 3464 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 3465 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 3466 | backlight_new = output->backlight_current - 25; |
| 3467 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 3468 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3469 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 3470 | if (backlight_new < 5) |
| 3471 | backlight_new = 5; |
| 3472 | if (backlight_new > 255) |
| 3473 | backlight_new = 255; |
| 3474 | |
| 3475 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3476 | output->set_backlight(output, output->backlight_current); |
| 3477 | } |
| 3478 | |
| 3479 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3480 | debug_repaint_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 3481 | void *data) |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 3482 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3483 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 3484 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 3485 | struct weston_surface *surface; |
Ander Conselvan de Oliveira | 383b671 | 2012-08-09 16:44:59 +0300 | [diff] [blame] | 3486 | struct weston_plane plane; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 3487 | |
| 3488 | if (shell->debug_repaint_surface) { |
| 3489 | weston_surface_destroy(shell->debug_repaint_surface); |
| 3490 | shell->debug_repaint_surface = NULL; |
| 3491 | } else { |
| 3492 | surface = weston_surface_create(compositor); |
| 3493 | weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2); |
| 3494 | weston_surface_configure(surface, 0, 0, 8192, 8192); |
| 3495 | wl_list_insert(&compositor->fade_layer.surface_list, |
| 3496 | &surface->layer_link); |
Pekka Paalanen | b89b004 | 2012-10-10 12:49:29 +0300 | [diff] [blame] | 3497 | pixman_region32_fini(&surface->input); |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 3498 | pixman_region32_init(&surface->input); |
| 3499 | |
| 3500 | /* Here's the dirty little trick that makes the |
Ander Conselvan de Oliveira | 383b671 | 2012-08-09 16:44:59 +0300 | [diff] [blame] | 3501 | * repaint debugging work: we move the surface to a |
| 3502 | * different plane and force an update_transform to |
| 3503 | * update dependent state and clear the |
| 3504 | * geometry.dirty bit. This way the call to |
| 3505 | * damage_below() in update_transform() does not |
| 3506 | * add damage to the primary plane. */ |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 3507 | |
Ander Conselvan de Oliveira | 383b671 | 2012-08-09 16:44:59 +0300 | [diff] [blame] | 3508 | weston_plane_init(&plane, 0, 0); |
| 3509 | surface->plane = &plane; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 3510 | weston_surface_update_transform(surface); |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 3511 | shell->debug_repaint_surface = surface; |
Ander Conselvan de Oliveira | 383b671 | 2012-08-09 16:44:59 +0300 | [diff] [blame] | 3512 | surface->plane = &compositor->primary_plane; |
| 3513 | weston_plane_release(&plane); |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 3514 | } |
| 3515 | } |
| 3516 | |
Pekka Paalanen | 07c91f8 | 2012-08-30 16:47:21 -0500 | [diff] [blame] | 3517 | |
| 3518 | static void |
| 3519 | fan_debug_repaint_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 3520 | void *data) |
| 3521 | { |
| 3522 | struct desktop_shell *shell = data; |
| 3523 | struct weston_compositor *compositor = shell->compositor; |
| 3524 | compositor->fan_debug = !compositor->fan_debug; |
| 3525 | weston_compositor_damage_all(compositor); |
| 3526 | } |
| 3527 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 3528 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3529 | force_kill_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 3530 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 3531 | { |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 3532 | struct wl_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 3533 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 3534 | struct desktop_shell *shell = data; |
| 3535 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 3536 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 3537 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 3538 | focus_surface = seat->keyboard->focus; |
| 3539 | if (!focus_surface) |
| 3540 | return; |
| 3541 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 3542 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 3543 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 3544 | client = focus_surface->resource.client; |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 3545 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 3546 | |
| 3547 | /* Skip clients that we launched ourselves (the credentials of |
| 3548 | * the socketpair is ours) */ |
| 3549 | if (pid == getpid()) |
| 3550 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 3551 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3552 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3556 | workspace_up_binding(struct wl_seat *seat, uint32_t time, |
| 3557 | uint32_t key, void *data) |
| 3558 | { |
| 3559 | struct desktop_shell *shell = data; |
| 3560 | unsigned int new_index = shell->workspaces.current; |
| 3561 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 3562 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3563 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3564 | if (new_index != 0) |
| 3565 | new_index--; |
| 3566 | |
| 3567 | change_workspace(shell, new_index); |
| 3568 | } |
| 3569 | |
| 3570 | static void |
| 3571 | workspace_down_binding(struct wl_seat *seat, uint32_t time, |
| 3572 | uint32_t key, void *data) |
| 3573 | { |
| 3574 | struct desktop_shell *shell = data; |
| 3575 | unsigned int new_index = shell->workspaces.current; |
| 3576 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 3577 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3578 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3579 | if (new_index < shell->workspaces.num - 1) |
| 3580 | new_index++; |
| 3581 | |
| 3582 | change_workspace(shell, new_index); |
| 3583 | } |
| 3584 | |
| 3585 | static void |
| 3586 | workspace_f_binding(struct wl_seat *seat, uint32_t time, |
| 3587 | uint32_t key, void *data) |
| 3588 | { |
| 3589 | struct desktop_shell *shell = data; |
| 3590 | unsigned int new_index; |
| 3591 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 3592 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3593 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3594 | new_index = key - KEY_F1; |
| 3595 | if (new_index >= shell->workspaces.num) |
| 3596 | new_index = shell->workspaces.num - 1; |
| 3597 | |
| 3598 | change_workspace(shell, new_index); |
| 3599 | } |
| 3600 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 3601 | static void |
| 3602 | workspace_move_surface_up_binding(struct wl_seat *seat, uint32_t time, |
| 3603 | uint32_t key, void *data) |
| 3604 | { |
| 3605 | struct desktop_shell *shell = data; |
| 3606 | unsigned int new_index = shell->workspaces.current; |
| 3607 | |
| 3608 | if (shell->locked) |
| 3609 | return; |
| 3610 | |
| 3611 | if (new_index != 0) |
| 3612 | new_index--; |
| 3613 | |
| 3614 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 3615 | } |
| 3616 | |
| 3617 | static void |
| 3618 | workspace_move_surface_down_binding(struct wl_seat *seat, uint32_t time, |
| 3619 | uint32_t key, void *data) |
| 3620 | { |
| 3621 | struct desktop_shell *shell = data; |
| 3622 | unsigned int new_index = shell->workspaces.current; |
| 3623 | |
| 3624 | if (shell->locked) |
| 3625 | return; |
| 3626 | |
| 3627 | if (new_index < shell->workspaces.num - 1) |
| 3628 | new_index++; |
| 3629 | |
| 3630 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 3631 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3632 | |
| 3633 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 3634 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 3635 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3636 | struct desktop_shell *shell = |
| 3637 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3638 | struct workspace **ws; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 3639 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 3640 | if (shell->child.client) |
| 3641 | wl_client_destroy(shell->child.client); |
| 3642 | |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 3643 | wl_list_remove(&shell->lock_listener.link); |
| 3644 | wl_list_remove(&shell->unlock_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3645 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 3646 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 3647 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3648 | wl_array_for_each(ws, &shell->workspaces.array) |
| 3649 | workspace_destroy(*ws); |
| 3650 | wl_array_release(&shell->workspaces.array); |
| 3651 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 3652 | free(shell->screensaver.path); |
| 3653 | free(shell); |
| 3654 | } |
| 3655 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3656 | static void |
| 3657 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 3658 | { |
| 3659 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3660 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3661 | |
| 3662 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3663 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 3664 | MODIFIER_CTRL | MODIFIER_ALT, |
| 3665 | terminate_binding, ec); |
| 3666 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 3667 | click_to_activate_binding, |
| 3668 | shell); |
| 3669 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 3670 | MODIFIER_SUPER | MODIFIER_ALT, |
| 3671 | surface_opacity_binding, NULL); |
| 3672 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 3673 | MODIFIER_SUPER, zoom_axis_binding, |
| 3674 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3675 | |
| 3676 | /* configurable bindings */ |
| 3677 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3678 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 3679 | zoom_key_binding, NULL); |
| 3680 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 3681 | zoom_key_binding, NULL); |
| 3682 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 3683 | shell); |
| 3684 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 3685 | resize_binding, shell); |
| 3686 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 3687 | rotate_binding, NULL); |
| 3688 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 3689 | shell); |
| 3690 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 3691 | ec); |
| 3692 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 3693 | backlight_binding, ec); |
| 3694 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 3695 | ec); |
| 3696 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 3697 | backlight_binding, ec); |
Kristian Høgsberg | 73694c8 | 2012-06-28 14:13:10 -0400 | [diff] [blame] | 3698 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3699 | debug_repaint_binding, shell); |
Pekka Paalanen | 07c91f8 | 2012-08-30 16:47:21 -0500 | [diff] [blame] | 3700 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_ALT, |
| 3701 | fan_debug_repaint_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3702 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 3703 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3704 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 3705 | workspace_up_binding, shell); |
| 3706 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 3707 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 3708 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 3709 | workspace_move_surface_up_binding, |
| 3710 | shell); |
| 3711 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 3712 | workspace_move_surface_down_binding, |
| 3713 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3714 | |
| 3715 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 3716 | if (shell->workspaces.num > 1) { |
| 3717 | num_workspace_bindings = shell->workspaces.num; |
| 3718 | if (num_workspace_bindings > 6) |
| 3719 | num_workspace_bindings = 6; |
| 3720 | for (i = 0; i < num_workspace_bindings; i++) |
| 3721 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 3722 | workspace_f_binding, |
| 3723 | shell); |
| 3724 | } |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3725 | } |
| 3726 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3727 | WL_EXPORT int |
Kristian Høgsberg | b00a9d3 | 2012-09-11 14:06:27 -0400 | [diff] [blame] | 3728 | module_init(struct weston_compositor *ec) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3729 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 3730 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3731 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3732 | struct workspace **pws; |
| 3733 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 3734 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3735 | |
| 3736 | shell = malloc(sizeof *shell); |
| 3737 | if (shell == NULL) |
| 3738 | return -1; |
| 3739 | |
Kristian Høgsberg | f0d9116 | 2011-10-11 22:44:23 -0400 | [diff] [blame] | 3740 | memset(shell, 0, sizeof *shell); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3741 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 3742 | |
| 3743 | shell->destroy_listener.notify = shell_destroy; |
| 3744 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
| 3745 | shell->lock_listener.notify = lock; |
| 3746 | wl_signal_add(&ec->lock_signal, &shell->lock_listener); |
| 3747 | shell->unlock_listener.notify = unlock; |
| 3748 | wl_signal_add(&ec->unlock_signal, &shell->unlock_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3749 | shell->show_input_panel_listener.notify = show_input_panels; |
| 3750 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 3751 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 3752 | wl_signal_add(&ec->hide_input_panel_signal, &shell->hide_input_panel_listener); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3753 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 3754 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3755 | ec->shell_interface.create_shell_surface = create_shell_surface; |
| 3756 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 3757 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3758 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3759 | ec->shell_interface.resize = surface_resize; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3760 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3761 | wl_list_init(&shell->screensaver.surfaces); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3762 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3763 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3764 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 3765 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3766 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 3767 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3768 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3769 | |
| 3770 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 3771 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3772 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 3773 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3774 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3775 | for (i = 0; i < shell->workspaces.num; i++) { |
| 3776 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 3777 | if (pws == NULL) |
| 3778 | return -1; |
| 3779 | |
| 3780 | *pws = workspace_create(); |
| 3781 | if (*pws == NULL) |
| 3782 | return -1; |
| 3783 | } |
| 3784 | activate_workspace(shell, 0); |
| 3785 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 3786 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3787 | wl_list_init(&shell->workspaces.animation.link); |
| 3788 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 3789 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3790 | if (wl_display_add_global(ec->wl_display, &wl_shell_interface, |
| 3791 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3792 | return -1; |
| 3793 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3794 | if (wl_display_add_global(ec->wl_display, |
| 3795 | &desktop_shell_interface, |
| 3796 | shell, bind_desktop_shell) == NULL) |
| 3797 | return -1; |
| 3798 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3799 | if (wl_display_add_global(ec->wl_display, &screensaver_interface, |
| 3800 | shell, bind_screensaver) == NULL) |
| 3801 | return -1; |
| 3802 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3803 | if (wl_display_add_global(ec->wl_display, &input_panel_interface, |
| 3804 | shell, bind_input_panel) == NULL) |
| 3805 | return -1; |
| 3806 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 3807 | if (wl_display_add_global(ec->wl_display, &workspace_manager_interface, |
| 3808 | shell, bind_workspace_manager) == NULL) |
| 3809 | return -1; |
| 3810 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 3811 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 3812 | |
| 3813 | loop = wl_display_get_event_loop(ec->wl_display); |
| 3814 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3815 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 3816 | wl_list_for_each(seat, &ec->seat_list, link) |
| 3817 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3818 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3819 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3820 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3821 | return 0; |
| 3822 | } |