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