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. |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4 | * Copyright © 2013 Raspberry Pi Foundation |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5 | * |
| 6 | * Permission to use, copy, modify, distribute, and sell this software and |
| 7 | * its documentation for any purpose is hereby granted without fee, provided |
| 8 | * that the above copyright notice appear in all copies and that both that |
| 9 | * copyright notice and this permission notice appear in supporting |
| 10 | * documentation, and that the name of the copyright holders not be used in |
| 11 | * advertising or publicity pertaining to distribution of the software |
| 12 | * without specific, written prior permission. The copyright holders make |
| 13 | * no representations about the suitability of this software for any |
| 14 | * purpose. It is provided "as is" without express or implied warranty. |
| 15 | * |
| 16 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 17 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 18 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 20 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 21 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 22 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 23 | */ |
| 24 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 25 | #include "config.h" |
| 26 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 27 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 28 | #include <stdio.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 29 | #include <string.h> |
| 30 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 31 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 32 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 33 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 34 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 35 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 36 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame^] | 37 | #include "shell.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 38 | #include "desktop-shell-server-protocol.h" |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 39 | #include "input-method-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 40 | #include "workspaces-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 41 | #include "../shared/config-parser.h" |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 42 | #include "xdg-shell-server-protocol.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 43 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 44 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 45 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 46 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 47 | struct focus_state { |
| 48 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 49 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 50 | struct weston_surface *keyboard_focus; |
| 51 | struct wl_list link; |
| 52 | struct wl_listener seat_destroy_listener; |
| 53 | struct wl_listener surface_destroy_listener; |
| 54 | }; |
| 55 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 56 | struct input_panel_surface { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 57 | struct wl_resource *resource; |
| 58 | struct wl_signal destroy_signal; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 59 | |
| 60 | struct desktop_shell *shell; |
| 61 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 62 | struct wl_list link; |
| 63 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 64 | struct weston_view *view; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 65 | struct wl_listener surface_destroy_listener; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 66 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 67 | struct weston_output *output; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 68 | uint32_t panel; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 69 | }; |
| 70 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 71 | struct shell_output { |
| 72 | struct desktop_shell *shell; |
| 73 | struct weston_output *output; |
| 74 | struct wl_listener destroy_listener; |
| 75 | struct wl_list link; |
| 76 | }; |
| 77 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 78 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 79 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 80 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 81 | SHELL_SURFACE_POPUP, |
| 82 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 83 | }; |
| 84 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 85 | struct ping_timer { |
| 86 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 87 | uint32_t serial; |
| 88 | }; |
| 89 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 90 | /* |
| 91 | * Surface stacking and ordering. |
| 92 | * |
| 93 | * This is handled using several linked lists of surfaces, organised into |
| 94 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 95 | * above all of the surfaces in the layer below. The set of layers is static and |
| 96 | * in the following order (top-most first): |
| 97 | * • Lock layer (only ever displayed on its own) |
| 98 | * • Cursor layer |
| 99 | * • Fullscreen layer |
| 100 | * • Panel layer |
| 101 | * • Input panel layer |
| 102 | * • Workspace layers |
| 103 | * • Background layer |
| 104 | * |
| 105 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 106 | * display. For example, when locking the screen, all layers except the lock |
| 107 | * layer are removed. |
| 108 | * |
| 109 | * A surface’s layer is modified on configuring the surface, in |
| 110 | * set_surface_type() (which is only called when the surface’s type change is |
| 111 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 112 | * fullscreen) its layer changes too. |
| 113 | * |
| 114 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 115 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 116 | * linked list of its children. When a surface’s layer is updated, so are the |
| 117 | * layers of its children. Note that child surfaces are *not* the same as |
| 118 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 119 | * order. |
| 120 | * |
| 121 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 122 | * have the same parent) only contains weston_surfaces which have a |
| 123 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 124 | * weston_surfaces. This means that the following implication does *not* hold: |
| 125 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 126 | */ |
| 127 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 128 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 129 | struct wl_resource *resource; |
| 130 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 131 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 132 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 133 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 134 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 135 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 136 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 137 | struct wl_list children_list; /* child surfaces of this one */ |
| 138 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 139 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 140 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 141 | enum shell_surface_type type, next_type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 142 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 143 | int32_t saved_x, saved_y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 144 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 145 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 146 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 147 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 148 | int unresponsive, grabbed; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 149 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 150 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 151 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 152 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 153 | } rotation; |
| 154 | |
| 155 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 156 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 157 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 158 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 159 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 160 | } popup; |
| 161 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 162 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 163 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 164 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 165 | } transient; |
| 166 | |
| 167 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 168 | enum wl_shell_surface_fullscreen_method type; |
| 169 | struct weston_transform transform; /* matrix from x, y */ |
| 170 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 171 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 172 | } fullscreen; |
| 173 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 174 | struct ping_timer *ping_timer; |
| 175 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 176 | struct weston_transform workspace_transform; |
| 177 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 178 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 179 | struct weston_output *output; |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 180 | struct weston_output *recommended_output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 181 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 182 | |
| 183 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 184 | |
| 185 | struct { |
| 186 | bool maximized; |
| 187 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 188 | bool relative; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 189 | } state, next_state; /* surface states */ |
| 190 | bool state_changed; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 191 | }; |
| 192 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 193 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 194 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 195 | struct shell_surface *shsurf; |
| 196 | struct wl_listener shsurf_destroy_listener; |
| 197 | }; |
| 198 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 199 | struct shell_touch_grab { |
| 200 | struct weston_touch_grab grab; |
| 201 | struct shell_surface *shsurf; |
| 202 | struct wl_listener shsurf_destroy_listener; |
| 203 | struct weston_touch *touch; |
| 204 | }; |
| 205 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 206 | struct weston_move_grab { |
| 207 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 208 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 209 | }; |
| 210 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 211 | struct weston_touch_move_grab { |
| 212 | struct shell_touch_grab base; |
| 213 | wl_fixed_t dx, dy; |
| 214 | }; |
| 215 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 216 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 217 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 218 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 219 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 220 | float x; |
| 221 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 222 | } center; |
| 223 | }; |
| 224 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 225 | struct shell_seat { |
| 226 | struct weston_seat *seat; |
| 227 | struct wl_listener seat_destroy_listener; |
| 228 | |
| 229 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 230 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 231 | struct wl_list surfaces_list; |
| 232 | struct wl_client *client; |
| 233 | int32_t initial_up; |
| 234 | } popup_grab; |
| 235 | }; |
| 236 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 237 | static struct desktop_shell * |
| 238 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 239 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 240 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 241 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 242 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 243 | static void |
| 244 | shell_fade_startup(struct desktop_shell *shell); |
| 245 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 246 | static struct shell_seat * |
| 247 | get_shell_seat(struct weston_seat *seat); |
| 248 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 249 | static void |
| 250 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 251 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 252 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 253 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 254 | |
| 255 | static bool |
| 256 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 257 | |
| 258 | static bool |
| 259 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 260 | |
| 261 | static void |
| 262 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 263 | struct weston_surface *parent); |
| 264 | |
| 265 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 266 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 267 | { |
| 268 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 269 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 270 | |
| 271 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 272 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 273 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 274 | return false; |
| 275 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 276 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 277 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 278 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 279 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 280 | } |
| 281 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 282 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 283 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 284 | { |
| 285 | struct shell_grab *grab; |
| 286 | |
| 287 | grab = container_of(listener, struct shell_grab, |
| 288 | shsurf_destroy_listener); |
| 289 | |
| 290 | grab->shsurf = NULL; |
| 291 | } |
| 292 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame^] | 293 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 294 | get_default_view(struct weston_surface *surface) |
| 295 | { |
| 296 | struct shell_surface *shsurf; |
| 297 | struct weston_view *view; |
| 298 | |
| 299 | if (!surface || wl_list_empty(&surface->views)) |
| 300 | return NULL; |
| 301 | |
| 302 | shsurf = get_shell_surface(surface); |
| 303 | if (shsurf) |
| 304 | return shsurf->view; |
| 305 | |
| 306 | wl_list_for_each(view, &surface->views, surface_link) |
| 307 | if (weston_view_is_mapped(view)) |
| 308 | return view; |
| 309 | |
| 310 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 311 | } |
| 312 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 313 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 314 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 315 | |
| 316 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 317 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 318 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 319 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 320 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 321 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 322 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 323 | struct desktop_shell *shell = shsurf->shell; |
| 324 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 325 | popup_grab_end(pointer); |
| 326 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 327 | grab->grab.interface = interface; |
| 328 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 329 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 330 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 331 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 332 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 333 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 334 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 335 | if (shell->child.desktop_shell) { |
| 336 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 337 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 338 | weston_pointer_set_focus(pointer, |
| 339 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 340 | wl_fixed_from_int(0), |
| 341 | wl_fixed_from_int(0)); |
| 342 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 346 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 347 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 348 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 349 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 350 | grab->shsurf->grabbed = 0; |
| 351 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 352 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 353 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 357 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 358 | const struct weston_touch_grab_interface *interface, |
| 359 | struct shell_surface *shsurf, |
| 360 | struct weston_touch *touch) |
| 361 | { |
| 362 | struct desktop_shell *shell = shsurf->shell; |
| 363 | |
| 364 | grab->grab.interface = interface; |
| 365 | grab->shsurf = shsurf; |
| 366 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 367 | wl_signal_add(&shsurf->destroy_signal, |
| 368 | &grab->shsurf_destroy_listener); |
| 369 | |
| 370 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 371 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 372 | |
| 373 | weston_touch_start_grab(touch, &grab->grab); |
| 374 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 375 | weston_touch_set_focus(touch->seat, |
| 376 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | static void |
| 380 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 381 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 382 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 383 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 384 | grab->shsurf->grabbed = 0; |
| 385 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 386 | |
| 387 | weston_touch_end_grab(grab->touch); |
| 388 | } |
| 389 | |
| 390 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 391 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 392 | struct weston_output *output); |
| 393 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 394 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 395 | get_modifier(char *modifier) |
| 396 | { |
| 397 | if (!modifier) |
| 398 | return MODIFIER_SUPER; |
| 399 | |
| 400 | if (!strcmp("ctrl", modifier)) |
| 401 | return MODIFIER_CTRL; |
| 402 | else if (!strcmp("alt", modifier)) |
| 403 | return MODIFIER_ALT; |
| 404 | else if (!strcmp("super", modifier)) |
| 405 | return MODIFIER_SUPER; |
| 406 | else |
| 407 | return MODIFIER_SUPER; |
| 408 | } |
| 409 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 410 | static enum animation_type |
| 411 | get_animation_type(char *animation) |
| 412 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 413 | if (!strcmp("zoom", animation)) |
| 414 | return ANIMATION_ZOOM; |
| 415 | else if (!strcmp("fade", animation)) |
| 416 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 417 | else if (!strcmp("dim-layer", animation)) |
| 418 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 419 | else |
| 420 | return ANIMATION_NONE; |
| 421 | } |
| 422 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 423 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 424 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 425 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 426 | struct weston_config_section *section; |
| 427 | int duration; |
| 428 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 429 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 430 | section = weston_config_get_section(shell->compositor->config, |
| 431 | "screensaver", NULL, NULL); |
| 432 | weston_config_section_get_string(section, |
| 433 | "path", &shell->screensaver.path, NULL); |
| 434 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 435 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 436 | |
| 437 | section = weston_config_get_section(shell->compositor->config, |
| 438 | "shell", NULL, NULL); |
| 439 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 440 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 441 | shell->client = s; |
| 442 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 443 | "binding-modifier", &s, "super"); |
| 444 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 445 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 446 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 447 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 448 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 449 | weston_config_section_get_string(section, |
| 450 | "startup-animation", &s, "fade"); |
| 451 | shell->startup_animation_type = get_animation_type(s); |
| 452 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 453 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 454 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 455 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 456 | shell->focus_animation_type = get_animation_type(s); |
| 457 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 458 | weston_config_section_get_uint(section, "num-workspaces", |
| 459 | &shell->workspaces.num, |
| 460 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 461 | } |
| 462 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame^] | 463 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 464 | get_default_output(struct weston_compositor *compositor) |
| 465 | { |
| 466 | return container_of(compositor->output_list.next, |
| 467 | struct weston_output, link); |
| 468 | } |
| 469 | |
| 470 | |
| 471 | /* no-op func for checking focus surface */ |
| 472 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 473 | focus_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 474 | { |
| 475 | } |
| 476 | |
| 477 | static struct focus_surface * |
| 478 | get_focus_surface(struct weston_surface *surface) |
| 479 | { |
| 480 | if (surface->configure == focus_surface_configure) |
| 481 | return surface->configure_private; |
| 482 | else |
| 483 | return NULL; |
| 484 | } |
| 485 | |
| 486 | static bool |
| 487 | is_focus_surface (struct weston_surface *es) |
| 488 | { |
| 489 | return (es->configure == focus_surface_configure); |
| 490 | } |
| 491 | |
| 492 | static bool |
| 493 | is_focus_view (struct weston_view *view) |
| 494 | { |
| 495 | return is_focus_surface (view->surface); |
| 496 | } |
| 497 | |
| 498 | static struct focus_surface * |
| 499 | create_focus_surface(struct weston_compositor *ec, |
| 500 | struct weston_output *output) |
| 501 | { |
| 502 | struct focus_surface *fsurf = NULL; |
| 503 | struct weston_surface *surface = NULL; |
| 504 | |
| 505 | fsurf = malloc(sizeof *fsurf); |
| 506 | if (!fsurf) |
| 507 | return NULL; |
| 508 | |
| 509 | fsurf->surface = weston_surface_create(ec); |
| 510 | surface = fsurf->surface; |
| 511 | if (surface == NULL) { |
| 512 | free(fsurf); |
| 513 | return NULL; |
| 514 | } |
| 515 | |
| 516 | surface->configure = focus_surface_configure; |
| 517 | surface->output = output; |
| 518 | surface->configure_private = fsurf; |
| 519 | |
| 520 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 521 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 522 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 523 | surface->width = output->width; |
| 524 | surface->height = output->height; |
| 525 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 526 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 527 | pixman_region32_fini(&surface->opaque); |
| 528 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 529 | output->width, output->height); |
| 530 | pixman_region32_fini(&surface->input); |
| 531 | pixman_region32_init(&surface->input); |
| 532 | |
| 533 | wl_list_init(&fsurf->workspace_transform.link); |
| 534 | |
| 535 | return fsurf; |
| 536 | } |
| 537 | |
| 538 | static void |
| 539 | focus_surface_destroy(struct focus_surface *fsurf) |
| 540 | { |
| 541 | weston_surface_destroy(fsurf->surface); |
| 542 | free(fsurf); |
| 543 | } |
| 544 | |
| 545 | static void |
| 546 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 547 | { |
| 548 | struct workspace *ws = data; |
| 549 | |
| 550 | ws->focus_animation = NULL; |
| 551 | } |
| 552 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 553 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 554 | focus_state_destroy(struct focus_state *state) |
| 555 | { |
| 556 | wl_list_remove(&state->seat_destroy_listener.link); |
| 557 | wl_list_remove(&state->surface_destroy_listener.link); |
| 558 | free(state); |
| 559 | } |
| 560 | |
| 561 | static void |
| 562 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 563 | { |
| 564 | struct focus_state *state = container_of(listener, |
| 565 | struct focus_state, |
| 566 | seat_destroy_listener); |
| 567 | |
| 568 | wl_list_remove(&state->link); |
| 569 | focus_state_destroy(state); |
| 570 | } |
| 571 | |
| 572 | static void |
| 573 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 574 | { |
| 575 | struct focus_state *state = container_of(listener, |
| 576 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 577 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 578 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 579 | struct weston_surface *main_surface, *next; |
| 580 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 581 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 582 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 583 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 584 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 585 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 586 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 587 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 588 | if (is_focus_view(view)) |
| 589 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 590 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 591 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 592 | break; |
| 593 | } |
| 594 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 595 | /* if the focus was a sub-surface, activate its main surface */ |
| 596 | if (main_surface != state->keyboard_focus) |
| 597 | next = main_surface; |
| 598 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 599 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 600 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 601 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 602 | activate(shell, next, state->seat); |
| 603 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 604 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 605 | if (state->ws->focus_animation) |
| 606 | weston_view_animation_destroy(state->ws->focus_animation); |
| 607 | |
| 608 | state->ws->focus_animation = weston_fade_run( |
| 609 | state->ws->fsurf_front->view, |
| 610 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 611 | focus_animation_done, state->ws); |
| 612 | } |
| 613 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 614 | wl_list_remove(&state->link); |
| 615 | focus_state_destroy(state); |
| 616 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 620 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 621 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 622 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 623 | |
| 624 | state = malloc(sizeof *state); |
| 625 | if (state == NULL) |
| 626 | return NULL; |
| 627 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 628 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 629 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 630 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 631 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 632 | |
| 633 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 634 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 635 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 636 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 637 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 638 | |
| 639 | return state; |
| 640 | } |
| 641 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 642 | static struct focus_state * |
| 643 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 644 | { |
| 645 | struct workspace *ws = get_current_workspace(shell); |
| 646 | struct focus_state *state; |
| 647 | |
| 648 | wl_list_for_each(state, &ws->focus_list, link) |
| 649 | if (state->seat == seat) |
| 650 | break; |
| 651 | |
| 652 | if (&state->link == &ws->focus_list) |
| 653 | state = focus_state_create(seat, ws); |
| 654 | |
| 655 | return state; |
| 656 | } |
| 657 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 658 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 659 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 660 | { |
| 661 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 662 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 663 | |
| 664 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 665 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 666 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 667 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | |
| 671 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 672 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 673 | struct weston_seat *seat) |
| 674 | { |
| 675 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 676 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 677 | |
| 678 | wl_list_for_each(state, &ws->focus_list, link) { |
| 679 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 680 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 681 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 682 | return; |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | static void |
| 688 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 689 | struct weston_surface *surface) |
| 690 | { |
| 691 | struct focus_state *state; |
| 692 | |
| 693 | wl_list_for_each(state, &ws->focus_list, link) |
| 694 | if (state->keyboard_focus == surface) |
| 695 | state->keyboard_focus = NULL; |
| 696 | } |
| 697 | |
| 698 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 699 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 700 | struct weston_view *from, struct weston_view *to) |
| 701 | { |
| 702 | struct weston_output *output; |
| 703 | bool focus_surface_created = false; |
| 704 | |
| 705 | /* FIXME: Only support dim animation using two layers */ |
| 706 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 707 | return; |
| 708 | |
| 709 | output = get_default_output(shell->compositor); |
| 710 | if (ws->fsurf_front == NULL && (from || to)) { |
| 711 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 712 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 713 | ws->fsurf_front->view->alpha = 0.0; |
| 714 | ws->fsurf_back->view->alpha = 0.0; |
| 715 | focus_surface_created = true; |
| 716 | } else { |
| 717 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 718 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 719 | } |
| 720 | |
| 721 | if (ws->focus_animation) { |
| 722 | weston_view_animation_destroy(ws->focus_animation); |
| 723 | ws->focus_animation = NULL; |
| 724 | } |
| 725 | |
| 726 | if (to) |
| 727 | wl_list_insert(&to->layer_link, |
| 728 | &ws->fsurf_front->view->layer_link); |
| 729 | else if (from) |
| 730 | wl_list_insert(&ws->layer.view_list, |
| 731 | &ws->fsurf_front->view->layer_link); |
| 732 | |
| 733 | if (focus_surface_created) { |
| 734 | ws->focus_animation = weston_fade_run( |
| 735 | ws->fsurf_front->view, |
| 736 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 737 | focus_animation_done, ws); |
| 738 | } else if (from) { |
| 739 | wl_list_insert(&from->layer_link, |
| 740 | &ws->fsurf_back->view->layer_link); |
| 741 | ws->focus_animation = weston_stable_fade_run( |
| 742 | ws->fsurf_front->view, 0.0, |
| 743 | ws->fsurf_back->view, 0.6, |
| 744 | focus_animation_done, ws); |
| 745 | } else if (to) { |
| 746 | wl_list_insert(&ws->layer.view_list, |
| 747 | &ws->fsurf_back->view->layer_link); |
| 748 | ws->focus_animation = weston_stable_fade_run( |
| 749 | ws->fsurf_front->view, 0.0, |
| 750 | ws->fsurf_back->view, 0.6, |
| 751 | focus_animation_done, ws); |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 756 | workspace_destroy(struct workspace *ws) |
| 757 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 758 | struct focus_state *state, *next; |
| 759 | |
| 760 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 761 | focus_state_destroy(state); |
| 762 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 763 | if (ws->fsurf_front) |
| 764 | focus_surface_destroy(ws->fsurf_front); |
| 765 | if (ws->fsurf_back) |
| 766 | focus_surface_destroy(ws->fsurf_back); |
| 767 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 768 | free(ws); |
| 769 | } |
| 770 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 771 | static void |
| 772 | seat_destroyed(struct wl_listener *listener, void *data) |
| 773 | { |
| 774 | struct weston_seat *seat = data; |
| 775 | struct focus_state *state, *next; |
| 776 | struct workspace *ws = container_of(listener, |
| 777 | struct workspace, |
| 778 | seat_destroyed_listener); |
| 779 | |
| 780 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 781 | if (state->seat == seat) |
| 782 | wl_list_remove(&state->link); |
| 783 | } |
| 784 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 785 | static struct workspace * |
| 786 | workspace_create(void) |
| 787 | { |
| 788 | struct workspace *ws = malloc(sizeof *ws); |
| 789 | if (ws == NULL) |
| 790 | return NULL; |
| 791 | |
| 792 | weston_layer_init(&ws->layer, NULL); |
| 793 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 794 | wl_list_init(&ws->focus_list); |
| 795 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 796 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 797 | ws->fsurf_front = NULL; |
| 798 | ws->fsurf_back = NULL; |
| 799 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 800 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 801 | return ws; |
| 802 | } |
| 803 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 804 | static int |
| 805 | workspace_is_empty(struct workspace *ws) |
| 806 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 807 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 808 | } |
| 809 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 810 | static struct workspace * |
| 811 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 812 | { |
| 813 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 814 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 815 | pws += index; |
| 816 | return *pws; |
| 817 | } |
| 818 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame^] | 819 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 820 | get_current_workspace(struct desktop_shell *shell) |
| 821 | { |
| 822 | return get_workspace(shell, shell->workspaces.current); |
| 823 | } |
| 824 | |
| 825 | static void |
| 826 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 827 | { |
| 828 | struct workspace *ws; |
| 829 | |
| 830 | ws = get_workspace(shell, index); |
| 831 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 832 | |
| 833 | shell->workspaces.current = index; |
| 834 | } |
| 835 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 836 | static unsigned int |
| 837 | get_output_height(struct weston_output *output) |
| 838 | { |
| 839 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 840 | } |
| 841 | |
| 842 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 843 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 844 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 845 | struct weston_transform *transform; |
| 846 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 847 | if (is_focus_view(view)) { |
| 848 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 849 | transform = &fsurf->workspace_transform; |
| 850 | } else { |
| 851 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 852 | transform = &shsurf->workspace_transform; |
| 853 | } |
| 854 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 855 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 856 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 857 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 858 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 859 | weston_matrix_init(&transform->matrix); |
| 860 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 861 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 862 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | static void |
| 866 | workspace_translate_out(struct workspace *ws, double fraction) |
| 867 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 868 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 869 | unsigned int height; |
| 870 | double d; |
| 871 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 872 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 873 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 874 | d = height * fraction; |
| 875 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 876 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | |
| 880 | static void |
| 881 | workspace_translate_in(struct workspace *ws, double fraction) |
| 882 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 883 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 884 | unsigned int height; |
| 885 | double d; |
| 886 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 887 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 888 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 889 | |
| 890 | if (fraction > 0) |
| 891 | d = -(height - height * fraction); |
| 892 | else |
| 893 | d = height + height * fraction; |
| 894 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 895 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 896 | } |
| 897 | } |
| 898 | |
| 899 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 900 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 901 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 902 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 903 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 904 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 905 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 906 | shell->workspaces.current, |
| 907 | shell->workspaces.num); |
| 908 | } |
| 909 | |
| 910 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 911 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 912 | unsigned int index, |
| 913 | struct workspace *from, |
| 914 | struct workspace *to) |
| 915 | { |
| 916 | shell->workspaces.current = index; |
| 917 | |
| 918 | shell->workspaces.anim_to = to; |
| 919 | shell->workspaces.anim_from = from; |
| 920 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 921 | shell->workspaces.anim_timestamp = 0; |
| 922 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 923 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | static void |
| 927 | workspace_deactivate_transforms(struct workspace *ws) |
| 928 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 929 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 930 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 931 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 932 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 933 | if (is_focus_view(view)) { |
| 934 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 935 | transform = &fsurf->workspace_transform; |
| 936 | } else { |
| 937 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 938 | transform = &shsurf->workspace_transform; |
| 939 | } |
| 940 | |
| 941 | if (!wl_list_empty(&transform->link)) { |
| 942 | wl_list_remove(&transform->link); |
| 943 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 944 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 945 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | |
| 949 | static void |
| 950 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 951 | struct workspace *from, |
| 952 | struct workspace *to) |
| 953 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 954 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 955 | |
| 956 | wl_list_remove(&shell->workspaces.animation.link); |
| 957 | workspace_deactivate_transforms(from); |
| 958 | workspace_deactivate_transforms(to); |
| 959 | shell->workspaces.anim_to = NULL; |
| 960 | |
| 961 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 962 | } |
| 963 | |
| 964 | static void |
| 965 | animate_workspace_change_frame(struct weston_animation *animation, |
| 966 | struct weston_output *output, uint32_t msecs) |
| 967 | { |
| 968 | struct desktop_shell *shell = |
| 969 | container_of(animation, struct desktop_shell, |
| 970 | workspaces.animation); |
| 971 | struct workspace *from = shell->workspaces.anim_from; |
| 972 | struct workspace *to = shell->workspaces.anim_to; |
| 973 | uint32_t t; |
| 974 | double x, y; |
| 975 | |
| 976 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 977 | finish_workspace_change_animation(shell, from, to); |
| 978 | return; |
| 979 | } |
| 980 | |
| 981 | if (shell->workspaces.anim_timestamp == 0) { |
| 982 | if (shell->workspaces.anim_current == 0.0) |
| 983 | shell->workspaces.anim_timestamp = msecs; |
| 984 | else |
| 985 | shell->workspaces.anim_timestamp = |
| 986 | msecs - |
| 987 | /* Invers of movement function 'y' below. */ |
| 988 | (asin(1.0 - shell->workspaces.anim_current) * |
| 989 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 990 | M_2_PI); |
| 991 | } |
| 992 | |
| 993 | t = msecs - shell->workspaces.anim_timestamp; |
| 994 | |
| 995 | /* |
| 996 | * x = [0, π/2] |
| 997 | * y(x) = sin(x) |
| 998 | */ |
| 999 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1000 | y = sin(x); |
| 1001 | |
| 1002 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1003 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1004 | |
| 1005 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1006 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1007 | shell->workspaces.anim_current = y; |
| 1008 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1009 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1010 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1011 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1012 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | static void |
| 1016 | animate_workspace_change(struct desktop_shell *shell, |
| 1017 | unsigned int index, |
| 1018 | struct workspace *from, |
| 1019 | struct workspace *to) |
| 1020 | { |
| 1021 | struct weston_output *output; |
| 1022 | |
| 1023 | int dir; |
| 1024 | |
| 1025 | if (index > shell->workspaces.current) |
| 1026 | dir = -1; |
| 1027 | else |
| 1028 | dir = 1; |
| 1029 | |
| 1030 | shell->workspaces.current = index; |
| 1031 | |
| 1032 | shell->workspaces.anim_dir = dir; |
| 1033 | shell->workspaces.anim_from = from; |
| 1034 | shell->workspaces.anim_to = to; |
| 1035 | shell->workspaces.anim_current = 0.0; |
| 1036 | shell->workspaces.anim_timestamp = 0; |
| 1037 | |
| 1038 | output = container_of(shell->compositor->output_list.next, |
| 1039 | struct weston_output, link); |
| 1040 | wl_list_insert(&output->animation_list, |
| 1041 | &shell->workspaces.animation.link); |
| 1042 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1043 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1044 | |
| 1045 | workspace_translate_in(to, 0); |
| 1046 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1047 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1048 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1049 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1050 | } |
| 1051 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1052 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1053 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1054 | struct workspace *from, struct workspace *to) |
| 1055 | { |
| 1056 | shell->workspaces.current = index; |
| 1057 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1058 | wl_list_remove(&from->layer.link); |
| 1059 | } |
| 1060 | |
| 1061 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1062 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1063 | { |
| 1064 | struct workspace *from; |
| 1065 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1066 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1067 | |
| 1068 | if (index == shell->workspaces.current) |
| 1069 | return; |
| 1070 | |
| 1071 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1072 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1073 | return; |
| 1074 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1075 | from = get_current_workspace(shell); |
| 1076 | to = get_workspace(shell, index); |
| 1077 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1078 | if (shell->workspaces.anim_from == to && |
| 1079 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1080 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1081 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1082 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1083 | return; |
| 1084 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1085 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1086 | if (shell->workspaces.anim_to != NULL) |
| 1087 | finish_workspace_change_animation(shell, |
| 1088 | shell->workspaces.anim_from, |
| 1089 | shell->workspaces.anim_to); |
| 1090 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1091 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1092 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1093 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1094 | wl_list_for_each(state, &from->focus_list, link) |
| 1095 | if (state->keyboard_focus) |
| 1096 | animate_focus_change(shell, from, |
| 1097 | get_default_view(state->keyboard_focus), NULL); |
| 1098 | |
| 1099 | wl_list_for_each(state, &to->focus_list, link) |
| 1100 | if (state->keyboard_focus) |
| 1101 | animate_focus_change(shell, to, |
| 1102 | NULL, get_default_view(state->keyboard_focus)); |
| 1103 | } |
| 1104 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1105 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1106 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1107 | else |
| 1108 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1109 | |
| 1110 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1111 | } |
| 1112 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1113 | static bool |
| 1114 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1115 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1116 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1117 | struct wl_list *e; |
| 1118 | |
| 1119 | if (wl_list_empty(list)) |
| 1120 | return false; |
| 1121 | |
| 1122 | e = list->next; |
| 1123 | |
| 1124 | if (e->next != list) |
| 1125 | return false; |
| 1126 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1127 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1131 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1132 | struct shell_surface *shsurf, |
| 1133 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1134 | { |
| 1135 | struct workspace *from; |
| 1136 | struct workspace *to; |
| 1137 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1138 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1139 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1140 | |
| 1141 | if (workspace == shell->workspaces.current) |
| 1142 | return; |
| 1143 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1144 | view = get_default_view(shsurf->surface); |
| 1145 | if (!view) |
| 1146 | return; |
| 1147 | |
| 1148 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1149 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1150 | if (workspace >= shell->workspaces.num) |
| 1151 | workspace = shell->workspaces.num - 1; |
| 1152 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1153 | from = get_current_workspace(shell); |
| 1154 | to = get_workspace(shell, workspace); |
| 1155 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1156 | wl_list_remove(&view->layer_link); |
| 1157 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1158 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1159 | shell_surface_update_child_surface_layers(shsurf); |
| 1160 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1161 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1162 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1163 | if (!seat->keyboard) |
| 1164 | continue; |
| 1165 | |
| 1166 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1167 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1168 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1169 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1170 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1171 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1175 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1176 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1177 | unsigned int index) |
| 1178 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1179 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1180 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1181 | struct shell_surface *shsurf; |
| 1182 | struct workspace *from; |
| 1183 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1184 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1185 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1186 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1187 | view = get_default_view(surface); |
| 1188 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1189 | index == shell->workspaces.current || |
| 1190 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1191 | return; |
| 1192 | |
| 1193 | from = get_current_workspace(shell); |
| 1194 | to = get_workspace(shell, index); |
| 1195 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1196 | wl_list_remove(&view->layer_link); |
| 1197 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1198 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1199 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1200 | if (shsurf != NULL) |
| 1201 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1202 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1203 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1204 | drop_focus_state(shell, from, surface); |
| 1205 | |
| 1206 | if (shell->workspaces.anim_from == to && |
| 1207 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1208 | wl_list_remove(&to->layer.link); |
| 1209 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1210 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1211 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1212 | broadcast_current_workspace_state(shell); |
| 1213 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1214 | return; |
| 1215 | } |
| 1216 | |
| 1217 | if (shell->workspaces.anim_to != NULL) |
| 1218 | finish_workspace_change_animation(shell, |
| 1219 | shell->workspaces.anim_from, |
| 1220 | shell->workspaces.anim_to); |
| 1221 | |
| 1222 | if (workspace_is_empty(from) && |
| 1223 | workspace_has_only(to, surface)) |
| 1224 | update_workspace(shell, index, from, to); |
| 1225 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1226 | if (shsurf != NULL && |
| 1227 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1228 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1229 | &shsurf->workspace_transform.link); |
| 1230 | |
| 1231 | animate_workspace_change(shell, index, from, to); |
| 1232 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1233 | |
| 1234 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1235 | |
| 1236 | state = ensure_focus_state(shell, seat); |
| 1237 | if (state != NULL) |
| 1238 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | static void |
| 1242 | workspace_manager_move_surface(struct wl_client *client, |
| 1243 | struct wl_resource *resource, |
| 1244 | struct wl_resource *surface_resource, |
| 1245 | uint32_t workspace) |
| 1246 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1247 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1248 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1249 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1250 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1251 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1252 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1253 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1254 | shell_surface = get_shell_surface(main_surface); |
| 1255 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1256 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1257 | |
| 1258 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1262 | workspace_manager_move_surface, |
| 1263 | }; |
| 1264 | |
| 1265 | static void |
| 1266 | unbind_resource(struct wl_resource *resource) |
| 1267 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1268 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | static void |
| 1272 | bind_workspace_manager(struct wl_client *client, |
| 1273 | void *data, uint32_t version, uint32_t id) |
| 1274 | { |
| 1275 | struct desktop_shell *shell = data; |
| 1276 | struct wl_resource *resource; |
| 1277 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1278 | resource = wl_resource_create(client, |
| 1279 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1280 | |
| 1281 | if (resource == NULL) { |
| 1282 | weston_log("couldn't add workspace manager object"); |
| 1283 | return; |
| 1284 | } |
| 1285 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1286 | wl_resource_set_implementation(resource, |
| 1287 | &workspace_manager_implementation, |
| 1288 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1289 | wl_list_insert(&shell->workspaces.client_list, |
| 1290 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1291 | |
| 1292 | workspace_manager_send_state(resource, |
| 1293 | shell->workspaces.current, |
| 1294 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1295 | } |
| 1296 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1297 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1298 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1299 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1300 | { |
| 1301 | } |
| 1302 | |
| 1303 | static void |
| 1304 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1305 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1306 | struct weston_touch_move_grab *move = |
| 1307 | (struct weston_touch_move_grab *) container_of( |
| 1308 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1309 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1310 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1311 | shell_touch_grab_end(&move->base); |
| 1312 | free(move); |
| 1313 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | static void |
| 1317 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1318 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1319 | { |
| 1320 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1321 | struct shell_surface *shsurf = move->base.shsurf; |
| 1322 | struct weston_surface *es; |
| 1323 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1324 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1325 | |
| 1326 | if (!shsurf) |
| 1327 | return; |
| 1328 | |
| 1329 | es = shsurf->surface; |
| 1330 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1331 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1332 | |
| 1333 | weston_compositor_schedule_repaint(es->compositor); |
| 1334 | } |
| 1335 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1336 | static void |
| 1337 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1338 | { |
| 1339 | struct weston_touch_move_grab *move = |
| 1340 | (struct weston_touch_move_grab *) container_of( |
| 1341 | grab, struct shell_touch_grab, grab); |
| 1342 | |
| 1343 | shell_touch_grab_end(&move->base); |
| 1344 | free(move); |
| 1345 | } |
| 1346 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1347 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1348 | touch_move_grab_down, |
| 1349 | touch_move_grab_up, |
| 1350 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1351 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1352 | }; |
| 1353 | |
| 1354 | static int |
| 1355 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1356 | { |
| 1357 | struct weston_touch_move_grab *move; |
| 1358 | |
| 1359 | if (!shsurf) |
| 1360 | return -1; |
| 1361 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1362 | if (shsurf->state.fullscreen) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1363 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1364 | if (shsurf->grabbed) |
| 1365 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1366 | |
| 1367 | move = malloc(sizeof *move); |
| 1368 | if (!move) |
| 1369 | return -1; |
| 1370 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1371 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1372 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1373 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1374 | seat->touch->grab_y; |
| 1375 | |
| 1376 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1377 | seat->touch); |
| 1378 | |
| 1379 | return 0; |
| 1380 | } |
| 1381 | |
| 1382 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1383 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1384 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1388 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1389 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1390 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1391 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1392 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1393 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1394 | int dx, dy; |
| 1395 | |
| 1396 | weston_pointer_move(pointer, x, y); |
| 1397 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1398 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1399 | |
| 1400 | if (!shsurf) |
| 1401 | return; |
| 1402 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1403 | weston_view_set_position(shsurf->view, dx, dy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1404 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1405 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1409 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1410 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1411 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1412 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1413 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1414 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1415 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1416 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1417 | if (pointer->button_count == 0 && |
| 1418 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1419 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1420 | free(grab); |
| 1421 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1422 | } |
| 1423 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1424 | static void |
| 1425 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1426 | { |
| 1427 | struct shell_grab *shell_grab = |
| 1428 | container_of(grab, struct shell_grab, grab); |
| 1429 | |
| 1430 | shell_grab_end(shell_grab); |
| 1431 | free(grab); |
| 1432 | } |
| 1433 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1434 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1435 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1436 | move_grab_motion, |
| 1437 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1438 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1439 | }; |
| 1440 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1441 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1442 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1443 | { |
| 1444 | struct weston_move_grab *move; |
| 1445 | |
| 1446 | if (!shsurf) |
| 1447 | return -1; |
| 1448 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1449 | if (shsurf->grabbed) |
| 1450 | return 0; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1451 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1452 | return 0; |
| 1453 | |
| 1454 | move = malloc(sizeof *move); |
| 1455 | if (!move) |
| 1456 | return -1; |
| 1457 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1458 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1459 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1460 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1461 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1462 | |
| 1463 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1464 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1465 | |
| 1466 | return 0; |
| 1467 | } |
| 1468 | |
| 1469 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1470 | common_surface_move(struct wl_resource *resource, |
| 1471 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1472 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1473 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1474 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1475 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1476 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1477 | if (seat->pointer && |
| 1478 | seat->pointer->button_count > 0 && |
| 1479 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1480 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1481 | if ((surface == shsurf->surface) && |
| 1482 | (surface_move(shsurf, seat) < 0)) |
| 1483 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1484 | } else if (seat->touch && |
| 1485 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1486 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1487 | if ((surface == shsurf->surface) && |
| 1488 | (surface_touch_move(shsurf, seat) < 0)) |
| 1489 | wl_resource_post_no_memory(resource); |
| 1490 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1491 | } |
| 1492 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1493 | static void |
| 1494 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1495 | struct wl_resource *seat_resource, uint32_t serial) |
| 1496 | { |
| 1497 | common_surface_move(resource, seat_resource, serial); |
| 1498 | } |
| 1499 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1500 | struct weston_resize_grab { |
| 1501 | struct shell_grab base; |
| 1502 | uint32_t edges; |
| 1503 | int32_t width, height; |
| 1504 | }; |
| 1505 | |
| 1506 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1507 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1508 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1509 | { |
| 1510 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1511 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1512 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1513 | int32_t width, height; |
| 1514 | wl_fixed_t from_x, from_y; |
| 1515 | wl_fixed_t to_x, to_y; |
| 1516 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1517 | weston_pointer_move(pointer, x, y); |
| 1518 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1519 | if (!shsurf) |
| 1520 | return; |
| 1521 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1522 | weston_view_from_global_fixed(shsurf->view, |
| 1523 | pointer->grab_x, pointer->grab_y, |
| 1524 | &from_x, &from_y); |
| 1525 | weston_view_from_global_fixed(shsurf->view, |
| 1526 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1527 | |
| 1528 | width = resize->width; |
| 1529 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1530 | width += wl_fixed_to_int(from_x - to_x); |
| 1531 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1532 | width += wl_fixed_to_int(to_x - from_x); |
| 1533 | } |
| 1534 | |
| 1535 | height = resize->height; |
| 1536 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1537 | height += wl_fixed_to_int(from_y - to_y); |
| 1538 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1539 | height += wl_fixed_to_int(to_y - from_y); |
| 1540 | } |
| 1541 | |
| 1542 | shsurf->client->send_configure(shsurf->surface, |
| 1543 | resize->edges, width, height); |
| 1544 | } |
| 1545 | |
| 1546 | static void |
| 1547 | send_configure(struct weston_surface *surface, |
| 1548 | uint32_t edges, int32_t width, int32_t height) |
| 1549 | { |
| 1550 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1551 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1552 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1553 | edges, width, height); |
| 1554 | } |
| 1555 | |
| 1556 | static const struct weston_shell_client shell_client = { |
| 1557 | send_configure |
| 1558 | }; |
| 1559 | |
| 1560 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1561 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1562 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1563 | { |
| 1564 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1565 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1566 | enum wl_pointer_button_state state = state_w; |
| 1567 | |
| 1568 | if (pointer->button_count == 0 && |
| 1569 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1570 | shell_grab_end(&resize->base); |
| 1571 | free(grab); |
| 1572 | } |
| 1573 | } |
| 1574 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1575 | static void |
| 1576 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1577 | { |
| 1578 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1579 | |
| 1580 | shell_grab_end(&resize->base); |
| 1581 | free(grab); |
| 1582 | } |
| 1583 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1584 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1585 | noop_grab_focus, |
| 1586 | resize_grab_motion, |
| 1587 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1588 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1589 | }; |
| 1590 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1591 | /* |
| 1592 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1593 | * in the surface coordinates system. */ |
| 1594 | static void |
| 1595 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1596 | int32_t *y, int32_t *w, int32_t *h) { |
| 1597 | pixman_region32_t region; |
| 1598 | pixman_box32_t *box; |
| 1599 | struct weston_subsurface *subsurface; |
| 1600 | |
| 1601 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1602 | surface->width, |
| 1603 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1604 | |
| 1605 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1606 | pixman_region32_union_rect(®ion, ®ion, |
| 1607 | subsurface->position.x, |
| 1608 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1609 | subsurface->surface->width, |
| 1610 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | box = pixman_region32_extents(®ion); |
| 1614 | if (x) |
| 1615 | *x = box->x1; |
| 1616 | if (y) |
| 1617 | *y = box->y1; |
| 1618 | if (w) |
| 1619 | *w = box->x2 - box->x1; |
| 1620 | if (h) |
| 1621 | *h = box->y2 - box->y1; |
| 1622 | |
| 1623 | pixman_region32_fini(®ion); |
| 1624 | } |
| 1625 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1626 | static int |
| 1627 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1628 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1629 | { |
| 1630 | struct weston_resize_grab *resize; |
| 1631 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1632 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1633 | return 0; |
| 1634 | |
| 1635 | if (edges == 0 || edges > 15 || |
| 1636 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1637 | return 0; |
| 1638 | |
| 1639 | resize = malloc(sizeof *resize); |
| 1640 | if (!resize) |
| 1641 | return -1; |
| 1642 | |
| 1643 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1644 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1645 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1646 | |
| 1647 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1648 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1649 | |
| 1650 | return 0; |
| 1651 | } |
| 1652 | |
| 1653 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1654 | common_surface_resize(struct wl_resource *resource, |
| 1655 | struct wl_resource *seat_resource, uint32_t serial, |
| 1656 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1657 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1658 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1659 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1660 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1661 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1662 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1663 | return; |
| 1664 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1665 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1666 | if (seat->pointer->button_count == 0 || |
| 1667 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1668 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1669 | return; |
| 1670 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1671 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1672 | wl_resource_post_no_memory(resource); |
| 1673 | } |
| 1674 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1675 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1676 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1677 | struct wl_resource *seat_resource, uint32_t serial, |
| 1678 | uint32_t edges) |
| 1679 | { |
| 1680 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1681 | } |
| 1682 | |
| 1683 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1684 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1685 | |
| 1686 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1687 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1688 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1689 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1690 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1691 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1692 | wl_fixed_t sx, sy; |
| 1693 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1694 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1695 | pointer->x, pointer->y, |
| 1696 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1697 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1698 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1699 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1703 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1704 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1705 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1706 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1707 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1708 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1709 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1710 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1711 | uint32_t time, uint32_t button, uint32_t state) |
| 1712 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1713 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1714 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1715 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1716 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1717 | if (shsurf && button == BTN_LEFT && state) { |
| 1718 | activate(shsurf->shell, shsurf->surface, seat); |
| 1719 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1720 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1721 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1722 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1723 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1724 | } |
| 1725 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1726 | static void |
| 1727 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1728 | { |
| 1729 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1730 | |
| 1731 | shell_grab_end(grab); |
| 1732 | free(grab); |
| 1733 | } |
| 1734 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1735 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1736 | busy_cursor_grab_focus, |
| 1737 | busy_cursor_grab_motion, |
| 1738 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1739 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1740 | }; |
| 1741 | |
| 1742 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1743 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1744 | { |
| 1745 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1746 | |
| 1747 | grab = malloc(sizeof *grab); |
| 1748 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1749 | return; |
| 1750 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1751 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1752 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1753 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1754 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1755 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1756 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1757 | { |
| 1758 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1759 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1760 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1761 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1762 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1763 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1764 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1765 | } |
| 1766 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1767 | static void |
| 1768 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1769 | { |
| 1770 | if (!shsurf || !shsurf->ping_timer) |
| 1771 | return; |
| 1772 | |
| 1773 | if (shsurf->ping_timer->source) |
| 1774 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1775 | |
| 1776 | free(shsurf->ping_timer); |
| 1777 | shsurf->ping_timer = NULL; |
| 1778 | } |
| 1779 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1780 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1781 | ping_timeout_handler(void *data) |
| 1782 | { |
| 1783 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1784 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1785 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1786 | /* Client is not responding */ |
| 1787 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1788 | |
| 1789 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Emilio Pozuelo Monfort | 3d0fc76 | 2013-11-22 16:21:20 +0100 | [diff] [blame] | 1790 | if (seat->pointer->focus && |
| 1791 | seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1792 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1793 | |
| 1794 | return 1; |
| 1795 | } |
| 1796 | |
| 1797 | static void |
| 1798 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1799 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1800 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1801 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1802 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1803 | |
| 1804 | if (!shsurf) |
| 1805 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1806 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1807 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1808 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1809 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1810 | return; |
| 1811 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1812 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1813 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1814 | if (!shsurf->ping_timer) |
| 1815 | return; |
| 1816 | |
| 1817 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1818 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1819 | shsurf->ping_timer->source = |
| 1820 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1821 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1822 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1823 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 1824 | wl_shell_surface_send_ping(shsurf->resource, serial); |
| 1825 | else if (shell_surface_is_xdg_surface(shsurf)) |
| 1826 | xdg_surface_send_ping(shsurf->resource, serial); |
| 1827 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 1828 | xdg_popup_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1833 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1834 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1835 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1836 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1837 | struct weston_compositor *compositor; |
| 1838 | struct shell_surface *shsurf; |
| 1839 | uint32_t serial; |
| 1840 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1841 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1842 | return; |
| 1843 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1844 | compositor = view->surface->compositor; |
| 1845 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1846 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1847 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1848 | set_busy_cursor(shsurf, pointer); |
| 1849 | } else { |
| 1850 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1851 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1856 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1857 | { |
| 1858 | struct wl_listener *listener; |
| 1859 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1860 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1861 | return; |
| 1862 | |
| 1863 | listener = malloc(sizeof *listener); |
| 1864 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1865 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1869 | xdg_surface_set_transient_for(struct wl_client *client, |
| 1870 | struct wl_resource *resource, |
| 1871 | struct wl_resource *parent_resource) |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1872 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1873 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1874 | struct weston_surface *parent = |
| 1875 | wl_resource_get_user_data(parent_resource); |
| 1876 | |
| 1877 | shell_surface_set_parent(shsurf, parent); |
| 1878 | } |
| 1879 | |
| 1880 | static void |
| 1881 | surface_pong(struct shell_surface *shsurf, uint32_t serial) |
| 1882 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1883 | struct weston_compositor *ec = shsurf->surface->compositor; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1884 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1885 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1886 | if (shsurf->ping_timer == NULL) |
| 1887 | /* Just ignore unsolicited pong. */ |
| 1888 | return; |
| 1889 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1890 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1891 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 1892 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 1893 | if(seat->pointer) |
| 1894 | end_busy_cursor(shsurf, seat->pointer); |
| 1895 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1896 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1897 | } |
| 1898 | } |
| 1899 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1900 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1901 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 1902 | uint32_t serial) |
| 1903 | { |
| 1904 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 1905 | |
| 1906 | surface_pong(shsurf, serial); |
| 1907 | |
| 1908 | } |
| 1909 | |
| 1910 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1911 | set_title(struct shell_surface *shsurf, const char *title) |
| 1912 | { |
| 1913 | free(shsurf->title); |
| 1914 | shsurf->title = strdup(title); |
| 1915 | } |
| 1916 | |
| 1917 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1918 | shell_surface_set_title(struct wl_client *client, |
| 1919 | struct wl_resource *resource, const char *title) |
| 1920 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1921 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1922 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1923 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | static void |
| 1927 | shell_surface_set_class(struct wl_client *client, |
| 1928 | struct wl_resource *resource, const char *class) |
| 1929 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1930 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1931 | |
| 1932 | free(shsurf->class); |
| 1933 | shsurf->class = strdup(class); |
| 1934 | } |
| 1935 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1936 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1937 | restore_output_mode(struct weston_output *output) |
| 1938 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1939 | if (output->current_mode != output->original_mode || |
| 1940 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1941 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1942 | output->original_mode, |
| 1943 | output->original_scale, |
| 1944 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | static void |
| 1948 | restore_all_output_modes(struct weston_compositor *compositor) |
| 1949 | { |
| 1950 | struct weston_output *output; |
| 1951 | |
| 1952 | wl_list_for_each(output, &compositor->output_list, link) |
| 1953 | restore_output_mode(output); |
| 1954 | } |
| 1955 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1956 | static int |
| 1957 | get_output_panel_height(struct desktop_shell *shell, |
| 1958 | struct weston_output *output) |
| 1959 | { |
| 1960 | struct weston_view *view; |
| 1961 | int panel_height = 0; |
| 1962 | |
| 1963 | if (!output) |
| 1964 | return 0; |
| 1965 | |
| 1966 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 1967 | if (view->surface->output == output) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1968 | panel_height = view->surface->height; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1969 | break; |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | return panel_height; |
| 1974 | } |
| 1975 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1976 | /* The surface will be inserted into the list immediately after the link |
| 1977 | * returned by this function (i.e. will be stacked immediately above the |
| 1978 | * returned link). */ |
| 1979 | static struct wl_list * |
| 1980 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 1981 | { |
| 1982 | struct workspace *ws; |
| 1983 | |
| 1984 | switch (shsurf->type) { |
Philip Withnall | da704d9 | 2013-11-25 18:01:46 +0000 | [diff] [blame] | 1985 | case SHELL_SURFACE_POPUP: { |
| 1986 | /* Popups should go at the front of the workspace of their |
| 1987 | * parent surface, rather than just in front of the parent. This |
| 1988 | * fixes the situation where there are two top-level windows: |
| 1989 | * - Above |
| 1990 | * - Below |
| 1991 | * and a pop-up menu is created for 'Below'. We want: |
| 1992 | * - Popup |
| 1993 | * - Above |
| 1994 | * - Below |
| 1995 | * not: |
| 1996 | * - Above |
| 1997 | * - Popup |
| 1998 | * - Below |
| 1999 | */ |
| 2000 | struct shell_surface *parent_shsurf; |
| 2001 | |
| 2002 | parent_shsurf = get_shell_surface(shsurf->parent); |
| 2003 | if (parent_shsurf != NULL) |
| 2004 | return shell_surface_calculate_layer_link(parent_shsurf); |
| 2005 | |
| 2006 | break; |
| 2007 | } |
| 2008 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2009 | case SHELL_SURFACE_TOPLEVEL: { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2010 | if (shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2011 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2012 | } else if (shsurf->parent) { |
| 2013 | /* Move the surface to its parent layer so that |
| 2014 | * surfaces which are transient for fullscreen surfaces |
| 2015 | * don't get hidden by the fullscreen surfaces. |
| 2016 | * However, unlike popups, transient surfaces are |
| 2017 | * stacked in front of their parent but not in front of |
| 2018 | * other surfaces of the same type. */ |
| 2019 | struct weston_view *parent; |
| 2020 | |
| 2021 | /* TODO: Handle a parent with multiple views */ |
| 2022 | parent = get_default_view(shsurf->parent); |
| 2023 | if (parent) |
| 2024 | return parent->layer_link.prev; |
| 2025 | } |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2026 | break; |
| 2027 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2028 | |
| 2029 | case SHELL_SURFACE_XWAYLAND: |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2030 | case SHELL_SURFACE_NONE: |
| 2031 | default: |
| 2032 | /* Go to the fallback, below. */ |
| 2033 | break; |
| 2034 | } |
| 2035 | |
| 2036 | /* Move the surface to a normal workspace layer so that surfaces |
| 2037 | * which were previously fullscreen or transient are no longer |
| 2038 | * rendered on top. */ |
| 2039 | ws = get_current_workspace(shsurf->shell); |
| 2040 | return &ws->layer.view_list; |
| 2041 | } |
| 2042 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2043 | static void |
| 2044 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2045 | { |
| 2046 | struct shell_surface *child; |
| 2047 | |
| 2048 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2049 | * stacked above shsurf. */ |
| 2050 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2051 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
| 2052 | weston_view_geometry_dirty(child->view); |
| 2053 | wl_list_remove(&child->view->layer_link); |
| 2054 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2055 | &child->view->layer_link); |
| 2056 | weston_view_geometry_dirty(child->view); |
| 2057 | weston_surface_damage(child->surface); |
| 2058 | |
| 2059 | /* Recurse. We don’t expect this to recurse very far (if |
| 2060 | * at all) because that would imply we have transient |
| 2061 | * (or popup) children of transient surfaces, which |
| 2062 | * would be unusual. */ |
| 2063 | shell_surface_update_child_surface_layers(child); |
| 2064 | } |
| 2065 | } |
| 2066 | } |
| 2067 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2068 | /* Update the surface’s layer. Mark both the old and new views as having dirty |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2069 | * geometry to ensure the changes are redrawn. |
| 2070 | * |
| 2071 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2072 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2073 | static void |
| 2074 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2075 | { |
| 2076 | struct wl_list *new_layer_link; |
| 2077 | |
| 2078 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2079 | |
| 2080 | if (new_layer_link == &shsurf->view->layer_link) |
| 2081 | return; |
| 2082 | |
| 2083 | weston_view_geometry_dirty(shsurf->view); |
| 2084 | wl_list_remove(&shsurf->view->layer_link); |
| 2085 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2086 | weston_view_geometry_dirty(shsurf->view); |
| 2087 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2088 | |
| 2089 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2092 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2093 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2094 | struct weston_surface *parent) |
| 2095 | { |
| 2096 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2097 | |
| 2098 | wl_list_remove(&shsurf->children_link); |
| 2099 | wl_list_init(&shsurf->children_link); |
| 2100 | |
| 2101 | /* Insert into the parent surface’s child list. */ |
| 2102 | if (parent != NULL) { |
| 2103 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2104 | if (parent_shsurf != NULL) |
| 2105 | wl_list_insert(&parent_shsurf->children_list, |
| 2106 | &shsurf->children_link); |
| 2107 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2111 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2112 | struct weston_output *output) |
| 2113 | { |
| 2114 | struct weston_surface *es = shsurf->surface; |
| 2115 | |
| 2116 | /* get the default output, if the client set it as NULL |
| 2117 | check whether the ouput is available */ |
| 2118 | if (output) |
| 2119 | shsurf->output = output; |
| 2120 | else if (es->output) |
| 2121 | shsurf->output = es->output; |
| 2122 | else |
| 2123 | shsurf->output = get_default_output(es->compositor); |
| 2124 | } |
| 2125 | |
| 2126 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2127 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2128 | { |
| 2129 | shsurf->next_state.maximized = false; |
| 2130 | shsurf->next_state.fullscreen = false; |
| 2131 | |
| 2132 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2133 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2134 | shsurf->state_changed = true; |
| 2135 | } |
| 2136 | |
| 2137 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2138 | set_toplevel(struct shell_surface *shsurf) |
| 2139 | { |
| 2140 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2141 | |
| 2142 | /* The layer_link is updated in set_surface_type(), |
| 2143 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | static void |
| 2147 | shell_surface_set_toplevel(struct wl_client *client, |
| 2148 | struct wl_resource *resource) |
| 2149 | { |
| 2150 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2151 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2152 | shell_surface_set_parent(surface, NULL); |
| 2153 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2154 | surface_clear_next_states(surface); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2155 | set_toplevel(surface); |
| 2156 | } |
| 2157 | |
| 2158 | static void |
| 2159 | set_transient(struct shell_surface *shsurf, |
| 2160 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2161 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2162 | assert(parent != NULL); |
| 2163 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2164 | shsurf->transient.x = x; |
| 2165 | shsurf->transient.y = y; |
| 2166 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2167 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2168 | shsurf->next_state.relative = true; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2169 | |
| 2170 | /* The layer_link is updated in set_surface_type(), |
| 2171 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | static void |
| 2175 | shell_surface_set_transient(struct wl_client *client, |
| 2176 | struct wl_resource *resource, |
| 2177 | struct wl_resource *parent_resource, |
| 2178 | int x, int y, uint32_t flags) |
| 2179 | { |
| 2180 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2181 | struct weston_surface *parent = |
| 2182 | wl_resource_get_user_data(parent_resource); |
| 2183 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2184 | shell_surface_set_parent(shsurf, parent); |
| 2185 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2186 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2187 | set_transient(shsurf, parent, x, y, flags); |
| 2188 | } |
| 2189 | |
| 2190 | static void |
| 2191 | set_fullscreen(struct shell_surface *shsurf, |
| 2192 | uint32_t method, |
| 2193 | uint32_t framerate, |
| 2194 | struct weston_output *output) |
| 2195 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2196 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2197 | |
| 2198 | shsurf->fullscreen_output = shsurf->output; |
| 2199 | shsurf->fullscreen.type = method; |
| 2200 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2201 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2202 | shsurf->next_type = shsurf->type; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2203 | |
| 2204 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2205 | shsurf->output->width, |
| 2206 | shsurf->output->height); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2207 | |
| 2208 | /* The layer_link is updated in set_surface_type(), |
| 2209 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | static void |
| 2213 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2214 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2215 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2216 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2217 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2218 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2219 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2220 | shsurf->fullscreen_output = NULL; |
| 2221 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2222 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2223 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2224 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2225 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2226 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2227 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2228 | if (shsurf->fullscreen.black_view) |
| 2229 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2230 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2231 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2232 | weston_view_set_position(shsurf->view, |
| 2233 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2234 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2235 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2236 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2237 | shsurf->saved_rotation_valid = false; |
| 2238 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2239 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2240 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2241 | } |
| 2242 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2243 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2244 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2245 | struct wl_resource *resource, |
| 2246 | uint32_t method, |
| 2247 | uint32_t framerate, |
| 2248 | struct wl_resource *output_resource) |
| 2249 | { |
| 2250 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2251 | struct weston_output *output; |
| 2252 | |
| 2253 | if (output_resource) |
| 2254 | output = wl_resource_get_user_data(output_resource); |
| 2255 | else |
| 2256 | output = NULL; |
| 2257 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2258 | shell_surface_set_parent(shsurf, NULL); |
| 2259 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2260 | surface_clear_next_states(shsurf); |
| 2261 | shsurf->next_state.fullscreen = true; |
| 2262 | shsurf->state_changed = true; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2263 | set_fullscreen(shsurf, method, framerate, output); |
| 2264 | } |
| 2265 | |
| 2266 | static void |
| 2267 | set_popup(struct shell_surface *shsurf, |
| 2268 | struct weston_surface *parent, |
| 2269 | struct weston_seat *seat, |
| 2270 | uint32_t serial, |
| 2271 | int32_t x, |
| 2272 | int32_t y) |
| 2273 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2274 | assert(parent != NULL); |
| 2275 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2276 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2277 | shsurf->popup.serial = serial; |
| 2278 | shsurf->popup.x = x; |
| 2279 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2280 | |
Philip Withnall | b995e1d | 2013-11-25 18:01:39 +0000 | [diff] [blame] | 2281 | shsurf->next_type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | static void |
| 2285 | shell_surface_set_popup(struct wl_client *client, |
| 2286 | struct wl_resource *resource, |
| 2287 | struct wl_resource *seat_resource, |
| 2288 | uint32_t serial, |
| 2289 | struct wl_resource *parent_resource, |
| 2290 | int32_t x, int32_t y, uint32_t flags) |
| 2291 | { |
| 2292 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2293 | struct weston_surface *parent = |
| 2294 | wl_resource_get_user_data(parent_resource); |
| 2295 | |
| 2296 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2297 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2298 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2299 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2300 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2301 | wl_resource_get_user_data(seat_resource), |
| 2302 | serial, x, y); |
| 2303 | } |
| 2304 | |
| 2305 | static void |
| 2306 | set_maximized(struct shell_surface *shsurf, |
| 2307 | struct weston_output *output) |
| 2308 | { |
| 2309 | struct desktop_shell *shell; |
| 2310 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2311 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2312 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2313 | |
| 2314 | shell = shell_surface_get_shell(shsurf); |
| 2315 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2316 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2317 | |
| 2318 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2319 | shsurf->output->width, |
| 2320 | shsurf->output->height - panel_height); |
| 2321 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2322 | shsurf->next_type = shsurf->type; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | static void |
| 2326 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2327 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2328 | /* undo all maximized things here */ |
| 2329 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2330 | weston_view_set_position(shsurf->view, |
| 2331 | shsurf->saved_x, |
| 2332 | shsurf->saved_y); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2333 | |
| 2334 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2335 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2336 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2337 | shsurf->saved_rotation_valid = false; |
| 2338 | } |
| 2339 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2340 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2341 | } |
| 2342 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2343 | static void |
| 2344 | shell_surface_set_maximized(struct wl_client *client, |
| 2345 | struct wl_resource *resource, |
| 2346 | struct wl_resource *output_resource) |
| 2347 | { |
| 2348 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2349 | struct weston_output *output; |
| 2350 | |
| 2351 | if (output_resource) |
| 2352 | output = wl_resource_get_user_data(output_resource); |
| 2353 | else |
| 2354 | output = NULL; |
| 2355 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2356 | shell_surface_set_parent(shsurf, NULL); |
| 2357 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2358 | surface_clear_next_states(shsurf); |
| 2359 | shsurf->next_state.maximized = true; |
| 2360 | shsurf->state_changed = true; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2361 | set_maximized(shsurf, output); |
| 2362 | } |
| 2363 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2364 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2365 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2366 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2367 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2368 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2369 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2370 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2371 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2372 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2373 | |
| 2374 | surface->type = SHELL_SURFACE_NONE; |
| 2375 | return 0; |
| 2376 | } |
| 2377 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2378 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2379 | set_full_output(struct shell_surface *shsurf) |
| 2380 | { |
| 2381 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2382 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2383 | shsurf->saved_width = shsurf->surface->width; |
| 2384 | shsurf->saved_height = shsurf->surface->height; |
| 2385 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2386 | shsurf->saved_position_valid = true; |
| 2387 | |
| 2388 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2389 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2390 | wl_list_init(&shsurf->rotation.transform.link); |
| 2391 | weston_view_geometry_dirty(shsurf->view); |
| 2392 | shsurf->saved_rotation_valid = true; |
| 2393 | } |
| 2394 | } |
| 2395 | |
| 2396 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2397 | set_surface_type(struct shell_surface *shsurf) |
| 2398 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2399 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2400 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2401 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2402 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2403 | |
| 2404 | shsurf->type = shsurf->next_type; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2405 | shsurf->state = shsurf->next_state; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2406 | shsurf->next_type = SHELL_SURFACE_NONE; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2407 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2408 | |
| 2409 | switch (shsurf->type) { |
| 2410 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2411 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2412 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2413 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2414 | weston_view_set_position(shsurf->view, |
| 2415 | pev->geometry.x + shsurf->transient.x, |
| 2416 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2417 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2418 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2419 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2420 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2421 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2422 | break; |
| 2423 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2424 | case SHELL_SURFACE_POPUP: |
| 2425 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2426 | default: |
| 2427 | break; |
| 2428 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2429 | |
| 2430 | /* Update the surface’s layer. */ |
| 2431 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2432 | } |
| 2433 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2434 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2435 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2436 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2437 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2438 | } |
| 2439 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2440 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2441 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy); |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2442 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2443 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2444 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2445 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2446 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2447 | { |
| 2448 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2449 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2450 | |
| 2451 | surface = weston_surface_create(ec); |
| 2452 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2453 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2454 | return NULL; |
| 2455 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2456 | view = weston_view_create(surface); |
| 2457 | if (surface == NULL) { |
| 2458 | weston_log("no memory\n"); |
| 2459 | weston_surface_destroy(surface); |
| 2460 | return NULL; |
| 2461 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2462 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2463 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2464 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2465 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2466 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2467 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2468 | pixman_region32_fini(&surface->input); |
| 2469 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2470 | |
Xiong Zhang | becf5a3 | 2013-11-29 11:18:14 +0800 | [diff] [blame] | 2471 | surface->width = w; |
| 2472 | surface->height = h; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2473 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2474 | |
| 2475 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2476 | } |
| 2477 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2478 | static void |
| 2479 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2480 | { |
| 2481 | struct weston_output *output = shsurf->fullscreen_output; |
| 2482 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2483 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2484 | |
| 2485 | if (!shsurf->fullscreen.black_view) |
| 2486 | shsurf->fullscreen.black_view = |
| 2487 | create_black_surface(shsurf->surface->compositor, |
| 2488 | shsurf->surface, |
| 2489 | output->x, output->y, |
| 2490 | output->width, |
| 2491 | output->height); |
| 2492 | |
| 2493 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2494 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2495 | wl_list_insert(&shsurf->view->layer_link, |
| 2496 | &shsurf->fullscreen.black_view->layer_link); |
| 2497 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2498 | weston_surface_damage(shsurf->surface); |
| 2499 | } |
| 2500 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2501 | /* Create black surface and append it to the associated fullscreen surface. |
| 2502 | * Handle size dismatch and positioning according to the method. */ |
| 2503 | static void |
| 2504 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2505 | { |
| 2506 | struct weston_output *output = shsurf->fullscreen_output; |
| 2507 | struct weston_surface *surface = shsurf->surface; |
| 2508 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2509 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2510 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2511 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2512 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2513 | restore_output_mode(output); |
| 2514 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2515 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2516 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2517 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2518 | &surf_width, &surf_height); |
| 2519 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2520 | switch (shsurf->fullscreen.type) { |
| 2521 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2522 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2523 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2524 | break; |
| 2525 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2526 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2527 | if (output->width == surf_width && |
| 2528 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2529 | weston_view_set_position(shsurf->view, |
| 2530 | output->x - surf_x, |
| 2531 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2532 | break; |
| 2533 | } |
| 2534 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2535 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2536 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2537 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2538 | output_aspect = (float) output->width / |
| 2539 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2540 | /* XXX: Use surf_width and surf_height here? */ |
| 2541 | surface_aspect = (float) surface->width / |
| 2542 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2543 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2544 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2545 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2546 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2547 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2548 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2549 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2550 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2551 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2552 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2553 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2554 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2555 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2556 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2557 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2558 | break; |
| 2559 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2560 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2561 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2562 | surf_width * surface->buffer_viewport.scale, |
| 2563 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2564 | shsurf->fullscreen.framerate}; |
| 2565 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2566 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2567 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2568 | weston_view_set_position(shsurf->view, |
| 2569 | output->x - surf_x, |
| 2570 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2571 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2572 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2573 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2574 | output->x - surf_x, |
| 2575 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2576 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2577 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2578 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2579 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2580 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2581 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2582 | break; |
| 2583 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2584 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2585 | break; |
| 2586 | default: |
| 2587 | break; |
| 2588 | } |
| 2589 | } |
| 2590 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2591 | static void |
| 2592 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2593 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2594 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2595 | } |
| 2596 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2597 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2598 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2599 | { |
| 2600 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2601 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2602 | shsurf->transient.x = x; |
| 2603 | shsurf->transient.y = y; |
| 2604 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2605 | |
| 2606 | shell_surface_set_parent(shsurf, NULL); |
| 2607 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2608 | shsurf->next_type = SHELL_SURFACE_XWAYLAND; |
| 2609 | } |
| 2610 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2611 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2612 | |
| 2613 | static void |
| 2614 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2615 | { |
| 2616 | struct shell_seat *shseat = |
| 2617 | container_of(listener, |
| 2618 | struct shell_seat, seat_destroy_listener); |
| 2619 | struct shell_surface *shsurf, *prev = NULL; |
| 2620 | |
| 2621 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2622 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2623 | shseat->popup_grab.client = NULL; |
| 2624 | |
| 2625 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2626 | shsurf->popup.shseat = NULL; |
| 2627 | if (prev) { |
| 2628 | wl_list_init(&prev->popup.grab_link); |
| 2629 | } |
| 2630 | prev = shsurf; |
| 2631 | } |
| 2632 | wl_list_init(&prev->popup.grab_link); |
| 2633 | } |
| 2634 | |
| 2635 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2636 | free(shseat); |
| 2637 | } |
| 2638 | |
| 2639 | static struct shell_seat * |
| 2640 | create_shell_seat(struct weston_seat *seat) |
| 2641 | { |
| 2642 | struct shell_seat *shseat; |
| 2643 | |
| 2644 | shseat = calloc(1, sizeof *shseat); |
| 2645 | if (!shseat) { |
| 2646 | weston_log("no memory to allocate shell seat\n"); |
| 2647 | return NULL; |
| 2648 | } |
| 2649 | |
| 2650 | shseat->seat = seat; |
| 2651 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2652 | |
| 2653 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2654 | wl_signal_add(&seat->destroy_signal, |
| 2655 | &shseat->seat_destroy_listener); |
| 2656 | |
| 2657 | return shseat; |
| 2658 | } |
| 2659 | |
| 2660 | static struct shell_seat * |
| 2661 | get_shell_seat(struct weston_seat *seat) |
| 2662 | { |
| 2663 | struct wl_listener *listener; |
| 2664 | |
| 2665 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2666 | if (listener == NULL) |
| 2667 | return create_shell_seat(seat); |
| 2668 | |
| 2669 | return container_of(listener, |
| 2670 | struct shell_seat, seat_destroy_listener); |
| 2671 | } |
| 2672 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2673 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2674 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2675 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2676 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2677 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2678 | struct shell_seat *shseat = |
| 2679 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2680 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2681 | wl_fixed_t sx, sy; |
| 2682 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2683 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2684 | pointer->x, pointer->y, |
| 2685 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2686 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2687 | if (view && view->surface->resource && |
| 2688 | wl_resource_get_client(view->surface->resource) == client) { |
| 2689 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2690 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2691 | weston_pointer_set_focus(pointer, NULL, |
| 2692 | wl_fixed_from_int(0), |
| 2693 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2694 | } |
| 2695 | } |
| 2696 | |
| 2697 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2698 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2699 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2700 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2701 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2702 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2703 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2704 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2705 | weston_pointer_move(pointer, x, y); |
| 2706 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2707 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2708 | weston_view_from_global_fixed(pointer->focus, |
| 2709 | pointer->x, pointer->y, |
| 2710 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2711 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2712 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2716 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2717 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2718 | { |
| 2719 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2720 | struct shell_seat *shseat = |
| 2721 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2722 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2723 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2724 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2725 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2726 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2727 | resource_list = &grab->pointer->focus_resource_list; |
| 2728 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2729 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2730 | wl_resource_for_each(resource, resource_list) { |
| 2731 | wl_pointer_send_button(resource, serial, |
| 2732 | time, button, state); |
| 2733 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2734 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2735 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2736 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2737 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2738 | } |
| 2739 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2740 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2741 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2742 | } |
| 2743 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2744 | static void |
| 2745 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2746 | { |
| 2747 | popup_grab_end(grab->pointer); |
| 2748 | } |
| 2749 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2750 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2751 | popup_grab_focus, |
| 2752 | popup_grab_motion, |
| 2753 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2754 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2755 | }; |
| 2756 | |
| 2757 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2758 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 2759 | { |
| 2760 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2761 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 2762 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 2763 | xdg_popup_send_popup_done(shsurf->resource, |
| 2764 | shsurf->popup.serial); |
| 2765 | } |
| 2766 | |
| 2767 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2768 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2769 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2770 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2771 | struct shell_seat *shseat = |
| 2772 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2773 | struct shell_surface *shsurf; |
| 2774 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2775 | |
| 2776 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2777 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2778 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2779 | shseat->popup_grab.grab.interface = NULL; |
| 2780 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2781 | /* Send the popup_done event to all the popups open */ |
| 2782 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2783 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2784 | shsurf->popup.shseat = NULL; |
| 2785 | if (prev) { |
| 2786 | wl_list_init(&prev->popup.grab_link); |
| 2787 | } |
| 2788 | prev = shsurf; |
| 2789 | } |
| 2790 | wl_list_init(&prev->popup.grab_link); |
| 2791 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2792 | } |
| 2793 | } |
| 2794 | |
| 2795 | static void |
| 2796 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2797 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2798 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2799 | |
| 2800 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2801 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2802 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2803 | /* We must make sure here that this popup was opened after |
| 2804 | * a mouse press, and not just by moving around with other |
| 2805 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2806 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2807 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2808 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2809 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2810 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2811 | } else { |
| 2812 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2813 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | static void |
| 2817 | remove_popup_grab(struct shell_surface *shsurf) |
| 2818 | { |
| 2819 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2820 | |
| 2821 | wl_list_remove(&shsurf->popup.grab_link); |
| 2822 | wl_list_init(&shsurf->popup.grab_link); |
| 2823 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2824 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2825 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2826 | } |
| 2827 | } |
| 2828 | |
| 2829 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2830 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2831 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2832 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2833 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2834 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2835 | shsurf->surface->output = parent_view->output; |
| 2836 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2837 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2838 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2839 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2840 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2841 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2842 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2843 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2844 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2845 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2846 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2847 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2848 | } |
| 2849 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2850 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2851 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2852 | shell_surface_move, |
| 2853 | shell_surface_resize, |
| 2854 | shell_surface_set_toplevel, |
| 2855 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2856 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2857 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2858 | shell_surface_set_maximized, |
| 2859 | shell_surface_set_title, |
| 2860 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2861 | }; |
| 2862 | |
| 2863 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2864 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2865 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2866 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2867 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2868 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2869 | remove_popup_grab(shsurf); |
| 2870 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2871 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2872 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2873 | shell_surface_is_top_fullscreen(shsurf)) |
| 2874 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2875 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2876 | if (shsurf->fullscreen.black_view) |
| 2877 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2878 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2879 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2880 | * we can always remove the listener. |
| 2881 | */ |
| 2882 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2883 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2884 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2885 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2886 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2887 | weston_view_destroy(shsurf->view); |
| 2888 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2889 | wl_list_remove(&shsurf->children_link); |
| 2890 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2891 | wl_list_remove(&shsurf->link); |
| 2892 | free(shsurf); |
| 2893 | } |
| 2894 | |
| 2895 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2896 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2897 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2898 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2899 | |
| 2900 | destroy_shell_surface(shsurf); |
| 2901 | } |
| 2902 | |
| 2903 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2904 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2905 | { |
| 2906 | struct shell_surface *shsurf = container_of(listener, |
| 2907 | struct shell_surface, |
| 2908 | surface_destroy_listener); |
| 2909 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2910 | if (shsurf->resource) |
| 2911 | wl_resource_destroy(shsurf->resource); |
| 2912 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2913 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2914 | } |
| 2915 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2916 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2917 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2918 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame^] | 2919 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2920 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2921 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2922 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2923 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2924 | else |
| 2925 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2926 | } |
| 2927 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2928 | static struct shell_surface * |
| 2929 | create_common_surface(void *shell, struct weston_surface *surface, |
| 2930 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2931 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2932 | struct shell_surface *shsurf; |
| 2933 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2934 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2935 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2936 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2937 | } |
| 2938 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2939 | shsurf = calloc(1, sizeof *shsurf); |
| 2940 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2941 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2942 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2943 | } |
| 2944 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2945 | shsurf->view = weston_view_create(surface); |
| 2946 | if (!shsurf->view) { |
| 2947 | weston_log("no memory to allocate shell surface\n"); |
| 2948 | free(shsurf); |
| 2949 | return NULL; |
| 2950 | } |
| 2951 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2952 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2953 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2954 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2955 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2956 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2957 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2958 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2959 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2960 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2961 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2962 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2963 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2964 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2965 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2966 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2967 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2968 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2969 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2970 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2971 | |
| 2972 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 2973 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2974 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2975 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2976 | /* empty when not in use */ |
| 2977 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2978 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2979 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2980 | wl_list_init(&shsurf->workspace_transform.link); |
| 2981 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2982 | wl_list_init(&shsurf->children_link); |
| 2983 | wl_list_init(&shsurf->children_list); |
| 2984 | shsurf->parent = NULL; |
| 2985 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2986 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2987 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2988 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2989 | shsurf->client = client; |
| 2990 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2991 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2992 | } |
| 2993 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2994 | static struct shell_surface * |
| 2995 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 2996 | const struct weston_shell_client *client) |
| 2997 | { |
| 2998 | struct shell_surface *shsurf; |
| 2999 | shsurf = create_common_surface(shell, surface, client); |
| 3000 | |
| 3001 | shsurf->type = SHELL_SURFACE_NONE; |
| 3002 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 3003 | |
| 3004 | return shsurf; |
| 3005 | } |
| 3006 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3007 | static struct weston_view * |
| 3008 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3009 | { |
| 3010 | return shsurf->view; |
| 3011 | } |
| 3012 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3013 | static void |
| 3014 | shell_get_shell_surface(struct wl_client *client, |
| 3015 | struct wl_resource *resource, |
| 3016 | uint32_t id, |
| 3017 | struct wl_resource *surface_resource) |
| 3018 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3019 | struct weston_surface *surface = |
| 3020 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3021 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3022 | struct shell_surface *shsurf; |
| 3023 | |
| 3024 | if (get_shell_surface(surface)) { |
| 3025 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3026 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3027 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3028 | return; |
| 3029 | } |
| 3030 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3031 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3032 | if (!shsurf) { |
| 3033 | wl_resource_post_error(surface_resource, |
| 3034 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3035 | "surface->configure already set"); |
| 3036 | return; |
| 3037 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3038 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3039 | shsurf->resource = |
| 3040 | wl_resource_create(client, |
| 3041 | &wl_shell_surface_interface, 1, id); |
| 3042 | wl_resource_set_implementation(shsurf->resource, |
| 3043 | &shell_surface_implementation, |
| 3044 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3045 | } |
| 3046 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3047 | static bool |
| 3048 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3049 | { |
| 3050 | return wl_resource_instance_of(shsurf->resource, |
| 3051 | &wl_shell_surface_interface, |
| 3052 | &shell_surface_implementation); |
| 3053 | } |
| 3054 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3055 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3056 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3057 | }; |
| 3058 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3059 | /**************************** |
| 3060 | * xdg-shell implementation */ |
| 3061 | |
| 3062 | static void |
| 3063 | xdg_surface_destroy(struct wl_client *client, |
| 3064 | struct wl_resource *resource) |
| 3065 | { |
| 3066 | wl_resource_destroy(resource); |
| 3067 | } |
| 3068 | |
| 3069 | static void |
| 3070 | xdg_surface_pong(struct wl_client *client, |
| 3071 | struct wl_resource *resource, |
| 3072 | uint32_t serial) |
| 3073 | { |
| 3074 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3075 | |
| 3076 | surface_pong(shsurf, serial); |
| 3077 | } |
| 3078 | |
| 3079 | static void |
| 3080 | xdg_surface_set_app_id(struct wl_client *client, |
| 3081 | struct wl_resource *resource, |
| 3082 | const char *app_id) |
| 3083 | { |
| 3084 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3085 | |
| 3086 | free(shsurf->class); |
| 3087 | shsurf->class = strdup(app_id); |
| 3088 | } |
| 3089 | |
| 3090 | static void |
| 3091 | xdg_surface_set_title(struct wl_client *client, |
| 3092 | struct wl_resource *resource, const char *title) |
| 3093 | { |
| 3094 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3095 | |
| 3096 | set_title(shsurf, title); |
| 3097 | } |
| 3098 | |
| 3099 | static void |
| 3100 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3101 | struct wl_resource *seat_resource, uint32_t serial) |
| 3102 | { |
| 3103 | common_surface_move(resource, seat_resource, serial); |
| 3104 | } |
| 3105 | |
| 3106 | static void |
| 3107 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3108 | struct wl_resource *seat_resource, uint32_t serial, |
| 3109 | uint32_t edges) |
| 3110 | { |
| 3111 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3112 | } |
| 3113 | |
| 3114 | static void |
| 3115 | xdg_surface_set_output(struct wl_client *client, |
| 3116 | struct wl_resource *resource, |
| 3117 | struct wl_resource *output_resource) |
| 3118 | { |
| 3119 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3120 | struct weston_output *output; |
| 3121 | |
| 3122 | if (output_resource) |
| 3123 | output = wl_resource_get_user_data(output_resource); |
| 3124 | else |
| 3125 | output = NULL; |
| 3126 | |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3127 | shsurf->recommended_output = output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3128 | } |
| 3129 | |
| 3130 | static void |
| 3131 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3132 | struct wl_resource *resource) |
| 3133 | { |
| 3134 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3135 | |
| 3136 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3137 | return; |
| 3138 | |
| 3139 | if (!shsurf->next_state.fullscreen) { |
| 3140 | shsurf->next_state.fullscreen = true; |
| 3141 | shsurf->state_changed = true; |
| 3142 | set_fullscreen(shsurf, |
| 3143 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3144 | 0, shsurf->recommended_output); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | static void |
| 3149 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3150 | struct wl_resource *resource) |
| 3151 | { |
| 3152 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3153 | int32_t width, height; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3154 | |
| 3155 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3156 | return; |
| 3157 | |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3158 | if (!shsurf->next_state.fullscreen) |
| 3159 | return; |
| 3160 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3161 | shsurf->next_state.fullscreen = false; |
| 3162 | shsurf->state_changed = true; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3163 | |
| 3164 | if (shsurf->saved_size_valid) { |
| 3165 | width = shsurf->saved_width; |
| 3166 | height = shsurf->saved_height; |
| 3167 | shsurf->saved_size_valid = false; |
| 3168 | } else { |
| 3169 | width = shsurf->surface->width; |
| 3170 | height = shsurf->surface->height; |
| 3171 | } |
| 3172 | |
| 3173 | shsurf->client->send_configure(shsurf->surface, 0, width, height); |
| 3174 | shsurf->next_type = shsurf->type; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | static void |
| 3178 | xdg_surface_set_maximized(struct wl_client *client, |
| 3179 | struct wl_resource *resource) |
| 3180 | { |
| 3181 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3182 | |
| 3183 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3184 | return; |
| 3185 | |
| 3186 | if (!shsurf->next_state.maximized) { |
| 3187 | shsurf->next_state.maximized = true; |
| 3188 | shsurf->state_changed = true; |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3189 | set_maximized(shsurf, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3190 | } |
| 3191 | } |
| 3192 | |
| 3193 | static void |
| 3194 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3195 | struct wl_resource *resource) |
| 3196 | { |
| 3197 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3198 | int32_t width, height; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3199 | |
| 3200 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3201 | return; |
| 3202 | |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3203 | if (!shsurf->next_state.maximized) |
| 3204 | return; |
| 3205 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3206 | shsurf->next_state.maximized = false; |
| 3207 | shsurf->state_changed = true; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3208 | |
| 3209 | if (shsurf->saved_size_valid) { |
| 3210 | width = shsurf->saved_width; |
| 3211 | height = shsurf->saved_height; |
| 3212 | shsurf->saved_size_valid = false; |
| 3213 | } else { |
| 3214 | width = shsurf->surface->width; |
| 3215 | height = shsurf->surface->height; |
| 3216 | } |
| 3217 | |
| 3218 | shsurf->client->send_configure(shsurf->surface, 0, width, height); |
| 3219 | shsurf->next_type = shsurf->type; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3223 | xdg_surface_destroy, |
| 3224 | xdg_surface_set_transient_for, |
| 3225 | xdg_surface_set_title, |
| 3226 | xdg_surface_set_app_id, |
| 3227 | xdg_surface_pong, |
| 3228 | xdg_surface_move, |
| 3229 | xdg_surface_resize, |
| 3230 | xdg_surface_set_output, |
| 3231 | xdg_surface_set_fullscreen, |
| 3232 | xdg_surface_unset_fullscreen, |
| 3233 | xdg_surface_set_maximized, |
| 3234 | xdg_surface_unset_maximized, |
| 3235 | NULL /* set_minimized */ |
| 3236 | }; |
| 3237 | |
| 3238 | static void |
| 3239 | xdg_send_configure(struct weston_surface *surface, |
| 3240 | uint32_t edges, int32_t width, int32_t height) |
| 3241 | { |
| 3242 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 3243 | |
| 3244 | xdg_surface_send_configure(shsurf->resource, edges, width, height); |
| 3245 | } |
| 3246 | |
| 3247 | static const struct weston_shell_client xdg_client = { |
| 3248 | xdg_send_configure |
| 3249 | }; |
| 3250 | |
| 3251 | static void |
| 3252 | xdg_use_unstable_version(struct wl_client *client, |
| 3253 | struct wl_resource *resource, |
| 3254 | int32_t version) |
| 3255 | { |
| 3256 | if (version > 1) { |
| 3257 | wl_resource_post_error(resource, |
| 3258 | 1, |
| 3259 | "xdg-shell:: version not implemented yet."); |
| 3260 | return; |
| 3261 | } |
| 3262 | } |
| 3263 | |
| 3264 | static struct shell_surface * |
| 3265 | create_xdg_surface(void *shell, struct weston_surface *surface, |
| 3266 | const struct weston_shell_client *client) |
| 3267 | { |
| 3268 | struct shell_surface *shsurf; |
| 3269 | shsurf = create_common_surface(shell, surface, client); |
| 3270 | |
| 3271 | shsurf->type = SHELL_SURFACE_NONE; |
| 3272 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
| 3273 | |
| 3274 | return shsurf; |
| 3275 | } |
| 3276 | |
| 3277 | static void |
| 3278 | xdg_get_xdg_surface(struct wl_client *client, |
| 3279 | struct wl_resource *resource, |
| 3280 | uint32_t id, |
| 3281 | struct wl_resource *surface_resource) |
| 3282 | { |
| 3283 | struct weston_surface *surface = |
| 3284 | wl_resource_get_user_data(surface_resource); |
| 3285 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3286 | struct shell_surface *shsurf; |
| 3287 | |
| 3288 | if (get_shell_surface(surface)) { |
| 3289 | wl_resource_post_error(surface_resource, |
| 3290 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3291 | "desktop_shell::get_shell_surface already requested"); |
| 3292 | return; |
| 3293 | } |
| 3294 | |
| 3295 | shsurf = create_xdg_surface(shell, surface, &xdg_client); |
| 3296 | if (!shsurf) { |
| 3297 | wl_resource_post_error(surface_resource, |
| 3298 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3299 | "surface->configure already set"); |
| 3300 | return; |
| 3301 | } |
| 3302 | |
| 3303 | shsurf->resource = |
| 3304 | wl_resource_create(client, |
| 3305 | &xdg_surface_interface, 1, id); |
| 3306 | wl_resource_set_implementation(shsurf->resource, |
| 3307 | &xdg_surface_implementation, |
| 3308 | shsurf, shell_destroy_shell_surface); |
| 3309 | } |
| 3310 | |
| 3311 | static bool |
| 3312 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3313 | { |
| 3314 | return wl_resource_instance_of(shsurf->resource, |
| 3315 | &xdg_surface_interface, |
| 3316 | &xdg_surface_implementation); |
| 3317 | } |
| 3318 | |
| 3319 | /* xdg-popup implementation */ |
| 3320 | |
| 3321 | static void |
| 3322 | xdg_popup_destroy(struct wl_client *client, |
| 3323 | struct wl_resource *resource) |
| 3324 | { |
| 3325 | wl_resource_destroy(resource); |
| 3326 | } |
| 3327 | |
| 3328 | static void |
| 3329 | xdg_popup_pong(struct wl_client *client, |
| 3330 | struct wl_resource *resource, |
| 3331 | uint32_t serial) |
| 3332 | { |
| 3333 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3334 | |
| 3335 | surface_pong(shsurf, serial); |
| 3336 | } |
| 3337 | |
| 3338 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3339 | xdg_popup_destroy, |
| 3340 | xdg_popup_pong |
| 3341 | }; |
| 3342 | |
| 3343 | static void |
| 3344 | xdg_popup_send_configure(struct weston_surface *surface, |
| 3345 | uint32_t edges, int32_t width, int32_t height) |
| 3346 | { |
| 3347 | } |
| 3348 | |
| 3349 | static const struct weston_shell_client xdg_popup_client = { |
| 3350 | xdg_popup_send_configure |
| 3351 | }; |
| 3352 | |
| 3353 | static struct shell_surface * |
| 3354 | create_xdg_popup(void *shell, struct weston_surface *surface, |
| 3355 | const struct weston_shell_client *client, |
| 3356 | struct weston_surface *parent, |
| 3357 | struct shell_seat *seat, |
| 3358 | uint32_t serial, |
| 3359 | int32_t x, int32_t y) |
| 3360 | { |
| 3361 | struct shell_surface *shsurf; |
| 3362 | shsurf = create_common_surface(shell, surface, client); |
| 3363 | |
| 3364 | shsurf->type = SHELL_SURFACE_NONE; |
| 3365 | shsurf->next_type = SHELL_SURFACE_POPUP; |
| 3366 | shsurf->popup.shseat = seat; |
| 3367 | shsurf->popup.serial = serial; |
| 3368 | shsurf->popup.x = x; |
| 3369 | shsurf->popup.y = y; |
| 3370 | shell_surface_set_parent(shsurf, parent); |
| 3371 | |
| 3372 | return shsurf; |
| 3373 | } |
| 3374 | |
| 3375 | static void |
| 3376 | xdg_get_xdg_popup(struct wl_client *client, |
| 3377 | struct wl_resource *resource, |
| 3378 | uint32_t id, |
| 3379 | struct wl_resource *surface_resource, |
| 3380 | struct wl_resource *parent_resource, |
| 3381 | struct wl_resource *seat_resource, |
| 3382 | uint32_t serial, |
| 3383 | int32_t x, int32_t y, uint32_t flags) |
| 3384 | { |
| 3385 | struct weston_surface *surface = |
| 3386 | wl_resource_get_user_data(surface_resource); |
| 3387 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3388 | struct shell_surface *shsurf; |
| 3389 | struct weston_surface *parent; |
| 3390 | struct shell_seat *seat; |
| 3391 | |
| 3392 | if (get_shell_surface(surface)) { |
| 3393 | wl_resource_post_error(surface_resource, |
| 3394 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3395 | "desktop_shell::get_shell_surface already requested"); |
| 3396 | return; |
| 3397 | } |
| 3398 | |
| 3399 | if (!parent_resource) { |
| 3400 | wl_resource_post_error(surface_resource, |
| 3401 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3402 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
| 3403 | } |
| 3404 | |
| 3405 | parent = wl_resource_get_user_data(parent_resource); |
| 3406 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 3407 | |
| 3408 | shsurf = create_xdg_popup(shell, surface, &xdg_popup_client, |
| 3409 | parent, seat, serial, x, y); |
| 3410 | if (!shsurf) { |
| 3411 | wl_resource_post_error(surface_resource, |
| 3412 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3413 | "surface->configure already set"); |
| 3414 | return; |
| 3415 | } |
| 3416 | |
| 3417 | shsurf->resource = |
| 3418 | wl_resource_create(client, |
| 3419 | &xdg_popup_interface, 1, id); |
| 3420 | wl_resource_set_implementation(shsurf->resource, |
| 3421 | &xdg_popup_implementation, |
| 3422 | shsurf, shell_destroy_shell_surface); |
| 3423 | } |
| 3424 | |
| 3425 | static bool |
| 3426 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 3427 | { |
| 3428 | return wl_resource_instance_of(shsurf->resource, |
| 3429 | &xdg_popup_interface, |
| 3430 | &xdg_popup_implementation); |
| 3431 | } |
| 3432 | |
| 3433 | static const struct xdg_shell_interface xdg_implementation = { |
| 3434 | xdg_use_unstable_version, |
| 3435 | xdg_get_xdg_surface, |
| 3436 | xdg_get_xdg_popup |
| 3437 | }; |
| 3438 | |
| 3439 | static int |
| 3440 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 3441 | void *_target, uint32_t opcode, |
| 3442 | const struct wl_message *message, |
| 3443 | union wl_argument *args) |
| 3444 | { |
| 3445 | struct wl_resource *resource = _target; |
| 3446 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3447 | |
| 3448 | if (opcode != 0) { |
| 3449 | wl_resource_post_error(resource, |
| 3450 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3451 | "must call use_unstable_version first"); |
| 3452 | return 0; |
| 3453 | } |
| 3454 | |
| 3455 | #define XDG_SERVER_VERSION 1 |
| 3456 | |
| 3457 | if (args[0].i != XDG_SERVER_VERSION) { |
| 3458 | wl_resource_post_error(resource, |
| 3459 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3460 | "incompatible version, server is %d " |
| 3461 | "client wants %d", |
| 3462 | XDG_SERVER_VERSION, args[0].i); |
| 3463 | return 0; |
| 3464 | } |
| 3465 | |
| 3466 | wl_resource_set_implementation(resource, &xdg_implementation, |
| 3467 | shell, NULL); |
| 3468 | |
| 3469 | return 1; |
| 3470 | } |
| 3471 | |
| 3472 | /* end of xdg-shell implementation */ |
| 3473 | /***********************************/ |
| 3474 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3475 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3476 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3477 | |
| 3478 | static int |
| 3479 | screensaver_timeout(void *data) |
| 3480 | { |
| 3481 | struct desktop_shell *shell = data; |
| 3482 | |
| 3483 | shell_fade(shell, FADE_OUT); |
| 3484 | |
| 3485 | return 1; |
| 3486 | } |
| 3487 | |
| 3488 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3489 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3490 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3491 | struct desktop_shell *shell = |
| 3492 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3493 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3494 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3495 | |
| 3496 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3497 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3501 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3502 | { |
| 3503 | if (shell->screensaver.binding) |
| 3504 | return; |
| 3505 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3506 | if (!shell->screensaver.path) { |
| 3507 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3508 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3509 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3510 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3511 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3512 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3513 | return; |
| 3514 | } |
| 3515 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3516 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3517 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3518 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3519 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3523 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3524 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3525 | if (shell->screensaver.process.pid == 0) |
| 3526 | return; |
| 3527 | |
| 3528 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3532 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3533 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3534 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3535 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3536 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3537 | if (v->output == ev->output && v != ev) { |
| 3538 | weston_view_unmap(v); |
| 3539 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3540 | } |
| 3541 | } |
| 3542 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3543 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3544 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3545 | if (wl_list_empty(&ev->layer_link)) { |
| 3546 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3547 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3548 | } |
| 3549 | } |
| 3550 | |
| 3551 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3552 | background_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3553 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3554 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3555 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3556 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3557 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3558 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3559 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3560 | } |
| 3561 | |
| 3562 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3563 | desktop_shell_set_background(struct wl_client *client, |
| 3564 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3565 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3566 | struct wl_resource *surface_resource) |
| 3567 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3568 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3569 | struct weston_surface *surface = |
| 3570 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3571 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3572 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3573 | if (surface->configure) { |
| 3574 | wl_resource_post_error(surface_resource, |
| 3575 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3576 | "surface role already assigned"); |
| 3577 | return; |
| 3578 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3579 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3580 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3581 | weston_view_destroy(view); |
| 3582 | view = weston_view_create(surface); |
| 3583 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3584 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3585 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3586 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3587 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3588 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3589 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3590 | surface->output->width, |
| 3591 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3592 | } |
| 3593 | |
| 3594 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3595 | panel_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3596 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3597 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3598 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3599 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3600 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3601 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3602 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3603 | } |
| 3604 | |
| 3605 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3606 | desktop_shell_set_panel(struct wl_client *client, |
| 3607 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3608 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3609 | struct wl_resource *surface_resource) |
| 3610 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3611 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3612 | struct weston_surface *surface = |
| 3613 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3614 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3615 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3616 | if (surface->configure) { |
| 3617 | wl_resource_post_error(surface_resource, |
| 3618 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3619 | "surface role already assigned"); |
| 3620 | return; |
| 3621 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3622 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3623 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3624 | weston_view_destroy(view); |
| 3625 | view = weston_view_create(surface); |
| 3626 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3627 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3628 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3629 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3630 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3631 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3632 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3633 | surface->output->width, |
| 3634 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3635 | } |
| 3636 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3637 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3638 | lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3639 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3640 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3641 | struct weston_view *view; |
| 3642 | |
| 3643 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3644 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3645 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3646 | return; |
| 3647 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3648 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3649 | |
| 3650 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3651 | wl_list_insert(&shell->lock_layer.view_list, |
| 3652 | &view->layer_link); |
| 3653 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3654 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3655 | } |
| 3656 | } |
| 3657 | |
| 3658 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3659 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3660 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3661 | struct desktop_shell *shell = |
| 3662 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3663 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3664 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3665 | shell->lock_surface = NULL; |
| 3666 | } |
| 3667 | |
| 3668 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3669 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3670 | struct wl_resource *resource, |
| 3671 | struct wl_resource *surface_resource) |
| 3672 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3673 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3674 | struct weston_surface *surface = |
| 3675 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3676 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3677 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3678 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3679 | if (!shell->locked) |
| 3680 | return; |
| 3681 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3682 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3683 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3684 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3685 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3686 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3687 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3688 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3689 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3690 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3691 | } |
| 3692 | |
| 3693 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3694 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3695 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3696 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3697 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3698 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3699 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3700 | wl_list_remove(&shell->lock_layer.link); |
| 3701 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3702 | &shell->fullscreen_layer.link); |
| 3703 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3704 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3705 | if (shell->showing_input_panels) { |
| 3706 | wl_list_insert(&shell->panel_layer.link, |
| 3707 | &shell->input_panel_layer.link); |
| 3708 | wl_list_insert(&shell->input_panel_layer.link, |
| 3709 | &ws->layer.link); |
| 3710 | } else { |
| 3711 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3712 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3713 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3714 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3715 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3716 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3717 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3718 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | static void |
| 3722 | desktop_shell_unlock(struct wl_client *client, |
| 3723 | struct wl_resource *resource) |
| 3724 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3725 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3726 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3727 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3728 | |
| 3729 | if (shell->locked) |
| 3730 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3731 | } |
| 3732 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3733 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3734 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3735 | struct wl_resource *resource, |
| 3736 | struct wl_resource *surface_resource) |
| 3737 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3738 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3739 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3740 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3741 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3742 | } |
| 3743 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3744 | static void |
| 3745 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3746 | struct wl_resource *resource) |
| 3747 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3748 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3749 | |
| 3750 | shell_fade_startup(shell); |
| 3751 | } |
| 3752 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3753 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3754 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3755 | desktop_shell_set_panel, |
| 3756 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3757 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3758 | desktop_shell_set_grab_surface, |
| 3759 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3760 | }; |
| 3761 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3762 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3763 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3764 | { |
| 3765 | struct shell_surface *shsurf; |
| 3766 | |
| 3767 | shsurf = get_shell_surface(surface); |
| 3768 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3769 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3770 | return shsurf->type; |
| 3771 | } |
| 3772 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3773 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3774 | move_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3775 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3776 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3777 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3778 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3779 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3780 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3781 | if (surface == NULL) |
| 3782 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3783 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3784 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3785 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3786 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3787 | return; |
| 3788 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3789 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3790 | } |
| 3791 | |
| 3792 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3793 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3794 | { |
| 3795 | struct weston_surface *focus = seat->pointer->focus->surface; |
| 3796 | struct weston_surface *surface; |
| 3797 | struct shell_surface *shsurf; |
| 3798 | |
| 3799 | surface = weston_surface_get_main_surface(focus); |
| 3800 | if (surface == NULL) |
| 3801 | return; |
| 3802 | |
| 3803 | shsurf = get_shell_surface(surface); |
| 3804 | if (shsurf == NULL) |
| 3805 | return; |
| 3806 | |
| 3807 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3808 | return; |
| 3809 | |
| 3810 | if (shsurf->state.maximized) |
| 3811 | xdg_surface_send_request_unset_maximized(shsurf->resource); |
| 3812 | else |
| 3813 | xdg_surface_send_request_set_maximized(shsurf->resource); |
| 3814 | } |
| 3815 | |
| 3816 | static void |
| 3817 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3818 | { |
| 3819 | struct weston_surface *focus = seat->pointer->focus->surface; |
| 3820 | struct weston_surface *surface; |
| 3821 | struct shell_surface *shsurf; |
| 3822 | |
| 3823 | surface = weston_surface_get_main_surface(focus); |
| 3824 | if (surface == NULL) |
| 3825 | return; |
| 3826 | |
| 3827 | shsurf = get_shell_surface(surface); |
| 3828 | if (shsurf == NULL) |
| 3829 | return; |
| 3830 | |
| 3831 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3832 | return; |
| 3833 | |
| 3834 | if (shsurf->state.fullscreen) |
| 3835 | xdg_surface_send_request_unset_fullscreen(shsurf->resource); |
| 3836 | else |
| 3837 | xdg_surface_send_request_set_fullscreen(shsurf->resource); |
| 3838 | } |
| 3839 | |
| 3840 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3841 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3842 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3843 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3844 | struct weston_surface *surface; |
| 3845 | struct shell_surface *shsurf; |
| 3846 | |
| 3847 | surface = weston_surface_get_main_surface(focus); |
| 3848 | if (surface == NULL) |
| 3849 | return; |
| 3850 | |
| 3851 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3852 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3853 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3854 | return; |
| 3855 | |
| 3856 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3857 | } |
| 3858 | |
| 3859 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3860 | resize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3861 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3862 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3863 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3864 | uint32_t edges = 0; |
| 3865 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3866 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3867 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3868 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3869 | if (surface == NULL) |
| 3870 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3871 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3872 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3873 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3874 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3875 | return; |
| 3876 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3877 | weston_view_from_global(shsurf->view, |
| 3878 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3879 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3880 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3881 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3882 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3883 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3884 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3885 | edges |= 0; |
| 3886 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3887 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3888 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3889 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3890 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3891 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3892 | edges |= 0; |
| 3893 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3894 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3895 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3896 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3897 | } |
| 3898 | |
| 3899 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3900 | surface_opacity_binding(struct weston_seat *seat, uint32_t time, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3901 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3902 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3903 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3904 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3905 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3906 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3907 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3908 | /* XXX: broken for windows containing sub-surfaces */ |
| 3909 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3910 | if (surface == NULL) |
| 3911 | return; |
| 3912 | |
| 3913 | shsurf = get_shell_surface(surface); |
| 3914 | if (!shsurf) |
| 3915 | return; |
| 3916 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3917 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3918 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3919 | if (shsurf->view->alpha > 1.0) |
| 3920 | shsurf->view->alpha = 1.0; |
| 3921 | if (shsurf->view->alpha < step) |
| 3922 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3923 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3924 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3925 | weston_surface_damage(surface); |
| 3926 | } |
| 3927 | |
| 3928 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3929 | do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3930 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3931 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3932 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3933 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3934 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3935 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3936 | |
| 3937 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3938 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3939 | wl_fixed_to_double(seat->pointer->x), |
| 3940 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3941 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3942 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3943 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3944 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3945 | increment = -output->zoom.increment; |
| 3946 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3947 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3948 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3949 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3950 | else |
| 3951 | increment = 0; |
| 3952 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3953 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3954 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3955 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3956 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3957 | else if (output->zoom.level > output->zoom.max_level) |
| 3958 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 3959 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 3960 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3961 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3962 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3963 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3964 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3965 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3966 | } |
| 3967 | } |
| 3968 | } |
| 3969 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3970 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3971 | zoom_axis_binding(struct weston_seat *seat, uint32_t time, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3972 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3973 | { |
| 3974 | do_zoom(seat, time, 0, axis, value); |
| 3975 | } |
| 3976 | |
| 3977 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3978 | zoom_key_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3979 | void *data) |
| 3980 | { |
| 3981 | do_zoom(seat, time, key, 0, 0); |
| 3982 | } |
| 3983 | |
| 3984 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3985 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3986 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3987 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3988 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3989 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3990 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3991 | } |
| 3992 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3993 | struct alt_tab { |
| 3994 | struct desktop_shell *shell; |
| 3995 | struct weston_keyboard_grab grab; |
| 3996 | |
| 3997 | struct wl_list *current; |
| 3998 | |
| 3999 | struct wl_list preview_list; |
| 4000 | }; |
| 4001 | |
| 4002 | struct alt_tab_preview { |
| 4003 | struct alt_tab *alt_tab; |
| 4004 | |
| 4005 | struct weston_view *view; |
| 4006 | struct weston_transform transform; |
| 4007 | |
| 4008 | struct wl_listener listener; |
| 4009 | |
| 4010 | struct wl_list link; |
| 4011 | }; |
| 4012 | |
| 4013 | static void |
| 4014 | alt_tab_next(struct alt_tab *alt_tab) |
| 4015 | { |
| 4016 | alt_tab->current = alt_tab->current->next; |
| 4017 | |
| 4018 | /* Make sure we're not pointing to the list header e.g. after |
| 4019 | * cycling through the whole list. */ |
| 4020 | if (alt_tab->current->next == alt_tab->preview_list.next) |
| 4021 | alt_tab->current = alt_tab->current->next; |
| 4022 | } |
| 4023 | |
| 4024 | static void |
| 4025 | alt_tab_destroy(struct alt_tab *alt_tab) |
| 4026 | { |
| 4027 | struct alt_tab_preview *preview, *next; |
| 4028 | struct weston_keyboard *keyboard = alt_tab->grab.keyboard; |
| 4029 | |
| 4030 | if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) { |
| 4031 | preview = wl_container_of(alt_tab->current, preview, link); |
| 4032 | |
| 4033 | activate(alt_tab->shell, preview->view->surface, |
| 4034 | (struct weston_seat *) keyboard->seat); |
| 4035 | } |
| 4036 | |
| 4037 | wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) { |
| 4038 | wl_list_remove(&preview->link); |
| 4039 | wl_list_remove(&preview->listener.link); |
| 4040 | weston_view_destroy(preview->view); |
| 4041 | free(preview); |
| 4042 | } |
| 4043 | |
| 4044 | weston_keyboard_end_grab(keyboard); |
| 4045 | if (keyboard->input_method_resource) |
| 4046 | keyboard->grab = &keyboard->input_method_grab; |
| 4047 | |
| 4048 | free(alt_tab); |
| 4049 | } |
| 4050 | |
| 4051 | static void |
| 4052 | alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4053 | { |
| 4054 | struct alt_tab_preview *preview = |
| 4055 | container_of(listener, struct alt_tab_preview, listener); |
| 4056 | struct alt_tab *alt_tab = preview->alt_tab; |
| 4057 | int advance = 0; |
| 4058 | |
| 4059 | /* If the preview that we're removing is the currently selected one, |
| 4060 | * we want to move to the next one. So we move to ->prev and then |
| 4061 | * call _next() after removing the preview. */ |
| 4062 | if (alt_tab->current == &preview->link) { |
| 4063 | alt_tab->current = alt_tab->current->prev; |
| 4064 | advance = 1; |
| 4065 | } |
| 4066 | |
| 4067 | wl_list_remove(&preview->listener.link); |
| 4068 | wl_list_remove(&preview->link); |
| 4069 | |
| 4070 | free(preview); |
| 4071 | |
| 4072 | if (advance) |
| 4073 | alt_tab_next(alt_tab); |
| 4074 | |
| 4075 | /* If the last preview goes away, stop the alt-tab */ |
| 4076 | if (wl_list_empty(alt_tab->current)) |
| 4077 | alt_tab_destroy(alt_tab); |
| 4078 | } |
| 4079 | |
| 4080 | static void |
| 4081 | alt_tab_key(struct weston_keyboard_grab *grab, |
| 4082 | uint32_t time, uint32_t key, uint32_t state_w) |
| 4083 | { |
| 4084 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4085 | enum wl_keyboard_key_state state = state_w; |
| 4086 | |
| 4087 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 4088 | alt_tab_next(alt_tab); |
| 4089 | } |
| 4090 | |
| 4091 | static void |
| 4092 | alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 4093 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4094 | uint32_t mods_locked, uint32_t group) |
| 4095 | { |
| 4096 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4097 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 4098 | |
| 4099 | if ((seat->modifier_state & MODIFIER_ALT) == 0) |
| 4100 | alt_tab_destroy(alt_tab); |
| 4101 | } |
| 4102 | |
| 4103 | static void |
| 4104 | alt_tab_cancel(struct weston_keyboard_grab *grab) |
| 4105 | { |
| 4106 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4107 | |
| 4108 | alt_tab_destroy(alt_tab); |
| 4109 | } |
| 4110 | |
| 4111 | static const struct weston_keyboard_grab_interface alt_tab_grab = { |
| 4112 | alt_tab_key, |
| 4113 | alt_tab_modifier, |
| 4114 | alt_tab_cancel, |
| 4115 | }; |
| 4116 | |
| 4117 | static int |
| 4118 | view_for_alt_tab(struct weston_view *view) |
| 4119 | { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4120 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 4121 | if (!shsurf) |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4122 | return 0; |
| 4123 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4124 | if (shsurf->parent) |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4125 | return 0; |
| 4126 | |
| 4127 | if (view != get_default_view(view->surface)) |
| 4128 | return 0; |
| 4129 | |
| 4130 | return 1; |
| 4131 | } |
| 4132 | |
| 4133 | static void |
| 4134 | alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 4135 | void *data) |
| 4136 | { |
| 4137 | struct alt_tab *alt_tab; |
| 4138 | struct desktop_shell *shell = data; |
| 4139 | struct weston_output *output = get_default_output(shell->compositor); |
| 4140 | struct workspace *ws; |
| 4141 | struct weston_view *view; |
| 4142 | int num_surfaces = 0; |
| 4143 | int x, y, side, margin; |
| 4144 | |
| 4145 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 4146 | |
| 4147 | if (view_for_alt_tab(view)) |
| 4148 | num_surfaces++; |
| 4149 | } |
| 4150 | |
| 4151 | if (!num_surfaces) |
| 4152 | return; |
| 4153 | |
| 4154 | alt_tab = malloc(sizeof *alt_tab); |
| 4155 | if (!alt_tab) |
| 4156 | return; |
| 4157 | |
| 4158 | alt_tab->shell = shell; |
| 4159 | wl_list_init(&alt_tab->preview_list); |
| 4160 | alt_tab->current = &alt_tab->preview_list; |
| 4161 | |
| 4162 | restore_all_output_modes(shell->compositor); |
| 4163 | lower_fullscreen_layer(alt_tab->shell); |
| 4164 | |
| 4165 | alt_tab->grab.interface = &alt_tab_grab; |
| 4166 | weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab); |
| 4167 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 4168 | |
| 4169 | ws = get_current_workspace(shell); |
| 4170 | |
| 4171 | /* FIXME: add some visual candy e.g. prelight the selected view |
| 4172 | * and/or add a black surrounding background à la gnome-shell */ |
| 4173 | |
| 4174 | /* Determine the size for each preview */ |
| 4175 | side = output->width / num_surfaces; |
| 4176 | if (side > 200) |
| 4177 | side = 200; |
| 4178 | margin = side / 4; |
| 4179 | side -= margin; |
| 4180 | |
| 4181 | x = margin; |
| 4182 | y = (output->height - side) / 2; |
| 4183 | |
| 4184 | /* Create a view for each surface */ |
| 4185 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 4186 | struct alt_tab_preview *preview; |
| 4187 | struct weston_view *v; |
| 4188 | float scale; |
| 4189 | |
| 4190 | if (!view_for_alt_tab(view)) |
| 4191 | continue; |
| 4192 | |
| 4193 | preview = malloc(sizeof *preview); |
| 4194 | if (!preview) { |
| 4195 | alt_tab_destroy(alt_tab); |
| 4196 | return; |
| 4197 | } |
| 4198 | |
| 4199 | preview->alt_tab = alt_tab; |
| 4200 | |
| 4201 | preview->view = v = weston_view_create(view->surface); |
| 4202 | v->output = view->output; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4203 | |
| 4204 | wl_list_remove(&v->layer_link); |
| 4205 | wl_list_insert(&ws->layer.view_list, &v->layer_link); |
| 4206 | weston_view_damage_below(v); |
| 4207 | weston_surface_damage(v->surface); |
| 4208 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4209 | weston_view_set_position(v, x, y); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4210 | |
| 4211 | preview->listener.notify = alt_tab_handle_surface_destroy; |
| 4212 | wl_signal_add(&v->destroy_signal, &preview->listener); |
| 4213 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4214 | if (view->surface->width > view->surface->height) |
| 4215 | scale = side / (float) view->surface->width; |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4216 | else |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4217 | scale = side / (float) view->surface->height; |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4218 | |
| 4219 | wl_list_insert(&v->geometry.transformation_list, |
| 4220 | &preview->transform.link); |
| 4221 | weston_matrix_init(&preview->transform.matrix); |
| 4222 | weston_matrix_scale(&preview->transform.matrix, |
| 4223 | scale, scale, 1.0f); |
| 4224 | |
| 4225 | weston_view_geometry_dirty(v); |
| 4226 | weston_compositor_schedule_repaint(v->surface->compositor); |
| 4227 | |
| 4228 | /* Insert at the end of the list */ |
| 4229 | wl_list_insert(alt_tab->preview_list.prev, &preview->link); |
| 4230 | |
| 4231 | x += side + margin; |
| 4232 | } |
| 4233 | |
| 4234 | /* Start at the second preview so a simple <alt>tab changes window. |
| 4235 | * We set `current' to the first preview and not the second because |
| 4236 | * we're going to receive a key press callback for the initial |
| 4237 | * <alt>tab which will make `current' point to the second element. */ |
| 4238 | alt_tab_next(alt_tab); |
| 4239 | } |
| 4240 | |
| 4241 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4242 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4243 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4244 | { |
| 4245 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4246 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4247 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4248 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4249 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4250 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4251 | weston_pointer_move(pointer, x, y); |
| 4252 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4253 | if (!shsurf) |
| 4254 | return; |
| 4255 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4256 | cx = 0.5f * shsurf->surface->width; |
| 4257 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4258 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4259 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4260 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4261 | r = sqrtf(dx * dx + dy * dy); |
| 4262 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4263 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4264 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4265 | |
| 4266 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4267 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4268 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4269 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4270 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4271 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4272 | |
| 4273 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4274 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4275 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4276 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4277 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4278 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4279 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4280 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4281 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4282 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4283 | wl_list_init(&shsurf->rotation.transform.link); |
| 4284 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4285 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4286 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4287 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4288 | /* We need to adjust the position of the surface |
| 4289 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4290 | cposx = shsurf->view->geometry.x + cx; |
| 4291 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4292 | dposx = rotate->center.x - cposx; |
| 4293 | dposy = rotate->center.y - cposy; |
| 4294 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4295 | weston_view_set_position(shsurf->view, |
| 4296 | shsurf->view->geometry.x + dposx, |
| 4297 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4298 | } |
| 4299 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4300 | /* Repaint implies weston_surface_update_transform(), which |
| 4301 | * lazily applies the damage due to rotation update. |
| 4302 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4303 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4307 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4308 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4309 | { |
| 4310 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4311 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4312 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4313 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4314 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4315 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4316 | if (pointer->button_count == 0 && |
| 4317 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4318 | if (shsurf) |
| 4319 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4320 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4321 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4322 | free(rotate); |
| 4323 | } |
| 4324 | } |
| 4325 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4326 | static void |
| 4327 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4328 | { |
| 4329 | struct rotate_grab *rotate = |
| 4330 | container_of(grab, struct rotate_grab, base.grab); |
| 4331 | |
| 4332 | shell_grab_end(&rotate->base); |
| 4333 | free(rotate); |
| 4334 | } |
| 4335 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4336 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4337 | noop_grab_focus, |
| 4338 | rotate_grab_motion, |
| 4339 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4340 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4341 | }; |
| 4342 | |
| 4343 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4344 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4345 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4346 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4347 | float dx, dy; |
| 4348 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4349 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4350 | rotate = malloc(sizeof *rotate); |
| 4351 | if (!rotate) |
| 4352 | return; |
| 4353 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4354 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4355 | surface->surface->width * 0.5f, |
| 4356 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4357 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4358 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4359 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4360 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4361 | r = sqrtf(dx * dx + dy * dy); |
| 4362 | if (r > 20.0f) { |
| 4363 | struct weston_matrix inverse; |
| 4364 | |
| 4365 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4366 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4367 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4368 | |
| 4369 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4370 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4371 | } else { |
| 4372 | weston_matrix_init(&surface->rotation.rotation); |
| 4373 | weston_matrix_init(&rotate->rotation); |
| 4374 | } |
| 4375 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4376 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4377 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4381 | rotate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4382 | void *data) |
| 4383 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4384 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4385 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4386 | struct shell_surface *surface; |
| 4387 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4388 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4389 | if (base_surface == NULL) |
| 4390 | return; |
| 4391 | |
| 4392 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4393 | if (surface == NULL || surface->state.fullscreen || |
| 4394 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4395 | return; |
| 4396 | |
| 4397 | surface_rotate(surface, seat); |
| 4398 | } |
| 4399 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4400 | /* Move all fullscreen layers down to the current workspace in a non-reversible |
| 4401 | * manner. This should be used when implementing shell-wide overlays, such as |
| 4402 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame^] | 4403 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4404 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4405 | { |
| 4406 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4407 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4408 | |
| 4409 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4410 | wl_list_for_each_reverse_safe(view, prev, |
| 4411 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4412 | layer_link) { |
| 4413 | wl_list_remove(&view->layer_link); |
| 4414 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4415 | weston_view_damage_below(view); |
| 4416 | weston_surface_damage(view->surface); |
| 4417 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4418 | } |
| 4419 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame^] | 4420 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4421 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4422 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4423 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4424 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4425 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4426 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4427 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4428 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4429 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4430 | main_surface = weston_surface_get_main_surface(es); |
| 4431 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4432 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4433 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4434 | state = ensure_focus_state(shell, seat); |
| 4435 | if (state == NULL) |
| 4436 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4437 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4438 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4439 | state->keyboard_focus = es; |
| 4440 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4441 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4442 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4443 | shsurf = get_shell_surface(main_surface); |
| 4444 | if (shsurf->state.fullscreen) |
| 4445 | shell_configure_fullscreen(shsurf); |
| 4446 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4447 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4448 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4449 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4450 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4451 | animate_focus_change(shell, ws, get_default_view(old_es), get_default_view(es)); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4452 | } |
| 4453 | |
| 4454 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4455 | * order as appropriate. */ |
| 4456 | shell_surface_update_layer(get_shell_surface(main_surface)); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4457 | } |
| 4458 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4459 | /* no-op func for checking black surface */ |
| 4460 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4461 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4462 | { |
| 4463 | } |
| 4464 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4465 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4466 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4467 | { |
| 4468 | if (es->configure == black_surface_configure) { |
| 4469 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4470 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4471 | return true; |
| 4472 | } |
| 4473 | return false; |
| 4474 | } |
| 4475 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4476 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4477 | activate_binding(struct weston_seat *seat, |
| 4478 | struct desktop_shell *shell, |
| 4479 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4480 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4481 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4482 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4483 | if (!focus) |
| 4484 | return; |
| 4485 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4486 | if (is_black_surface(focus, &main_surface)) |
| 4487 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4488 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4489 | main_surface = weston_surface_get_main_surface(focus); |
| 4490 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4491 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4492 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4493 | activate(shell, focus, seat); |
| 4494 | } |
| 4495 | |
| 4496 | static void |
| 4497 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4498 | void *data) |
| 4499 | { |
| 4500 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4501 | return; |
| 4502 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4503 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4504 | } |
| 4505 | |
| 4506 | static void |
| 4507 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4508 | { |
| 4509 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4510 | return; |
| 4511 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4512 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4513 | } |
| 4514 | |
| 4515 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4516 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4517 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4518 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4519 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4520 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4521 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4522 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4523 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4524 | |
| 4525 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4526 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4527 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4528 | * toplevel layers. This way nothing else can show or receive |
| 4529 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4530 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4531 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4532 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4533 | if (shell->showing_input_panels) |
| 4534 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4535 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4536 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4537 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4538 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4539 | launch_screensaver(shell); |
| 4540 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4541 | /* TODO: disable bindings that should not work while locked. */ |
| 4542 | |
| 4543 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4544 | } |
| 4545 | |
| 4546 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4547 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4548 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4549 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4550 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4551 | return; |
| 4552 | } |
| 4553 | |
| 4554 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4555 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4556 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4557 | return; |
| 4558 | } |
| 4559 | |
| 4560 | if (shell->prepare_event_sent) |
| 4561 | return; |
| 4562 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4563 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4564 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4565 | } |
| 4566 | |
| 4567 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4568 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4569 | { |
| 4570 | struct desktop_shell *shell = data; |
| 4571 | |
| 4572 | shell->fade.animation = NULL; |
| 4573 | |
| 4574 | switch (shell->fade.type) { |
| 4575 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4576 | weston_surface_destroy(shell->fade.view->surface); |
| 4577 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4578 | break; |
| 4579 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4580 | lock(shell); |
| 4581 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4582 | default: |
| 4583 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4584 | } |
| 4585 | } |
| 4586 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4587 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4588 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4589 | { |
| 4590 | struct weston_compositor *compositor = shell->compositor; |
| 4591 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4592 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4593 | |
| 4594 | surface = weston_surface_create(compositor); |
| 4595 | if (!surface) |
| 4596 | return NULL; |
| 4597 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4598 | view = weston_view_create(surface); |
| 4599 | if (!view) { |
| 4600 | weston_surface_destroy(surface); |
| 4601 | return NULL; |
| 4602 | } |
| 4603 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4604 | surface->width = 8192; |
| 4605 | surface->height = 8192; |
| 4606 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4607 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4608 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4609 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4610 | pixman_region32_init(&surface->input); |
| 4611 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4612 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4613 | } |
| 4614 | |
| 4615 | static void |
| 4616 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4617 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4618 | float tint; |
| 4619 | |
| 4620 | switch (type) { |
| 4621 | case FADE_IN: |
| 4622 | tint = 0.0; |
| 4623 | break; |
| 4624 | case FADE_OUT: |
| 4625 | tint = 1.0; |
| 4626 | break; |
| 4627 | default: |
| 4628 | weston_log("shell: invalid fade type\n"); |
| 4629 | return; |
| 4630 | } |
| 4631 | |
| 4632 | shell->fade.type = type; |
| 4633 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4634 | if (shell->fade.view == NULL) { |
| 4635 | shell->fade.view = shell_fade_create_surface(shell); |
| 4636 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4637 | return; |
| 4638 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4639 | shell->fade.view->alpha = 1.0 - tint; |
| 4640 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4644 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4645 | else |
| 4646 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4647 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4648 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4649 | shell_fade_done, shell); |
| 4650 | } |
| 4651 | |
| 4652 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4653 | do_shell_fade_startup(void *data) |
| 4654 | { |
| 4655 | struct desktop_shell *shell = data; |
| 4656 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4657 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4658 | shell_fade(shell, FADE_IN); |
| 4659 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4660 | weston_surface_destroy(shell->fade.view->surface); |
| 4661 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4662 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4663 | } |
| 4664 | |
| 4665 | static void |
| 4666 | shell_fade_startup(struct desktop_shell *shell) |
| 4667 | { |
| 4668 | struct wl_event_loop *loop; |
| 4669 | |
| 4670 | if (!shell->fade.startup_timer) |
| 4671 | return; |
| 4672 | |
| 4673 | wl_event_source_remove(shell->fade.startup_timer); |
| 4674 | shell->fade.startup_timer = NULL; |
| 4675 | |
| 4676 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4677 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4678 | } |
| 4679 | |
| 4680 | static int |
| 4681 | fade_startup_timeout(void *data) |
| 4682 | { |
| 4683 | struct desktop_shell *shell = data; |
| 4684 | |
| 4685 | shell_fade_startup(shell); |
| 4686 | return 0; |
| 4687 | } |
| 4688 | |
| 4689 | static void |
| 4690 | shell_fade_init(struct desktop_shell *shell) |
| 4691 | { |
| 4692 | /* Make compositor output all black, and wait for the desktop-shell |
| 4693 | * client to signal it is ready, then fade in. The timer triggers a |
| 4694 | * fade-in, in case the desktop-shell client takes too long. |
| 4695 | */ |
| 4696 | |
| 4697 | struct wl_event_loop *loop; |
| 4698 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4699 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4700 | weston_log("%s: warning: fade surface already exists\n", |
| 4701 | __func__); |
| 4702 | return; |
| 4703 | } |
| 4704 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4705 | shell->fade.view = shell_fade_create_surface(shell); |
| 4706 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4707 | return; |
| 4708 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4709 | weston_view_update_transform(shell->fade.view); |
| 4710 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4711 | |
| 4712 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4713 | shell->fade.startup_timer = |
| 4714 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4715 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4716 | } |
| 4717 | |
| 4718 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4719 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4720 | { |
| 4721 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4722 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4723 | |
| 4724 | shell_fade(shell, FADE_OUT); |
| 4725 | /* lock() is called from shell_fade_done() */ |
| 4726 | } |
| 4727 | |
| 4728 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4729 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4730 | { |
| 4731 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4732 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4733 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4734 | unlock(shell); |
| 4735 | } |
| 4736 | |
| 4737 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4738 | show_input_panels(struct wl_listener *listener, void *data) |
| 4739 | { |
| 4740 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4741 | container_of(listener, struct desktop_shell, |
| 4742 | show_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4743 | struct input_panel_surface *ipsurf, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4744 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4745 | shell->text_input.surface = (struct weston_surface*)data; |
| 4746 | |
Jan Arne Petersen | 451a971 | 2013-02-11 15:10:11 +0100 | [diff] [blame] | 4747 | if (shell->showing_input_panels) |
| 4748 | return; |
| 4749 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4750 | shell->showing_input_panels = true; |
| 4751 | |
Jan Arne Petersen | cf18a32 | 2012-11-07 15:32:54 +0100 | [diff] [blame] | 4752 | if (!shell->locked) |
| 4753 | wl_list_insert(&shell->panel_layer.link, |
| 4754 | &shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4755 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4756 | wl_list_for_each_safe(ipsurf, next, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4757 | &shell->input_panel.surfaces, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4758 | if (!ipsurf->surface->buffer_ref.buffer) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4759 | continue; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4760 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4761 | &ipsurf->view->layer_link); |
| 4762 | weston_view_geometry_dirty(ipsurf->view); |
| 4763 | weston_view_update_transform(ipsurf->view); |
| 4764 | weston_surface_damage(ipsurf->surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4765 | weston_slide_run(ipsurf->view, ipsurf->surface->height, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4766 | 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4767 | } |
| 4768 | } |
| 4769 | |
| 4770 | static void |
| 4771 | hide_input_panels(struct wl_listener *listener, void *data) |
| 4772 | { |
| 4773 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4774 | container_of(listener, struct desktop_shell, |
| 4775 | hide_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4776 | struct weston_view *view, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4777 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 4778 | if (!shell->showing_input_panels) |
| 4779 | return; |
| 4780 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4781 | shell->showing_input_panels = false; |
| 4782 | |
Jan Arne Petersen | 82ec909 | 2012-12-03 15:36:02 +0100 | [diff] [blame] | 4783 | if (!shell->locked) |
| 4784 | wl_list_remove(&shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4785 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4786 | wl_list_for_each_safe(view, next, |
| 4787 | &shell->input_panel_layer.view_list, layer_link) |
| 4788 | weston_view_unmap(view); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4789 | } |
| 4790 | |
| 4791 | static void |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4792 | update_input_panels(struct wl_listener *listener, void *data) |
| 4793 | { |
| 4794 | struct desktop_shell *shell = |
| 4795 | container_of(listener, struct desktop_shell, |
| 4796 | update_input_panel_listener); |
| 4797 | |
| 4798 | memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t)); |
| 4799 | } |
| 4800 | |
| 4801 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4802 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4803 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4804 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4805 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4806 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4807 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4808 | |
| 4809 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4810 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4811 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4812 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4813 | } |
| 4814 | |
| 4815 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4816 | weston_view_set_initial_position(struct weston_view *view, |
| 4817 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4818 | { |
| 4819 | struct weston_compositor *compositor = shell->compositor; |
| 4820 | int ix = 0, iy = 0; |
| 4821 | int range_x, range_y; |
| 4822 | int dx, dy, x, y, panel_height; |
| 4823 | struct weston_output *output, *target_output = NULL; |
| 4824 | struct weston_seat *seat; |
| 4825 | |
| 4826 | /* As a heuristic place the new window on the same output as the |
| 4827 | * pointer. Falling back to the output containing 0, 0. |
| 4828 | * |
| 4829 | * TODO: Do something clever for touch too? |
| 4830 | */ |
| 4831 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4832 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4833 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4834 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4835 | break; |
| 4836 | } |
| 4837 | } |
| 4838 | |
| 4839 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4840 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4841 | target_output = output; |
| 4842 | break; |
| 4843 | } |
| 4844 | } |
| 4845 | |
| 4846 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4847 | weston_view_set_position(view, 10 + random() % 400, |
| 4848 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4849 | return; |
| 4850 | } |
| 4851 | |
| 4852 | /* Valid range within output where the surface will still be onscreen. |
| 4853 | * If this is negative it means that the surface is bigger than |
| 4854 | * output. |
| 4855 | */ |
| 4856 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4857 | range_x = target_output->width - view->surface->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4858 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4859 | view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4860 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4861 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4862 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4863 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4864 | dx = 0; |
| 4865 | |
| 4866 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4867 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4868 | else |
| 4869 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4870 | |
| 4871 | x = target_output->x + dx; |
| 4872 | y = target_output->y + dy; |
| 4873 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4874 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4875 | } |
| 4876 | |
| 4877 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4878 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4879 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4880 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4881 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4882 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4883 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4884 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4885 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4886 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4887 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4888 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4889 | if (shsurf->state.fullscreen) { |
| 4890 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 4891 | shell_map_fullscreen(shsurf); |
| 4892 | } else if (shsurf->state.maximized) { |
| 4893 | /* use surface configure to set the geometry */ |
| 4894 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4895 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4896 | &surf_x, &surf_y, NULL, NULL); |
| 4897 | weston_view_set_position(shsurf->view, |
| 4898 | shsurf->output->x - surf_x, |
| 4899 | shsurf->output->y + |
| 4900 | panel_height - surf_y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4901 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4902 | weston_view_set_initial_position(shsurf->view, shell); |
| 4903 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4904 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4905 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4906 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4907 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4908 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4909 | weston_view_set_position(shsurf->view, |
| 4910 | shsurf->view->geometry.x + sx, |
| 4911 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4912 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4913 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4914 | default: |
| 4915 | ; |
| 4916 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4917 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 4918 | /* Surface stacking order, see also activate(). */ |
| 4919 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4920 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4921 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4922 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4923 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4924 | shsurf->surface->output = shsurf->output; |
| 4925 | shsurf->view->output = shsurf->output; |
| 4926 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4927 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4928 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4929 | if ((shsurf->type == SHELL_SURFACE_XWAYLAND || shsurf->state.relative) && |
| 4930 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) { |
| 4931 | } |
| 4932 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4933 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4934 | /* XXX: xwayland's using the same fields for transient type */ |
| 4935 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4936 | if (shsurf->transient.flags == |
| 4937 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4938 | break; |
| 4939 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4940 | if (shsurf->state.relative && |
| 4941 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4942 | break; |
| 4943 | if (!shell->locked) |
| 4944 | break; |
| 4945 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 4946 | activate(shell, shsurf->surface, seat); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4947 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4948 | case SHELL_SURFACE_POPUP: |
| 4949 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4950 | default: |
| 4951 | break; |
| 4952 | } |
| 4953 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4954 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 4955 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4956 | { |
| 4957 | switch (shell->win_animation_type) { |
| 4958 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4959 | weston_fade_run(shsurf->view, 0.0, 1.0, 300.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4960 | break; |
| 4961 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4962 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4963 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4964 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4965 | default: |
| 4966 | break; |
| 4967 | } |
| 4968 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4969 | } |
| 4970 | |
| 4971 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4972 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4973 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4974 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4975 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4976 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4977 | int32_t mx, my, surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4978 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4979 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4980 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4981 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4982 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4983 | else if (shsurf->state.maximized) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4984 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4985 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4986 | NULL, NULL); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4987 | mx = shsurf->output->x - surf_x; |
| 4988 | my = shsurf->output->y + |
| 4989 | get_output_panel_height(shell,shsurf->output) - surf_y; |
| 4990 | weston_view_set_position(shsurf->view, mx, my); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4991 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4992 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4993 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4994 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4995 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4996 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4997 | wl_list_for_each(view, &surface->views, surface_link) |
| 4998 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4999 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5000 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5001 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5002 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5003 | } |
| 5004 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5005 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5006 | shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5007 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5008 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5009 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5010 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5011 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5012 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5013 | if (!weston_surface_is_mapped(es) && |
| 5014 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5015 | remove_popup_grab(shsurf); |
| 5016 | } |
| 5017 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5018 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5019 | return; |
| 5020 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5021 | if ((shsurf->next_type != SHELL_SURFACE_NONE && |
| 5022 | shsurf->type != shsurf->next_type) || |
| 5023 | shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5024 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5025 | type_changed = 1; |
| 5026 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5027 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5028 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5029 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5030 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5031 | shsurf->last_width != es->width || |
| 5032 | shsurf->last_height != es->height) { |
| 5033 | shsurf->last_width = es->width; |
| 5034 | shsurf->last_height = es->height; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5035 | float from_x, from_y; |
| 5036 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5037 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5038 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5039 | weston_view_to_global_float(shsurf->view, sx, sy, &to_x, &to_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5040 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5041 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5042 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5043 | } |
| 5044 | } |
| 5045 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5046 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5047 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5048 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5049 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5050 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5051 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5052 | struct desktop_shell *shell = |
| 5053 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5054 | |
| 5055 | shell->child.process.pid = 0; |
| 5056 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5057 | |
| 5058 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5059 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5060 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5061 | shell->child.deathstamp = time; |
| 5062 | shell->child.deathcount = 0; |
| 5063 | } |
| 5064 | |
| 5065 | shell->child.deathcount++; |
| 5066 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5067 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5068 | return; |
| 5069 | } |
| 5070 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5071 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5072 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5073 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5074 | } |
| 5075 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5076 | static void |
| 5077 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5078 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5079 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5080 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5081 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5082 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5083 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5084 | desktop_shell_sigchld); |
| 5085 | |
| 5086 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5087 | weston_log("not able to start %s\n", shell->client); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5088 | } |
| 5089 | |
| 5090 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5091 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5092 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5093 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5094 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5095 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5096 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 5097 | if (resource) |
| 5098 | wl_resource_set_implementation(resource, &shell_implementation, |
| 5099 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5100 | } |
| 5101 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5102 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5103 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5104 | { |
| 5105 | struct desktop_shell *shell = data; |
| 5106 | struct wl_resource *resource; |
| 5107 | |
| 5108 | resource = wl_resource_create(client, &xdg_shell_interface, 1, id); |
| 5109 | if (resource) |
| 5110 | wl_resource_set_dispatcher(resource, |
| 5111 | xdg_shell_unversioned_dispatch, |
| 5112 | NULL, shell, NULL); |
| 5113 | } |
| 5114 | |
| 5115 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5116 | unbind_desktop_shell(struct wl_resource *resource) |
| 5117 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5118 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5119 | |
| 5120 | if (shell->locked) |
| 5121 | resume_desktop(shell); |
| 5122 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5123 | shell->child.desktop_shell = NULL; |
| 5124 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5125 | } |
| 5126 | |
| 5127 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5128 | bind_desktop_shell(struct wl_client *client, |
| 5129 | void *data, uint32_t version, uint32_t id) |
| 5130 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5131 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5132 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5133 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5134 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 5135 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5136 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5137 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5138 | wl_resource_set_implementation(resource, |
| 5139 | &desktop_shell_implementation, |
| 5140 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5141 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5142 | |
| 5143 | if (version < 2) |
| 5144 | shell_fade_startup(shell); |
| 5145 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5146 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5147 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5148 | |
| 5149 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5150 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5151 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5152 | } |
| 5153 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5154 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5155 | screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5156 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5157 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5158 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5159 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5160 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5161 | return; |
| 5162 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 5163 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5164 | if (!shell->locked) |
| 5165 | return; |
| 5166 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5167 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 5168 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5169 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5170 | if (wl_list_empty(&view->layer_link)) { |
| 5171 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 5172 | &view->layer_link); |
| 5173 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5174 | wl_event_source_timer_update(shell->screensaver.timer, |
| 5175 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5176 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5177 | } |
| 5178 | } |
| 5179 | |
| 5180 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5181 | screensaver_set_surface(struct wl_client *client, |
| 5182 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5183 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5184 | struct wl_resource *output_resource) |
| 5185 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5186 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5187 | struct weston_surface *surface = |
| 5188 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5189 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5190 | struct weston_view *view, *next; |
| 5191 | |
| 5192 | /* Make sure we only have one view */ |
| 5193 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 5194 | weston_view_destroy(view); |
| 5195 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5196 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5197 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5198 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5199 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5200 | } |
| 5201 | |
| 5202 | static const struct screensaver_interface screensaver_implementation = { |
| 5203 | screensaver_set_surface |
| 5204 | }; |
| 5205 | |
| 5206 | static void |
| 5207 | unbind_screensaver(struct wl_resource *resource) |
| 5208 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5209 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5210 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5211 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5212 | } |
| 5213 | |
| 5214 | static void |
| 5215 | bind_screensaver(struct wl_client *client, |
| 5216 | void *data, uint32_t version, uint32_t id) |
| 5217 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5218 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5219 | struct wl_resource *resource; |
| 5220 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5221 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5222 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5223 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5224 | wl_resource_set_implementation(resource, |
| 5225 | &screensaver_implementation, |
| 5226 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5227 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5228 | return; |
| 5229 | } |
| 5230 | |
| 5231 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5232 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5233 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5234 | } |
| 5235 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5236 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5237 | input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5238 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5239 | struct input_panel_surface *ip_surface = surface->configure_private; |
| 5240 | struct desktop_shell *shell = ip_surface->shell; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 5241 | float x, y; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5242 | uint32_t show_surface = 0; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 5243 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5244 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5245 | return; |
| 5246 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5247 | if (!weston_surface_is_mapped(surface)) { |
| 5248 | if (!shell->showing_input_panels) |
| 5249 | return; |
| 5250 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5251 | show_surface = 1; |
| 5252 | } |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 5253 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 5254 | fprintf(stderr, "%s panel: %d, output: %p\n", __FUNCTION__, ip_surface->panel, ip_surface->output); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5255 | |
| 5256 | if (ip_surface->panel) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5257 | x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2; |
| 5258 | y = get_default_view(shell->text_input.surface)->geometry.y + shell->text_input.cursor_rectangle.y2; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5259 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5260 | x = ip_surface->output->x + (ip_surface->output->width - surface->width) / 2; |
| 5261 | y = ip_surface->output->y + ip_surface->output->height - surface->height; |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 5262 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5263 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5264 | weston_view_set_position(ip_surface->view, x, y); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5265 | |
| 5266 | if (show_surface) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5267 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 5268 | &ip_surface->view->layer_link); |
| 5269 | weston_view_update_transform(ip_surface->view); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5270 | weston_surface_damage(surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5271 | weston_slide_run(ip_surface->view, ip_surface->view->surface->height, 0, NULL, NULL); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5272 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | static void |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5276 | destroy_input_panel_surface(struct input_panel_surface *input_panel_surface) |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5277 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5278 | wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface); |
| 5279 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5280 | wl_list_remove(&input_panel_surface->surface_destroy_listener.link); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5281 | wl_list_remove(&input_panel_surface->link); |
| 5282 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5283 | input_panel_surface->surface->configure = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5284 | weston_view_destroy(input_panel_surface->view); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5285 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5286 | free(input_panel_surface); |
| 5287 | } |
| 5288 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5289 | static struct input_panel_surface * |
| 5290 | get_input_panel_surface(struct weston_surface *surface) |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5291 | { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5292 | if (surface->configure == input_panel_configure) { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5293 | return surface->configure_private; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5294 | } else { |
| 5295 | return NULL; |
| 5296 | } |
| 5297 | } |
| 5298 | |
| 5299 | static void |
| 5300 | input_panel_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 5301 | { |
| 5302 | struct input_panel_surface *ipsurface = container_of(listener, |
| 5303 | struct input_panel_surface, |
| 5304 | surface_destroy_listener); |
| 5305 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5306 | if (ipsurface->resource) { |
| 5307 | wl_resource_destroy(ipsurface->resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5308 | } else { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5309 | destroy_input_panel_surface(ipsurface); |
| 5310 | } |
| 5311 | } |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5312 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5313 | static struct input_panel_surface * |
| 5314 | create_input_panel_surface(struct desktop_shell *shell, |
| 5315 | struct weston_surface *surface) |
| 5316 | { |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5317 | struct input_panel_surface *input_panel_surface; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5318 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5319 | input_panel_surface = calloc(1, sizeof *input_panel_surface); |
| 5320 | if (!input_panel_surface) |
| 5321 | return NULL; |
| 5322 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5323 | surface->configure = input_panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5324 | surface->configure_private = input_panel_surface; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5325 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5326 | input_panel_surface->shell = shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5327 | |
| 5328 | input_panel_surface->surface = surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5329 | input_panel_surface->view = weston_view_create(surface); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5330 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5331 | wl_signal_init(&input_panel_surface->destroy_signal); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5332 | input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5333 | wl_signal_add(&surface->destroy_signal, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5334 | &input_panel_surface->surface_destroy_listener); |
| 5335 | |
| 5336 | wl_list_init(&input_panel_surface->link); |
| 5337 | |
| 5338 | return input_panel_surface; |
| 5339 | } |
| 5340 | |
| 5341 | static void |
| 5342 | input_panel_surface_set_toplevel(struct wl_client *client, |
| 5343 | struct wl_resource *resource, |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 5344 | struct wl_resource *output_resource, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5345 | uint32_t position) |
| 5346 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5347 | struct input_panel_surface *input_panel_surface = |
| 5348 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5349 | struct desktop_shell *shell = input_panel_surface->shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5350 | |
| 5351 | wl_list_insert(&shell->input_panel.surfaces, |
| 5352 | &input_panel_surface->link); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5353 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5354 | input_panel_surface->output = wl_resource_get_user_data(output_resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5355 | input_panel_surface->panel = 0; |
| 5356 | } |
| 5357 | |
| 5358 | static void |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 5359 | input_panel_surface_set_overlay_panel(struct wl_client *client, |
| 5360 | struct wl_resource *resource) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5361 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5362 | struct input_panel_surface *input_panel_surface = |
| 5363 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5364 | struct desktop_shell *shell = input_panel_surface->shell; |
| 5365 | |
| 5366 | wl_list_insert(&shell->input_panel.surfaces, |
| 5367 | &input_panel_surface->link); |
| 5368 | |
| 5369 | input_panel_surface->panel = 1; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5370 | } |
| 5371 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 5372 | static const struct wl_input_panel_surface_interface input_panel_surface_implementation = { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5373 | input_panel_surface_set_toplevel, |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 5374 | input_panel_surface_set_overlay_panel |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5375 | }; |
| 5376 | |
| 5377 | static void |
| 5378 | destroy_input_panel_surface_resource(struct wl_resource *resource) |
| 5379 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5380 | struct input_panel_surface *ipsurf = |
| 5381 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5382 | |
| 5383 | destroy_input_panel_surface(ipsurf); |
| 5384 | } |
| 5385 | |
| 5386 | static void |
| 5387 | input_panel_get_input_panel_surface(struct wl_client *client, |
| 5388 | struct wl_resource *resource, |
| 5389 | uint32_t id, |
| 5390 | struct wl_resource *surface_resource) |
| 5391 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5392 | struct weston_surface *surface = |
| 5393 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5394 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5395 | struct input_panel_surface *ipsurf; |
| 5396 | |
| 5397 | if (get_input_panel_surface(surface)) { |
| 5398 | wl_resource_post_error(surface_resource, |
| 5399 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 5400 | "wl_input_panel::get_input_panel_surface already requested"); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5401 | return; |
| 5402 | } |
| 5403 | |
| 5404 | ipsurf = create_input_panel_surface(shell, surface); |
| 5405 | if (!ipsurf) { |
| 5406 | wl_resource_post_error(surface_resource, |
| 5407 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5408 | "surface->configure already set"); |
| 5409 | return; |
| 5410 | } |
| 5411 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5412 | ipsurf->resource = |
| 5413 | wl_resource_create(client, |
| 5414 | &wl_input_panel_surface_interface, 1, id); |
| 5415 | wl_resource_set_implementation(ipsurf->resource, |
| 5416 | &input_panel_surface_implementation, |
| 5417 | ipsurf, |
| 5418 | destroy_input_panel_surface_resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5419 | } |
| 5420 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 5421 | static const struct wl_input_panel_interface input_panel_implementation = { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5422 | input_panel_get_input_panel_surface |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5423 | }; |
| 5424 | |
| 5425 | static void |
| 5426 | unbind_input_panel(struct wl_resource *resource) |
| 5427 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5428 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5429 | |
| 5430 | shell->input_panel.binding = NULL; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | static void |
| 5434 | bind_input_panel(struct wl_client *client, |
| 5435 | void *data, uint32_t version, uint32_t id) |
| 5436 | { |
| 5437 | struct desktop_shell *shell = data; |
| 5438 | struct wl_resource *resource; |
| 5439 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5440 | resource = wl_resource_create(client, |
| 5441 | &wl_input_panel_interface, 1, id); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5442 | |
| 5443 | if (shell->input_panel.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5444 | wl_resource_set_implementation(resource, |
| 5445 | &input_panel_implementation, |
| 5446 | shell, unbind_input_panel); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5447 | shell->input_panel.binding = resource; |
| 5448 | return; |
| 5449 | } |
| 5450 | |
| 5451 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5452 | "interface object already bound"); |
| 5453 | wl_resource_destroy(resource); |
| 5454 | } |
| 5455 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5456 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5457 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5458 | struct weston_surface *current; |
| 5459 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5460 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5461 | }; |
| 5462 | |
| 5463 | static void |
| 5464 | switcher_next(struct switcher *switcher) |
| 5465 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5466 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5467 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5468 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5469 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5470 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5471 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5472 | shsurf = get_shell_surface(view->surface); |
| 5473 | switch (shsurf->type) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5474 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5475 | if (shsurf->parent) |
| 5476 | break; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5477 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5478 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5479 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5480 | next = view->surface; |
| 5481 | prev = view->surface; |
| 5482 | view->alpha = 0.25; |
| 5483 | weston_view_geometry_dirty(view); |
| 5484 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5485 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5486 | case SHELL_SURFACE_POPUP: |
| 5487 | case SHELL_SURFACE_XWAYLAND: |
| 5488 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5489 | default: |
| 5490 | break; |
| 5491 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5492 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5493 | if (is_black_surface(view->surface, NULL)) { |
| 5494 | view->alpha = 0.25; |
| 5495 | weston_view_geometry_dirty(view); |
| 5496 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5497 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5498 | } |
| 5499 | |
| 5500 | if (next == NULL) |
| 5501 | next = first; |
| 5502 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5503 | if (next == NULL) |
| 5504 | return; |
| 5505 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5506 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5507 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5508 | |
| 5509 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5510 | wl_list_for_each(view, &next->views, surface_link) |
| 5511 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5512 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5513 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5514 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5515 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5519 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5520 | { |
| 5521 | struct switcher *switcher = |
| 5522 | container_of(listener, struct switcher, listener); |
| 5523 | |
| 5524 | switcher_next(switcher); |
| 5525 | } |
| 5526 | |
| 5527 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5528 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5529 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5530 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5531 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5532 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5533 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5534 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 5535 | if (is_focus_view(view)) |
| 5536 | continue; |
| 5537 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5538 | view->alpha = 1.0; |
| 5539 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5540 | } |
| 5541 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5542 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5543 | activate(switcher->shell, switcher->current, |
| 5544 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5545 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5546 | weston_keyboard_end_grab(keyboard); |
| 5547 | if (keyboard->input_method_resource) |
| 5548 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5549 | free(switcher); |
| 5550 | } |
| 5551 | |
| 5552 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5553 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5554 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5555 | { |
| 5556 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5557 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5558 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5559 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5560 | switcher_next(switcher); |
| 5561 | } |
| 5562 | |
| 5563 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5564 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5565 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5566 | uint32_t mods_locked, uint32_t group) |
| 5567 | { |
| 5568 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5569 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5570 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5571 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5572 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5573 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5574 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5575 | static void |
| 5576 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5577 | { |
| 5578 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5579 | |
| 5580 | switcher_destroy(switcher); |
| 5581 | } |
| 5582 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5583 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5584 | switcher_key, |
| 5585 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5586 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5587 | }; |
| 5588 | |
| 5589 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5590 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5591 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5592 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5593 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5594 | struct switcher *switcher; |
| 5595 | |
| 5596 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5597 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5598 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5599 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5600 | wl_list_init(&switcher->listener.link); |
| 5601 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5602 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5603 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5604 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5605 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5606 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5607 | switcher_next(switcher); |
| 5608 | } |
| 5609 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5610 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5611 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5612 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5613 | { |
| 5614 | struct weston_compositor *compositor = data; |
| 5615 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5616 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5617 | |
| 5618 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5619 | * control on the primary display. We'd have to extend later if we |
| 5620 | * ever get support for setting backlights on random desktop LCD |
| 5621 | * panels though */ |
| 5622 | output = get_default_output(compositor); |
| 5623 | if (!output) |
| 5624 | return; |
| 5625 | |
| 5626 | if (!output->set_backlight) |
| 5627 | return; |
| 5628 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5629 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5630 | backlight_new = output->backlight_current - 25; |
| 5631 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5632 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5633 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5634 | if (backlight_new < 5) |
| 5635 | backlight_new = 5; |
| 5636 | if (backlight_new > 255) |
| 5637 | backlight_new = 255; |
| 5638 | |
| 5639 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5640 | output->set_backlight(output, output->backlight_current); |
| 5641 | } |
| 5642 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5643 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5644 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5645 | struct weston_seat *seat; |
| 5646 | uint32_t key[2]; |
| 5647 | int key_released[2]; |
| 5648 | }; |
| 5649 | |
| 5650 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5651 | debug_binding_key(struct weston_keyboard_grab *grab, uint32_t time, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5652 | uint32_t key, uint32_t state) |
| 5653 | { |
| 5654 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5655 | struct weston_compositor *ec = db->seat->compositor; |
| 5656 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5657 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5658 | uint32_t serial; |
| 5659 | int send = 0, terminate = 0; |
| 5660 | int check_binding = 1; |
| 5661 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5662 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5663 | |
| 5664 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5665 | /* Do not run bindings on key releases */ |
| 5666 | check_binding = 0; |
| 5667 | |
| 5668 | for (i = 0; i < 2; i++) |
| 5669 | if (key == db->key[i]) |
| 5670 | db->key_released[i] = 1; |
| 5671 | |
| 5672 | if (db->key_released[0] && db->key_released[1]) { |
| 5673 | /* All key releases been swalled so end the grab */ |
| 5674 | terminate = 1; |
| 5675 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5676 | /* Should not swallow release of other keys */ |
| 5677 | send = 1; |
| 5678 | } |
| 5679 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5680 | /* Do not check bindings for the first press of the binding |
| 5681 | * key. This allows it to be used as a debug shortcut. |
| 5682 | * We still need to swallow this event. */ |
| 5683 | check_binding = 0; |
| 5684 | } else if (db->key[1]) { |
| 5685 | /* If we already ran a binding don't process another one since |
| 5686 | * we can't keep track of all the binding keys that were |
| 5687 | * pressed in order to swallow the release events. */ |
| 5688 | send = 1; |
| 5689 | check_binding = 0; |
| 5690 | } |
| 5691 | |
| 5692 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5693 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5694 | key, state)) { |
| 5695 | /* We ran a binding so swallow the press and keep the |
| 5696 | * grab to swallow the released too. */ |
| 5697 | send = 0; |
| 5698 | terminate = 0; |
| 5699 | db->key[1] = key; |
| 5700 | } else { |
| 5701 | /* Terminate the grab since the key pressed is not a |
| 5702 | * debug binding key. */ |
| 5703 | send = 1; |
| 5704 | terminate = 1; |
| 5705 | } |
| 5706 | } |
| 5707 | |
| 5708 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5709 | serial = wl_display_next_serial(display); |
| 5710 | resource_list = &grab->keyboard->focus_resource_list; |
| 5711 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5712 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5713 | } |
| 5714 | } |
| 5715 | |
| 5716 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5717 | weston_keyboard_end_grab(grab->keyboard); |
| 5718 | if (grab->keyboard->input_method_resource) |
| 5719 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5720 | free(db); |
| 5721 | } |
| 5722 | } |
| 5723 | |
| 5724 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5725 | debug_binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5726 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5727 | uint32_t mods_locked, uint32_t group) |
| 5728 | { |
| 5729 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5730 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5731 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5732 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5733 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5734 | wl_resource_for_each(resource, resource_list) { |
| 5735 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5736 | mods_latched, mods_locked, group); |
| 5737 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5738 | } |
| 5739 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5740 | static void |
| 5741 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5742 | { |
| 5743 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5744 | |
| 5745 | weston_keyboard_end_grab(grab->keyboard); |
| 5746 | free(db); |
| 5747 | } |
| 5748 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5749 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5750 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5751 | debug_binding_modifiers, |
| 5752 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5753 | }; |
| 5754 | |
| 5755 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5756 | debug_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data) |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5757 | { |
| 5758 | struct debug_binding_grab *grab; |
| 5759 | |
| 5760 | grab = calloc(1, sizeof *grab); |
| 5761 | if (!grab) |
| 5762 | return; |
| 5763 | |
| 5764 | grab->seat = (struct weston_seat *) seat; |
| 5765 | grab->key[0] = key; |
| 5766 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5767 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5768 | } |
| 5769 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5770 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5771 | force_kill_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5772 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5773 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5774 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5775 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5776 | struct desktop_shell *shell = data; |
| 5777 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5778 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5779 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5780 | focus_surface = seat->keyboard->focus; |
| 5781 | if (!focus_surface) |
| 5782 | return; |
| 5783 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5784 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5785 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5786 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5787 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5788 | |
| 5789 | /* Skip clients that we launched ourselves (the credentials of |
| 5790 | * the socketpair is ours) */ |
| 5791 | if (pid == getpid()) |
| 5792 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5793 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5794 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5795 | } |
| 5796 | |
| 5797 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5798 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5799 | uint32_t key, void *data) |
| 5800 | { |
| 5801 | struct desktop_shell *shell = data; |
| 5802 | unsigned int new_index = shell->workspaces.current; |
| 5803 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5804 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5805 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5806 | if (new_index != 0) |
| 5807 | new_index--; |
| 5808 | |
| 5809 | change_workspace(shell, new_index); |
| 5810 | } |
| 5811 | |
| 5812 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5813 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5814 | uint32_t key, void *data) |
| 5815 | { |
| 5816 | struct desktop_shell *shell = data; |
| 5817 | unsigned int new_index = shell->workspaces.current; |
| 5818 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5819 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5820 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5821 | if (new_index < shell->workspaces.num - 1) |
| 5822 | new_index++; |
| 5823 | |
| 5824 | change_workspace(shell, new_index); |
| 5825 | } |
| 5826 | |
| 5827 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5828 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5829 | uint32_t key, void *data) |
| 5830 | { |
| 5831 | struct desktop_shell *shell = data; |
| 5832 | unsigned int new_index; |
| 5833 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5834 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5835 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5836 | new_index = key - KEY_F1; |
| 5837 | if (new_index >= shell->workspaces.num) |
| 5838 | new_index = shell->workspaces.num - 1; |
| 5839 | |
| 5840 | change_workspace(shell, new_index); |
| 5841 | } |
| 5842 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5843 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5844 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5845 | uint32_t key, void *data) |
| 5846 | { |
| 5847 | struct desktop_shell *shell = data; |
| 5848 | unsigned int new_index = shell->workspaces.current; |
| 5849 | |
| 5850 | if (shell->locked) |
| 5851 | return; |
| 5852 | |
| 5853 | if (new_index != 0) |
| 5854 | new_index--; |
| 5855 | |
| 5856 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5857 | } |
| 5858 | |
| 5859 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5860 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5861 | uint32_t key, void *data) |
| 5862 | { |
| 5863 | struct desktop_shell *shell = data; |
| 5864 | unsigned int new_index = shell->workspaces.current; |
| 5865 | |
| 5866 | if (shell->locked) |
| 5867 | return; |
| 5868 | |
| 5869 | if (new_index < shell->workspaces.num - 1) |
| 5870 | new_index++; |
| 5871 | |
| 5872 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5873 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5874 | |
| 5875 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5876 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5877 | { |
| 5878 | struct shell_output *output_listener = |
| 5879 | container_of(listener, struct shell_output, destroy_listener); |
| 5880 | |
| 5881 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5882 | wl_list_remove(&output_listener->link); |
| 5883 | free(output_listener); |
| 5884 | } |
| 5885 | |
| 5886 | static void |
| 5887 | create_shell_output(struct desktop_shell *shell, |
| 5888 | struct weston_output *output) |
| 5889 | { |
| 5890 | struct shell_output *shell_output; |
| 5891 | |
| 5892 | shell_output = zalloc(sizeof *shell_output); |
| 5893 | if (shell_output == NULL) |
| 5894 | return; |
| 5895 | |
| 5896 | shell_output->output = output; |
| 5897 | shell_output->shell = shell; |
| 5898 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5899 | wl_signal_add(&output->destroy_signal, |
| 5900 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5901 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5902 | } |
| 5903 | |
| 5904 | static void |
| 5905 | handle_output_create(struct wl_listener *listener, void *data) |
| 5906 | { |
| 5907 | struct desktop_shell *shell = |
| 5908 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5909 | struct weston_output *output = (struct weston_output *)data; |
| 5910 | |
| 5911 | create_shell_output(shell, output); |
| 5912 | } |
| 5913 | |
| 5914 | static void |
| 5915 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5916 | struct desktop_shell *shell) |
| 5917 | { |
| 5918 | struct weston_output *output; |
| 5919 | |
| 5920 | wl_list_init(&shell->output_list); |
| 5921 | wl_list_for_each(output, &ec->output_list, link) |
| 5922 | create_shell_output(shell, output); |
| 5923 | |
| 5924 | shell->output_create_listener.notify = handle_output_create; |
| 5925 | wl_signal_add(&ec->output_created_signal, |
| 5926 | &shell->output_create_listener); |
| 5927 | } |
| 5928 | |
| 5929 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5930 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5931 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5932 | struct desktop_shell *shell = |
| 5933 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5934 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5935 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5936 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5937 | if (shell->child.client) |
| 5938 | wl_client_destroy(shell->child.client); |
| 5939 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5940 | wl_list_remove(&shell->idle_listener.link); |
| 5941 | wl_list_remove(&shell->wake_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5942 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 5943 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5944 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5945 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5946 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5947 | wl_list_remove(&shell_output->link); |
| 5948 | free(shell_output); |
| 5949 | } |
| 5950 | |
| 5951 | wl_list_remove(&shell->output_create_listener.link); |
| 5952 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5953 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5954 | workspace_destroy(*ws); |
| 5955 | wl_array_release(&shell->workspaces.array); |
| 5956 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5957 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5958 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5959 | free(shell); |
| 5960 | } |
| 5961 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5962 | static void |
| 5963 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5964 | { |
| 5965 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5966 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5967 | |
| 5968 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5969 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5970 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5971 | terminate_binding, ec); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 5972 | weston_compositor_add_key_binding(ec, KEY_TAB, |
| 5973 | MODIFIER_ALT, |
| 5974 | alt_tab_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5975 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5976 | click_to_activate_binding, |
| 5977 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5978 | weston_compositor_add_touch_binding(ec, 0, |
| 5979 | touch_to_activate_binding, |
| 5980 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5981 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5982 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5983 | surface_opacity_binding, NULL); |
| 5984 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5985 | MODIFIER_SUPER, zoom_axis_binding, |
| 5986 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5987 | |
| 5988 | /* configurable bindings */ |
| 5989 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5990 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5991 | zoom_key_binding, NULL); |
| 5992 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5993 | zoom_key_binding, NULL); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 5994 | weston_compositor_add_key_binding(ec, KEY_M, mod, maximize_binding, |
| 5995 | NULL); |
| 5996 | weston_compositor_add_key_binding(ec, KEY_F, mod, fullscreen_binding, |
| 5997 | NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5998 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5999 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6000 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6001 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 6002 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6003 | |
| 6004 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 6005 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 6006 | rotate_binding, NULL); |
| 6007 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6008 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6009 | shell); |
| 6010 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6011 | ec); |
| 6012 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6013 | backlight_binding, ec); |
| 6014 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6015 | ec); |
| 6016 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6017 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6018 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6019 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6020 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6021 | workspace_up_binding, shell); |
| 6022 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6023 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6024 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6025 | workspace_move_surface_up_binding, |
| 6026 | shell); |
| 6027 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6028 | workspace_move_surface_down_binding, |
| 6029 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6030 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6031 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 6032 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6033 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6034 | if (shell->workspaces.num > 1) { |
| 6035 | num_workspace_bindings = shell->workspaces.num; |
| 6036 | if (num_workspace_bindings > 6) |
| 6037 | num_workspace_bindings = 6; |
| 6038 | for (i = 0; i < num_workspace_bindings; i++) |
| 6039 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6040 | workspace_f_binding, |
| 6041 | shell); |
| 6042 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6043 | |
| 6044 | /* Debug bindings */ |
| 6045 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 6046 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6047 | } |
| 6048 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6049 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6050 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6051 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6052 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6053 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6054 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6055 | struct workspace **pws; |
| 6056 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6057 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6058 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6059 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6060 | if (shell == NULL) |
| 6061 | return -1; |
| 6062 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6063 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6064 | |
| 6065 | shell->destroy_listener.notify = shell_destroy; |
| 6066 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6067 | shell->idle_listener.notify = idle_handler; |
| 6068 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6069 | shell->wake_listener.notify = wake_handler; |
| 6070 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6071 | shell->show_input_panel_listener.notify = show_input_panels; |
| 6072 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 6073 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 6074 | wl_signal_add(&ec->hide_input_panel_signal, &shell->hide_input_panel_listener); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 6075 | shell->update_input_panel_listener.notify = update_input_panels; |
| 6076 | wl_signal_add(&ec->update_input_panel_signal, &shell->update_input_panel_listener); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 6077 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6078 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6079 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6080 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6081 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6082 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 6083 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6084 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 6085 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6086 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6087 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6088 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6089 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 6090 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6091 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6092 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6093 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6094 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6095 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6096 | |
| 6097 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6098 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6099 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6100 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6101 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6102 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6103 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6104 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6105 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6106 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6107 | if (pws == NULL) |
| 6108 | return -1; |
| 6109 | |
| 6110 | *pws = workspace_create(); |
| 6111 | if (*pws == NULL) |
| 6112 | return -1; |
| 6113 | } |
| 6114 | activate_workspace(shell, 0); |
| 6115 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6116 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6117 | wl_list_init(&shell->workspaces.animation.link); |
| 6118 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6119 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6120 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6121 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6122 | return -1; |
| 6123 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6124 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6125 | shell, bind_xdg_shell) == NULL) |
| 6126 | return -1; |
| 6127 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6128 | if (wl_global_create(ec->wl_display, |
| 6129 | &desktop_shell_interface, 2, |
| 6130 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6131 | return -1; |
| 6132 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6133 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6134 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6135 | return -1; |
| 6136 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6137 | if (wl_global_create(ec->wl_display, &wl_input_panel_interface, 1, |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6138 | shell, bind_input_panel) == NULL) |
| 6139 | return -1; |
| 6140 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6141 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6142 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6143 | return -1; |
| 6144 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6145 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6146 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6147 | setup_output_destroy_handler(ec, shell); |
| 6148 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6149 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6150 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6151 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6152 | shell->screensaver.timer = |
| 6153 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6154 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6155 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6156 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6157 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6158 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6159 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6160 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6161 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6162 | return 0; |
| 6163 | } |