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