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