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