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