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