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" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 39 | #include "workspaces-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 40 | #include "../shared/config-parser.h" |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 41 | #include "xdg-shell-server-protocol.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 42 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 43 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 44 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 45 | |
Giulio Camuffo | 1aaf3e4 | 2013-12-09 22:47:58 +0100 | [diff] [blame] | 46 | #ifndef static_assert |
| 47 | #define static_assert(cond, msg) |
| 48 | #endif |
| 49 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 50 | struct focus_state { |
| 51 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 52 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 53 | struct weston_surface *keyboard_focus; |
| 54 | struct wl_list link; |
| 55 | struct wl_listener seat_destroy_listener; |
| 56 | struct wl_listener surface_destroy_listener; |
| 57 | }; |
| 58 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 59 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 60 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 61 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 62 | SHELL_SURFACE_POPUP, |
| 63 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 64 | }; |
| 65 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 66 | struct shell_client; |
| 67 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 68 | /* |
| 69 | * Surface stacking and ordering. |
| 70 | * |
| 71 | * This is handled using several linked lists of surfaces, organised into |
| 72 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 73 | * above all of the surfaces in the layer below. The set of layers is static and |
| 74 | * in the following order (top-most first): |
| 75 | * • Lock layer (only ever displayed on its own) |
| 76 | * • Cursor layer |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 77 | * • Input panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 78 | * • Fullscreen layer |
| 79 | * • Panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 80 | * • Workspace layers |
| 81 | * • Background layer |
| 82 | * |
| 83 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 84 | * display. For example, when locking the screen, all layers except the lock |
| 85 | * layer are removed. |
| 86 | * |
| 87 | * A surface’s layer is modified on configuring the surface, in |
| 88 | * set_surface_type() (which is only called when the surface’s type change is |
| 89 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 90 | * fullscreen) its layer changes too. |
| 91 | * |
| 92 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 93 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 94 | * linked list of its children. When a surface’s layer is updated, so are the |
| 95 | * layers of its children. Note that child surfaces are *not* the same as |
| 96 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 97 | * order. |
| 98 | * |
| 99 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 100 | * have the same parent) only contains weston_surfaces which have a |
| 101 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 102 | * weston_surfaces. This means that the following implication does *not* hold: |
| 103 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 104 | */ |
| 105 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 106 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 107 | struct wl_resource *resource; |
| 108 | struct wl_signal destroy_signal; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 109 | struct shell_client *owner; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 110 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 111 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 112 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 113 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 114 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 115 | struct wl_listener resource_destroy_listener; |
| 116 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 117 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 118 | struct wl_list children_list; /* child surfaces of this one */ |
| 119 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 120 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 121 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 122 | enum shell_surface_type type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 123 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 124 | int32_t saved_x, saved_y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 125 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 126 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 127 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 128 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 129 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 130 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 131 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 132 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 133 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 134 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 135 | } rotation; |
| 136 | |
| 137 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 138 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 139 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 140 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 141 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 142 | } popup; |
| 143 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 144 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 145 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 146 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 147 | } transient; |
| 148 | |
| 149 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 150 | enum wl_shell_surface_fullscreen_method type; |
| 151 | struct weston_transform transform; /* matrix from x, y */ |
| 152 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 153 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 154 | } fullscreen; |
| 155 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 156 | struct weston_transform workspace_transform; |
| 157 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 158 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 159 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 160 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 161 | |
| 162 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 163 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 164 | struct surface_state { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 165 | bool maximized; |
| 166 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 167 | bool relative; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 168 | bool lowered; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 169 | } state, next_state, requested_state; /* surface states */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 170 | bool state_changed; |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 171 | bool state_requested; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 172 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 173 | struct { |
| 174 | int left, right, top, bottom; |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 175 | } margin, next_margin; |
| 176 | bool has_next_margin; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 177 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 178 | int focus_count; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 179 | }; |
| 180 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 181 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 182 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 183 | struct shell_surface *shsurf; |
| 184 | struct wl_listener shsurf_destroy_listener; |
| 185 | }; |
| 186 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 187 | struct shell_touch_grab { |
| 188 | struct weston_touch_grab grab; |
| 189 | struct shell_surface *shsurf; |
| 190 | struct wl_listener shsurf_destroy_listener; |
| 191 | struct weston_touch *touch; |
| 192 | }; |
| 193 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 194 | struct weston_move_grab { |
| 195 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 196 | wl_fixed_t dx, dy; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 197 | int client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 198 | }; |
| 199 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 200 | struct weston_touch_move_grab { |
| 201 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 202 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 203 | wl_fixed_t dx, dy; |
| 204 | }; |
| 205 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 206 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 207 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 208 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 209 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 210 | float x; |
| 211 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 212 | } center; |
| 213 | }; |
| 214 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 215 | struct shell_seat { |
| 216 | struct weston_seat *seat; |
| 217 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 218 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 219 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 220 | struct wl_listener caps_changed_listener; |
| 221 | struct wl_listener pointer_focus_listener; |
| 222 | struct wl_listener keyboard_focus_listener; |
| 223 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 224 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 225 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 226 | struct wl_list surfaces_list; |
| 227 | struct wl_client *client; |
| 228 | int32_t initial_up; |
| 229 | } popup_grab; |
| 230 | }; |
| 231 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 232 | struct shell_client { |
| 233 | struct wl_resource *resource; |
| 234 | struct wl_client *client; |
| 235 | struct desktop_shell *shell; |
| 236 | struct wl_listener destroy_listener; |
| 237 | struct wl_event_source *ping_timer; |
| 238 | uint32_t ping_serial; |
| 239 | int unresponsive; |
| 240 | }; |
| 241 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 242 | static struct desktop_shell * |
| 243 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 244 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 245 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 246 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 247 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 248 | static void |
| 249 | shell_fade_startup(struct desktop_shell *shell); |
| 250 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 251 | static struct shell_seat * |
| 252 | get_shell_seat(struct weston_seat *seat); |
| 253 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 254 | static int |
| 255 | get_output_panel_height(struct desktop_shell *shell, |
| 256 | struct weston_output *output); |
| 257 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 258 | static void |
| 259 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 260 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 261 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 262 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 263 | |
| 264 | static bool |
| 265 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 266 | |
| 267 | static bool |
| 268 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 269 | |
| 270 | static void |
| 271 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 272 | struct weston_surface *parent); |
| 273 | |
| 274 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 275 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 276 | { |
| 277 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 278 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 279 | |
| 280 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 281 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 282 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 283 | return false; |
| 284 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 285 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 286 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 287 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 288 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 289 | } |
| 290 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 291 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 292 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 293 | { |
| 294 | struct shell_grab *grab; |
| 295 | |
| 296 | grab = container_of(listener, struct shell_grab, |
| 297 | shsurf_destroy_listener); |
| 298 | |
| 299 | grab->shsurf = NULL; |
| 300 | } |
| 301 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 302 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 303 | get_default_view(struct weston_surface *surface) |
| 304 | { |
| 305 | struct shell_surface *shsurf; |
| 306 | struct weston_view *view; |
| 307 | |
| 308 | if (!surface || wl_list_empty(&surface->views)) |
| 309 | return NULL; |
| 310 | |
| 311 | shsurf = get_shell_surface(surface); |
| 312 | if (shsurf) |
| 313 | return shsurf->view; |
| 314 | |
| 315 | wl_list_for_each(view, &surface->views, surface_link) |
| 316 | if (weston_view_is_mapped(view)) |
| 317 | return view; |
| 318 | |
| 319 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 320 | } |
| 321 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 322 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 323 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 324 | |
| 325 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 326 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 327 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 328 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 329 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 330 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 331 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 332 | struct desktop_shell *shell = shsurf->shell; |
| 333 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 334 | popup_grab_end(pointer); |
| 335 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 336 | grab->grab.interface = interface; |
| 337 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 338 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 339 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 340 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 341 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 342 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 343 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 344 | if (shell->child.desktop_shell) { |
| 345 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 346 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 347 | weston_pointer_set_focus(pointer, |
| 348 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 349 | wl_fixed_from_int(0), |
| 350 | wl_fixed_from_int(0)); |
| 351 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 352 | } |
| 353 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 354 | static int |
| 355 | get_output_panel_height(struct desktop_shell *shell, |
| 356 | struct weston_output *output) |
| 357 | { |
| 358 | struct weston_view *view; |
| 359 | int panel_height = 0; |
| 360 | |
| 361 | if (!output) |
| 362 | return 0; |
| 363 | |
| 364 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 365 | if (view->surface->output == output) { |
| 366 | panel_height = view->surface->height; |
| 367 | break; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | return panel_height; |
| 372 | } |
| 373 | |
| 374 | static void |
| 375 | send_configure_for_surface(struct shell_surface *shsurf) |
| 376 | { |
| 377 | int32_t width, height; |
| 378 | struct surface_state *state; |
| 379 | |
| 380 | if (shsurf->state_requested) |
| 381 | state = &shsurf->requested_state; |
| 382 | else if (shsurf->state_changed) |
| 383 | state = &shsurf->next_state; |
| 384 | else |
| 385 | state = &shsurf->state; |
| 386 | |
| 387 | if (state->fullscreen) { |
| 388 | width = shsurf->output->width; |
| 389 | height = shsurf->output->height; |
| 390 | } else if (state->maximized) { |
| 391 | struct desktop_shell *shell; |
| 392 | uint32_t panel_height = 0; |
| 393 | |
| 394 | shell = shell_surface_get_shell(shsurf); |
| 395 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 396 | |
| 397 | width = shsurf->output->width; |
| 398 | height = shsurf->output->height - panel_height; |
| 399 | } else { |
| 400 | width = 0; |
| 401 | height = 0; |
| 402 | } |
| 403 | |
| 404 | shsurf->client->send_configure(shsurf->surface, width, height); |
| 405 | } |
| 406 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 407 | static void |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 408 | shell_surface_state_changed(struct shell_surface *shsurf) |
| 409 | { |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 410 | if (shell_surface_is_xdg_surface(shsurf)) |
| 411 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 415 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 416 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 417 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 418 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 419 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 420 | |
| 421 | if (grab->shsurf->resize_edges) { |
| 422 | grab->shsurf->resize_edges = 0; |
| 423 | shell_surface_state_changed(grab->shsurf); |
| 424 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 425 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 426 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 427 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 431 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 432 | const struct weston_touch_grab_interface *interface, |
| 433 | struct shell_surface *shsurf, |
| 434 | struct weston_touch *touch) |
| 435 | { |
| 436 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 437 | |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 438 | if (touch->seat->pointer) |
| 439 | popup_grab_end(touch->seat->pointer); |
| 440 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 441 | grab->grab.interface = interface; |
| 442 | grab->shsurf = shsurf; |
| 443 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 444 | wl_signal_add(&shsurf->destroy_signal, |
| 445 | &grab->shsurf_destroy_listener); |
| 446 | |
| 447 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 448 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 449 | |
| 450 | weston_touch_start_grab(touch, &grab->grab); |
| 451 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 452 | weston_touch_set_focus(touch->seat, |
| 453 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | static void |
| 457 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 458 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 459 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 460 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 461 | grab->shsurf->grabbed = 0; |
| 462 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 463 | |
| 464 | weston_touch_end_grab(grab->touch); |
| 465 | } |
| 466 | |
| 467 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 468 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 469 | struct weston_output *output); |
| 470 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 471 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 472 | get_modifier(char *modifier) |
| 473 | { |
| 474 | if (!modifier) |
| 475 | return MODIFIER_SUPER; |
| 476 | |
| 477 | if (!strcmp("ctrl", modifier)) |
| 478 | return MODIFIER_CTRL; |
| 479 | else if (!strcmp("alt", modifier)) |
| 480 | return MODIFIER_ALT; |
| 481 | else if (!strcmp("super", modifier)) |
| 482 | return MODIFIER_SUPER; |
| 483 | else |
| 484 | return MODIFIER_SUPER; |
| 485 | } |
| 486 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 487 | static enum animation_type |
| 488 | get_animation_type(char *animation) |
| 489 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 490 | if (!animation) |
| 491 | return ANIMATION_NONE; |
| 492 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 493 | if (!strcmp("zoom", animation)) |
| 494 | return ANIMATION_ZOOM; |
| 495 | else if (!strcmp("fade", animation)) |
| 496 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 497 | else if (!strcmp("dim-layer", animation)) |
| 498 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 499 | else |
| 500 | return ANIMATION_NONE; |
| 501 | } |
| 502 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 503 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 504 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 505 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 506 | struct weston_config_section *section; |
| 507 | int duration; |
| 508 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 509 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 510 | section = weston_config_get_section(shell->compositor->config, |
| 511 | "screensaver", NULL, NULL); |
| 512 | weston_config_section_get_string(section, |
| 513 | "path", &shell->screensaver.path, NULL); |
| 514 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 515 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 516 | |
| 517 | section = weston_config_get_section(shell->compositor->config, |
| 518 | "shell", NULL, NULL); |
| 519 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 520 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 521 | shell->client = s; |
| 522 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 523 | "binding-modifier", &s, "super"); |
| 524 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 525 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 526 | |
| 527 | weston_config_section_get_string(section, |
| 528 | "exposay-modifier", &s, "none"); |
| 529 | if (strcmp(s, "none") == 0) |
| 530 | shell->exposay_modifier = 0; |
| 531 | else |
| 532 | shell->exposay_modifier = get_modifier(s); |
| 533 | free(s); |
| 534 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 535 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 536 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 537 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 538 | weston_config_section_get_string(section, |
| 539 | "startup-animation", &s, "fade"); |
| 540 | shell->startup_animation_type = get_animation_type(s); |
| 541 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 542 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 543 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 544 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 545 | shell->focus_animation_type = get_animation_type(s); |
| 546 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 547 | weston_config_section_get_uint(section, "num-workspaces", |
| 548 | &shell->workspaces.num, |
| 549 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 550 | } |
| 551 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 552 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 553 | get_default_output(struct weston_compositor *compositor) |
| 554 | { |
| 555 | return container_of(compositor->output_list.next, |
| 556 | struct weston_output, link); |
| 557 | } |
| 558 | |
| 559 | |
| 560 | /* no-op func for checking focus surface */ |
| 561 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 562 | 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] | 563 | { |
| 564 | } |
| 565 | |
| 566 | static struct focus_surface * |
| 567 | get_focus_surface(struct weston_surface *surface) |
| 568 | { |
| 569 | if (surface->configure == focus_surface_configure) |
| 570 | return surface->configure_private; |
| 571 | else |
| 572 | return NULL; |
| 573 | } |
| 574 | |
| 575 | static bool |
| 576 | is_focus_surface (struct weston_surface *es) |
| 577 | { |
| 578 | return (es->configure == focus_surface_configure); |
| 579 | } |
| 580 | |
| 581 | static bool |
| 582 | is_focus_view (struct weston_view *view) |
| 583 | { |
| 584 | return is_focus_surface (view->surface); |
| 585 | } |
| 586 | |
| 587 | static struct focus_surface * |
| 588 | create_focus_surface(struct weston_compositor *ec, |
| 589 | struct weston_output *output) |
| 590 | { |
| 591 | struct focus_surface *fsurf = NULL; |
| 592 | struct weston_surface *surface = NULL; |
| 593 | |
| 594 | fsurf = malloc(sizeof *fsurf); |
| 595 | if (!fsurf) |
| 596 | return NULL; |
| 597 | |
| 598 | fsurf->surface = weston_surface_create(ec); |
| 599 | surface = fsurf->surface; |
| 600 | if (surface == NULL) { |
| 601 | free(fsurf); |
| 602 | return NULL; |
| 603 | } |
| 604 | |
| 605 | surface->configure = focus_surface_configure; |
| 606 | surface->output = output; |
| 607 | surface->configure_private = fsurf; |
| 608 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 609 | fsurf->view = weston_view_create(surface); |
| 610 | if (fsurf->view == NULL) { |
| 611 | weston_surface_destroy(surface); |
| 612 | free(fsurf); |
| 613 | return NULL; |
| 614 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 615 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 616 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 617 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 618 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 619 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 620 | pixman_region32_fini(&surface->opaque); |
| 621 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 622 | output->width, output->height); |
| 623 | pixman_region32_fini(&surface->input); |
| 624 | pixman_region32_init(&surface->input); |
| 625 | |
| 626 | wl_list_init(&fsurf->workspace_transform.link); |
| 627 | |
| 628 | return fsurf; |
| 629 | } |
| 630 | |
| 631 | static void |
| 632 | focus_surface_destroy(struct focus_surface *fsurf) |
| 633 | { |
| 634 | weston_surface_destroy(fsurf->surface); |
| 635 | free(fsurf); |
| 636 | } |
| 637 | |
| 638 | static void |
| 639 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 640 | { |
| 641 | struct workspace *ws = data; |
| 642 | |
| 643 | ws->focus_animation = NULL; |
| 644 | } |
| 645 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 646 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 647 | focus_state_destroy(struct focus_state *state) |
| 648 | { |
| 649 | wl_list_remove(&state->seat_destroy_listener.link); |
| 650 | wl_list_remove(&state->surface_destroy_listener.link); |
| 651 | free(state); |
| 652 | } |
| 653 | |
| 654 | static void |
| 655 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 656 | { |
| 657 | struct focus_state *state = container_of(listener, |
| 658 | struct focus_state, |
| 659 | seat_destroy_listener); |
| 660 | |
| 661 | wl_list_remove(&state->link); |
| 662 | focus_state_destroy(state); |
| 663 | } |
| 664 | |
| 665 | static void |
| 666 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 667 | { |
| 668 | struct focus_state *state = container_of(listener, |
| 669 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 670 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 671 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 672 | struct weston_surface *main_surface, *next; |
| 673 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 674 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 675 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 676 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 677 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 678 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 679 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 680 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 681 | if (is_focus_view(view)) |
| 682 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 683 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 684 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 685 | break; |
| 686 | } |
| 687 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 688 | /* if the focus was a sub-surface, activate its main surface */ |
| 689 | if (main_surface != state->keyboard_focus) |
| 690 | next = main_surface; |
| 691 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 692 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 693 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 694 | state->keyboard_focus = NULL; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 695 | activate(shell, next, state->seat, true); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 696 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 697 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 698 | if (state->ws->focus_animation) |
| 699 | weston_view_animation_destroy(state->ws->focus_animation); |
| 700 | |
| 701 | state->ws->focus_animation = weston_fade_run( |
| 702 | state->ws->fsurf_front->view, |
| 703 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 704 | focus_animation_done, state->ws); |
| 705 | } |
| 706 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 707 | wl_list_remove(&state->link); |
| 708 | focus_state_destroy(state); |
| 709 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 713 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 714 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 715 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 716 | |
| 717 | state = malloc(sizeof *state); |
| 718 | if (state == NULL) |
| 719 | return NULL; |
| 720 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 721 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 722 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 723 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 724 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 725 | |
| 726 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 727 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 728 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 729 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 730 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 731 | |
| 732 | return state; |
| 733 | } |
| 734 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 735 | static struct focus_state * |
| 736 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 737 | { |
| 738 | struct workspace *ws = get_current_workspace(shell); |
| 739 | struct focus_state *state; |
| 740 | |
| 741 | wl_list_for_each(state, &ws->focus_list, link) |
| 742 | if (state->seat == seat) |
| 743 | break; |
| 744 | |
| 745 | if (&state->link == &ws->focus_list) |
| 746 | state = focus_state_create(seat, ws); |
| 747 | |
| 748 | return state; |
| 749 | } |
| 750 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 751 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 752 | focus_state_set_focus(struct focus_state *state, |
| 753 | struct weston_surface *surface) |
| 754 | { |
| 755 | if (state->keyboard_focus) { |
| 756 | wl_list_remove(&state->surface_destroy_listener.link); |
| 757 | wl_list_init(&state->surface_destroy_listener.link); |
| 758 | } |
| 759 | |
| 760 | state->keyboard_focus = surface; |
| 761 | if (surface) |
| 762 | wl_signal_add(&surface->destroy_signal, |
| 763 | &state->surface_destroy_listener); |
| 764 | } |
| 765 | |
| 766 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 767 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 768 | { |
| 769 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 770 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 771 | struct wl_list pending_seat_list; |
| 772 | struct weston_seat *seat, *next_seat; |
| 773 | |
| 774 | /* Temporarily steal the list of seats so that we can keep |
| 775 | * track of the seats we've already processed */ |
| 776 | wl_list_init(&pending_seat_list); |
| 777 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 778 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 779 | |
| 780 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 781 | wl_list_remove(&state->seat->link); |
| 782 | wl_list_insert(&shell->compositor->seat_list, |
| 783 | &state->seat->link); |
| 784 | |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 785 | if (state->seat->keyboard == NULL) |
| 786 | continue; |
| 787 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 788 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 789 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 790 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 791 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 792 | |
| 793 | /* For any remaining seats that we don't have a focus state |
| 794 | * for we'll reset the keyboard focus to NULL */ |
| 795 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
| 796 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 797 | |
Ander Conselvan de Oliveira | 6e56ab4 | 2014-05-07 11:57:28 +0300 | [diff] [blame] | 798 | if (seat->keyboard == NULL) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 799 | continue; |
| 800 | |
| 801 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 802 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 806 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 807 | struct weston_seat *seat) |
| 808 | { |
| 809 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 810 | |
| 811 | wl_list_for_each(state, &ws->focus_list, link) { |
| 812 | if (state->seat == seat) { |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 813 | focus_state_set_focus(state, seat->keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 814 | return; |
| 815 | } |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | static void |
| 820 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 821 | struct weston_surface *surface) |
| 822 | { |
| 823 | struct focus_state *state; |
| 824 | |
| 825 | wl_list_for_each(state, &ws->focus_list, link) |
| 826 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 827 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 831 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 832 | struct weston_view *from, struct weston_view *to) |
| 833 | { |
| 834 | struct weston_output *output; |
| 835 | bool focus_surface_created = false; |
| 836 | |
| 837 | /* FIXME: Only support dim animation using two layers */ |
| 838 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 839 | return; |
| 840 | |
| 841 | output = get_default_output(shell->compositor); |
| 842 | if (ws->fsurf_front == NULL && (from || to)) { |
| 843 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 844 | if (ws->fsurf_front == NULL) |
| 845 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 846 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 847 | |
| 848 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 849 | if (ws->fsurf_back == NULL) { |
| 850 | focus_surface_destroy(ws->fsurf_front); |
| 851 | return; |
| 852 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 853 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 854 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 855 | focus_surface_created = true; |
| 856 | } else { |
| 857 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 858 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 859 | } |
| 860 | |
| 861 | if (ws->focus_animation) { |
| 862 | weston_view_animation_destroy(ws->focus_animation); |
| 863 | ws->focus_animation = NULL; |
| 864 | } |
| 865 | |
| 866 | if (to) |
| 867 | wl_list_insert(&to->layer_link, |
| 868 | &ws->fsurf_front->view->layer_link); |
| 869 | else if (from) |
| 870 | wl_list_insert(&ws->layer.view_list, |
| 871 | &ws->fsurf_front->view->layer_link); |
| 872 | |
| 873 | if (focus_surface_created) { |
| 874 | ws->focus_animation = weston_fade_run( |
| 875 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 876 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 877 | focus_animation_done, ws); |
| 878 | } else if (from) { |
| 879 | wl_list_insert(&from->layer_link, |
| 880 | &ws->fsurf_back->view->layer_link); |
| 881 | ws->focus_animation = weston_stable_fade_run( |
| 882 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 883 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 884 | focus_animation_done, ws); |
| 885 | } else if (to) { |
| 886 | wl_list_insert(&ws->layer.view_list, |
| 887 | &ws->fsurf_back->view->layer_link); |
| 888 | ws->focus_animation = weston_stable_fade_run( |
| 889 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 890 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 891 | focus_animation_done, ws); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 896 | workspace_destroy(struct workspace *ws) |
| 897 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 898 | struct focus_state *state, *next; |
| 899 | |
| 900 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 901 | focus_state_destroy(state); |
| 902 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 903 | if (ws->fsurf_front) |
| 904 | focus_surface_destroy(ws->fsurf_front); |
| 905 | if (ws->fsurf_back) |
| 906 | focus_surface_destroy(ws->fsurf_back); |
| 907 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 908 | free(ws); |
| 909 | } |
| 910 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 911 | static void |
| 912 | seat_destroyed(struct wl_listener *listener, void *data) |
| 913 | { |
| 914 | struct weston_seat *seat = data; |
| 915 | struct focus_state *state, *next; |
| 916 | struct workspace *ws = container_of(listener, |
| 917 | struct workspace, |
| 918 | seat_destroyed_listener); |
| 919 | |
| 920 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 921 | if (state->seat == seat) |
| 922 | wl_list_remove(&state->link); |
| 923 | } |
| 924 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 925 | static struct workspace * |
| 926 | workspace_create(void) |
| 927 | { |
| 928 | struct workspace *ws = malloc(sizeof *ws); |
| 929 | if (ws == NULL) |
| 930 | return NULL; |
| 931 | |
| 932 | weston_layer_init(&ws->layer, NULL); |
| 933 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 934 | wl_list_init(&ws->focus_list); |
| 935 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 936 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 937 | ws->fsurf_front = NULL; |
| 938 | ws->fsurf_back = NULL; |
| 939 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 940 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 941 | return ws; |
| 942 | } |
| 943 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 944 | static int |
| 945 | workspace_is_empty(struct workspace *ws) |
| 946 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 947 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 948 | } |
| 949 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 950 | static struct workspace * |
| 951 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 952 | { |
| 953 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 954 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 955 | pws += index; |
| 956 | return *pws; |
| 957 | } |
| 958 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 959 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 960 | get_current_workspace(struct desktop_shell *shell) |
| 961 | { |
| 962 | return get_workspace(shell, shell->workspaces.current); |
| 963 | } |
| 964 | |
| 965 | static void |
| 966 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 967 | { |
| 968 | struct workspace *ws; |
| 969 | |
| 970 | ws = get_workspace(shell, index); |
| 971 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 972 | |
| 973 | shell->workspaces.current = index; |
| 974 | } |
| 975 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 976 | static unsigned int |
| 977 | get_output_height(struct weston_output *output) |
| 978 | { |
| 979 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 980 | } |
| 981 | |
| 982 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 983 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 984 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 985 | struct weston_transform *transform; |
| 986 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 987 | if (is_focus_view(view)) { |
| 988 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 989 | transform = &fsurf->workspace_transform; |
| 990 | } else { |
| 991 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 992 | transform = &shsurf->workspace_transform; |
| 993 | } |
| 994 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 995 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 996 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 997 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 998 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 999 | weston_matrix_init(&transform->matrix); |
| 1000 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1001 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1002 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | static void |
| 1006 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1007 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1008 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1009 | unsigned int height; |
| 1010 | double d; |
| 1011 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1012 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 1013 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1014 | d = height * fraction; |
| 1015 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1016 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | static void |
| 1021 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1022 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1023 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1024 | unsigned int height; |
| 1025 | double d; |
| 1026 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1027 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 1028 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1029 | |
| 1030 | if (fraction > 0) |
| 1031 | d = -(height - height * fraction); |
| 1032 | else |
| 1033 | d = height + height * fraction; |
| 1034 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1035 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1040 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1041 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1042 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1043 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1044 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1045 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1046 | shell->workspaces.current, |
| 1047 | shell->workspaces.num); |
| 1048 | } |
| 1049 | |
| 1050 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1051 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1052 | unsigned int index, |
| 1053 | struct workspace *from, |
| 1054 | struct workspace *to) |
| 1055 | { |
| 1056 | shell->workspaces.current = index; |
| 1057 | |
| 1058 | shell->workspaces.anim_to = to; |
| 1059 | shell->workspaces.anim_from = from; |
| 1060 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1061 | shell->workspaces.anim_timestamp = 0; |
| 1062 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1063 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | static void |
| 1067 | workspace_deactivate_transforms(struct workspace *ws) |
| 1068 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1069 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1070 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1071 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1072 | 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] | 1073 | if (is_focus_view(view)) { |
| 1074 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1075 | transform = &fsurf->workspace_transform; |
| 1076 | } else { |
| 1077 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1078 | transform = &shsurf->workspace_transform; |
| 1079 | } |
| 1080 | |
| 1081 | if (!wl_list_empty(&transform->link)) { |
| 1082 | wl_list_remove(&transform->link); |
| 1083 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1084 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1085 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | static void |
| 1090 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1091 | struct workspace *from, |
| 1092 | struct workspace *to) |
| 1093 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1094 | struct weston_view *view; |
| 1095 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1096 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1097 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1098 | /* Views that extend past the bottom of the output are still |
| 1099 | * visible after the workspace animation ends but before its layer |
| 1100 | * is hidden. In that case, we need to damage below those views so |
| 1101 | * that the screen is properly repainted. */ |
| 1102 | wl_list_for_each(view, &from->layer.view_list, layer_link) |
| 1103 | weston_view_damage_below(view); |
| 1104 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1105 | wl_list_remove(&shell->workspaces.animation.link); |
| 1106 | workspace_deactivate_transforms(from); |
| 1107 | workspace_deactivate_transforms(to); |
| 1108 | shell->workspaces.anim_to = NULL; |
| 1109 | |
| 1110 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1111 | } |
| 1112 | |
| 1113 | static void |
| 1114 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1115 | struct weston_output *output, uint32_t msecs) |
| 1116 | { |
| 1117 | struct desktop_shell *shell = |
| 1118 | container_of(animation, struct desktop_shell, |
| 1119 | workspaces.animation); |
| 1120 | struct workspace *from = shell->workspaces.anim_from; |
| 1121 | struct workspace *to = shell->workspaces.anim_to; |
| 1122 | uint32_t t; |
| 1123 | double x, y; |
| 1124 | |
| 1125 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1126 | finish_workspace_change_animation(shell, from, to); |
| 1127 | return; |
| 1128 | } |
| 1129 | |
| 1130 | if (shell->workspaces.anim_timestamp == 0) { |
| 1131 | if (shell->workspaces.anim_current == 0.0) |
| 1132 | shell->workspaces.anim_timestamp = msecs; |
| 1133 | else |
| 1134 | shell->workspaces.anim_timestamp = |
| 1135 | msecs - |
| 1136 | /* Invers of movement function 'y' below. */ |
| 1137 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1138 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1139 | M_2_PI); |
| 1140 | } |
| 1141 | |
| 1142 | t = msecs - shell->workspaces.anim_timestamp; |
| 1143 | |
| 1144 | /* |
| 1145 | * x = [0, π/2] |
| 1146 | * y(x) = sin(x) |
| 1147 | */ |
| 1148 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1149 | y = sin(x); |
| 1150 | |
| 1151 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1152 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1153 | |
| 1154 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1155 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1156 | shell->workspaces.anim_current = y; |
| 1157 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1158 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1159 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1160 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1161 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | static void |
| 1165 | animate_workspace_change(struct desktop_shell *shell, |
| 1166 | unsigned int index, |
| 1167 | struct workspace *from, |
| 1168 | struct workspace *to) |
| 1169 | { |
| 1170 | struct weston_output *output; |
| 1171 | |
| 1172 | int dir; |
| 1173 | |
| 1174 | if (index > shell->workspaces.current) |
| 1175 | dir = -1; |
| 1176 | else |
| 1177 | dir = 1; |
| 1178 | |
| 1179 | shell->workspaces.current = index; |
| 1180 | |
| 1181 | shell->workspaces.anim_dir = dir; |
| 1182 | shell->workspaces.anim_from = from; |
| 1183 | shell->workspaces.anim_to = to; |
| 1184 | shell->workspaces.anim_current = 0.0; |
| 1185 | shell->workspaces.anim_timestamp = 0; |
| 1186 | |
| 1187 | output = container_of(shell->compositor->output_list.next, |
| 1188 | struct weston_output, link); |
| 1189 | wl_list_insert(&output->animation_list, |
| 1190 | &shell->workspaces.animation.link); |
| 1191 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1192 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1193 | |
| 1194 | workspace_translate_in(to, 0); |
| 1195 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1196 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1197 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1198 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1199 | } |
| 1200 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1201 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1202 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1203 | struct workspace *from, struct workspace *to) |
| 1204 | { |
| 1205 | shell->workspaces.current = index; |
| 1206 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1207 | wl_list_remove(&from->layer.link); |
| 1208 | } |
| 1209 | |
| 1210 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1211 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1212 | { |
| 1213 | struct workspace *from; |
| 1214 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1215 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1216 | |
| 1217 | if (index == shell->workspaces.current) |
| 1218 | return; |
| 1219 | |
| 1220 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1221 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1222 | return; |
| 1223 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1224 | from = get_current_workspace(shell); |
| 1225 | to = get_workspace(shell, index); |
| 1226 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1227 | if (shell->workspaces.anim_from == to && |
| 1228 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1229 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1230 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1231 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1232 | return; |
| 1233 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1234 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1235 | if (shell->workspaces.anim_to != NULL) |
| 1236 | finish_workspace_change_animation(shell, |
| 1237 | shell->workspaces.anim_from, |
| 1238 | shell->workspaces.anim_to); |
| 1239 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1240 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1241 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1242 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1243 | wl_list_for_each(state, &from->focus_list, link) |
| 1244 | if (state->keyboard_focus) |
| 1245 | animate_focus_change(shell, from, |
| 1246 | get_default_view(state->keyboard_focus), NULL); |
| 1247 | |
| 1248 | wl_list_for_each(state, &to->focus_list, link) |
| 1249 | if (state->keyboard_focus) |
| 1250 | animate_focus_change(shell, to, |
| 1251 | NULL, get_default_view(state->keyboard_focus)); |
| 1252 | } |
| 1253 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1254 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1255 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1256 | else |
| 1257 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1258 | |
| 1259 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1260 | } |
| 1261 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1262 | static bool |
| 1263 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1264 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1265 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1266 | struct wl_list *e; |
| 1267 | |
| 1268 | if (wl_list_empty(list)) |
| 1269 | return false; |
| 1270 | |
| 1271 | e = list->next; |
| 1272 | |
| 1273 | if (e->next != list) |
| 1274 | return false; |
| 1275 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1276 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1280 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1281 | struct shell_surface *shsurf, |
| 1282 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1283 | { |
| 1284 | struct workspace *from; |
| 1285 | struct workspace *to; |
| 1286 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1287 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1288 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1289 | |
| 1290 | if (workspace == shell->workspaces.current) |
| 1291 | return; |
| 1292 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1293 | view = get_default_view(shsurf->surface); |
| 1294 | if (!view) |
| 1295 | return; |
| 1296 | |
| 1297 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1298 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1299 | if (workspace >= shell->workspaces.num) |
| 1300 | workspace = shell->workspaces.num - 1; |
| 1301 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1302 | from = get_current_workspace(shell); |
| 1303 | to = get_workspace(shell, workspace); |
| 1304 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1305 | wl_list_remove(&view->layer_link); |
| 1306 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1307 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1308 | shell_surface_update_child_surface_layers(shsurf); |
| 1309 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1310 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1311 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1312 | if (!seat->keyboard) |
| 1313 | continue; |
| 1314 | |
| 1315 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1316 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1317 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1318 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1319 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1320 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1324 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1325 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1326 | unsigned int index) |
| 1327 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1328 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1329 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1330 | struct shell_surface *shsurf; |
| 1331 | struct workspace *from; |
| 1332 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1333 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1334 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1335 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1336 | view = get_default_view(surface); |
| 1337 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1338 | index == shell->workspaces.current || |
| 1339 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1340 | return; |
| 1341 | |
| 1342 | from = get_current_workspace(shell); |
| 1343 | to = get_workspace(shell, index); |
| 1344 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1345 | wl_list_remove(&view->layer_link); |
| 1346 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1347 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1348 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1349 | if (shsurf != NULL) |
| 1350 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1351 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1352 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1353 | drop_focus_state(shell, from, surface); |
| 1354 | |
| 1355 | if (shell->workspaces.anim_from == to && |
| 1356 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1357 | wl_list_remove(&to->layer.link); |
| 1358 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1359 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1360 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1361 | broadcast_current_workspace_state(shell); |
| 1362 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1363 | return; |
| 1364 | } |
| 1365 | |
| 1366 | if (shell->workspaces.anim_to != NULL) |
| 1367 | finish_workspace_change_animation(shell, |
| 1368 | shell->workspaces.anim_from, |
| 1369 | shell->workspaces.anim_to); |
| 1370 | |
| 1371 | if (workspace_is_empty(from) && |
| 1372 | workspace_has_only(to, surface)) |
| 1373 | update_workspace(shell, index, from, to); |
| 1374 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1375 | if (shsurf != NULL && |
| 1376 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1377 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1378 | &shsurf->workspace_transform.link); |
| 1379 | |
| 1380 | animate_workspace_change(shell, index, from, to); |
| 1381 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1382 | |
| 1383 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1384 | |
| 1385 | state = ensure_focus_state(shell, seat); |
| 1386 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1387 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | static void |
| 1391 | workspace_manager_move_surface(struct wl_client *client, |
| 1392 | struct wl_resource *resource, |
| 1393 | struct wl_resource *surface_resource, |
| 1394 | uint32_t workspace) |
| 1395 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1396 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1397 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1398 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1399 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1400 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1401 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1402 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1403 | shell_surface = get_shell_surface(main_surface); |
| 1404 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1405 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1406 | |
| 1407 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1411 | workspace_manager_move_surface, |
| 1412 | }; |
| 1413 | |
| 1414 | static void |
| 1415 | unbind_resource(struct wl_resource *resource) |
| 1416 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1417 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | static void |
| 1421 | bind_workspace_manager(struct wl_client *client, |
| 1422 | void *data, uint32_t version, uint32_t id) |
| 1423 | { |
| 1424 | struct desktop_shell *shell = data; |
| 1425 | struct wl_resource *resource; |
| 1426 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1427 | resource = wl_resource_create(client, |
| 1428 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1429 | |
| 1430 | if (resource == NULL) { |
| 1431 | weston_log("couldn't add workspace manager object"); |
| 1432 | return; |
| 1433 | } |
| 1434 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1435 | wl_resource_set_implementation(resource, |
| 1436 | &workspace_manager_implementation, |
| 1437 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1438 | wl_list_insert(&shell->workspaces.client_list, |
| 1439 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1440 | |
| 1441 | workspace_manager_send_state(resource, |
| 1442 | shell->workspaces.current, |
| 1443 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1444 | } |
| 1445 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1446 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1447 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1448 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1449 | { |
| 1450 | } |
| 1451 | |
| 1452 | static void |
| 1453 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1454 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1455 | struct weston_touch_move_grab *move = |
| 1456 | (struct weston_touch_move_grab *) container_of( |
| 1457 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1458 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1459 | if (touch_id == 0) |
| 1460 | move->active = 0; |
| 1461 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1462 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1463 | shell_touch_grab_end(&move->base); |
| 1464 | free(move); |
| 1465 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | static void |
| 1469 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1470 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1471 | { |
| 1472 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1473 | struct shell_surface *shsurf = move->base.shsurf; |
| 1474 | struct weston_surface *es; |
| 1475 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1476 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1477 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1478 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1479 | return; |
| 1480 | |
| 1481 | es = shsurf->surface; |
| 1482 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1483 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1484 | |
| 1485 | weston_compositor_schedule_repaint(es->compositor); |
| 1486 | } |
| 1487 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1488 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1489 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1490 | { |
| 1491 | } |
| 1492 | |
| 1493 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1494 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1495 | { |
| 1496 | struct weston_touch_move_grab *move = |
| 1497 | (struct weston_touch_move_grab *) container_of( |
| 1498 | grab, struct shell_touch_grab, grab); |
| 1499 | |
| 1500 | shell_touch_grab_end(&move->base); |
| 1501 | free(move); |
| 1502 | } |
| 1503 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1504 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1505 | touch_move_grab_down, |
| 1506 | touch_move_grab_up, |
| 1507 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1508 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1509 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1510 | }; |
| 1511 | |
| 1512 | static int |
| 1513 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1514 | { |
| 1515 | struct weston_touch_move_grab *move; |
| 1516 | |
| 1517 | if (!shsurf) |
| 1518 | return -1; |
| 1519 | |
Ander Conselvan de Oliveira | 6d43f04 | 2014-05-07 14:22:23 +0300 | [diff] [blame] | 1520 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1521 | return 0; |
| 1522 | |
| 1523 | move = malloc(sizeof *move); |
| 1524 | if (!move) |
| 1525 | return -1; |
| 1526 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1527 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1528 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1529 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1530 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1531 | seat->touch->grab_y; |
| 1532 | |
| 1533 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1534 | seat->touch); |
| 1535 | |
| 1536 | return 0; |
| 1537 | } |
| 1538 | |
| 1539 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1540 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1541 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1545 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1546 | { |
| 1547 | struct shell_surface *shsurf = move->base.shsurf; |
| 1548 | struct weston_pointer *pointer = move->base.grab.pointer; |
Kristian Høgsberg | 3434b33 | 2014-04-29 16:38:23 -0700 | [diff] [blame] | 1549 | int x, y, panel_height, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1550 | const int safety = 50; |
| 1551 | |
| 1552 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1553 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1554 | |
| 1555 | panel_height = get_output_panel_height(shsurf->shell, |
| 1556 | shsurf->surface->output); |
| 1557 | bottom = y + shsurf->surface->height - shsurf->margin.bottom; |
| 1558 | if (bottom - panel_height < safety) |
| 1559 | y = panel_height + safety - |
| 1560 | shsurf->surface->height + shsurf->margin.bottom; |
| 1561 | |
| 1562 | if (move->client_initiated && |
| 1563 | y + shsurf->margin.top < panel_height) |
| 1564 | y = panel_height - shsurf->margin.top; |
| 1565 | |
| 1566 | *cx = x; |
| 1567 | *cy = y; |
| 1568 | } |
| 1569 | |
| 1570 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1571 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1572 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1573 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1574 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1575 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1576 | struct shell_surface *shsurf = move->base.shsurf; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1577 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1578 | |
| 1579 | weston_pointer_move(pointer, x, y); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1580 | if (!shsurf) |
| 1581 | return; |
| 1582 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1583 | constrain_position(move, &cx, &cy); |
| 1584 | |
| 1585 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1586 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1587 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1591 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1592 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1593 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1594 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1595 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1596 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1597 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1598 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1599 | if (pointer->button_count == 0 && |
| 1600 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1601 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1602 | free(grab); |
| 1603 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1604 | } |
| 1605 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1606 | static void |
| 1607 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1608 | { |
| 1609 | struct shell_grab *shell_grab = |
| 1610 | container_of(grab, struct shell_grab, grab); |
| 1611 | |
| 1612 | shell_grab_end(shell_grab); |
| 1613 | free(grab); |
| 1614 | } |
| 1615 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1616 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1617 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1618 | move_grab_motion, |
| 1619 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1620 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1621 | }; |
| 1622 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1623 | static int |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1624 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat, |
| 1625 | int client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1626 | { |
| 1627 | struct weston_move_grab *move; |
| 1628 | |
| 1629 | if (!shsurf) |
| 1630 | return -1; |
| 1631 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1632 | if (shsurf->grabbed || |
| 1633 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1634 | return 0; |
| 1635 | |
| 1636 | move = malloc(sizeof *move); |
| 1637 | if (!move) |
| 1638 | return -1; |
| 1639 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1640 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1641 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1642 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1643 | seat->pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1644 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1645 | |
| 1646 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1647 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1648 | |
| 1649 | return 0; |
| 1650 | } |
| 1651 | |
| 1652 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1653 | common_surface_move(struct wl_resource *resource, |
| 1654 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1655 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1656 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1657 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1658 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1659 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1660 | if (seat->pointer && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1661 | seat->pointer->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1662 | seat->pointer->button_count > 0 && |
| 1663 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1664 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1665 | if ((surface == shsurf->surface) && |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1666 | (surface_move(shsurf, seat, 1) < 0)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1667 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1668 | } else if (seat->touch && |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1669 | seat->touch->focus && |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1670 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1671 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1672 | if ((surface == shsurf->surface) && |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1673 | (surface_touch_move(shsurf, seat) < 0)) |
| 1674 | wl_resource_post_no_memory(resource); |
| 1675 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1676 | } |
| 1677 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1678 | static void |
| 1679 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1680 | struct wl_resource *seat_resource, uint32_t serial) |
| 1681 | { |
| 1682 | common_surface_move(resource, seat_resource, serial); |
| 1683 | } |
| 1684 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1685 | struct weston_resize_grab { |
| 1686 | struct shell_grab base; |
| 1687 | uint32_t edges; |
| 1688 | int32_t width, height; |
| 1689 | }; |
| 1690 | |
| 1691 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1692 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1693 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1694 | { |
| 1695 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1696 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1697 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1698 | int32_t width, height; |
| 1699 | wl_fixed_t from_x, from_y; |
| 1700 | wl_fixed_t to_x, to_y; |
| 1701 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1702 | weston_pointer_move(pointer, x, y); |
| 1703 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1704 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1705 | return; |
| 1706 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1707 | weston_view_from_global_fixed(shsurf->view, |
| 1708 | pointer->grab_x, pointer->grab_y, |
| 1709 | &from_x, &from_y); |
| 1710 | weston_view_from_global_fixed(shsurf->view, |
| 1711 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1712 | |
| 1713 | width = resize->width; |
| 1714 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1715 | width += wl_fixed_to_int(from_x - to_x); |
| 1716 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1717 | width += wl_fixed_to_int(to_x - from_x); |
| 1718 | } |
| 1719 | |
| 1720 | height = resize->height; |
| 1721 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1722 | height += wl_fixed_to_int(from_y - to_y); |
| 1723 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1724 | height += wl_fixed_to_int(to_y - from_y); |
| 1725 | } |
| 1726 | |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1727 | shsurf->client->send_configure(shsurf->surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | static void |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1731 | send_configure(struct weston_surface *surface, int32_t width, int32_t height) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1732 | { |
| 1733 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1734 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 1735 | assert(shsurf); |
| 1736 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1737 | if (shsurf->resource) |
| 1738 | wl_shell_surface_send_configure(shsurf->resource, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 1739 | shsurf->resize_edges, |
| 1740 | width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | static const struct weston_shell_client shell_client = { |
| 1744 | send_configure |
| 1745 | }; |
| 1746 | |
| 1747 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1748 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1749 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1750 | { |
| 1751 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1752 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1753 | enum wl_pointer_button_state state = state_w; |
| 1754 | |
| 1755 | if (pointer->button_count == 0 && |
| 1756 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1757 | shell_grab_end(&resize->base); |
| 1758 | free(grab); |
| 1759 | } |
| 1760 | } |
| 1761 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1762 | static void |
| 1763 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1764 | { |
| 1765 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1766 | |
| 1767 | shell_grab_end(&resize->base); |
| 1768 | free(grab); |
| 1769 | } |
| 1770 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1771 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1772 | noop_grab_focus, |
| 1773 | resize_grab_motion, |
| 1774 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1775 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1776 | }; |
| 1777 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1778 | /* |
| 1779 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1780 | * in the surface coordinates system. */ |
| 1781 | static void |
| 1782 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1783 | int32_t *y, int32_t *w, int32_t *h) { |
| 1784 | pixman_region32_t region; |
| 1785 | pixman_box32_t *box; |
| 1786 | struct weston_subsurface *subsurface; |
| 1787 | |
| 1788 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1789 | surface->width, |
| 1790 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1791 | |
| 1792 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1793 | pixman_region32_union_rect(®ion, ®ion, |
| 1794 | subsurface->position.x, |
| 1795 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1796 | subsurface->surface->width, |
| 1797 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | box = pixman_region32_extents(®ion); |
| 1801 | if (x) |
| 1802 | *x = box->x1; |
| 1803 | if (y) |
| 1804 | *y = box->y1; |
| 1805 | if (w) |
| 1806 | *w = box->x2 - box->x1; |
| 1807 | if (h) |
| 1808 | *h = box->y2 - box->y1; |
| 1809 | |
| 1810 | pixman_region32_fini(®ion); |
| 1811 | } |
| 1812 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1813 | static int |
| 1814 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1815 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1816 | { |
| 1817 | struct weston_resize_grab *resize; |
| 1818 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1819 | if (shsurf->grabbed || |
| 1820 | shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1821 | return 0; |
| 1822 | |
| 1823 | if (edges == 0 || edges > 15 || |
| 1824 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1825 | return 0; |
| 1826 | |
| 1827 | resize = malloc(sizeof *resize); |
| 1828 | if (!resize) |
| 1829 | return -1; |
| 1830 | |
| 1831 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1832 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1833 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1834 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1835 | shsurf->resize_edges = edges; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 1836 | shell_surface_state_changed(shsurf); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1837 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1838 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1839 | |
| 1840 | return 0; |
| 1841 | } |
| 1842 | |
| 1843 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1844 | common_surface_resize(struct wl_resource *resource, |
| 1845 | struct wl_resource *seat_resource, uint32_t serial, |
| 1846 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1847 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1848 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1849 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1850 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1851 | |
Emilio Pozuelo Monfort | 5872b68 | 2014-06-18 17:48:58 +0200 | [diff] [blame] | 1852 | if (seat->pointer == NULL || |
| 1853 | seat->pointer->button_count == 0 || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1854 | seat->pointer->grab_serial != serial || |
Kristian Høgsberg | 70f2901 | 2014-01-09 15:43:17 -0800 | [diff] [blame] | 1855 | seat->pointer->focus == NULL) |
| 1856 | return; |
| 1857 | |
| 1858 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
| 1859 | if (surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1860 | return; |
| 1861 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1862 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1863 | wl_resource_post_no_memory(resource); |
| 1864 | } |
| 1865 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1866 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1867 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1868 | struct wl_resource *seat_resource, uint32_t serial, |
| 1869 | uint32_t edges) |
| 1870 | { |
| 1871 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1872 | } |
| 1873 | |
| 1874 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1875 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1876 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1877 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1878 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1879 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1880 | wl_fixed_t sx, sy; |
| 1881 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1882 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1883 | pointer->x, pointer->y, |
| 1884 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1885 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1886 | if (!grab->shsurf || grab->shsurf->surface != view->surface) { |
| 1887 | shell_grab_end(grab); |
| 1888 | free(grab); |
| 1889 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1893 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1894 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1895 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1896 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1897 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1898 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1899 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1900 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1901 | uint32_t time, uint32_t button, uint32_t state) |
| 1902 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1903 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1904 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1905 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1906 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1907 | if (shsurf && button == BTN_LEFT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 1908 | activate(shsurf->shell, shsurf->surface, seat, true); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1909 | surface_move(shsurf, seat, 0); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1910 | } else if (shsurf && button == BTN_RIGHT && state) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 1911 | activate(shsurf->shell, shsurf->surface, seat, true); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1912 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1913 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1914 | } |
| 1915 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1916 | static void |
| 1917 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1918 | { |
| 1919 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1920 | |
| 1921 | shell_grab_end(grab); |
| 1922 | free(grab); |
| 1923 | } |
| 1924 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1925 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1926 | busy_cursor_grab_focus, |
| 1927 | busy_cursor_grab_motion, |
| 1928 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1929 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1930 | }; |
| 1931 | |
| 1932 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1933 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1934 | { |
| 1935 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1936 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1937 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 1938 | return; |
| 1939 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1940 | grab = malloc(sizeof *grab); |
| 1941 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1942 | return; |
| 1943 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1944 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1945 | DESKTOP_SHELL_CURSOR_BUSY); |
Ander Conselvan de Oliveira | e5a1aee | 2014-04-09 17:39:39 +0300 | [diff] [blame] | 1946 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 1947 | * to move it. */ |
| 1948 | shsurf->grabbed = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1949 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1950 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1951 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1952 | end_busy_cursor(struct weston_compositor *compositor, struct wl_client *client) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1953 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1954 | struct shell_grab *grab; |
| 1955 | struct weston_seat *seat; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1956 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1957 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 1958 | if (seat->pointer == NULL) |
| 1959 | continue; |
| 1960 | |
| 1961 | grab = (struct shell_grab *) seat->pointer->grab; |
| 1962 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1963 | wl_resource_get_client(grab->shsurf->resource) == client) { |
| 1964 | shell_grab_end(grab); |
| 1965 | free(grab); |
| 1966 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1967 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1968 | } |
| 1969 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1970 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1971 | handle_shell_client_destroy(struct wl_listener *listener, void *data); |
| 1972 | |
| 1973 | static int |
| 1974 | xdg_ping_timeout_handler(void *data) |
| 1975 | { |
| 1976 | struct shell_client *sc = data; |
| 1977 | struct weston_seat *seat; |
| 1978 | struct shell_surface *shsurf; |
| 1979 | |
| 1980 | /* Client is not responding */ |
| 1981 | sc->unresponsive = 1; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1982 | wl_list_for_each(seat, &sc->shell->compositor->seat_list, link) { |
| 1983 | if (seat->pointer == NULL || seat->pointer->focus == NULL) |
| 1984 | continue; |
| 1985 | if (seat->pointer->focus->surface->resource == NULL) |
| 1986 | continue; |
| 1987 | |
| 1988 | shsurf = get_shell_surface(seat->pointer->focus->surface); |
| 1989 | if (shsurf && |
| 1990 | wl_resource_get_client(shsurf->resource) == sc->client) |
| 1991 | set_busy_cursor(shsurf, seat->pointer); |
| 1992 | } |
| 1993 | |
| 1994 | return 1; |
| 1995 | } |
| 1996 | |
| 1997 | static void |
| 1998 | handle_xdg_ping(struct shell_surface *shsurf, uint32_t serial) |
| 1999 | { |
| 2000 | struct weston_compositor *compositor = shsurf->shell->compositor; |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2001 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2002 | struct wl_event_loop *loop; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2003 | static const int ping_timeout = 200; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2004 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2005 | if (sc->unresponsive) { |
| 2006 | xdg_ping_timeout_handler(sc); |
| 2007 | return; |
| 2008 | } |
| 2009 | |
| 2010 | sc->ping_serial = serial; |
| 2011 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2012 | if (sc->ping_timer == NULL) |
| 2013 | sc->ping_timer = |
| 2014 | wl_event_loop_add_timer(loop, |
| 2015 | xdg_ping_timeout_handler, sc); |
| 2016 | if (sc->ping_timer == NULL) |
| 2017 | return; |
| 2018 | |
| 2019 | wl_event_source_timer_update(sc->ping_timer, ping_timeout); |
| 2020 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2021 | if (shell_surface_is_xdg_surface(shsurf) || |
| 2022 | shell_surface_is_xdg_popup(shsurf)) |
| 2023 | xdg_shell_send_ping(sc->resource, serial); |
| 2024 | else if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2025 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2026 | } |
| 2027 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2028 | static void |
| 2029 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 2030 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2031 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2032 | |
| 2033 | if (!shsurf) |
| 2034 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2035 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 2036 | return; |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 2037 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 2038 | return; |
| 2039 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2040 | handle_xdg_ping(shsurf, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2044 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2045 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2046 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2047 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2048 | struct weston_compositor *compositor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2049 | uint32_t serial; |
| 2050 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2051 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2052 | return; |
| 2053 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2054 | compositor = view->surface->compositor; |
Kristian Høgsberg | e11ef64 | 2014-02-11 16:35:22 -0800 | [diff] [blame] | 2055 | serial = wl_display_next_serial(compositor->wl_display); |
| 2056 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2060 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 2061 | { |
| 2062 | if (--shsurf->focus_count == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2063 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | static void |
| 2067 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 2068 | { |
| 2069 | if (shsurf->focus_count++ == 0) |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2070 | shell_surface_state_changed(shsurf); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | static void |
| 2074 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 2075 | { |
| 2076 | struct weston_keyboard *keyboard = data; |
| 2077 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 2078 | |
| 2079 | if (seat->focused_surface) { |
| 2080 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2081 | if (shsurf) |
| 2082 | shell_surface_lose_keyboard_focus(shsurf); |
| 2083 | } |
| 2084 | |
| 2085 | seat->focused_surface = keyboard->focus; |
| 2086 | |
| 2087 | if (seat->focused_surface) { |
| 2088 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 2089 | if (shsurf) |
| 2090 | shell_surface_gain_keyboard_focus(shsurf); |
| 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | static void |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2095 | shell_client_pong(struct shell_client *sc, uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2096 | { |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2097 | if (sc->ping_serial != serial) |
| 2098 | return; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2099 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2100 | sc->unresponsive = 0; |
| 2101 | end_busy_cursor(sc->shell->compositor, sc->client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2102 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2103 | if (sc->ping_timer) { |
| 2104 | wl_event_source_remove(sc->ping_timer); |
| 2105 | sc->ping_timer = NULL; |
| 2106 | } |
| 2107 | |
| 2108 | } |
| 2109 | |
| 2110 | static void |
| 2111 | shell_surface_pong(struct wl_client *client, |
| 2112 | struct wl_resource *resource, uint32_t serial) |
| 2113 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 2114 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2115 | struct shell_client *sc = shsurf->owner; |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2116 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 2117 | shell_client_pong(sc, serial); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2118 | } |
| 2119 | |
| 2120 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2121 | set_title(struct shell_surface *shsurf, const char *title) |
| 2122 | { |
| 2123 | free(shsurf->title); |
| 2124 | shsurf->title = strdup(title); |
| 2125 | } |
| 2126 | |
| 2127 | static void |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2128 | set_margin(struct shell_surface *shsurf, |
| 2129 | int32_t left, int32_t right, int32_t top, int32_t bottom) |
| 2130 | { |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 2131 | shsurf->next_margin.left = left; |
| 2132 | shsurf->next_margin.right = right; |
| 2133 | shsurf->next_margin.top = top; |
| 2134 | shsurf->next_margin.bottom = bottom; |
| 2135 | shsurf->has_next_margin = true; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2139 | shell_surface_set_title(struct wl_client *client, |
| 2140 | struct wl_resource *resource, const char *title) |
| 2141 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2142 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2143 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2144 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | static void |
| 2148 | shell_surface_set_class(struct wl_client *client, |
| 2149 | struct wl_resource *resource, const char *class) |
| 2150 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2151 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2152 | |
| 2153 | free(shsurf->class); |
| 2154 | shsurf->class = strdup(class); |
| 2155 | } |
| 2156 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2157 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2158 | restore_output_mode(struct weston_output *output) |
| 2159 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2160 | if (output->current_mode != output->original_mode || |
| 2161 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2162 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2163 | output->original_mode, |
| 2164 | output->original_scale, |
| 2165 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | static void |
| 2169 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2170 | { |
| 2171 | struct weston_output *output; |
| 2172 | |
| 2173 | wl_list_for_each(output, &compositor->output_list, link) |
| 2174 | restore_output_mode(output); |
| 2175 | } |
| 2176 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2177 | /* The surface will be inserted into the list immediately after the link |
| 2178 | * returned by this function (i.e. will be stacked immediately above the |
| 2179 | * returned link). */ |
| 2180 | static struct wl_list * |
| 2181 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2182 | { |
| 2183 | struct workspace *ws; |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2184 | struct weston_view *parent; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2185 | |
| 2186 | switch (shsurf->type) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2187 | case SHELL_SURFACE_XWAYLAND: |
| 2188 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2189 | |
| 2190 | case SHELL_SURFACE_NONE: |
| 2191 | return NULL; |
| 2192 | |
Kristian Høgsberg | ead5242 | 2014-01-01 13:51:52 -0800 | [diff] [blame] | 2193 | case SHELL_SURFACE_POPUP: |
| 2194 | case SHELL_SURFACE_TOPLEVEL: |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2195 | if (shsurf->state.fullscreen && !shsurf->state.lowered) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2196 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2197 | } else if (shsurf->parent) { |
Kristian Høgsberg | d55db69 | 2014-01-01 12:26:14 -0800 | [diff] [blame] | 2198 | /* Move the surface to its parent layer so |
| 2199 | * that surfaces which are transient for |
| 2200 | * fullscreen surfaces don't get hidden by the |
| 2201 | * fullscreen surfaces. */ |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2202 | |
| 2203 | /* TODO: Handle a parent with multiple views */ |
| 2204 | parent = get_default_view(shsurf->parent); |
| 2205 | if (parent) |
| 2206 | return parent->layer_link.prev; |
| 2207 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2208 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2209 | /* Move the surface to a normal workspace layer so that surfaces |
| 2210 | * which were previously fullscreen or transient are no longer |
| 2211 | * rendered on top. */ |
| 2212 | ws = get_current_workspace(shsurf->shell); |
| 2213 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2214 | } |
| 2215 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2216 | assert(0 && "Unknown shell surface type"); |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2217 | } |
| 2218 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2219 | static void |
| 2220 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2221 | { |
| 2222 | struct shell_surface *child; |
| 2223 | |
| 2224 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2225 | * stacked above shsurf. */ |
| 2226 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2227 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
Ander Conselvan de Oliveira | facc0cc | 2014-04-10 15:35:58 +0300 | [diff] [blame] | 2228 | weston_view_damage_below(child->view); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2229 | weston_view_geometry_dirty(child->view); |
| 2230 | wl_list_remove(&child->view->layer_link); |
| 2231 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2232 | &child->view->layer_link); |
| 2233 | weston_view_geometry_dirty(child->view); |
| 2234 | weston_surface_damage(child->surface); |
| 2235 | |
| 2236 | /* Recurse. We don’t expect this to recurse very far (if |
| 2237 | * at all) because that would imply we have transient |
| 2238 | * (or popup) children of transient surfaces, which |
| 2239 | * would be unusual. */ |
| 2240 | shell_surface_update_child_surface_layers(child); |
| 2241 | } |
| 2242 | } |
| 2243 | } |
| 2244 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2245 | /* 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] | 2246 | * geometry to ensure the changes are redrawn. |
| 2247 | * |
| 2248 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2249 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2250 | static void |
| 2251 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2252 | { |
| 2253 | struct wl_list *new_layer_link; |
| 2254 | |
| 2255 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2256 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 2257 | if (new_layer_link == NULL) |
| 2258 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2259 | if (new_layer_link == &shsurf->view->layer_link) |
| 2260 | return; |
| 2261 | |
| 2262 | weston_view_geometry_dirty(shsurf->view); |
| 2263 | wl_list_remove(&shsurf->view->layer_link); |
| 2264 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2265 | weston_view_geometry_dirty(shsurf->view); |
| 2266 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2267 | |
| 2268 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2269 | } |
| 2270 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2271 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2272 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2273 | struct weston_surface *parent) |
| 2274 | { |
| 2275 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2276 | |
| 2277 | wl_list_remove(&shsurf->children_link); |
| 2278 | wl_list_init(&shsurf->children_link); |
| 2279 | |
| 2280 | /* Insert into the parent surface’s child list. */ |
| 2281 | if (parent != NULL) { |
| 2282 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2283 | if (parent_shsurf != NULL) |
| 2284 | wl_list_insert(&parent_shsurf->children_list, |
| 2285 | &shsurf->children_link); |
| 2286 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2290 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2291 | struct weston_output *output) |
| 2292 | { |
| 2293 | struct weston_surface *es = shsurf->surface; |
| 2294 | |
| 2295 | /* get the default output, if the client set it as NULL |
| 2296 | check whether the ouput is available */ |
| 2297 | if (output) |
| 2298 | shsurf->output = output; |
| 2299 | else if (es->output) |
| 2300 | shsurf->output = es->output; |
| 2301 | else |
| 2302 | shsurf->output = get_default_output(es->compositor); |
| 2303 | } |
| 2304 | |
| 2305 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2306 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2307 | { |
| 2308 | shsurf->next_state.maximized = false; |
| 2309 | shsurf->next_state.fullscreen = false; |
| 2310 | |
| 2311 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2312 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2313 | shsurf->state_changed = true; |
| 2314 | } |
| 2315 | |
| 2316 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2317 | set_toplevel(struct shell_surface *shsurf) |
| 2318 | { |
Kristian Høgsberg | 41fbf6f | 2013-12-05 22:31:25 -0800 | [diff] [blame] | 2319 | shell_surface_set_parent(shsurf, NULL); |
| 2320 | surface_clear_next_states(shsurf); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2321 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2322 | |
| 2323 | /* The layer_link is updated in set_surface_type(), |
| 2324 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | static void |
| 2328 | shell_surface_set_toplevel(struct wl_client *client, |
| 2329 | struct wl_resource *resource) |
| 2330 | { |
| 2331 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2332 | |
| 2333 | set_toplevel(surface); |
| 2334 | } |
| 2335 | |
| 2336 | static void |
| 2337 | set_transient(struct shell_surface *shsurf, |
| 2338 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2339 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2340 | assert(parent != NULL); |
| 2341 | |
Kristian Høgsberg | 9f7e331 | 2014-01-02 22:40:37 -0800 | [diff] [blame] | 2342 | shell_surface_set_parent(shsurf, parent); |
| 2343 | |
| 2344 | surface_clear_next_states(shsurf); |
| 2345 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2346 | shsurf->transient.x = x; |
| 2347 | shsurf->transient.y = y; |
| 2348 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2349 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2350 | shsurf->next_state.relative = true; |
Kristian Høgsberg | a1df7ac | 2013-12-31 15:01:01 -0800 | [diff] [blame] | 2351 | shsurf->state_changed = true; |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2352 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2353 | |
| 2354 | /* The layer_link is updated in set_surface_type(), |
| 2355 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | static void |
| 2359 | shell_surface_set_transient(struct wl_client *client, |
| 2360 | struct wl_resource *resource, |
| 2361 | struct wl_resource *parent_resource, |
| 2362 | int x, int y, uint32_t flags) |
| 2363 | { |
| 2364 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2365 | struct weston_surface *parent = |
| 2366 | wl_resource_get_user_data(parent_resource); |
| 2367 | |
| 2368 | set_transient(shsurf, parent, x, y, flags); |
| 2369 | } |
| 2370 | |
| 2371 | static void |
| 2372 | set_fullscreen(struct shell_surface *shsurf, |
| 2373 | uint32_t method, |
| 2374 | uint32_t framerate, |
| 2375 | struct weston_output *output) |
| 2376 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2377 | shell_surface_set_output(shsurf, output); |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2378 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2379 | |
| 2380 | shsurf->fullscreen_output = shsurf->output; |
| 2381 | shsurf->fullscreen.type = method; |
| 2382 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2383 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2384 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2388 | weston_view_set_initial_position(struct weston_view *view, |
| 2389 | struct desktop_shell *shell); |
| 2390 | |
| 2391 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2392 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2393 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2394 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2395 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2396 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2397 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2398 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2399 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2400 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2401 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2402 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2403 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2404 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2405 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2406 | if (shsurf->fullscreen.black_view) |
| 2407 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2408 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2409 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2410 | if (shsurf->saved_position_valid) |
| 2411 | weston_view_set_position(shsurf->view, |
| 2412 | shsurf->saved_x, shsurf->saved_y); |
| 2413 | else |
| 2414 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 2415 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2416 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2417 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2418 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2419 | shsurf->saved_rotation_valid = false; |
| 2420 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2421 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2422 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2423 | } |
| 2424 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2425 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2426 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2427 | struct wl_resource *resource, |
| 2428 | uint32_t method, |
| 2429 | uint32_t framerate, |
| 2430 | struct wl_resource *output_resource) |
| 2431 | { |
| 2432 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2433 | struct weston_output *output; |
| 2434 | |
| 2435 | if (output_resource) |
| 2436 | output = wl_resource_get_user_data(output_resource); |
| 2437 | else |
| 2438 | output = NULL; |
| 2439 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2440 | shell_surface_set_parent(shsurf, NULL); |
| 2441 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2442 | surface_clear_next_states(shsurf); |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 2443 | shsurf->next_state.fullscreen = true; |
| 2444 | shsurf->state_changed = true; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 2445 | set_fullscreen(shsurf, method, framerate, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | static void |
| 2449 | set_popup(struct shell_surface *shsurf, |
| 2450 | struct weston_surface *parent, |
| 2451 | struct weston_seat *seat, |
| 2452 | uint32_t serial, |
| 2453 | int32_t x, |
| 2454 | int32_t y) |
| 2455 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2456 | assert(parent != NULL); |
| 2457 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2458 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2459 | shsurf->popup.serial = serial; |
| 2460 | shsurf->popup.x = x; |
| 2461 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2462 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2463 | shsurf->type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | static void |
| 2467 | shell_surface_set_popup(struct wl_client *client, |
| 2468 | struct wl_resource *resource, |
| 2469 | struct wl_resource *seat_resource, |
| 2470 | uint32_t serial, |
| 2471 | struct wl_resource *parent_resource, |
| 2472 | int32_t x, int32_t y, uint32_t flags) |
| 2473 | { |
| 2474 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2475 | struct weston_surface *parent = |
| 2476 | wl_resource_get_user_data(parent_resource); |
| 2477 | |
| 2478 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2479 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2480 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2481 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2482 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2483 | wl_resource_get_user_data(seat_resource), |
| 2484 | serial, x, y); |
| 2485 | } |
| 2486 | |
| 2487 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2488 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2489 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2490 | /* undo all maximized things here */ |
| 2491 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2492 | |
| 2493 | if (shsurf->saved_position_valid) |
| 2494 | weston_view_set_position(shsurf->view, |
| 2495 | shsurf->saved_x, shsurf->saved_y); |
| 2496 | else |
| 2497 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2498 | |
| 2499 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2500 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2501 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2502 | shsurf->saved_rotation_valid = false; |
| 2503 | } |
| 2504 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2505 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2506 | } |
| 2507 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2508 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2509 | set_minimized(struct weston_surface *surface, uint32_t is_true) |
| 2510 | { |
| 2511 | struct shell_surface *shsurf; |
| 2512 | struct workspace *current_ws; |
| 2513 | struct weston_seat *seat; |
| 2514 | struct weston_surface *focus; |
| 2515 | struct weston_view *view; |
| 2516 | |
| 2517 | view = get_default_view(surface); |
| 2518 | if (!view) |
| 2519 | return; |
| 2520 | |
| 2521 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2522 | |
| 2523 | shsurf = get_shell_surface(surface); |
| 2524 | current_ws = get_current_workspace(shsurf->shell); |
| 2525 | |
| 2526 | wl_list_remove(&view->layer_link); |
| 2527 | /* hide or show, depending on the state */ |
| 2528 | if (is_true) { |
| 2529 | wl_list_insert(&shsurf->shell->minimized_layer.view_list, &view->layer_link); |
| 2530 | |
| 2531 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
| 2532 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2533 | if (!seat->keyboard) |
| 2534 | continue; |
| 2535 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
| 2536 | if (focus == view->surface) |
| 2537 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 2538 | } |
| 2539 | } |
| 2540 | else { |
| 2541 | wl_list_insert(¤t_ws->layer.view_list, &view->layer_link); |
| 2542 | |
| 2543 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2544 | if (!seat->keyboard) |
| 2545 | continue; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2546 | activate(shsurf->shell, view->surface, seat, true); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2547 | } |
| 2548 | } |
| 2549 | |
| 2550 | shell_surface_update_child_surface_layers(shsurf); |
| 2551 | |
| 2552 | weston_view_damage_below(view); |
| 2553 | } |
| 2554 | |
| 2555 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2556 | shell_surface_set_maximized(struct wl_client *client, |
| 2557 | struct wl_resource *resource, |
| 2558 | struct wl_resource *output_resource) |
| 2559 | { |
| 2560 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2561 | struct weston_output *output; |
| 2562 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2563 | surface_clear_next_states(shsurf); |
| 2564 | shsurf->next_state.maximized = true; |
| 2565 | shsurf->state_changed = true; |
| 2566 | |
| 2567 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
| 2568 | shell_surface_set_parent(shsurf, NULL); |
| 2569 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2570 | if (output_resource) |
| 2571 | output = wl_resource_get_user_data(output_resource); |
| 2572 | else |
| 2573 | output = NULL; |
| 2574 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2575 | shell_surface_set_output(shsurf, output); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2576 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2577 | send_configure_for_surface(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2578 | } |
| 2579 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2580 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2581 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2582 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2583 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2584 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2585 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2586 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2587 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2588 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2589 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2590 | return 0; |
| 2591 | } |
| 2592 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2593 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2594 | set_full_output(struct shell_surface *shsurf) |
| 2595 | { |
| 2596 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2597 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2598 | shsurf->saved_width = shsurf->surface->width; |
| 2599 | shsurf->saved_height = shsurf->surface->height; |
| 2600 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2601 | shsurf->saved_position_valid = true; |
| 2602 | |
| 2603 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2604 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2605 | wl_list_init(&shsurf->rotation.transform.link); |
| 2606 | weston_view_geometry_dirty(shsurf->view); |
| 2607 | shsurf->saved_rotation_valid = true; |
| 2608 | } |
| 2609 | } |
| 2610 | |
| 2611 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2612 | set_surface_type(struct shell_surface *shsurf) |
| 2613 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2614 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2615 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2616 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2617 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2618 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2619 | shsurf->state = shsurf->next_state; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2620 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2621 | |
| 2622 | switch (shsurf->type) { |
| 2623 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2624 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2625 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2626 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2627 | weston_view_set_position(shsurf->view, |
| 2628 | pev->geometry.x + shsurf->transient.x, |
| 2629 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2630 | } |
Rafael Antognolli | 44a3162 | 2013-12-04 18:37:16 -0200 | [diff] [blame] | 2631 | break; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2632 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2633 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2634 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2635 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2636 | break; |
| 2637 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2638 | case SHELL_SURFACE_POPUP: |
| 2639 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2640 | default: |
| 2641 | break; |
| 2642 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2643 | |
| 2644 | /* Update the surface’s layer. */ |
| 2645 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2646 | } |
| 2647 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2648 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2649 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2650 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2651 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2652 | } |
| 2653 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2654 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2655 | 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] | 2656 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2657 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2658 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2659 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2660 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2661 | { |
| 2662 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2663 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2664 | |
| 2665 | surface = weston_surface_create(ec); |
| 2666 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2667 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2668 | return NULL; |
| 2669 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2670 | view = weston_view_create(surface); |
| 2671 | if (surface == NULL) { |
| 2672 | weston_log("no memory\n"); |
| 2673 | weston_surface_destroy(surface); |
| 2674 | return NULL; |
| 2675 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2676 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2677 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2678 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2679 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2680 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2681 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2682 | pixman_region32_fini(&surface->input); |
| 2683 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2684 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2685 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2686 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2687 | |
| 2688 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2689 | } |
| 2690 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2691 | static void |
| 2692 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2693 | { |
| 2694 | struct weston_output *output = shsurf->fullscreen_output; |
| 2695 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2696 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2697 | |
| 2698 | if (!shsurf->fullscreen.black_view) |
| 2699 | shsurf->fullscreen.black_view = |
| 2700 | create_black_surface(shsurf->surface->compositor, |
| 2701 | shsurf->surface, |
| 2702 | output->x, output->y, |
| 2703 | output->width, |
| 2704 | output->height); |
| 2705 | |
| 2706 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2707 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2708 | wl_list_insert(&shsurf->view->layer_link, |
| 2709 | &shsurf->fullscreen.black_view->layer_link); |
| 2710 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2711 | weston_surface_damage(shsurf->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2712 | |
| 2713 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2714 | } |
| 2715 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2716 | /* Create black surface and append it to the associated fullscreen surface. |
| 2717 | * Handle size dismatch and positioning according to the method. */ |
| 2718 | static void |
| 2719 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2720 | { |
| 2721 | struct weston_output *output = shsurf->fullscreen_output; |
| 2722 | struct weston_surface *surface = shsurf->surface; |
| 2723 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2724 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2725 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2726 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2727 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2728 | restore_output_mode(output); |
| 2729 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2730 | /* Reverse the effect of lower_fullscreen_layer() */ |
| 2731 | wl_list_remove(&shsurf->view->layer_link); |
| 2732 | wl_list_insert(&shsurf->shell->fullscreen_layer.view_list, &shsurf->view->layer_link); |
| 2733 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2734 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2735 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2736 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2737 | &surf_width, &surf_height); |
| 2738 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2739 | switch (shsurf->fullscreen.type) { |
| 2740 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2741 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2742 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2743 | break; |
| 2744 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2745 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2746 | if (output->width == surf_width && |
| 2747 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2748 | weston_view_set_position(shsurf->view, |
| 2749 | output->x - surf_x, |
| 2750 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2751 | break; |
| 2752 | } |
| 2753 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2754 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2755 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2756 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2757 | output_aspect = (float) output->width / |
| 2758 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2759 | /* XXX: Use surf_width and surf_height here? */ |
| 2760 | surface_aspect = (float) surface->width / |
| 2761 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2762 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2763 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2764 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2765 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2766 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2767 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2768 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2769 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2770 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2771 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2772 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2773 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2774 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2775 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2776 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2777 | break; |
| 2778 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2779 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2780 | struct weston_mode mode = {0, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2781 | surf_width * surface->buffer_viewport.buffer.scale, |
| 2782 | surf_height * surface->buffer_viewport.buffer.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2783 | shsurf->fullscreen.framerate}; |
| 2784 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2785 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.buffer.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2786 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2787 | weston_view_set_position(shsurf->view, |
| 2788 | output->x - surf_x, |
| 2789 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2790 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2791 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2792 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2793 | output->x - surf_x, |
| 2794 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2795 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2796 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2797 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2798 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2799 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2800 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2801 | break; |
| 2802 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2803 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2804 | break; |
| 2805 | default: |
| 2806 | break; |
| 2807 | } |
| 2808 | } |
| 2809 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2810 | static void |
| 2811 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2812 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2813 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2814 | } |
| 2815 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2816 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2817 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2818 | { |
| 2819 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2820 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2821 | shsurf->transient.x = x; |
| 2822 | shsurf->transient.y = y; |
| 2823 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2824 | |
| 2825 | shell_surface_set_parent(shsurf, NULL); |
| 2826 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 2827 | shsurf->type = SHELL_SURFACE_XWAYLAND; |
Kristian Høgsberg | 8bc525c | 2014-01-01 22:34:49 -0800 | [diff] [blame] | 2828 | shsurf->state_changed = true; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2829 | } |
| 2830 | |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 2831 | static void |
| 2832 | shell_interface_set_fullscreen(struct shell_surface *shsurf, |
| 2833 | uint32_t method, |
| 2834 | uint32_t framerate, |
| 2835 | struct weston_output *output) |
| 2836 | { |
| 2837 | surface_clear_next_states(shsurf); |
| 2838 | set_fullscreen(shsurf, method, framerate, output); |
| 2839 | |
| 2840 | shsurf->next_state.fullscreen = true; |
| 2841 | shsurf->state_changed = true; |
| 2842 | } |
| 2843 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 2844 | static int |
| 2845 | shell_interface_move(struct shell_surface *shsurf, struct weston_seat *ws) |
| 2846 | { |
| 2847 | return surface_move(shsurf, ws, 1); |
| 2848 | } |
| 2849 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2850 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2851 | |
| 2852 | static void |
| 2853 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2854 | { |
| 2855 | struct shell_seat *shseat = |
| 2856 | container_of(listener, |
| 2857 | struct shell_seat, seat_destroy_listener); |
| 2858 | struct shell_surface *shsurf, *prev = NULL; |
| 2859 | |
| 2860 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2861 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2862 | shseat->popup_grab.client = NULL; |
| 2863 | |
| 2864 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2865 | shsurf->popup.shseat = NULL; |
| 2866 | if (prev) { |
| 2867 | wl_list_init(&prev->popup.grab_link); |
| 2868 | } |
| 2869 | prev = shsurf; |
| 2870 | } |
| 2871 | wl_list_init(&prev->popup.grab_link); |
| 2872 | } |
| 2873 | |
| 2874 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2875 | free(shseat); |
| 2876 | } |
| 2877 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2878 | static void |
| 2879 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 2880 | { |
| 2881 | struct shell_seat *seat; |
| 2882 | |
| 2883 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
| 2884 | |
| 2885 | if (seat->seat->keyboard && |
| 2886 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
| 2887 | wl_signal_add(&seat->seat->keyboard->focus_signal, |
| 2888 | &seat->keyboard_focus_listener); |
| 2889 | } else if (!seat->seat->keyboard) { |
| 2890 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 2891 | } |
| 2892 | |
| 2893 | if (seat->seat->pointer && |
| 2894 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
| 2895 | wl_signal_add(&seat->seat->pointer->focus_signal, |
| 2896 | &seat->pointer_focus_listener); |
| 2897 | } else if (!seat->seat->pointer) { |
| 2898 | wl_list_init(&seat->pointer_focus_listener.link); |
| 2899 | } |
| 2900 | } |
| 2901 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2902 | static struct shell_seat * |
| 2903 | create_shell_seat(struct weston_seat *seat) |
| 2904 | { |
| 2905 | struct shell_seat *shseat; |
| 2906 | |
| 2907 | shseat = calloc(1, sizeof *shseat); |
| 2908 | if (!shseat) { |
| 2909 | weston_log("no memory to allocate shell seat\n"); |
| 2910 | return NULL; |
| 2911 | } |
| 2912 | |
| 2913 | shseat->seat = seat; |
| 2914 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2915 | |
| 2916 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2917 | wl_signal_add(&seat->destroy_signal, |
| 2918 | &shseat->seat_destroy_listener); |
| 2919 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2920 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 2921 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 2922 | |
| 2923 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 2924 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 2925 | |
| 2926 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 2927 | wl_signal_add(&seat->updated_caps_signal, |
| 2928 | &shseat->caps_changed_listener); |
| 2929 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 2930 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2931 | return shseat; |
| 2932 | } |
| 2933 | |
| 2934 | static struct shell_seat * |
| 2935 | get_shell_seat(struct weston_seat *seat) |
| 2936 | { |
| 2937 | struct wl_listener *listener; |
| 2938 | |
| 2939 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2940 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2941 | |
| 2942 | return container_of(listener, |
| 2943 | struct shell_seat, seat_destroy_listener); |
| 2944 | } |
| 2945 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2946 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2947 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2948 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2949 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2950 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2951 | struct shell_seat *shseat = |
| 2952 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2953 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2954 | wl_fixed_t sx, sy; |
| 2955 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2956 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2957 | pointer->x, pointer->y, |
| 2958 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2959 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2960 | if (view && view->surface->resource && |
| 2961 | wl_resource_get_client(view->surface->resource) == client) { |
| 2962 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2963 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2964 | weston_pointer_set_focus(pointer, NULL, |
| 2965 | wl_fixed_from_int(0), |
| 2966 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2967 | } |
| 2968 | } |
| 2969 | |
| 2970 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2971 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2972 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2973 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2974 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2975 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2976 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2977 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2978 | weston_pointer_move(pointer, x, y); |
| 2979 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2980 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2981 | weston_view_from_global_fixed(pointer->focus, |
| 2982 | pointer->x, pointer->y, |
| 2983 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2984 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2985 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2989 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2990 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2991 | { |
| 2992 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2993 | struct shell_seat *shseat = |
| 2994 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2995 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2996 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2997 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2998 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2999 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3000 | resource_list = &grab->pointer->focus_resource_list; |
| 3001 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3002 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 3003 | wl_resource_for_each(resource, resource_list) { |
| 3004 | wl_pointer_send_button(resource, serial, |
| 3005 | time, button, state); |
| 3006 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3007 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3008 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3009 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3010 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3011 | } |
| 3012 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3013 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3014 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3015 | } |
| 3016 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3017 | static void |
| 3018 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 3019 | { |
| 3020 | popup_grab_end(grab->pointer); |
| 3021 | } |
| 3022 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3023 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3024 | popup_grab_focus, |
| 3025 | popup_grab_motion, |
| 3026 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3027 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3028 | }; |
| 3029 | |
| 3030 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3031 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 3032 | { |
| 3033 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 3034 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 3035 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 3036 | xdg_popup_send_popup_done(shsurf->resource, |
| 3037 | shsurf->popup.serial); |
| 3038 | } |
| 3039 | |
| 3040 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3041 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3042 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3043 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3044 | struct shell_seat *shseat = |
| 3045 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 3046 | struct shell_surface *shsurf; |
| 3047 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3048 | |
| 3049 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3050 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3051 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3052 | shseat->popup_grab.grab.interface = NULL; |
| 3053 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3054 | /* Send the popup_done event to all the popups open */ |
| 3055 | 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] | 3056 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3057 | shsurf->popup.shseat = NULL; |
| 3058 | if (prev) { |
| 3059 | wl_list_init(&prev->popup.grab_link); |
| 3060 | } |
| 3061 | prev = shsurf; |
| 3062 | } |
| 3063 | wl_list_init(&prev->popup.grab_link); |
| 3064 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 3065 | } |
| 3066 | } |
| 3067 | |
| 3068 | static void |
| 3069 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 3070 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3071 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3072 | |
| 3073 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3074 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3075 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 3076 | /* We must make sure here that this popup was opened after |
| 3077 | * a mouse press, and not just by moving around with other |
| 3078 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3079 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 3080 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3081 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3082 | 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] | 3083 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 3084 | } else { |
| 3085 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3086 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3087 | } |
| 3088 | |
| 3089 | static void |
| 3090 | remove_popup_grab(struct shell_surface *shsurf) |
| 3091 | { |
| 3092 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 3093 | |
| 3094 | wl_list_remove(&shsurf->popup.grab_link); |
| 3095 | wl_list_init(&shsurf->popup.grab_link); |
| 3096 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3097 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 3098 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 3099 | } |
| 3100 | } |
| 3101 | |
| 3102 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3103 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3104 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3105 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3106 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3107 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3108 | shsurf->surface->output = parent_view->output; |
| 3109 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3110 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3111 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3112 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3113 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3114 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3115 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3116 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3117 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3118 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3119 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3120 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3121 | } |
| 3122 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3123 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3124 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3125 | shell_surface_move, |
| 3126 | shell_surface_resize, |
| 3127 | shell_surface_set_toplevel, |
| 3128 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3129 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3130 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3131 | shell_surface_set_maximized, |
| 3132 | shell_surface_set_title, |
| 3133 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3134 | }; |
| 3135 | |
| 3136 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3137 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3138 | { |
Kristian Høgsberg | 9046d24 | 2014-01-10 00:25:30 -0800 | [diff] [blame] | 3139 | struct shell_surface *child, *next; |
| 3140 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3141 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3142 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3143 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3144 | remove_popup_grab(shsurf); |
| 3145 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3146 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3147 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3148 | shell_surface_is_top_fullscreen(shsurf)) |
| 3149 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3150 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3151 | if (shsurf->fullscreen.black_view) |
| 3152 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3153 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3154 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3155 | * we can always remove the listener. |
| 3156 | */ |
| 3157 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3158 | shsurf->surface->configure = NULL; |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3159 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3160 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3161 | weston_view_destroy(shsurf->view); |
| 3162 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3163 | wl_list_remove(&shsurf->children_link); |
Emilio Pozuelo Monfort | adaa20c | 2014-01-28 13:54:16 +0100 | [diff] [blame] | 3164 | wl_list_for_each_safe(child, next, &shsurf->children_list, children_link) |
| 3165 | shell_surface_set_parent(child, NULL); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3166 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3167 | wl_list_remove(&shsurf->link); |
| 3168 | free(shsurf); |
| 3169 | } |
| 3170 | |
| 3171 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3172 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3173 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3174 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3175 | |
Bryan Cain | a46b946 | 2014-04-04 17:41:24 -0500 | [diff] [blame] | 3176 | if (!wl_list_empty(&shsurf->popup.grab_link)) |
| 3177 | remove_popup_grab(shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3178 | shsurf->resource = NULL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3182 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3183 | { |
| 3184 | struct shell_surface *shsurf = container_of(listener, |
| 3185 | struct shell_surface, |
| 3186 | surface_destroy_listener); |
| 3187 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3188 | if (shsurf->resource) |
| 3189 | wl_resource_destroy(shsurf->resource); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3190 | |
| 3191 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3192 | } |
| 3193 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3194 | static void |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3195 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 3196 | { |
| 3197 | struct shell_surface *shsurf = data; |
| 3198 | |
| 3199 | weston_surface_destroy(shsurf->surface); |
| 3200 | } |
| 3201 | |
| 3202 | static void |
| 3203 | handle_resource_destroy(struct wl_listener *listener, void *data) |
| 3204 | { |
| 3205 | struct shell_surface *shsurf = |
| 3206 | container_of(listener, struct shell_surface, |
| 3207 | resource_destroy_listener); |
| 3208 | |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3209 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3210 | return; |
| 3211 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3212 | shsurf->surface->ref_count++; |
| 3213 | |
| 3214 | pixman_region32_fini(&shsurf->surface->pending.input); |
| 3215 | pixman_region32_init(&shsurf->surface->pending.input); |
| 3216 | pixman_region32_fini(&shsurf->surface->input); |
| 3217 | pixman_region32_init(&shsurf->surface->input); |
Ander Conselvan de Oliveira | 15f9a26 | 2014-04-29 17:54:02 +0300 | [diff] [blame] | 3218 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 3219 | fade_out_done, shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3223 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3224 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3225 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3226 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3227 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3228 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3229 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3230 | else |
| 3231 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3232 | } |
| 3233 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3234 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3235 | create_common_surface(struct shell_client *owner, void *shell, |
| 3236 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3237 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3238 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3239 | struct shell_surface *shsurf; |
| 3240 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3241 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3242 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3243 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3244 | } |
| 3245 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3246 | shsurf = calloc(1, sizeof *shsurf); |
| 3247 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3248 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3249 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3250 | } |
| 3251 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3252 | shsurf->view = weston_view_create(surface); |
| 3253 | if (!shsurf->view) { |
| 3254 | weston_log("no memory to allocate shell surface\n"); |
| 3255 | free(shsurf); |
| 3256 | return NULL; |
| 3257 | } |
| 3258 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3259 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3260 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3261 | |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3262 | shsurf->resource_destroy_listener.notify = handle_resource_destroy; |
| 3263 | wl_resource_add_destroy_listener(surface->resource, |
| 3264 | &shsurf->resource_destroy_listener); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3265 | shsurf->owner = owner; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 3266 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3267 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3268 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3269 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3270 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3271 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3272 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3273 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3274 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3275 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3276 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3277 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3278 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 3279 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3280 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3281 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3282 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3283 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3284 | |
| 3285 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3286 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3287 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3288 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3289 | /* empty when not in use */ |
| 3290 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3291 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3292 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3293 | wl_list_init(&shsurf->workspace_transform.link); |
| 3294 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3295 | wl_list_init(&shsurf->children_link); |
| 3296 | wl_list_init(&shsurf->children_list); |
| 3297 | shsurf->parent = NULL; |
| 3298 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3299 | shsurf->type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3300 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3301 | shsurf->client = client; |
| 3302 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3303 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3304 | } |
| 3305 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3306 | static struct shell_surface * |
| 3307 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3308 | const struct weston_shell_client *client) |
| 3309 | { |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3310 | return create_common_surface(NULL, shell, surface, client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3311 | } |
| 3312 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3313 | static struct weston_view * |
| 3314 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3315 | { |
| 3316 | return shsurf->view; |
| 3317 | } |
| 3318 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3319 | static void |
| 3320 | shell_get_shell_surface(struct wl_client *client, |
| 3321 | struct wl_resource *resource, |
| 3322 | uint32_t id, |
| 3323 | struct wl_resource *surface_resource) |
| 3324 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3325 | struct weston_surface *surface = |
| 3326 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3327 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3328 | struct desktop_shell *shell = sc->shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3329 | struct shell_surface *shsurf; |
| 3330 | |
| 3331 | if (get_shell_surface(surface)) { |
| 3332 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3333 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3334 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3335 | return; |
| 3336 | } |
| 3337 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3338 | shsurf = create_common_surface(sc, shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3339 | if (!shsurf) { |
| 3340 | wl_resource_post_error(surface_resource, |
| 3341 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3342 | "surface->configure already set"); |
| 3343 | return; |
| 3344 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3345 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3346 | shsurf->resource = |
| 3347 | wl_resource_create(client, |
| 3348 | &wl_shell_surface_interface, 1, id); |
| 3349 | wl_resource_set_implementation(shsurf->resource, |
| 3350 | &shell_surface_implementation, |
| 3351 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3352 | } |
| 3353 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3354 | static bool |
| 3355 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3356 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3357 | /* A shell surface without a resource is created from xwayland |
| 3358 | * and is considered a wl_shell surface for now. */ |
| 3359 | |
| 3360 | return shsurf->resource == NULL || |
| 3361 | wl_resource_instance_of(shsurf->resource, |
| 3362 | &wl_shell_surface_interface, |
| 3363 | &shell_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3364 | } |
| 3365 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3366 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3367 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3368 | }; |
| 3369 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3370 | /**************************** |
| 3371 | * xdg-shell implementation */ |
| 3372 | |
| 3373 | static void |
| 3374 | xdg_surface_destroy(struct wl_client *client, |
| 3375 | struct wl_resource *resource) |
| 3376 | { |
| 3377 | wl_resource_destroy(resource); |
| 3378 | } |
| 3379 | |
| 3380 | static void |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3381 | xdg_surface_set_parent(struct wl_client *client, |
| 3382 | struct wl_resource *resource, |
| 3383 | struct wl_resource *parent_resource) |
Jasper St. Pierre | 63a9c33 | 2014-02-01 18:35:15 -0500 | [diff] [blame] | 3384 | { |
| 3385 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3386 | struct weston_surface *parent; |
| 3387 | |
| 3388 | if (parent_resource) |
| 3389 | parent = wl_resource_get_user_data(parent_resource); |
| 3390 | else |
| 3391 | parent = NULL; |
| 3392 | |
| 3393 | shell_surface_set_parent(shsurf, parent); |
| 3394 | } |
| 3395 | |
| 3396 | static void |
Jasper St. Pierre | 7407345 | 2014-02-01 18:36:41 -0500 | [diff] [blame] | 3397 | xdg_surface_set_margin(struct wl_client *client, |
| 3398 | struct wl_resource *resource, |
| 3399 | int32_t left, |
| 3400 | int32_t right, |
| 3401 | int32_t top, |
| 3402 | int32_t bottom) |
| 3403 | { |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 3404 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3405 | |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 3406 | set_margin(shsurf, left, right, top, bottom); |
Jasper St. Pierre | 7407345 | 2014-02-01 18:36:41 -0500 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3410 | xdg_surface_set_app_id(struct wl_client *client, |
| 3411 | struct wl_resource *resource, |
| 3412 | const char *app_id) |
| 3413 | { |
| 3414 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3415 | |
| 3416 | free(shsurf->class); |
| 3417 | shsurf->class = strdup(app_id); |
| 3418 | } |
| 3419 | |
| 3420 | static void |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3421 | xdg_surface_show_window_menu(struct wl_client *client, |
| 3422 | struct wl_resource *surface_resource, |
| 3423 | struct wl_resource *seat_resource, |
| 3424 | uint32_t serial, |
| 3425 | int32_t x, |
| 3426 | int32_t y) |
| 3427 | { |
| 3428 | /* TODO */ |
| 3429 | } |
| 3430 | |
| 3431 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3432 | xdg_surface_set_title(struct wl_client *client, |
| 3433 | struct wl_resource *resource, const char *title) |
| 3434 | { |
| 3435 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3436 | |
| 3437 | set_title(shsurf, title); |
| 3438 | } |
| 3439 | |
| 3440 | static void |
| 3441 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3442 | struct wl_resource *seat_resource, uint32_t serial) |
| 3443 | { |
| 3444 | common_surface_move(resource, seat_resource, serial); |
| 3445 | } |
| 3446 | |
| 3447 | static void |
| 3448 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3449 | struct wl_resource *seat_resource, uint32_t serial, |
| 3450 | uint32_t edges) |
| 3451 | { |
| 3452 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3453 | } |
| 3454 | |
| 3455 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3456 | xdg_surface_ack_configure(struct wl_client *client, |
| 3457 | struct wl_resource *resource, |
| 3458 | uint32_t serial) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3459 | { |
| 3460 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3461 | |
Jasper St. Pierre | 8c6aa45 | 2014-02-08 18:29:49 -0500 | [diff] [blame] | 3462 | if (shsurf->state_requested) { |
| 3463 | shsurf->next_state = shsurf->requested_state; |
| 3464 | shsurf->state_changed = true; |
| 3465 | shsurf->state_requested = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3466 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3467 | } |
| 3468 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3469 | static void |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3470 | xdg_surface_set_maximized(struct wl_client *client, |
| 3471 | struct wl_resource *resource) |
| 3472 | { |
| 3473 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3474 | |
| 3475 | shsurf->state_requested = true; |
| 3476 | shsurf->requested_state.maximized = true; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3477 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3478 | } |
| 3479 | |
| 3480 | static void |
| 3481 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3482 | struct wl_resource *resource) |
| 3483 | { |
| 3484 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3485 | |
| 3486 | shsurf->state_requested = true; |
| 3487 | shsurf->requested_state.maximized = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3488 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3489 | } |
| 3490 | |
| 3491 | static void |
| 3492 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3493 | struct wl_resource *resource, |
| 3494 | struct wl_resource *output_resource) |
| 3495 | { |
| 3496 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3497 | struct weston_output *output; |
| 3498 | |
| 3499 | shsurf->state_requested = true; |
| 3500 | shsurf->requested_state.fullscreen = true; |
| 3501 | |
| 3502 | if (output_resource) |
| 3503 | output = wl_resource_get_user_data(output_resource); |
| 3504 | else |
| 3505 | output = NULL; |
| 3506 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3507 | shell_surface_set_output(shsurf, output); |
| 3508 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3509 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 3510 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | static void |
| 3514 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3515 | struct wl_resource *resource) |
| 3516 | { |
| 3517 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3518 | |
| 3519 | shsurf->state_requested = true; |
| 3520 | shsurf->requested_state.fullscreen = false; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 3521 | send_configure_for_surface(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | static void |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 3525 | xdg_surface_set_minimized(struct wl_client *client, |
| 3526 | struct wl_resource *resource) |
| 3527 | { |
| 3528 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3529 | |
| 3530 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3531 | return; |
| 3532 | |
| 3533 | /* apply compositor's own minimization logic (hide) */ |
| 3534 | set_minimized(shsurf->surface, 1); |
| 3535 | } |
| 3536 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3537 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3538 | xdg_surface_destroy, |
Jasper St. Pierre | c815d62 | 2014-04-10 18:37:54 -0700 | [diff] [blame] | 3539 | xdg_surface_set_parent, |
Jasper St. Pierre | 7407345 | 2014-02-01 18:36:41 -0500 | [diff] [blame] | 3540 | xdg_surface_set_margin, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3541 | xdg_surface_set_title, |
| 3542 | xdg_surface_set_app_id, |
Jasper St. Pierre | 81ff075 | 2014-03-13 11:04:53 -0400 | [diff] [blame] | 3543 | xdg_surface_show_window_menu, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3544 | xdg_surface_move, |
| 3545 | xdg_surface_resize, |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3546 | xdg_surface_ack_configure, |
| 3547 | xdg_surface_set_maximized, |
| 3548 | xdg_surface_unset_maximized, |
| 3549 | xdg_surface_set_fullscreen, |
| 3550 | xdg_surface_unset_fullscreen, |
| 3551 | xdg_surface_set_minimized, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3552 | }; |
| 3553 | |
| 3554 | static void |
| 3555 | xdg_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 3556 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3557 | { |
| 3558 | struct shell_surface *shsurf = get_shell_surface(surface); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3559 | uint32_t *s; |
| 3560 | struct wl_array states; |
| 3561 | uint32_t serial; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3562 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 3563 | assert(shsurf); |
| 3564 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3565 | if (!shsurf->resource) |
| 3566 | return; |
| 3567 | |
| 3568 | wl_array_init(&states); |
| 3569 | if (shsurf->requested_state.fullscreen) { |
| 3570 | s = wl_array_add(&states, sizeof *s); |
| 3571 | *s = XDG_SURFACE_STATE_FULLSCREEN; |
| 3572 | } else if (shsurf->requested_state.maximized) { |
| 3573 | s = wl_array_add(&states, sizeof *s); |
| 3574 | *s = XDG_SURFACE_STATE_MAXIMIZED; |
| 3575 | } |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 3576 | if (shsurf->resize_edges != 0) { |
| 3577 | s = wl_array_add(&states, sizeof *s); |
| 3578 | *s = XDG_SURFACE_STATE_RESIZING; |
| 3579 | } |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 3580 | if (shsurf->focus_count > 0) { |
| 3581 | s = wl_array_add(&states, sizeof *s); |
| 3582 | *s = XDG_SURFACE_STATE_ACTIVATED; |
| 3583 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 3584 | |
| 3585 | serial = wl_display_next_serial(shsurf->surface->compositor->wl_display); |
| 3586 | xdg_surface_send_configure(shsurf->resource, width, height, &states, serial); |
| 3587 | |
| 3588 | wl_array_release(&states); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | static const struct weston_shell_client xdg_client = { |
| 3592 | xdg_send_configure |
| 3593 | }; |
| 3594 | |
| 3595 | static void |
| 3596 | xdg_use_unstable_version(struct wl_client *client, |
| 3597 | struct wl_resource *resource, |
| 3598 | int32_t version) |
| 3599 | { |
| 3600 | if (version > 1) { |
| 3601 | wl_resource_post_error(resource, |
| 3602 | 1, |
| 3603 | "xdg-shell:: version not implemented yet."); |
| 3604 | return; |
| 3605 | } |
| 3606 | } |
| 3607 | |
| 3608 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3609 | create_xdg_surface(struct shell_client *owner, void *shell, |
| 3610 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3611 | const struct weston_shell_client *client) |
| 3612 | { |
| 3613 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3614 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3615 | shsurf = create_common_surface(owner, shell, surface, client); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3616 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3617 | |
| 3618 | return shsurf; |
| 3619 | } |
| 3620 | |
| 3621 | static void |
| 3622 | xdg_get_xdg_surface(struct wl_client *client, |
| 3623 | struct wl_resource *resource, |
| 3624 | uint32_t id, |
| 3625 | struct wl_resource *surface_resource) |
| 3626 | { |
| 3627 | struct weston_surface *surface = |
| 3628 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3629 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3630 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3631 | struct shell_surface *shsurf; |
| 3632 | |
| 3633 | if (get_shell_surface(surface)) { |
| 3634 | wl_resource_post_error(surface_resource, |
| 3635 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jasper St. Pierre | fe9671e | 2014-03-25 13:31:44 -0400 | [diff] [blame] | 3636 | "xdg_shell::get_xdg_surface already requested"); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3637 | return; |
| 3638 | } |
| 3639 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3640 | shsurf = create_xdg_surface(sc, shell, surface, &xdg_client); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3641 | if (!shsurf) { |
| 3642 | wl_resource_post_error(surface_resource, |
| 3643 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3644 | "surface->configure already set"); |
| 3645 | return; |
| 3646 | } |
| 3647 | |
| 3648 | shsurf->resource = |
| 3649 | wl_resource_create(client, |
| 3650 | &xdg_surface_interface, 1, id); |
| 3651 | wl_resource_set_implementation(shsurf->resource, |
| 3652 | &xdg_surface_implementation, |
| 3653 | shsurf, shell_destroy_shell_surface); |
| 3654 | } |
| 3655 | |
| 3656 | static bool |
| 3657 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3658 | { |
Kristian Høgsberg | 0b7d995 | 2014-02-03 15:50:38 -0800 | [diff] [blame] | 3659 | return shsurf->resource && |
| 3660 | wl_resource_instance_of(shsurf->resource, |
| 3661 | &xdg_surface_interface, |
| 3662 | &xdg_surface_implementation); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3663 | } |
| 3664 | |
| 3665 | /* xdg-popup implementation */ |
| 3666 | |
| 3667 | static void |
| 3668 | xdg_popup_destroy(struct wl_client *client, |
| 3669 | struct wl_resource *resource) |
| 3670 | { |
| 3671 | wl_resource_destroy(resource); |
| 3672 | } |
| 3673 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3674 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3675 | xdg_popup_destroy, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3676 | }; |
| 3677 | |
| 3678 | static void |
| 3679 | xdg_popup_send_configure(struct weston_surface *surface, |
Jasper St. Pierre | ac985be | 2014-04-28 11:19:28 -0400 | [diff] [blame] | 3680 | int32_t width, int32_t height) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3681 | { |
| 3682 | } |
| 3683 | |
| 3684 | static const struct weston_shell_client xdg_popup_client = { |
| 3685 | xdg_popup_send_configure |
| 3686 | }; |
| 3687 | |
| 3688 | static struct shell_surface * |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3689 | create_xdg_popup(struct shell_client *owner, void *shell, |
| 3690 | struct weston_surface *surface, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3691 | const struct weston_shell_client *client, |
| 3692 | struct weston_surface *parent, |
| 3693 | struct shell_seat *seat, |
| 3694 | uint32_t serial, |
| 3695 | int32_t x, int32_t y) |
| 3696 | { |
| 3697 | struct shell_surface *shsurf; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3698 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3699 | shsurf = create_common_surface(owner, shell, surface, client); |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 3700 | shsurf->type = SHELL_SURFACE_POPUP; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3701 | shsurf->popup.shseat = seat; |
| 3702 | shsurf->popup.serial = serial; |
| 3703 | shsurf->popup.x = x; |
| 3704 | shsurf->popup.y = y; |
| 3705 | shell_surface_set_parent(shsurf, parent); |
| 3706 | |
| 3707 | return shsurf; |
| 3708 | } |
| 3709 | |
| 3710 | static void |
| 3711 | xdg_get_xdg_popup(struct wl_client *client, |
| 3712 | struct wl_resource *resource, |
| 3713 | uint32_t id, |
| 3714 | struct wl_resource *surface_resource, |
| 3715 | struct wl_resource *parent_resource, |
| 3716 | struct wl_resource *seat_resource, |
| 3717 | uint32_t serial, |
| 3718 | int32_t x, int32_t y, uint32_t flags) |
| 3719 | { |
| 3720 | struct weston_surface *surface = |
| 3721 | wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3722 | struct shell_client *sc = wl_resource_get_user_data(resource); |
| 3723 | struct desktop_shell *shell = sc->shell; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3724 | struct shell_surface *shsurf; |
| 3725 | struct weston_surface *parent; |
| 3726 | struct shell_seat *seat; |
| 3727 | |
| 3728 | if (get_shell_surface(surface)) { |
| 3729 | wl_resource_post_error(surface_resource, |
| 3730 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jasper St. Pierre | fe9671e | 2014-03-25 13:31:44 -0400 | [diff] [blame] | 3731 | "xdg_shell::get_xdg_popup already requested"); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3732 | return; |
| 3733 | } |
| 3734 | |
| 3735 | if (!parent_resource) { |
| 3736 | wl_resource_post_error(surface_resource, |
| 3737 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3738 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
| 3739 | } |
| 3740 | |
| 3741 | parent = wl_resource_get_user_data(parent_resource); |
| 3742 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 3743 | |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 3744 | shsurf = create_xdg_popup(sc, shell, surface, &xdg_popup_client, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3745 | parent, seat, serial, x, y); |
| 3746 | if (!shsurf) { |
| 3747 | wl_resource_post_error(surface_resource, |
| 3748 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3749 | "surface->configure already set"); |
| 3750 | return; |
| 3751 | } |
| 3752 | |
| 3753 | shsurf->resource = |
| 3754 | wl_resource_create(client, |
| 3755 | &xdg_popup_interface, 1, id); |
| 3756 | wl_resource_set_implementation(shsurf->resource, |
| 3757 | &xdg_popup_implementation, |
| 3758 | shsurf, shell_destroy_shell_surface); |
| 3759 | } |
| 3760 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3761 | static void |
| 3762 | xdg_pong(struct wl_client *client, |
| 3763 | struct wl_resource *resource, uint32_t serial) |
| 3764 | { |
| 3765 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3766 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 3767 | shell_client_pong(sc, serial); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3768 | } |
| 3769 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3770 | static bool |
| 3771 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 3772 | { |
| 3773 | return wl_resource_instance_of(shsurf->resource, |
| 3774 | &xdg_popup_interface, |
| 3775 | &xdg_popup_implementation); |
| 3776 | } |
| 3777 | |
| 3778 | static const struct xdg_shell_interface xdg_implementation = { |
| 3779 | xdg_use_unstable_version, |
| 3780 | xdg_get_xdg_surface, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3781 | xdg_get_xdg_popup, |
| 3782 | xdg_pong |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3783 | }; |
| 3784 | |
| 3785 | static int |
| 3786 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 3787 | void *_target, uint32_t opcode, |
| 3788 | const struct wl_message *message, |
| 3789 | union wl_argument *args) |
| 3790 | { |
| 3791 | struct wl_resource *resource = _target; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3792 | struct shell_client *sc = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3793 | |
| 3794 | if (opcode != 0) { |
| 3795 | wl_resource_post_error(resource, |
| 3796 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3797 | "must call use_unstable_version first"); |
| 3798 | return 0; |
| 3799 | } |
| 3800 | |
Kristian Høgsberg | c7680b0 | 2014-02-19 10:14:46 -0800 | [diff] [blame] | 3801 | #define XDG_SERVER_VERSION 3 |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3802 | |
Kristian Høgsberg | 8d344a0 | 2013-12-08 22:27:11 -0800 | [diff] [blame] | 3803 | static_assert(XDG_SERVER_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 3804 | "shell implementation doesn't match protocol version"); |
| 3805 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3806 | if (args[0].i != XDG_SERVER_VERSION) { |
| 3807 | wl_resource_post_error(resource, |
| 3808 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3809 | "incompatible version, server is %d " |
| 3810 | "client wants %d", |
| 3811 | XDG_SERVER_VERSION, args[0].i); |
| 3812 | return 0; |
| 3813 | } |
| 3814 | |
| 3815 | wl_resource_set_implementation(resource, &xdg_implementation, |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 3816 | sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3817 | |
| 3818 | return 1; |
| 3819 | } |
| 3820 | |
| 3821 | /* end of xdg-shell implementation */ |
| 3822 | /***********************************/ |
| 3823 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3824 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3825 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3826 | |
| 3827 | static int |
| 3828 | screensaver_timeout(void *data) |
| 3829 | { |
| 3830 | struct desktop_shell *shell = data; |
| 3831 | |
| 3832 | shell_fade(shell, FADE_OUT); |
| 3833 | |
| 3834 | return 1; |
| 3835 | } |
| 3836 | |
| 3837 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3838 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3839 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3840 | struct desktop_shell *shell = |
| 3841 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3842 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3843 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3844 | |
| 3845 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3846 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3850 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3851 | { |
| 3852 | if (shell->screensaver.binding) |
| 3853 | return; |
| 3854 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3855 | if (!shell->screensaver.path) { |
| 3856 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3857 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3858 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3859 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3860 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3861 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3862 | return; |
| 3863 | } |
| 3864 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3865 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3866 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3867 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3868 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3872 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3873 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3874 | if (shell->screensaver.process.pid == 0) |
| 3875 | return; |
| 3876 | |
Ander Conselvan de Oliveira | 4e20e9b | 2014-04-10 14:49:35 +0300 | [diff] [blame] | 3877 | /* Disarm the screensaver timer, otherwise it may fire when the |
| 3878 | * compositor is not in the idle state. In that case, the screen will |
| 3879 | * be locked, but the wake_signal won't fire on user input, making the |
| 3880 | * system unresponsive. */ |
| 3881 | wl_event_source_timer_update(shell->screensaver.timer, 0); |
| 3882 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3883 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3884 | } |
| 3885 | |
| 3886 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3887 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3888 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3889 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3890 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3891 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3892 | if (v->output == ev->output && v != ev) { |
| 3893 | weston_view_unmap(v); |
| 3894 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3895 | } |
| 3896 | } |
| 3897 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3898 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3899 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3900 | if (wl_list_empty(&ev->layer_link)) { |
| 3901 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3902 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3903 | } |
| 3904 | } |
| 3905 | |
| 3906 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3907 | 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] | 3908 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3909 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3910 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3911 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3912 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3913 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3914 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3918 | desktop_shell_set_background(struct wl_client *client, |
| 3919 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3920 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3921 | struct wl_resource *surface_resource) |
| 3922 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3923 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3924 | struct weston_surface *surface = |
| 3925 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3926 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3927 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3928 | if (surface->configure) { |
| 3929 | wl_resource_post_error(surface_resource, |
| 3930 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3931 | "surface role already assigned"); |
| 3932 | return; |
| 3933 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3934 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3935 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3936 | weston_view_destroy(view); |
| 3937 | view = weston_view_create(surface); |
| 3938 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3939 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3940 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3941 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3942 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3943 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3944 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3945 | surface->output->width, |
| 3946 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3947 | } |
| 3948 | |
| 3949 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3950 | 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] | 3951 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3952 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3953 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3954 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3955 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3956 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3957 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3958 | } |
| 3959 | |
| 3960 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3961 | desktop_shell_set_panel(struct wl_client *client, |
| 3962 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3963 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3964 | struct wl_resource *surface_resource) |
| 3965 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3966 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3967 | struct weston_surface *surface = |
| 3968 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3969 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3970 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3971 | if (surface->configure) { |
| 3972 | wl_resource_post_error(surface_resource, |
| 3973 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3974 | "surface role already assigned"); |
| 3975 | return; |
| 3976 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3977 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3978 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3979 | weston_view_destroy(view); |
| 3980 | view = weston_view_create(surface); |
| 3981 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3982 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3983 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3984 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3985 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3986 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3987 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3988 | surface->output->width, |
| 3989 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3990 | } |
| 3991 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3992 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3993 | 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] | 3994 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3995 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3996 | struct weston_view *view; |
| 3997 | |
| 3998 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3999 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4000 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4001 | return; |
| 4002 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4003 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4004 | |
| 4005 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4006 | wl_list_insert(&shell->lock_layer.view_list, |
| 4007 | &view->layer_link); |
| 4008 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4009 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4010 | } |
| 4011 | } |
| 4012 | |
| 4013 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4014 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4015 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4016 | struct desktop_shell *shell = |
| 4017 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4018 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4019 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4020 | shell->lock_surface = NULL; |
| 4021 | } |
| 4022 | |
| 4023 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4024 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 4025 | struct wl_resource *resource, |
| 4026 | struct wl_resource *surface_resource) |
| 4027 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4028 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4029 | struct weston_surface *surface = |
| 4030 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4031 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4032 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4033 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4034 | if (!shell->locked) |
| 4035 | return; |
| 4036 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4037 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4038 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4039 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4040 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4041 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4042 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 4043 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 4044 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4045 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4046 | } |
| 4047 | |
| 4048 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4049 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4050 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4051 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4052 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4053 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4054 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4055 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4056 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4057 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4058 | &shell->input_panel_layer.link); |
| 4059 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4060 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4061 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4062 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4063 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4064 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 4065 | wl_list_insert(&shell->fullscreen_layer.link, |
| 4066 | &shell->panel_layer.link); |
| 4067 | wl_list_insert(&shell->panel_layer.link, |
| 4068 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4069 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4070 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 4071 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4072 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4073 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 4074 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | static void |
| 4078 | desktop_shell_unlock(struct wl_client *client, |
| 4079 | struct wl_resource *resource) |
| 4080 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4081 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4082 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4083 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4084 | |
| 4085 | if (shell->locked) |
| 4086 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4087 | } |
| 4088 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4089 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4090 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4091 | struct wl_resource *resource, |
| 4092 | struct wl_resource *surface_resource) |
| 4093 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4094 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4095 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4096 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 4097 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4098 | } |
| 4099 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4100 | static void |
| 4101 | desktop_shell_desktop_ready(struct wl_client *client, |
| 4102 | struct wl_resource *resource) |
| 4103 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4104 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4105 | |
| 4106 | shell_fade_startup(shell); |
| 4107 | } |
| 4108 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4109 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 4110 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4111 | desktop_shell_set_panel, |
| 4112 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4113 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4114 | desktop_shell_set_grab_surface, |
| 4115 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4116 | }; |
| 4117 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4118 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4119 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4120 | { |
| 4121 | struct shell_surface *shsurf; |
| 4122 | |
| 4123 | shsurf = get_shell_surface(surface); |
| 4124 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 4125 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4126 | return shsurf->type; |
| 4127 | } |
| 4128 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4129 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4130 | 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] | 4131 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4132 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4133 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4134 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4135 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4136 | if (seat->pointer->focus == NULL) |
| 4137 | return; |
| 4138 | |
| 4139 | focus = seat->pointer->focus->surface; |
| 4140 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4141 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4142 | if (surface == NULL) |
| 4143 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4144 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4145 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4146 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4147 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4148 | return; |
| 4149 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 4150 | surface_move(shsurf, (struct weston_seat *) seat, 0); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4151 | } |
| 4152 | |
| 4153 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4154 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4155 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4156 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4157 | struct weston_surface *surface; |
| 4158 | struct shell_surface *shsurf; |
| 4159 | |
| 4160 | surface = weston_surface_get_main_surface(focus); |
| 4161 | if (surface == NULL) |
| 4162 | return; |
| 4163 | |
| 4164 | shsurf = get_shell_surface(surface); |
| 4165 | if (shsurf == NULL) |
| 4166 | return; |
| 4167 | |
| 4168 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4169 | return; |
| 4170 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4171 | shsurf->state_requested = true; |
| 4172 | shsurf->requested_state.maximized = !shsurf->state.maximized; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4173 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | static void |
| 4177 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 4178 | { |
Emilio Pozuelo Monfort | 38b58eb | 2014-01-29 11:11:12 +0100 | [diff] [blame] | 4179 | struct weston_surface *focus = seat->keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4180 | struct weston_surface *surface; |
| 4181 | struct shell_surface *shsurf; |
| 4182 | |
| 4183 | surface = weston_surface_get_main_surface(focus); |
| 4184 | if (surface == NULL) |
| 4185 | return; |
| 4186 | |
| 4187 | shsurf = get_shell_surface(surface); |
| 4188 | if (shsurf == NULL) |
| 4189 | return; |
| 4190 | |
| 4191 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4192 | return; |
| 4193 | |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 4194 | shsurf->state_requested = true; |
| 4195 | shsurf->requested_state.fullscreen = !shsurf->state.fullscreen; |
Boyan Ding | 32abdbb | 2014-06-26 10:19:32 +0800 | [diff] [blame^] | 4196 | shsurf->fullscreen_output = shsurf->output; |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 4197 | send_configure_for_surface(shsurf); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 4198 | } |
| 4199 | |
| 4200 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4201 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4202 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4203 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4204 | struct weston_surface *surface; |
| 4205 | struct shell_surface *shsurf; |
| 4206 | |
| 4207 | surface = weston_surface_get_main_surface(focus); |
| 4208 | if (surface == NULL) |
| 4209 | return; |
| 4210 | |
| 4211 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4212 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4213 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4214 | return; |
| 4215 | |
| 4216 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 4217 | } |
| 4218 | |
| 4219 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4220 | 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] | 4221 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4222 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4223 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4224 | uint32_t edges = 0; |
| 4225 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4226 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4227 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4228 | if (seat->pointer->focus == NULL) |
| 4229 | return; |
| 4230 | |
| 4231 | focus = seat->pointer->focus->surface; |
| 4232 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4233 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4234 | if (surface == NULL) |
| 4235 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4236 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4237 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4238 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4239 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4240 | return; |
| 4241 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4242 | weston_view_from_global(shsurf->view, |
| 4243 | wl_fixed_to_int(seat->pointer->grab_x), |
| 4244 | wl_fixed_to_int(seat->pointer->grab_y), |
| 4245 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4246 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4247 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4248 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4249 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4250 | edges |= 0; |
| 4251 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4252 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4253 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4254 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4255 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4256 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4257 | edges |= 0; |
| 4258 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4259 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4260 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 4261 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4265 | 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] | 4266 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4267 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4268 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4269 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4270 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4271 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4272 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4273 | /* XXX: broken for windows containing sub-surfaces */ |
| 4274 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4275 | if (surface == NULL) |
| 4276 | return; |
| 4277 | |
| 4278 | shsurf = get_shell_surface(surface); |
| 4279 | if (!shsurf) |
| 4280 | return; |
| 4281 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4282 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4283 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4284 | if (shsurf->view->alpha > 1.0) |
| 4285 | shsurf->view->alpha = 1.0; |
| 4286 | if (shsurf->view->alpha < step) |
| 4287 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4288 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4289 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4290 | weston_surface_damage(surface); |
| 4291 | } |
| 4292 | |
| 4293 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4294 | 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] | 4295 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4296 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4297 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 4298 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4299 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4300 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4301 | |
| 4302 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4303 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4304 | wl_fixed_to_double(seat->pointer->x), |
| 4305 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4306 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4307 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4308 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4309 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4310 | increment = -output->zoom.increment; |
| 4311 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4312 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4313 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4314 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4315 | else |
| 4316 | increment = 0; |
| 4317 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4318 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4319 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4320 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4321 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4322 | else if (output->zoom.level > output->zoom.max_level) |
| 4323 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 4324 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 4325 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4326 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4327 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4328 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4329 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4330 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4331 | } |
| 4332 | } |
| 4333 | } |
| 4334 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4335 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4336 | 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] | 4337 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4338 | { |
| 4339 | do_zoom(seat, time, 0, axis, value); |
| 4340 | } |
| 4341 | |
| 4342 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4343 | 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] | 4344 | void *data) |
| 4345 | { |
| 4346 | do_zoom(seat, time, key, 0, 0); |
| 4347 | } |
| 4348 | |
| 4349 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4350 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4351 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4352 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4353 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4354 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4355 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4356 | } |
| 4357 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4358 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4359 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4360 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4361 | { |
| 4362 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4363 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4364 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4365 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4366 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4367 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4368 | weston_pointer_move(pointer, x, y); |
| 4369 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4370 | if (!shsurf) |
| 4371 | return; |
| 4372 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4373 | cx = 0.5f * shsurf->surface->width; |
| 4374 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4375 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4376 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4377 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4378 | r = sqrtf(dx * dx + dy * dy); |
| 4379 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4380 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4381 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4382 | |
| 4383 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4384 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4385 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4386 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4387 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4388 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4389 | |
| 4390 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4391 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4392 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4393 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4394 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4395 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4396 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4397 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4398 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4399 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4400 | wl_list_init(&shsurf->rotation.transform.link); |
| 4401 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4402 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4403 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4404 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4405 | /* We need to adjust the position of the surface |
| 4406 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4407 | cposx = shsurf->view->geometry.x + cx; |
| 4408 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4409 | dposx = rotate->center.x - cposx; |
| 4410 | dposy = rotate->center.y - cposy; |
| 4411 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4412 | weston_view_set_position(shsurf->view, |
| 4413 | shsurf->view->geometry.x + dposx, |
| 4414 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4415 | } |
| 4416 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4417 | /* Repaint implies weston_surface_update_transform(), which |
| 4418 | * lazily applies the damage due to rotation update. |
| 4419 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4420 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4424 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4425 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4426 | { |
| 4427 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4428 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4429 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4430 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4431 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4432 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4433 | if (pointer->button_count == 0 && |
| 4434 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4435 | if (shsurf) |
| 4436 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4437 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4438 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4439 | free(rotate); |
| 4440 | } |
| 4441 | } |
| 4442 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4443 | static void |
| 4444 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4445 | { |
| 4446 | struct rotate_grab *rotate = |
| 4447 | container_of(grab, struct rotate_grab, base.grab); |
| 4448 | |
| 4449 | shell_grab_end(&rotate->base); |
| 4450 | free(rotate); |
| 4451 | } |
| 4452 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4453 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4454 | noop_grab_focus, |
| 4455 | rotate_grab_motion, |
| 4456 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4457 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4458 | }; |
| 4459 | |
| 4460 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4461 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4462 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4463 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4464 | float dx, dy; |
| 4465 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4466 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4467 | rotate = malloc(sizeof *rotate); |
| 4468 | if (!rotate) |
| 4469 | return; |
| 4470 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4471 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4472 | surface->surface->width * 0.5f, |
| 4473 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4474 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4475 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4476 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4477 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4478 | r = sqrtf(dx * dx + dy * dy); |
| 4479 | if (r > 20.0f) { |
| 4480 | struct weston_matrix inverse; |
| 4481 | |
| 4482 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4483 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4484 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4485 | |
| 4486 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4487 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4488 | } else { |
| 4489 | weston_matrix_init(&surface->rotation.rotation); |
| 4490 | weston_matrix_init(&rotate->rotation); |
| 4491 | } |
| 4492 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4493 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4494 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4498 | 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] | 4499 | void *data) |
| 4500 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4501 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4502 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4503 | struct shell_surface *surface; |
| 4504 | |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 4505 | if (seat->pointer->focus == NULL) |
| 4506 | return; |
| 4507 | |
| 4508 | focus = seat->pointer->focus->surface; |
| 4509 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4510 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4511 | if (base_surface == NULL) |
| 4512 | return; |
| 4513 | |
| 4514 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4515 | if (surface == NULL || surface->state.fullscreen || |
| 4516 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4517 | return; |
| 4518 | |
| 4519 | surface_rotate(surface, seat); |
| 4520 | } |
| 4521 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4522 | /* Move all fullscreen layers down to the current workspace and hide their |
| 4523 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 4524 | * and this is reversed when such a surface is re-configured, see |
| 4525 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 4526 | * |
| 4527 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4528 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4529 | void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4530 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4531 | { |
| 4532 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4533 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4534 | |
| 4535 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4536 | wl_list_for_each_reverse_safe(view, prev, |
| 4537 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4538 | layer_link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4539 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 4540 | |
| 4541 | if (!shsurf) |
| 4542 | continue; |
| 4543 | |
| 4544 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 4545 | * in the fullscreen layer. */ |
| 4546 | if (shsurf->state.fullscreen) { |
| 4547 | /* Hide the black view */ |
| 4548 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 4549 | wl_list_init(&shsurf->fullscreen.black_view->layer_link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 4550 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 4551 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4552 | } |
| 4553 | |
| 4554 | /* Lower the view to the workspace layer */ |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4555 | wl_list_remove(&view->layer_link); |
| 4556 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4557 | weston_view_damage_below(view); |
| 4558 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4559 | |
| 4560 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4561 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4562 | } |
| 4563 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 4564 | void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4565 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4566 | struct weston_seat *seat, bool configure) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4567 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4568 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4569 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4570 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4571 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4572 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4573 | |
Kristian Høgsberg | 6110d07 | 2014-04-29 15:15:45 -0700 | [diff] [blame] | 4574 | lower_fullscreen_layer(shell); |
| 4575 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4576 | main_surface = weston_surface_get_main_surface(es); |
| 4577 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4578 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4579 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4580 | state = ensure_focus_state(shell, seat); |
| 4581 | if (state == NULL) |
| 4582 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4583 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4584 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 4585 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4586 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4587 | shsurf = get_shell_surface(main_surface); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 4588 | assert(shsurf); |
| 4589 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4590 | if (shsurf->state.fullscreen && configure) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4591 | shell_configure_fullscreen(shsurf); |
| 4592 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4593 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4594 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 4595 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4596 | * order as appropriate. */ |
| 4597 | shell_surface_update_layer(shsurf); |
| 4598 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4599 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4600 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4601 | 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] | 4602 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4603 | } |
| 4604 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4605 | /* no-op func for checking black surface */ |
| 4606 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4607 | 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] | 4608 | { |
| 4609 | } |
| 4610 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4611 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4612 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4613 | { |
| 4614 | if (es->configure == black_surface_configure) { |
| 4615 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4616 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4617 | return true; |
| 4618 | } |
| 4619 | return false; |
| 4620 | } |
| 4621 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4622 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4623 | activate_binding(struct weston_seat *seat, |
| 4624 | struct desktop_shell *shell, |
| 4625 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4626 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4627 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4628 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4629 | if (!focus) |
| 4630 | return; |
| 4631 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4632 | if (is_black_surface(focus, &main_surface)) |
| 4633 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4634 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4635 | main_surface = weston_surface_get_main_surface(focus); |
| 4636 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4637 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4638 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 4639 | activate(shell, focus, seat, true); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4640 | } |
| 4641 | |
| 4642 | static void |
| 4643 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4644 | void *data) |
| 4645 | { |
| 4646 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4647 | return; |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 4648 | if (seat->pointer->focus == NULL) |
| 4649 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4650 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4651 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | static void |
| 4655 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4656 | { |
| 4657 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4658 | return; |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 4659 | if (seat->touch->focus == NULL) |
| 4660 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4661 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4662 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4663 | } |
| 4664 | |
| 4665 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 4666 | unfocus_all_seats(struct desktop_shell *shell) |
| 4667 | { |
| 4668 | struct weston_seat *seat, *next; |
| 4669 | |
| 4670 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
| 4671 | if (seat->keyboard == NULL) |
| 4672 | continue; |
| 4673 | |
| 4674 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 4675 | } |
| 4676 | } |
| 4677 | |
| 4678 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4679 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4680 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4681 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4682 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4683 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4684 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4685 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4686 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4687 | |
| 4688 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4689 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4690 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4691 | * toplevel layers. This way nothing else can show or receive |
| 4692 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4693 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4694 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4695 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4696 | if (shell->showing_input_panels) |
| 4697 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4698 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4699 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4700 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4701 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4702 | launch_screensaver(shell); |
| 4703 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 4704 | /* Remove the keyboard focus on all seats. This will be |
| 4705 | * restored to the workspace's saved state via |
| 4706 | * restore_focus_state when the compositor is unlocked */ |
| 4707 | unfocus_all_seats(shell); |
| 4708 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4709 | /* TODO: disable bindings that should not work while locked. */ |
| 4710 | |
| 4711 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4712 | } |
| 4713 | |
| 4714 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4715 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4716 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4717 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4718 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4719 | return; |
| 4720 | } |
| 4721 | |
| 4722 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4723 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4724 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4725 | return; |
| 4726 | } |
| 4727 | |
| 4728 | if (shell->prepare_event_sent) |
| 4729 | return; |
| 4730 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4731 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4732 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4736 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4737 | { |
| 4738 | struct desktop_shell *shell = data; |
| 4739 | |
| 4740 | shell->fade.animation = NULL; |
| 4741 | |
| 4742 | switch (shell->fade.type) { |
| 4743 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4744 | weston_surface_destroy(shell->fade.view->surface); |
| 4745 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4746 | break; |
| 4747 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4748 | lock(shell); |
| 4749 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4750 | default: |
| 4751 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4752 | } |
| 4753 | } |
| 4754 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4755 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4756 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4757 | { |
| 4758 | struct weston_compositor *compositor = shell->compositor; |
| 4759 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4760 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4761 | |
| 4762 | surface = weston_surface_create(compositor); |
| 4763 | if (!surface) |
| 4764 | return NULL; |
| 4765 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4766 | view = weston_view_create(surface); |
| 4767 | if (!view) { |
| 4768 | weston_surface_destroy(surface); |
| 4769 | return NULL; |
| 4770 | } |
| 4771 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 4772 | weston_surface_set_size(surface, 8192, 8192); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4773 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4774 | 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] | 4775 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4776 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4777 | pixman_region32_init(&surface->input); |
| 4778 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4779 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4780 | } |
| 4781 | |
| 4782 | static void |
| 4783 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4784 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4785 | float tint; |
| 4786 | |
| 4787 | switch (type) { |
| 4788 | case FADE_IN: |
| 4789 | tint = 0.0; |
| 4790 | break; |
| 4791 | case FADE_OUT: |
| 4792 | tint = 1.0; |
| 4793 | break; |
| 4794 | default: |
| 4795 | weston_log("shell: invalid fade type\n"); |
| 4796 | return; |
| 4797 | } |
| 4798 | |
| 4799 | shell->fade.type = type; |
| 4800 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4801 | if (shell->fade.view == NULL) { |
| 4802 | shell->fade.view = shell_fade_create_surface(shell); |
| 4803 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4804 | return; |
| 4805 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4806 | shell->fade.view->alpha = 1.0 - tint; |
| 4807 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4808 | } |
| 4809 | |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4810 | if (shell->fade.view->output == NULL) { |
| 4811 | /* If the black view gets a NULL output, we lost the |
| 4812 | * last output and we'll just cancel the fade. This |
| 4813 | * happens when you close the last window under the |
| 4814 | * X11 or Wayland backends. */ |
| 4815 | shell->locked = false; |
| 4816 | weston_surface_destroy(shell->fade.view->surface); |
| 4817 | shell->fade.view = NULL; |
| 4818 | } else if (shell->fade.animation) { |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4819 | weston_fade_update(shell->fade.animation, tint); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4820 | } else { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4821 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4822 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4823 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4824 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4825 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4826 | } |
| 4827 | |
| 4828 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4829 | do_shell_fade_startup(void *data) |
| 4830 | { |
| 4831 | struct desktop_shell *shell = data; |
| 4832 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4833 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4834 | shell_fade(shell, FADE_IN); |
| 4835 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4836 | weston_surface_destroy(shell->fade.view->surface); |
| 4837 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4838 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4839 | } |
| 4840 | |
| 4841 | static void |
| 4842 | shell_fade_startup(struct desktop_shell *shell) |
| 4843 | { |
| 4844 | struct wl_event_loop *loop; |
| 4845 | |
| 4846 | if (!shell->fade.startup_timer) |
| 4847 | return; |
| 4848 | |
| 4849 | wl_event_source_remove(shell->fade.startup_timer); |
| 4850 | shell->fade.startup_timer = NULL; |
| 4851 | |
| 4852 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4853 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4854 | } |
| 4855 | |
| 4856 | static int |
| 4857 | fade_startup_timeout(void *data) |
| 4858 | { |
| 4859 | struct desktop_shell *shell = data; |
| 4860 | |
| 4861 | shell_fade_startup(shell); |
| 4862 | return 0; |
| 4863 | } |
| 4864 | |
| 4865 | static void |
| 4866 | shell_fade_init(struct desktop_shell *shell) |
| 4867 | { |
| 4868 | /* Make compositor output all black, and wait for the desktop-shell |
| 4869 | * client to signal it is ready, then fade in. The timer triggers a |
| 4870 | * fade-in, in case the desktop-shell client takes too long. |
| 4871 | */ |
| 4872 | |
| 4873 | struct wl_event_loop *loop; |
| 4874 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4875 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4876 | weston_log("%s: warning: fade surface already exists\n", |
| 4877 | __func__); |
| 4878 | return; |
| 4879 | } |
| 4880 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4881 | shell->fade.view = shell_fade_create_surface(shell); |
| 4882 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4883 | return; |
| 4884 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4885 | weston_view_update_transform(shell->fade.view); |
| 4886 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4887 | |
| 4888 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4889 | shell->fade.startup_timer = |
| 4890 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4891 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4892 | } |
| 4893 | |
| 4894 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4895 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4896 | { |
| 4897 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4898 | container_of(listener, struct desktop_shell, idle_listener); |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 4899 | struct weston_seat *seat; |
| 4900 | |
| 4901 | wl_list_for_each(seat, &shell->compositor->seat_list, link) |
| 4902 | if (seat->pointer) |
| 4903 | popup_grab_end(seat->pointer); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4904 | |
| 4905 | shell_fade(shell, FADE_OUT); |
| 4906 | /* lock() is called from shell_fade_done() */ |
| 4907 | } |
| 4908 | |
| 4909 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4910 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4911 | { |
| 4912 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4913 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4914 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4915 | unlock(shell); |
| 4916 | } |
| 4917 | |
| 4918 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4919 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4920 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4921 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4922 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4923 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4924 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4925 | |
| 4926 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4927 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4928 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4929 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4933 | weston_view_set_initial_position(struct weston_view *view, |
| 4934 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4935 | { |
| 4936 | struct weston_compositor *compositor = shell->compositor; |
| 4937 | int ix = 0, iy = 0; |
| 4938 | int range_x, range_y; |
| 4939 | int dx, dy, x, y, panel_height; |
| 4940 | struct weston_output *output, *target_output = NULL; |
| 4941 | struct weston_seat *seat; |
| 4942 | |
| 4943 | /* As a heuristic place the new window on the same output as the |
| 4944 | * pointer. Falling back to the output containing 0, 0. |
| 4945 | * |
| 4946 | * TODO: Do something clever for touch too? |
| 4947 | */ |
| 4948 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4949 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4950 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4951 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4952 | break; |
| 4953 | } |
| 4954 | } |
| 4955 | |
| 4956 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4957 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4958 | target_output = output; |
| 4959 | break; |
| 4960 | } |
| 4961 | } |
| 4962 | |
| 4963 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4964 | weston_view_set_position(view, 10 + random() % 400, |
| 4965 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4966 | return; |
| 4967 | } |
| 4968 | |
| 4969 | /* Valid range within output where the surface will still be onscreen. |
| 4970 | * If this is negative it means that the surface is bigger than |
| 4971 | * output. |
| 4972 | */ |
| 4973 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4974 | range_x = target_output->width - view->surface->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4975 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4976 | view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4977 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4978 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4979 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4980 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4981 | dx = 0; |
| 4982 | |
| 4983 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4984 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4985 | else |
| 4986 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4987 | |
| 4988 | x = target_output->x + dx; |
| 4989 | y = target_output->y + dy; |
| 4990 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4991 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4992 | } |
| 4993 | |
| 4994 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4995 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4996 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4997 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4998 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4999 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5000 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5001 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5002 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5003 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5004 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5005 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5006 | if (shsurf->state.fullscreen) { |
| 5007 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5008 | shell_map_fullscreen(shsurf); |
| 5009 | } else if (shsurf->state.maximized) { |
| 5010 | /* use surface configure to set the geometry */ |
| 5011 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 5012 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5013 | &surf_x, &surf_y, NULL, NULL); |
| 5014 | weston_view_set_position(shsurf->view, |
| 5015 | shsurf->output->x - surf_x, |
| 5016 | shsurf->output->y + |
| 5017 | panel_height - surf_y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5018 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5019 | weston_view_set_initial_position(shsurf->view, shell); |
| 5020 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5021 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5022 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 5023 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5024 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5025 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5026 | weston_view_set_position(shsurf->view, |
| 5027 | shsurf->view->geometry.x + sx, |
| 5028 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5029 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5030 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5031 | default: |
| 5032 | ; |
| 5033 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5034 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5035 | /* Surface stacking order, see also activate(). */ |
| 5036 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5037 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5038 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5039 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5040 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5041 | shsurf->surface->output = shsurf->output; |
| 5042 | shsurf->view->output = shsurf->output; |
| 5043 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5044 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5045 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5046 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5047 | /* XXX: xwayland's using the same fields for transient type */ |
| 5048 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5049 | if (shsurf->transient.flags == |
| 5050 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5051 | break; |
| 5052 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5053 | if (shsurf->state.relative && |
| 5054 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5055 | break; |
Rafael Antognolli | ba5d2d7 | 2013-12-04 17:49:55 -0200 | [diff] [blame] | 5056 | if (shell->locked) |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5057 | break; |
| 5058 | wl_list_for_each(seat, &compositor->seat_list, link) |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5059 | activate(shell, shsurf->surface, seat, true); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5060 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5061 | case SHELL_SURFACE_POPUP: |
| 5062 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5063 | default: |
| 5064 | break; |
| 5065 | } |
| 5066 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5067 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5068 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5069 | { |
| 5070 | switch (shell->win_animation_type) { |
| 5071 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5072 | 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] | 5073 | break; |
| 5074 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5075 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5076 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5077 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5078 | default: |
| 5079 | break; |
| 5080 | } |
| 5081 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5082 | } |
| 5083 | |
| 5084 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5085 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5086 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5087 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5088 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5089 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5090 | int32_t mx, my, surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5091 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5092 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5093 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5094 | assert(shsurf); |
| 5095 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5096 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5097 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5098 | else if (shsurf->state.maximized) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5099 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5100 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 5101 | NULL, NULL); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5102 | mx = shsurf->output->x - surf_x; |
| 5103 | my = shsurf->output->y + |
| 5104 | get_output_panel_height(shell,shsurf->output) - surf_y; |
| 5105 | weston_view_set_position(shsurf->view, mx, my); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5106 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5107 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5108 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5109 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5110 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5111 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5112 | wl_list_for_each(view, &surface->views, surface_link) |
| 5113 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5114 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5115 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5116 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5117 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5118 | } |
| 5119 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5120 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5121 | 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] | 5122 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5123 | struct shell_surface *shsurf = get_shell_surface(es); |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5124 | struct desktop_shell *shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5125 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5126 | |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 5127 | assert(shsurf); |
| 5128 | |
| 5129 | shell = shsurf->shell; |
| 5130 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5131 | if (!weston_surface_is_mapped(es) && |
| 5132 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5133 | remove_popup_grab(shsurf); |
| 5134 | } |
| 5135 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5136 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5137 | return; |
| 5138 | |
Jasper St. Pierre | 851799e | 2014-05-02 10:14:07 -0400 | [diff] [blame] | 5139 | if (shsurf->has_next_margin) { |
| 5140 | shsurf->margin = shsurf->next_margin; |
| 5141 | shsurf->has_next_margin = false; |
| 5142 | } |
| 5143 | |
Kristian Høgsberg | c8f8dd8 | 2013-12-05 23:20:33 -0800 | [diff] [blame] | 5144 | if (shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5145 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5146 | type_changed = 1; |
| 5147 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5148 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5149 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5150 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5151 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5152 | shsurf->last_width != es->width || |
| 5153 | shsurf->last_height != es->height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5154 | float from_x, from_y; |
| 5155 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5156 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 5157 | if (shsurf->resize_edges) { |
| 5158 | sx = 0; |
| 5159 | sy = 0; |
| 5160 | } |
| 5161 | |
| 5162 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 5163 | sx = shsurf->last_width - es->width; |
| 5164 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 5165 | sy = shsurf->last_height - es->height; |
| 5166 | |
| 5167 | shsurf->last_width = es->width; |
| 5168 | shsurf->last_height = es->height; |
| 5169 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5170 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5171 | 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] | 5172 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5173 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5174 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5175 | } |
| 5176 | } |
| 5177 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5178 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5179 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5180 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5181 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5182 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5183 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5184 | struct desktop_shell *shell = |
| 5185 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5186 | |
| 5187 | shell->child.process.pid = 0; |
| 5188 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5189 | |
| 5190 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5191 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5192 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5193 | shell->child.deathstamp = time; |
| 5194 | shell->child.deathcount = 0; |
| 5195 | } |
| 5196 | |
| 5197 | shell->child.deathcount++; |
| 5198 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5199 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5200 | return; |
| 5201 | } |
| 5202 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5203 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5204 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5205 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5206 | } |
| 5207 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5208 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5209 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5210 | { |
| 5211 | struct desktop_shell *shell; |
| 5212 | |
| 5213 | shell = container_of(listener, struct desktop_shell, |
| 5214 | child.client_destroy_listener); |
| 5215 | |
| 5216 | shell->child.client = NULL; |
| 5217 | } |
| 5218 | |
| 5219 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5220 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5221 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5222 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5223 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5224 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5225 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5226 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5227 | desktop_shell_sigchld); |
| 5228 | |
| 5229 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5230 | weston_log("not able to start %s\n", shell->client); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 5231 | |
| 5232 | shell->child.client_destroy_listener.notify = |
| 5233 | desktop_shell_client_destroy; |
| 5234 | wl_client_add_destroy_listener(shell->child.client, |
| 5235 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5236 | } |
| 5237 | |
| 5238 | static void |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5239 | handle_shell_client_destroy(struct wl_listener *listener, void *data) |
| 5240 | { |
| 5241 | struct shell_client *sc = |
| 5242 | container_of(listener, struct shell_client, destroy_listener); |
| 5243 | |
| 5244 | if (sc->ping_timer) |
| 5245 | wl_event_source_remove(sc->ping_timer); |
| 5246 | free(sc); |
| 5247 | } |
| 5248 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5249 | static struct shell_client * |
| 5250 | shell_client_create(struct wl_client *client, struct desktop_shell *shell, |
| 5251 | const struct wl_interface *interface, uint32_t id) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5252 | { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5253 | struct shell_client *sc; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5254 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5255 | sc = zalloc(sizeof *sc); |
| 5256 | if (sc == NULL) { |
| 5257 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5258 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5259 | } |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5260 | |
| 5261 | sc->resource = wl_resource_create(client, interface, 1, id); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5262 | if (sc->resource == NULL) { |
| 5263 | free(sc); |
| 5264 | wl_client_post_no_memory(client); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5265 | return NULL; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | sc->client = client; |
| 5269 | sc->shell = shell; |
| 5270 | sc->destroy_listener.notify = handle_shell_client_destroy; |
| 5271 | wl_client_add_destroy_listener(client, &sc->destroy_listener); |
| 5272 | |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5273 | return sc; |
| 5274 | } |
| 5275 | |
| 5276 | static void |
| 5277 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5278 | { |
| 5279 | struct desktop_shell *shell = data; |
| 5280 | struct shell_client *sc; |
| 5281 | |
| 5282 | sc = shell_client_create(client, shell, &wl_shell_interface, id); |
| 5283 | if (sc) |
| 5284 | wl_resource_set_implementation(sc->resource, |
| 5285 | &shell_implementation, |
Jason Ekstrand | 9e9512f | 2014-04-16 21:12:10 -0500 | [diff] [blame] | 5286 | sc, NULL); |
Kristian Høgsberg | dd62aba | 2014-02-12 09:56:19 -0800 | [diff] [blame] | 5287 | } |
| 5288 | |
| 5289 | static void |
| 5290 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5291 | { |
| 5292 | struct desktop_shell *shell = data; |
| 5293 | struct shell_client *sc; |
| 5294 | |
| 5295 | sc = shell_client_create(client, shell, &xdg_shell_interface, id); |
| 5296 | if (sc) |
| 5297 | wl_resource_set_dispatcher(sc->resource, |
| 5298 | xdg_shell_unversioned_dispatch, |
| 5299 | NULL, sc, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5300 | } |
| 5301 | |
| 5302 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5303 | unbind_desktop_shell(struct wl_resource *resource) |
| 5304 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5305 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5306 | |
| 5307 | if (shell->locked) |
| 5308 | resume_desktop(shell); |
| 5309 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5310 | shell->child.desktop_shell = NULL; |
| 5311 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5315 | bind_desktop_shell(struct wl_client *client, |
| 5316 | void *data, uint32_t version, uint32_t id) |
| 5317 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5318 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5319 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5320 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5321 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 5322 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5323 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5324 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5325 | wl_resource_set_implementation(resource, |
| 5326 | &desktop_shell_implementation, |
| 5327 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5328 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5329 | |
| 5330 | if (version < 2) |
| 5331 | shell_fade_startup(shell); |
| 5332 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5333 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5334 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5335 | |
| 5336 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5337 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5338 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5339 | } |
| 5340 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5341 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5342 | 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] | 5343 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5344 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5345 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5346 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5347 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5348 | return; |
| 5349 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 5350 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5351 | if (!shell->locked) |
| 5352 | return; |
| 5353 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5354 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 5355 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5356 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5357 | if (wl_list_empty(&view->layer_link)) { |
| 5358 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 5359 | &view->layer_link); |
| 5360 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5361 | wl_event_source_timer_update(shell->screensaver.timer, |
| 5362 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5363 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5364 | } |
| 5365 | } |
| 5366 | |
| 5367 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5368 | screensaver_set_surface(struct wl_client *client, |
| 5369 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5370 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5371 | struct wl_resource *output_resource) |
| 5372 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5373 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5374 | struct weston_surface *surface = |
| 5375 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5376 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5377 | struct weston_view *view, *next; |
| 5378 | |
| 5379 | /* Make sure we only have one view */ |
| 5380 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 5381 | weston_view_destroy(view); |
| 5382 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5383 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5384 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5385 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5386 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5387 | } |
| 5388 | |
| 5389 | static const struct screensaver_interface screensaver_implementation = { |
| 5390 | screensaver_set_surface |
| 5391 | }; |
| 5392 | |
| 5393 | static void |
| 5394 | unbind_screensaver(struct wl_resource *resource) |
| 5395 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5396 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5397 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5398 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5399 | } |
| 5400 | |
| 5401 | static void |
| 5402 | bind_screensaver(struct wl_client *client, |
| 5403 | void *data, uint32_t version, uint32_t id) |
| 5404 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5405 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5406 | struct wl_resource *resource; |
| 5407 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5408 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5409 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5410 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5411 | wl_resource_set_implementation(resource, |
| 5412 | &screensaver_implementation, |
| 5413 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5414 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5415 | return; |
| 5416 | } |
| 5417 | |
| 5418 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5419 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5420 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5421 | } |
| 5422 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5423 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5424 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5425 | struct weston_surface *current; |
| 5426 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5427 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5428 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5429 | }; |
| 5430 | |
| 5431 | static void |
| 5432 | switcher_next(struct switcher *switcher) |
| 5433 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5434 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5435 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5436 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5437 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5438 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5439 | /* temporary re-display minimized surfaces */ |
| 5440 | struct weston_view *tmp; |
| 5441 | struct weston_view **minimized; |
| 5442 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list, layer_link) { |
| 5443 | wl_list_remove(&view->layer_link); |
| 5444 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 5445 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 5446 | *minimized = view; |
| 5447 | } |
| 5448 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5449 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5450 | shsurf = get_shell_surface(view->surface); |
Rafael Antognolli | 5031cbe | 2013-12-05 19:01:21 -0200 | [diff] [blame] | 5451 | if (shsurf && |
| 5452 | shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5453 | shsurf->parent == NULL) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5454 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5455 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5456 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5457 | next = view->surface; |
| 5458 | prev = view->surface; |
| 5459 | view->alpha = 0.25; |
| 5460 | weston_view_geometry_dirty(view); |
| 5461 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5462 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5463 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5464 | if (is_black_surface(view->surface, NULL)) { |
| 5465 | view->alpha = 0.25; |
| 5466 | weston_view_geometry_dirty(view); |
| 5467 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5468 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5469 | } |
| 5470 | |
| 5471 | if (next == NULL) |
| 5472 | next = first; |
| 5473 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5474 | if (next == NULL) |
| 5475 | return; |
| 5476 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5477 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5478 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5479 | |
| 5480 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5481 | wl_list_for_each(view, &next->views, surface_link) |
| 5482 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5483 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5484 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5485 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5486 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5487 | } |
| 5488 | |
| 5489 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5490 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5491 | { |
| 5492 | struct switcher *switcher = |
| 5493 | container_of(listener, struct switcher, listener); |
| 5494 | |
| 5495 | switcher_next(switcher); |
| 5496 | } |
| 5497 | |
| 5498 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5499 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5500 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5501 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5502 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5503 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5504 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5505 | 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] | 5506 | if (is_focus_view(view)) |
| 5507 | continue; |
| 5508 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5509 | view->alpha = 1.0; |
| 5510 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5511 | } |
| 5512 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5513 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5514 | activate(switcher->shell, switcher->current, |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 5515 | (struct weston_seat *) keyboard->seat, true); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5516 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5517 | weston_keyboard_end_grab(keyboard); |
| 5518 | if (keyboard->input_method_resource) |
| 5519 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5520 | |
| 5521 | /* re-hide surfaces that were temporary shown during the switch */ |
| 5522 | struct weston_view **minimized; |
| 5523 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 5524 | /* with the exception of the current selected */ |
| 5525 | if ((*minimized)->surface != switcher->current) { |
| 5526 | wl_list_remove(&(*minimized)->layer_link); |
| 5527 | wl_list_insert(&switcher->shell->minimized_layer.view_list, &(*minimized)->layer_link); |
| 5528 | weston_view_damage_below(*minimized); |
| 5529 | } |
| 5530 | } |
| 5531 | wl_array_release(&switcher->minimized_array); |
| 5532 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5533 | free(switcher); |
| 5534 | } |
| 5535 | |
| 5536 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5537 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5538 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5539 | { |
| 5540 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5541 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5542 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5543 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5544 | switcher_next(switcher); |
| 5545 | } |
| 5546 | |
| 5547 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5548 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5549 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5550 | uint32_t mods_locked, uint32_t group) |
| 5551 | { |
| 5552 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5553 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5554 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5555 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5556 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5557 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5558 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5559 | static void |
| 5560 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5561 | { |
| 5562 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5563 | |
| 5564 | switcher_destroy(switcher); |
| 5565 | } |
| 5566 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5567 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5568 | switcher_key, |
| 5569 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5570 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5571 | }; |
| 5572 | |
| 5573 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5574 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5575 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5576 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5577 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5578 | struct switcher *switcher; |
| 5579 | |
| 5580 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5581 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5582 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5583 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5584 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 5585 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5586 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5587 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5588 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5589 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5590 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5591 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5592 | switcher_next(switcher); |
| 5593 | } |
| 5594 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5595 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5596 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5597 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5598 | { |
| 5599 | struct weston_compositor *compositor = data; |
| 5600 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5601 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5602 | |
| 5603 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5604 | * control on the primary display. We'd have to extend later if we |
| 5605 | * ever get support for setting backlights on random desktop LCD |
| 5606 | * panels though */ |
| 5607 | output = get_default_output(compositor); |
| 5608 | if (!output) |
| 5609 | return; |
| 5610 | |
| 5611 | if (!output->set_backlight) |
| 5612 | return; |
| 5613 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5614 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5615 | backlight_new = output->backlight_current - 25; |
| 5616 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5617 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5618 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5619 | if (backlight_new < 5) |
| 5620 | backlight_new = 5; |
| 5621 | if (backlight_new > 255) |
| 5622 | backlight_new = 255; |
| 5623 | |
| 5624 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5625 | output->set_backlight(output, output->backlight_current); |
| 5626 | } |
| 5627 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5628 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5629 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5630 | struct weston_seat *seat; |
| 5631 | uint32_t key[2]; |
| 5632 | int key_released[2]; |
| 5633 | }; |
| 5634 | |
| 5635 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5636 | 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] | 5637 | uint32_t key, uint32_t state) |
| 5638 | { |
| 5639 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5640 | struct weston_compositor *ec = db->seat->compositor; |
| 5641 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5642 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5643 | uint32_t serial; |
| 5644 | int send = 0, terminate = 0; |
| 5645 | int check_binding = 1; |
| 5646 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5647 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5648 | |
| 5649 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5650 | /* Do not run bindings on key releases */ |
| 5651 | check_binding = 0; |
| 5652 | |
| 5653 | for (i = 0; i < 2; i++) |
| 5654 | if (key == db->key[i]) |
| 5655 | db->key_released[i] = 1; |
| 5656 | |
| 5657 | if (db->key_released[0] && db->key_released[1]) { |
| 5658 | /* All key releases been swalled so end the grab */ |
| 5659 | terminate = 1; |
| 5660 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5661 | /* Should not swallow release of other keys */ |
| 5662 | send = 1; |
| 5663 | } |
| 5664 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5665 | /* Do not check bindings for the first press of the binding |
| 5666 | * key. This allows it to be used as a debug shortcut. |
| 5667 | * We still need to swallow this event. */ |
| 5668 | check_binding = 0; |
| 5669 | } else if (db->key[1]) { |
| 5670 | /* If we already ran a binding don't process another one since |
| 5671 | * we can't keep track of all the binding keys that were |
| 5672 | * pressed in order to swallow the release events. */ |
| 5673 | send = 1; |
| 5674 | check_binding = 0; |
| 5675 | } |
| 5676 | |
| 5677 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5678 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5679 | key, state)) { |
| 5680 | /* We ran a binding so swallow the press and keep the |
| 5681 | * grab to swallow the released too. */ |
| 5682 | send = 0; |
| 5683 | terminate = 0; |
| 5684 | db->key[1] = key; |
| 5685 | } else { |
| 5686 | /* Terminate the grab since the key pressed is not a |
| 5687 | * debug binding key. */ |
| 5688 | send = 1; |
| 5689 | terminate = 1; |
| 5690 | } |
| 5691 | } |
| 5692 | |
| 5693 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5694 | serial = wl_display_next_serial(display); |
| 5695 | resource_list = &grab->keyboard->focus_resource_list; |
| 5696 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5697 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5698 | } |
| 5699 | } |
| 5700 | |
| 5701 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5702 | weston_keyboard_end_grab(grab->keyboard); |
| 5703 | if (grab->keyboard->input_method_resource) |
| 5704 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5705 | free(db); |
| 5706 | } |
| 5707 | } |
| 5708 | |
| 5709 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5710 | 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] | 5711 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5712 | uint32_t mods_locked, uint32_t group) |
| 5713 | { |
| 5714 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5715 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5716 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5717 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5718 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5719 | wl_resource_for_each(resource, resource_list) { |
| 5720 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5721 | mods_latched, mods_locked, group); |
| 5722 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5723 | } |
| 5724 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5725 | static void |
| 5726 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5727 | { |
| 5728 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5729 | |
| 5730 | weston_keyboard_end_grab(grab->keyboard); |
| 5731 | free(db); |
| 5732 | } |
| 5733 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5734 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5735 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5736 | debug_binding_modifiers, |
| 5737 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5738 | }; |
| 5739 | |
| 5740 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5741 | 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] | 5742 | { |
| 5743 | struct debug_binding_grab *grab; |
| 5744 | |
| 5745 | grab = calloc(1, sizeof *grab); |
| 5746 | if (!grab) |
| 5747 | return; |
| 5748 | |
| 5749 | grab->seat = (struct weston_seat *) seat; |
| 5750 | grab->key[0] = key; |
| 5751 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5752 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5753 | } |
| 5754 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5755 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5756 | 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] | 5757 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5758 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5759 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5760 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5761 | struct desktop_shell *shell = data; |
| 5762 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5763 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5764 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5765 | focus_surface = seat->keyboard->focus; |
| 5766 | if (!focus_surface) |
| 5767 | return; |
| 5768 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5769 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5770 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5771 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5772 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5773 | |
| 5774 | /* Skip clients that we launched ourselves (the credentials of |
| 5775 | * the socketpair is ours) */ |
| 5776 | if (pid == getpid()) |
| 5777 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5778 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5779 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5780 | } |
| 5781 | |
| 5782 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5783 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5784 | uint32_t key, void *data) |
| 5785 | { |
| 5786 | struct desktop_shell *shell = data; |
| 5787 | unsigned int new_index = shell->workspaces.current; |
| 5788 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5789 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5790 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5791 | if (new_index != 0) |
| 5792 | new_index--; |
| 5793 | |
| 5794 | change_workspace(shell, new_index); |
| 5795 | } |
| 5796 | |
| 5797 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5798 | workspace_down_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 < shell->workspaces.num - 1) |
| 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_f_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; |
| 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 | new_index = key - KEY_F1; |
| 5822 | if (new_index >= shell->workspaces.num) |
| 5823 | new_index = shell->workspaces.num - 1; |
| 5824 | |
| 5825 | change_workspace(shell, new_index); |
| 5826 | } |
| 5827 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5828 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5829 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5830 | uint32_t key, void *data) |
| 5831 | { |
| 5832 | struct desktop_shell *shell = data; |
| 5833 | unsigned int new_index = shell->workspaces.current; |
| 5834 | |
| 5835 | if (shell->locked) |
| 5836 | return; |
| 5837 | |
| 5838 | if (new_index != 0) |
| 5839 | new_index--; |
| 5840 | |
| 5841 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5842 | } |
| 5843 | |
| 5844 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5845 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5846 | uint32_t key, void *data) |
| 5847 | { |
| 5848 | struct desktop_shell *shell = data; |
| 5849 | unsigned int new_index = shell->workspaces.current; |
| 5850 | |
| 5851 | if (shell->locked) |
| 5852 | return; |
| 5853 | |
| 5854 | if (new_index < shell->workspaces.num - 1) |
| 5855 | new_index++; |
| 5856 | |
| 5857 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5858 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5859 | |
| 5860 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5861 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 5862 | { |
| 5863 | struct weston_output *output, *first_output; |
| 5864 | struct weston_compositor *ec = view->surface->compositor; |
| 5865 | struct shell_surface *shsurf; |
| 5866 | float x, y; |
| 5867 | int visible; |
| 5868 | |
| 5869 | x = view->geometry.x; |
| 5870 | y = view->geometry.y; |
| 5871 | |
| 5872 | /* At this point the destroyed output is not in the list anymore. |
| 5873 | * If the view is still visible somewhere, we leave where it is, |
| 5874 | * otherwise, move it to the first output. */ |
| 5875 | visible = 0; |
| 5876 | wl_list_for_each(output, &ec->output_list, link) { |
| 5877 | if (pixman_region32_contains_point(&output->region, |
| 5878 | x, y, NULL)) { |
| 5879 | visible = 1; |
| 5880 | break; |
| 5881 | } |
| 5882 | } |
| 5883 | |
| 5884 | if (!visible) { |
| 5885 | first_output = container_of(ec->output_list.next, |
| 5886 | struct weston_output, link); |
| 5887 | |
| 5888 | x = first_output->x + first_output->width / 4; |
| 5889 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 5890 | |
| 5891 | weston_view_set_position(view, x, y); |
| 5892 | } else { |
| 5893 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5894 | } |
| 5895 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5896 | |
| 5897 | shsurf = get_shell_surface(view->surface); |
| 5898 | |
| 5899 | if (shsurf) { |
| 5900 | shsurf->saved_position_valid = false; |
| 5901 | shsurf->next_state.maximized = false; |
| 5902 | shsurf->next_state.fullscreen = false; |
| 5903 | shsurf->state_changed = true; |
| 5904 | } |
| 5905 | } |
| 5906 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5907 | void |
| 5908 | shell_for_each_layer(struct desktop_shell *shell, |
| 5909 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5910 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5911 | struct workspace **ws; |
| 5912 | |
| 5913 | func(shell, &shell->fullscreen_layer, data); |
| 5914 | func(shell, &shell->panel_layer, data); |
| 5915 | func(shell, &shell->background_layer, data); |
| 5916 | func(shell, &shell->lock_layer, data); |
| 5917 | func(shell, &shell->input_panel_layer, data); |
| 5918 | |
| 5919 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5920 | func(shell, &(*ws)->layer, data); |
| 5921 | } |
| 5922 | |
| 5923 | static void |
| 5924 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 5925 | struct weston_layer *layer, |
| 5926 | void *data) |
| 5927 | { |
| 5928 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5929 | struct weston_view *view; |
| 5930 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5931 | wl_list_for_each(view, &layer->view_list, layer_link) { |
| 5932 | if (view->output != output) |
| 5933 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5934 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5935 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5936 | } |
| 5937 | } |
| 5938 | |
| 5939 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5940 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5941 | { |
| 5942 | struct shell_output *output_listener = |
| 5943 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5944 | struct weston_output *output = output_listener->output; |
| 5945 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5946 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5947 | shell_for_each_layer(shell, shell_output_destroy_move_layer, output); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 5948 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5949 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5950 | wl_list_remove(&output_listener->link); |
| 5951 | free(output_listener); |
| 5952 | } |
| 5953 | |
| 5954 | static void |
| 5955 | create_shell_output(struct desktop_shell *shell, |
| 5956 | struct weston_output *output) |
| 5957 | { |
| 5958 | struct shell_output *shell_output; |
| 5959 | |
| 5960 | shell_output = zalloc(sizeof *shell_output); |
| 5961 | if (shell_output == NULL) |
| 5962 | return; |
| 5963 | |
| 5964 | shell_output->output = output; |
| 5965 | shell_output->shell = shell; |
| 5966 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5967 | wl_signal_add(&output->destroy_signal, |
| 5968 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5969 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5970 | } |
| 5971 | |
| 5972 | static void |
| 5973 | handle_output_create(struct wl_listener *listener, void *data) |
| 5974 | { |
| 5975 | struct desktop_shell *shell = |
| 5976 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5977 | struct weston_output *output = (struct weston_output *)data; |
| 5978 | |
| 5979 | create_shell_output(shell, output); |
| 5980 | } |
| 5981 | |
| 5982 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5983 | handle_output_move_layer(struct desktop_shell *shell, |
| 5984 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5985 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5986 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5987 | struct weston_view *view; |
| 5988 | float x, y; |
| 5989 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5990 | wl_list_for_each(view, &layer->view_list, layer_link) { |
| 5991 | if (view->output != output) |
| 5992 | continue; |
| 5993 | |
| 5994 | x = view->geometry.x + output->move_x; |
| 5995 | y = view->geometry.y + output->move_y; |
| 5996 | weston_view_set_position(view, x, y); |
| 5997 | } |
| 5998 | } |
| 5999 | |
| 6000 | static void |
| 6001 | handle_output_move(struct wl_listener *listener, void *data) |
| 6002 | { |
| 6003 | struct desktop_shell *shell; |
| 6004 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6005 | shell = container_of(listener, struct desktop_shell, |
| 6006 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6007 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 6008 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6009 | } |
| 6010 | |
| 6011 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6012 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6013 | struct desktop_shell *shell) |
| 6014 | { |
| 6015 | struct weston_output *output; |
| 6016 | |
| 6017 | wl_list_init(&shell->output_list); |
| 6018 | wl_list_for_each(output, &ec->output_list, link) |
| 6019 | create_shell_output(shell, output); |
| 6020 | |
| 6021 | shell->output_create_listener.notify = handle_output_create; |
| 6022 | wl_signal_add(&ec->output_created_signal, |
| 6023 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6024 | |
| 6025 | shell->output_move_listener.notify = handle_output_move; |
| 6026 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6027 | } |
| 6028 | |
| 6029 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6030 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6031 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6032 | struct desktop_shell *shell = |
| 6033 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6034 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6035 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6036 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 6037 | /* Force state to unlocked so we don't try to fade */ |
| 6038 | shell->locked = false; |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6039 | if (shell->child.client) |
| 6040 | wl_client_destroy(shell->child.client); |
| 6041 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6042 | wl_list_remove(&shell->idle_listener.link); |
| 6043 | wl_list_remove(&shell->wake_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6044 | |
| 6045 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6046 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6047 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6048 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6049 | wl_list_remove(&shell_output->link); |
| 6050 | free(shell_output); |
| 6051 | } |
| 6052 | |
| 6053 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 6054 | wl_list_remove(&shell->output_move_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6055 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6056 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6057 | workspace_destroy(*ws); |
| 6058 | wl_array_release(&shell->workspaces.array); |
| 6059 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6060 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6061 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6062 | free(shell); |
| 6063 | } |
| 6064 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6065 | static void |
| 6066 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6067 | { |
| 6068 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6069 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6070 | |
| 6071 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6072 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6073 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6074 | terminate_binding, ec); |
| 6075 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6076 | click_to_activate_binding, |
| 6077 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 6078 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 6079 | click_to_activate_binding, |
| 6080 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6081 | weston_compositor_add_touch_binding(ec, 0, |
| 6082 | touch_to_activate_binding, |
| 6083 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6084 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6085 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6086 | surface_opacity_binding, NULL); |
| 6087 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6088 | MODIFIER_SUPER, zoom_axis_binding, |
| 6089 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6090 | |
| 6091 | /* configurable bindings */ |
| 6092 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6093 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6094 | zoom_key_binding, NULL); |
| 6095 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6096 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 6097 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 6098 | maximize_binding, NULL); |
| 6099 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 6100 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6101 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6102 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6103 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6104 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 6105 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 6106 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 6107 | mod | MODIFIER_SHIFT, |
| 6108 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6109 | |
| 6110 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 6111 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 6112 | rotate_binding, NULL); |
| 6113 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6114 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6115 | shell); |
| 6116 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6117 | ec); |
| 6118 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6119 | backlight_binding, ec); |
| 6120 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6121 | ec); |
| 6122 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6123 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6124 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6125 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6126 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6127 | workspace_up_binding, shell); |
| 6128 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6129 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6130 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6131 | workspace_move_surface_up_binding, |
| 6132 | shell); |
| 6133 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6134 | workspace_move_surface_down_binding, |
| 6135 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6136 | |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 6137 | if (shell->exposay_modifier) |
| 6138 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 6139 | exposay_binding, shell); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6140 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6141 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6142 | if (shell->workspaces.num > 1) { |
| 6143 | num_workspace_bindings = shell->workspaces.num; |
| 6144 | if (num_workspace_bindings > 6) |
| 6145 | num_workspace_bindings = 6; |
| 6146 | for (i = 0; i < num_workspace_bindings; i++) |
| 6147 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6148 | workspace_f_binding, |
| 6149 | shell); |
| 6150 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6151 | |
| 6152 | /* Debug bindings */ |
| 6153 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 6154 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6155 | } |
| 6156 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6157 | static void |
| 6158 | handle_seat_created(struct wl_listener *listener, void *data) |
| 6159 | { |
| 6160 | struct weston_seat *seat = data; |
| 6161 | |
| 6162 | create_shell_seat(seat); |
| 6163 | } |
| 6164 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6165 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6166 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6167 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6168 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6169 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6170 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6171 | struct workspace **pws; |
| 6172 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6173 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6174 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6175 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6176 | if (shell == NULL) |
| 6177 | return -1; |
| 6178 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6179 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6180 | |
| 6181 | shell->destroy_listener.notify = shell_destroy; |
| 6182 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6183 | shell->idle_listener.notify = idle_handler; |
| 6184 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6185 | shell->wake_listener.notify = wake_handler; |
| 6186 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6187 | |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6188 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6189 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6190 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6191 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6192 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 4779241 | 2014-05-04 13:47:06 -0700 | [diff] [blame] | 6193 | ec->shell_interface.set_fullscreen = shell_interface_set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6194 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 6195 | ec->shell_interface.move = shell_interface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6196 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6197 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | e5c1ae9 | 2014-04-30 16:28:41 -0700 | [diff] [blame] | 6198 | ec->shell_interface.set_margin = set_margin; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6199 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6200 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6201 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6202 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6203 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6204 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6205 | |
| 6206 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6207 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6208 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 6209 | if (input_panel_setup(shell) < 0) |
| 6210 | return -1; |
| 6211 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6212 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6213 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6214 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6215 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6216 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6217 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6218 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6219 | if (pws == NULL) |
| 6220 | return -1; |
| 6221 | |
| 6222 | *pws = workspace_create(); |
| 6223 | if (*pws == NULL) |
| 6224 | return -1; |
| 6225 | } |
| 6226 | activate_workspace(shell, 0); |
| 6227 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 6228 | weston_layer_init(&shell->minimized_layer, NULL); |
| 6229 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6230 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6231 | wl_list_init(&shell->workspaces.animation.link); |
| 6232 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6233 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6234 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6235 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6236 | return -1; |
| 6237 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6238 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6239 | shell, bind_xdg_shell) == NULL) |
| 6240 | return -1; |
| 6241 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6242 | if (wl_global_create(ec->wl_display, |
| 6243 | &desktop_shell_interface, 2, |
| 6244 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6245 | return -1; |
| 6246 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6247 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6248 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6249 | return -1; |
| 6250 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6251 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6252 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6253 | return -1; |
| 6254 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6255 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6256 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6257 | setup_output_destroy_handler(ec, shell); |
| 6258 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6259 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6260 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6261 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6262 | shell->screensaver.timer = |
| 6263 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6264 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 6265 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6266 | handle_seat_created(NULL, seat); |
| 6267 | shell->seat_create_listener.notify = handle_seat_created; |
| 6268 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6269 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 6270 | screenshooter_create(ec); |
| 6271 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6272 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6273 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6274 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6275 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6276 | return 0; |
| 6277 | } |