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