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