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