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 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 12 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 13 | * The above copyright notice and this permission notice (including the next |
| 14 | * paragraph) shall be included in all copies or substantial portions of the |
| 15 | * Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | * DEALINGS IN THE SOFTWARE. |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 24 | */ |
| 25 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 26 | #include "config.h" |
| 27 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 28 | #include <stdlib.h> |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 29 | #include <stdint.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 30 | #include <stdio.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 31 | #include <string.h> |
| 32 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 33 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 34 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 35 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 36 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 37 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 38 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 39 | #include "shell.h" |
Pekka Paalanen | 58f98c9 | 2016-06-03 16:45:21 +0300 | [diff] [blame] | 40 | #include "compositor/weston.h" |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 41 | #include "weston-desktop-shell-server-protocol.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 42 | #include "shared/config-parser.h" |
Jon Cruz | d618f68 | 2015-06-15 15:37:09 -0700 | [diff] [blame] | 43 | #include "shared/helpers.h" |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 44 | #include "libweston-desktop/libweston-desktop.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 45 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 46 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 47 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 48 | |
Giulio Camuffo | 1aaf3e4 | 2013-12-09 22:47:58 +0100 | [diff] [blame] | 49 | #ifndef static_assert |
| 50 | #define static_assert(cond, msg) |
| 51 | #endif |
| 52 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 53 | struct focus_state { |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 54 | struct desktop_shell *shell; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 55 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 56 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 57 | struct weston_surface *keyboard_focus; |
| 58 | struct wl_list link; |
| 59 | struct wl_listener seat_destroy_listener; |
| 60 | struct wl_listener surface_destroy_listener; |
| 61 | }; |
| 62 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 63 | /* |
| 64 | * Surface stacking and ordering. |
| 65 | * |
| 66 | * This is handled using several linked lists of surfaces, organised into |
| 67 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 68 | * above all of the surfaces in the layer below. The set of layers is static and |
| 69 | * in the following order (top-most first): |
| 70 | * • Lock layer (only ever displayed on its own) |
| 71 | * • Cursor layer |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 72 | * • Input panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 73 | * • Fullscreen layer |
| 74 | * • Panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 75 | * • Workspace layers |
| 76 | * • Background layer |
| 77 | * |
| 78 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 79 | * display. For example, when locking the screen, all layers except the lock |
| 80 | * layer are removed. |
| 81 | * |
| 82 | * A surface’s layer is modified on configuring the surface, in |
| 83 | * set_surface_type() (which is only called when the surface’s type change is |
| 84 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 85 | * fullscreen) its layer changes too. |
| 86 | * |
| 87 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 88 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 89 | * linked list of its children. When a surface’s layer is updated, so are the |
| 90 | * layers of its children. Note that child surfaces are *not* the same as |
| 91 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 92 | * order. |
| 93 | * |
| 94 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 95 | * have the same parent) only contains weston_surfaces which have a |
| 96 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 97 | * weston_surfaces. This means that the following implication does *not* hold: |
| 98 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 99 | */ |
| 100 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 101 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 102 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 103 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 104 | struct weston_desktop_surface *desktop_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 105 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 106 | int32_t last_width, last_height; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 107 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 108 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 109 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 110 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 111 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 112 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 113 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 114 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 115 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 116 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 117 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 118 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 119 | } rotation; |
| 120 | |
| 121 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 122 | struct weston_transform transform; /* matrix from x, y */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 123 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 124 | } fullscreen; |
| 125 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 126 | struct weston_transform workspace_transform; |
| 127 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 128 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 129 | struct weston_output *output; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 130 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 131 | struct surface_state { |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame^] | 132 | bool fullscreen; |
| 133 | bool maximized; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 134 | bool lowered; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 135 | } state; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 136 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 137 | int focus_count; |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 138 | |
| 139 | bool destroying; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 140 | }; |
| 141 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 142 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 143 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 144 | struct shell_surface *shsurf; |
| 145 | struct wl_listener shsurf_destroy_listener; |
| 146 | }; |
| 147 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 148 | struct shell_touch_grab { |
| 149 | struct weston_touch_grab grab; |
| 150 | struct shell_surface *shsurf; |
| 151 | struct wl_listener shsurf_destroy_listener; |
| 152 | struct weston_touch *touch; |
| 153 | }; |
| 154 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 155 | struct weston_move_grab { |
| 156 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 157 | wl_fixed_t dx, dy; |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 158 | bool client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 159 | }; |
| 160 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 161 | struct weston_touch_move_grab { |
| 162 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 163 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 164 | wl_fixed_t dx, dy; |
| 165 | }; |
| 166 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 167 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 168 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 169 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 170 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 171 | float x; |
| 172 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 173 | } center; |
| 174 | }; |
| 175 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 176 | struct shell_seat { |
| 177 | struct weston_seat *seat; |
| 178 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 179 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 180 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 181 | struct wl_listener caps_changed_listener; |
| 182 | struct wl_listener pointer_focus_listener; |
| 183 | struct wl_listener keyboard_focus_listener; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 184 | }; |
| 185 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 186 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 187 | static struct desktop_shell * |
| 188 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 189 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 190 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 191 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 192 | |
| 193 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 194 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 195 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 196 | static void |
| 197 | shell_fade_startup(struct desktop_shell *shell); |
| 198 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 199 | static struct shell_seat * |
| 200 | get_shell_seat(struct weston_seat *seat); |
| 201 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 202 | static void |
| 203 | get_output_panel_size(struct desktop_shell *shell, |
| 204 | struct weston_output *output, |
| 205 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 206 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 207 | static void |
| 208 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 209 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 210 | static int |
| 211 | shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 212 | { |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 213 | const char *t, *c; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 214 | struct weston_desktop_surface *desktop_surface = |
| 215 | weston_surface_get_desktop_surface(surface); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 216 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 217 | t = weston_desktop_surface_get_title(desktop_surface); |
| 218 | c = weston_desktop_surface_get_app_id(desktop_surface); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 219 | |
| 220 | return snprintf(buf, len, "%s window%s%s%s%s%s", |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 221 | "top-level", |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 222 | t ? " '" : "", t ?: "", t ? "'" : "", |
| 223 | c ? " of " : "", c ?: ""); |
| 224 | } |
| 225 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 226 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 227 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 228 | { |
| 229 | struct shell_grab *grab; |
| 230 | |
| 231 | grab = container_of(listener, struct shell_grab, |
| 232 | shsurf_destroy_listener); |
| 233 | |
| 234 | grab->shsurf = NULL; |
| 235 | } |
| 236 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 237 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 238 | get_default_view(struct weston_surface *surface) |
| 239 | { |
| 240 | struct shell_surface *shsurf; |
| 241 | struct weston_view *view; |
| 242 | |
| 243 | if (!surface || wl_list_empty(&surface->views)) |
| 244 | return NULL; |
| 245 | |
| 246 | shsurf = get_shell_surface(surface); |
| 247 | if (shsurf) |
| 248 | return shsurf->view; |
| 249 | |
| 250 | wl_list_for_each(view, &surface->views, surface_link) |
| 251 | if (weston_view_is_mapped(view)) |
| 252 | return view; |
| 253 | |
| 254 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 255 | } |
| 256 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 257 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 258 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 259 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 260 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 261 | struct weston_pointer *pointer, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 262 | enum weston_desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 263 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 264 | struct desktop_shell *shell = shsurf->shell; |
| 265 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 266 | weston_seat_break_desktop_grabs(pointer->seat); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 267 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 268 | grab->grab.interface = interface; |
| 269 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 270 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 271 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 272 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 273 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 274 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 275 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 276 | if (shell->child.desktop_shell) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 277 | weston_desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 278 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 279 | weston_pointer_set_focus(pointer, |
| 280 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 281 | wl_fixed_from_int(0), |
| 282 | wl_fixed_from_int(0)); |
| 283 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 284 | } |
| 285 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 286 | static void |
| 287 | get_output_panel_size(struct desktop_shell *shell, |
| 288 | struct weston_output *output, |
| 289 | int *width, |
| 290 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 291 | { |
| 292 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 293 | |
| 294 | *width = 0; |
| 295 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 296 | |
| 297 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 298 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 299 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 300 | wl_list_for_each(view, &shell->panel_layer.view_list.link, layer_link.link) { |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 301 | float x, y; |
| 302 | |
| 303 | if (view->surface->output != output) |
| 304 | continue; |
| 305 | |
| 306 | switch (shell->panel_position) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 307 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 308 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 309 | weston_view_to_global_float(view, |
| 310 | view->surface->width, 0, |
| 311 | &x, &y); |
| 312 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 313 | *width = (int)x - output->x; |
| 314 | *height = view->surface->height + (int) y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 315 | return; |
| 316 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 317 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 318 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 319 | weston_view_to_global_float(view, |
| 320 | 0, view->surface->height, |
| 321 | &x, &y); |
| 322 | |
Derek Foreman | 612341f | 2015-04-15 12:23:55 -0500 | [diff] [blame] | 323 | *width = view->surface->width + (int)x - output->x; |
| 324 | *height = (int)y - output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 325 | return; |
| 326 | |
| 327 | default: |
| 328 | /* we've already set width and height to |
| 329 | * fallback values. */ |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 330 | break; |
| 331 | } |
| 332 | } |
| 333 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 334 | /* the correct view wasn't found */ |
| 335 | } |
| 336 | |
| 337 | static void |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 338 | get_output_work_area(struct desktop_shell *shell, |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 339 | struct weston_output *output, |
| 340 | pixman_rectangle32_t *area) |
| 341 | { |
| 342 | int32_t panel_width = 0, panel_height = 0; |
| 343 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 344 | area->x = output->x; |
| 345 | area->y = output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 346 | |
| 347 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 348 | switch (shell->panel_position) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 349 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 350 | default: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 351 | area->y += panel_height; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 352 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 353 | area->width = output->width; |
| 354 | area->height = output->height - panel_height; |
| 355 | break; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 356 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 357 | area->x += panel_width; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 358 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 359 | area->width = output->width - panel_width; |
| 360 | area->height = output->height; |
| 361 | break; |
| 362 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 365 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 366 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 367 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 368 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 369 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 370 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 371 | |
| 372 | if (grab->shsurf->resize_edges) { |
| 373 | grab->shsurf->resize_edges = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 374 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 375 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 376 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 377 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 381 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 382 | const struct weston_touch_grab_interface *interface, |
| 383 | struct shell_surface *shsurf, |
| 384 | struct weston_touch *touch) |
| 385 | { |
| 386 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 387 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 388 | weston_seat_break_desktop_grabs(touch->seat); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 389 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 390 | grab->grab.interface = interface; |
| 391 | grab->shsurf = shsurf; |
| 392 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 393 | wl_signal_add(&shsurf->destroy_signal, |
| 394 | &grab->shsurf_destroy_listener); |
| 395 | |
| 396 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 397 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 398 | |
| 399 | weston_touch_start_grab(touch, &grab->grab); |
| 400 | if (shell->child.desktop_shell) |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 401 | weston_touch_set_focus(touch, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 402 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | static void |
| 406 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 407 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 408 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 409 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 410 | grab->shsurf->grabbed = 0; |
| 411 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 412 | |
| 413 | weston_touch_end_grab(grab->touch); |
| 414 | } |
| 415 | |
| 416 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 417 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 418 | struct weston_output *output); |
| 419 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 420 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 421 | get_modifier(char *modifier) |
| 422 | { |
| 423 | if (!modifier) |
| 424 | return MODIFIER_SUPER; |
| 425 | |
| 426 | if (!strcmp("ctrl", modifier)) |
| 427 | return MODIFIER_CTRL; |
| 428 | else if (!strcmp("alt", modifier)) |
| 429 | return MODIFIER_ALT; |
| 430 | else if (!strcmp("super", modifier)) |
| 431 | return MODIFIER_SUPER; |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 432 | else if (!strcmp("none", modifier)) |
| 433 | return 0; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 434 | else |
| 435 | return MODIFIER_SUPER; |
| 436 | } |
| 437 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 438 | static enum animation_type |
| 439 | get_animation_type(char *animation) |
| 440 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 441 | if (!animation) |
| 442 | return ANIMATION_NONE; |
| 443 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 444 | if (!strcmp("zoom", animation)) |
| 445 | return ANIMATION_ZOOM; |
| 446 | else if (!strcmp("fade", animation)) |
| 447 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 448 | else if (!strcmp("dim-layer", animation)) |
| 449 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 450 | else |
| 451 | return ANIMATION_NONE; |
| 452 | } |
| 453 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 454 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 455 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 456 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 457 | struct weston_config_section *section; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 458 | char *s, *client; |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 459 | int ret; |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 460 | int allow_zap; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 461 | |
Giulio Camuffo | d52f3b7 | 2016-06-02 21:48:11 +0300 | [diff] [blame] | 462 | section = weston_config_get_section(wet_get_config(shell->compositor), |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 463 | "shell", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 464 | ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 465 | WESTON_SHELL_CLIENT); |
| 466 | if (ret < 0) |
| 467 | client = NULL; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 468 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 469 | "client", &s, client); |
| 470 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 471 | shell->client = s; |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 472 | |
| 473 | weston_config_section_get_bool(section, |
| 474 | "allow-zap", &allow_zap, true); |
| 475 | shell->allow_zap = allow_zap; |
| 476 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 477 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 478 | "binding-modifier", &s, "super"); |
| 479 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 480 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 481 | |
| 482 | weston_config_section_get_string(section, |
| 483 | "exposay-modifier", &s, "none"); |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 484 | shell->exposay_modifier = get_modifier(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 485 | free(s); |
| 486 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 487 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 488 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 489 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 490 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 491 | shell->win_close_animation_type = get_animation_type(s); |
| 492 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 493 | weston_config_section_get_string(section, |
| 494 | "startup-animation", &s, "fade"); |
| 495 | shell->startup_animation_type = get_animation_type(s); |
| 496 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 497 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 498 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 499 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 500 | shell->focus_animation_type = get_animation_type(s); |
| 501 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 502 | weston_config_section_get_uint(section, "num-workspaces", |
| 503 | &shell->workspaces.num, |
| 504 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 505 | } |
| 506 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 507 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 508 | get_default_output(struct weston_compositor *compositor) |
| 509 | { |
Armin Krezović | 10b0618 | 2016-06-23 11:59:30 +0200 | [diff] [blame] | 510 | if (wl_list_empty(&compositor->output_list)) |
| 511 | return NULL; |
| 512 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 513 | return container_of(compositor->output_list.next, |
| 514 | struct weston_output, link); |
| 515 | } |
| 516 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 517 | static int |
| 518 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 519 | { |
| 520 | return snprintf(buf, len, "focus highlight effect for output %s", |
| 521 | surface->output->name); |
| 522 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 523 | |
| 524 | /* no-op func for checking focus surface */ |
| 525 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 526 | focus_surface_committed(struct weston_surface *es, int32_t sx, int32_t sy) |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 527 | { |
| 528 | } |
| 529 | |
| 530 | static struct focus_surface * |
| 531 | get_focus_surface(struct weston_surface *surface) |
| 532 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 533 | if (surface->committed == focus_surface_committed) |
| 534 | return surface->committed_private; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 535 | else |
| 536 | return NULL; |
| 537 | } |
| 538 | |
| 539 | static bool |
| 540 | is_focus_surface (struct weston_surface *es) |
| 541 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 542 | return (es->committed == focus_surface_committed); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | static bool |
| 546 | is_focus_view (struct weston_view *view) |
| 547 | { |
| 548 | return is_focus_surface (view->surface); |
| 549 | } |
| 550 | |
| 551 | static struct focus_surface * |
| 552 | create_focus_surface(struct weston_compositor *ec, |
| 553 | struct weston_output *output) |
| 554 | { |
| 555 | struct focus_surface *fsurf = NULL; |
| 556 | struct weston_surface *surface = NULL; |
| 557 | |
| 558 | fsurf = malloc(sizeof *fsurf); |
| 559 | if (!fsurf) |
| 560 | return NULL; |
| 561 | |
| 562 | fsurf->surface = weston_surface_create(ec); |
| 563 | surface = fsurf->surface; |
| 564 | if (surface == NULL) { |
| 565 | free(fsurf); |
| 566 | return NULL; |
| 567 | } |
| 568 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 569 | surface->committed = focus_surface_committed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 570 | surface->output = output; |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 571 | surface->is_mapped = true; |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 572 | surface->committed_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 573 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 574 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 575 | fsurf->view = weston_view_create(surface); |
| 576 | if (fsurf->view == NULL) { |
| 577 | weston_surface_destroy(surface); |
| 578 | free(fsurf); |
| 579 | return NULL; |
| 580 | } |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 581 | fsurf->view->output = output; |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 582 | fsurf->view->is_mapped = true; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 583 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 584 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 585 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 586 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 587 | pixman_region32_fini(&surface->opaque); |
| 588 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 589 | output->width, output->height); |
| 590 | pixman_region32_fini(&surface->input); |
| 591 | pixman_region32_init(&surface->input); |
| 592 | |
| 593 | wl_list_init(&fsurf->workspace_transform.link); |
| 594 | |
| 595 | return fsurf; |
| 596 | } |
| 597 | |
| 598 | static void |
| 599 | focus_surface_destroy(struct focus_surface *fsurf) |
| 600 | { |
| 601 | weston_surface_destroy(fsurf->surface); |
| 602 | free(fsurf); |
| 603 | } |
| 604 | |
| 605 | static void |
| 606 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 607 | { |
| 608 | struct workspace *ws = data; |
| 609 | |
| 610 | ws->focus_animation = NULL; |
| 611 | } |
| 612 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 613 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 614 | focus_state_destroy(struct focus_state *state) |
| 615 | { |
| 616 | wl_list_remove(&state->seat_destroy_listener.link); |
| 617 | wl_list_remove(&state->surface_destroy_listener.link); |
| 618 | free(state); |
| 619 | } |
| 620 | |
| 621 | static void |
| 622 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 623 | { |
| 624 | struct focus_state *state = container_of(listener, |
| 625 | struct focus_state, |
| 626 | seat_destroy_listener); |
| 627 | |
| 628 | wl_list_remove(&state->link); |
| 629 | focus_state_destroy(state); |
| 630 | } |
| 631 | |
| 632 | static void |
| 633 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 634 | { |
| 635 | struct focus_state *state = container_of(listener, |
| 636 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 637 | surface_destroy_listener); |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 638 | struct weston_surface *main_surface; |
| 639 | struct weston_view *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 640 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 641 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 642 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 643 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 644 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 645 | wl_list_for_each(view, |
| 646 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 647 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 648 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 649 | if (is_focus_view(view)) |
| 650 | continue; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 651 | if (!get_shell_surface(view->surface)) |
| 652 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 653 | |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 654 | next = view; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 655 | break; |
| 656 | } |
| 657 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 658 | /* if the focus was a sub-surface, activate its main surface */ |
| 659 | if (main_surface != state->keyboard_focus) |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 660 | next = get_default_view(main_surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 661 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 662 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 663 | state->keyboard_focus = NULL; |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 664 | activate(state->shell, next, state->seat, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 665 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 666 | } else { |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 667 | if (state->shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 668 | if (state->ws->focus_animation) |
| 669 | weston_view_animation_destroy(state->ws->focus_animation); |
| 670 | |
| 671 | state->ws->focus_animation = weston_fade_run( |
| 672 | state->ws->fsurf_front->view, |
| 673 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 674 | focus_animation_done, state->ws); |
| 675 | } |
| 676 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 677 | wl_list_remove(&state->link); |
| 678 | focus_state_destroy(state); |
| 679 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | static struct focus_state * |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 683 | focus_state_create(struct desktop_shell *shell, struct weston_seat *seat, |
| 684 | struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 685 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 686 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 687 | |
| 688 | state = malloc(sizeof *state); |
| 689 | if (state == NULL) |
| 690 | return NULL; |
| 691 | |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 692 | state->shell = shell; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 693 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 694 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 695 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 696 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 697 | |
| 698 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 699 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 700 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 701 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 702 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 703 | |
| 704 | return state; |
| 705 | } |
| 706 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 707 | static struct focus_state * |
| 708 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 709 | { |
| 710 | struct workspace *ws = get_current_workspace(shell); |
| 711 | struct focus_state *state; |
| 712 | |
| 713 | wl_list_for_each(state, &ws->focus_list, link) |
| 714 | if (state->seat == seat) |
| 715 | break; |
| 716 | |
| 717 | if (&state->link == &ws->focus_list) |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 718 | state = focus_state_create(shell, seat, ws); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 719 | |
| 720 | return state; |
| 721 | } |
| 722 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 723 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 724 | focus_state_set_focus(struct focus_state *state, |
| 725 | struct weston_surface *surface) |
| 726 | { |
| 727 | if (state->keyboard_focus) { |
| 728 | wl_list_remove(&state->surface_destroy_listener.link); |
| 729 | wl_list_init(&state->surface_destroy_listener.link); |
| 730 | } |
| 731 | |
| 732 | state->keyboard_focus = surface; |
| 733 | if (surface) |
| 734 | wl_signal_add(&surface->destroy_signal, |
| 735 | &state->surface_destroy_listener); |
| 736 | } |
| 737 | |
| 738 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 739 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 740 | { |
| 741 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 742 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 743 | struct wl_list pending_seat_list; |
| 744 | struct weston_seat *seat, *next_seat; |
| 745 | |
| 746 | /* Temporarily steal the list of seats so that we can keep |
| 747 | * track of the seats we've already processed */ |
| 748 | wl_list_init(&pending_seat_list); |
| 749 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 750 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 751 | |
| 752 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 753 | struct weston_keyboard *keyboard = |
| 754 | weston_seat_get_keyboard(state->seat); |
| 755 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 756 | wl_list_remove(&state->seat->link); |
| 757 | wl_list_insert(&shell->compositor->seat_list, |
| 758 | &state->seat->link); |
| 759 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 760 | if (!keyboard) |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 761 | continue; |
| 762 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 763 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 764 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 765 | weston_keyboard_set_focus(keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 766 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 767 | |
| 768 | /* For any remaining seats that we don't have a focus state |
| 769 | * for we'll reset the keyboard focus to NULL */ |
| 770 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 771 | struct weston_keyboard *keyboard = |
| 772 | weston_seat_get_keyboard(seat); |
| 773 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 774 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 775 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 776 | if (!keyboard) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 777 | continue; |
| 778 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 779 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 780 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 784 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 785 | struct weston_seat *seat) |
| 786 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 787 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 788 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 789 | |
| 790 | wl_list_for_each(state, &ws->focus_list, link) { |
| 791 | if (state->seat == seat) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 792 | focus_state_set_focus(state, keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 793 | return; |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | static void |
| 799 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 800 | struct weston_surface *surface) |
| 801 | { |
| 802 | struct focus_state *state; |
| 803 | |
| 804 | wl_list_for_each(state, &ws->focus_list, link) |
| 805 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 806 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 810 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 811 | struct weston_view *from, struct weston_view *to) |
| 812 | { |
| 813 | struct weston_output *output; |
| 814 | bool focus_surface_created = false; |
| 815 | |
| 816 | /* FIXME: Only support dim animation using two layers */ |
| 817 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 818 | return; |
| 819 | |
| 820 | output = get_default_output(shell->compositor); |
| 821 | if (ws->fsurf_front == NULL && (from || to)) { |
| 822 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 823 | if (ws->fsurf_front == NULL) |
| 824 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 825 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 826 | |
| 827 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 828 | if (ws->fsurf_back == NULL) { |
| 829 | focus_surface_destroy(ws->fsurf_front); |
| 830 | return; |
| 831 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 832 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 833 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 834 | focus_surface_created = true; |
| 835 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 836 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 837 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | if (ws->focus_animation) { |
| 841 | weston_view_animation_destroy(ws->focus_animation); |
| 842 | ws->focus_animation = NULL; |
| 843 | } |
| 844 | |
| 845 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 846 | weston_layer_entry_insert(&to->layer_link, |
| 847 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 848 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 849 | weston_layer_entry_insert(&ws->layer.view_list, |
| 850 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 851 | |
| 852 | if (focus_surface_created) { |
| 853 | ws->focus_animation = weston_fade_run( |
| 854 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 855 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 856 | focus_animation_done, ws); |
| 857 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 858 | weston_layer_entry_insert(&from->layer_link, |
| 859 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 860 | ws->focus_animation = weston_stable_fade_run( |
| 861 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 862 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 863 | focus_animation_done, ws); |
| 864 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 865 | weston_layer_entry_insert(&ws->layer.view_list, |
| 866 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 867 | ws->focus_animation = weston_stable_fade_run( |
| 868 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 869 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 870 | focus_animation_done, ws); |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 875 | workspace_destroy(struct workspace *ws) |
| 876 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 877 | struct focus_state *state, *next; |
| 878 | |
| 879 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 880 | focus_state_destroy(state); |
| 881 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 882 | if (ws->fsurf_front) |
| 883 | focus_surface_destroy(ws->fsurf_front); |
| 884 | if (ws->fsurf_back) |
| 885 | focus_surface_destroy(ws->fsurf_back); |
| 886 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 887 | free(ws); |
| 888 | } |
| 889 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 890 | static void |
| 891 | seat_destroyed(struct wl_listener *listener, void *data) |
| 892 | { |
| 893 | struct weston_seat *seat = data; |
| 894 | struct focus_state *state, *next; |
| 895 | struct workspace *ws = container_of(listener, |
| 896 | struct workspace, |
| 897 | seat_destroyed_listener); |
| 898 | |
| 899 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 900 | if (state->seat == seat) |
| 901 | wl_list_remove(&state->link); |
| 902 | } |
| 903 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 904 | static struct workspace * |
| 905 | workspace_create(void) |
| 906 | { |
| 907 | struct workspace *ws = malloc(sizeof *ws); |
| 908 | if (ws == NULL) |
| 909 | return NULL; |
| 910 | |
| 911 | weston_layer_init(&ws->layer, NULL); |
| 912 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 913 | wl_list_init(&ws->focus_list); |
| 914 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 915 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 916 | ws->fsurf_front = NULL; |
| 917 | ws->fsurf_back = NULL; |
| 918 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 919 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 920 | return ws; |
| 921 | } |
| 922 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 923 | static int |
| 924 | workspace_is_empty(struct workspace *ws) |
| 925 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 926 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 927 | } |
| 928 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 929 | static struct workspace * |
| 930 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 931 | { |
| 932 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 933 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 934 | pws += index; |
| 935 | return *pws; |
| 936 | } |
| 937 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 938 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 939 | get_current_workspace(struct desktop_shell *shell) |
| 940 | { |
| 941 | return get_workspace(shell, shell->workspaces.current); |
| 942 | } |
| 943 | |
| 944 | static void |
| 945 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 946 | { |
| 947 | struct workspace *ws; |
| 948 | |
| 949 | ws = get_workspace(shell, index); |
| 950 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 951 | |
| 952 | shell->workspaces.current = index; |
| 953 | } |
| 954 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 955 | static unsigned int |
| 956 | get_output_height(struct weston_output *output) |
| 957 | { |
| 958 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 959 | } |
| 960 | |
| 961 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 962 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 963 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 964 | struct weston_transform *transform; |
| 965 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 966 | if (is_focus_view(view)) { |
| 967 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 968 | transform = &fsurf->workspace_transform; |
| 969 | } else { |
| 970 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 971 | transform = &shsurf->workspace_transform; |
| 972 | } |
| 973 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 974 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 975 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 976 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 977 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 978 | weston_matrix_init(&transform->matrix); |
| 979 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 980 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 981 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | static void |
| 985 | workspace_translate_out(struct workspace *ws, double fraction) |
| 986 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 987 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 988 | unsigned int height; |
| 989 | double d; |
| 990 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 991 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 992 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 993 | d = height * fraction; |
| 994 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 995 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 996 | } |
| 997 | } |
| 998 | |
| 999 | static void |
| 1000 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1001 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1002 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1003 | unsigned int height; |
| 1004 | double d; |
| 1005 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1006 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1007 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1008 | |
| 1009 | if (fraction > 0) |
| 1010 | d = -(height - height * fraction); |
| 1011 | else |
| 1012 | d = height + height * fraction; |
| 1013 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1014 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1019 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1020 | unsigned int index, |
| 1021 | struct workspace *from, |
| 1022 | struct workspace *to) |
| 1023 | { |
| 1024 | shell->workspaces.current = index; |
| 1025 | |
| 1026 | shell->workspaces.anim_to = to; |
| 1027 | shell->workspaces.anim_from = from; |
| 1028 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1029 | shell->workspaces.anim_timestamp = 0; |
| 1030 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1031 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | static void |
| 1035 | workspace_deactivate_transforms(struct workspace *ws) |
| 1036 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1037 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1038 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1039 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1040 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1041 | if (is_focus_view(view)) { |
| 1042 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1043 | transform = &fsurf->workspace_transform; |
| 1044 | } else { |
| 1045 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1046 | transform = &shsurf->workspace_transform; |
| 1047 | } |
| 1048 | |
| 1049 | if (!wl_list_empty(&transform->link)) { |
| 1050 | wl_list_remove(&transform->link); |
| 1051 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1052 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1053 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | static void |
| 1058 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1059 | struct workspace *from, |
| 1060 | struct workspace *to) |
| 1061 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1062 | struct weston_view *view; |
| 1063 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1064 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1065 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1066 | /* Views that extend past the bottom of the output are still |
| 1067 | * visible after the workspace animation ends but before its layer |
| 1068 | * is hidden. In that case, we need to damage below those views so |
| 1069 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1070 | wl_list_for_each(view, &from->layer.view_list.link, layer_link.link) |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1071 | weston_view_damage_below(view); |
| 1072 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1073 | wl_list_remove(&shell->workspaces.animation.link); |
| 1074 | workspace_deactivate_transforms(from); |
| 1075 | workspace_deactivate_transforms(to); |
| 1076 | shell->workspaces.anim_to = NULL; |
| 1077 | |
| 1078 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1079 | } |
| 1080 | |
| 1081 | static void |
| 1082 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1083 | struct weston_output *output, uint32_t msecs) |
| 1084 | { |
| 1085 | struct desktop_shell *shell = |
| 1086 | container_of(animation, struct desktop_shell, |
| 1087 | workspaces.animation); |
| 1088 | struct workspace *from = shell->workspaces.anim_from; |
| 1089 | struct workspace *to = shell->workspaces.anim_to; |
| 1090 | uint32_t t; |
| 1091 | double x, y; |
| 1092 | |
| 1093 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1094 | finish_workspace_change_animation(shell, from, to); |
| 1095 | return; |
| 1096 | } |
| 1097 | |
| 1098 | if (shell->workspaces.anim_timestamp == 0) { |
| 1099 | if (shell->workspaces.anim_current == 0.0) |
| 1100 | shell->workspaces.anim_timestamp = msecs; |
| 1101 | else |
| 1102 | shell->workspaces.anim_timestamp = |
| 1103 | msecs - |
| 1104 | /* Invers of movement function 'y' below. */ |
| 1105 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1106 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1107 | M_2_PI); |
| 1108 | } |
| 1109 | |
| 1110 | t = msecs - shell->workspaces.anim_timestamp; |
| 1111 | |
| 1112 | /* |
| 1113 | * x = [0, π/2] |
| 1114 | * y(x) = sin(x) |
| 1115 | */ |
| 1116 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1117 | y = sin(x); |
| 1118 | |
| 1119 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1120 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1121 | |
| 1122 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1123 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1124 | shell->workspaces.anim_current = y; |
| 1125 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1126 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1127 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1128 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1129 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | static void |
| 1133 | animate_workspace_change(struct desktop_shell *shell, |
| 1134 | unsigned int index, |
| 1135 | struct workspace *from, |
| 1136 | struct workspace *to) |
| 1137 | { |
| 1138 | struct weston_output *output; |
| 1139 | |
| 1140 | int dir; |
| 1141 | |
| 1142 | if (index > shell->workspaces.current) |
| 1143 | dir = -1; |
| 1144 | else |
| 1145 | dir = 1; |
| 1146 | |
| 1147 | shell->workspaces.current = index; |
| 1148 | |
| 1149 | shell->workspaces.anim_dir = dir; |
| 1150 | shell->workspaces.anim_from = from; |
| 1151 | shell->workspaces.anim_to = to; |
| 1152 | shell->workspaces.anim_current = 0.0; |
| 1153 | shell->workspaces.anim_timestamp = 0; |
| 1154 | |
| 1155 | output = container_of(shell->compositor->output_list.next, |
| 1156 | struct weston_output, link); |
| 1157 | wl_list_insert(&output->animation_list, |
| 1158 | &shell->workspaces.animation.link); |
| 1159 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1160 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1161 | |
| 1162 | workspace_translate_in(to, 0); |
| 1163 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1164 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1165 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1166 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1167 | } |
| 1168 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1169 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1170 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1171 | struct workspace *from, struct workspace *to) |
| 1172 | { |
| 1173 | shell->workspaces.current = index; |
| 1174 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1175 | wl_list_remove(&from->layer.link); |
| 1176 | } |
| 1177 | |
| 1178 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1179 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1180 | { |
| 1181 | struct workspace *from; |
| 1182 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1183 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1184 | |
| 1185 | if (index == shell->workspaces.current) |
| 1186 | return; |
| 1187 | |
| 1188 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1189 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1190 | return; |
| 1191 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1192 | from = get_current_workspace(shell); |
| 1193 | to = get_workspace(shell, index); |
| 1194 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1195 | if (shell->workspaces.anim_from == to && |
| 1196 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1197 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1198 | reverse_workspace_change_animation(shell, index, from, to); |
| 1199 | return; |
| 1200 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1201 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1202 | if (shell->workspaces.anim_to != NULL) |
| 1203 | finish_workspace_change_animation(shell, |
| 1204 | shell->workspaces.anim_from, |
| 1205 | shell->workspaces.anim_to); |
| 1206 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1207 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1208 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1209 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1210 | wl_list_for_each(state, &from->focus_list, link) |
| 1211 | if (state->keyboard_focus) |
| 1212 | animate_focus_change(shell, from, |
| 1213 | get_default_view(state->keyboard_focus), NULL); |
| 1214 | |
| 1215 | wl_list_for_each(state, &to->focus_list, link) |
| 1216 | if (state->keyboard_focus) |
| 1217 | animate_focus_change(shell, to, |
| 1218 | NULL, get_default_view(state->keyboard_focus)); |
| 1219 | } |
| 1220 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1221 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1222 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1223 | else |
| 1224 | animate_workspace_change(shell, index, from, to); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1225 | } |
| 1226 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1227 | static bool |
| 1228 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1229 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1230 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1231 | struct wl_list *e; |
| 1232 | |
| 1233 | if (wl_list_empty(list)) |
| 1234 | return false; |
| 1235 | |
| 1236 | e = list->next; |
| 1237 | |
| 1238 | if (e->next != list) |
| 1239 | return false; |
| 1240 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1241 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | static void |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 1245 | surface_keyboard_focus_lost(struct weston_surface *surface) |
| 1246 | { |
| 1247 | struct weston_compositor *compositor = surface->compositor; |
| 1248 | struct weston_seat *seat; |
| 1249 | struct weston_surface *focus; |
| 1250 | |
| 1251 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 1252 | struct weston_keyboard *keyboard = |
| 1253 | weston_seat_get_keyboard(seat); |
| 1254 | |
| 1255 | if (!keyboard) |
| 1256 | continue; |
| 1257 | |
| 1258 | focus = weston_surface_get_main_surface(keyboard->focus); |
| 1259 | if (focus == surface) |
| 1260 | weston_keyboard_set_focus(keyboard, NULL); |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1265 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1266 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1267 | unsigned int index) |
| 1268 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1269 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1270 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1271 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1272 | struct shell_surface *shsurf; |
| 1273 | struct workspace *from; |
| 1274 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1275 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1276 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1277 | surface = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1278 | view = get_default_view(surface); |
| 1279 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1280 | index == shell->workspaces.current || |
| 1281 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1282 | return; |
| 1283 | |
| 1284 | from = get_current_workspace(shell); |
| 1285 | to = get_workspace(shell, index); |
| 1286 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1287 | weston_layer_entry_remove(&view->layer_link); |
| 1288 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1289 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1290 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1291 | if (shsurf != NULL) |
| 1292 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1293 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1294 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1295 | drop_focus_state(shell, from, surface); |
| 1296 | |
| 1297 | if (shell->workspaces.anim_from == to && |
| 1298 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1299 | wl_list_remove(&to->layer.link); |
| 1300 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1301 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1302 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1303 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1304 | return; |
| 1305 | } |
| 1306 | |
| 1307 | if (shell->workspaces.anim_to != NULL) |
| 1308 | finish_workspace_change_animation(shell, |
| 1309 | shell->workspaces.anim_from, |
| 1310 | shell->workspaces.anim_to); |
| 1311 | |
| 1312 | if (workspace_is_empty(from) && |
| 1313 | workspace_has_only(to, surface)) |
| 1314 | update_workspace(shell, index, from, to); |
| 1315 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1316 | if (shsurf != NULL && |
| 1317 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1318 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1319 | &shsurf->workspace_transform.link); |
| 1320 | |
| 1321 | animate_workspace_change(shell, index, from, to); |
| 1322 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1323 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1324 | state = ensure_focus_state(shell, seat); |
| 1325 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1326 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1330 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1331 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1332 | { |
| 1333 | } |
| 1334 | |
| 1335 | static void |
| 1336 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1337 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1338 | struct weston_touch_move_grab *move = |
| 1339 | (struct weston_touch_move_grab *) container_of( |
| 1340 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1341 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1342 | if (touch_id == 0) |
| 1343 | move->active = 0; |
| 1344 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1345 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1346 | shell_touch_grab_end(&move->base); |
| 1347 | free(move); |
| 1348 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | static void |
| 1352 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1353 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1354 | { |
| 1355 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1356 | struct shell_surface *shsurf = move->base.shsurf; |
| 1357 | struct weston_surface *es; |
| 1358 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1359 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1360 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1361 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1362 | return; |
| 1363 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1364 | es = weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1365 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1366 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1367 | |
| 1368 | weston_compositor_schedule_repaint(es->compositor); |
| 1369 | } |
| 1370 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1371 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1372 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1373 | { |
| 1374 | } |
| 1375 | |
| 1376 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1377 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1378 | { |
| 1379 | struct weston_touch_move_grab *move = |
| 1380 | (struct weston_touch_move_grab *) container_of( |
| 1381 | grab, struct shell_touch_grab, grab); |
| 1382 | |
| 1383 | shell_touch_grab_end(&move->base); |
| 1384 | free(move); |
| 1385 | } |
| 1386 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1387 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1388 | touch_move_grab_down, |
| 1389 | touch_move_grab_up, |
| 1390 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1391 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1392 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1393 | }; |
| 1394 | |
| 1395 | static int |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1396 | surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1397 | { |
| 1398 | struct weston_touch_move_grab *move; |
| 1399 | |
| 1400 | if (!shsurf) |
| 1401 | return -1; |
| 1402 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1403 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1404 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1405 | return 0; |
| 1406 | |
| 1407 | move = malloc(sizeof *move); |
| 1408 | if (!move) |
| 1409 | return -1; |
| 1410 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1411 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1412 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1413 | touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1414 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1415 | touch->grab_y; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1416 | |
| 1417 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1418 | touch); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1419 | |
| 1420 | return 0; |
| 1421 | } |
| 1422 | |
| 1423 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1424 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1425 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | static void |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1429 | noop_grab_axis(struct weston_pointer_grab *grab, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1430 | uint32_t time, struct weston_pointer_axis_event *event) |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1431 | { |
| 1432 | } |
| 1433 | |
| 1434 | static void |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1435 | noop_grab_axis_source(struct weston_pointer_grab *grab, |
| 1436 | uint32_t source) |
| 1437 | { |
| 1438 | } |
| 1439 | |
| 1440 | static void |
| 1441 | noop_grab_frame(struct weston_pointer_grab *grab) |
| 1442 | { |
| 1443 | } |
| 1444 | |
| 1445 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1446 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1447 | { |
| 1448 | struct shell_surface *shsurf = move->base.shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1449 | struct weston_surface *surface = |
| 1450 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1451 | struct weston_pointer *pointer = move->base.grab.pointer; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1452 | int x, y, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1453 | const int safety = 50; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1454 | pixman_rectangle32_t area; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1455 | struct weston_geometry geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1456 | |
| 1457 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1458 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1459 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1460 | if (shsurf->shell->panel_position == |
| 1461 | WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1462 | get_output_work_area(shsurf->shell, surface->output, &area); |
| 1463 | geometry = |
| 1464 | weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1465 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1466 | bottom = y + geometry.height + geometry.y; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1467 | if (bottom - safety < area.y) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1468 | y = area.y + safety - geometry.height |
| 1469 | - geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1470 | |
| 1471 | if (move->client_initiated && |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1472 | y + geometry.y < area.y) |
| 1473 | y = area.y - geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1474 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1475 | |
| 1476 | *cx = x; |
| 1477 | *cy = y; |
| 1478 | } |
| 1479 | |
| 1480 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1481 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1482 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1483 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1484 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1485 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1486 | struct shell_surface *shsurf = move->base.shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1487 | struct weston_surface *surface; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1488 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1489 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1490 | weston_pointer_move(pointer, event); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1491 | if (!shsurf) |
| 1492 | return; |
| 1493 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1494 | surface = weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 1495 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1496 | constrain_position(move, &cx, &cy); |
| 1497 | |
| 1498 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1499 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1500 | weston_compositor_schedule_repaint(surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1504 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1505 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1506 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1507 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1508 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1509 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1510 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1511 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1512 | if (pointer->button_count == 0 && |
| 1513 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1514 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1515 | free(grab); |
| 1516 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1517 | } |
| 1518 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1519 | static void |
| 1520 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1521 | { |
| 1522 | struct shell_grab *shell_grab = |
| 1523 | container_of(grab, struct shell_grab, grab); |
| 1524 | |
| 1525 | shell_grab_end(shell_grab); |
| 1526 | free(grab); |
| 1527 | } |
| 1528 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1529 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1530 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1531 | move_grab_motion, |
| 1532 | move_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1533 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1534 | noop_grab_axis_source, |
| 1535 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1536 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1537 | }; |
| 1538 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1539 | static int |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1540 | surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 1541 | bool client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1542 | { |
| 1543 | struct weston_move_grab *move; |
| 1544 | |
| 1545 | if (!shsurf) |
| 1546 | return -1; |
| 1547 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1548 | if (shsurf->grabbed || |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1549 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1550 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1551 | return 0; |
| 1552 | |
| 1553 | move = malloc(sizeof *move); |
| 1554 | if (!move) |
| 1555 | return -1; |
| 1556 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1557 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1558 | pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1559 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1560 | pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1561 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1562 | |
| 1563 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1564 | pointer, WESTON_DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1565 | |
| 1566 | return 0; |
| 1567 | } |
| 1568 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1569 | struct weston_resize_grab { |
| 1570 | struct shell_grab base; |
| 1571 | uint32_t edges; |
| 1572 | int32_t width, height; |
| 1573 | }; |
| 1574 | |
| 1575 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1576 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1577 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1578 | { |
| 1579 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1580 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1581 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1582 | int32_t width, height; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1583 | struct weston_size min_size, max_size; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1584 | wl_fixed_t from_x, from_y; |
| 1585 | wl_fixed_t to_x, to_y; |
| 1586 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1587 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1588 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1589 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1590 | return; |
| 1591 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1592 | weston_view_from_global_fixed(shsurf->view, |
| 1593 | pointer->grab_x, pointer->grab_y, |
| 1594 | &from_x, &from_y); |
| 1595 | weston_view_from_global_fixed(shsurf->view, |
| 1596 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1597 | |
| 1598 | width = resize->width; |
| 1599 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1600 | width += wl_fixed_to_int(from_x - to_x); |
| 1601 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1602 | width += wl_fixed_to_int(to_x - from_x); |
| 1603 | } |
| 1604 | |
| 1605 | height = resize->height; |
| 1606 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1607 | height += wl_fixed_to_int(from_y - to_y); |
| 1608 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1609 | height += wl_fixed_to_int(to_y - from_y); |
| 1610 | } |
| 1611 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1612 | max_size = weston_desktop_surface_get_max_size(shsurf->desktop_surface); |
| 1613 | min_size = weston_desktop_surface_get_min_size(shsurf->desktop_surface); |
| 1614 | |
| 1615 | min_size.width = MAX(1, min_size.width); |
| 1616 | min_size.height = MAX(1, min_size.height); |
| 1617 | |
| 1618 | if (width < min_size.width) |
| 1619 | width = min_size.width; |
| 1620 | else if (max_size.width > 0 && width > max_size.width) |
| 1621 | width = max_size.width; |
| 1622 | if (height < min_size.height) |
| 1623 | height = min_size.height; |
| 1624 | else if (max_size.width > 0 && width > max_size.width) |
| 1625 | width = max_size.width; |
| 1626 | weston_desktop_surface_set_size(shsurf->desktop_surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1630 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1631 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1632 | { |
| 1633 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1634 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1635 | enum wl_pointer_button_state state = state_w; |
| 1636 | |
| 1637 | if (pointer->button_count == 0 && |
| 1638 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1639 | shell_grab_end(&resize->base); |
| 1640 | free(grab); |
| 1641 | } |
| 1642 | } |
| 1643 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1644 | static void |
| 1645 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1646 | { |
| 1647 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1648 | |
| 1649 | shell_grab_end(&resize->base); |
| 1650 | free(grab); |
| 1651 | } |
| 1652 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1653 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1654 | noop_grab_focus, |
| 1655 | resize_grab_motion, |
| 1656 | resize_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1657 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1658 | noop_grab_axis_source, |
| 1659 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1660 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1661 | }; |
| 1662 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1663 | /* |
| 1664 | * Returns the bounding box of a surface and all its sub-surfaces, |
Yong Bakos | bbb783a | 2016-04-28 11:59:06 -0500 | [diff] [blame] | 1665 | * in surface-local coordinates. */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1666 | static void |
| 1667 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1668 | int32_t *y, int32_t *w, int32_t *h) { |
| 1669 | pixman_region32_t region; |
| 1670 | pixman_box32_t *box; |
| 1671 | struct weston_subsurface *subsurface; |
| 1672 | |
| 1673 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1674 | surface->width, |
| 1675 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1676 | |
| 1677 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1678 | pixman_region32_union_rect(®ion, ®ion, |
| 1679 | subsurface->position.x, |
| 1680 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1681 | subsurface->surface->width, |
| 1682 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | box = pixman_region32_extents(®ion); |
| 1686 | if (x) |
| 1687 | *x = box->x1; |
| 1688 | if (y) |
| 1689 | *y = box->y1; |
| 1690 | if (w) |
| 1691 | *w = box->x2 - box->x1; |
| 1692 | if (h) |
| 1693 | *h = box->y2 - box->y1; |
| 1694 | |
| 1695 | pixman_region32_fini(®ion); |
| 1696 | } |
| 1697 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1698 | static int |
| 1699 | surface_resize(struct shell_surface *shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1700 | struct weston_pointer *pointer, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1701 | { |
| 1702 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1703 | const unsigned resize_topbottom = |
| 1704 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1705 | const unsigned resize_leftright = |
| 1706 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1707 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1708 | struct weston_geometry geometry; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1709 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1710 | if (shsurf->grabbed || |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1711 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1712 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1713 | return 0; |
| 1714 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1715 | /* Check for invalid edge combinations. */ |
| 1716 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1717 | (edges & resize_topbottom) == resize_topbottom || |
| 1718 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1719 | return 0; |
| 1720 | |
| 1721 | resize = malloc(sizeof *resize); |
| 1722 | if (!resize) |
| 1723 | return -1; |
| 1724 | |
| 1725 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1726 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1727 | geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
| 1728 | resize->width = geometry.width; |
| 1729 | resize->height = geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1730 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1731 | shsurf->resize_edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1732 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1733 | pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1734 | |
| 1735 | return 0; |
| 1736 | } |
| 1737 | |
| 1738 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1739 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1740 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1741 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1742 | struct weston_pointer *pointer = base->pointer; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1743 | struct weston_desktop_surface *desktop_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1744 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1745 | wl_fixed_t sx, sy; |
| 1746 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1747 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1748 | pointer->x, pointer->y, |
| 1749 | &sx, &sy); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1750 | desktop_surface = weston_surface_get_desktop_surface(view->surface); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1751 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1752 | if (!grab->shsurf || grab->shsurf->desktop_surface != desktop_surface) { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1753 | shell_grab_end(grab); |
| 1754 | free(grab); |
| 1755 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1759 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1760 | struct weston_pointer_motion_event *event) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1761 | { |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1762 | weston_pointer_move(grab->pointer, event); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1763 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1764 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1765 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1766 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1767 | uint32_t time, uint32_t button, uint32_t state) |
| 1768 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1769 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1770 | struct shell_surface *shsurf = grab->shsurf; |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1771 | struct weston_pointer *pointer = grab->grab.pointer; |
| 1772 | struct weston_seat *seat = pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1773 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1774 | if (shsurf && button == BTN_LEFT && state) { |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 1775 | activate(shsurf->shell, shsurf->view, seat, |
| 1776 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1777 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1778 | } else if (shsurf && button == BTN_RIGHT && state) { |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 1779 | activate(shsurf->shell, shsurf->view, seat, |
| 1780 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 1781 | surface_rotate(shsurf, pointer); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1782 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1783 | } |
| 1784 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1785 | static void |
| 1786 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1787 | { |
| 1788 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1789 | |
| 1790 | shell_grab_end(grab); |
| 1791 | free(grab); |
| 1792 | } |
| 1793 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1794 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1795 | busy_cursor_grab_focus, |
| 1796 | busy_cursor_grab_motion, |
| 1797 | busy_cursor_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1798 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1799 | noop_grab_axis_source, |
| 1800 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1801 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1802 | }; |
| 1803 | |
| 1804 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1805 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1806 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1807 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1808 | struct weston_view *view = pointer->focus; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1809 | struct shell_surface *shsurf; |
| 1810 | struct weston_desktop_client *client; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1811 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1812 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1813 | return; |
| 1814 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1815 | shsurf = get_shell_surface(view->surface); |
| 1816 | if (!shsurf) |
| 1817 | return; |
| 1818 | |
| 1819 | client = weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 1820 | |
| 1821 | if (shsurf->unresponsive) |
| 1822 | set_busy_cursor(shsurf, pointer); |
| 1823 | else |
| 1824 | weston_desktop_client_ping(client); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1828 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 1829 | { |
| 1830 | if (--shsurf->focus_count == 0) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1831 | weston_desktop_surface_set_activated(shsurf->desktop_surface, false); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | static void |
| 1835 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 1836 | { |
| 1837 | if (shsurf->focus_count++ == 0) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1838 | weston_desktop_surface_set_activated(shsurf->desktop_surface, true); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | static void |
| 1842 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 1843 | { |
| 1844 | struct weston_keyboard *keyboard = data; |
| 1845 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 1846 | |
| 1847 | if (seat->focused_surface) { |
| 1848 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 1849 | if (shsurf) |
| 1850 | shell_surface_lose_keyboard_focus(shsurf); |
| 1851 | } |
| 1852 | |
| 1853 | seat->focused_surface = keyboard->focus; |
| 1854 | |
| 1855 | if (seat->focused_surface) { |
| 1856 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 1857 | if (shsurf) |
| 1858 | shell_surface_gain_keyboard_focus(shsurf); |
| 1859 | } |
| 1860 | } |
| 1861 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1862 | /* The surface will be inserted into the list immediately after the link |
| 1863 | * returned by this function (i.e. will be stacked immediately above the |
| 1864 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1865 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1866 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 1867 | { |
| 1868 | struct workspace *ws; |
| 1869 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1870 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) && |
| 1871 | !shsurf->state.lowered) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 1872 | return &shsurf->shell->fullscreen_layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1875 | /* Move the surface to a normal workspace layer so that surfaces |
| 1876 | * which were previously fullscreen or transient are no longer |
| 1877 | * rendered on top. */ |
| 1878 | ws = get_current_workspace(shsurf->shell); |
| 1879 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1880 | } |
| 1881 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1882 | static void |
| 1883 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 1884 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1885 | weston_desktop_surface_propagate_layer(shsurf->desktop_surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1888 | /* 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] | 1889 | * geometry to ensure the changes are redrawn. |
| 1890 | * |
| 1891 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 1892 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1893 | static void |
| 1894 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 1895 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1896 | struct weston_surface *surface = |
| 1897 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1898 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1899 | |
| 1900 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 1901 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 1902 | if (new_layer_link == NULL) |
| 1903 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1904 | if (new_layer_link == &shsurf->view->layer_link) |
| 1905 | return; |
| 1906 | |
| 1907 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1908 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 1909 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1910 | weston_view_geometry_dirty(shsurf->view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1911 | weston_surface_damage(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1912 | |
| 1913 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1914 | } |
| 1915 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1916 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1917 | shell_surface_set_output(struct shell_surface *shsurf, |
| 1918 | struct weston_output *output) |
| 1919 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1920 | struct weston_surface *es = |
| 1921 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1922 | |
| 1923 | /* get the default output, if the client set it as NULL |
| 1924 | check whether the ouput is available */ |
| 1925 | if (output) |
| 1926 | shsurf->output = output; |
| 1927 | else if (es->output) |
| 1928 | shsurf->output = es->output; |
| 1929 | else |
| 1930 | shsurf->output = get_default_output(es->compositor); |
| 1931 | } |
| 1932 | |
| 1933 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 1934 | weston_view_set_initial_position(struct weston_view *view, |
| 1935 | struct desktop_shell *shell); |
| 1936 | |
| 1937 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1938 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1939 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 1940 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1941 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 1942 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 1943 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1944 | if (shsurf->fullscreen.black_view) |
| 1945 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 1946 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 1947 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 1948 | if (shsurf->saved_position_valid) |
| 1949 | weston_view_set_position(shsurf->view, |
| 1950 | shsurf->saved_x, shsurf->saved_y); |
| 1951 | else |
| 1952 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
| 1953 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 1954 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1955 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1956 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 1957 | shsurf->saved_rotation_valid = false; |
| 1958 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 1959 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1960 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1961 | } |
| 1962 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 1963 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1964 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 1965 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1966 | struct weston_surface *surface = |
| 1967 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 1968 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 1969 | /* undo all maximized things here */ |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1970 | shsurf->output = get_default_output(surface->compositor); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 1971 | |
| 1972 | if (shsurf->saved_position_valid) |
| 1973 | weston_view_set_position(shsurf->view, |
| 1974 | shsurf->saved_x, shsurf->saved_y); |
| 1975 | else |
| 1976 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 1977 | |
| 1978 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1979 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 1980 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 1981 | shsurf->saved_rotation_valid = false; |
| 1982 | } |
| 1983 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1984 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 1985 | } |
| 1986 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1987 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 1988 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 1989 | { |
| 1990 | struct shell_surface *shsurf; |
| 1991 | struct workspace *current_ws; |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 1992 | struct weston_view *view; |
| 1993 | |
| 1994 | view = get_default_view(surface); |
| 1995 | if (!view) |
| 1996 | return; |
| 1997 | |
| 1998 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1999 | |
| 2000 | shsurf = get_shell_surface(surface); |
| 2001 | current_ws = get_current_workspace(shsurf->shell); |
| 2002 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2003 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2004 | weston_layer_entry_insert(&shsurf->shell->minimized_layer.view_list, &view->layer_link); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2005 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2006 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 2007 | surface_keyboard_focus_lost(surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2008 | |
| 2009 | shell_surface_update_child_surface_layers(shsurf); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2010 | weston_view_damage_below(view); |
| 2011 | } |
| 2012 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2013 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2014 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2015 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2016 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2017 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2018 | } |
| 2019 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2020 | static int |
| 2021 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2022 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2023 | struct weston_view *fs_view = surface->committed_private; |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2024 | struct weston_surface *fs_surface = fs_view->surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2025 | int n; |
| 2026 | int rem; |
| 2027 | int ret; |
| 2028 | |
| 2029 | n = snprintf(buf, len, "black background surface for "); |
| 2030 | if (n < 0) |
| 2031 | return n; |
| 2032 | |
| 2033 | rem = (int)len - n; |
| 2034 | if (rem < 0) |
| 2035 | rem = 0; |
| 2036 | |
| 2037 | if (fs_surface->get_label) |
| 2038 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2039 | else |
| 2040 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2041 | |
| 2042 | if (ret < 0) |
| 2043 | return n; |
| 2044 | |
| 2045 | return n + ret; |
| 2046 | } |
| 2047 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2048 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2049 | black_surface_committed(struct weston_surface *es, int32_t sx, int32_t sy); |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2050 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2051 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2052 | create_black_surface(struct weston_compositor *ec, |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2053 | struct weston_view *fs_view, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2054 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2055 | { |
| 2056 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2057 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2058 | |
| 2059 | surface = weston_surface_create(ec); |
| 2060 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2061 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2062 | return NULL; |
| 2063 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2064 | view = weston_view_create(surface); |
| 2065 | if (surface == NULL) { |
| 2066 | weston_log("no memory\n"); |
| 2067 | weston_surface_destroy(surface); |
| 2068 | return NULL; |
| 2069 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2070 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2071 | surface->committed = black_surface_committed; |
| 2072 | surface->committed_private = fs_view; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2073 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2074 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2075 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2076 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2077 | pixman_region32_fini(&surface->input); |
| 2078 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2079 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2080 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2081 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2082 | |
| 2083 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2084 | } |
| 2085 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2086 | static void |
| 2087 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2088 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2089 | struct weston_surface *surface = |
| 2090 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2091 | struct weston_output *output = shsurf->fullscreen_output; |
| 2092 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2093 | assert(weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2094 | |
| 2095 | if (!shsurf->fullscreen.black_view) |
| 2096 | shsurf->fullscreen.black_view = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2097 | create_black_surface(surface->compositor, |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2098 | shsurf->view, |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2099 | output->x, output->y, |
| 2100 | output->width, |
| 2101 | output->height); |
| 2102 | |
| 2103 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2104 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2105 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2106 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2107 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2108 | weston_surface_damage(surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2109 | |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 2110 | shsurf->fullscreen.black_view->is_mapped = true; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2111 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2112 | } |
| 2113 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2114 | /* Create black surface and append it to the associated fullscreen surface. |
| 2115 | * Handle size dismatch and positioning according to the method. */ |
| 2116 | static void |
| 2117 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2118 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2119 | struct weston_surface *surface = |
| 2120 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2121 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2122 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2123 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2124 | weston_layer_entry_remove(&shsurf->view->layer_link); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2125 | weston_layer_entry_insert(&shsurf->shell->fullscreen_layer.view_list, |
| 2126 | &shsurf->view->layer_link); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2127 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2128 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2129 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2130 | surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2131 | &surf_width, &surf_height); |
| 2132 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2133 | if (surface->buffer_ref.buffer) |
| 2134 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2135 | } |
| 2136 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2137 | static void |
| 2138 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2139 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2140 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2141 | } |
| 2142 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2143 | static struct weston_output * |
| 2144 | get_focused_output(struct weston_compositor *compositor) |
| 2145 | { |
| 2146 | struct weston_seat *seat; |
| 2147 | struct weston_output *output = NULL; |
| 2148 | |
| 2149 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2150 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2151 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2152 | struct weston_keyboard *keyboard = |
| 2153 | weston_seat_get_keyboard(seat); |
| 2154 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2155 | /* Priority has touch focus, then pointer and |
| 2156 | * then keyboard focus. We should probably have |
| 2157 | * three for loops and check frist for touch, |
| 2158 | * then for pointer, etc. but unless somebody has some |
| 2159 | * objections, I think this is sufficient. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2160 | if (touch && touch->focus) |
| 2161 | output = touch->focus->output; |
| 2162 | else if (pointer && pointer->focus) |
| 2163 | output = pointer->focus->output; |
| 2164 | else if (keyboard && keyboard->focus) |
| 2165 | output = keyboard->focus->output; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2166 | |
| 2167 | if (output) |
| 2168 | break; |
| 2169 | } |
| 2170 | |
| 2171 | return output; |
| 2172 | } |
| 2173 | |
| 2174 | static void |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2175 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2176 | { |
| 2177 | struct shell_seat *shseat = |
| 2178 | container_of(listener, |
| 2179 | struct shell_seat, seat_destroy_listener); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2180 | |
| 2181 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2182 | free(shseat); |
| 2183 | } |
| 2184 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2185 | static void |
| 2186 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 2187 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2188 | struct weston_keyboard *keyboard; |
| 2189 | struct weston_pointer *pointer; |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2190 | struct shell_seat *seat; |
| 2191 | |
| 2192 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2193 | keyboard = weston_seat_get_keyboard(seat->seat); |
| 2194 | pointer = weston_seat_get_pointer(seat->seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2195 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2196 | if (keyboard && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2197 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2198 | wl_signal_add(&keyboard->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2199 | &seat->keyboard_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2200 | } else if (!keyboard) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 2201 | wl_list_remove(&seat->keyboard_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2202 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 2203 | } |
| 2204 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2205 | if (pointer && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2206 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2207 | wl_signal_add(&pointer->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2208 | &seat->pointer_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2209 | } else if (!pointer) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 2210 | wl_list_remove(&seat->pointer_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2211 | wl_list_init(&seat->pointer_focus_listener.link); |
| 2212 | } |
| 2213 | } |
| 2214 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2215 | static struct shell_seat * |
| 2216 | create_shell_seat(struct weston_seat *seat) |
| 2217 | { |
| 2218 | struct shell_seat *shseat; |
| 2219 | |
| 2220 | shseat = calloc(1, sizeof *shseat); |
| 2221 | if (!shseat) { |
| 2222 | weston_log("no memory to allocate shell seat\n"); |
| 2223 | return NULL; |
| 2224 | } |
| 2225 | |
| 2226 | shseat->seat = seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2227 | |
| 2228 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2229 | wl_signal_add(&seat->destroy_signal, |
| 2230 | &shseat->seat_destroy_listener); |
| 2231 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2232 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 2233 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 2234 | |
| 2235 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 2236 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 2237 | |
| 2238 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 2239 | wl_signal_add(&seat->updated_caps_signal, |
| 2240 | &shseat->caps_changed_listener); |
| 2241 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 2242 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2243 | return shseat; |
| 2244 | } |
| 2245 | |
| 2246 | static struct shell_seat * |
| 2247 | get_shell_seat(struct weston_seat *seat) |
| 2248 | { |
| 2249 | struct wl_listener *listener; |
| 2250 | |
| 2251 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2252 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2253 | |
| 2254 | return container_of(listener, |
| 2255 | struct shell_seat, seat_destroy_listener); |
| 2256 | } |
| 2257 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2258 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2259 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 2260 | { |
| 2261 | struct shell_surface *shsurf = data; |
| 2262 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2263 | weston_surface_destroy(shsurf->view->surface); |
| 2264 | free(shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2268 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 2269 | { |
| 2270 | struct shell_surface *shsurf = data; |
| 2271 | struct wl_event_loop *loop; |
| 2272 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2273 | loop = wl_display_get_event_loop(shsurf->shell->compositor->wl_display); |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2274 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2275 | if (weston_view_is_mapped(shsurf->view)) { |
| 2276 | shsurf->view->is_mapped = false; |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2277 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2278 | } |
| 2279 | } |
| 2280 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 2281 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2282 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2283 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2284 | if (weston_surface_is_desktop_surface(surface)) { |
| 2285 | struct weston_desktop_surface *desktop_surface = |
| 2286 | weston_surface_get_desktop_surface(surface); |
| 2287 | return weston_desktop_surface_get_user_data(desktop_surface); |
| 2288 | } |
| 2289 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2290 | } |
| 2291 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2292 | /* |
| 2293 | * libweston-desktop |
| 2294 | */ |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2295 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2296 | static void |
| 2297 | desktop_surface_added(struct weston_desktop_surface *desktop_surface, |
| 2298 | void *shell) |
| 2299 | { |
| 2300 | struct weston_desktop_client *client = |
| 2301 | weston_desktop_surface_get_client(desktop_surface); |
| 2302 | struct wl_client *wl_client = |
| 2303 | weston_desktop_client_get_client(client); |
| 2304 | struct weston_view *view; |
| 2305 | struct shell_surface *shsurf; |
| 2306 | struct weston_surface *surface = |
| 2307 | weston_desktop_surface_get_surface(desktop_surface); |
| 2308 | |
| 2309 | view = weston_desktop_surface_create_view(desktop_surface); |
| 2310 | if (!view) |
| 2311 | return; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2312 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2313 | shsurf = calloc(1, sizeof *shsurf); |
| 2314 | if (!shsurf) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2315 | if (wl_client) |
| 2316 | wl_client_post_no_memory(wl_client); |
| 2317 | else |
| 2318 | weston_log("no memory to allocate shell surface\n"); |
| 2319 | return; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2320 | } |
| 2321 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2322 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2323 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2324 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2325 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2326 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2327 | shsurf->saved_rotation_valid = false; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2328 | shsurf->desktop_surface = desktop_surface; |
| 2329 | shsurf->view = view; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2330 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2331 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2332 | |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2333 | shsurf->output = get_default_output(shsurf->shell->compositor); |
| 2334 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2335 | wl_signal_init(&shsurf->destroy_signal); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2336 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2337 | /* empty when not in use */ |
| 2338 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2339 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2340 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2341 | wl_list_init(&shsurf->workspace_transform.link); |
| 2342 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2343 | weston_desktop_surface_set_user_data(desktop_surface, shsurf); |
| 2344 | weston_desktop_surface_set_activated(desktop_surface, |
| 2345 | shsurf->focus_count > 0); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2346 | } |
| 2347 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2348 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2349 | desktop_surface_removed(struct weston_desktop_surface *desktop_surface, |
| 2350 | void *shell) |
| 2351 | { |
| 2352 | struct shell_surface *shsurf = |
| 2353 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2354 | struct weston_surface *surface = |
| 2355 | weston_desktop_surface_get_surface(desktop_surface); |
| 2356 | |
| 2357 | if (!shsurf) |
| 2358 | return; |
| 2359 | |
| 2360 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2361 | |
| 2362 | if (shsurf->fullscreen.black_view) |
| 2363 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2364 | |
| 2365 | weston_surface_set_label_func(surface, NULL); |
| 2366 | weston_desktop_surface_set_user_data(shsurf->desktop_surface, NULL); |
| 2367 | shsurf->desktop_surface = NULL; |
| 2368 | |
Quentin Glidic | f01ecee | 2016-08-16 10:52:46 +0200 | [diff] [blame] | 2369 | weston_desktop_surface_unlink_view(shsurf->view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2370 | if (weston_surface_is_mapped(surface) && |
| 2371 | shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 2372 | pixman_region32_fini(&surface->pending.input); |
| 2373 | pixman_region32_init(&surface->pending.input); |
| 2374 | pixman_region32_fini(&surface->input); |
| 2375 | pixman_region32_init(&surface->input); |
| 2376 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 2377 | fade_out_done, shsurf); |
| 2378 | } else { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2379 | weston_view_destroy(shsurf->view); |
| 2380 | free(shsurf); |
| 2381 | } |
| 2382 | } |
| 2383 | |
| 2384 | static void |
| 2385 | set_maximized_position(struct desktop_shell *shell, |
| 2386 | struct shell_surface *shsurf) |
| 2387 | { |
| 2388 | pixman_rectangle32_t area; |
| 2389 | struct weston_geometry geometry; |
| 2390 | |
| 2391 | get_output_work_area(shell, shsurf->output, &area); |
| 2392 | geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
| 2393 | |
| 2394 | weston_view_set_position(shsurf->view, |
| 2395 | area.x - geometry.x, |
| 2396 | area.y - geometry.y); |
| 2397 | } |
| 2398 | |
| 2399 | static void |
| 2400 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
| 2401 | int32_t sx, int32_t sy) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2402 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2403 | struct weston_surface *surface = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2404 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2405 | struct weston_compositor *compositor = shell->compositor; |
| 2406 | struct weston_seat *seat; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2407 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2408 | /* initial positioning, see also configure() */ |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame^] | 2409 | if (shsurf->state.fullscreen) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2410 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 2411 | shell_map_fullscreen(shsurf); |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame^] | 2412 | } else if (shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2413 | set_maximized_position(shell, shsurf); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 2414 | } else { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2415 | weston_view_set_initial_position(shsurf->view, shell); |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 2416 | } |
| 2417 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2418 | /* Surface stacking order, see also activate(). */ |
| 2419 | shell_surface_update_layer(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2420 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2421 | weston_view_update_transform(shsurf->view); |
| 2422 | shsurf->view->is_mapped = true; |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame^] | 2423 | if (shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2424 | surface->output = shsurf->output; |
| 2425 | shsurf->view->output = shsurf->output; |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2426 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2427 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2428 | if (!shell->locked) { |
| 2429 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 2430 | activate(shell, shsurf->view, seat, |
| 2431 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
| 2432 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2433 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame^] | 2434 | if (!shsurf->state.fullscreen && !shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2435 | switch (shell->win_animation_type) { |
| 2436 | case ANIMATION_FADE: |
| 2437 | weston_fade_run(shsurf->view, 0.0, 1.0, 300.0, NULL, NULL); |
| 2438 | break; |
| 2439 | case ANIMATION_ZOOM: |
| 2440 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
| 2441 | break; |
| 2442 | case ANIMATION_NONE: |
| 2443 | default: |
| 2444 | break; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 2445 | } |
| 2446 | } |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2450 | desktop_surface_committed(struct weston_desktop_surface *desktop_surface, |
| 2451 | int32_t sx, int32_t sy, void *data) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2452 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2453 | struct shell_surface *shsurf = |
| 2454 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2455 | struct weston_surface *surface = |
| 2456 | weston_desktop_surface_get_surface(desktop_surface); |
| 2457 | struct weston_view *view = shsurf->view; |
| 2458 | struct desktop_shell *shell = data; |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame^] | 2459 | bool was_fullscreen; |
| 2460 | bool was_maximized; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2461 | |
| 2462 | if (surface->width == 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2463 | return; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2464 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame^] | 2465 | was_fullscreen = shsurf->state.fullscreen; |
| 2466 | was_maximized = shsurf->state.maximized; |
| 2467 | |
| 2468 | shsurf->state.fullscreen = |
| 2469 | weston_desktop_surface_get_fullscreen(desktop_surface); |
| 2470 | shsurf->state.maximized = |
| 2471 | weston_desktop_surface_get_maximized(desktop_surface); |
| 2472 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2473 | if (!weston_surface_is_mapped(surface)) { |
| 2474 | map(shell, shsurf, sx, sy); |
| 2475 | surface->is_mapped = true; |
| 2476 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) |
| 2477 | ++surface->ref_count; |
| 2478 | return; |
| 2479 | } |
| 2480 | |
| 2481 | if (sx == 0 && sy == 0 && |
| 2482 | shsurf->last_width == surface->width && |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame^] | 2483 | shsurf->last_height == surface->height && |
| 2484 | was_fullscreen == shsurf->state.fullscreen && |
| 2485 | was_maximized == shsurf->state.maximized) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2486 | return; |
| 2487 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame^] | 2488 | if (was_fullscreen) |
| 2489 | unset_fullscreen(shsurf); |
| 2490 | if (was_maximized) |
| 2491 | unset_maximized(shsurf); |
| 2492 | |
| 2493 | if (shsurf->state.fullscreen) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2494 | shell_configure_fullscreen(shsurf); |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame^] | 2495 | } else if (shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2496 | set_maximized_position(shell, shsurf); |
| 2497 | surface->output = shsurf->output; |
| 2498 | } else { |
| 2499 | float from_x, from_y; |
| 2500 | float to_x, to_y; |
| 2501 | float x, y; |
| 2502 | |
| 2503 | if (shsurf->resize_edges) { |
| 2504 | sx = 0; |
| 2505 | sy = 0; |
| 2506 | } |
| 2507 | |
| 2508 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 2509 | sx = shsurf->last_width - surface->width; |
| 2510 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 2511 | sy = shsurf->last_height - surface->height; |
| 2512 | |
| 2513 | shsurf->last_width = surface->width; |
| 2514 | shsurf->last_height = surface->height; |
| 2515 | |
| 2516 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 2517 | weston_view_to_global_float(shsurf->view, sx, sy, &to_x, &to_y); |
| 2518 | x = shsurf->view->geometry.x + to_x - from_x; |
| 2519 | y = shsurf->view->geometry.y + to_y - from_y; |
| 2520 | |
| 2521 | weston_view_set_position(shsurf->view, x, y); |
| 2522 | } |
| 2523 | |
| 2524 | /* XXX: would a fullscreen surface need the same handling? */ |
| 2525 | if (surface->output) { |
| 2526 | wl_list_for_each(view, &surface->views, surface_link) |
| 2527 | weston_view_update_transform(view); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2528 | } |
| 2529 | } |
| 2530 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2531 | static void |
| 2532 | set_fullscreen(struct shell_surface *shsurf, bool fullscreen, |
| 2533 | struct weston_output *output) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2534 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2535 | struct weston_desktop_surface *desktop_surface = shsurf->desktop_surface; |
| 2536 | struct weston_surface *surface = |
| 2537 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2538 | int32_t width = 0, height = 0; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2539 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2540 | if (fullscreen) { |
| 2541 | /* handle clients launching in fullscreen */ |
| 2542 | if (output == NULL && !weston_surface_is_mapped(surface)) { |
| 2543 | /* Set the output to the one that has focus currently. */ |
| 2544 | output = get_focused_output(surface->compositor); |
| 2545 | } |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 2546 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2547 | shell_surface_set_output(shsurf, output); |
| 2548 | shsurf->fullscreen_output = shsurf->output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2549 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2550 | width = shsurf->output->width; |
| 2551 | height = shsurf->output->height; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2552 | } |
| 2553 | weston_desktop_surface_set_fullscreen(desktop_surface, fullscreen); |
| 2554 | weston_desktop_surface_set_size(desktop_surface, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2558 | desktop_surface_move(struct weston_desktop_surface *desktop_surface, |
| 2559 | struct weston_seat *seat, uint32_t serial, void *shell) |
| 2560 | { |
| 2561 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2562 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2563 | struct shell_surface *shsurf = |
| 2564 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2565 | struct weston_surface *surface = |
| 2566 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2567 | struct wl_resource *resource = surface->resource; |
| 2568 | struct weston_surface *focus; |
| 2569 | |
| 2570 | if (pointer && |
| 2571 | pointer->focus && |
| 2572 | pointer->button_count > 0 && |
| 2573 | pointer->grab_serial == serial) { |
| 2574 | focus = weston_surface_get_main_surface(pointer->focus->surface); |
| 2575 | if ((focus == surface) && |
| 2576 | (surface_move(shsurf, pointer, true) < 0)) |
| 2577 | wl_resource_post_no_memory(resource); |
| 2578 | } else if (touch && |
| 2579 | touch->focus && |
| 2580 | touch->grab_serial == serial) { |
| 2581 | focus = weston_surface_get_main_surface(touch->focus->surface); |
| 2582 | if ((focus == surface) && |
| 2583 | (surface_touch_move(shsurf, touch) < 0)) |
| 2584 | wl_resource_post_no_memory(resource); |
| 2585 | } |
| 2586 | } |
| 2587 | |
| 2588 | static void |
| 2589 | desktop_surface_resize(struct weston_desktop_surface *desktop_surface, |
| 2590 | struct weston_seat *seat, uint32_t serial, |
| 2591 | enum weston_desktop_surface_edge edges, void *shell) |
| 2592 | { |
| 2593 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2594 | struct shell_surface *shsurf = |
| 2595 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2596 | struct weston_surface *surface = |
| 2597 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2598 | struct wl_resource *resource = surface->resource; |
| 2599 | struct weston_surface *focus; |
| 2600 | |
| 2601 | if (!pointer || |
| 2602 | pointer->button_count == 0 || |
| 2603 | pointer->grab_serial != serial || |
| 2604 | pointer->focus == NULL) |
| 2605 | return; |
| 2606 | |
| 2607 | focus = weston_surface_get_main_surface(pointer->focus->surface); |
| 2608 | if (focus != surface) |
| 2609 | return; |
| 2610 | |
| 2611 | if (surface_resize(shsurf, pointer, edges) < 0) |
| 2612 | wl_resource_post_no_memory(resource); |
| 2613 | } |
| 2614 | |
| 2615 | static void |
| 2616 | desktop_surface_fullscreen_requested(struct weston_desktop_surface *desktop_surface, |
| 2617 | bool fullscreen, |
| 2618 | struct weston_output *output, void *shell) |
| 2619 | { |
| 2620 | struct shell_surface *shsurf = |
| 2621 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2622 | |
| 2623 | set_fullscreen(shsurf, fullscreen, output); |
| 2624 | } |
| 2625 | |
| 2626 | static void |
| 2627 | set_maximized(struct shell_surface *shsurf, bool maximized) |
| 2628 | { |
| 2629 | struct weston_desktop_surface *desktop_surface = shsurf->desktop_surface; |
| 2630 | struct weston_surface *surface = |
| 2631 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2632 | int32_t width = 0, height = 0; |
| 2633 | |
| 2634 | if (maximized) { |
| 2635 | struct weston_output *output; |
| 2636 | struct desktop_shell *shell; |
| 2637 | pixman_rectangle32_t area; |
| 2638 | |
| 2639 | if (!weston_surface_is_mapped(surface)) |
| 2640 | output = get_focused_output(surface->compositor); |
| 2641 | else |
| 2642 | output = surface->output; |
| 2643 | |
| 2644 | shell_surface_set_output(shsurf, output); |
| 2645 | |
| 2646 | shell = shell_surface_get_shell(shsurf); |
| 2647 | get_output_work_area(shell, shsurf->output, &area); |
| 2648 | |
| 2649 | width = area.width; |
| 2650 | height = area.height; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2651 | } |
| 2652 | weston_desktop_surface_set_maximized(desktop_surface, maximized); |
| 2653 | weston_desktop_surface_set_size(desktop_surface, width, height); |
| 2654 | } |
| 2655 | |
| 2656 | static void |
| 2657 | desktop_surface_maximized_requested(struct weston_desktop_surface *desktop_surface, |
| 2658 | bool maximized, void *shell) |
| 2659 | { |
| 2660 | struct shell_surface *shsurf = |
| 2661 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2662 | |
| 2663 | set_maximized(shsurf, maximized); |
| 2664 | } |
| 2665 | |
| 2666 | static void |
| 2667 | desktop_surface_minimized_requested(struct weston_desktop_surface *desktop_surface, |
| 2668 | void *shell) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2669 | { |
| 2670 | struct weston_surface *surface = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2671 | weston_desktop_surface_get_surface(desktop_surface); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2672 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2673 | /* apply compositor's own minimization logic (hide) */ |
| 2674 | set_minimized(surface); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2675 | } |
| 2676 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2677 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2678 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2679 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2680 | struct shell_grab *grab; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2681 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2682 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2683 | return; |
| 2684 | |
| 2685 | grab = malloc(sizeof *grab); |
| 2686 | if (!grab) |
| 2687 | return; |
| 2688 | |
| 2689 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2690 | WESTON_DESKTOP_SHELL_CURSOR_BUSY); |
| 2691 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2692 | * to move it. */ |
| 2693 | shsurf->grabbed = 0; |
| 2694 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2695 | |
| 2696 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2697 | end_busy_cursor(struct weston_compositor *compositor, |
| 2698 | struct weston_desktop_client *desktop_client) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2699 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 2700 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2701 | struct shell_grab *grab; |
| 2702 | struct weston_seat *seat; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 2703 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2704 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 2705 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2706 | struct weston_desktop_client *grab_client; |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 2707 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2708 | if (!pointer) |
| 2709 | continue; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2710 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2711 | if (pointer->grab->interface != &busy_cursor_grab_interface) |
| 2712 | continue; |
| 2713 | |
| 2714 | grab = (struct shell_grab *) pointer->grab; |
| 2715 | shsurf = grab->shsurf; |
| 2716 | if (!shsurf) |
| 2717 | continue; |
| 2718 | |
| 2719 | grab_client = |
| 2720 | weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 2721 | if (grab_client == desktop_client) { |
| 2722 | shell_grab_end(grab); |
| 2723 | free(grab); |
| 2724 | } |
| 2725 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2729 | desktop_surface_set_unresponsive(struct weston_desktop_surface *desktop_surface, |
| 2730 | void *user_data) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2731 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2732 | struct shell_surface *shsurf = |
| 2733 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2734 | bool *unresponsive = user_data; |
| 2735 | |
| 2736 | shsurf->unresponsive = *unresponsive; |
| 2737 | } |
| 2738 | |
| 2739 | static void |
| 2740 | desktop_surface_ping_timeout(struct weston_desktop_client *desktop_client, |
| 2741 | void *shell_) |
| 2742 | { |
| 2743 | struct desktop_shell *shell = shell_; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2744 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2745 | struct weston_seat *seat; |
| 2746 | bool unresponsive = true; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2747 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2748 | weston_desktop_client_for_each_surface(desktop_client, |
| 2749 | desktop_surface_set_unresponsive, |
| 2750 | &unresponsive); |
| 2751 | |
| 2752 | |
| 2753 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 2754 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2755 | struct weston_desktop_client *grab_client; |
| 2756 | |
| 2757 | if (!pointer || !pointer->focus) |
| 2758 | continue; |
| 2759 | |
| 2760 | shsurf = get_shell_surface(pointer->focus->surface); |
| 2761 | if (!shsurf) |
| 2762 | continue; |
| 2763 | |
| 2764 | grab_client = |
| 2765 | weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 2766 | if (grab_client == desktop_client) |
| 2767 | set_busy_cursor(shsurf, pointer); |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 2768 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2769 | } |
| 2770 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2771 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2772 | desktop_surface_pong(struct weston_desktop_client *desktop_client, |
| 2773 | void *shell_) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2774 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2775 | struct desktop_shell *shell = shell_; |
| 2776 | bool unresponsive = false; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2777 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2778 | weston_desktop_client_for_each_surface(desktop_client, |
| 2779 | desktop_surface_set_unresponsive, |
| 2780 | &unresponsive); |
| 2781 | end_busy_cursor(shell->compositor, desktop_client); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2782 | } |
| 2783 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2784 | static const struct weston_desktop_api shell_desktop_api = { |
| 2785 | .struct_size = sizeof(struct weston_desktop_api), |
| 2786 | .surface_added = desktop_surface_added, |
| 2787 | .surface_removed = desktop_surface_removed, |
| 2788 | .committed = desktop_surface_committed, |
| 2789 | .move = desktop_surface_move, |
| 2790 | .resize = desktop_surface_resize, |
| 2791 | .fullscreen_requested = desktop_surface_fullscreen_requested, |
| 2792 | .maximized_requested = desktop_surface_maximized_requested, |
| 2793 | .minimized_requested = desktop_surface_minimized_requested, |
| 2794 | .ping_timeout = desktop_surface_ping_timeout, |
| 2795 | .pong = desktop_surface_pong, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2796 | }; |
| 2797 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2798 | /* ************************ * |
| 2799 | * end of libweston-desktop * |
| 2800 | * ************************ */ |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2801 | static void |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 2802 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 2803 | |
| 2804 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2805 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2806 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2807 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2808 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2809 | wl_list_for_each_safe(v, next, &layer->view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2810 | if (v->output == ev->output && v != ev) { |
| 2811 | weston_view_unmap(v); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2812 | v->surface->committed = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2813 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2814 | } |
| 2815 | } |
| 2816 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2817 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 2818 | ev->surface->is_mapped = true; |
| 2819 | ev->is_mapped = true; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2820 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2821 | if (wl_list_empty(&ev->layer_link.link)) { |
| 2822 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2823 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2824 | } |
| 2825 | } |
| 2826 | |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2827 | |
| 2828 | static struct shell_output * |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2829 | find_shell_output_from_weston_output(struct desktop_shell *shell, |
| 2830 | struct weston_output *output) |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2831 | { |
| 2832 | struct shell_output *shell_output; |
| 2833 | |
| 2834 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 2835 | if (shell_output->output == output) |
| 2836 | return shell_output; |
| 2837 | } |
| 2838 | |
| 2839 | return NULL; |
| 2840 | } |
| 2841 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2842 | static int |
| 2843 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2844 | { |
| 2845 | return snprintf(buf, len, "background for output %s", |
| 2846 | surface->output->name); |
| 2847 | } |
| 2848 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2849 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2850 | background_committed(struct weston_surface *es, int32_t sx, int32_t sy) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2851 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2852 | struct desktop_shell *shell = es->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2853 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2854 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2855 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 2856 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2857 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2861 | handle_background_surface_destroy(struct wl_listener *listener, void *data) |
| 2862 | { |
| 2863 | struct shell_output *output = |
| 2864 | container_of(listener, struct shell_output, background_surface_listener); |
| 2865 | |
| 2866 | weston_log("background surface gone\n"); |
| 2867 | output->background_surface = NULL; |
| 2868 | } |
| 2869 | |
| 2870 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2871 | desktop_shell_set_background(struct wl_client *client, |
| 2872 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2873 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2874 | struct wl_resource *surface_resource) |
| 2875 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2876 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2877 | struct weston_surface *surface = |
| 2878 | wl_resource_get_user_data(surface_resource); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2879 | struct shell_output *sh_output; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2880 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2881 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2882 | if (surface->committed) { |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2883 | wl_resource_post_error(surface_resource, |
| 2884 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2885 | "surface role already assigned"); |
| 2886 | return; |
| 2887 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2888 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2889 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 2890 | weston_view_destroy(view); |
| 2891 | view = weston_view_create(surface); |
| 2892 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2893 | surface->committed = background_committed; |
| 2894 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2895 | weston_surface_set_label_func(surface, background_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2896 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2897 | view->output = surface->output; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 2898 | weston_desktop_shell_send_configure(resource, 0, |
| 2899 | surface_resource, |
| 2900 | surface->output->width, |
| 2901 | surface->output->height); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2902 | |
| 2903 | sh_output = find_shell_output_from_weston_output(shell, surface->output); |
| 2904 | sh_output->background_surface = surface; |
| 2905 | |
| 2906 | sh_output->background_surface_listener.notify = handle_background_surface_destroy; |
| 2907 | wl_signal_add(&surface->destroy_signal, &sh_output->background_surface_listener); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2908 | } |
| 2909 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2910 | static int |
| 2911 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2912 | { |
| 2913 | return snprintf(buf, len, "panel for output %s", |
| 2914 | surface->output->name); |
| 2915 | } |
| 2916 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2917 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2918 | panel_committed(struct weston_surface *es, int32_t sx, int32_t sy) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2919 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2920 | struct desktop_shell *shell = es->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2921 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2922 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2923 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 2924 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2925 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2929 | handle_panel_surface_destroy(struct wl_listener *listener, void *data) |
| 2930 | { |
| 2931 | struct shell_output *output = |
| 2932 | container_of(listener, struct shell_output, panel_surface_listener); |
| 2933 | |
| 2934 | weston_log("panel surface gone\n"); |
| 2935 | output->panel_surface = NULL; |
| 2936 | } |
| 2937 | |
| 2938 | |
| 2939 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2940 | desktop_shell_set_panel(struct wl_client *client, |
| 2941 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2942 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2943 | struct wl_resource *surface_resource) |
| 2944 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2945 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2946 | struct weston_surface *surface = |
| 2947 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2948 | struct weston_view *view, *next; |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2949 | struct shell_output *sh_output; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2950 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2951 | if (surface->committed) { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2952 | wl_resource_post_error(surface_resource, |
| 2953 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2954 | "surface role already assigned"); |
| 2955 | return; |
| 2956 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2957 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2958 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 2959 | weston_view_destroy(view); |
| 2960 | view = weston_view_create(surface); |
| 2961 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2962 | surface->committed = panel_committed; |
| 2963 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2964 | weston_surface_set_label_func(surface, panel_get_label); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2965 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2966 | view->output = surface->output; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 2967 | weston_desktop_shell_send_configure(resource, 0, |
| 2968 | surface_resource, |
| 2969 | surface->output->width, |
| 2970 | surface->output->height); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2971 | |
| 2972 | sh_output = find_shell_output_from_weston_output(shell, surface->output); |
| 2973 | sh_output->panel_surface = surface; |
| 2974 | |
| 2975 | sh_output->panel_surface_listener.notify = handle_panel_surface_destroy; |
| 2976 | wl_signal_add(&surface->destroy_signal, &sh_output->panel_surface_listener); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2977 | } |
| 2978 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2979 | static int |
| 2980 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2981 | { |
| 2982 | return snprintf(buf, len, "lock window"); |
| 2983 | } |
| 2984 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2985 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2986 | lock_surface_committed(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2987 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2988 | struct desktop_shell *shell = surface->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2989 | struct weston_view *view; |
| 2990 | |
| 2991 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2992 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2993 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2994 | return; |
| 2995 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2996 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2997 | |
| 2998 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2999 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 3000 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3001 | weston_view_update_transform(view); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 3002 | surface->is_mapped = true; |
| 3003 | view->is_mapped = true; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3004 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3005 | } |
| 3006 | } |
| 3007 | |
| 3008 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3009 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3010 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3011 | struct desktop_shell *shell = |
| 3012 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3013 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3014 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3015 | shell->lock_surface = NULL; |
| 3016 | } |
| 3017 | |
| 3018 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3019 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3020 | struct wl_resource *resource, |
| 3021 | struct wl_resource *surface_resource) |
| 3022 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3023 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3024 | struct weston_surface *surface = |
| 3025 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3026 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3027 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3028 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3029 | if (!shell->locked) |
| 3030 | return; |
| 3031 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3032 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3033 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3034 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3035 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3036 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3037 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3038 | weston_view_create(surface); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3039 | surface->committed = lock_surface_committed; |
| 3040 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3041 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3042 | } |
| 3043 | |
| 3044 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3045 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3046 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3047 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3048 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3049 | wl_list_remove(&shell->lock_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3050 | if (shell->showing_input_panels) { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 3051 | wl_list_insert(&shell->compositor->cursor_layer.link, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3052 | &shell->input_panel_layer.link); |
| 3053 | wl_list_insert(&shell->input_panel_layer.link, |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 3054 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3055 | } else { |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 3056 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3057 | &shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3058 | } |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 3059 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3060 | &shell->panel_layer.link); |
| 3061 | wl_list_insert(&shell->panel_layer.link, |
| 3062 | &ws->layer.link), |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3063 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3064 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3065 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3066 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3067 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3068 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3069 | } |
| 3070 | |
| 3071 | static void |
| 3072 | desktop_shell_unlock(struct wl_client *client, |
| 3073 | struct wl_resource *resource) |
| 3074 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3075 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3076 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3077 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3078 | |
| 3079 | if (shell->locked) |
| 3080 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3081 | } |
| 3082 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3083 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3084 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3085 | struct wl_resource *resource, |
| 3086 | struct wl_resource *surface_resource) |
| 3087 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3088 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3089 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3090 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3091 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3092 | } |
| 3093 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3094 | static void |
| 3095 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3096 | struct wl_resource *resource) |
| 3097 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3098 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3099 | |
| 3100 | shell_fade_startup(shell); |
| 3101 | } |
| 3102 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3103 | static void |
| 3104 | desktop_shell_set_panel_position(struct wl_client *client, |
| 3105 | struct wl_resource *resource, |
| 3106 | uint32_t position) |
| 3107 | { |
| 3108 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3109 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3110 | if (position != WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 3111 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 3112 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 3113 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3114 | wl_resource_post_error(resource, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3115 | WESTON_DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3116 | "bad position argument"); |
| 3117 | return; |
| 3118 | } |
| 3119 | |
| 3120 | shell->panel_position = position; |
| 3121 | } |
| 3122 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3123 | static const struct weston_desktop_shell_interface desktop_shell_implementation = { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3124 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3125 | desktop_shell_set_panel, |
| 3126 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3127 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3128 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3129 | desktop_shell_desktop_ready, |
| 3130 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3131 | }; |
| 3132 | |
| 3133 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3134 | move_binding(struct weston_pointer *pointer, uint32_t time, |
| 3135 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3136 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3137 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3138 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3139 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3140 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3141 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3142 | return; |
| 3143 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3144 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3145 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3146 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3147 | if (surface == NULL) |
| 3148 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3149 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3150 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3151 | if (shsurf == NULL || |
| 3152 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3153 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3154 | return; |
| 3155 | |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 3156 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3160 | maximize_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 3161 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3162 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3163 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3164 | struct weston_surface *surface; |
| 3165 | struct shell_surface *shsurf; |
| 3166 | |
| 3167 | surface = weston_surface_get_main_surface(focus); |
| 3168 | if (surface == NULL) |
| 3169 | return; |
| 3170 | |
| 3171 | shsurf = get_shell_surface(surface); |
| 3172 | if (shsurf == NULL) |
| 3173 | return; |
| 3174 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3175 | set_maximized(shsurf, !weston_desktop_surface_get_maximized(shsurf->desktop_surface)); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3179 | fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 3180 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3181 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3182 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3183 | struct weston_surface *surface; |
| 3184 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3185 | bool fullscreen; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3186 | |
| 3187 | surface = weston_surface_get_main_surface(focus); |
| 3188 | if (surface == NULL) |
| 3189 | return; |
| 3190 | |
| 3191 | shsurf = get_shell_surface(surface); |
| 3192 | if (shsurf == NULL) |
| 3193 | return; |
| 3194 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3195 | fullscreen = |
| 3196 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3197 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3198 | set_fullscreen(shsurf, !fullscreen, NULL); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3202 | touch_move_binding(struct weston_touch *touch, uint32_t time, void *data) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3203 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 3204 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3205 | struct weston_surface *surface; |
| 3206 | struct shell_surface *shsurf; |
| 3207 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3208 | if (touch->focus == NULL) |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 3209 | return; |
| 3210 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3211 | focus = touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3212 | surface = weston_surface_get_main_surface(focus); |
| 3213 | if (surface == NULL) |
| 3214 | return; |
| 3215 | |
| 3216 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3217 | if (shsurf == NULL || |
| 3218 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3219 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3220 | return; |
| 3221 | |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 3222 | surface_touch_move(shsurf, touch); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3223 | } |
| 3224 | |
| 3225 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3226 | resize_binding(struct weston_pointer *pointer, uint32_t time, |
| 3227 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3228 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3229 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3230 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3231 | uint32_t edges = 0; |
| 3232 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3233 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3234 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3235 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3236 | return; |
| 3237 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3238 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3239 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3240 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3241 | if (surface == NULL) |
| 3242 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3243 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3244 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3245 | if (shsurf == NULL || |
| 3246 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3247 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3248 | return; |
| 3249 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3250 | weston_view_from_global(shsurf->view, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3251 | wl_fixed_to_int(pointer->grab_x), |
| 3252 | wl_fixed_to_int(pointer->grab_y), |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3253 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3254 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3255 | if (x < surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3256 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3257 | else if (x < 2 * surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3258 | edges |= 0; |
| 3259 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3260 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3261 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3262 | if (y < surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3263 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3264 | else if (y < 2 * surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3265 | edges |= 0; |
| 3266 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3267 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3268 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3269 | surface_resize(shsurf, pointer, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3273 | surface_opacity_binding(struct weston_pointer *pointer, uint32_t time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3274 | struct weston_pointer_axis_event *event, |
| 3275 | void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3276 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3277 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3278 | struct shell_surface *shsurf; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3279 | struct weston_surface *focus = pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3280 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3281 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3282 | /* XXX: broken for windows containing sub-surfaces */ |
| 3283 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3284 | if (surface == NULL) |
| 3285 | return; |
| 3286 | |
| 3287 | shsurf = get_shell_surface(surface); |
| 3288 | if (!shsurf) |
| 3289 | return; |
| 3290 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 3291 | shsurf->view->alpha -= event->value * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3292 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3293 | if (shsurf->view->alpha > 1.0) |
| 3294 | shsurf->view->alpha = 1.0; |
| 3295 | if (shsurf->view->alpha < step) |
| 3296 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3297 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3298 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3299 | weston_surface_damage(surface); |
| 3300 | } |
| 3301 | |
| 3302 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3303 | do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 3304 | double value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3305 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 3306 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3307 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3308 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3309 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3310 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3311 | if (!pointer) { |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 3312 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 3313 | return; |
| 3314 | } |
| 3315 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3316 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3317 | if (pixman_region32_contains_point(&output->region, |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3318 | wl_fixed_to_double(pointer->x), |
| 3319 | wl_fixed_to_double(pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3320 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3321 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3322 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3323 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3324 | increment = -output->zoom.increment; |
| 3325 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3326 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3327 | increment = output->zoom.increment * |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 3328 | -value / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3329 | else |
| 3330 | increment = 0; |
| 3331 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3332 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3333 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3334 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3335 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3336 | else if (output->zoom.level > output->zoom.max_level) |
| 3337 | output->zoom.level = output->zoom.max_level; |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 3338 | |
| 3339 | if (!output->zoom.active) { |
| 3340 | if (output->zoom.level <= 0.0) |
| 3341 | continue; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 3342 | weston_output_activate_zoom(output, seat); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3343 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3344 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3345 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3346 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3347 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3348 | } |
| 3349 | } |
| 3350 | } |
| 3351 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3352 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3353 | zoom_axis_binding(struct weston_pointer *pointer, uint32_t time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3354 | struct weston_pointer_axis_event *event, |
| 3355 | void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3356 | { |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3357 | do_zoom(pointer->seat, time, 0, event->axis, event->value); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3361 | zoom_key_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 3362 | uint32_t key, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3363 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3364 | do_zoom(keyboard->seat, time, key, 0, 0); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3368 | terminate_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 3369 | uint32_t key, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3370 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3371 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3372 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3373 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3374 | } |
| 3375 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3376 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3377 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3378 | struct weston_pointer_motion_event *event) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3379 | { |
| 3380 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3381 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3382 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3383 | struct shell_surface *shsurf = rotate->base.shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3384 | struct weston_surface *surface = |
| 3385 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3386 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3387 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3388 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3389 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3390 | if (!shsurf) |
| 3391 | return; |
| 3392 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3393 | cx = 0.5f * surface->width; |
| 3394 | cy = 0.5f * surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3395 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3396 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3397 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3398 | r = sqrtf(dx * dx + dy * dy); |
| 3399 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3400 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3401 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3402 | |
| 3403 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3404 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3405 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3406 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3407 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3408 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3409 | |
| 3410 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3411 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3412 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3413 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3414 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3415 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 3416 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3417 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3418 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3419 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3420 | wl_list_init(&shsurf->rotation.transform.link); |
| 3421 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3422 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3423 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3424 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3425 | /* We need to adjust the position of the surface |
| 3426 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3427 | cposx = shsurf->view->geometry.x + cx; |
| 3428 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3429 | dposx = rotate->center.x - cposx; |
| 3430 | dposy = rotate->center.y - cposy; |
| 3431 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3432 | weston_view_set_position(shsurf->view, |
| 3433 | shsurf->view->geometry.x + dposx, |
| 3434 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3435 | } |
| 3436 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 3437 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3438 | * lazily applies the damage due to rotation update. |
| 3439 | */ |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3440 | weston_compositor_schedule_repaint(surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3441 | } |
| 3442 | |
| 3443 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3444 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 3445 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3446 | { |
| 3447 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3448 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3449 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3450 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3451 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3452 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3453 | if (pointer->button_count == 0 && |
| 3454 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3455 | if (shsurf) |
| 3456 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 3457 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3458 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3459 | free(rotate); |
| 3460 | } |
| 3461 | } |
| 3462 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3463 | static void |
| 3464 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 3465 | { |
| 3466 | struct rotate_grab *rotate = |
| 3467 | container_of(grab, struct rotate_grab, base.grab); |
| 3468 | |
| 3469 | shell_grab_end(&rotate->base); |
| 3470 | free(rotate); |
| 3471 | } |
| 3472 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3473 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3474 | noop_grab_focus, |
| 3475 | rotate_grab_motion, |
| 3476 | rotate_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3477 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 3478 | noop_grab_axis_source, |
| 3479 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3480 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3481 | }; |
| 3482 | |
| 3483 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3484 | surface_rotate(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3485 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3486 | struct weston_surface *surface = |
| 3487 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3488 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3489 | float dx, dy; |
| 3490 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3491 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3492 | rotate = malloc(sizeof *rotate); |
| 3493 | if (!rotate) |
| 3494 | return; |
| 3495 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3496 | weston_view_to_global_float(shsurf->view, |
| 3497 | surface->width * 0.5f, |
| 3498 | surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3499 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3500 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 3501 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3502 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3503 | r = sqrtf(dx * dx + dy * dy); |
| 3504 | if (r > 20.0f) { |
| 3505 | struct weston_matrix inverse; |
| 3506 | |
| 3507 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3508 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3509 | weston_matrix_multiply(&shsurf->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3510 | |
| 3511 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3512 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3513 | } else { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3514 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3515 | weston_matrix_init(&rotate->rotation); |
| 3516 | } |
| 3517 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3518 | shell_grab_start(&rotate->base, &rotate_grab_interface, shsurf, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3519 | pointer, WESTON_DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3523 | rotate_binding(struct weston_pointer *pointer, uint32_t time, uint32_t button, |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3524 | void *data) |
| 3525 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3526 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3527 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3528 | struct shell_surface *surface; |
| 3529 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3530 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3531 | return; |
| 3532 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3533 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3534 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3535 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3536 | if (base_surface == NULL) |
| 3537 | return; |
| 3538 | |
| 3539 | surface = get_shell_surface(base_surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3540 | if (surface == NULL || |
| 3541 | weston_desktop_surface_get_fullscreen(surface->desktop_surface) || |
| 3542 | weston_desktop_surface_get_maximized(surface->desktop_surface)) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3543 | return; |
| 3544 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 3545 | surface_rotate(surface, pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3546 | } |
| 3547 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3548 | /* Move all fullscreen layers down to the current workspace and hide their |
| 3549 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 3550 | * and this is reversed when such a surface is re-configured, see |
| 3551 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 3552 | * |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3553 | * lowering_output = NULL - Lower on all outputs, else only lower on the |
| 3554 | * specified output. |
| 3555 | * |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3556 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3557 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3558 | void |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3559 | lower_fullscreen_layer(struct desktop_shell *shell, |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3560 | struct weston_output *lowering_output) |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3561 | { |
| 3562 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3563 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3564 | |
| 3565 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3566 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3567 | &shell->fullscreen_layer.view_list.link, |
| 3568 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3569 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 3570 | |
| 3571 | if (!shsurf) |
| 3572 | continue; |
| 3573 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3574 | /* Only lower surfaces which have lowering_output as their fullscreen |
| 3575 | * output, unless a NULL output asks for lowering on all outputs. |
| 3576 | */ |
| 3577 | if (lowering_output && (shsurf->fullscreen_output != lowering_output)) |
| 3578 | continue; |
| 3579 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3580 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 3581 | * in the fullscreen layer. */ |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3582 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3583 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3584 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 3585 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 3586 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 3587 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3588 | } |
| 3589 | |
| 3590 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3591 | weston_layer_entry_remove(&view->layer_link); |
| 3592 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3593 | weston_view_damage_below(view); |
| 3594 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3595 | |
| 3596 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3597 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3598 | } |
| 3599 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3600 | void |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 3601 | activate(struct desktop_shell *shell, struct weston_view *view, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3602 | struct weston_seat *seat, uint32_t flags) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3603 | { |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 3604 | struct weston_surface *es = view->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3605 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3606 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3607 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3608 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3609 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3610 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3611 | main_surface = weston_surface_get_main_surface(es); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3612 | shsurf = get_shell_surface(main_surface); |
| 3613 | assert(shsurf); |
| 3614 | |
| 3615 | /* Only demote fullscreen surfaces on the output of activated shsurf. |
| 3616 | * Leave fullscreen surfaces on unrelated outputs alone. */ |
| 3617 | lower_fullscreen_layer(shell, shsurf->output); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3618 | |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 3619 | weston_view_activate(view, seat, flags); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3620 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3621 | state = ensure_focus_state(shell, seat); |
| 3622 | if (state == NULL) |
| 3623 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3624 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3625 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 3626 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3627 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3628 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) && |
| 3629 | flags & WESTON_ACTIVATE_FLAG_CONFIGURE) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3630 | shell_configure_fullscreen(shsurf); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3631 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 3632 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 3633 | * order as appropriate. */ |
| 3634 | shell_surface_update_layer(shsurf); |
| 3635 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3636 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 3637 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3638 | 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] | 3639 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3640 | } |
| 3641 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3642 | /* no-op func for checking black surface */ |
| 3643 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3644 | black_surface_committed(struct weston_surface *es, int32_t sx, int32_t sy) |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3645 | { |
| 3646 | } |
| 3647 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 3648 | static bool |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3649 | is_black_surface_view(struct weston_view *view, struct weston_view **fs_view) |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3650 | { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3651 | struct weston_surface *surface = view->surface; |
| 3652 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3653 | if (surface->committed == black_surface_committed) { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3654 | if (fs_view) |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3655 | *fs_view = surface->committed_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3656 | return true; |
| 3657 | } |
| 3658 | return false; |
| 3659 | } |
| 3660 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3661 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3662 | activate_binding(struct weston_seat *seat, |
| 3663 | struct desktop_shell *shell, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3664 | struct weston_view *focus_view, |
| 3665 | uint32_t flags) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3666 | { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3667 | struct weston_view *main_view; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3668 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3669 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3670 | if (!focus_view) |
| 3671 | return; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 3672 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3673 | if (is_black_surface_view(focus_view, &main_view)) |
| 3674 | focus_view = main_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3675 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3676 | main_surface = weston_surface_get_main_surface(focus_view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3677 | if (!get_shell_surface(main_surface)) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3678 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 3679 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3680 | activate(shell, focus_view, seat, flags); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3681 | } |
| 3682 | |
| 3683 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3684 | click_to_activate_binding(struct weston_pointer *pointer, uint32_t time, |
| 3685 | uint32_t button, void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3686 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3687 | if (pointer->grab != &pointer->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3688 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3689 | if (pointer->focus == NULL) |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 3690 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3691 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3692 | activate_binding(pointer->seat, data, pointer->focus, |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 3693 | WESTON_ACTIVATE_FLAG_CLICKED | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3694 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3698 | touch_to_activate_binding(struct weston_touch *touch, uint32_t time, |
| 3699 | void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3700 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3701 | if (touch->grab != &touch->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3702 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3703 | if (touch->focus == NULL) |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 3704 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3705 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3706 | activate_binding(touch->seat, data, touch->focus, |
| 3707 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3711 | unfocus_all_seats(struct desktop_shell *shell) |
| 3712 | { |
| 3713 | struct weston_seat *seat, *next; |
| 3714 | |
| 3715 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3716 | struct weston_keyboard *keyboard = |
| 3717 | weston_seat_get_keyboard(seat); |
| 3718 | |
| 3719 | if (!keyboard) |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3720 | continue; |
| 3721 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3722 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3723 | } |
| 3724 | } |
| 3725 | |
| 3726 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3727 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3728 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3729 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3730 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3731 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3732 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3733 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3734 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3735 | |
| 3736 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3737 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3738 | /* Hide all surfaces by removing the fullscreen, panel and |
| 3739 | * toplevel layers. This way nothing else can show or receive |
| 3740 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3741 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3742 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3743 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3744 | if (shell->showing_input_panels) |
| 3745 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3746 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3747 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3748 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3749 | |
Derek Foreman | 004b4a1 | 2015-07-20 16:28:13 -0500 | [diff] [blame] | 3750 | weston_compositor_sleep(shell->compositor); |
| 3751 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3752 | /* Remove the keyboard focus on all seats. This will be |
| 3753 | * restored to the workspace's saved state via |
| 3754 | * restore_focus_state when the compositor is unlocked */ |
| 3755 | unfocus_all_seats(shell); |
| 3756 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3757 | /* TODO: disable bindings that should not work while locked. */ |
| 3758 | |
| 3759 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3763 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3764 | { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3765 | struct wl_resource *shell_resource; |
| 3766 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 3767 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3768 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3769 | return; |
| 3770 | } |
| 3771 | |
| 3772 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 3773 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3774 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3775 | return; |
| 3776 | } |
| 3777 | |
| 3778 | if (shell->prepare_event_sent) |
| 3779 | return; |
| 3780 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3781 | shell_resource = shell->child.desktop_shell; |
| 3782 | weston_desktop_shell_send_prepare_lock_surface(shell_resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3783 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | static void |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3787 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3788 | { |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3789 | struct desktop_shell *shell = data; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3790 | |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3791 | shell->fade.animation = NULL; |
| 3792 | |
| 3793 | switch (shell->fade.type) { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3794 | case FADE_IN: |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3795 | weston_surface_destroy(shell->fade.view->surface); |
| 3796 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3797 | break; |
| 3798 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3799 | lock(shell); |
| 3800 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 3801 | default: |
| 3802 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3803 | } |
| 3804 | } |
| 3805 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3806 | static struct weston_view * |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3807 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3808 | { |
| 3809 | struct weston_compositor *compositor = shell->compositor; |
| 3810 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3811 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3812 | |
| 3813 | surface = weston_surface_create(compositor); |
| 3814 | if (!surface) |
| 3815 | return NULL; |
| 3816 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3817 | view = weston_view_create(surface); |
| 3818 | if (!view) { |
| 3819 | weston_surface_destroy(surface); |
| 3820 | return NULL; |
| 3821 | } |
| 3822 | |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3823 | weston_surface_set_size(surface, 8192, 8192); |
| 3824 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3825 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3826 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 3827 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3828 | pixman_region32_init(&surface->input); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 3829 | surface->is_mapped = true; |
| 3830 | view->is_mapped = true; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3831 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3832 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | static void |
| 3836 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 3837 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3838 | float tint; |
| 3839 | |
| 3840 | switch (type) { |
| 3841 | case FADE_IN: |
| 3842 | tint = 0.0; |
| 3843 | break; |
| 3844 | case FADE_OUT: |
| 3845 | tint = 1.0; |
| 3846 | break; |
| 3847 | default: |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3848 | weston_log("shell: invalid fade type\n"); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3849 | return; |
| 3850 | } |
| 3851 | |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3852 | shell->fade.type = type; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3853 | |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3854 | if (shell->fade.view == NULL) { |
| 3855 | shell->fade.view = shell_fade_create_surface(shell); |
| 3856 | if (!shell->fade.view) |
| 3857 | return; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3858 | |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3859 | shell->fade.view->alpha = 1.0 - tint; |
| 3860 | weston_view_update_transform(shell->fade.view); |
| 3861 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3862 | |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3863 | if (shell->fade.view->output == NULL) { |
| 3864 | /* If the black view gets a NULL output, we lost the |
| 3865 | * last output and we'll just cancel the fade. This |
| 3866 | * happens when you close the last window under the |
| 3867 | * X11 or Wayland backends. */ |
| 3868 | shell->locked = false; |
| 3869 | weston_surface_destroy(shell->fade.view->surface); |
| 3870 | shell->fade.view = NULL; |
| 3871 | } else if (shell->fade.animation) { |
| 3872 | weston_fade_update(shell->fade.animation, tint); |
| 3873 | } else { |
| 3874 | shell->fade.animation = |
| 3875 | weston_fade_run(shell->fade.view, |
| 3876 | 1.0 - tint, tint, 300.0, |
| 3877 | shell_fade_done, shell); |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 3878 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3882 | do_shell_fade_startup(void *data) |
| 3883 | { |
| 3884 | struct desktop_shell *shell = data; |
| 3885 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 3886 | if (shell->startup_animation_type == ANIMATION_FADE) { |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 3887 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 3888 | } else { |
| 3889 | weston_log("desktop shell: " |
| 3890 | "unexpected fade-in animation type %d\n", |
| 3891 | shell->startup_animation_type); |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3892 | weston_surface_destroy(shell->fade.view->surface); |
| 3893 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 3894 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3895 | } |
| 3896 | |
| 3897 | static void |
| 3898 | shell_fade_startup(struct desktop_shell *shell) |
| 3899 | { |
| 3900 | struct wl_event_loop *loop; |
| 3901 | |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3902 | if (!shell->fade.startup_timer) |
| 3903 | return; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3904 | |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3905 | wl_event_source_remove(shell->fade.startup_timer); |
| 3906 | shell->fade.startup_timer = NULL; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3907 | |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3908 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 3909 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3910 | } |
| 3911 | |
| 3912 | static int |
| 3913 | fade_startup_timeout(void *data) |
| 3914 | { |
| 3915 | struct desktop_shell *shell = data; |
| 3916 | |
| 3917 | shell_fade_startup(shell); |
| 3918 | return 0; |
| 3919 | } |
| 3920 | |
| 3921 | static void |
| 3922 | shell_fade_init(struct desktop_shell *shell) |
| 3923 | { |
| 3924 | /* Make compositor output all black, and wait for the desktop-shell |
| 3925 | * client to signal it is ready, then fade in. The timer triggers a |
| 3926 | * fade-in, in case the desktop-shell client takes too long. |
| 3927 | */ |
| 3928 | |
| 3929 | struct wl_event_loop *loop; |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3930 | |
| 3931 | if (shell->fade.view != NULL) { |
| 3932 | weston_log("%s: warning: fade surface already exists\n", |
| 3933 | __func__); |
| 3934 | return; |
| 3935 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3936 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 3937 | if (shell->startup_animation_type == ANIMATION_NONE) |
| 3938 | return; |
| 3939 | |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3940 | shell->fade.view = shell_fade_create_surface(shell); |
| 3941 | if (!shell->fade.view) |
| 3942 | return; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3943 | |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3944 | weston_view_update_transform(shell->fade.view); |
| 3945 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3946 | |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3947 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 3948 | shell->fade.startup_timer = |
| 3949 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 3950 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3954 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3955 | { |
| 3956 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3957 | container_of(listener, struct desktop_shell, idle_listener); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3958 | |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 3959 | struct weston_seat *seat; |
| 3960 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3961 | wl_list_for_each(seat, &shell->compositor->seat_list, link) |
| 3962 | weston_seat_break_desktop_grabs(seat); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3963 | |
| 3964 | shell_fade(shell, FADE_OUT); |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3965 | /* lock() is called from shell_fade_done() */ |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3966 | } |
| 3967 | |
| 3968 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3969 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3970 | { |
| 3971 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3972 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3973 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3974 | unlock(shell); |
| 3975 | } |
| 3976 | |
| 3977 | static void |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 3978 | transform_handler(struct wl_listener *listener, void *data) |
| 3979 | { |
| 3980 | struct weston_surface *surface = data; |
| 3981 | struct shell_surface *shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3982 | const struct weston_xwayland_surface_api *api; |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 3983 | int x, y; |
| 3984 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3985 | if (!shsurf) |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 3986 | return; |
| 3987 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3988 | api = shsurf->shell->xwayland_surface_api; |
| 3989 | if (!api) { |
| 3990 | api = weston_xwayland_surface_get_api(shsurf->shell->compositor); |
| 3991 | shsurf->shell->xwayland_surface_api = api; |
| 3992 | } |
| 3993 | |
| 3994 | if (!api || !api->is_xwayland_surface(surface)) |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 3995 | return; |
| 3996 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3997 | if (!weston_view_is_mapped(shsurf->view)) |
| 3998 | return; |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 3999 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4000 | x = shsurf->view->geometry.x; |
| 4001 | y = shsurf->view->geometry.y; |
| 4002 | |
| 4003 | api->send_position(surface, x, y); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4004 | } |
| 4005 | |
| 4006 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4007 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4008 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4009 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4010 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4011 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4012 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4013 | |
| 4014 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4015 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4016 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4017 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4018 | } |
| 4019 | |
| 4020 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4021 | weston_view_set_initial_position(struct weston_view *view, |
| 4022 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4023 | { |
| 4024 | struct weston_compositor *compositor = shell->compositor; |
| 4025 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4026 | int32_t range_x, range_y; |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4027 | int32_t x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4028 | struct weston_output *output, *target_output = NULL; |
| 4029 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4030 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4031 | |
| 4032 | /* As a heuristic place the new window on the same output as the |
| 4033 | * pointer. Falling back to the output containing 0, 0. |
| 4034 | * |
| 4035 | * TODO: Do something clever for touch too? |
| 4036 | */ |
| 4037 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4038 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 4039 | |
| 4040 | if (pointer) { |
| 4041 | ix = wl_fixed_to_int(pointer->x); |
| 4042 | iy = wl_fixed_to_int(pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4043 | break; |
| 4044 | } |
| 4045 | } |
| 4046 | |
| 4047 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4048 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4049 | target_output = output; |
| 4050 | break; |
| 4051 | } |
| 4052 | } |
| 4053 | |
| 4054 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4055 | weston_view_set_position(view, 10 + random() % 400, |
| 4056 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4057 | return; |
| 4058 | } |
| 4059 | |
| 4060 | /* Valid range within output where the surface will still be onscreen. |
| 4061 | * If this is negative it means that the surface is bigger than |
| 4062 | * output. |
| 4063 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4064 | get_output_work_area(shell, target_output, &area); |
| 4065 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4066 | x = area.x; |
| 4067 | y = area.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4068 | range_x = area.width - view->surface->width; |
| 4069 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4070 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4071 | if (range_x > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4072 | x += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4073 | |
| 4074 | if (range_y > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4075 | y += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4076 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4077 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4078 | } |
| 4079 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 4080 | static bool |
| 4081 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 4082 | { |
| 4083 | struct timespec now; |
| 4084 | |
| 4085 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 4086 | return false; |
| 4087 | |
| 4088 | /* |
| 4089 | * If the shell helper client dies before the session has been |
| 4090 | * up for roughly 30 seconds, better just make Weston shut down, |
| 4091 | * because the user likely has no way to interact with the desktop |
| 4092 | * anyway. |
| 4093 | */ |
| 4094 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 4095 | weston_log("Error: %s apparently cannot run at all.\n", |
| 4096 | shell->client); |
| 4097 | weston_log_continue(STAMP_SPACE "Quitting..."); |
| 4098 | wl_display_terminate(shell->compositor->wl_display); |
| 4099 | |
| 4100 | return true; |
| 4101 | } |
| 4102 | |
| 4103 | return false; |
| 4104 | } |
| 4105 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4106 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4107 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4108 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4109 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4110 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4111 | uint32_t time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4112 | |
| 4113 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4114 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4115 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4116 | shell->child.deathstamp = time; |
| 4117 | shell->child.deathcount = 0; |
| 4118 | } |
| 4119 | |
| 4120 | shell->child.deathcount++; |
| 4121 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4122 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4123 | return; |
| 4124 | } |
| 4125 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4126 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4127 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4128 | } |
| 4129 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4130 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4131 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 4132 | { |
| 4133 | struct desktop_shell *shell; |
| 4134 | |
| 4135 | shell = container_of(listener, struct desktop_shell, |
| 4136 | child.client_destroy_listener); |
| 4137 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4138 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4139 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4140 | /* |
| 4141 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 4142 | * before the respawned process has a chance to create a new |
| 4143 | * desktop_shell object, because we are being called from the |
| 4144 | * wl_client destructor which destroys all wl_resources before |
| 4145 | * returning. |
| 4146 | */ |
| 4147 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 4148 | if (!check_desktop_shell_crash_too_early(shell)) |
| 4149 | respawn_desktop_shell_process(shell); |
| 4150 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4151 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4152 | } |
| 4153 | |
| 4154 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4155 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4156 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4157 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4158 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4159 | shell->child.client = weston_client_start(shell->compositor, |
| 4160 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4161 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 4162 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4163 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 4164 | return; |
| 4165 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4166 | |
| 4167 | shell->child.client_destroy_listener.notify = |
| 4168 | desktop_shell_client_destroy; |
| 4169 | wl_client_add_destroy_listener(shell->child.client, |
| 4170 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4171 | } |
| 4172 | |
| 4173 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4174 | unbind_desktop_shell(struct wl_resource *resource) |
| 4175 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4176 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4177 | |
| 4178 | if (shell->locked) |
| 4179 | resume_desktop(shell); |
| 4180 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4181 | shell->child.desktop_shell = NULL; |
| 4182 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4183 | } |
| 4184 | |
| 4185 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4186 | bind_desktop_shell(struct wl_client *client, |
| 4187 | void *data, uint32_t version, uint32_t id) |
| 4188 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4189 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4190 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4191 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4192 | resource = wl_resource_create(client, &weston_desktop_shell_interface, |
| 4193 | 1, id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4194 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4195 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4196 | wl_resource_set_implementation(resource, |
| 4197 | &desktop_shell_implementation, |
| 4198 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4199 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4200 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4201 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4202 | |
| 4203 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4204 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4205 | } |
| 4206 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4207 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4208 | struct desktop_shell *shell; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4209 | struct weston_view *current; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4210 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4211 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4212 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4213 | }; |
| 4214 | |
| 4215 | static void |
| 4216 | switcher_next(struct switcher *switcher) |
| 4217 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4218 | struct weston_view *view; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4219 | struct weston_view *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4220 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4221 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4222 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4223 | /* temporary re-display minimized surfaces */ |
| 4224 | struct weston_view *tmp; |
| 4225 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4226 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 4227 | weston_layer_entry_remove(&view->layer_link); |
| 4228 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4229 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 4230 | *minimized = view; |
| 4231 | } |
| 4232 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4233 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4234 | shsurf = get_shell_surface(view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4235 | if (shsurf) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4236 | if (first == NULL) |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4237 | first = view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4238 | if (prev == switcher->current) |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4239 | next = view; |
| 4240 | prev = view; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4241 | view->alpha = 0.25; |
| 4242 | weston_view_geometry_dirty(view); |
| 4243 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4244 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4245 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 4246 | if (is_black_surface_view(view, NULL)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4247 | view->alpha = 0.25; |
| 4248 | weston_view_geometry_dirty(view); |
| 4249 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4250 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4251 | } |
| 4252 | |
| 4253 | if (next == NULL) |
| 4254 | next = first; |
| 4255 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4256 | if (next == NULL) |
| 4257 | return; |
| 4258 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4259 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4260 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4261 | |
| 4262 | switcher->current = next; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4263 | wl_list_for_each(view, &next->surface->views, surface_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4264 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4265 | |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4266 | shsurf = get_shell_surface(switcher->current->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4267 | if (shsurf && weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4268 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | static void |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4272 | switcher_handle_view_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4273 | { |
| 4274 | struct switcher *switcher = |
| 4275 | container_of(listener, struct switcher, listener); |
| 4276 | |
| 4277 | switcher_next(switcher); |
| 4278 | } |
| 4279 | |
| 4280 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4281 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4282 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4283 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4284 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4285 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4286 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4287 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4288 | if (is_focus_view(view)) |
| 4289 | continue; |
| 4290 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4291 | view->alpha = 1.0; |
| 4292 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4293 | } |
| 4294 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 4295 | if (switcher->current) { |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 4296 | activate(switcher->shell, switcher->current, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 4297 | keyboard->seat, |
| 4298 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
| 4299 | } |
| 4300 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4301 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4302 | weston_keyboard_end_grab(keyboard); |
| 4303 | if (keyboard->input_method_resource) |
| 4304 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4305 | |
| 4306 | /* re-hide surfaces that were temporary shown during the switch */ |
| 4307 | struct weston_view **minimized; |
| 4308 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 4309 | /* with the exception of the current selected */ |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4310 | if ((*minimized)->surface != switcher->current->surface) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4311 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 4312 | weston_layer_entry_insert(&switcher->shell->minimized_layer.view_list, &(*minimized)->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4313 | weston_view_damage_below(*minimized); |
| 4314 | } |
| 4315 | } |
| 4316 | wl_array_release(&switcher->minimized_array); |
| 4317 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4318 | free(switcher); |
| 4319 | } |
| 4320 | |
| 4321 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4322 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4323 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4324 | { |
| 4325 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4326 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4327 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4328 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4329 | switcher_next(switcher); |
| 4330 | } |
| 4331 | |
| 4332 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4333 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4334 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4335 | uint32_t mods_locked, uint32_t group) |
| 4336 | { |
| 4337 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4338 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4339 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4340 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 4341 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 4342 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4343 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4344 | static void |
| 4345 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 4346 | { |
| 4347 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 4348 | |
| 4349 | switcher_destroy(switcher); |
| 4350 | } |
| 4351 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4352 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4353 | switcher_key, |
| 4354 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4355 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4356 | }; |
| 4357 | |
| 4358 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4359 | switcher_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4360 | uint32_t key, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4361 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4362 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4363 | struct switcher *switcher; |
| 4364 | |
| 4365 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4366 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4367 | switcher->current = NULL; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4368 | switcher->listener.notify = switcher_handle_view_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4369 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4370 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4371 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 4372 | lower_fullscreen_layer(switcher->shell, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4373 | switcher->grab.interface = &switcher_grab; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4374 | weston_keyboard_start_grab(keyboard, &switcher->grab); |
| 4375 | weston_keyboard_set_focus(keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4376 | switcher_next(switcher); |
| 4377 | } |
| 4378 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4379 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4380 | backlight_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4381 | uint32_t key, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4382 | { |
| 4383 | struct weston_compositor *compositor = data; |
| 4384 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4385 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4386 | |
| 4387 | /* TODO: we're limiting to simple use cases, where we assume just |
| 4388 | * control on the primary display. We'd have to extend later if we |
| 4389 | * ever get support for setting backlights on random desktop LCD |
| 4390 | * panels though */ |
| 4391 | output = get_default_output(compositor); |
| 4392 | if (!output) |
| 4393 | return; |
| 4394 | |
| 4395 | if (!output->set_backlight) |
| 4396 | return; |
| 4397 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4398 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 4399 | backlight_new = output->backlight_current - 25; |
| 4400 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 4401 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4402 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4403 | if (backlight_new < 5) |
| 4404 | backlight_new = 5; |
| 4405 | if (backlight_new > 255) |
| 4406 | backlight_new = 255; |
| 4407 | |
| 4408 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4409 | output->set_backlight(output, output->backlight_current); |
| 4410 | } |
| 4411 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 4412 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4413 | force_kill_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 4414 | uint32_t key, void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4415 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 4416 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4417 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 4418 | struct desktop_shell *shell = data; |
| 4419 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4420 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4421 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4422 | focus_surface = keyboard->focus; |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 4423 | if (!focus_surface) |
| 4424 | return; |
| 4425 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 4426 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 4427 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4428 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 4429 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 4430 | |
| 4431 | /* Skip clients that we launched ourselves (the credentials of |
| 4432 | * the socketpair is ours) */ |
| 4433 | if (pid == getpid()) |
| 4434 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4435 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4436 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4437 | } |
| 4438 | |
| 4439 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4440 | workspace_up_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4441 | uint32_t key, void *data) |
| 4442 | { |
| 4443 | struct desktop_shell *shell = data; |
| 4444 | unsigned int new_index = shell->workspaces.current; |
| 4445 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4446 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4447 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4448 | if (new_index != 0) |
| 4449 | new_index--; |
| 4450 | |
| 4451 | change_workspace(shell, new_index); |
| 4452 | } |
| 4453 | |
| 4454 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4455 | workspace_down_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4456 | uint32_t key, void *data) |
| 4457 | { |
| 4458 | struct desktop_shell *shell = data; |
| 4459 | unsigned int new_index = shell->workspaces.current; |
| 4460 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4461 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4462 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4463 | if (new_index < shell->workspaces.num - 1) |
| 4464 | new_index++; |
| 4465 | |
| 4466 | change_workspace(shell, new_index); |
| 4467 | } |
| 4468 | |
| 4469 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4470 | workspace_f_binding(struct weston_keyboard *keyboard, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4471 | uint32_t key, void *data) |
| 4472 | { |
| 4473 | struct desktop_shell *shell = data; |
| 4474 | unsigned int new_index; |
| 4475 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4476 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4477 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4478 | new_index = key - KEY_F1; |
| 4479 | if (new_index >= shell->workspaces.num) |
| 4480 | new_index = shell->workspaces.num - 1; |
| 4481 | |
| 4482 | change_workspace(shell, new_index); |
| 4483 | } |
| 4484 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4485 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4486 | workspace_move_surface_up_binding(struct weston_keyboard *keyboard, |
| 4487 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4488 | { |
| 4489 | struct desktop_shell *shell = data; |
| 4490 | unsigned int new_index = shell->workspaces.current; |
| 4491 | |
| 4492 | if (shell->locked) |
| 4493 | return; |
| 4494 | |
| 4495 | if (new_index != 0) |
| 4496 | new_index--; |
| 4497 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4498 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4499 | } |
| 4500 | |
| 4501 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4502 | workspace_move_surface_down_binding(struct weston_keyboard *keyboard, |
| 4503 | uint32_t time, uint32_t key, void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4504 | { |
| 4505 | struct desktop_shell *shell = data; |
| 4506 | unsigned int new_index = shell->workspaces.current; |
| 4507 | |
| 4508 | if (shell->locked) |
| 4509 | return; |
| 4510 | |
| 4511 | if (new_index < shell->workspaces.num - 1) |
| 4512 | new_index++; |
| 4513 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4514 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4515 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4516 | |
| 4517 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4518 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 4519 | { |
| 4520 | struct weston_output *output, *first_output; |
| 4521 | struct weston_compositor *ec = view->surface->compositor; |
| 4522 | struct shell_surface *shsurf; |
| 4523 | float x, y; |
| 4524 | int visible; |
| 4525 | |
| 4526 | x = view->geometry.x; |
| 4527 | y = view->geometry.y; |
| 4528 | |
| 4529 | /* At this point the destroyed output is not in the list anymore. |
| 4530 | * If the view is still visible somewhere, we leave where it is, |
| 4531 | * otherwise, move it to the first output. */ |
| 4532 | visible = 0; |
| 4533 | wl_list_for_each(output, &ec->output_list, link) { |
| 4534 | if (pixman_region32_contains_point(&output->region, |
| 4535 | x, y, NULL)) { |
| 4536 | visible = 1; |
| 4537 | break; |
| 4538 | } |
| 4539 | } |
| 4540 | |
| 4541 | if (!visible) { |
| 4542 | first_output = container_of(ec->output_list.next, |
| 4543 | struct weston_output, link); |
| 4544 | |
| 4545 | x = first_output->x + first_output->width / 4; |
| 4546 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 4547 | |
| 4548 | weston_view_set_position(view, x, y); |
| 4549 | } else { |
| 4550 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4551 | } |
| 4552 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4553 | |
| 4554 | shsurf = get_shell_surface(view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4555 | if (!shsurf) |
| 4556 | return; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4557 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4558 | shsurf->saved_position_valid = false; |
| 4559 | set_maximized(shsurf, false); |
| 4560 | set_fullscreen(shsurf, false, NULL); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4561 | } |
| 4562 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4563 | void |
| 4564 | shell_for_each_layer(struct desktop_shell *shell, |
| 4565 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4566 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4567 | struct workspace **ws; |
| 4568 | |
| 4569 | func(shell, &shell->fullscreen_layer, data); |
| 4570 | func(shell, &shell->panel_layer, data); |
| 4571 | func(shell, &shell->background_layer, data); |
| 4572 | func(shell, &shell->lock_layer, data); |
| 4573 | func(shell, &shell->input_panel_layer, data); |
| 4574 | |
| 4575 | wl_array_for_each(ws, &shell->workspaces.array) |
| 4576 | func(shell, &(*ws)->layer, data); |
| 4577 | } |
| 4578 | |
| 4579 | static void |
| 4580 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 4581 | struct weston_layer *layer, |
| 4582 | void *data) |
| 4583 | { |
| 4584 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4585 | struct weston_view *view; |
| 4586 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4587 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4588 | if (view->output != output) |
| 4589 | continue; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4590 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4591 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4592 | } |
| 4593 | } |
| 4594 | |
| 4595 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4596 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 4597 | { |
| 4598 | struct shell_output *output_listener = |
| 4599 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4600 | struct weston_output *output = output_listener->output; |
| 4601 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4602 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4603 | 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] | 4604 | |
Quentin Glidic | 561201c | 2016-08-20 18:19:51 +0200 | [diff] [blame] | 4605 | wl_list_remove(&output_listener->panel_surface_listener.link); |
| 4606 | wl_list_remove(&output_listener->background_surface_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4607 | wl_list_remove(&output_listener->destroy_listener.link); |
| 4608 | wl_list_remove(&output_listener->link); |
| 4609 | free(output_listener); |
| 4610 | } |
| 4611 | |
| 4612 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4613 | shell_resize_surface_to_output(struct desktop_shell *shell, |
| 4614 | struct weston_surface *surface, |
| 4615 | const struct weston_output *output) |
| 4616 | { |
| 4617 | if (!surface) |
| 4618 | return; |
| 4619 | |
| 4620 | weston_desktop_shell_send_configure(shell->child.desktop_shell, 0, |
| 4621 | surface->resource, |
| 4622 | output->width, |
| 4623 | output->height); |
| 4624 | } |
| 4625 | |
| 4626 | |
| 4627 | static void |
| 4628 | handle_output_resized(struct wl_listener *listener, void *data) |
| 4629 | { |
| 4630 | struct desktop_shell *shell = |
| 4631 | container_of(listener, struct desktop_shell, resized_listener); |
| 4632 | struct weston_output *output = (struct weston_output *)data; |
| 4633 | struct shell_output *sh_output = find_shell_output_from_weston_output(shell, output); |
| 4634 | |
| 4635 | shell_resize_surface_to_output(shell, sh_output->background_surface, output); |
| 4636 | shell_resize_surface_to_output(shell, sh_output->panel_surface, output); |
| 4637 | } |
| 4638 | |
| 4639 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4640 | create_shell_output(struct desktop_shell *shell, |
| 4641 | struct weston_output *output) |
| 4642 | { |
| 4643 | struct shell_output *shell_output; |
| 4644 | |
| 4645 | shell_output = zalloc(sizeof *shell_output); |
| 4646 | if (shell_output == NULL) |
| 4647 | return; |
| 4648 | |
| 4649 | shell_output->output = output; |
| 4650 | shell_output->shell = shell; |
| 4651 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 4652 | wl_signal_add(&output->destroy_signal, |
| 4653 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 4654 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4655 | } |
| 4656 | |
| 4657 | static void |
| 4658 | handle_output_create(struct wl_listener *listener, void *data) |
| 4659 | { |
| 4660 | struct desktop_shell *shell = |
| 4661 | container_of(listener, struct desktop_shell, output_create_listener); |
| 4662 | struct weston_output *output = (struct weston_output *)data; |
| 4663 | |
| 4664 | create_shell_output(shell, output); |
| 4665 | } |
| 4666 | |
| 4667 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4668 | handle_output_move_layer(struct desktop_shell *shell, |
| 4669 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4670 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4671 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4672 | struct weston_view *view; |
| 4673 | float x, y; |
| 4674 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4675 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4676 | if (view->output != output) |
| 4677 | continue; |
| 4678 | |
| 4679 | x = view->geometry.x + output->move_x; |
| 4680 | y = view->geometry.y + output->move_y; |
| 4681 | weston_view_set_position(view, x, y); |
| 4682 | } |
| 4683 | } |
| 4684 | |
| 4685 | static void |
| 4686 | handle_output_move(struct wl_listener *listener, void *data) |
| 4687 | { |
| 4688 | struct desktop_shell *shell; |
| 4689 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4690 | shell = container_of(listener, struct desktop_shell, |
| 4691 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4692 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4693 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4694 | } |
| 4695 | |
| 4696 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4697 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 4698 | struct desktop_shell *shell) |
| 4699 | { |
| 4700 | struct weston_output *output; |
| 4701 | |
| 4702 | wl_list_init(&shell->output_list); |
| 4703 | wl_list_for_each(output, &ec->output_list, link) |
| 4704 | create_shell_output(shell, output); |
| 4705 | |
| 4706 | shell->output_create_listener.notify = handle_output_create; |
| 4707 | wl_signal_add(&ec->output_created_signal, |
| 4708 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4709 | |
| 4710 | shell->output_move_listener.notify = handle_output_move; |
| 4711 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4712 | } |
| 4713 | |
| 4714 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4715 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4716 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4717 | struct desktop_shell *shell = |
| 4718 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4719 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4720 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4721 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 4722 | /* Force state to unlocked so we don't try to fade */ |
| 4723 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4724 | |
| 4725 | if (shell->child.client) { |
| 4726 | /* disable respawn */ |
| 4727 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 4728 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4729 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 4730 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4731 | wl_list_remove(&shell->idle_listener.link); |
| 4732 | wl_list_remove(&shell->wake_listener.link); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4733 | wl_list_remove(&shell->transform_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 4734 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 4735 | text_backend_destroy(shell->text_backend); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 4736 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 4737 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4738 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 4739 | wl_list_remove(&shell_output->destroy_listener.link); |
| 4740 | wl_list_remove(&shell_output->link); |
| 4741 | free(shell_output); |
| 4742 | } |
| 4743 | |
| 4744 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 4745 | wl_list_remove(&shell->output_move_listener.link); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4746 | wl_list_remove(&shell->resized_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4747 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4748 | wl_array_for_each(ws, &shell->workspaces.array) |
| 4749 | workspace_destroy(*ws); |
| 4750 | wl_array_release(&shell->workspaces.array); |
| 4751 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4752 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4753 | free(shell); |
| 4754 | } |
| 4755 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4756 | static void |
| 4757 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 4758 | { |
| 4759 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4760 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4761 | |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 4762 | if (shell->allow_zap) |
| 4763 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 4764 | MODIFIER_CTRL | MODIFIER_ALT, |
| 4765 | terminate_binding, ec); |
| 4766 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4767 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4768 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 4769 | click_to_activate_binding, |
| 4770 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 4771 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 4772 | click_to_activate_binding, |
| 4773 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4774 | weston_compositor_add_touch_binding(ec, 0, |
| 4775 | touch_to_activate_binding, |
| 4776 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4777 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 4778 | MODIFIER_SUPER | MODIFIER_ALT, |
| 4779 | surface_opacity_binding, NULL); |
| 4780 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 4781 | MODIFIER_SUPER, zoom_axis_binding, |
| 4782 | NULL); |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 4783 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 4784 | backlight_binding, ec); |
| 4785 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 4786 | backlight_binding, ec); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4787 | |
| 4788 | /* configurable bindings */ |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 4789 | if (shell->exposay_modifier) |
| 4790 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 4791 | exposay_binding, shell); |
| 4792 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4793 | mod = shell->binding_modifier; |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 4794 | if (!mod) |
| 4795 | return; |
| 4796 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4797 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 4798 | zoom_key_binding, NULL); |
| 4799 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 4800 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 4801 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 4802 | maximize_binding, NULL); |
| 4803 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 4804 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4805 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 4806 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4807 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 4808 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4809 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 4810 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 4811 | mod | MODIFIER_SHIFT, |
| 4812 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 4813 | |
| 4814 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 4815 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 4816 | rotate_binding, NULL); |
| 4817 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4818 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 4819 | shell); |
| 4820 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 4821 | ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4822 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 4823 | ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4824 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 4825 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4826 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 4827 | workspace_up_binding, shell); |
| 4828 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 4829 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4830 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 4831 | workspace_move_surface_up_binding, |
| 4832 | shell); |
| 4833 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 4834 | workspace_move_surface_down_binding, |
| 4835 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4836 | |
| 4837 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 4838 | if (shell->workspaces.num > 1) { |
| 4839 | num_workspace_bindings = shell->workspaces.num; |
| 4840 | if (num_workspace_bindings > 6) |
| 4841 | num_workspace_bindings = 6; |
| 4842 | for (i = 0; i < num_workspace_bindings; i++) |
| 4843 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 4844 | workspace_f_binding, |
| 4845 | shell); |
| 4846 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 4847 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 4848 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4849 | } |
| 4850 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 4851 | static void |
| 4852 | handle_seat_created(struct wl_listener *listener, void *data) |
| 4853 | { |
| 4854 | struct weston_seat *seat = data; |
| 4855 | |
| 4856 | create_shell_seat(seat); |
| 4857 | } |
| 4858 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4859 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 4860 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 4861 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 4862 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 4863 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4864 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4865 | struct workspace **pws; |
| 4866 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4867 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4868 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 4869 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4870 | if (shell == NULL) |
| 4871 | return -1; |
| 4872 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4873 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4874 | |
| 4875 | shell->destroy_listener.notify = shell_destroy; |
| 4876 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4877 | shell->idle_listener.notify = idle_handler; |
| 4878 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 4879 | shell->wake_listener.notify = wake_handler; |
| 4880 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4881 | shell->transform_listener.notify = transform_handler; |
| 4882 | wl_signal_add(&ec->transform_signal, &shell->transform_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 4883 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4884 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 4885 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4886 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 4887 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4888 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4889 | |
| 4890 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 4891 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4892 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 4893 | if (input_panel_setup(shell) < 0) |
| 4894 | return -1; |
| 4895 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 4896 | shell->text_backend = text_backend_init(ec); |
| 4897 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 4898 | return -1; |
| 4899 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 4900 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 4901 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4902 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 4903 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 4904 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4905 | for (i = 0; i < shell->workspaces.num; i++) { |
| 4906 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 4907 | if (pws == NULL) |
| 4908 | return -1; |
| 4909 | |
| 4910 | *pws = workspace_create(); |
| 4911 | if (*pws == NULL) |
| 4912 | return -1; |
| 4913 | } |
| 4914 | activate_workspace(shell, 0); |
| 4915 | |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 4916 | weston_layer_init(&shell->minimized_layer, NULL); |
| 4917 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4918 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 4919 | wl_list_init(&shell->workspaces.animation.link); |
| 4920 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 4921 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4922 | shell->desktop = weston_desktop_create(ec, &shell_desktop_api, shell); |
| 4923 | if (!shell->desktop) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 4924 | return -1; |
| 4925 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 4926 | if (wl_global_create(ec->wl_display, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4927 | &weston_desktop_shell_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 4928 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4929 | return -1; |
| 4930 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4931 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4932 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4933 | shell->panel_position = WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP; |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 4934 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4935 | setup_output_destroy_handler(ec, shell); |
| 4936 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4937 | loop = wl_display_get_event_loop(ec->wl_display); |
| 4938 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4939 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 4940 | wl_list_for_each(seat, &ec->seat_list, link) |
| 4941 | handle_seat_created(NULL, seat); |
| 4942 | shell->seat_create_listener.notify = handle_seat_created; |
| 4943 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4944 | |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4945 | shell->resized_listener.notify = handle_output_resized; |
| 4946 | wl_signal_add(&ec->output_resized_signal, &shell->resized_listener); |
| 4947 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 4948 | screenshooter_create(ec); |
| 4949 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4950 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4951 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4952 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4953 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 4954 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 4955 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 4956 | return 0; |
| 4957 | } |