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; |
| 53 | struct weston_surface *keyboard_focus; |
| 54 | struct wl_list link; |
| 55 | struct wl_listener seat_destroy_listener; |
| 56 | struct wl_listener surface_destroy_listener; |
| 57 | }; |
| 58 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 59 | struct workspace { |
| 60 | struct weston_layer layer; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 61 | |
| 62 | struct wl_list focus_list; |
| 63 | struct wl_listener seat_destroyed_listener; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 64 | }; |
| 65 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 66 | struct desktop_shell { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 67 | struct weston_compositor *compositor; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 68 | |
| 69 | struct wl_listener lock_listener; |
| 70 | struct wl_listener unlock_listener; |
| 71 | struct wl_listener destroy_listener; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 72 | struct wl_listener show_input_panel_listener; |
| 73 | struct wl_listener hide_input_panel_listener; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 74 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 75 | struct weston_layer fullscreen_layer; |
| 76 | struct weston_layer panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 77 | struct weston_layer background_layer; |
| 78 | struct weston_layer lock_layer; |
| 79 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 80 | struct wl_listener pointer_focus_listener; |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 81 | struct weston_surface *grab_surface; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 82 | |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 83 | struct { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 84 | struct weston_process process; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 85 | struct wl_client *client; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 86 | struct wl_resource *desktop_shell; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 87 | |
| 88 | unsigned deathcount; |
| 89 | uint32_t deathstamp; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 90 | } child; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 91 | |
| 92 | bool locked; |
| 93 | bool prepare_event_sent; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 94 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 95 | struct weston_surface *lock_surface; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 96 | struct wl_listener lock_surface_listener; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 97 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 98 | struct { |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 99 | struct wl_array array; |
| 100 | unsigned int current; |
| 101 | unsigned int num; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 102 | |
| 103 | struct weston_animation animation; |
| 104 | int anim_dir; |
| 105 | uint32_t anim_timestamp; |
| 106 | double anim_current; |
| 107 | struct workspace *anim_from; |
| 108 | struct workspace *anim_to; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 109 | } workspaces; |
| 110 | |
| 111 | struct { |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 112 | char *path; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 113 | int duration; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 114 | struct wl_resource *binding; |
| 115 | struct wl_list surfaces; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 116 | struct weston_process process; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 117 | } screensaver; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 118 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 119 | struct { |
| 120 | struct wl_resource *binding; |
| 121 | struct wl_list surfaces; |
| 122 | } input_panel; |
| 123 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 124 | uint32_t binding_modifier; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 125 | enum animation_type win_animation_type; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 126 | struct weston_surface *debug_repaint_surface; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 127 | }; |
| 128 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 129 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 130 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 131 | SHELL_SURFACE_TOPLEVEL, |
| 132 | SHELL_SURFACE_TRANSIENT, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 133 | SHELL_SURFACE_FULLSCREEN, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 134 | SHELL_SURFACE_MAXIMIZED, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 135 | SHELL_SURFACE_POPUP |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 136 | }; |
| 137 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 138 | struct ping_timer { |
| 139 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 140 | uint32_t serial; |
| 141 | }; |
| 142 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 143 | struct shell_surface { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 144 | struct wl_resource resource; |
| 145 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 146 | struct weston_surface *surface; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 147 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 148 | struct weston_surface *parent; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 149 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 150 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 151 | enum shell_surface_type type, next_type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 152 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 153 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 154 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 155 | bool saved_rotation_valid; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 156 | int unresponsive; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 157 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 158 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 159 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 160 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 161 | } rotation; |
| 162 | |
| 163 | struct { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 164 | struct wl_pointer_grab grab; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 165 | int32_t x, y; |
Pekka Paalanen | 938269a | 2012-02-07 14:19:01 +0200 | [diff] [blame] | 166 | struct weston_transform parent_transform; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 167 | int32_t initial_up; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 168 | struct wl_seat *seat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 169 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 170 | } popup; |
| 171 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 172 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 173 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 174 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 175 | } transient; |
| 176 | |
| 177 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 178 | enum wl_shell_surface_fullscreen_method type; |
| 179 | struct weston_transform transform; /* matrix from x, y */ |
| 180 | uint32_t framerate; |
| 181 | struct weston_surface *black_surface; |
| 182 | } fullscreen; |
| 183 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 184 | struct ping_timer *ping_timer; |
| 185 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 186 | struct weston_transform workspace_transform; |
| 187 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 188 | struct focus_state *focus_state; |
| 189 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 190 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 191 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 192 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 193 | |
| 194 | const struct weston_shell_client *client; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 195 | }; |
| 196 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 197 | struct shell_grab { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 198 | struct wl_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 199 | struct shell_surface *shsurf; |
| 200 | struct wl_listener shsurf_destroy_listener; |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 201 | struct wl_pointer *pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | struct weston_move_grab { |
| 205 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 206 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 207 | }; |
| 208 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 209 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 210 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 211 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 212 | struct { |
Kristian Høgsberg | b2af93e | 2012-06-07 20:10:23 -0400 | [diff] [blame] | 213 | GLfloat x; |
| 214 | GLfloat y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 215 | } center; |
| 216 | }; |
| 217 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 218 | static struct shell_surface * |
| 219 | get_shell_surface(struct weston_surface *surface); |
| 220 | |
| 221 | static struct desktop_shell * |
| 222 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 223 | |
| 224 | static bool |
| 225 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 226 | { |
| 227 | struct desktop_shell *shell; |
| 228 | struct weston_surface *top_fs_es; |
| 229 | |
| 230 | shell = shell_surface_get_shell(shsurf); |
| 231 | |
| 232 | if (wl_list_empty(&shell->fullscreen_layer.surface_list)) |
| 233 | return false; |
| 234 | |
| 235 | top_fs_es = container_of(shell->fullscreen_layer.surface_list.next, |
| 236 | struct weston_surface, |
| 237 | layer_link); |
| 238 | return (shsurf == get_shell_surface(top_fs_es)); |
| 239 | } |
| 240 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 241 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 242 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 243 | { |
| 244 | struct shell_grab *grab; |
| 245 | |
| 246 | grab = container_of(listener, struct shell_grab, |
| 247 | shsurf_destroy_listener); |
| 248 | |
| 249 | grab->shsurf = NULL; |
| 250 | } |
| 251 | |
| 252 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 253 | shell_grab_start(struct shell_grab *grab, |
| 254 | const struct wl_pointer_grab_interface *interface, |
| 255 | struct shell_surface *shsurf, |
| 256 | struct wl_pointer *pointer, |
| 257 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 258 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 259 | struct desktop_shell *shell = shsurf->shell; |
| 260 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 261 | grab->grab.interface = interface; |
| 262 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 263 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 264 | wl_signal_add(&shsurf->resource.destroy_signal, |
| 265 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 266 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 267 | grab->pointer = pointer; |
| 268 | grab->grab.focus = &shsurf->surface->surface; |
| 269 | |
| 270 | wl_pointer_start_grab(pointer, &grab->grab); |
| 271 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, cursor); |
| 272 | wl_pointer_set_focus(pointer, &shell->grab_surface->surface, |
| 273 | wl_fixed_from_int(0), wl_fixed_from_int(0)); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 277 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 278 | { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 279 | if (grab->shsurf) |
| 280 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 281 | |
| 282 | wl_pointer_end_grab(grab->pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | static void |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 286 | center_on_output(struct weston_surface *surface, |
| 287 | struct weston_output *output); |
| 288 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 289 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 290 | get_modifier(char *modifier) |
| 291 | { |
| 292 | if (!modifier) |
| 293 | return MODIFIER_SUPER; |
| 294 | |
| 295 | if (!strcmp("ctrl", modifier)) |
| 296 | return MODIFIER_CTRL; |
| 297 | else if (!strcmp("alt", modifier)) |
| 298 | return MODIFIER_ALT; |
| 299 | else if (!strcmp("super", modifier)) |
| 300 | return MODIFIER_SUPER; |
| 301 | else |
| 302 | return MODIFIER_SUPER; |
| 303 | } |
| 304 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 305 | static enum animation_type |
| 306 | get_animation_type(char *animation) |
| 307 | { |
| 308 | if (!animation) |
| 309 | return ANIMATION_NONE; |
| 310 | |
| 311 | if (!strcmp("zoom", animation)) |
| 312 | return ANIMATION_ZOOM; |
| 313 | else if (!strcmp("fade", animation)) |
| 314 | return ANIMATION_FADE; |
| 315 | else |
| 316 | return ANIMATION_NONE; |
| 317 | } |
| 318 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 319 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 320 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 321 | { |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 322 | char *config_file; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 323 | char *path = NULL; |
| 324 | int duration = 60; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 325 | unsigned int num_workspaces = DEFAULT_NUM_WORKSPACES; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 326 | char *modifier = NULL; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 327 | char *win_animation = NULL; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 328 | |
Kristian Høgsberg | a4e8b33 | 2012-04-20 16:48:21 -0400 | [diff] [blame] | 329 | struct config_key shell_keys[] = { |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 330 | { "binding-modifier", CONFIG_KEY_STRING, &modifier }, |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 331 | { "animation", CONFIG_KEY_STRING, &win_animation}, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 332 | { "num-workspaces", |
| 333 | CONFIG_KEY_UNSIGNED_INTEGER, &num_workspaces }, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 334 | }; |
| 335 | |
Kristian Høgsberg | a4e8b33 | 2012-04-20 16:48:21 -0400 | [diff] [blame] | 336 | struct config_key saver_keys[] = { |
| 337 | { "path", CONFIG_KEY_STRING, &path }, |
| 338 | { "duration", CONFIG_KEY_INTEGER, &duration }, |
| 339 | }; |
| 340 | |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 341 | struct config_section cs[] = { |
Kristian Høgsberg | a4e8b33 | 2012-04-20 16:48:21 -0400 | [diff] [blame] | 342 | { "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL }, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 343 | { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL }, |
| 344 | }; |
| 345 | |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 346 | config_file = config_file_path("weston.ini"); |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 347 | parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 348 | free(config_file); |
| 349 | |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 350 | shell->screensaver.path = path; |
| 351 | shell->screensaver.duration = duration; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 352 | shell->binding_modifier = get_modifier(modifier); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 353 | shell->win_animation_type = get_animation_type(win_animation); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 354 | shell->workspaces.num = num_workspaces > 0 ? num_workspaces : 1; |
| 355 | } |
| 356 | |
| 357 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 358 | focus_state_destroy(struct focus_state *state) |
| 359 | { |
| 360 | wl_list_remove(&state->seat_destroy_listener.link); |
| 361 | wl_list_remove(&state->surface_destroy_listener.link); |
| 362 | free(state); |
| 363 | } |
| 364 | |
| 365 | static void |
| 366 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 367 | { |
| 368 | struct focus_state *state = container_of(listener, |
| 369 | struct focus_state, |
| 370 | seat_destroy_listener); |
| 371 | |
| 372 | wl_list_remove(&state->link); |
| 373 | focus_state_destroy(state); |
| 374 | } |
| 375 | |
| 376 | static void |
| 377 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 378 | { |
| 379 | struct focus_state *state = container_of(listener, |
| 380 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame^] | 381 | surface_destroy_listener); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 382 | |
| 383 | wl_list_remove(&state->link); |
| 384 | focus_state_destroy(state); |
| 385 | } |
| 386 | |
| 387 | static struct focus_state * |
| 388 | focus_state_create(struct weston_seat *seat) |
| 389 | { |
| 390 | struct wl_keyboard *keyboard = seat->seat.keyboard; |
| 391 | struct focus_state *state; |
| 392 | struct wl_surface *surface; |
| 393 | struct shell_surface *shsurf; |
| 394 | |
| 395 | state = malloc(sizeof *state); |
| 396 | if (state == NULL) |
| 397 | return NULL; |
| 398 | |
| 399 | surface = keyboard->focus; |
| 400 | shsurf = get_shell_surface((struct weston_surface *)keyboard->focus); |
| 401 | shsurf->focus_state = state; |
| 402 | |
| 403 | state->seat = seat; |
| 404 | state->keyboard_focus = shsurf->surface; |
| 405 | wl_list_init(&state->link); |
| 406 | |
| 407 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 408 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
| 409 | wl_signal_add(&seat->seat.destroy_signal, |
| 410 | &state->seat_destroy_listener); |
| 411 | wl_signal_add(&surface->resource.destroy_signal, |
| 412 | &state->surface_destroy_listener); |
| 413 | |
| 414 | return state; |
| 415 | } |
| 416 | |
| 417 | static void |
| 418 | pop_focus_state(struct desktop_shell *shell, struct workspace *ws) |
| 419 | { |
| 420 | struct focus_state *state, *next; |
| 421 | |
| 422 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
| 423 | if (state->keyboard_focus) |
| 424 | wl_keyboard_set_focus(state->seat->seat.keyboard, |
| 425 | &state->keyboard_focus->surface); |
| 426 | |
| 427 | focus_state_destroy(state); |
| 428 | } |
| 429 | wl_list_init(&ws->focus_list); |
| 430 | } |
| 431 | |
| 432 | static void |
| 433 | push_focus_state(struct desktop_shell *shell, struct workspace *ws) |
| 434 | { |
| 435 | struct weston_seat *seat; |
| 436 | struct focus_state *state; |
| 437 | struct wl_keyboard *keyboard; |
| 438 | |
| 439 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 440 | keyboard = seat->seat.keyboard; |
| 441 | if (keyboard && keyboard->focus) { |
| 442 | state = focus_state_create(seat); |
| 443 | if (state == NULL) |
| 444 | return; |
| 445 | |
| 446 | wl_list_insert(&ws->focus_list, &state->link); |
| 447 | |
| 448 | wl_keyboard_set_focus(seat->seat.keyboard, NULL); |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 454 | workspace_destroy(struct workspace *ws) |
| 455 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 456 | struct focus_state *state, *next; |
| 457 | |
| 458 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 459 | focus_state_destroy(state); |
| 460 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 461 | free(ws); |
| 462 | } |
| 463 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 464 | static void |
| 465 | seat_destroyed(struct wl_listener *listener, void *data) |
| 466 | { |
| 467 | struct weston_seat *seat = data; |
| 468 | struct focus_state *state, *next; |
| 469 | struct workspace *ws = container_of(listener, |
| 470 | struct workspace, |
| 471 | seat_destroyed_listener); |
| 472 | |
| 473 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 474 | if (state->seat == seat) |
| 475 | wl_list_remove(&state->link); |
| 476 | } |
| 477 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 478 | static struct workspace * |
| 479 | workspace_create(void) |
| 480 | { |
| 481 | struct workspace *ws = malloc(sizeof *ws); |
| 482 | if (ws == NULL) |
| 483 | return NULL; |
| 484 | |
| 485 | weston_layer_init(&ws->layer, NULL); |
| 486 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 487 | wl_list_init(&ws->focus_list); |
| 488 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 489 | ws->seat_destroyed_listener.notify = seat_destroyed; |
| 490 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 491 | return ws; |
| 492 | } |
| 493 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 494 | static int |
| 495 | workspace_is_empty(struct workspace *ws) |
| 496 | { |
| 497 | return wl_list_empty(&ws->layer.surface_list); |
| 498 | } |
| 499 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 500 | static struct workspace * |
| 501 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 502 | { |
| 503 | struct workspace **pws = shell->workspaces.array.data; |
| 504 | pws += index; |
| 505 | return *pws; |
| 506 | } |
| 507 | |
| 508 | static struct workspace * |
| 509 | get_current_workspace(struct desktop_shell *shell) |
| 510 | { |
| 511 | return get_workspace(shell, shell->workspaces.current); |
| 512 | } |
| 513 | |
| 514 | static void |
| 515 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 516 | { |
| 517 | struct workspace *ws; |
| 518 | |
| 519 | ws = get_workspace(shell, index); |
| 520 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 521 | |
| 522 | shell->workspaces.current = index; |
| 523 | } |
| 524 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 525 | static unsigned int |
| 526 | get_output_height(struct weston_output *output) |
| 527 | { |
| 528 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 529 | } |
| 530 | |
| 531 | static void |
| 532 | surface_translate(struct weston_surface *surface, double d) |
| 533 | { |
| 534 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 535 | struct weston_transform *transform; |
| 536 | |
| 537 | transform = &shsurf->workspace_transform; |
| 538 | if (wl_list_empty(&transform->link)) |
| 539 | wl_list_insert(surface->geometry.transformation_list.prev, |
| 540 | &shsurf->workspace_transform.link); |
| 541 | |
| 542 | weston_matrix_init(&shsurf->workspace_transform.matrix); |
| 543 | weston_matrix_translate(&shsurf->workspace_transform.matrix, |
| 544 | 0.0, d, 0.0); |
| 545 | surface->geometry.dirty = 1; |
| 546 | } |
| 547 | |
| 548 | static void |
| 549 | workspace_translate_out(struct workspace *ws, double fraction) |
| 550 | { |
| 551 | struct weston_surface *surface; |
| 552 | unsigned int height; |
| 553 | double d; |
| 554 | |
| 555 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
| 556 | height = get_output_height(surface->output); |
| 557 | d = height * fraction; |
| 558 | |
| 559 | surface_translate(surface, d); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | static void |
| 564 | workspace_translate_in(struct workspace *ws, double fraction) |
| 565 | { |
| 566 | struct weston_surface *surface; |
| 567 | unsigned int height; |
| 568 | double d; |
| 569 | |
| 570 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
| 571 | height = get_output_height(surface->output); |
| 572 | |
| 573 | if (fraction > 0) |
| 574 | d = -(height - height * fraction); |
| 575 | else |
| 576 | d = height + height * fraction; |
| 577 | |
| 578 | surface_translate(surface, d); |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | static void |
| 583 | workspace_damage_all_surfaces(struct workspace *ws) |
| 584 | { |
| 585 | struct weston_surface *surface; |
| 586 | |
| 587 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) |
| 588 | weston_surface_damage(surface); |
| 589 | } |
| 590 | |
| 591 | static void |
| 592 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 593 | unsigned int index, |
| 594 | struct workspace *from, |
| 595 | struct workspace *to) |
| 596 | { |
| 597 | shell->workspaces.current = index; |
| 598 | |
| 599 | shell->workspaces.anim_to = to; |
| 600 | shell->workspaces.anim_from = from; |
| 601 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 602 | shell->workspaces.anim_timestamp = 0; |
| 603 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 604 | push_focus_state(shell, from); |
| 605 | pop_focus_state(shell, to); |
| 606 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 607 | workspace_damage_all_surfaces(from); |
| 608 | workspace_damage_all_surfaces(to); |
| 609 | } |
| 610 | |
| 611 | static void |
| 612 | workspace_deactivate_transforms(struct workspace *ws) |
| 613 | { |
| 614 | struct weston_surface *surface; |
| 615 | struct shell_surface *shsurf; |
| 616 | |
| 617 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
| 618 | shsurf = get_shell_surface(surface); |
| 619 | wl_list_remove(&shsurf->workspace_transform.link); |
| 620 | wl_list_init(&shsurf->workspace_transform.link); |
| 621 | shsurf->surface->geometry.dirty = 1; |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | static void |
| 626 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 627 | struct workspace *from, |
| 628 | struct workspace *to) |
| 629 | { |
| 630 | workspace_damage_all_surfaces(from); |
| 631 | workspace_damage_all_surfaces(to); |
| 632 | |
| 633 | wl_list_remove(&shell->workspaces.animation.link); |
| 634 | workspace_deactivate_transforms(from); |
| 635 | workspace_deactivate_transforms(to); |
| 636 | shell->workspaces.anim_to = NULL; |
| 637 | |
| 638 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 639 | } |
| 640 | |
| 641 | static void |
| 642 | animate_workspace_change_frame(struct weston_animation *animation, |
| 643 | struct weston_output *output, uint32_t msecs) |
| 644 | { |
| 645 | struct desktop_shell *shell = |
| 646 | container_of(animation, struct desktop_shell, |
| 647 | workspaces.animation); |
| 648 | struct workspace *from = shell->workspaces.anim_from; |
| 649 | struct workspace *to = shell->workspaces.anim_to; |
| 650 | uint32_t t; |
| 651 | double x, y; |
| 652 | |
| 653 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 654 | finish_workspace_change_animation(shell, from, to); |
| 655 | return; |
| 656 | } |
| 657 | |
| 658 | if (shell->workspaces.anim_timestamp == 0) { |
| 659 | if (shell->workspaces.anim_current == 0.0) |
| 660 | shell->workspaces.anim_timestamp = msecs; |
| 661 | else |
| 662 | shell->workspaces.anim_timestamp = |
| 663 | msecs - |
| 664 | /* Invers of movement function 'y' below. */ |
| 665 | (asin(1.0 - shell->workspaces.anim_current) * |
| 666 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 667 | M_2_PI); |
| 668 | } |
| 669 | |
| 670 | t = msecs - shell->workspaces.anim_timestamp; |
| 671 | |
| 672 | /* |
| 673 | * x = [0, π/2] |
| 674 | * y(x) = sin(x) |
| 675 | */ |
| 676 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 677 | y = sin(x); |
| 678 | |
| 679 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
| 680 | workspace_damage_all_surfaces(from); |
| 681 | workspace_damage_all_surfaces(to); |
| 682 | |
| 683 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 684 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 685 | shell->workspaces.anim_current = y; |
| 686 | |
| 687 | workspace_damage_all_surfaces(from); |
| 688 | workspace_damage_all_surfaces(to); |
| 689 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 690 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 691 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | static void |
| 695 | animate_workspace_change(struct desktop_shell *shell, |
| 696 | unsigned int index, |
| 697 | struct workspace *from, |
| 698 | struct workspace *to) |
| 699 | { |
| 700 | struct weston_output *output; |
| 701 | |
| 702 | int dir; |
| 703 | |
| 704 | if (index > shell->workspaces.current) |
| 705 | dir = -1; |
| 706 | else |
| 707 | dir = 1; |
| 708 | |
| 709 | shell->workspaces.current = index; |
| 710 | |
| 711 | shell->workspaces.anim_dir = dir; |
| 712 | shell->workspaces.anim_from = from; |
| 713 | shell->workspaces.anim_to = to; |
| 714 | shell->workspaces.anim_current = 0.0; |
| 715 | shell->workspaces.anim_timestamp = 0; |
| 716 | |
| 717 | output = container_of(shell->compositor->output_list.next, |
| 718 | struct weston_output, link); |
| 719 | wl_list_insert(&output->animation_list, |
| 720 | &shell->workspaces.animation.link); |
| 721 | |
| 722 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 723 | |
| 724 | workspace_translate_in(to, 0); |
| 725 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 726 | push_focus_state(shell, from); |
| 727 | pop_focus_state(shell, to); |
| 728 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 729 | workspace_damage_all_surfaces(from); |
| 730 | workspace_damage_all_surfaces(to); |
| 731 | } |
| 732 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 733 | static void |
| 734 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 735 | { |
| 736 | struct workspace *from; |
| 737 | struct workspace *to; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 738 | |
| 739 | if (index == shell->workspaces.current) |
| 740 | return; |
| 741 | |
| 742 | /* Don't change workspace when there is any fullscreen surfaces. */ |
| 743 | if (!wl_list_empty(&shell->fullscreen_layer.surface_list)) |
| 744 | return; |
| 745 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 746 | from = get_current_workspace(shell); |
| 747 | to = get_workspace(shell, index); |
| 748 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 749 | if (shell->workspaces.anim_from == to && |
| 750 | shell->workspaces.anim_to == from) { |
| 751 | reverse_workspace_change_animation(shell, index, from, to); |
| 752 | return; |
| 753 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 754 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 755 | if (shell->workspaces.anim_to != NULL) |
| 756 | finish_workspace_change_animation(shell, |
| 757 | shell->workspaces.anim_from, |
| 758 | shell->workspaces.anim_to); |
| 759 | |
| 760 | if (workspace_is_empty(to) && workspace_is_empty(from)) { |
| 761 | shell->workspaces.current = index; |
| 762 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 763 | wl_list_remove(&from->layer.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 764 | |
| 765 | push_focus_state(shell, from); |
| 766 | pop_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 767 | } |
| 768 | else |
| 769 | animate_workspace_change(shell, index, from, to); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 770 | } |
| 771 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 772 | static void |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 773 | noop_grab_focus(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 774 | 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] | 775 | { |
| 776 | grab->focus = NULL; |
| 777 | } |
| 778 | |
| 779 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 780 | move_grab_motion(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 781 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 782 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 783 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 784 | struct wl_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 785 | struct shell_surface *shsurf = move->base.shsurf; |
| 786 | struct weston_surface *es; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 787 | int dx = wl_fixed_to_int(pointer->x + move->dx); |
| 788 | int dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 789 | |
| 790 | if (!shsurf) |
| 791 | return; |
| 792 | |
| 793 | es = shsurf->surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 794 | |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 795 | weston_surface_configure(es, dx, dy, |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 796 | es->geometry.width, es->geometry.height); |
Kristian Høgsberg | 6c6fb99 | 2012-06-21 12:06:22 -0400 | [diff] [blame] | 797 | |
| 798 | weston_compositor_schedule_repaint(es->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 802 | move_grab_button(struct wl_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 803 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 804 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 805 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 806 | grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 807 | struct wl_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 808 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 809 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 810 | if (pointer->button_count == 0 && |
| 811 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 812 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 813 | free(grab); |
| 814 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 815 | } |
| 816 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 817 | static const struct wl_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 818 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 819 | move_grab_motion, |
| 820 | move_grab_button, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 821 | }; |
| 822 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 823 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 824 | busy_cursor_grab_focus(struct wl_pointer_grab *base, |
| 825 | struct wl_surface *surface, int32_t x, int32_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 826 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 827 | struct shell_grab *grab = (struct shell_grab *) base; |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 828 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 829 | if (grab->grab.focus != surface) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 830 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 831 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | |
| 835 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 836 | busy_cursor_grab_motion(struct wl_pointer_grab *grab, |
| 837 | uint32_t time, int32_t x, int32_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 838 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 839 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 840 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 841 | static void |
| 842 | busy_cursor_grab_button(struct wl_pointer_grab *grab, |
| 843 | uint32_t time, uint32_t button, uint32_t state) |
| 844 | { |
| 845 | } |
| 846 | |
| 847 | static const struct wl_pointer_grab_interface busy_cursor_grab_interface = { |
| 848 | busy_cursor_grab_focus, |
| 849 | busy_cursor_grab_motion, |
| 850 | busy_cursor_grab_button, |
| 851 | }; |
| 852 | |
| 853 | static void |
| 854 | set_busy_cursor(struct shell_surface *shsurf, struct wl_pointer *pointer) |
| 855 | { |
| 856 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 857 | |
| 858 | grab = malloc(sizeof *grab); |
| 859 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 860 | return; |
| 861 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 862 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 863 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 864 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 865 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 866 | static void |
| 867 | end_busy_cursor(struct shell_surface *shsurf, struct wl_pointer *pointer) |
| 868 | { |
| 869 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 870 | |
| 871 | if (grab->grab.interface == &busy_cursor_grab_interface) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 872 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 873 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 874 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 875 | } |
| 876 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 877 | static void |
| 878 | ping_timer_destroy(struct shell_surface *shsurf) |
| 879 | { |
| 880 | if (!shsurf || !shsurf->ping_timer) |
| 881 | return; |
| 882 | |
| 883 | if (shsurf->ping_timer->source) |
| 884 | wl_event_source_remove(shsurf->ping_timer->source); |
| 885 | |
| 886 | free(shsurf->ping_timer); |
| 887 | shsurf->ping_timer = NULL; |
| 888 | } |
| 889 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 890 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 891 | ping_timeout_handler(void *data) |
| 892 | { |
| 893 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 894 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 895 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 896 | /* Client is not responding */ |
| 897 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 898 | |
| 899 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
| 900 | if (seat->seat.pointer->focus == &shsurf->surface->surface) |
| 901 | set_busy_cursor(shsurf, seat->seat.pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 902 | |
| 903 | return 1; |
| 904 | } |
| 905 | |
| 906 | static void |
| 907 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 908 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 909 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 910 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 911 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 912 | |
| 913 | if (!shsurf) |
| 914 | return; |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 915 | if (!shsurf->resource.client) |
| 916 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 917 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 918 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 919 | return; |
| 920 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 921 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 922 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 923 | if (!shsurf->ping_timer) |
| 924 | return; |
| 925 | |
| 926 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 927 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 928 | shsurf->ping_timer->source = |
| 929 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 930 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 931 | |
| 932 | wl_shell_surface_send_ping(&shsurf->resource, serial); |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 937 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 938 | { |
| 939 | struct wl_pointer *pointer = data; |
| 940 | struct weston_surface *surface = |
| 941 | (struct weston_surface *) pointer->focus; |
| 942 | struct weston_compositor *compositor; |
| 943 | struct shell_surface *shsurf; |
| 944 | uint32_t serial; |
| 945 | |
| 946 | if (!surface) |
| 947 | return; |
| 948 | |
| 949 | compositor = surface->compositor; |
| 950 | shsurf = get_shell_surface(surface); |
| 951 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 952 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 953 | set_busy_cursor(shsurf, pointer); |
| 954 | } else { |
| 955 | serial = wl_display_next_serial(compositor->wl_display); |
| 956 | ping_handler(surface, serial); |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | static void |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 961 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 962 | uint32_t serial) |
| 963 | { |
| 964 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 965 | struct desktop_shell *shell = shsurf->shell; |
| 966 | struct weston_seat *seat; |
| 967 | struct weston_compositor *ec = shsurf->surface->compositor; |
| 968 | struct wl_pointer *pointer; |
| 969 | int was_unresponsive; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 970 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 971 | if (shsurf->ping_timer->serial == serial) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 972 | was_unresponsive = shsurf->unresponsive; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 973 | shsurf->unresponsive = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 974 | if (was_unresponsive) { |
| 975 | /* Received pong from previously unresponsive client */ |
| 976 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 977 | pointer = seat->seat.pointer; |
| 978 | if (pointer->focus == |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 979 | &shell->grab_surface->surface && |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 980 | pointer->current == |
| 981 | &shsurf->surface->surface) |
| 982 | end_busy_cursor(shsurf, pointer); |
| 983 | } |
| 984 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 985 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 986 | } |
| 987 | } |
| 988 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 989 | static void |
| 990 | shell_surface_set_title(struct wl_client *client, |
| 991 | struct wl_resource *resource, const char *title) |
| 992 | { |
| 993 | struct shell_surface *shsurf = resource->data; |
| 994 | |
| 995 | free(shsurf->title); |
| 996 | shsurf->title = strdup(title); |
| 997 | } |
| 998 | |
| 999 | static void |
| 1000 | shell_surface_set_class(struct wl_client *client, |
| 1001 | struct wl_resource *resource, const char *class) |
| 1002 | { |
| 1003 | struct shell_surface *shsurf = resource->data; |
| 1004 | |
| 1005 | free(shsurf->class); |
| 1006 | shsurf->class = strdup(class); |
| 1007 | } |
| 1008 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1009 | static int |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 1010 | surface_move(struct shell_surface *shsurf, struct weston_seat *ws) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1011 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1012 | struct weston_move_grab *move; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1013 | |
| 1014 | if (!shsurf) |
| 1015 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1016 | |
Ander Conselvan de Oliveira | 00d17bb | 2012-06-28 18:08:06 +0300 | [diff] [blame] | 1017 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1018 | return 0; |
| 1019 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1020 | move = malloc(sizeof *move); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1021 | if (!move) |
| 1022 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1023 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 1024 | move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) - |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1025 | ws->seat.pointer->grab_x; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 1026 | move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) - |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1027 | ws->seat.pointer->grab_y; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1028 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1029 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
| 1030 | ws->seat.pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1031 | |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
| 1035 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1036 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1037 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1038 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1039 | struct weston_seat *ws = seat_resource->data; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1040 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1041 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1042 | if (ws->seat.pointer->button_count == 0 || |
| 1043 | ws->seat.pointer->grab_serial != serial || |
| 1044 | ws->seat.pointer->focus != &shsurf->surface->surface) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1045 | return; |
| 1046 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 1047 | if (surface_move(shsurf, ws) < 0) |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 1048 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1049 | } |
| 1050 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1051 | struct weston_resize_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1052 | struct shell_grab base; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1053 | uint32_t edges; |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 1054 | int32_t width, height; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1055 | }; |
| 1056 | |
| 1057 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1058 | resize_grab_motion(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1059 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1060 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1061 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1062 | struct wl_pointer *pointer = grab->pointer; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1063 | struct shell_surface *shsurf = resize->base.shsurf; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1064 | int32_t width, height; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1065 | wl_fixed_t from_x, from_y; |
| 1066 | wl_fixed_t to_x, to_y; |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 1067 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1068 | if (!shsurf) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1069 | return; |
| 1070 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1071 | weston_surface_from_global_fixed(shsurf->surface, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1072 | pointer->grab_x, pointer->grab_y, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1073 | &from_x, &from_y); |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1074 | weston_surface_from_global_fixed(shsurf->surface, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1075 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1076 | |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1077 | width = resize->width; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1078 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1079 | width += wl_fixed_to_int(from_x - to_x); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1080 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1081 | width += wl_fixed_to_int(to_x - from_x); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1082 | } |
| 1083 | |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1084 | height = resize->height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1085 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1086 | height += wl_fixed_to_int(from_y - to_y); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1087 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1088 | height += wl_fixed_to_int(to_y - from_y); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1089 | } |
| 1090 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1091 | shsurf->client->send_configure(shsurf->surface, |
| 1092 | resize->edges, width, height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | static void |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1096 | send_configure(struct weston_surface *surface, |
| 1097 | uint32_t edges, int32_t width, int32_t height) |
| 1098 | { |
| 1099 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1100 | |
| 1101 | wl_shell_surface_send_configure(&shsurf->resource, |
| 1102 | edges, width, height); |
| 1103 | } |
| 1104 | |
| 1105 | static const struct weston_shell_client shell_client = { |
| 1106 | send_configure |
| 1107 | }; |
| 1108 | |
| 1109 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1110 | resize_grab_button(struct wl_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1111 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1112 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1113 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1114 | struct wl_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1115 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1116 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1117 | if (pointer->button_count == 0 && |
| 1118 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1119 | shell_grab_end(&resize->base); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1120 | free(grab); |
| 1121 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1122 | } |
| 1123 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1124 | static const struct wl_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1125 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1126 | resize_grab_motion, |
| 1127 | resize_grab_button, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1128 | }; |
| 1129 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1130 | static int |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 1131 | surface_resize(struct shell_surface *shsurf, |
| 1132 | struct weston_seat *ws, uint32_t edges) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1133 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1134 | struct weston_resize_grab *resize; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1135 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1136 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1137 | return 0; |
Kristian Høgsberg | 0ce2457 | 2011-01-28 15:18:33 -0500 | [diff] [blame] | 1138 | |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 1139 | if (edges == 0 || edges > 15 || |
| 1140 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1141 | return 0; |
| 1142 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1143 | resize = malloc(sizeof *resize); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1144 | if (!resize) |
| 1145 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1146 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1147 | resize->edges = edges; |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 1148 | resize->width = shsurf->surface->geometry.width; |
| 1149 | resize->height = shsurf->surface->geometry.height; |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1150 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1151 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
| 1152 | ws->seat.pointer, edges); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1153 | |
| 1154 | return 0; |
| 1155 | } |
| 1156 | |
| 1157 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1158 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1159 | struct wl_resource *seat_resource, uint32_t serial, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1160 | uint32_t edges) |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1161 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1162 | struct weston_seat *ws = seat_resource->data; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1163 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1164 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1165 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1166 | return; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1167 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1168 | if (ws->seat.pointer->button_count == 0 || |
| 1169 | ws->seat.pointer->grab_serial != serial || |
| 1170 | ws->seat.pointer->focus != &shsurf->surface->surface) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1171 | return; |
| 1172 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 1173 | if (surface_resize(shsurf, ws, edges) < 0) |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 1174 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1175 | } |
| 1176 | |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1177 | static struct weston_output * |
| 1178 | get_default_output(struct weston_compositor *compositor) |
| 1179 | { |
| 1180 | return container_of(compositor->output_list.next, |
| 1181 | struct weston_output, link); |
| 1182 | } |
| 1183 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1184 | static void |
| 1185 | shell_unset_fullscreen(struct shell_surface *shsurf) |
| 1186 | { |
| 1187 | /* undo all fullscreen things here */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1188 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 1189 | shell_surface_is_top_fullscreen(shsurf)) { |
| 1190 | weston_output_switch_mode(shsurf->fullscreen_output, |
| 1191 | shsurf->fullscreen_output->origin); |
| 1192 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1193 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 1194 | shsurf->fullscreen.framerate = 0; |
| 1195 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 1196 | wl_list_init(&shsurf->fullscreen.transform.link); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1197 | if (shsurf->fullscreen.black_surface) |
| 1198 | weston_surface_destroy(shsurf->fullscreen.black_surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1199 | shsurf->fullscreen.black_surface = NULL; |
| 1200 | shsurf->fullscreen_output = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1201 | weston_surface_set_position(shsurf->surface, |
| 1202 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 1203 | if (shsurf->saved_rotation_valid) { |
| 1204 | wl_list_insert(&shsurf->surface->geometry.transformation_list, |
| 1205 | &shsurf->rotation.transform.link); |
| 1206 | shsurf->saved_rotation_valid = false; |
| 1207 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1208 | } |
| 1209 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1210 | static int |
| 1211 | reset_shell_surface_type(struct shell_surface *surface) |
| 1212 | { |
| 1213 | switch (surface->type) { |
| 1214 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1215 | shell_unset_fullscreen(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1216 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1217 | case SHELL_SURFACE_MAXIMIZED: |
| 1218 | surface->output = get_default_output(surface->surface->compositor); |
| 1219 | weston_surface_set_position(surface->surface, |
| 1220 | surface->saved_x, |
| 1221 | surface->saved_y); |
| 1222 | break; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1223 | case SHELL_SURFACE_NONE: |
| 1224 | case SHELL_SURFACE_TOPLEVEL: |
| 1225 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1226 | case SHELL_SURFACE_POPUP: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1227 | break; |
| 1228 | } |
| 1229 | |
| 1230 | surface->type = SHELL_SURFACE_NONE; |
| 1231 | return 0; |
| 1232 | } |
| 1233 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1234 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1235 | set_surface_type(struct shell_surface *shsurf) |
| 1236 | { |
| 1237 | struct weston_surface *surface = shsurf->surface; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1238 | struct weston_surface *pes = shsurf->parent; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1239 | |
| 1240 | reset_shell_surface_type(shsurf); |
| 1241 | |
| 1242 | shsurf->type = shsurf->next_type; |
| 1243 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 1244 | |
| 1245 | switch (shsurf->type) { |
| 1246 | case SHELL_SURFACE_TOPLEVEL: |
| 1247 | break; |
| 1248 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1249 | weston_surface_set_position(surface, |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 1250 | pes->geometry.x + shsurf->transient.x, |
| 1251 | pes->geometry.y + shsurf->transient.y); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1252 | break; |
| 1253 | |
| 1254 | case SHELL_SURFACE_MAXIMIZED: |
| 1255 | shsurf->saved_x = surface->geometry.x; |
| 1256 | shsurf->saved_y = surface->geometry.y; |
| 1257 | shsurf->saved_position_valid = true; |
| 1258 | break; |
| 1259 | |
| 1260 | case SHELL_SURFACE_FULLSCREEN: |
| 1261 | shsurf->saved_x = surface->geometry.x; |
| 1262 | shsurf->saved_y = surface->geometry.y; |
| 1263 | shsurf->saved_position_valid = true; |
| 1264 | |
| 1265 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 1266 | wl_list_remove(&shsurf->rotation.transform.link); |
| 1267 | wl_list_init(&shsurf->rotation.transform.link); |
| 1268 | shsurf->surface->geometry.dirty = 1; |
| 1269 | shsurf->saved_rotation_valid = true; |
| 1270 | } |
| 1271 | break; |
| 1272 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1273 | default: |
| 1274 | break; |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1279 | set_toplevel(struct shell_surface *shsurf) |
| 1280 | { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1281 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1285 | shell_surface_set_toplevel(struct wl_client *client, |
| 1286 | struct wl_resource *resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1287 | { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1288 | struct shell_surface *surface = resource->data; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1289 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1290 | set_toplevel(surface); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | static void |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 1294 | set_transient(struct shell_surface *shsurf, |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1295 | struct weston_surface *parent, int x, int y, uint32_t flags) |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 1296 | { |
| 1297 | /* assign to parents output */ |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1298 | shsurf->parent = parent; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 1299 | shsurf->transient.x = x; |
| 1300 | shsurf->transient.y = y; |
| 1301 | shsurf->transient.flags = flags; |
| 1302 | shsurf->next_type = SHELL_SURFACE_TRANSIENT; |
| 1303 | } |
| 1304 | |
| 1305 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1306 | shell_surface_set_transient(struct wl_client *client, |
| 1307 | struct wl_resource *resource, |
| 1308 | struct wl_resource *parent_resource, |
| 1309 | int x, int y, uint32_t flags) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1310 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1311 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1312 | struct weston_surface *parent = parent_resource->data; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1313 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1314 | set_transient(shsurf, parent, x, y, flags); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1315 | } |
| 1316 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1317 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1318 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 1319 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 1320 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | static int |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1324 | get_output_panel_height(struct desktop_shell *shell, |
| 1325 | struct weston_output *output) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1326 | { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1327 | struct weston_surface *surface; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1328 | int panel_height = 0; |
| 1329 | |
| 1330 | if (!output) |
| 1331 | return 0; |
| 1332 | |
Juan Zhao | 4ab9468 | 2012-07-09 22:24:09 -0700 | [diff] [blame] | 1333 | 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] | 1334 | if (surface->output == output) { |
| 1335 | panel_height = surface->geometry.height; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1336 | break; |
| 1337 | } |
| 1338 | } |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1339 | |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1340 | return panel_height; |
| 1341 | } |
| 1342 | |
| 1343 | static void |
| 1344 | shell_surface_set_maximized(struct wl_client *client, |
| 1345 | struct wl_resource *resource, |
| 1346 | struct wl_resource *output_resource ) |
| 1347 | { |
| 1348 | struct shell_surface *shsurf = resource->data; |
| 1349 | struct weston_surface *es = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1350 | struct desktop_shell *shell = NULL; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1351 | uint32_t edges = 0, panel_height = 0; |
| 1352 | |
| 1353 | /* get the default output, if the client set it as NULL |
| 1354 | check whether the ouput is available */ |
| 1355 | if (output_resource) |
| 1356 | shsurf->output = output_resource->data; |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 1357 | else if (es->output) |
| 1358 | shsurf->output = es->output; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1359 | else |
| 1360 | shsurf->output = get_default_output(es->compositor); |
| 1361 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1362 | shell = shell_surface_get_shell(shsurf); |
Rob Bradford | 31b6862 | 2012-07-02 19:00:19 +0100 | [diff] [blame] | 1363 | panel_height = get_output_panel_height(shell, shsurf->output); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1364 | edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT; |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1365 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1366 | shsurf->client->send_configure(shsurf->surface, edges, |
Rob Bradford | 31b6862 | 2012-07-02 19:00:19 +0100 | [diff] [blame] | 1367 | shsurf->output->current->width, |
| 1368 | shsurf->output->current->height - panel_height); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1369 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1370 | shsurf->next_type = SHELL_SURFACE_MAXIMIZED; |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 1371 | } |
| 1372 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1373 | static void |
| 1374 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy); |
| 1375 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1376 | static struct weston_surface * |
| 1377 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1378 | struct weston_surface *fs_surface, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1379 | GLfloat x, GLfloat y, int w, int h) |
| 1380 | { |
| 1381 | struct weston_surface *surface = NULL; |
| 1382 | |
| 1383 | surface = weston_surface_create(ec); |
| 1384 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1385 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1386 | return NULL; |
| 1387 | } |
| 1388 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1389 | surface->configure = black_surface_configure; |
| 1390 | surface->private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1391 | weston_surface_configure(surface, x, y, w, h); |
| 1392 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
| 1393 | return surface; |
| 1394 | } |
| 1395 | |
| 1396 | /* Create black surface and append it to the associated fullscreen surface. |
| 1397 | * Handle size dismatch and positioning according to the method. */ |
| 1398 | static void |
| 1399 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 1400 | { |
| 1401 | struct weston_output *output = shsurf->fullscreen_output; |
| 1402 | struct weston_surface *surface = shsurf->surface; |
| 1403 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1404 | float scale, output_aspect, surface_aspect, x, y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1405 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1406 | if (!shsurf->fullscreen.black_surface) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1407 | shsurf->fullscreen.black_surface = |
| 1408 | create_black_surface(surface->compositor, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1409 | surface, |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1410 | output->x, output->y, |
| 1411 | output->current->width, |
| 1412 | output->current->height); |
| 1413 | |
| 1414 | wl_list_remove(&shsurf->fullscreen.black_surface->layer_link); |
| 1415 | wl_list_insert(&surface->layer_link, |
| 1416 | &shsurf->fullscreen.black_surface->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1417 | shsurf->fullscreen.black_surface->output = output; |
| 1418 | |
| 1419 | switch (shsurf->fullscreen.type) { |
| 1420 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Kristian Høgsberg | a08b528 | 2012-07-20 15:30:36 -0400 | [diff] [blame] | 1421 | if (surface->buffer) |
| 1422 | center_on_output(surface, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1423 | break; |
| 1424 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
| 1425 | matrix = &shsurf->fullscreen.transform.matrix; |
| 1426 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1427 | |
| 1428 | output_aspect = (float) output->current->width / |
| 1429 | (float) output->current->height; |
| 1430 | surface_aspect = (float) surface->geometry.width / |
| 1431 | (float) surface->geometry.height; |
| 1432 | if (output_aspect < surface_aspect) |
| 1433 | scale = (float) output->current->width / |
| 1434 | (float) surface->geometry.width; |
| 1435 | else |
| 1436 | scale = (float) output->current->height / |
| 1437 | (float) surface->geometry.height; |
| 1438 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1439 | weston_matrix_scale(matrix, scale, scale, 1); |
| 1440 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1441 | wl_list_insert(&surface->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1442 | &shsurf->fullscreen.transform.link); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1443 | x = output->x + (output->current->width - surface->geometry.width * scale) / 2; |
| 1444 | y = output->y + (output->current->height - surface->geometry.height * scale) / 2; |
| 1445 | weston_surface_set_position(surface, x, y); |
| 1446 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1447 | break; |
| 1448 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1449 | if (shell_surface_is_top_fullscreen(shsurf)) { |
| 1450 | struct weston_mode mode = {0, |
| 1451 | surface->geometry.width, |
| 1452 | surface->geometry.height, |
| 1453 | shsurf->fullscreen.framerate}; |
| 1454 | |
| 1455 | if (weston_output_switch_mode(output, &mode) == 0) { |
| 1456 | weston_surface_configure(shsurf->fullscreen.black_surface, |
| 1457 | output->x, output->y, |
| 1458 | output->current->width, |
| 1459 | output->current->height); |
| 1460 | weston_surface_set_position(surface, output->x, output->y); |
| 1461 | break; |
| 1462 | } |
| 1463 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1464 | break; |
| 1465 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
| 1466 | break; |
| 1467 | default: |
| 1468 | break; |
| 1469 | } |
| 1470 | } |
| 1471 | |
| 1472 | /* make the fullscreen and black surface at the top */ |
| 1473 | static void |
| 1474 | shell_stack_fullscreen(struct shell_surface *shsurf) |
| 1475 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1476 | struct weston_output *output = shsurf->fullscreen_output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1477 | struct weston_surface *surface = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1478 | struct desktop_shell *shell = shell_surface_get_shell(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1479 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1480 | wl_list_remove(&surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1481 | wl_list_insert(&shell->fullscreen_layer.surface_list, |
| 1482 | &surface->layer_link); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1483 | weston_surface_damage(surface); |
| 1484 | |
| 1485 | if (!shsurf->fullscreen.black_surface) |
| 1486 | shsurf->fullscreen.black_surface = |
| 1487 | create_black_surface(surface->compositor, |
| 1488 | surface, |
| 1489 | output->x, output->y, |
| 1490 | output->current->width, |
| 1491 | output->current->height); |
| 1492 | |
| 1493 | wl_list_remove(&shsurf->fullscreen.black_surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1494 | wl_list_insert(&surface->layer_link, |
| 1495 | &shsurf->fullscreen.black_surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1496 | weston_surface_damage(shsurf->fullscreen.black_surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | static void |
| 1500 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 1501 | { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1502 | shell_stack_fullscreen(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1503 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1504 | } |
| 1505 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1506 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1507 | shell_surface_set_fullscreen(struct wl_client *client, |
Kristian Høgsberg | f856fd2 | 2012-02-16 15:58:14 -0500 | [diff] [blame] | 1508 | struct wl_resource *resource, |
| 1509 | uint32_t method, |
| 1510 | uint32_t framerate, |
| 1511 | struct wl_resource *output_resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1512 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1513 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1514 | struct weston_surface *es = shsurf->surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1515 | |
| 1516 | if (output_resource) |
| 1517 | shsurf->output = output_resource->data; |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 1518 | else if (es->output) |
| 1519 | shsurf->output = es->output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1520 | else |
| 1521 | shsurf->output = get_default_output(es->compositor); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1522 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1523 | shsurf->fullscreen_output = shsurf->output; |
| 1524 | shsurf->fullscreen.type = method; |
| 1525 | shsurf->fullscreen.framerate = framerate; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1526 | shsurf->next_type = SHELL_SURFACE_FULLSCREEN; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1527 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1528 | shsurf->client->send_configure(shsurf->surface, 0, |
| 1529 | shsurf->output->current->width, |
| 1530 | shsurf->output->current->height); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1531 | } |
| 1532 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1533 | static void |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1534 | popup_grab_focus(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1535 | struct wl_surface *surface, |
| 1536 | wl_fixed_t x, |
| 1537 | wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1538 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1539 | struct wl_pointer *pointer = grab->pointer; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1540 | struct shell_surface *priv = |
| 1541 | container_of(grab, struct shell_surface, popup.grab); |
| 1542 | struct wl_client *client = priv->surface->surface.resource.client; |
| 1543 | |
Pekka Paalanen | cb10843 | 2012-01-19 16:25:40 +0200 | [diff] [blame] | 1544 | if (surface && surface->resource.client == client) { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1545 | wl_pointer_set_focus(pointer, surface, x, y); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1546 | grab->focus = surface; |
| 1547 | } else { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1548 | wl_pointer_set_focus(pointer, NULL, |
| 1549 | wl_fixed_from_int(0), |
| 1550 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1551 | grab->focus = NULL; |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1556 | popup_grab_motion(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1557 | uint32_t time, wl_fixed_t sx, wl_fixed_t sy) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1558 | { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1559 | struct wl_resource *resource; |
| 1560 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1561 | resource = grab->pointer->focus_resource; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1562 | if (resource) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1563 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1567 | popup_grab_button(struct wl_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1568 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1569 | { |
| 1570 | struct wl_resource *resource; |
| 1571 | struct shell_surface *shsurf = |
| 1572 | container_of(grab, struct shell_surface, popup.grab); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1573 | struct wl_display *display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1574 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1575 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1576 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1577 | resource = grab->pointer->focus_resource; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1578 | if (resource) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1579 | display = wl_client_get_display(resource->client); |
| 1580 | serial = wl_display_get_serial(display); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1581 | wl_pointer_send_button(resource, serial, time, button, state); |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1582 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1583 | (shsurf->popup.initial_up || |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1584 | time - shsurf->popup.seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1585 | wl_shell_surface_send_popup_done(&shsurf->resource); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1586 | wl_pointer_end_grab(grab->pointer); |
| 1587 | shsurf->popup.grab.pointer = NULL; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1588 | } |
| 1589 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1590 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1591 | shsurf->popup.initial_up = 1; |
| 1592 | } |
| 1593 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1594 | static const struct wl_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1595 | popup_grab_focus, |
| 1596 | popup_grab_motion, |
| 1597 | popup_grab_button, |
| 1598 | }; |
| 1599 | |
| 1600 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1601 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1602 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1603 | struct wl_seat *seat = shsurf->popup.seat; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1604 | struct weston_surface *es = shsurf->surface; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1605 | struct weston_surface *parent = shsurf->parent; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1606 | |
| 1607 | es->output = parent->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1608 | shsurf->popup.grab.interface = &popup_grab_interface; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1609 | |
Pekka Paalanen | 938269a | 2012-02-07 14:19:01 +0200 | [diff] [blame] | 1610 | weston_surface_update_transform(parent); |
| 1611 | if (parent->transform.enabled) { |
| 1612 | shsurf->popup.parent_transform.matrix = |
| 1613 | parent->transform.matrix; |
| 1614 | } else { |
| 1615 | /* construct x, y translation matrix */ |
| 1616 | weston_matrix_init(&shsurf->popup.parent_transform.matrix); |
| 1617 | shsurf->popup.parent_transform.matrix.d[12] = |
| 1618 | parent->geometry.x; |
| 1619 | shsurf->popup.parent_transform.matrix.d[13] = |
| 1620 | parent->geometry.y; |
| 1621 | } |
| 1622 | wl_list_insert(es->geometry.transformation_list.prev, |
| 1623 | &shsurf->popup.parent_transform.link); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1624 | weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1625 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1626 | shsurf->popup.initial_up = 0; |
| 1627 | |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1628 | /* We don't require the grab to still be active, but if another |
| 1629 | * grab has started in the meantime, we end the popup now. */ |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1630 | if (seat->pointer->grab_serial == shsurf->popup.serial) { |
| 1631 | wl_pointer_start_grab(seat->pointer, &shsurf->popup.grab); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1632 | } else { |
| 1633 | wl_shell_surface_send_popup_done(&shsurf->resource); |
| 1634 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | static void |
| 1638 | shell_surface_set_popup(struct wl_client *client, |
| 1639 | struct wl_resource *resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1640 | struct wl_resource *seat_resource, |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1641 | uint32_t serial, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1642 | struct wl_resource *parent_resource, |
| 1643 | int32_t x, int32_t y, uint32_t flags) |
| 1644 | { |
| 1645 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1646 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1647 | shsurf->type = SHELL_SURFACE_POPUP; |
| 1648 | shsurf->parent = parent_resource->data; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1649 | shsurf->popup.seat = seat_resource->data; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1650 | shsurf->popup.serial = serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1651 | shsurf->popup.x = x; |
| 1652 | shsurf->popup.y = y; |
| 1653 | } |
| 1654 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1655 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1656 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1657 | shell_surface_move, |
| 1658 | shell_surface_resize, |
| 1659 | shell_surface_set_toplevel, |
| 1660 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1661 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1662 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1663 | shell_surface_set_maximized, |
| 1664 | shell_surface_set_title, |
| 1665 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1666 | }; |
| 1667 | |
| 1668 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1669 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1670 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1671 | if (shsurf->popup.grab.pointer) |
| 1672 | wl_pointer_end_grab(shsurf->popup.grab.pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1673 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1674 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 1675 | shell_surface_is_top_fullscreen(shsurf)) { |
| 1676 | weston_output_switch_mode(shsurf->fullscreen_output, |
| 1677 | shsurf->fullscreen_output->origin); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1678 | } |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1679 | |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 1680 | if (shsurf->fullscreen.black_surface) |
| 1681 | weston_surface_destroy(shsurf->fullscreen.black_surface); |
| 1682 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1683 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 1684 | * we can always remove the listener. |
| 1685 | */ |
| 1686 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 1687 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1688 | ping_timer_destroy(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1689 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1690 | wl_list_remove(&shsurf->link); |
| 1691 | free(shsurf); |
| 1692 | } |
| 1693 | |
| 1694 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1695 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 1696 | { |
| 1697 | struct shell_surface *shsurf = resource->data; |
| 1698 | |
| 1699 | destroy_shell_surface(shsurf); |
| 1700 | } |
| 1701 | |
| 1702 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1703 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1704 | { |
| 1705 | struct shell_surface *shsurf = container_of(listener, |
| 1706 | struct shell_surface, |
| 1707 | surface_destroy_listener); |
| 1708 | |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 1709 | if (shsurf->resource.client) { |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1710 | wl_resource_destroy(&shsurf->resource); |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 1711 | } else { |
| 1712 | wl_signal_emit(&shsurf->resource.destroy_signal, |
| 1713 | &shsurf->resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1714 | destroy_shell_surface(shsurf); |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 1715 | } |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1716 | } |
| 1717 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 1718 | static void |
| 1719 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
| 1720 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1721 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1722 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1723 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 1724 | if (surface->configure == shell_surface_configure) |
| 1725 | return surface->private; |
| 1726 | else |
| 1727 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1728 | } |
| 1729 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 1730 | static struct shell_surface * |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1731 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 1732 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1733 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1734 | struct shell_surface *shsurf; |
| 1735 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1736 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1737 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 1738 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1739 | } |
| 1740 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1741 | shsurf = calloc(1, sizeof *shsurf); |
| 1742 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1743 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 1744 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1745 | } |
| 1746 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1747 | surface->configure = shell_surface_configure; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 1748 | surface->private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1749 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1750 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1751 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1752 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 1753 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1754 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1755 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 1756 | shsurf->fullscreen.framerate = 0; |
| 1757 | shsurf->fullscreen.black_surface = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1758 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1759 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 1760 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1761 | wl_signal_init(&shsurf->resource.destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1762 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
| 1763 | wl_signal_add(&surface->surface.resource.destroy_signal, |
| 1764 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1765 | |
| 1766 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 1767 | wl_list_init(&shsurf->link); |
| 1768 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1769 | /* empty when not in use */ |
| 1770 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1771 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1772 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1773 | wl_list_init(&shsurf->workspace_transform.link); |
| 1774 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1775 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1776 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1777 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1778 | shsurf->client = client; |
| 1779 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 1780 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | static void |
| 1784 | shell_get_shell_surface(struct wl_client *client, |
| 1785 | struct wl_resource *resource, |
| 1786 | uint32_t id, |
| 1787 | struct wl_resource *surface_resource) |
| 1788 | { |
| 1789 | struct weston_surface *surface = surface_resource->data; |
| 1790 | struct desktop_shell *shell = resource->data; |
| 1791 | struct shell_surface *shsurf; |
| 1792 | |
| 1793 | if (get_shell_surface(surface)) { |
| 1794 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 1795 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1796 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1797 | return; |
| 1798 | } |
| 1799 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1800 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 1801 | if (!shsurf) { |
| 1802 | wl_resource_post_error(surface_resource, |
| 1803 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1804 | "surface->configure already set"); |
| 1805 | return; |
| 1806 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1807 | |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 1808 | shsurf->resource.destroy = shell_destroy_shell_surface; |
| 1809 | shsurf->resource.object.id = id; |
| 1810 | shsurf->resource.object.interface = &wl_shell_surface_interface; |
| 1811 | shsurf->resource.object.implementation = |
| 1812 | (void (**)(void)) &shell_surface_implementation; |
| 1813 | shsurf->resource.data = shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1814 | |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 1815 | wl_client_add_resource(client, &shsurf->resource); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 1819 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1820 | }; |
| 1821 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1822 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1823 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1824 | { |
| 1825 | proc->pid = 0; |
| 1826 | } |
| 1827 | |
| 1828 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1829 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1830 | { |
| 1831 | if (shell->screensaver.binding) |
| 1832 | return; |
| 1833 | |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1834 | if (!shell->screensaver.path) |
| 1835 | return; |
| 1836 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 1837 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1838 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 1839 | return; |
| 1840 | } |
| 1841 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1842 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1843 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1844 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1845 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1849 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1850 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1851 | if (shell->screensaver.process.pid == 0) |
| 1852 | return; |
| 1853 | |
| 1854 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | static void |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1858 | configure_static_surface(struct weston_surface *es, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1859 | { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1860 | struct weston_surface *s, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1861 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1862 | wl_list_for_each_safe(s, next, &layer->surface_list, layer_link) { |
| 1863 | if (s->output == es->output && s != es) { |
| 1864 | weston_surface_unmap(s); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1865 | s->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | weston_surface_configure(es, es->output->x, es->output->y, |
| 1870 | es->buffer->width, es->buffer->height); |
| 1871 | |
| 1872 | if (wl_list_empty(&es->layer_link)) { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1873 | wl_list_insert(&layer->surface_list, &es->layer_link); |
Kristian Høgsberg | c7cd626 | 2012-06-28 13:46:09 -0400 | [diff] [blame] | 1874 | weston_compositor_schedule_repaint(es->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | static void |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1879 | background_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 1880 | { |
| 1881 | struct desktop_shell *shell = es->private; |
| 1882 | |
| 1883 | configure_static_surface(es, &shell->background_layer); |
| 1884 | } |
| 1885 | |
| 1886 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1887 | desktop_shell_set_background(struct wl_client *client, |
| 1888 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1889 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1890 | struct wl_resource *surface_resource) |
| 1891 | { |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1892 | struct desktop_shell *shell = resource->data; |
| 1893 | struct weston_surface *surface = surface_resource->data; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1894 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1895 | if (surface->configure) { |
| 1896 | wl_resource_post_error(surface_resource, |
| 1897 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1898 | "surface role already assigned"); |
| 1899 | return; |
| 1900 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1901 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1902 | surface->configure = background_configure; |
| 1903 | surface->private = shell; |
| 1904 | surface->output = output_resource->data; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1905 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1906 | surface_resource, |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1907 | surface->output->current->width, |
| 1908 | surface->output->current->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | static void |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1912 | panel_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 1913 | { |
| 1914 | struct desktop_shell *shell = es->private; |
| 1915 | |
| 1916 | configure_static_surface(es, &shell->panel_layer); |
| 1917 | } |
| 1918 | |
| 1919 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1920 | desktop_shell_set_panel(struct wl_client *client, |
| 1921 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1922 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1923 | struct wl_resource *surface_resource) |
| 1924 | { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1925 | struct desktop_shell *shell = resource->data; |
| 1926 | struct weston_surface *surface = surface_resource->data; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1927 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1928 | if (surface->configure) { |
| 1929 | wl_resource_post_error(surface_resource, |
| 1930 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1931 | "surface role already assigned"); |
| 1932 | return; |
| 1933 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1934 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1935 | surface->configure = panel_configure; |
| 1936 | surface->private = shell; |
| 1937 | surface->output = output_resource->data; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1938 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1939 | surface_resource, |
| 1940 | surface->output->current->width, |
| 1941 | surface->output->current->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1942 | } |
| 1943 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1944 | static void |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 1945 | lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
| 1946 | { |
| 1947 | struct desktop_shell *shell = surface->private; |
| 1948 | |
| 1949 | center_on_output(surface, get_default_output(shell->compositor)); |
| 1950 | |
| 1951 | if (!weston_surface_is_mapped(surface)) { |
| 1952 | wl_list_insert(&shell->lock_layer.surface_list, |
| 1953 | &surface->layer_link); |
| 1954 | weston_surface_assign_output(surface); |
| 1955 | weston_compositor_wake(shell->compositor); |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1960 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1961 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1962 | struct desktop_shell *shell = |
| 1963 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1964 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1965 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1966 | shell->lock_surface = NULL; |
| 1967 | } |
| 1968 | |
| 1969 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1970 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 1971 | struct wl_resource *resource, |
| 1972 | struct wl_resource *surface_resource) |
| 1973 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1974 | struct desktop_shell *shell = resource->data; |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 1975 | struct weston_surface *surface = surface_resource->data; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1976 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1977 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 1978 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1979 | if (!shell->locked) |
| 1980 | return; |
| 1981 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1982 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1983 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1984 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
| 1985 | wl_signal_add(&surface_resource->destroy_signal, |
| 1986 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1987 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 1988 | surface->configure = lock_surface_configure; |
| 1989 | surface->private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1993 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1994 | { |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 1995 | struct weston_surface *surface; |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 1996 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1997 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 1998 | wl_list_for_each(surface, &shell->screensaver.surfaces, link) |
| 1999 | weston_surface_unmap(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2000 | |
| 2001 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2002 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2003 | wl_list_remove(&shell->lock_layer.link); |
| 2004 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 2005 | &shell->fullscreen_layer.link); |
| 2006 | wl_list_insert(&shell->fullscreen_layer.link, |
| 2007 | &shell->panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 2008 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2009 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 2010 | pop_focus_state(shell, get_current_workspace(shell)); |
| 2011 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2012 | shell->locked = false; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 2013 | shell->compositor->idle_time = shell->compositor->option_idle_time; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2014 | weston_compositor_wake(shell->compositor); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 2015 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | static void |
| 2019 | desktop_shell_unlock(struct wl_client *client, |
| 2020 | struct wl_resource *resource) |
| 2021 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2022 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2023 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2024 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2025 | |
| 2026 | if (shell->locked) |
| 2027 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2028 | } |
| 2029 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2030 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2031 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2032 | struct wl_resource *resource, |
| 2033 | struct wl_resource *surface_resource) |
| 2034 | { |
| 2035 | struct desktop_shell *shell = resource->data; |
| 2036 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2037 | shell->grab_surface = surface_resource->data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2038 | } |
| 2039 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2040 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 2041 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2042 | desktop_shell_set_panel, |
| 2043 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2044 | desktop_shell_unlock, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2045 | desktop_shell_set_grab_surface |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2046 | }; |
| 2047 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2048 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2049 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2050 | { |
| 2051 | struct shell_surface *shsurf; |
| 2052 | |
| 2053 | shsurf = get_shell_surface(surface); |
| 2054 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2055 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2056 | return shsurf->type; |
| 2057 | } |
| 2058 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2059 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2060 | 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] | 2061 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2062 | struct weston_surface *surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2063 | (struct weston_surface *) seat->pointer->focus; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2064 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 2065 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2066 | if (surface == NULL) |
| 2067 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2068 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2069 | shsurf = get_shell_surface(surface); |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2070 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2071 | return; |
| 2072 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2073 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2077 | 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] | 2078 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2079 | struct weston_surface *surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2080 | (struct weston_surface *) seat->pointer->focus; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2081 | uint32_t edges = 0; |
| 2082 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2083 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 2084 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2085 | if (surface == NULL) |
| 2086 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2087 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2088 | shsurf = get_shell_surface(surface); |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2089 | if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2090 | return; |
| 2091 | |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 2092 | weston_surface_from_global(surface, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2093 | wl_fixed_to_int(seat->pointer->grab_x), |
| 2094 | wl_fixed_to_int(seat->pointer->grab_y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 2095 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2096 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2097 | if (x < surface->geometry.width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2098 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2099 | else if (x < 2 * surface->geometry.width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2100 | edges |= 0; |
| 2101 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2102 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2103 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2104 | if (y < surface->geometry.height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2105 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2106 | else if (y < 2 * surface->geometry.height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2107 | edges |= 0; |
| 2108 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2109 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2110 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 2111 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2115 | 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] | 2116 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2117 | { |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 2118 | float step = 0.05; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2119 | struct shell_surface *shsurf; |
| 2120 | struct weston_surface *surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2121 | (struct weston_surface *) seat->pointer->focus; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2122 | |
| 2123 | if (surface == NULL) |
| 2124 | return; |
| 2125 | |
| 2126 | shsurf = get_shell_surface(surface); |
| 2127 | if (!shsurf) |
| 2128 | return; |
| 2129 | |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 2130 | surface->alpha += wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2131 | |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 2132 | if (surface->alpha > 1.0) |
| 2133 | surface->alpha = 1.0; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2134 | if (surface->alpha < step) |
| 2135 | surface->alpha = step; |
| 2136 | |
| 2137 | surface->geometry.dirty = 1; |
| 2138 | weston_surface_damage(surface); |
| 2139 | } |
| 2140 | |
| 2141 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2142 | 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] | 2143 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2144 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2145 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 2146 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2147 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2148 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2149 | |
| 2150 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2151 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2152 | wl_fixed_to_double(seat->pointer->x), |
| 2153 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 2154 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2155 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2156 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2157 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2158 | increment = -output->zoom.increment; |
| 2159 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 2160 | increment = output->zoom.increment * |
| 2161 | wl_fixed_to_double(value); |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2162 | else |
| 2163 | increment = 0; |
| 2164 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2165 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 2166 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2167 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 2168 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2169 | else if (output->zoom.level > output->zoom.max_level) |
| 2170 | output->zoom.level = output->zoom.max_level; |
| 2171 | else |
| 2172 | output->zoom.active = 1; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2173 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2174 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2175 | |
Scott Moreau | 8dacaab | 2012-06-17 18:10:58 -0600 | [diff] [blame] | 2176 | weston_output_update_zoom(output, output->zoom.type); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2177 | } |
| 2178 | } |
| 2179 | } |
| 2180 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2181 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2182 | 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] | 2183 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2184 | { |
| 2185 | do_zoom(seat, time, 0, axis, value); |
| 2186 | } |
| 2187 | |
| 2188 | static void |
| 2189 | zoom_key_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 2190 | void *data) |
| 2191 | { |
| 2192 | do_zoom(seat, time, key, 0, 0); |
| 2193 | } |
| 2194 | |
| 2195 | static void |
| 2196 | terminate_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 2197 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2198 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2199 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2200 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2201 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 2205 | rotate_grab_motion(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 2206 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2207 | { |
| 2208 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2209 | container_of(grab, struct rotate_grab, base.grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2210 | struct wl_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2211 | struct shell_surface *shsurf = rotate->base.shsurf; |
| 2212 | struct weston_surface *surface; |
| 2213 | GLfloat cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
| 2214 | |
| 2215 | if (!shsurf) |
| 2216 | return; |
| 2217 | |
| 2218 | surface = shsurf->surface; |
| 2219 | |
| 2220 | cx = 0.5f * surface->geometry.width; |
| 2221 | cy = 0.5f * surface->geometry.height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2222 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2223 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 2224 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2225 | r = sqrtf(dx * dx + dy * dy); |
| 2226 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2227 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2228 | shsurf->surface->geometry.dirty = 1; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2229 | |
| 2230 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2231 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2232 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2233 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2234 | weston_matrix_init(&rotate->rotation); |
| 2235 | rotate->rotation.d[0] = dx / r; |
| 2236 | rotate->rotation.d[4] = -dy / r; |
| 2237 | rotate->rotation.d[1] = -rotate->rotation.d[4]; |
| 2238 | rotate->rotation.d[5] = rotate->rotation.d[0]; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2239 | |
| 2240 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 2241 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2242 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2243 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 2244 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2245 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 2246 | wl_list_insert( |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2247 | &shsurf->surface->geometry.transformation_list, |
| 2248 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2249 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2250 | wl_list_init(&shsurf->rotation.transform.link); |
| 2251 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2252 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2253 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 2254 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2255 | /* We need to adjust the position of the surface |
| 2256 | * in case it was resized in a rotated state before */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2257 | cposx = surface->geometry.x + cx; |
| 2258 | cposy = surface->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2259 | dposx = rotate->center.x - cposx; |
| 2260 | dposy = rotate->center.y - cposy; |
| 2261 | if (dposx != 0.0f || dposy != 0.0f) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2262 | weston_surface_set_position(surface, |
| 2263 | surface->geometry.x + dposx, |
| 2264 | surface->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2265 | } |
| 2266 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 2267 | /* Repaint implies weston_surface_update_transform(), which |
| 2268 | * lazily applies the damage due to rotation update. |
| 2269 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2270 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 2274 | rotate_grab_button(struct wl_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2275 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2276 | { |
| 2277 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2278 | container_of(grab, struct rotate_grab, base.grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2279 | struct wl_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2280 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2281 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2282 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2283 | if (pointer->button_count == 0 && |
| 2284 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2285 | if (shsurf) |
| 2286 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 2287 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2288 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2289 | free(rotate); |
| 2290 | } |
| 2291 | } |
| 2292 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 2293 | static const struct wl_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2294 | noop_grab_focus, |
| 2295 | rotate_grab_motion, |
| 2296 | rotate_grab_button, |
| 2297 | }; |
| 2298 | |
| 2299 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2300 | rotate_binding(struct wl_seat *seat, uint32_t time, uint32_t button, |
Daniel Stone | e5a0120 | 2012-05-04 11:21:57 +0100 | [diff] [blame] | 2301 | void *data) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2302 | { |
| 2303 | struct weston_surface *base_surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2304 | (struct weston_surface *) seat->pointer->focus; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2305 | struct shell_surface *surface; |
| 2306 | struct rotate_grab *rotate; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2307 | GLfloat dx, dy; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2308 | GLfloat r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2309 | |
| 2310 | if (base_surface == NULL) |
| 2311 | return; |
| 2312 | |
| 2313 | surface = get_shell_surface(base_surface); |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2314 | if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2315 | return; |
| 2316 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2317 | rotate = malloc(sizeof *rotate); |
| 2318 | if (!rotate) |
| 2319 | return; |
| 2320 | |
Kristian Høgsberg | b2af93e | 2012-06-07 20:10:23 -0400 | [diff] [blame] | 2321 | weston_surface_to_global_float(surface->surface, |
| 2322 | surface->surface->geometry.width / 2, |
| 2323 | surface->surface->geometry.height / 2, |
| 2324 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2325 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2326 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 2327 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2328 | r = sqrtf(dx * dx + dy * dy); |
| 2329 | if (r > 20.0f) { |
| 2330 | struct weston_matrix inverse; |
| 2331 | |
| 2332 | weston_matrix_init(&inverse); |
| 2333 | inverse.d[0] = dx / r; |
| 2334 | inverse.d[4] = dy / r; |
| 2335 | inverse.d[1] = -inverse.d[4]; |
| 2336 | inverse.d[5] = inverse.d[0]; |
| 2337 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2338 | |
| 2339 | weston_matrix_init(&rotate->rotation); |
| 2340 | rotate->rotation.d[0] = dx / r; |
| 2341 | rotate->rotation.d[4] = -dy / r; |
| 2342 | rotate->rotation.d[1] = -rotate->rotation.d[4]; |
| 2343 | rotate->rotation.d[5] = rotate->rotation.d[0]; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2344 | } else { |
| 2345 | weston_matrix_init(&surface->rotation.rotation); |
| 2346 | weston_matrix_init(&rotate->rotation); |
| 2347 | } |
| 2348 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2349 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 2350 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 2354 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 2355 | { |
| 2356 | struct workspace *ws; |
| 2357 | struct weston_surface *surface, *prev; |
| 2358 | |
| 2359 | ws = get_current_workspace(shell); |
| 2360 | wl_list_for_each_reverse_safe(surface, prev, |
| 2361 | &shell->fullscreen_layer.surface_list, |
| 2362 | layer_link) |
| 2363 | weston_surface_restack(surface, &ws->layer.surface_list); |
| 2364 | } |
| 2365 | |
| 2366 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2367 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2368 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2369 | { |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2370 | struct workspace *ws; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2371 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2372 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2373 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2374 | switch (get_shell_surface_type(es)) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2375 | case SHELL_SURFACE_FULLSCREEN: |
| 2376 | /* should on top of panels */ |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2377 | shell_stack_fullscreen(get_shell_surface(es)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2378 | shell_configure_fullscreen(get_shell_surface(es)); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2379 | break; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2380 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2381 | ws = get_current_workspace(shell); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 2382 | lower_fullscreen_layer(shell); |
| 2383 | weston_surface_restack(es, &ws->layer.surface_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2384 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2385 | } |
| 2386 | } |
| 2387 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2388 | /* no-op func for checking black surface */ |
| 2389 | static void |
| 2390 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 2391 | { |
| 2392 | } |
| 2393 | |
| 2394 | static bool |
| 2395 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 2396 | { |
| 2397 | if (es->configure == black_surface_configure) { |
| 2398 | if (fs_surface) |
| 2399 | *fs_surface = (struct weston_surface *)es->private; |
| 2400 | return true; |
| 2401 | } |
| 2402 | return false; |
| 2403 | } |
| 2404 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2405 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2406 | 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] | 2407 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2408 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2409 | struct weston_seat *ws = (struct weston_seat *) seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2410 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2411 | struct weston_surface *focus; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2412 | struct weston_surface *upper; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2413 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2414 | focus = (struct weston_surface *) seat->pointer->focus; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 2415 | if (!focus) |
| 2416 | return; |
| 2417 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2418 | if (is_black_surface(focus, &upper)) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2419 | focus = upper; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2420 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2421 | if (get_shell_surface_type(focus) == SHELL_SURFACE_NONE) |
| 2422 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 2423 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2424 | if (seat->pointer->grab == &seat->pointer->default_grab) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2425 | activate(shell, focus, ws); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2429 | lock(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2430 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2431 | struct desktop_shell *shell = |
| 2432 | container_of(listener, struct desktop_shell, lock_listener); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2433 | struct weston_output *output; |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 2434 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2435 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2436 | if (shell->locked) { |
| 2437 | wl_list_for_each(output, &shell->compositor->output_list, link) |
| 2438 | /* TODO: find a way to jump to other DPMS levels */ |
| 2439 | if (output->set_dpms) |
| 2440 | output->set_dpms(output, WESTON_DPMS_STANDBY); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2441 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2442 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2443 | |
| 2444 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2445 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2446 | /* Hide all surfaces by removing the fullscreen, panel and |
| 2447 | * toplevel layers. This way nothing else can show or receive |
| 2448 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2449 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2450 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2451 | wl_list_remove(&shell->fullscreen_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 2452 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2453 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 2454 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2455 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2456 | launch_screensaver(shell); |
| 2457 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 2458 | /* stash keyboard foci in current workspace */ |
| 2459 | push_focus_state(shell, get_current_workspace(shell)); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2460 | |
| 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 | } |