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