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