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