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