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" |
Pekka Paalanen | 91b1010 | 2019-04-04 14:27:31 +0300 | [diff] [blame] | 42 | #include <libweston/config-parser.h> |
Jon Cruz | d618f68 | 2015-06-15 15:37:09 -0700 | [diff] [blame] | 43 | #include "shared/helpers.h" |
Marius Vlad | d98c7e8 | 2021-03-08 18:02:32 +0200 | [diff] [blame^] | 44 | #include "shared/shell-utils.h" |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 45 | #include "shared/timespec-util.h" |
Pekka Paalanen | 8ebd981 | 2019-04-04 16:02:14 +0300 | [diff] [blame] | 46 | #include <libweston-desktop/libweston-desktop.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 47 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 48 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 49 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 50 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 51 | struct focus_state { |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 52 | struct desktop_shell *shell; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 53 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 54 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 55 | struct weston_surface *keyboard_focus; |
| 56 | struct wl_list link; |
| 57 | struct wl_listener seat_destroy_listener; |
| 58 | struct wl_listener surface_destroy_listener; |
| 59 | }; |
| 60 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 61 | /* |
| 62 | * Surface stacking and ordering. |
| 63 | * |
| 64 | * This is handled using several linked lists of surfaces, organised into |
| 65 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 66 | * above all of the surfaces in the layer below. The set of layers is static and |
| 67 | * in the following order (top-most first): |
| 68 | * • Lock layer (only ever displayed on its own) |
| 69 | * • Cursor layer |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 70 | * • Input panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 71 | * • Fullscreen layer |
| 72 | * • Panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 73 | * • Workspace layers |
| 74 | * • Background layer |
| 75 | * |
| 76 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 77 | * display. For example, when locking the screen, all layers except the lock |
| 78 | * layer are removed. |
| 79 | * |
| 80 | * A surface’s layer is modified on configuring the surface, in |
| 81 | * set_surface_type() (which is only called when the surface’s type change is |
| 82 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 83 | * fullscreen) its layer changes too. |
| 84 | * |
| 85 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 86 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 87 | * linked list of its children. When a surface’s layer is updated, so are the |
| 88 | * layers of its children. Note that child surfaces are *not* the same as |
| 89 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 90 | * order. |
| 91 | * |
| 92 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 93 | * have the same parent) only contains weston_surfaces which have a |
| 94 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 95 | * weston_surfaces. This means that the following implication does *not* hold: |
| 96 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 97 | */ |
| 98 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 99 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 100 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 101 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 102 | struct weston_desktop_surface *desktop_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 103 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 104 | int32_t last_width, last_height; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 105 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 106 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 107 | |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 108 | struct wl_list children_list; |
| 109 | struct wl_list children_link; |
| 110 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 111 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 112 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 113 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 114 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 115 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 116 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 117 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 118 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 119 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 120 | } rotation; |
| 121 | |
| 122 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 123 | struct weston_transform transform; /* matrix from x, y */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 124 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 125 | } fullscreen; |
| 126 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 127 | struct weston_transform workspace_transform; |
| 128 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 129 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 130 | struct weston_output *output; |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame] | 131 | struct wl_listener output_destroy_listener; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 132 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 133 | struct surface_state { |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 134 | bool fullscreen; |
| 135 | bool maximized; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 136 | bool lowered; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 137 | } state; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 138 | |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 139 | struct { |
| 140 | bool is_set; |
| 141 | int32_t x; |
| 142 | int32_t y; |
| 143 | } xwayland; |
| 144 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 145 | int focus_count; |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 146 | |
| 147 | bool destroying; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 148 | }; |
| 149 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 150 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 151 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 152 | struct shell_surface *shsurf; |
| 153 | struct wl_listener shsurf_destroy_listener; |
| 154 | }; |
| 155 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 156 | struct shell_touch_grab { |
| 157 | struct weston_touch_grab grab; |
| 158 | struct shell_surface *shsurf; |
| 159 | struct wl_listener shsurf_destroy_listener; |
| 160 | struct weston_touch *touch; |
| 161 | }; |
| 162 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 163 | struct weston_move_grab { |
| 164 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 165 | wl_fixed_t dx, dy; |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 166 | bool client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 167 | }; |
| 168 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 169 | struct weston_touch_move_grab { |
| 170 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 171 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 172 | wl_fixed_t dx, dy; |
| 173 | }; |
| 174 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 175 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 176 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 177 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 178 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 179 | float x; |
| 180 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 181 | } center; |
| 182 | }; |
| 183 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 184 | struct shell_seat { |
| 185 | struct weston_seat *seat; |
| 186 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 187 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 188 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 189 | struct wl_listener caps_changed_listener; |
| 190 | struct wl_listener pointer_focus_listener; |
| 191 | struct wl_listener keyboard_focus_listener; |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 192 | |
| 193 | struct wl_list link; /** shell::seat_list */ |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 194 | }; |
| 195 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 196 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 197 | static struct desktop_shell * |
| 198 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 199 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 200 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 201 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 202 | |
| 203 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 204 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 205 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 206 | static void |
| 207 | shell_fade_startup(struct desktop_shell *shell); |
| 208 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 209 | static void |
| 210 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 211 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 212 | static struct shell_seat * |
| 213 | get_shell_seat(struct weston_seat *seat); |
| 214 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 215 | static void |
| 216 | get_output_panel_size(struct desktop_shell *shell, |
| 217 | struct weston_output *output, |
| 218 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 219 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 220 | static void |
| 221 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 222 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 223 | static int |
| 224 | shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 225 | { |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 226 | const char *t, *c; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 227 | struct weston_desktop_surface *desktop_surface = |
| 228 | weston_surface_get_desktop_surface(surface); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 229 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 230 | t = weston_desktop_surface_get_title(desktop_surface); |
| 231 | c = weston_desktop_surface_get_app_id(desktop_surface); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 232 | |
| 233 | return snprintf(buf, len, "%s window%s%s%s%s%s", |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 234 | "top-level", |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 235 | t ? " '" : "", t ?: "", t ? "'" : "", |
| 236 | c ? " of " : "", c ?: ""); |
| 237 | } |
| 238 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 239 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 240 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 241 | { |
| 242 | struct shell_grab *grab; |
| 243 | |
| 244 | grab = container_of(listener, struct shell_grab, |
| 245 | shsurf_destroy_listener); |
| 246 | |
| 247 | grab->shsurf = NULL; |
| 248 | } |
| 249 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 250 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 251 | get_default_view(struct weston_surface *surface) |
| 252 | { |
| 253 | struct shell_surface *shsurf; |
| 254 | struct weston_view *view; |
| 255 | |
| 256 | if (!surface || wl_list_empty(&surface->views)) |
| 257 | return NULL; |
| 258 | |
| 259 | shsurf = get_shell_surface(surface); |
| 260 | if (shsurf) |
| 261 | return shsurf->view; |
| 262 | |
| 263 | wl_list_for_each(view, &surface->views, surface_link) |
| 264 | if (weston_view_is_mapped(view)) |
| 265 | return view; |
| 266 | |
| 267 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 268 | } |
| 269 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 270 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 271 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 272 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 273 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 274 | struct weston_pointer *pointer, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 275 | enum weston_desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 276 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 277 | struct desktop_shell *shell = shsurf->shell; |
| 278 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 279 | weston_seat_break_desktop_grabs(pointer->seat); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 280 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 281 | grab->grab.interface = interface; |
| 282 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 283 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 284 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 285 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 286 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 287 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 288 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 289 | if (shell->child.desktop_shell) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 290 | weston_desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 291 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 292 | weston_pointer_set_focus(pointer, |
| 293 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 294 | wl_fixed_from_int(0), |
| 295 | wl_fixed_from_int(0)); |
| 296 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 297 | } |
| 298 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 299 | static void |
Quentin Glidic | 581df06 | 2016-06-23 18:55:19 +0200 | [diff] [blame] | 300 | get_panel_size(struct desktop_shell *shell, |
| 301 | struct weston_view *view, |
| 302 | int *width, |
| 303 | int *height) |
| 304 | { |
| 305 | float x1, y1; |
| 306 | float x2, y2; |
| 307 | weston_view_to_global_float(view, 0, 0, &x1, &y1); |
| 308 | weston_view_to_global_float(view, |
| 309 | view->surface->width, |
| 310 | view->surface->height, |
| 311 | &x2, &y2); |
| 312 | *width = (int)(x2 - x1); |
| 313 | *height = (int)(y2 - y1); |
| 314 | } |
| 315 | |
| 316 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 317 | get_output_panel_size(struct desktop_shell *shell, |
| 318 | struct weston_output *output, |
| 319 | int *width, |
| 320 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 321 | { |
| 322 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 323 | |
| 324 | *width = 0; |
| 325 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 326 | |
| 327 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 328 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 329 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 330 | wl_list_for_each(view, &shell->panel_layer.view_list.link, layer_link.link) { |
Quentin Glidic | 581df06 | 2016-06-23 18:55:19 +0200 | [diff] [blame] | 331 | if (view->surface->output == output) { |
| 332 | get_panel_size(shell, view, width, height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 333 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 337 | /* the correct view wasn't found */ |
| 338 | } |
| 339 | |
Leandro Ribeiro | 0c59e92 | 2020-01-24 17:53:44 -0300 | [diff] [blame] | 340 | void |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 341 | get_output_work_area(struct desktop_shell *shell, |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 342 | struct weston_output *output, |
| 343 | pixman_rectangle32_t *area) |
| 344 | { |
| 345 | int32_t panel_width = 0, panel_height = 0; |
| 346 | |
Pekka Paalanen | 99372ba | 2018-05-02 10:21:55 +0200 | [diff] [blame] | 347 | if (!output) { |
| 348 | area->x = 0; |
| 349 | area->y = 0; |
| 350 | area->width = 0; |
| 351 | area->height = 0; |
| 352 | |
| 353 | return; |
| 354 | } |
| 355 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 356 | area->x = output->x; |
| 357 | area->y = output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 358 | |
| 359 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 360 | switch (shell->panel_position) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 361 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 362 | default: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 363 | area->y += panel_height; |
Daniel Stone | 2ef9b1a | 2017-03-13 16:31:36 +0000 | [diff] [blame] | 364 | /* fallthrough */ |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 365 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 366 | area->width = output->width; |
| 367 | area->height = output->height - panel_height; |
| 368 | break; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 369 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 370 | area->x += panel_width; |
Daniel Stone | 2ef9b1a | 2017-03-13 16:31:36 +0000 | [diff] [blame] | 371 | /* fallthrough */ |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 372 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 373 | area->width = output->width - panel_width; |
| 374 | area->height = output->height; |
| 375 | break; |
| 376 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 379 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 380 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 381 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 382 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 383 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 384 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 385 | |
| 386 | if (grab->shsurf->resize_edges) { |
| 387 | grab->shsurf->resize_edges = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 388 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 389 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 390 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 391 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 395 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 396 | const struct weston_touch_grab_interface *interface, |
| 397 | struct shell_surface *shsurf, |
| 398 | struct weston_touch *touch) |
| 399 | { |
| 400 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 401 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 402 | weston_seat_break_desktop_grabs(touch->seat); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 403 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 404 | grab->grab.interface = interface; |
| 405 | grab->shsurf = shsurf; |
| 406 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 407 | wl_signal_add(&shsurf->destroy_signal, |
| 408 | &grab->shsurf_destroy_listener); |
| 409 | |
| 410 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 411 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 412 | |
| 413 | weston_touch_start_grab(touch, &grab->grab); |
| 414 | if (shell->child.desktop_shell) |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 415 | weston_touch_set_focus(touch, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 416 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static void |
| 420 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 421 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 422 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 423 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 424 | grab->shsurf->grabbed = 0; |
| 425 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 426 | |
| 427 | weston_touch_end_grab(grab->touch); |
| 428 | } |
| 429 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 430 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 431 | get_modifier(char *modifier) |
| 432 | { |
| 433 | if (!modifier) |
| 434 | return MODIFIER_SUPER; |
| 435 | |
| 436 | if (!strcmp("ctrl", modifier)) |
| 437 | return MODIFIER_CTRL; |
| 438 | else if (!strcmp("alt", modifier)) |
| 439 | return MODIFIER_ALT; |
| 440 | else if (!strcmp("super", modifier)) |
| 441 | return MODIFIER_SUPER; |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 442 | else if (!strcmp("none", modifier)) |
| 443 | return 0; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 444 | else |
| 445 | return MODIFIER_SUPER; |
| 446 | } |
| 447 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 448 | static enum animation_type |
| 449 | get_animation_type(char *animation) |
| 450 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 451 | if (!animation) |
| 452 | return ANIMATION_NONE; |
| 453 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 454 | if (!strcmp("zoom", animation)) |
| 455 | return ANIMATION_ZOOM; |
| 456 | else if (!strcmp("fade", animation)) |
| 457 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 458 | else if (!strcmp("dim-layer", animation)) |
| 459 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 460 | else |
| 461 | return ANIMATION_NONE; |
| 462 | } |
| 463 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 464 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 465 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 466 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 467 | struct weston_config_section *section; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 468 | char *s, *client; |
Daniel Stone | 51d995a | 2019-11-26 00:14:24 +0000 | [diff] [blame] | 469 | bool allow_zap; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 470 | |
Giulio Camuffo | d52f3b7 | 2016-06-02 21:48:11 +0300 | [diff] [blame] | 471 | section = weston_config_get_section(wet_get_config(shell->compositor), |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 472 | "shell", NULL, NULL); |
Marius Vlad | 64fbd0f | 2018-12-15 15:51:57 +0200 | [diff] [blame] | 473 | client = wet_get_libexec_path(WESTON_SHELL_CLIENT); |
Daniel Stone | e03c111 | 2016-11-24 20:45:45 +0000 | [diff] [blame] | 474 | weston_config_section_get_string(section, "client", &s, client); |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 475 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 476 | shell->client = s; |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 477 | |
| 478 | weston_config_section_get_bool(section, |
| 479 | "allow-zap", &allow_zap, true); |
| 480 | shell->allow_zap = allow_zap; |
| 481 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 482 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 483 | "binding-modifier", &s, "super"); |
| 484 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 485 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 486 | |
| 487 | weston_config_section_get_string(section, |
| 488 | "exposay-modifier", &s, "none"); |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 489 | shell->exposay_modifier = get_modifier(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 490 | free(s); |
| 491 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 492 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 493 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 494 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 495 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 496 | shell->win_close_animation_type = get_animation_type(s); |
| 497 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 498 | weston_config_section_get_string(section, |
| 499 | "startup-animation", &s, "fade"); |
| 500 | shell->startup_animation_type = get_animation_type(s); |
| 501 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 502 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 503 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 504 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 505 | shell->focus_animation_type = get_animation_type(s); |
| 506 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 507 | weston_config_section_get_uint(section, "num-workspaces", |
| 508 | &shell->workspaces.num, |
| 509 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 510 | } |
| 511 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 512 | static int |
| 513 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 514 | { |
| 515 | return snprintf(buf, len, "focus highlight effect for output %s", |
Miguel A. Vico | 620f68d | 2019-09-25 11:23:13 -0700 | [diff] [blame] | 516 | (surface->output ? surface->output->name : "NULL")); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 517 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 518 | |
| 519 | /* no-op func for checking focus surface */ |
| 520 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 521 | 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] | 522 | { |
| 523 | } |
| 524 | |
| 525 | static struct focus_surface * |
| 526 | get_focus_surface(struct weston_surface *surface) |
| 527 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 528 | if (surface->committed == focus_surface_committed) |
| 529 | return surface->committed_private; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 530 | else |
| 531 | return NULL; |
| 532 | } |
| 533 | |
| 534 | static bool |
| 535 | is_focus_surface (struct weston_surface *es) |
| 536 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 537 | return (es->committed == focus_surface_committed); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static bool |
| 541 | is_focus_view (struct weston_view *view) |
| 542 | { |
| 543 | return is_focus_surface (view->surface); |
| 544 | } |
| 545 | |
| 546 | static struct focus_surface * |
| 547 | create_focus_surface(struct weston_compositor *ec, |
| 548 | struct weston_output *output) |
| 549 | { |
| 550 | struct focus_surface *fsurf = NULL; |
| 551 | struct weston_surface *surface = NULL; |
| 552 | |
| 553 | fsurf = malloc(sizeof *fsurf); |
| 554 | if (!fsurf) |
| 555 | return NULL; |
| 556 | |
| 557 | fsurf->surface = weston_surface_create(ec); |
| 558 | surface = fsurf->surface; |
| 559 | if (surface == NULL) { |
| 560 | free(fsurf); |
| 561 | return NULL; |
| 562 | } |
| 563 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 564 | surface->committed = focus_surface_committed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 565 | surface->output = output; |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 566 | surface->is_mapped = true; |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 567 | surface->committed_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 568 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 569 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 570 | fsurf->view = weston_view_create(surface); |
| 571 | if (fsurf->view == NULL) { |
| 572 | weston_surface_destroy(surface); |
| 573 | free(fsurf); |
| 574 | return NULL; |
| 575 | } |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 576 | weston_view_set_output(fsurf->view, output); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 577 | fsurf->view->is_mapped = true; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 578 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 579 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 580 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 581 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 582 | pixman_region32_fini(&surface->opaque); |
| 583 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 584 | output->width, output->height); |
| 585 | pixman_region32_fini(&surface->input); |
| 586 | pixman_region32_init(&surface->input); |
| 587 | |
| 588 | wl_list_init(&fsurf->workspace_transform.link); |
| 589 | |
| 590 | return fsurf; |
| 591 | } |
| 592 | |
| 593 | static void |
| 594 | focus_surface_destroy(struct focus_surface *fsurf) |
| 595 | { |
| 596 | weston_surface_destroy(fsurf->surface); |
| 597 | free(fsurf); |
| 598 | } |
| 599 | |
| 600 | static void |
| 601 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 602 | { |
| 603 | struct workspace *ws = data; |
| 604 | |
| 605 | ws->focus_animation = NULL; |
| 606 | } |
| 607 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 608 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 609 | focus_state_destroy(struct focus_state *state) |
| 610 | { |
| 611 | wl_list_remove(&state->seat_destroy_listener.link); |
| 612 | wl_list_remove(&state->surface_destroy_listener.link); |
| 613 | free(state); |
| 614 | } |
| 615 | |
| 616 | static void |
| 617 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 618 | { |
| 619 | struct focus_state *state = container_of(listener, |
| 620 | struct focus_state, |
| 621 | seat_destroy_listener); |
| 622 | |
| 623 | wl_list_remove(&state->link); |
| 624 | focus_state_destroy(state); |
| 625 | } |
| 626 | |
| 627 | static void |
| 628 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 629 | { |
| 630 | struct focus_state *state = container_of(listener, |
| 631 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 632 | surface_destroy_listener); |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 633 | struct weston_surface *main_surface; |
| 634 | struct weston_view *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 635 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 636 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 637 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 638 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 639 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 640 | wl_list_for_each(view, |
| 641 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 642 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 643 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 644 | if (is_focus_view(view)) |
| 645 | continue; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 646 | if (!get_shell_surface(view->surface)) |
| 647 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 648 | |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 649 | next = view; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 650 | break; |
| 651 | } |
| 652 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 653 | /* if the focus was a sub-surface, activate its main surface */ |
| 654 | if (main_surface != state->keyboard_focus) |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 655 | next = get_default_view(main_surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 656 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 657 | if (next) { |
Greg V | 15d3d30 | 2018-12-07 01:33:34 +0300 | [diff] [blame] | 658 | if (state->keyboard_focus) { |
| 659 | wl_list_remove(&state->surface_destroy_listener.link); |
| 660 | wl_list_init(&state->surface_destroy_listener.link); |
| 661 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 662 | state->keyboard_focus = NULL; |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 663 | activate(state->shell, next, state->seat, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 664 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 665 | } else { |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 666 | if (state->shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 667 | if (state->ws->focus_animation) |
| 668 | weston_view_animation_destroy(state->ws->focus_animation); |
| 669 | |
| 670 | state->ws->focus_animation = weston_fade_run( |
| 671 | state->ws->fsurf_front->view, |
| 672 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 673 | focus_animation_done, state->ws); |
| 674 | } |
| 675 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 676 | wl_list_remove(&state->link); |
| 677 | focus_state_destroy(state); |
| 678 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | static struct focus_state * |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 682 | focus_state_create(struct desktop_shell *shell, struct weston_seat *seat, |
| 683 | struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 684 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 685 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 686 | |
| 687 | state = malloc(sizeof *state); |
| 688 | if (state == NULL) |
| 689 | return NULL; |
| 690 | |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 691 | state->shell = shell; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 692 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 693 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 694 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 695 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 696 | |
| 697 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 698 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 699 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 700 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 701 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 702 | |
| 703 | return state; |
| 704 | } |
| 705 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 706 | static struct focus_state * |
| 707 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 708 | { |
| 709 | struct workspace *ws = get_current_workspace(shell); |
| 710 | struct focus_state *state; |
| 711 | |
| 712 | wl_list_for_each(state, &ws->focus_list, link) |
| 713 | if (state->seat == seat) |
| 714 | break; |
| 715 | |
| 716 | if (&state->link == &ws->focus_list) |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 717 | state = focus_state_create(shell, seat, ws); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 718 | |
| 719 | return state; |
| 720 | } |
| 721 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 722 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 723 | focus_state_set_focus(struct focus_state *state, |
| 724 | struct weston_surface *surface) |
| 725 | { |
| 726 | if (state->keyboard_focus) { |
| 727 | wl_list_remove(&state->surface_destroy_listener.link); |
| 728 | wl_list_init(&state->surface_destroy_listener.link); |
| 729 | } |
| 730 | |
| 731 | state->keyboard_focus = surface; |
| 732 | if (surface) |
| 733 | wl_signal_add(&surface->destroy_signal, |
| 734 | &state->surface_destroy_listener); |
| 735 | } |
| 736 | |
| 737 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 738 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 739 | { |
| 740 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 741 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 742 | struct wl_list pending_seat_list; |
| 743 | struct weston_seat *seat, *next_seat; |
| 744 | |
| 745 | /* Temporarily steal the list of seats so that we can keep |
| 746 | * track of the seats we've already processed */ |
| 747 | wl_list_init(&pending_seat_list); |
| 748 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 749 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 750 | |
| 751 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 752 | struct weston_keyboard *keyboard = |
| 753 | weston_seat_get_keyboard(state->seat); |
| 754 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 755 | wl_list_remove(&state->seat->link); |
| 756 | wl_list_insert(&shell->compositor->seat_list, |
| 757 | &state->seat->link); |
| 758 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 759 | if (!keyboard) |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 760 | continue; |
| 761 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 762 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 763 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 764 | weston_keyboard_set_focus(keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 765 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 766 | |
| 767 | /* For any remaining seats that we don't have a focus state |
| 768 | * for we'll reset the keyboard focus to NULL */ |
| 769 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 770 | struct weston_keyboard *keyboard = |
| 771 | weston_seat_get_keyboard(seat); |
| 772 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 773 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 774 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 775 | if (!keyboard) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 776 | continue; |
| 777 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 778 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 779 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 783 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 784 | struct weston_seat *seat) |
| 785 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 786 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 787 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 788 | |
| 789 | wl_list_for_each(state, &ws->focus_list, link) { |
| 790 | if (state->seat == seat) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 791 | focus_state_set_focus(state, keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 792 | return; |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | static void |
| 798 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 799 | struct weston_surface *surface) |
| 800 | { |
| 801 | struct focus_state *state; |
| 802 | |
| 803 | wl_list_for_each(state, &ws->focus_list, link) |
| 804 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 805 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 809 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 810 | struct weston_view *from, struct weston_view *to) |
| 811 | { |
| 812 | struct weston_output *output; |
| 813 | bool focus_surface_created = false; |
| 814 | |
| 815 | /* FIXME: Only support dim animation using two layers */ |
| 816 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 817 | return; |
| 818 | |
| 819 | output = get_default_output(shell->compositor); |
| 820 | if (ws->fsurf_front == NULL && (from || to)) { |
| 821 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 822 | if (ws->fsurf_front == NULL) |
| 823 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 824 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 825 | |
| 826 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 827 | if (ws->fsurf_back == NULL) { |
| 828 | focus_surface_destroy(ws->fsurf_front); |
| 829 | return; |
| 830 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 831 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 832 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 833 | focus_surface_created = true; |
| 834 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 835 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 836 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | if (ws->focus_animation) { |
| 840 | weston_view_animation_destroy(ws->focus_animation); |
| 841 | ws->focus_animation = NULL; |
| 842 | } |
| 843 | |
| 844 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 845 | weston_layer_entry_insert(&to->layer_link, |
| 846 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 847 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 848 | weston_layer_entry_insert(&ws->layer.view_list, |
| 849 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 850 | |
| 851 | if (focus_surface_created) { |
| 852 | ws->focus_animation = weston_fade_run( |
| 853 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 854 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 855 | focus_animation_done, ws); |
| 856 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 857 | weston_layer_entry_insert(&from->layer_link, |
| 858 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 859 | ws->focus_animation = weston_stable_fade_run( |
| 860 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 861 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 862 | focus_animation_done, ws); |
| 863 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 864 | weston_layer_entry_insert(&ws->layer.view_list, |
| 865 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 866 | ws->focus_animation = weston_stable_fade_run( |
| 867 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 868 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 869 | focus_animation_done, ws); |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 874 | workspace_destroy(struct workspace *ws) |
| 875 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 876 | struct focus_state *state, *next; |
| 877 | |
| 878 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 879 | focus_state_destroy(state); |
| 880 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 881 | if (ws->fsurf_front) |
| 882 | focus_surface_destroy(ws->fsurf_front); |
| 883 | if (ws->fsurf_back) |
| 884 | focus_surface_destroy(ws->fsurf_back); |
| 885 | |
Pekka Paalanen | 4bb326b | 2021-05-14 14:37:46 +0300 | [diff] [blame] | 886 | weston_layer_fini(&ws->layer); |
| 887 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 888 | free(ws); |
| 889 | } |
| 890 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 891 | static void |
| 892 | seat_destroyed(struct wl_listener *listener, void *data) |
| 893 | { |
| 894 | struct weston_seat *seat = data; |
| 895 | struct focus_state *state, *next; |
| 896 | struct workspace *ws = container_of(listener, |
| 897 | struct workspace, |
| 898 | seat_destroyed_listener); |
| 899 | |
| 900 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 901 | if (state->seat == seat) |
| 902 | wl_list_remove(&state->link); |
| 903 | } |
| 904 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 905 | static struct workspace * |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 906 | workspace_create(struct desktop_shell *shell) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 907 | { |
| 908 | struct workspace *ws = malloc(sizeof *ws); |
| 909 | if (ws == NULL) |
| 910 | return NULL; |
| 911 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 912 | weston_layer_init(&ws->layer, shell->compositor); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 913 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 914 | wl_list_init(&ws->focus_list); |
| 915 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 916 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 917 | ws->fsurf_front = NULL; |
| 918 | ws->fsurf_back = NULL; |
| 919 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 920 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 921 | return ws; |
| 922 | } |
| 923 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 924 | static int |
| 925 | workspace_is_empty(struct workspace *ws) |
| 926 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 927 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 928 | } |
| 929 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 930 | static struct workspace * |
| 931 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 932 | { |
| 933 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 934 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 935 | pws += index; |
| 936 | return *pws; |
| 937 | } |
| 938 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 939 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 940 | get_current_workspace(struct desktop_shell *shell) |
| 941 | { |
| 942 | return get_workspace(shell, shell->workspaces.current); |
| 943 | } |
| 944 | |
| 945 | static void |
| 946 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 947 | { |
| 948 | struct workspace *ws; |
| 949 | |
| 950 | ws = get_workspace(shell, index); |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 951 | weston_layer_set_position(&ws->layer, WESTON_LAYER_POSITION_NORMAL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 952 | |
| 953 | shell->workspaces.current = index; |
| 954 | } |
| 955 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 956 | static unsigned int |
| 957 | get_output_height(struct weston_output *output) |
| 958 | { |
| 959 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 960 | } |
| 961 | |
Greg V | f57774e | 2018-07-24 23:21:55 +0300 | [diff] [blame] | 962 | static struct weston_transform * |
| 963 | view_get_transform(struct weston_view *view) |
| 964 | { |
| 965 | struct focus_surface *fsurf = NULL; |
| 966 | struct shell_surface *shsurf = NULL; |
| 967 | |
| 968 | if (is_focus_view(view)) { |
| 969 | fsurf = get_focus_surface(view->surface); |
| 970 | return &fsurf->workspace_transform; |
| 971 | } |
| 972 | |
| 973 | shsurf = get_shell_surface(view->surface); |
| 974 | if (shsurf) |
| 975 | return &shsurf->workspace_transform; |
| 976 | |
| 977 | return NULL; |
| 978 | } |
| 979 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 980 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 981 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 982 | { |
Greg V | f57774e | 2018-07-24 23:21:55 +0300 | [diff] [blame] | 983 | struct weston_transform *transform = view_get_transform(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 984 | |
Greg V | f57774e | 2018-07-24 23:21:55 +0300 | [diff] [blame] | 985 | if (!transform) |
| 986 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 987 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 988 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 989 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 990 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 991 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 992 | weston_matrix_init(&transform->matrix); |
| 993 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 994 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 995 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | static void |
| 999 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1000 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1001 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1002 | unsigned int height; |
| 1003 | double d; |
| 1004 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1005 | 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] | 1006 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1007 | d = height * fraction; |
| 1008 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1009 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | static void |
| 1014 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1015 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1016 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1017 | unsigned int height; |
| 1018 | double d; |
| 1019 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1020 | 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] | 1021 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1022 | |
| 1023 | if (fraction > 0) |
| 1024 | d = -(height - height * fraction); |
| 1025 | else |
| 1026 | d = height + height * fraction; |
| 1027 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1028 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1033 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1034 | unsigned int index, |
| 1035 | struct workspace *from, |
| 1036 | struct workspace *to) |
| 1037 | { |
| 1038 | shell->workspaces.current = index; |
| 1039 | |
| 1040 | shell->workspaces.anim_to = to; |
| 1041 | shell->workspaces.anim_from = from; |
| 1042 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1043 | shell->workspaces.anim_timestamp = (struct timespec) { 0 }; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1044 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1045 | weston_layer_set_position(&to->layer, WESTON_LAYER_POSITION_NORMAL); |
| 1046 | weston_layer_set_position(&from->layer, WESTON_LAYER_POSITION_NORMAL - 1); |
| 1047 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1048 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | static void |
| 1052 | workspace_deactivate_transforms(struct workspace *ws) |
| 1053 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1054 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1055 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1056 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1057 | wl_list_for_each(view, &ws->layer.view_list.link, layer_link.link) { |
Greg V | f57774e | 2018-07-24 23:21:55 +0300 | [diff] [blame] | 1058 | transform = view_get_transform(view); |
| 1059 | if (!transform) |
| 1060 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1061 | |
| 1062 | if (!wl_list_empty(&transform->link)) { |
| 1063 | wl_list_remove(&transform->link); |
| 1064 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1065 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1066 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | static void |
| 1071 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1072 | struct workspace *from, |
| 1073 | struct workspace *to) |
| 1074 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1075 | struct weston_view *view; |
| 1076 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1077 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1078 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1079 | /* Views that extend past the bottom of the output are still |
| 1080 | * visible after the workspace animation ends but before its layer |
| 1081 | * is hidden. In that case, we need to damage below those views so |
| 1082 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1083 | 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] | 1084 | weston_view_damage_below(view); |
| 1085 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1086 | wl_list_remove(&shell->workspaces.animation.link); |
| 1087 | workspace_deactivate_transforms(from); |
| 1088 | workspace_deactivate_transforms(to); |
| 1089 | shell->workspaces.anim_to = NULL; |
| 1090 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1091 | weston_layer_unset_position(&shell->workspaces.anim_from->layer); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | static void |
| 1095 | animate_workspace_change_frame(struct weston_animation *animation, |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1096 | struct weston_output *output, |
| 1097 | const struct timespec *time) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1098 | { |
| 1099 | struct desktop_shell *shell = |
| 1100 | container_of(animation, struct desktop_shell, |
| 1101 | workspaces.animation); |
| 1102 | struct workspace *from = shell->workspaces.anim_from; |
| 1103 | struct workspace *to = shell->workspaces.anim_to; |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1104 | int64_t t; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1105 | double x, y; |
| 1106 | |
| 1107 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1108 | finish_workspace_change_animation(shell, from, to); |
| 1109 | return; |
| 1110 | } |
| 1111 | |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1112 | if (timespec_is_zero(&shell->workspaces.anim_timestamp)) { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1113 | if (shell->workspaces.anim_current == 0.0) |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1114 | shell->workspaces.anim_timestamp = *time; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1115 | else |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1116 | timespec_add_msec(&shell->workspaces.anim_timestamp, |
| 1117 | time, |
Emmanuel Gil Peyrot | 426c246 | 2019-02-20 16:33:32 +0100 | [diff] [blame] | 1118 | /* Inverse of movement function 'y' below. */ |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1119 | -(asin(1.0 - shell->workspaces.anim_current) * |
| 1120 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1121 | M_2_PI)); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1122 | } |
| 1123 | |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1124 | t = timespec_sub_to_msec(time, &shell->workspaces.anim_timestamp); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1125 | |
| 1126 | /* |
| 1127 | * x = [0, π/2] |
| 1128 | * y(x) = sin(x) |
| 1129 | */ |
| 1130 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1131 | y = sin(x); |
| 1132 | |
| 1133 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1134 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1135 | |
| 1136 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1137 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1138 | shell->workspaces.anim_current = y; |
| 1139 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1140 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1141 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1142 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1143 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | static void |
| 1147 | animate_workspace_change(struct desktop_shell *shell, |
| 1148 | unsigned int index, |
| 1149 | struct workspace *from, |
| 1150 | struct workspace *to) |
| 1151 | { |
| 1152 | struct weston_output *output; |
| 1153 | |
| 1154 | int dir; |
| 1155 | |
| 1156 | if (index > shell->workspaces.current) |
| 1157 | dir = -1; |
| 1158 | else |
| 1159 | dir = 1; |
| 1160 | |
| 1161 | shell->workspaces.current = index; |
| 1162 | |
| 1163 | shell->workspaces.anim_dir = dir; |
| 1164 | shell->workspaces.anim_from = from; |
| 1165 | shell->workspaces.anim_to = to; |
| 1166 | shell->workspaces.anim_current = 0.0; |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1167 | shell->workspaces.anim_timestamp = (struct timespec) { 0 }; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1168 | |
| 1169 | output = container_of(shell->compositor->output_list.next, |
| 1170 | struct weston_output, link); |
| 1171 | wl_list_insert(&output->animation_list, |
| 1172 | &shell->workspaces.animation.link); |
| 1173 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1174 | weston_layer_set_position(&to->layer, WESTON_LAYER_POSITION_NORMAL); |
| 1175 | weston_layer_set_position(&from->layer, WESTON_LAYER_POSITION_NORMAL - 1); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1176 | |
| 1177 | workspace_translate_in(to, 0); |
| 1178 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1179 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1180 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1181 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1182 | } |
| 1183 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1184 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1185 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1186 | struct workspace *from, struct workspace *to) |
| 1187 | { |
| 1188 | shell->workspaces.current = index; |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1189 | weston_layer_set_position(&to->layer, WESTON_LAYER_POSITION_NORMAL); |
| 1190 | weston_layer_unset_position(&from->layer); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1194 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1195 | { |
| 1196 | struct workspace *from; |
| 1197 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1198 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1199 | |
| 1200 | if (index == shell->workspaces.current) |
| 1201 | return; |
| 1202 | |
| 1203 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1204 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1205 | return; |
| 1206 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1207 | from = get_current_workspace(shell); |
| 1208 | to = get_workspace(shell, index); |
| 1209 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1210 | if (shell->workspaces.anim_from == to && |
| 1211 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1212 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1213 | reverse_workspace_change_animation(shell, index, from, to); |
| 1214 | return; |
| 1215 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1216 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1217 | if (shell->workspaces.anim_to != NULL) |
| 1218 | finish_workspace_change_animation(shell, |
| 1219 | shell->workspaces.anim_from, |
| 1220 | shell->workspaces.anim_to); |
| 1221 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1222 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1223 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1224 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1225 | wl_list_for_each(state, &from->focus_list, link) |
| 1226 | if (state->keyboard_focus) |
| 1227 | animate_focus_change(shell, from, |
| 1228 | get_default_view(state->keyboard_focus), NULL); |
| 1229 | |
| 1230 | wl_list_for_each(state, &to->focus_list, link) |
| 1231 | if (state->keyboard_focus) |
| 1232 | animate_focus_change(shell, to, |
| 1233 | NULL, get_default_view(state->keyboard_focus)); |
| 1234 | } |
| 1235 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1236 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1237 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1238 | else |
| 1239 | animate_workspace_change(shell, index, from, to); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1240 | } |
| 1241 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1242 | static bool |
| 1243 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1244 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1245 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1246 | struct wl_list *e; |
| 1247 | |
| 1248 | if (wl_list_empty(list)) |
| 1249 | return false; |
| 1250 | |
| 1251 | e = list->next; |
| 1252 | |
| 1253 | if (e->next != list) |
| 1254 | return false; |
| 1255 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1256 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | static void |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 1260 | surface_keyboard_focus_lost(struct weston_surface *surface) |
| 1261 | { |
| 1262 | struct weston_compositor *compositor = surface->compositor; |
| 1263 | struct weston_seat *seat; |
| 1264 | struct weston_surface *focus; |
| 1265 | |
| 1266 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 1267 | struct weston_keyboard *keyboard = |
| 1268 | weston_seat_get_keyboard(seat); |
| 1269 | |
| 1270 | if (!keyboard) |
| 1271 | continue; |
| 1272 | |
| 1273 | focus = weston_surface_get_main_surface(keyboard->focus); |
| 1274 | if (focus == surface) |
| 1275 | weston_keyboard_set_focus(keyboard, NULL); |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1280 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1281 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1282 | unsigned int index) |
| 1283 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1284 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1285 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1286 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1287 | struct shell_surface *shsurf; |
| 1288 | struct workspace *from; |
| 1289 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1290 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1291 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1292 | surface = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1293 | view = get_default_view(surface); |
| 1294 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1295 | index == shell->workspaces.current || |
| 1296 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1297 | return; |
| 1298 | |
| 1299 | from = get_current_workspace(shell); |
| 1300 | to = get_workspace(shell, index); |
| 1301 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1302 | weston_layer_entry_remove(&view->layer_link); |
| 1303 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1304 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1305 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1306 | if (shsurf != NULL) |
| 1307 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1308 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1309 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1310 | drop_focus_state(shell, from, surface); |
| 1311 | |
| 1312 | if (shell->workspaces.anim_from == to && |
| 1313 | shell->workspaces.anim_to == from) { |
| 1314 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1315 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1316 | return; |
| 1317 | } |
| 1318 | |
| 1319 | if (shell->workspaces.anim_to != NULL) |
| 1320 | finish_workspace_change_animation(shell, |
| 1321 | shell->workspaces.anim_from, |
| 1322 | shell->workspaces.anim_to); |
| 1323 | |
| 1324 | if (workspace_is_empty(from) && |
| 1325 | workspace_has_only(to, surface)) |
| 1326 | update_workspace(shell, index, from, to); |
| 1327 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1328 | if (shsurf != NULL && |
| 1329 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1330 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1331 | &shsurf->workspace_transform.link); |
| 1332 | |
| 1333 | animate_workspace_change(shell, index, from, to); |
| 1334 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1335 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1336 | state = ensure_focus_state(shell, seat); |
| 1337 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1338 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | static void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 1342 | touch_move_grab_down(struct weston_touch_grab *grab, |
| 1343 | const struct timespec *time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1344 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1345 | { |
| 1346 | } |
| 1347 | |
| 1348 | static void |
Alexandros Frantzis | 27a51b8 | 2017-11-16 18:20:59 +0200 | [diff] [blame] | 1349 | touch_move_grab_up(struct weston_touch_grab *grab, const struct timespec *time, |
| 1350 | int touch_id) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1351 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1352 | struct weston_touch_move_grab *move = |
| 1353 | (struct weston_touch_move_grab *) container_of( |
| 1354 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1355 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1356 | if (touch_id == 0) |
| 1357 | move->active = 0; |
| 1358 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1359 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1360 | shell_touch_grab_end(&move->base); |
| 1361 | free(move); |
| 1362 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | static void |
Alexandros Frantzis | 7d2abcf | 2017-11-16 18:21:00 +0200 | [diff] [blame] | 1366 | touch_move_grab_motion(struct weston_touch_grab *grab, |
| 1367 | const struct timespec *time, int touch_id, |
| 1368 | wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1369 | { |
| 1370 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1371 | struct shell_surface *shsurf = move->base.shsurf; |
| 1372 | struct weston_surface *es; |
| 1373 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1374 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1375 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1376 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1377 | return; |
| 1378 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1379 | es = weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1380 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1381 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1382 | |
| 1383 | weston_compositor_schedule_repaint(es->compositor); |
| 1384 | } |
| 1385 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1386 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1387 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1388 | { |
| 1389 | } |
| 1390 | |
| 1391 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1392 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1393 | { |
| 1394 | struct weston_touch_move_grab *move = |
| 1395 | (struct weston_touch_move_grab *) container_of( |
| 1396 | grab, struct shell_touch_grab, grab); |
| 1397 | |
| 1398 | shell_touch_grab_end(&move->base); |
| 1399 | free(move); |
| 1400 | } |
| 1401 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1402 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1403 | touch_move_grab_down, |
| 1404 | touch_move_grab_up, |
| 1405 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1406 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1407 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1408 | }; |
| 1409 | |
| 1410 | static int |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1411 | surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1412 | { |
| 1413 | struct weston_touch_move_grab *move; |
| 1414 | |
| 1415 | if (!shsurf) |
| 1416 | return -1; |
| 1417 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1418 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1419 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1420 | return 0; |
| 1421 | |
| 1422 | move = malloc(sizeof *move); |
| 1423 | if (!move) |
| 1424 | return -1; |
| 1425 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1426 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1427 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1428 | touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1429 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1430 | touch->grab_y; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1431 | |
| 1432 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1433 | touch); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1434 | |
| 1435 | return 0; |
| 1436 | } |
| 1437 | |
| 1438 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1439 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1440 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | static void |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1444 | noop_grab_axis(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 1445 | const struct timespec *time, |
| 1446 | struct weston_pointer_axis_event *event) |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1447 | { |
| 1448 | } |
| 1449 | |
| 1450 | static void |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1451 | noop_grab_axis_source(struct weston_pointer_grab *grab, |
| 1452 | uint32_t source) |
| 1453 | { |
| 1454 | } |
| 1455 | |
| 1456 | static void |
| 1457 | noop_grab_frame(struct weston_pointer_grab *grab) |
| 1458 | { |
| 1459 | } |
| 1460 | |
| 1461 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1462 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1463 | { |
| 1464 | struct shell_surface *shsurf = move->base.shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1465 | struct weston_surface *surface = |
| 1466 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1467 | struct weston_pointer *pointer = move->base.grab.pointer; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1468 | int x, y, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1469 | const int safety = 50; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1470 | pixman_rectangle32_t area; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1471 | struct weston_geometry geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1472 | |
| 1473 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1474 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1475 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1476 | if (shsurf->shell->panel_position == |
| 1477 | WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1478 | get_output_work_area(shsurf->shell, surface->output, &area); |
| 1479 | geometry = |
| 1480 | weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1481 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1482 | bottom = y + geometry.height + geometry.y; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1483 | if (bottom - safety < area.y) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1484 | y = area.y + safety - geometry.height |
| 1485 | - geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1486 | |
| 1487 | if (move->client_initiated && |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1488 | y + geometry.y < area.y) |
| 1489 | y = area.y - geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1490 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1491 | |
| 1492 | *cx = x; |
| 1493 | *cy = y; |
| 1494 | } |
| 1495 | |
| 1496 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 1497 | move_grab_motion(struct weston_pointer_grab *grab, |
| 1498 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1499 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1500 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1501 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1502 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1503 | struct shell_surface *shsurf = move->base.shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1504 | struct weston_surface *surface; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1505 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1506 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1507 | weston_pointer_move(pointer, event); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1508 | if (!shsurf) |
| 1509 | return; |
| 1510 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1511 | surface = weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 1512 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1513 | constrain_position(move, &cx, &cy); |
| 1514 | |
| 1515 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1516 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1517 | weston_compositor_schedule_repaint(surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1521 | move_grab_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 1522 | const struct timespec *time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1523 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1524 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1525 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1526 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1527 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1528 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1529 | if (pointer->button_count == 0 && |
| 1530 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1531 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1532 | free(grab); |
| 1533 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1534 | } |
| 1535 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1536 | static void |
| 1537 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1538 | { |
| 1539 | struct shell_grab *shell_grab = |
| 1540 | container_of(grab, struct shell_grab, grab); |
| 1541 | |
| 1542 | shell_grab_end(shell_grab); |
| 1543 | free(grab); |
| 1544 | } |
| 1545 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1546 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1547 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1548 | move_grab_motion, |
| 1549 | move_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1550 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1551 | noop_grab_axis_source, |
| 1552 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1553 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1554 | }; |
| 1555 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1556 | static int |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1557 | surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 1558 | bool client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1559 | { |
| 1560 | struct weston_move_grab *move; |
| 1561 | |
| 1562 | if (!shsurf) |
| 1563 | return -1; |
| 1564 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1565 | if (shsurf->grabbed || |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1566 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1567 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1568 | return 0; |
| 1569 | |
| 1570 | move = malloc(sizeof *move); |
| 1571 | if (!move) |
| 1572 | return -1; |
| 1573 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1574 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1575 | pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1576 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1577 | pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1578 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1579 | |
| 1580 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1581 | pointer, WESTON_DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1582 | |
| 1583 | return 0; |
| 1584 | } |
| 1585 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1586 | struct weston_resize_grab { |
| 1587 | struct shell_grab base; |
| 1588 | uint32_t edges; |
| 1589 | int32_t width, height; |
| 1590 | }; |
| 1591 | |
| 1592 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 1593 | resize_grab_motion(struct weston_pointer_grab *grab, |
| 1594 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1595 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1596 | { |
| 1597 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1598 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1599 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1600 | int32_t width, height; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1601 | struct weston_size min_size, max_size; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1602 | wl_fixed_t from_x, from_y; |
| 1603 | wl_fixed_t to_x, to_y; |
| 1604 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1605 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1606 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1607 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1608 | return; |
| 1609 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1610 | weston_view_from_global_fixed(shsurf->view, |
| 1611 | pointer->grab_x, pointer->grab_y, |
| 1612 | &from_x, &from_y); |
| 1613 | weston_view_from_global_fixed(shsurf->view, |
| 1614 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1615 | |
| 1616 | width = resize->width; |
| 1617 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1618 | width += wl_fixed_to_int(from_x - to_x); |
| 1619 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1620 | width += wl_fixed_to_int(to_x - from_x); |
| 1621 | } |
| 1622 | |
| 1623 | height = resize->height; |
| 1624 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1625 | height += wl_fixed_to_int(from_y - to_y); |
| 1626 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1627 | height += wl_fixed_to_int(to_y - from_y); |
| 1628 | } |
| 1629 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1630 | max_size = weston_desktop_surface_get_max_size(shsurf->desktop_surface); |
| 1631 | min_size = weston_desktop_surface_get_min_size(shsurf->desktop_surface); |
| 1632 | |
| 1633 | min_size.width = MAX(1, min_size.width); |
| 1634 | min_size.height = MAX(1, min_size.height); |
| 1635 | |
| 1636 | if (width < min_size.width) |
| 1637 | width = min_size.width; |
| 1638 | else if (max_size.width > 0 && width > max_size.width) |
| 1639 | width = max_size.width; |
| 1640 | if (height < min_size.height) |
| 1641 | height = min_size.height; |
| 1642 | else if (max_size.width > 0 && width > max_size.width) |
| 1643 | width = max_size.width; |
| 1644 | weston_desktop_surface_set_size(shsurf->desktop_surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1648 | resize_grab_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 1649 | const struct timespec *time, |
| 1650 | uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1651 | { |
| 1652 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1653 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1654 | enum wl_pointer_button_state state = state_w; |
| 1655 | |
| 1656 | if (pointer->button_count == 0 && |
| 1657 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Greg V | ec3f779 | 2018-11-08 00:24:56 +0300 | [diff] [blame] | 1658 | if (resize->base.shsurf != NULL) { |
| 1659 | struct weston_desktop_surface *desktop_surface = |
| 1660 | resize->base.shsurf->desktop_surface; |
| 1661 | weston_desktop_surface_set_resizing(desktop_surface, |
| 1662 | false); |
| 1663 | } |
| 1664 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1665 | shell_grab_end(&resize->base); |
| 1666 | free(grab); |
| 1667 | } |
| 1668 | } |
| 1669 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1670 | static void |
| 1671 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1672 | { |
| 1673 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1674 | |
Greg V | ec3f779 | 2018-11-08 00:24:56 +0300 | [diff] [blame] | 1675 | if (resize->base.shsurf != NULL) { |
| 1676 | struct weston_desktop_surface *desktop_surface = |
| 1677 | resize->base.shsurf->desktop_surface; |
| 1678 | weston_desktop_surface_set_resizing(desktop_surface, false); |
| 1679 | } |
| 1680 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1681 | shell_grab_end(&resize->base); |
| 1682 | free(grab); |
| 1683 | } |
| 1684 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1685 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1686 | noop_grab_focus, |
| 1687 | resize_grab_motion, |
| 1688 | resize_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1689 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1690 | noop_grab_axis_source, |
| 1691 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1692 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1693 | }; |
| 1694 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1695 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1696 | static int |
| 1697 | surface_resize(struct shell_surface *shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1698 | struct weston_pointer *pointer, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1699 | { |
| 1700 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1701 | const unsigned resize_topbottom = |
| 1702 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1703 | const unsigned resize_leftright = |
| 1704 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1705 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1706 | struct weston_geometry geometry; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1707 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1708 | if (shsurf->grabbed || |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1709 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1710 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1711 | return 0; |
| 1712 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1713 | /* Check for invalid edge combinations. */ |
| 1714 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1715 | (edges & resize_topbottom) == resize_topbottom || |
| 1716 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1717 | return 0; |
| 1718 | |
| 1719 | resize = malloc(sizeof *resize); |
| 1720 | if (!resize) |
| 1721 | return -1; |
| 1722 | |
| 1723 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1724 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1725 | geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
| 1726 | resize->width = geometry.width; |
| 1727 | resize->height = geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1728 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1729 | shsurf->resize_edges = edges; |
Philipp Kerling | c5f1241 | 2017-07-28 14:11:58 +0200 | [diff] [blame] | 1730 | weston_desktop_surface_set_resizing(shsurf->desktop_surface, true); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1731 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1732 | pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1733 | |
| 1734 | return 0; |
| 1735 | } |
| 1736 | |
| 1737 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1738 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1739 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1740 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1741 | struct weston_pointer *pointer = base->pointer; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1742 | struct weston_desktop_surface *desktop_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1743 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1744 | wl_fixed_t sx, sy; |
| 1745 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1746 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1747 | pointer->x, pointer->y, |
| 1748 | &sx, &sy); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1749 | desktop_surface = weston_surface_get_desktop_surface(view->surface); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1750 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1751 | if (!grab->shsurf || grab->shsurf->desktop_surface != desktop_surface) { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1752 | shell_grab_end(grab); |
| 1753 | free(grab); |
| 1754 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 1758 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, |
| 1759 | const struct timespec *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, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 1767 | const struct timespec *time, |
| 1768 | uint32_t button, uint32_t state) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1769 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1770 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1771 | struct shell_surface *shsurf = grab->shsurf; |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1772 | struct weston_pointer *pointer = grab->grab.pointer; |
| 1773 | struct weston_seat *seat = pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1774 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1775 | if (shsurf && button == BTN_LEFT && state) { |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 1776 | activate(shsurf->shell, shsurf->view, seat, |
| 1777 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1778 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1779 | } else if (shsurf && button == BTN_RIGHT && state) { |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 1780 | activate(shsurf->shell, shsurf->view, seat, |
| 1781 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 1782 | surface_rotate(shsurf, pointer); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1783 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1784 | } |
| 1785 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1786 | static void |
| 1787 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1788 | { |
| 1789 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1790 | |
| 1791 | shell_grab_end(grab); |
| 1792 | free(grab); |
| 1793 | } |
| 1794 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1795 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1796 | busy_cursor_grab_focus, |
| 1797 | busy_cursor_grab_motion, |
| 1798 | busy_cursor_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1799 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1800 | noop_grab_axis_source, |
| 1801 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1802 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1803 | }; |
| 1804 | |
| 1805 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1806 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1807 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1808 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1809 | struct weston_view *view = pointer->focus; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1810 | struct shell_surface *shsurf; |
| 1811 | struct weston_desktop_client *client; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1812 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1813 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1814 | return; |
| 1815 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1816 | shsurf = get_shell_surface(view->surface); |
| 1817 | if (!shsurf) |
| 1818 | return; |
| 1819 | |
| 1820 | client = weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 1821 | |
| 1822 | if (shsurf->unresponsive) |
| 1823 | set_busy_cursor(shsurf, pointer); |
| 1824 | else |
| 1825 | weston_desktop_client_ping(client); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | static void |
Marius Vlad | ab39e1d | 2021-03-05 21:40:22 +0200 | [diff] [blame] | 1829 | shell_surface_deactivate(struct shell_surface *shsurf) |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1830 | { |
| 1831 | if (--shsurf->focus_count == 0) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1832 | weston_desktop_surface_set_activated(shsurf->desktop_surface, false); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | static void |
Marius Vlad | ab39e1d | 2021-03-05 21:40:22 +0200 | [diff] [blame] | 1836 | shell_surface_activate(struct shell_surface *shsurf) |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1837 | { |
| 1838 | if (shsurf->focus_count++ == 0) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1839 | weston_desktop_surface_set_activated(shsurf->desktop_surface, true); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1840 | } |
| 1841 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1842 | /* The surface will be inserted into the list immediately after the link |
| 1843 | * returned by this function (i.e. will be stacked immediately above the |
| 1844 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1845 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1846 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 1847 | { |
| 1848 | struct workspace *ws; |
| 1849 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1850 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) && |
| 1851 | !shsurf->state.lowered) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 1852 | return &shsurf->shell->fullscreen_layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1853 | } |
| 1854 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1855 | /* Move the surface to a normal workspace layer so that surfaces |
| 1856 | * which were previously fullscreen or transient are no longer |
| 1857 | * rendered on top. */ |
| 1858 | ws = get_current_workspace(shsurf->shell); |
| 1859 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1862 | static void |
| 1863 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 1864 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1865 | weston_desktop_surface_propagate_layer(shsurf->desktop_surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1868 | /* 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] | 1869 | * geometry to ensure the changes are redrawn. |
| 1870 | * |
| 1871 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 1872 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1873 | static void |
| 1874 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 1875 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1876 | struct weston_surface *surface = |
| 1877 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1878 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1879 | |
| 1880 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 1881 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 1882 | if (new_layer_link == NULL) |
| 1883 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1884 | if (new_layer_link == &shsurf->view->layer_link) |
| 1885 | return; |
| 1886 | |
| 1887 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1888 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 1889 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1890 | weston_view_geometry_dirty(shsurf->view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1891 | weston_surface_damage(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1892 | |
| 1893 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1894 | } |
| 1895 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1896 | static void |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame] | 1897 | notify_output_destroy(struct wl_listener *listener, void *data) |
| 1898 | { |
| 1899 | struct shell_surface *shsurf = |
| 1900 | container_of(listener, |
| 1901 | struct shell_surface, output_destroy_listener); |
| 1902 | |
| 1903 | shsurf->output = NULL; |
| 1904 | shsurf->output_destroy_listener.notify = NULL; |
| 1905 | } |
| 1906 | |
| 1907 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1908 | shell_surface_set_output(struct shell_surface *shsurf, |
| 1909 | struct weston_output *output) |
| 1910 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1911 | struct weston_surface *es = |
| 1912 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1913 | |
| 1914 | /* get the default output, if the client set it as NULL |
Abdur Rehman | 7f1da1f | 2017-01-01 19:46:33 +0500 | [diff] [blame] | 1915 | check whether the output is available */ |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1916 | if (output) |
| 1917 | shsurf->output = output; |
| 1918 | else if (es->output) |
| 1919 | shsurf->output = es->output; |
| 1920 | else |
| 1921 | shsurf->output = get_default_output(es->compositor); |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame] | 1922 | |
| 1923 | if (shsurf->output_destroy_listener.notify) { |
| 1924 | wl_list_remove(&shsurf->output_destroy_listener.link); |
| 1925 | shsurf->output_destroy_listener.notify = NULL; |
| 1926 | } |
| 1927 | |
| 1928 | if (!shsurf->output) |
| 1929 | return; |
| 1930 | |
| 1931 | shsurf->output_destroy_listener.notify = notify_output_destroy; |
| 1932 | wl_signal_add(&shsurf->output->destroy_signal, |
| 1933 | &shsurf->output_destroy_listener); |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 1937 | weston_view_set_initial_position(struct weston_view *view, |
| 1938 | struct desktop_shell *shell); |
| 1939 | |
| 1940 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1941 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1942 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 1943 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1944 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 1945 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 1946 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1947 | if (shsurf->fullscreen.black_view) |
| 1948 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 1949 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 1950 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 1951 | if (shsurf->saved_position_valid) |
| 1952 | weston_view_set_position(shsurf->view, |
| 1953 | shsurf->saved_x, shsurf->saved_y); |
| 1954 | else |
| 1955 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Quentin Glidic | 920cf04 | 2016-08-16 14:26:20 +0200 | [diff] [blame] | 1956 | shsurf->saved_position_valid = false; |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 1957 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 1958 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1959 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1960 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 1961 | shsurf->saved_rotation_valid = false; |
| 1962 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1963 | } |
| 1964 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 1965 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1966 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 1967 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1968 | struct weston_surface *surface = |
| 1969 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 1970 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 1971 | /* undo all maximized things here */ |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame] | 1972 | shell_surface_set_output(shsurf, get_default_output(surface->compositor)); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 1973 | |
| 1974 | if (shsurf->saved_position_valid) |
| 1975 | weston_view_set_position(shsurf->view, |
| 1976 | shsurf->saved_x, shsurf->saved_y); |
| 1977 | else |
| 1978 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Quentin Glidic | 920cf04 | 2016-08-16 14:26:20 +0200 | [diff] [blame] | 1979 | shsurf->saved_position_valid = false; |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 1980 | |
| 1981 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1982 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 1983 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 1984 | shsurf->saved_rotation_valid = false; |
| 1985 | } |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 1986 | } |
| 1987 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1988 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 1989 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 1990 | { |
| 1991 | struct shell_surface *shsurf; |
| 1992 | struct workspace *current_ws; |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 1993 | struct weston_view *view; |
Jonas Ådahl | 56958aa | 2021-10-01 11:12:21 +0200 | [diff] [blame] | 1994 | struct weston_subsurface *subsurface; |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 1995 | |
| 1996 | view = get_default_view(surface); |
| 1997 | if (!view) |
| 1998 | return; |
| 1999 | |
| 2000 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2001 | |
| 2002 | shsurf = get_shell_surface(surface); |
| 2003 | current_ws = get_current_workspace(shsurf->shell); |
| 2004 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2005 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2006 | 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] | 2007 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2008 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 2009 | surface_keyboard_focus_lost(surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2010 | |
| 2011 | shell_surface_update_child_surface_layers(shsurf); |
Jonas Ådahl | 56958aa | 2021-10-01 11:12:21 +0200 | [diff] [blame] | 2012 | |
| 2013 | weston_view_damage_below(shsurf->view); |
| 2014 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 2015 | wl_list_for_each(view, &subsurface->surface->views, surface_link) |
| 2016 | weston_view_damage_below(view); |
| 2017 | } |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2018 | } |
| 2019 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2020 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2021 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2022 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2023 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2024 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2025 | } |
| 2026 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2027 | static int |
| 2028 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2029 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2030 | struct weston_view *fs_view = surface->committed_private; |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2031 | struct weston_surface *fs_surface = fs_view->surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2032 | int n; |
| 2033 | int rem; |
| 2034 | int ret; |
| 2035 | |
| 2036 | n = snprintf(buf, len, "black background surface for "); |
| 2037 | if (n < 0) |
| 2038 | return n; |
| 2039 | |
| 2040 | rem = (int)len - n; |
| 2041 | if (rem < 0) |
| 2042 | rem = 0; |
| 2043 | |
| 2044 | if (fs_surface->get_label) |
| 2045 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2046 | else |
| 2047 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2048 | |
| 2049 | if (ret < 0) |
| 2050 | return n; |
| 2051 | |
| 2052 | return n + ret; |
| 2053 | } |
| 2054 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2055 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2056 | 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] | 2057 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2058 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2059 | create_black_surface(struct weston_compositor *ec, |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2060 | struct weston_view *fs_view, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2061 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2062 | { |
| 2063 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2064 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2065 | |
| 2066 | surface = weston_surface_create(ec); |
| 2067 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2068 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2069 | return NULL; |
| 2070 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2071 | view = weston_view_create(surface); |
| 2072 | if (surface == NULL) { |
| 2073 | weston_log("no memory\n"); |
| 2074 | weston_surface_destroy(surface); |
| 2075 | return NULL; |
| 2076 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2077 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2078 | surface->committed = black_surface_committed; |
| 2079 | surface->committed_private = fs_view; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2080 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2081 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2082 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2083 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2084 | pixman_region32_fini(&surface->input); |
| 2085 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2086 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2087 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2088 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2089 | |
| 2090 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2091 | } |
| 2092 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2093 | static void |
| 2094 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2095 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2096 | struct weston_surface *surface = |
| 2097 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2098 | struct weston_output *output = shsurf->fullscreen_output; |
| 2099 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2100 | assert(weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2101 | |
| 2102 | if (!shsurf->fullscreen.black_view) |
| 2103 | shsurf->fullscreen.black_view = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2104 | create_black_surface(surface->compositor, |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2105 | shsurf->view, |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2106 | output->x, output->y, |
| 2107 | output->width, |
| 2108 | output->height); |
| 2109 | |
| 2110 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2111 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2112 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2113 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2114 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2115 | weston_surface_damage(surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2116 | |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 2117 | shsurf->fullscreen.black_view->is_mapped = true; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2118 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2119 | } |
| 2120 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2121 | /* Create black surface and append it to the associated fullscreen surface. |
| 2122 | * Handle size dismatch and positioning according to the method. */ |
| 2123 | static void |
| 2124 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2125 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2126 | struct weston_surface *surface = |
| 2127 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2128 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2129 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2130 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2131 | weston_layer_entry_remove(&shsurf->view->layer_link); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2132 | weston_layer_entry_insert(&shsurf->shell->fullscreen_layer.view_list, |
| 2133 | &shsurf->view->layer_link); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2134 | |
Pekka Paalanen | c63acc4 | 2018-05-02 10:21:58 +0200 | [diff] [blame] | 2135 | if (!shsurf->fullscreen_output) { |
| 2136 | /* If there is no output, there's not much we can do. |
| 2137 | * Position the window somewhere, whatever. */ |
| 2138 | weston_view_set_position(shsurf->view, 0, 0); |
| 2139 | return; |
| 2140 | } |
| 2141 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2142 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2143 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2144 | surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2145 | &surf_width, &surf_height); |
| 2146 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2147 | if (surface->buffer_ref.buffer) |
| 2148 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2149 | } |
| 2150 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2151 | static void |
| 2152 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2153 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2154 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2155 | } |
| 2156 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2157 | static void |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 2158 | desktop_shell_destroy_seat(struct shell_seat *shseat) |
| 2159 | { |
Marius Vlad | f3584cf | 2021-10-26 19:40:44 +0300 | [diff] [blame] | 2160 | |
Marius Vlad | a7392c8 | 2021-08-26 16:38:43 +0300 | [diff] [blame] | 2161 | wl_list_remove(&shseat->keyboard_focus_listener.link); |
| 2162 | wl_list_remove(&shseat->caps_changed_listener.link); |
| 2163 | wl_list_remove(&shseat->pointer_focus_listener.link); |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 2164 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2165 | |
| 2166 | wl_list_remove(&shseat->link); |
| 2167 | free(shseat); |
| 2168 | } |
| 2169 | |
| 2170 | static void |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2171 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2172 | { |
| 2173 | struct shell_seat *shseat = |
| 2174 | container_of(listener, |
| 2175 | struct shell_seat, seat_destroy_listener); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2176 | |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 2177 | desktop_shell_destroy_seat(shseat); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2178 | } |
| 2179 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2180 | static void |
| 2181 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 2182 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2183 | struct weston_pointer *pointer; |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2184 | struct shell_seat *seat; |
| 2185 | |
| 2186 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2187 | pointer = weston_seat_get_pointer(seat->seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2188 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2189 | if (pointer && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2190 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2191 | wl_signal_add(&pointer->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2192 | &seat->pointer_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2193 | } else if (!pointer) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 2194 | wl_list_remove(&seat->pointer_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2195 | wl_list_init(&seat->pointer_focus_listener.link); |
| 2196 | } |
| 2197 | } |
| 2198 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2199 | static struct shell_seat * |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 2200 | create_shell_seat(struct desktop_shell *shell, struct weston_seat *seat) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2201 | { |
| 2202 | struct shell_seat *shseat; |
| 2203 | |
| 2204 | shseat = calloc(1, sizeof *shseat); |
| 2205 | if (!shseat) { |
| 2206 | weston_log("no memory to allocate shell seat\n"); |
| 2207 | return NULL; |
| 2208 | } |
| 2209 | |
| 2210 | shseat->seat = seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2211 | |
| 2212 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2213 | wl_signal_add(&seat->destroy_signal, |
| 2214 | &shseat->seat_destroy_listener); |
| 2215 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2216 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 2217 | |
| 2218 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 2219 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 2220 | |
| 2221 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 2222 | wl_signal_add(&seat->updated_caps_signal, |
| 2223 | &shseat->caps_changed_listener); |
| 2224 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 2225 | |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 2226 | wl_list_insert(&shell->seat_list, &shseat->link); |
| 2227 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2228 | return shseat; |
| 2229 | } |
| 2230 | |
| 2231 | static struct shell_seat * |
| 2232 | get_shell_seat(struct weston_seat *seat) |
| 2233 | { |
| 2234 | struct wl_listener *listener; |
| 2235 | |
| 2236 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2237 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2238 | |
| 2239 | return container_of(listener, |
| 2240 | struct shell_seat, seat_destroy_listener); |
| 2241 | } |
| 2242 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2243 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2244 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 2245 | { |
| 2246 | struct shell_surface *shsurf = data; |
| 2247 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2248 | weston_surface_destroy(shsurf->view->surface); |
Pekka Paalanen | 9962800 | 2018-05-22 12:48:35 +0300 | [diff] [blame] | 2249 | |
| 2250 | if (shsurf->output_destroy_listener.notify) { |
| 2251 | wl_list_remove(&shsurf->output_destroy_listener.link); |
| 2252 | shsurf->output_destroy_listener.notify = NULL; |
| 2253 | } |
| 2254 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2255 | free(shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2259 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 2260 | { |
| 2261 | struct shell_surface *shsurf = data; |
| 2262 | struct wl_event_loop *loop; |
| 2263 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2264 | loop = wl_display_get_event_loop(shsurf->shell->compositor->wl_display); |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2265 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2266 | if (weston_view_is_mapped(shsurf->view)) { |
Tomohito Esaki | 5898cd3 | 2019-04-01 17:50:14 +0900 | [diff] [blame] | 2267 | weston_view_unmap(shsurf->view); |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2268 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2269 | } |
| 2270 | } |
| 2271 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 2272 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2273 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2274 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2275 | if (weston_surface_is_desktop_surface(surface)) { |
| 2276 | struct weston_desktop_surface *desktop_surface = |
| 2277 | weston_surface_get_desktop_surface(surface); |
| 2278 | return weston_desktop_surface_get_user_data(desktop_surface); |
| 2279 | } |
| 2280 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2281 | } |
| 2282 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2283 | /* |
| 2284 | * libweston-desktop |
| 2285 | */ |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2286 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2287 | static void |
| 2288 | desktop_surface_added(struct weston_desktop_surface *desktop_surface, |
| 2289 | void *shell) |
| 2290 | { |
| 2291 | struct weston_desktop_client *client = |
| 2292 | weston_desktop_surface_get_client(desktop_surface); |
| 2293 | struct wl_client *wl_client = |
| 2294 | weston_desktop_client_get_client(client); |
| 2295 | struct weston_view *view; |
| 2296 | struct shell_surface *shsurf; |
| 2297 | struct weston_surface *surface = |
| 2298 | weston_desktop_surface_get_surface(desktop_surface); |
| 2299 | |
| 2300 | view = weston_desktop_surface_create_view(desktop_surface); |
| 2301 | if (!view) |
| 2302 | return; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2303 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2304 | shsurf = calloc(1, sizeof *shsurf); |
| 2305 | if (!shsurf) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2306 | if (wl_client) |
| 2307 | wl_client_post_no_memory(wl_client); |
| 2308 | else |
| 2309 | weston_log("no memory to allocate shell surface\n"); |
| 2310 | return; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2311 | } |
| 2312 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2313 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2314 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2315 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2316 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2317 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2318 | shsurf->saved_rotation_valid = false; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2319 | shsurf->desktop_surface = desktop_surface; |
| 2320 | shsurf->view = view; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2321 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2322 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2323 | |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame] | 2324 | shell_surface_set_output( |
| 2325 | shsurf, get_default_output(shsurf->shell->compositor)); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2326 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2327 | wl_signal_init(&shsurf->destroy_signal); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2328 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2329 | /* empty when not in use */ |
| 2330 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2331 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2332 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2333 | wl_list_init(&shsurf->workspace_transform.link); |
| 2334 | |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2335 | /* |
| 2336 | * initialize list as well as link. The latter allows to use |
| 2337 | * wl_list_remove() even when this surface is not in another list. |
| 2338 | */ |
| 2339 | wl_list_init(&shsurf->children_list); |
| 2340 | wl_list_init(&shsurf->children_link); |
| 2341 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2342 | weston_desktop_surface_set_user_data(desktop_surface, shsurf); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2343 | } |
| 2344 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2345 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2346 | desktop_surface_removed(struct weston_desktop_surface *desktop_surface, |
| 2347 | void *shell) |
| 2348 | { |
| 2349 | struct shell_surface *shsurf = |
| 2350 | weston_desktop_surface_get_user_data(desktop_surface); |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2351 | struct shell_surface *shsurf_child, *tmp; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2352 | struct weston_surface *surface = |
| 2353 | weston_desktop_surface_get_surface(desktop_surface); |
Marius Vlad | f12697b | 2021-03-05 21:44:26 +0200 | [diff] [blame] | 2354 | struct weston_seat *seat; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2355 | |
| 2356 | if (!shsurf) |
| 2357 | return; |
| 2358 | |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2359 | wl_list_for_each_safe(shsurf_child, tmp, &shsurf->children_list, children_link) { |
| 2360 | wl_list_remove(&shsurf_child->children_link); |
| 2361 | wl_list_init(&shsurf_child->children_link); |
| 2362 | } |
| 2363 | wl_list_remove(&shsurf->children_link); |
| 2364 | |
Marius Vlad | f12697b | 2021-03-05 21:44:26 +0200 | [diff] [blame] | 2365 | wl_list_for_each(seat, &shsurf->shell->compositor->seat_list, link) { |
| 2366 | struct shell_seat *shseat = get_shell_seat(seat); |
| 2367 | /* activate() controls the focused surface activation and |
| 2368 | * removal of a surface requires invalidating the |
| 2369 | * focused_surface to avoid activate() use a stale (and just |
| 2370 | * removed) surface when attempting to de-activate it. It will |
| 2371 | * also update the focused_surface once it has a chance to run. |
| 2372 | */ |
| 2373 | if (surface == shseat->focused_surface) |
| 2374 | shseat->focused_surface = NULL; |
| 2375 | } |
| 2376 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2377 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2378 | |
| 2379 | if (shsurf->fullscreen.black_view) |
| 2380 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2381 | |
| 2382 | weston_surface_set_label_func(surface, NULL); |
| 2383 | weston_desktop_surface_set_user_data(shsurf->desktop_surface, NULL); |
| 2384 | shsurf->desktop_surface = NULL; |
| 2385 | |
Quentin Glidic | f01ecee | 2016-08-16 10:52:46 +0200 | [diff] [blame] | 2386 | weston_desktop_surface_unlink_view(shsurf->view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2387 | if (weston_surface_is_mapped(surface) && |
| 2388 | shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
Erik Kurzinger | 04918f3 | 2021-05-18 11:49:37 -0400 | [diff] [blame] | 2389 | |
Emmanuel Gil Peyrot | eff793a | 2021-07-31 17:25:41 +0200 | [diff] [blame] | 2390 | if (shsurf->shell->compositor->state == WESTON_COMPOSITOR_ACTIVE) { |
| 2391 | pixman_region32_fini(&surface->pending.input); |
| 2392 | pixman_region32_init(&surface->pending.input); |
| 2393 | pixman_region32_fini(&surface->input); |
| 2394 | pixman_region32_init(&surface->input); |
| 2395 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 2396 | fade_out_done, shsurf); |
| 2397 | return; |
| 2398 | } else { |
Marius Vlad | c30cb29 | 2021-08-02 15:47:16 +0300 | [diff] [blame] | 2399 | weston_surface_destroy(surface); |
Emmanuel Gil Peyrot | eff793a | 2021-07-31 17:25:41 +0200 | [diff] [blame] | 2400 | } |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2401 | } |
Erik Kurzinger | 04918f3 | 2021-05-18 11:49:37 -0400 | [diff] [blame] | 2402 | |
Marius Vlad | c30cb29 | 2021-08-02 15:47:16 +0300 | [diff] [blame] | 2403 | weston_view_destroy(shsurf->view); |
Erik Kurzinger | 04918f3 | 2021-05-18 11:49:37 -0400 | [diff] [blame] | 2404 | |
| 2405 | if (shsurf->output_destroy_listener.notify) { |
| 2406 | wl_list_remove(&shsurf->output_destroy_listener.link); |
| 2407 | shsurf->output_destroy_listener.notify = NULL; |
| 2408 | } |
| 2409 | |
| 2410 | free(shsurf); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | static void |
| 2414 | set_maximized_position(struct desktop_shell *shell, |
| 2415 | struct shell_surface *shsurf) |
| 2416 | { |
| 2417 | pixman_rectangle32_t area; |
| 2418 | struct weston_geometry geometry; |
| 2419 | |
| 2420 | get_output_work_area(shell, shsurf->output, &area); |
| 2421 | geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
| 2422 | |
| 2423 | weston_view_set_position(shsurf->view, |
| 2424 | area.x - geometry.x, |
| 2425 | area.y - geometry.y); |
| 2426 | } |
| 2427 | |
| 2428 | static void |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2429 | set_position_from_xwayland(struct shell_surface *shsurf) |
| 2430 | { |
| 2431 | struct weston_geometry geometry; |
| 2432 | float x; |
| 2433 | float y; |
| 2434 | |
| 2435 | assert(shsurf->xwayland.is_set); |
| 2436 | |
| 2437 | geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
| 2438 | x = shsurf->xwayland.x - geometry.x; |
| 2439 | y = shsurf->xwayland.y - geometry.y; |
| 2440 | |
| 2441 | weston_view_set_position(shsurf->view, x, y); |
| 2442 | |
| 2443 | #ifdef WM_DEBUG |
| 2444 | weston_log("%s: XWM %d, %d; geometry %d, %d; view %f, %f\n", |
| 2445 | __func__, shsurf->xwayland.x, shsurf->xwayland.y, |
| 2446 | geometry.x, geometry.y, x, y); |
| 2447 | #endif |
| 2448 | } |
| 2449 | |
| 2450 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2451 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
| 2452 | int32_t sx, int32_t sy) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2453 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2454 | struct weston_surface *surface = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2455 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2456 | struct weston_compositor *compositor = shell->compositor; |
| 2457 | struct weston_seat *seat; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2458 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2459 | /* initial positioning, see also configure() */ |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2460 | if (shsurf->state.fullscreen) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2461 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 2462 | shell_map_fullscreen(shsurf); |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2463 | } else if (shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2464 | set_maximized_position(shell, shsurf); |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2465 | } else if (shsurf->xwayland.is_set) { |
| 2466 | set_position_from_xwayland(shsurf); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 2467 | } else { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2468 | weston_view_set_initial_position(shsurf->view, shell); |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 2469 | } |
| 2470 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2471 | /* Surface stacking order, see also activate(). */ |
| 2472 | shell_surface_update_layer(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2473 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2474 | weston_view_update_transform(shsurf->view); |
| 2475 | shsurf->view->is_mapped = true; |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2476 | if (shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2477 | surface->output = shsurf->output; |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 2478 | weston_view_set_output(shsurf->view, shsurf->output); |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2479 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2480 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2481 | if (!shell->locked) { |
| 2482 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 2483 | activate(shell, shsurf->view, seat, |
| 2484 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
| 2485 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2486 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2487 | if (!shsurf->state.fullscreen && !shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2488 | switch (shell->win_animation_type) { |
| 2489 | case ANIMATION_FADE: |
| 2490 | weston_fade_run(shsurf->view, 0.0, 1.0, 300.0, NULL, NULL); |
| 2491 | break; |
| 2492 | case ANIMATION_ZOOM: |
| 2493 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
| 2494 | break; |
| 2495 | case ANIMATION_NONE: |
| 2496 | default: |
| 2497 | break; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 2498 | } |
| 2499 | } |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2503 | desktop_surface_committed(struct weston_desktop_surface *desktop_surface, |
| 2504 | int32_t sx, int32_t sy, void *data) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2505 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2506 | struct shell_surface *shsurf = |
| 2507 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2508 | struct weston_surface *surface = |
| 2509 | weston_desktop_surface_get_surface(desktop_surface); |
| 2510 | struct weston_view *view = shsurf->view; |
| 2511 | struct desktop_shell *shell = data; |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2512 | bool was_fullscreen; |
| 2513 | bool was_maximized; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2514 | |
| 2515 | if (surface->width == 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2516 | return; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2517 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2518 | was_fullscreen = shsurf->state.fullscreen; |
| 2519 | was_maximized = shsurf->state.maximized; |
| 2520 | |
| 2521 | shsurf->state.fullscreen = |
| 2522 | weston_desktop_surface_get_fullscreen(desktop_surface); |
| 2523 | shsurf->state.maximized = |
| 2524 | weston_desktop_surface_get_maximized(desktop_surface); |
| 2525 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2526 | if (!weston_surface_is_mapped(surface)) { |
| 2527 | map(shell, shsurf, sx, sy); |
| 2528 | surface->is_mapped = true; |
| 2529 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) |
| 2530 | ++surface->ref_count; |
| 2531 | return; |
| 2532 | } |
| 2533 | |
| 2534 | if (sx == 0 && sy == 0 && |
| 2535 | shsurf->last_width == surface->width && |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2536 | shsurf->last_height == surface->height && |
| 2537 | was_fullscreen == shsurf->state.fullscreen && |
| 2538 | was_maximized == shsurf->state.maximized) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2539 | return; |
| 2540 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2541 | if (was_fullscreen) |
| 2542 | unset_fullscreen(shsurf); |
| 2543 | if (was_maximized) |
| 2544 | unset_maximized(shsurf); |
| 2545 | |
Quentin Glidic | 920cf04 | 2016-08-16 14:26:20 +0200 | [diff] [blame] | 2546 | if ((shsurf->state.fullscreen || shsurf->state.maximized) && |
| 2547 | !shsurf->saved_position_valid) { |
| 2548 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2549 | shsurf->saved_y = shsurf->view->geometry.y; |
| 2550 | shsurf->saved_position_valid = true; |
| 2551 | |
| 2552 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2553 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2554 | wl_list_init(&shsurf->rotation.transform.link); |
| 2555 | weston_view_geometry_dirty(shsurf->view); |
| 2556 | shsurf->saved_rotation_valid = true; |
| 2557 | } |
| 2558 | } |
| 2559 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2560 | if (shsurf->state.fullscreen) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2561 | shell_configure_fullscreen(shsurf); |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2562 | } else if (shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2563 | set_maximized_position(shell, shsurf); |
| 2564 | surface->output = shsurf->output; |
| 2565 | } else { |
| 2566 | float from_x, from_y; |
| 2567 | float to_x, to_y; |
| 2568 | float x, y; |
| 2569 | |
| 2570 | if (shsurf->resize_edges) { |
| 2571 | sx = 0; |
| 2572 | sy = 0; |
| 2573 | } |
| 2574 | |
| 2575 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 2576 | sx = shsurf->last_width - surface->width; |
| 2577 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 2578 | sy = shsurf->last_height - surface->height; |
| 2579 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2580 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 2581 | weston_view_to_global_float(shsurf->view, sx, sy, &to_x, &to_y); |
| 2582 | x = shsurf->view->geometry.x + to_x - from_x; |
| 2583 | y = shsurf->view->geometry.y + to_y - from_y; |
| 2584 | |
| 2585 | weston_view_set_position(shsurf->view, x, y); |
| 2586 | } |
| 2587 | |
Emmanuel Gil Peyrot | c394179 | 2017-04-04 18:49:33 +0100 | [diff] [blame] | 2588 | shsurf->last_width = surface->width; |
| 2589 | shsurf->last_height = surface->height; |
| 2590 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2591 | /* XXX: would a fullscreen surface need the same handling? */ |
| 2592 | if (surface->output) { |
| 2593 | wl_list_for_each(view, &surface->views, surface_link) |
| 2594 | weston_view_update_transform(view); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2595 | } |
| 2596 | } |
| 2597 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2598 | static void |
Derek Foreman | 927d9e2 | 2017-10-06 14:37:44 -0500 | [diff] [blame] | 2599 | get_maximized_size(struct shell_surface *shsurf, int32_t *width, int32_t *height) |
| 2600 | { |
| 2601 | struct desktop_shell *shell; |
| 2602 | pixman_rectangle32_t area; |
| 2603 | |
| 2604 | shell = shell_surface_get_shell(shsurf); |
| 2605 | get_output_work_area(shell, shsurf->output, &area); |
| 2606 | |
| 2607 | *width = area.width; |
| 2608 | *height = area.height; |
| 2609 | } |
| 2610 | |
| 2611 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2612 | set_fullscreen(struct shell_surface *shsurf, bool fullscreen, |
| 2613 | struct weston_output *output) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2614 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2615 | struct weston_desktop_surface *desktop_surface = shsurf->desktop_surface; |
| 2616 | struct weston_surface *surface = |
| 2617 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2618 | int32_t width = 0, height = 0; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2619 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2620 | if (fullscreen) { |
| 2621 | /* handle clients launching in fullscreen */ |
| 2622 | if (output == NULL && !weston_surface_is_mapped(surface)) { |
| 2623 | /* Set the output to the one that has focus currently. */ |
| 2624 | output = get_focused_output(surface->compositor); |
| 2625 | } |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 2626 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2627 | shell_surface_set_output(shsurf, output); |
| 2628 | shsurf->fullscreen_output = shsurf->output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2629 | |
Marius Vlad | 6ebda36 | 2020-03-28 00:23:14 +0200 | [diff] [blame] | 2630 | if (shsurf->output) { |
| 2631 | width = shsurf->output->width; |
| 2632 | height = shsurf->output->height; |
| 2633 | } |
Derek Foreman | e1af3d8 | 2017-10-06 14:37:45 -0500 | [diff] [blame] | 2634 | } else if (weston_desktop_surface_get_maximized(desktop_surface)) { |
| 2635 | get_maximized_size(shsurf, &width, &height); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2636 | } |
| 2637 | weston_desktop_surface_set_fullscreen(desktop_surface, fullscreen); |
| 2638 | weston_desktop_surface_set_size(desktop_surface, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2642 | desktop_surface_move(struct weston_desktop_surface *desktop_surface, |
| 2643 | struct weston_seat *seat, uint32_t serial, void *shell) |
| 2644 | { |
| 2645 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2646 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2647 | struct shell_surface *shsurf = |
| 2648 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2649 | struct weston_surface *surface = |
| 2650 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2651 | struct wl_resource *resource = surface->resource; |
| 2652 | struct weston_surface *focus; |
| 2653 | |
| 2654 | if (pointer && |
| 2655 | pointer->focus && |
| 2656 | pointer->button_count > 0 && |
| 2657 | pointer->grab_serial == serial) { |
| 2658 | focus = weston_surface_get_main_surface(pointer->focus->surface); |
| 2659 | if ((focus == surface) && |
| 2660 | (surface_move(shsurf, pointer, true) < 0)) |
| 2661 | wl_resource_post_no_memory(resource); |
| 2662 | } else if (touch && |
| 2663 | touch->focus && |
| 2664 | touch->grab_serial == serial) { |
| 2665 | focus = weston_surface_get_main_surface(touch->focus->surface); |
| 2666 | if ((focus == surface) && |
| 2667 | (surface_touch_move(shsurf, touch) < 0)) |
| 2668 | wl_resource_post_no_memory(resource); |
| 2669 | } |
| 2670 | } |
| 2671 | |
| 2672 | static void |
| 2673 | desktop_surface_resize(struct weston_desktop_surface *desktop_surface, |
| 2674 | struct weston_seat *seat, uint32_t serial, |
| 2675 | enum weston_desktop_surface_edge edges, void *shell) |
| 2676 | { |
| 2677 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2678 | struct shell_surface *shsurf = |
| 2679 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2680 | struct weston_surface *surface = |
| 2681 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2682 | struct wl_resource *resource = surface->resource; |
| 2683 | struct weston_surface *focus; |
| 2684 | |
| 2685 | if (!pointer || |
| 2686 | pointer->button_count == 0 || |
| 2687 | pointer->grab_serial != serial || |
| 2688 | pointer->focus == NULL) |
| 2689 | return; |
| 2690 | |
| 2691 | focus = weston_surface_get_main_surface(pointer->focus->surface); |
| 2692 | if (focus != surface) |
| 2693 | return; |
| 2694 | |
| 2695 | if (surface_resize(shsurf, pointer, edges) < 0) |
| 2696 | wl_resource_post_no_memory(resource); |
| 2697 | } |
| 2698 | |
| 2699 | static void |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2700 | desktop_surface_set_parent(struct weston_desktop_surface *desktop_surface, |
| 2701 | struct weston_desktop_surface *parent, |
| 2702 | void *shell) |
| 2703 | { |
Marius Vlad | a27658e | 2020-01-17 12:32:55 +0200 | [diff] [blame] | 2704 | struct shell_surface *shsurf_parent; |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2705 | struct shell_surface *shsurf = |
| 2706 | weston_desktop_surface_get_user_data(desktop_surface); |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2707 | |
Marius Vlad | a27658e | 2020-01-17 12:32:55 +0200 | [diff] [blame] | 2708 | /* unlink any potential child */ |
| 2709 | wl_list_remove(&shsurf->children_link); |
| 2710 | |
| 2711 | if (parent) { |
| 2712 | shsurf_parent = weston_desktop_surface_get_user_data(parent); |
| 2713 | wl_list_insert(shsurf_parent->children_list.prev, |
| 2714 | &shsurf->children_link); |
| 2715 | } else { |
| 2716 | wl_list_init(&shsurf->children_link); |
| 2717 | } |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2721 | desktop_surface_fullscreen_requested(struct weston_desktop_surface *desktop_surface, |
| 2722 | bool fullscreen, |
| 2723 | struct weston_output *output, void *shell) |
| 2724 | { |
| 2725 | struct shell_surface *shsurf = |
| 2726 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2727 | |
| 2728 | set_fullscreen(shsurf, fullscreen, output); |
| 2729 | } |
| 2730 | |
| 2731 | static void |
| 2732 | set_maximized(struct shell_surface *shsurf, bool maximized) |
| 2733 | { |
| 2734 | struct weston_desktop_surface *desktop_surface = shsurf->desktop_surface; |
| 2735 | struct weston_surface *surface = |
| 2736 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2737 | int32_t width = 0, height = 0; |
| 2738 | |
| 2739 | if (maximized) { |
| 2740 | struct weston_output *output; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2741 | |
| 2742 | if (!weston_surface_is_mapped(surface)) |
| 2743 | output = get_focused_output(surface->compositor); |
| 2744 | else |
| 2745 | output = surface->output; |
| 2746 | |
| 2747 | shell_surface_set_output(shsurf, output); |
| 2748 | |
Derek Foreman | 927d9e2 | 2017-10-06 14:37:44 -0500 | [diff] [blame] | 2749 | get_maximized_size(shsurf, &width, &height); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2750 | } |
| 2751 | weston_desktop_surface_set_maximized(desktop_surface, maximized); |
| 2752 | weston_desktop_surface_set_size(desktop_surface, width, height); |
| 2753 | } |
| 2754 | |
| 2755 | static void |
| 2756 | desktop_surface_maximized_requested(struct weston_desktop_surface *desktop_surface, |
| 2757 | bool maximized, void *shell) |
| 2758 | { |
| 2759 | struct shell_surface *shsurf = |
| 2760 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2761 | |
| 2762 | set_maximized(shsurf, maximized); |
| 2763 | } |
| 2764 | |
| 2765 | static void |
| 2766 | desktop_surface_minimized_requested(struct weston_desktop_surface *desktop_surface, |
| 2767 | void *shell) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2768 | { |
| 2769 | struct weston_surface *surface = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2770 | weston_desktop_surface_get_surface(desktop_surface); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2771 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2772 | /* apply compositor's own minimization logic (hide) */ |
| 2773 | set_minimized(surface); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2774 | } |
| 2775 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2776 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2777 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2778 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2779 | struct shell_grab *grab; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2780 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2781 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2782 | return; |
| 2783 | |
| 2784 | grab = malloc(sizeof *grab); |
| 2785 | if (!grab) |
| 2786 | return; |
| 2787 | |
| 2788 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2789 | WESTON_DESKTOP_SHELL_CURSOR_BUSY); |
| 2790 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2791 | * to move it. */ |
| 2792 | shsurf->grabbed = 0; |
| 2793 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2794 | |
| 2795 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2796 | end_busy_cursor(struct weston_compositor *compositor, |
| 2797 | struct weston_desktop_client *desktop_client) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2798 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 2799 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2800 | struct shell_grab *grab; |
| 2801 | struct weston_seat *seat; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 2802 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2803 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 2804 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2805 | struct weston_desktop_client *grab_client; |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 2806 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2807 | if (!pointer) |
| 2808 | continue; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2809 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2810 | if (pointer->grab->interface != &busy_cursor_grab_interface) |
| 2811 | continue; |
| 2812 | |
| 2813 | grab = (struct shell_grab *) pointer->grab; |
| 2814 | shsurf = grab->shsurf; |
| 2815 | if (!shsurf) |
| 2816 | continue; |
| 2817 | |
| 2818 | grab_client = |
| 2819 | weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 2820 | if (grab_client == desktop_client) { |
| 2821 | shell_grab_end(grab); |
| 2822 | free(grab); |
| 2823 | } |
| 2824 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2828 | desktop_surface_set_unresponsive(struct weston_desktop_surface *desktop_surface, |
| 2829 | void *user_data) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2830 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2831 | struct shell_surface *shsurf = |
| 2832 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2833 | bool *unresponsive = user_data; |
| 2834 | |
| 2835 | shsurf->unresponsive = *unresponsive; |
| 2836 | } |
| 2837 | |
| 2838 | static void |
| 2839 | desktop_surface_ping_timeout(struct weston_desktop_client *desktop_client, |
| 2840 | void *shell_) |
| 2841 | { |
| 2842 | struct desktop_shell *shell = shell_; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2843 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2844 | struct weston_seat *seat; |
| 2845 | bool unresponsive = true; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2846 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2847 | weston_desktop_client_for_each_surface(desktop_client, |
| 2848 | desktop_surface_set_unresponsive, |
| 2849 | &unresponsive); |
| 2850 | |
| 2851 | |
| 2852 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 2853 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2854 | struct weston_desktop_client *grab_client; |
| 2855 | |
| 2856 | if (!pointer || !pointer->focus) |
| 2857 | continue; |
| 2858 | |
| 2859 | shsurf = get_shell_surface(pointer->focus->surface); |
| 2860 | if (!shsurf) |
| 2861 | continue; |
| 2862 | |
| 2863 | grab_client = |
| 2864 | weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 2865 | if (grab_client == desktop_client) |
| 2866 | set_busy_cursor(shsurf, pointer); |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 2867 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2868 | } |
| 2869 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2870 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2871 | desktop_surface_pong(struct weston_desktop_client *desktop_client, |
| 2872 | void *shell_) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2873 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2874 | struct desktop_shell *shell = shell_; |
| 2875 | bool unresponsive = false; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2876 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2877 | weston_desktop_client_for_each_surface(desktop_client, |
| 2878 | desktop_surface_set_unresponsive, |
| 2879 | &unresponsive); |
| 2880 | end_busy_cursor(shell->compositor, desktop_client); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2881 | } |
| 2882 | |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2883 | static void |
| 2884 | desktop_surface_set_xwayland_position(struct weston_desktop_surface *surface, |
| 2885 | int32_t x, int32_t y, void *shell_) |
| 2886 | { |
| 2887 | struct shell_surface *shsurf = |
| 2888 | weston_desktop_surface_get_user_data(surface); |
| 2889 | |
| 2890 | shsurf->xwayland.x = x; |
| 2891 | shsurf->xwayland.y = y; |
| 2892 | shsurf->xwayland.is_set = true; |
| 2893 | } |
| 2894 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2895 | static const struct weston_desktop_api shell_desktop_api = { |
| 2896 | .struct_size = sizeof(struct weston_desktop_api), |
| 2897 | .surface_added = desktop_surface_added, |
| 2898 | .surface_removed = desktop_surface_removed, |
| 2899 | .committed = desktop_surface_committed, |
| 2900 | .move = desktop_surface_move, |
| 2901 | .resize = desktop_surface_resize, |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2902 | .set_parent = desktop_surface_set_parent, |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2903 | .fullscreen_requested = desktop_surface_fullscreen_requested, |
| 2904 | .maximized_requested = desktop_surface_maximized_requested, |
| 2905 | .minimized_requested = desktop_surface_minimized_requested, |
| 2906 | .ping_timeout = desktop_surface_ping_timeout, |
| 2907 | .pong = desktop_surface_pong, |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2908 | .set_xwayland_position = desktop_surface_set_xwayland_position, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2909 | }; |
| 2910 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2911 | /* ************************ * |
| 2912 | * end of libweston-desktop * |
| 2913 | * ************************ */ |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2914 | static void |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 2915 | configure_static_view(struct weston_view *ev, struct weston_layer *layer, int x, int y) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2916 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2917 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2918 | |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 2919 | if (!ev->output) |
| 2920 | return; |
| 2921 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2922 | 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] | 2923 | if (v->output == ev->output && v != ev) { |
| 2924 | weston_view_unmap(v); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2925 | v->surface->committed = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2926 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2927 | } |
| 2928 | } |
| 2929 | |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 2930 | weston_view_set_position(ev, ev->output->x + x, ev->output->y + y); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 2931 | ev->surface->is_mapped = true; |
| 2932 | ev->is_mapped = true; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2933 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2934 | if (wl_list_empty(&ev->layer_link.link)) { |
| 2935 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2936 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2937 | } |
| 2938 | } |
| 2939 | |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2940 | |
| 2941 | static struct shell_output * |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2942 | find_shell_output_from_weston_output(struct desktop_shell *shell, |
| 2943 | struct weston_output *output) |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2944 | { |
| 2945 | struct shell_output *shell_output; |
| 2946 | |
| 2947 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 2948 | if (shell_output->output == output) |
| 2949 | return shell_output; |
| 2950 | } |
| 2951 | |
| 2952 | return NULL; |
| 2953 | } |
| 2954 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2955 | static int |
| 2956 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2957 | { |
| 2958 | return snprintf(buf, len, "background for output %s", |
Miguel A. Vico | 620f68d | 2019-09-25 11:23:13 -0700 | [diff] [blame] | 2959 | (surface->output ? surface->output->name : "NULL")); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2960 | } |
| 2961 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2962 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2963 | 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] | 2964 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2965 | struct desktop_shell *shell = es->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2966 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2967 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2968 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 2969 | |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 2970 | configure_static_view(view, &shell->background_layer, 0, 0); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2971 | } |
| 2972 | |
| 2973 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2974 | handle_background_surface_destroy(struct wl_listener *listener, void *data) |
| 2975 | { |
| 2976 | struct shell_output *output = |
| 2977 | container_of(listener, struct shell_output, background_surface_listener); |
| 2978 | |
| 2979 | weston_log("background surface gone\n"); |
Tomohito Esaki | bf31f6c | 2018-01-31 15:15:45 +0900 | [diff] [blame] | 2980 | wl_list_remove(&output->background_surface_listener.link); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2981 | output->background_surface = NULL; |
| 2982 | } |
| 2983 | |
| 2984 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2985 | desktop_shell_set_background(struct wl_client *client, |
| 2986 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2987 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2988 | struct wl_resource *surface_resource) |
| 2989 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2990 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2991 | struct weston_surface *surface = |
| 2992 | wl_resource_get_user_data(surface_resource); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2993 | struct shell_output *sh_output; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2994 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2995 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2996 | if (surface->committed) { |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2997 | wl_resource_post_error(surface_resource, |
| 2998 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2999 | "surface role already assigned"); |
| 3000 | return; |
| 3001 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3002 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3003 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3004 | weston_view_destroy(view); |
| 3005 | view = weston_view_create(surface); |
| 3006 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3007 | surface->committed = background_committed; |
| 3008 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3009 | weston_surface_set_label_func(surface, background_get_label); |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 3010 | surface->output = weston_head_from_resource(output_resource)->output; |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 3011 | weston_view_set_output(view, surface->output); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3012 | |
| 3013 | sh_output = find_shell_output_from_weston_output(shell, surface->output); |
Pekka Paalanen | ff5e88d | 2017-12-07 11:44:18 +0200 | [diff] [blame] | 3014 | if (sh_output->background_surface) { |
| 3015 | /* The output already has a background, tell our helper |
| 3016 | * there is no need for another one. */ |
| 3017 | weston_desktop_shell_send_configure(resource, 0, |
| 3018 | surface_resource, |
| 3019 | 0, 0); |
| 3020 | } else { |
| 3021 | weston_desktop_shell_send_configure(resource, 0, |
| 3022 | surface_resource, |
| 3023 | surface->output->width, |
| 3024 | surface->output->height); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3025 | |
Pekka Paalanen | ff5e88d | 2017-12-07 11:44:18 +0200 | [diff] [blame] | 3026 | sh_output->background_surface = surface; |
| 3027 | |
| 3028 | sh_output->background_surface_listener.notify = |
| 3029 | handle_background_surface_destroy; |
| 3030 | wl_signal_add(&surface->destroy_signal, |
| 3031 | &sh_output->background_surface_listener); |
| 3032 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3033 | } |
| 3034 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3035 | static int |
| 3036 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3037 | { |
| 3038 | return snprintf(buf, len, "panel for output %s", |
Miguel A. Vico | 620f68d | 2019-09-25 11:23:13 -0700 | [diff] [blame] | 3039 | (surface->output ? surface->output->name : "NULL")); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3040 | } |
| 3041 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3042 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3043 | 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] | 3044 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3045 | struct desktop_shell *shell = es->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3046 | struct weston_view *view; |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 3047 | int width, height; |
| 3048 | int x = 0, y = 0; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3049 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3050 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3051 | |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 3052 | get_panel_size(shell, view, &width, &height); |
| 3053 | switch (shell->panel_position) { |
| 3054 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 3055 | break; |
| 3056 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 3057 | y = view->output->height - height; |
| 3058 | break; |
| 3059 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 3060 | break; |
| 3061 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 3062 | x = view->output->width - width; |
| 3063 | break; |
| 3064 | } |
| 3065 | |
| 3066 | configure_static_view(view, &shell->panel_layer, x, y); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3070 | handle_panel_surface_destroy(struct wl_listener *listener, void *data) |
| 3071 | { |
| 3072 | struct shell_output *output = |
| 3073 | container_of(listener, struct shell_output, panel_surface_listener); |
| 3074 | |
| 3075 | weston_log("panel surface gone\n"); |
Tomohito Esaki | bf31f6c | 2018-01-31 15:15:45 +0900 | [diff] [blame] | 3076 | wl_list_remove(&output->panel_surface_listener.link); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3077 | output->panel_surface = NULL; |
| 3078 | } |
| 3079 | |
| 3080 | |
| 3081 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3082 | desktop_shell_set_panel(struct wl_client *client, |
| 3083 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3084 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3085 | struct wl_resource *surface_resource) |
| 3086 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3087 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3088 | struct weston_surface *surface = |
| 3089 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3090 | struct weston_view *view, *next; |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3091 | struct shell_output *sh_output; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3092 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3093 | if (surface->committed) { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3094 | wl_resource_post_error(surface_resource, |
| 3095 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3096 | "surface role already assigned"); |
| 3097 | return; |
| 3098 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3099 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3100 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3101 | weston_view_destroy(view); |
| 3102 | view = weston_view_create(surface); |
| 3103 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3104 | surface->committed = panel_committed; |
| 3105 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3106 | weston_surface_set_label_func(surface, panel_get_label); |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 3107 | surface->output = weston_head_from_resource(output_resource)->output; |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 3108 | weston_view_set_output(view, surface->output); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3109 | |
| 3110 | sh_output = find_shell_output_from_weston_output(shell, surface->output); |
Pekka Paalanen | 1a0239e | 2017-12-07 11:54:11 +0200 | [diff] [blame] | 3111 | if (sh_output->panel_surface) { |
| 3112 | /* The output already has a panel, tell our helper |
| 3113 | * there is no need for another one. */ |
| 3114 | weston_desktop_shell_send_configure(resource, 0, |
| 3115 | surface_resource, |
| 3116 | 0, 0); |
| 3117 | } else { |
| 3118 | weston_desktop_shell_send_configure(resource, 0, |
| 3119 | surface_resource, |
| 3120 | surface->output->width, |
| 3121 | surface->output->height); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3122 | |
Pekka Paalanen | 1a0239e | 2017-12-07 11:54:11 +0200 | [diff] [blame] | 3123 | sh_output->panel_surface = surface; |
| 3124 | |
| 3125 | sh_output->panel_surface_listener.notify = handle_panel_surface_destroy; |
| 3126 | wl_signal_add(&surface->destroy_signal, &sh_output->panel_surface_listener); |
| 3127 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3128 | } |
| 3129 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3130 | static int |
| 3131 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3132 | { |
| 3133 | return snprintf(buf, len, "lock window"); |
| 3134 | } |
| 3135 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3136 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3137 | 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] | 3138 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3139 | struct desktop_shell *shell = surface->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3140 | struct weston_view *view; |
| 3141 | |
| 3142 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3143 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3144 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3145 | return; |
| 3146 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3147 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3148 | |
| 3149 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3150 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 3151 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3152 | weston_view_update_transform(view); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 3153 | surface->is_mapped = true; |
| 3154 | view->is_mapped = true; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3155 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3156 | } |
| 3157 | } |
| 3158 | |
| 3159 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3160 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3161 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3162 | struct desktop_shell *shell = |
| 3163 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3164 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3165 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3166 | shell->lock_surface = NULL; |
| 3167 | } |
| 3168 | |
| 3169 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3170 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3171 | struct wl_resource *resource, |
| 3172 | struct wl_resource *surface_resource) |
| 3173 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3174 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3175 | struct weston_surface *surface = |
| 3176 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3177 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3178 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3179 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3180 | if (!shell->locked) |
| 3181 | return; |
| 3182 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3183 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3184 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3185 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3186 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3187 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3188 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3189 | weston_view_create(surface); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3190 | surface->committed = lock_surface_committed; |
| 3191 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3192 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3196 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3197 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3198 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3199 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3200 | weston_layer_unset_position(&shell->lock_layer); |
| 3201 | |
| 3202 | if (shell->showing_input_panels) |
| 3203 | weston_layer_set_position(&shell->input_panel_layer, |
| 3204 | WESTON_LAYER_POSITION_TOP_UI); |
| 3205 | weston_layer_set_position(&shell->fullscreen_layer, |
| 3206 | WESTON_LAYER_POSITION_FULLSCREEN); |
| 3207 | weston_layer_set_position(&shell->panel_layer, |
| 3208 | WESTON_LAYER_POSITION_UI); |
| 3209 | weston_layer_set_position(&ws->layer, WESTON_LAYER_POSITION_NORMAL); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3210 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3211 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3212 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3213 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3214 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3215 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | static void |
| 3219 | desktop_shell_unlock(struct wl_client *client, |
| 3220 | struct wl_resource *resource) |
| 3221 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3222 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3223 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3224 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3225 | |
| 3226 | if (shell->locked) |
| 3227 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3228 | } |
| 3229 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3230 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3231 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3232 | struct wl_resource *resource, |
| 3233 | struct wl_resource *surface_resource) |
| 3234 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3235 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3236 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3237 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3238 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3239 | } |
| 3240 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3241 | static void |
| 3242 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3243 | struct wl_resource *resource) |
| 3244 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3245 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3246 | |
| 3247 | shell_fade_startup(shell); |
| 3248 | } |
| 3249 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3250 | static void |
| 3251 | desktop_shell_set_panel_position(struct wl_client *client, |
| 3252 | struct wl_resource *resource, |
| 3253 | uint32_t position) |
| 3254 | { |
| 3255 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3256 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3257 | if (position != WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 3258 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 3259 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 3260 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3261 | wl_resource_post_error(resource, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3262 | WESTON_DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3263 | "bad position argument"); |
| 3264 | return; |
| 3265 | } |
| 3266 | |
| 3267 | shell->panel_position = position; |
| 3268 | } |
| 3269 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3270 | static const struct weston_desktop_shell_interface desktop_shell_implementation = { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3271 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3272 | desktop_shell_set_panel, |
| 3273 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3274 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3275 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3276 | desktop_shell_desktop_ready, |
| 3277 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3278 | }; |
| 3279 | |
| 3280 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3281 | move_binding(struct weston_pointer *pointer, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3282 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3283 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3284 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3285 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3286 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3287 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3288 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3289 | return; |
| 3290 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3291 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3292 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3293 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3294 | if (surface == NULL) |
| 3295 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3296 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3297 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3298 | if (shsurf == NULL || |
| 3299 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3300 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3301 | return; |
| 3302 | |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 3303 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3307 | maximize_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3308 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3309 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3310 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3311 | struct weston_surface *surface; |
| 3312 | struct shell_surface *shsurf; |
| 3313 | |
| 3314 | surface = weston_surface_get_main_surface(focus); |
| 3315 | if (surface == NULL) |
| 3316 | return; |
| 3317 | |
| 3318 | shsurf = get_shell_surface(surface); |
| 3319 | if (shsurf == NULL) |
| 3320 | return; |
| 3321 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3322 | set_maximized(shsurf, !weston_desktop_surface_get_maximized(shsurf->desktop_surface)); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3323 | } |
| 3324 | |
| 3325 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3326 | fullscreen_binding(struct weston_keyboard *keyboard, |
| 3327 | const struct timespec *time, uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3328 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3329 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3330 | struct weston_surface *surface; |
| 3331 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3332 | bool fullscreen; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3333 | |
| 3334 | surface = weston_surface_get_main_surface(focus); |
| 3335 | if (surface == NULL) |
| 3336 | return; |
| 3337 | |
| 3338 | shsurf = get_shell_surface(surface); |
| 3339 | if (shsurf == NULL) |
| 3340 | return; |
| 3341 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3342 | fullscreen = |
| 3343 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3344 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3345 | set_fullscreen(shsurf, !fullscreen, NULL); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3346 | } |
| 3347 | |
| 3348 | static void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 3349 | touch_move_binding(struct weston_touch *touch, const struct timespec *time, void *data) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3350 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 3351 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3352 | struct weston_surface *surface; |
| 3353 | struct shell_surface *shsurf; |
| 3354 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3355 | if (touch->focus == NULL) |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 3356 | return; |
| 3357 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3358 | focus = touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3359 | surface = weston_surface_get_main_surface(focus); |
| 3360 | if (surface == NULL) |
| 3361 | return; |
| 3362 | |
| 3363 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3364 | if (shsurf == NULL || |
| 3365 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3366 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3367 | return; |
| 3368 | |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 3369 | surface_touch_move(shsurf, touch); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3370 | } |
| 3371 | |
| 3372 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3373 | resize_binding(struct weston_pointer *pointer, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3374 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3375 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3376 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3377 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3378 | uint32_t edges = 0; |
| 3379 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3380 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3381 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3382 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3383 | return; |
| 3384 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3385 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3386 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3387 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3388 | if (surface == NULL) |
| 3389 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3390 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3391 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3392 | if (shsurf == NULL || |
| 3393 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3394 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3395 | return; |
| 3396 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3397 | weston_view_from_global(shsurf->view, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3398 | wl_fixed_to_int(pointer->grab_x), |
| 3399 | wl_fixed_to_int(pointer->grab_y), |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3400 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3401 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3402 | if (x < surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3403 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3404 | else if (x < 2 * surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3405 | edges |= 0; |
| 3406 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3407 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3408 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3409 | if (y < surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3410 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3411 | else if (y < 2 * surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3412 | edges |= 0; |
| 3413 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3414 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3415 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3416 | surface_resize(shsurf, pointer, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3417 | } |
| 3418 | |
| 3419 | static void |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 3420 | surface_opacity_binding(struct weston_pointer *pointer, |
| 3421 | const struct timespec *time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3422 | struct weston_pointer_axis_event *event, |
| 3423 | void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3424 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3425 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3426 | struct shell_surface *shsurf; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3427 | struct weston_surface *focus = pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3428 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3429 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3430 | /* XXX: broken for windows containing sub-surfaces */ |
| 3431 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3432 | if (surface == NULL) |
| 3433 | return; |
| 3434 | |
| 3435 | shsurf = get_shell_surface(surface); |
| 3436 | if (!shsurf) |
| 3437 | return; |
| 3438 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 3439 | shsurf->view->alpha -= event->value * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3440 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3441 | if (shsurf->view->alpha > 1.0) |
| 3442 | shsurf->view->alpha = 1.0; |
| 3443 | if (shsurf->view->alpha < step) |
| 3444 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3445 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3446 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3447 | weston_surface_damage(surface); |
| 3448 | } |
| 3449 | |
| 3450 | static void |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 3451 | do_zoom(struct weston_seat *seat, const struct timespec *time, uint32_t key, |
| 3452 | uint32_t axis, double value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3453 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 3454 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3455 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3456 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3457 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3458 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3459 | if (!pointer) { |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 3460 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 3461 | return; |
| 3462 | } |
| 3463 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3464 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3465 | if (pixman_region32_contains_point(&output->region, |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3466 | wl_fixed_to_double(pointer->x), |
| 3467 | wl_fixed_to_double(pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3468 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3469 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3470 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3471 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3472 | increment = -output->zoom.increment; |
| 3473 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3474 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3475 | increment = output->zoom.increment * |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 3476 | -value / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3477 | else |
| 3478 | increment = 0; |
| 3479 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3480 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3481 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3482 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3483 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3484 | else if (output->zoom.level > output->zoom.max_level) |
| 3485 | output->zoom.level = output->zoom.max_level; |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 3486 | |
| 3487 | if (!output->zoom.active) { |
| 3488 | if (output->zoom.level <= 0.0) |
| 3489 | continue; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 3490 | weston_output_activate_zoom(output, seat); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3491 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3492 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3493 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3494 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3495 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3496 | } |
| 3497 | } |
| 3498 | } |
| 3499 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3500 | static void |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 3501 | zoom_axis_binding(struct weston_pointer *pointer, const struct timespec *time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3502 | struct weston_pointer_axis_event *event, |
| 3503 | void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3504 | { |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3505 | do_zoom(pointer->seat, time, 0, event->axis, event->value); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3509 | zoom_key_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3510 | uint32_t key, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3511 | { |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3512 | do_zoom(keyboard->seat, time, key, 0, 0); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3516 | terminate_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3517 | uint32_t key, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3518 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3519 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3520 | |
Pekka Paalanen | 052032d | 2019-02-06 10:44:37 +0200 | [diff] [blame] | 3521 | weston_compositor_exit(compositor); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3522 | } |
| 3523 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3524 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 3525 | rotate_grab_motion(struct weston_pointer_grab *grab, |
| 3526 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3527 | struct weston_pointer_motion_event *event) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3528 | { |
| 3529 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3530 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3531 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3532 | struct shell_surface *shsurf = rotate->base.shsurf; |
Sergey Bugaev | 14ef201 | 2019-02-11 22:55:09 +0300 | [diff] [blame] | 3533 | struct weston_surface *surface; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3534 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3535 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3536 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3537 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3538 | if (!shsurf) |
| 3539 | return; |
| 3540 | |
Sergey Bugaev | 14ef201 | 2019-02-11 22:55:09 +0300 | [diff] [blame] | 3541 | surface = weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 3542 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3543 | cx = 0.5f * surface->width; |
| 3544 | cy = 0.5f * surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3545 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3546 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3547 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3548 | r = sqrtf(dx * dx + dy * dy); |
| 3549 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3550 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3551 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3552 | |
| 3553 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3554 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3555 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3556 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3557 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3558 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3559 | |
| 3560 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3561 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3562 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3563 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3564 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3565 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 3566 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3567 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3568 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3569 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3570 | wl_list_init(&shsurf->rotation.transform.link); |
| 3571 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3572 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3573 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3574 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3575 | /* We need to adjust the position of the surface |
| 3576 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3577 | cposx = shsurf->view->geometry.x + cx; |
| 3578 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3579 | dposx = rotate->center.x - cposx; |
| 3580 | dposy = rotate->center.y - cposy; |
| 3581 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3582 | weston_view_set_position(shsurf->view, |
| 3583 | shsurf->view->geometry.x + dposx, |
| 3584 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3585 | } |
| 3586 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 3587 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3588 | * lazily applies the damage due to rotation update. |
| 3589 | */ |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3590 | weston_compositor_schedule_repaint(surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3591 | } |
| 3592 | |
| 3593 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3594 | rotate_grab_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3595 | const struct timespec *time, |
| 3596 | uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3597 | { |
| 3598 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3599 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3600 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3601 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3602 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3603 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3604 | if (pointer->button_count == 0 && |
| 3605 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3606 | if (shsurf) |
| 3607 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 3608 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3609 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3610 | free(rotate); |
| 3611 | } |
| 3612 | } |
| 3613 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3614 | static void |
| 3615 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 3616 | { |
| 3617 | struct rotate_grab *rotate = |
| 3618 | container_of(grab, struct rotate_grab, base.grab); |
| 3619 | |
| 3620 | shell_grab_end(&rotate->base); |
| 3621 | free(rotate); |
| 3622 | } |
| 3623 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3624 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3625 | noop_grab_focus, |
| 3626 | rotate_grab_motion, |
| 3627 | rotate_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3628 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 3629 | noop_grab_axis_source, |
| 3630 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3631 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3632 | }; |
| 3633 | |
| 3634 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3635 | surface_rotate(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3636 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3637 | struct weston_surface *surface = |
| 3638 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3639 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3640 | float dx, dy; |
| 3641 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3642 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3643 | rotate = malloc(sizeof *rotate); |
| 3644 | if (!rotate) |
| 3645 | return; |
| 3646 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3647 | weston_view_to_global_float(shsurf->view, |
| 3648 | surface->width * 0.5f, |
| 3649 | surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3650 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3651 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 3652 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3653 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3654 | r = sqrtf(dx * dx + dy * dy); |
| 3655 | if (r > 20.0f) { |
| 3656 | struct weston_matrix inverse; |
| 3657 | |
| 3658 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3659 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3660 | weston_matrix_multiply(&shsurf->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3661 | |
| 3662 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3663 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3664 | } else { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3665 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3666 | weston_matrix_init(&rotate->rotation); |
| 3667 | } |
| 3668 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3669 | shell_grab_start(&rotate->base, &rotate_grab_interface, shsurf, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3670 | pointer, WESTON_DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3674 | rotate_binding(struct weston_pointer *pointer, const struct timespec *time, |
| 3675 | uint32_t button, void *data) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3676 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3677 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3678 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3679 | struct shell_surface *surface; |
| 3680 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3681 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3682 | return; |
| 3683 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3684 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3685 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3686 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3687 | if (base_surface == NULL) |
| 3688 | return; |
| 3689 | |
| 3690 | surface = get_shell_surface(base_surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3691 | if (surface == NULL || |
| 3692 | weston_desktop_surface_get_fullscreen(surface->desktop_surface) || |
| 3693 | weston_desktop_surface_get_maximized(surface->desktop_surface)) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3694 | return; |
| 3695 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 3696 | surface_rotate(surface, pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3697 | } |
| 3698 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3699 | /* Move all fullscreen layers down to the current workspace and hide their |
| 3700 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 3701 | * and this is reversed when such a surface is re-configured, see |
| 3702 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 3703 | * |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3704 | * lowering_output = NULL - Lower on all outputs, else only lower on the |
| 3705 | * specified output. |
| 3706 | * |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3707 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3708 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3709 | void |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3710 | lower_fullscreen_layer(struct desktop_shell *shell, |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3711 | struct weston_output *lowering_output) |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3712 | { |
| 3713 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3714 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3715 | |
| 3716 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3717 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3718 | &shell->fullscreen_layer.view_list.link, |
| 3719 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3720 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 3721 | |
| 3722 | if (!shsurf) |
| 3723 | continue; |
| 3724 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3725 | /* Only lower surfaces which have lowering_output as their fullscreen |
| 3726 | * output, unless a NULL output asks for lowering on all outputs. |
| 3727 | */ |
| 3728 | if (lowering_output && (shsurf->fullscreen_output != lowering_output)) |
| 3729 | continue; |
| 3730 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3731 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 3732 | * in the fullscreen layer. */ |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3733 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3734 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3735 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 3736 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 3737 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 3738 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3742 | weston_layer_entry_remove(&view->layer_link); |
| 3743 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3744 | weston_view_damage_below(view); |
| 3745 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3746 | |
| 3747 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3748 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3749 | } |
| 3750 | |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 3751 | static struct shell_surface *get_last_child(struct shell_surface *shsurf) |
| 3752 | { |
| 3753 | struct shell_surface *shsurf_child; |
| 3754 | |
| 3755 | wl_list_for_each_reverse(shsurf_child, &shsurf->children_list, children_link) { |
| 3756 | if (weston_view_is_mapped(shsurf_child->view)) |
| 3757 | return shsurf_child; |
| 3758 | } |
| 3759 | |
| 3760 | return NULL; |
| 3761 | } |
| 3762 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3763 | void |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 3764 | activate(struct desktop_shell *shell, struct weston_view *view, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3765 | struct weston_seat *seat, uint32_t flags) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3766 | { |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 3767 | struct weston_surface *es = view->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3768 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3769 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3770 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3771 | struct weston_surface *old_es; |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 3772 | struct shell_surface *shsurf, *shsurf_child; |
Marius Vlad | f12697b | 2021-03-05 21:44:26 +0200 | [diff] [blame] | 3773 | struct shell_seat *shseat = get_shell_seat(seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3774 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3775 | main_surface = weston_surface_get_main_surface(es); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3776 | shsurf = get_shell_surface(main_surface); |
| 3777 | assert(shsurf); |
| 3778 | |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 3779 | shsurf_child = get_last_child(shsurf); |
| 3780 | if (shsurf_child) { |
| 3781 | /* Activate last xdg child instead of parent. */ |
| 3782 | activate(shell, shsurf_child->view, seat, flags); |
| 3783 | return; |
| 3784 | } |
| 3785 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3786 | /* Only demote fullscreen surfaces on the output of activated shsurf. |
| 3787 | * Leave fullscreen surfaces on unrelated outputs alone. */ |
Pekka Paalanen | 87860c2 | 2018-05-02 10:21:57 +0200 | [diff] [blame] | 3788 | if (shsurf->output) |
| 3789 | lower_fullscreen_layer(shell, shsurf->output); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3790 | |
Marius Vlad | d6ccc8b | 2021-03-05 22:07:30 +0200 | [diff] [blame] | 3791 | weston_view_activate_input(view, seat, flags); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3792 | |
Marius Vlad | f12697b | 2021-03-05 21:44:26 +0200 | [diff] [blame] | 3793 | if (shseat->focused_surface) { |
| 3794 | struct shell_surface *current_focus = |
| 3795 | get_shell_surface(shseat->focused_surface); |
| 3796 | assert(current_focus); |
| 3797 | shell_surface_deactivate(current_focus); |
| 3798 | } |
| 3799 | |
| 3800 | shseat->focused_surface = main_surface; |
| 3801 | shell_surface_activate(shsurf); |
| 3802 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3803 | state = ensure_focus_state(shell, seat); |
| 3804 | if (state == NULL) |
| 3805 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3806 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3807 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 3808 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3809 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3810 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) && |
| 3811 | flags & WESTON_ACTIVATE_FLAG_CONFIGURE) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3812 | shell_configure_fullscreen(shsurf); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3813 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 3814 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 3815 | * order as appropriate. */ |
| 3816 | shell_surface_update_layer(shsurf); |
| 3817 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3818 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 3819 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3820 | 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] | 3821 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3822 | } |
| 3823 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3824 | /* no-op func for checking black surface */ |
| 3825 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3826 | 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] | 3827 | { |
| 3828 | } |
| 3829 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 3830 | static bool |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3831 | 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] | 3832 | { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3833 | struct weston_surface *surface = view->surface; |
| 3834 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3835 | if (surface->committed == black_surface_committed) { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3836 | if (fs_view) |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3837 | *fs_view = surface->committed_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3838 | return true; |
| 3839 | } |
| 3840 | return false; |
| 3841 | } |
| 3842 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3843 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3844 | activate_binding(struct weston_seat *seat, |
| 3845 | struct desktop_shell *shell, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3846 | struct weston_view *focus_view, |
| 3847 | uint32_t flags) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3848 | { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3849 | struct weston_view *main_view; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3850 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3851 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3852 | if (!focus_view) |
| 3853 | return; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 3854 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3855 | if (is_black_surface_view(focus_view, &main_view)) |
| 3856 | focus_view = main_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3857 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3858 | main_surface = weston_surface_get_main_surface(focus_view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3859 | if (!get_shell_surface(main_surface)) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3860 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 3861 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3862 | activate(shell, focus_view, seat, flags); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3863 | } |
| 3864 | |
| 3865 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3866 | click_to_activate_binding(struct weston_pointer *pointer, |
| 3867 | const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3868 | uint32_t button, void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3869 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3870 | if (pointer->grab != &pointer->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3871 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3872 | if (pointer->focus == NULL) |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 3873 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3874 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3875 | activate_binding(pointer->seat, data, pointer->focus, |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 3876 | WESTON_ACTIVATE_FLAG_CLICKED | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3877 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | static void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 3881 | touch_to_activate_binding(struct weston_touch *touch, |
| 3882 | const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3883 | void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3884 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3885 | if (touch->grab != &touch->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3886 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3887 | if (touch->focus == NULL) |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 3888 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3889 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3890 | activate_binding(touch->seat, data, touch->focus, |
| 3891 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3892 | } |
| 3893 | |
| 3894 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3895 | unfocus_all_seats(struct desktop_shell *shell) |
| 3896 | { |
| 3897 | struct weston_seat *seat, *next; |
| 3898 | |
| 3899 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3900 | struct weston_keyboard *keyboard = |
| 3901 | weston_seat_get_keyboard(seat); |
| 3902 | |
| 3903 | if (!keyboard) |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3904 | continue; |
| 3905 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3906 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3911 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3912 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3913 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3914 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3915 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3916 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3917 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3918 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3919 | |
| 3920 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3921 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3922 | /* Hide all surfaces by removing the fullscreen, panel and |
| 3923 | * toplevel layers. This way nothing else can show or receive |
| 3924 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3925 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3926 | weston_layer_unset_position(&shell->panel_layer); |
| 3927 | weston_layer_unset_position(&shell->fullscreen_layer); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3928 | if (shell->showing_input_panels) |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3929 | weston_layer_unset_position(&shell->input_panel_layer); |
| 3930 | weston_layer_unset_position(&ws->layer); |
| 3931 | |
| 3932 | weston_layer_set_position(&shell->lock_layer, |
| 3933 | WESTON_LAYER_POSITION_LOCK); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3934 | |
Derek Foreman | 004b4a1 | 2015-07-20 16:28:13 -0500 | [diff] [blame] | 3935 | weston_compositor_sleep(shell->compositor); |
| 3936 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3937 | /* Remove the keyboard focus on all seats. This will be |
| 3938 | * restored to the workspace's saved state via |
| 3939 | * restore_focus_state when the compositor is unlocked */ |
| 3940 | unfocus_all_seats(shell); |
| 3941 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3942 | /* TODO: disable bindings that should not work while locked. */ |
| 3943 | |
| 3944 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3948 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3949 | { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3950 | struct wl_resource *shell_resource; |
| 3951 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 3952 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3953 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3954 | return; |
| 3955 | } |
| 3956 | |
| 3957 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 3958 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3959 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3960 | return; |
| 3961 | } |
| 3962 | |
| 3963 | if (shell->prepare_event_sent) |
| 3964 | return; |
| 3965 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3966 | shell_resource = shell->child.desktop_shell; |
| 3967 | weston_desktop_shell_send_prepare_lock_surface(shell_resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3968 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | static void |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 3972 | shell_fade_done_for_output(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3973 | { |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 3974 | struct shell_output *shell_output = data; |
| 3975 | struct desktop_shell *shell = shell_output->shell; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3976 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 3977 | shell_output->fade.animation = NULL; |
| 3978 | switch (shell_output->fade.type) { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3979 | case FADE_IN: |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 3980 | weston_surface_destroy(shell_output->fade.view->surface); |
| 3981 | shell_output->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3982 | break; |
| 3983 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3984 | lock(shell); |
| 3985 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 3986 | default: |
| 3987 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3988 | } |
| 3989 | } |
| 3990 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3991 | static struct weston_view * |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 3992 | shell_fade_create_surface_for_output(struct desktop_shell *shell, struct shell_output *shell_output) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3993 | { |
| 3994 | struct weston_compositor *compositor = shell->compositor; |
| 3995 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3996 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3997 | |
| 3998 | surface = weston_surface_create(compositor); |
| 3999 | if (!surface) |
| 4000 | return NULL; |
| 4001 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4002 | view = weston_view_create(surface); |
| 4003 | if (!view) { |
| 4004 | weston_surface_destroy(surface); |
| 4005 | return NULL; |
| 4006 | } |
| 4007 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4008 | weston_surface_set_size(surface, shell_output->output->width, shell_output->output->height); |
| 4009 | weston_view_set_position(view, shell_output->output->x, shell_output->output->y); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4010 | 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] | 4011 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 4012 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4013 | pixman_region32_init(&surface->input); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 4014 | surface->is_mapped = true; |
| 4015 | view->is_mapped = true; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4016 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4017 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4018 | } |
| 4019 | |
| 4020 | static void |
| 4021 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4022 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4023 | float tint; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4024 | struct shell_output *shell_output; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4025 | |
| 4026 | switch (type) { |
| 4027 | case FADE_IN: |
| 4028 | tint = 0.0; |
| 4029 | break; |
| 4030 | case FADE_OUT: |
| 4031 | tint = 1.0; |
| 4032 | break; |
| 4033 | default: |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 4034 | weston_log("shell: invalid fade type\n"); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4035 | return; |
| 4036 | } |
| 4037 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4038 | /* Create a separate fade surface for each output */ |
| 4039 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4040 | shell_output->fade.type = type; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4041 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4042 | if (shell_output->fade.view == NULL) { |
| 4043 | shell_output->fade.view = shell_fade_create_surface_for_output(shell, shell_output); |
| 4044 | if (!shell_output->fade.view) |
| 4045 | continue; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4046 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4047 | shell_output->fade.view->alpha = 1.0 - tint; |
| 4048 | weston_view_update_transform(shell_output->fade.view); |
| 4049 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4050 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4051 | if (shell_output->fade.view->output == NULL) { |
| 4052 | /* If the black view gets a NULL output, we lost the |
| 4053 | * last output and we'll just cancel the fade. This |
| 4054 | * happens when you close the last window under the |
| 4055 | * X11 or Wayland backends. */ |
| 4056 | shell->locked = false; |
| 4057 | weston_surface_destroy(shell_output->fade.view->surface); |
| 4058 | shell_output->fade.view = NULL; |
| 4059 | } else if (shell_output->fade.animation) { |
| 4060 | weston_fade_update(shell_output->fade.animation, tint); |
| 4061 | } else { |
| 4062 | shell_output->fade.animation = |
| 4063 | weston_fade_run(shell_output->fade.view, |
| 4064 | 1.0 - tint, tint, 300.0, |
| 4065 | shell_fade_done_for_output, shell_output); |
| 4066 | } |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4067 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4068 | } |
| 4069 | |
| 4070 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4071 | do_shell_fade_startup(void *data) |
| 4072 | { |
| 4073 | struct desktop_shell *shell = data; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4074 | struct shell_output *shell_output; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4075 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 4076 | if (shell->startup_animation_type == ANIMATION_FADE) { |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4077 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 4078 | } else { |
| 4079 | weston_log("desktop shell: " |
| 4080 | "unexpected fade-in animation type %d\n", |
| 4081 | shell->startup_animation_type); |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4082 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4083 | weston_surface_destroy(shell_output->fade.view->surface); |
| 4084 | shell_output->fade.view = NULL; |
| 4085 | } |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4086 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4087 | } |
| 4088 | |
| 4089 | static void |
| 4090 | shell_fade_startup(struct desktop_shell *shell) |
| 4091 | { |
| 4092 | struct wl_event_loop *loop; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4093 | struct shell_output *shell_output; |
| 4094 | bool has_fade = false; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4095 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4096 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4097 | if (!shell_output->fade.startup_timer) |
| 4098 | continue; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4099 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4100 | wl_event_source_remove(shell_output->fade.startup_timer); |
| 4101 | shell_output->fade.startup_timer = NULL; |
| 4102 | has_fade = true; |
| 4103 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4104 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4105 | if (has_fade) { |
| 4106 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4107 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4108 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4109 | } |
| 4110 | |
| 4111 | static int |
| 4112 | fade_startup_timeout(void *data) |
| 4113 | { |
| 4114 | struct desktop_shell *shell = data; |
| 4115 | |
| 4116 | shell_fade_startup(shell); |
| 4117 | return 0; |
| 4118 | } |
| 4119 | |
| 4120 | static void |
| 4121 | shell_fade_init(struct desktop_shell *shell) |
| 4122 | { |
| 4123 | /* Make compositor output all black, and wait for the desktop-shell |
| 4124 | * client to signal it is ready, then fade in. The timer triggers a |
| 4125 | * fade-in, in case the desktop-shell client takes too long. |
| 4126 | */ |
| 4127 | |
| 4128 | struct wl_event_loop *loop; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4129 | struct shell_output *shell_output; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4130 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 4131 | if (shell->startup_animation_type == ANIMATION_NONE) |
| 4132 | return; |
| 4133 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4134 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4135 | if (shell_output->fade.view != NULL) { |
| 4136 | weston_log("%s: warning: fade surface already exists\n", |
| 4137 | __func__); |
| 4138 | continue; |
| 4139 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4140 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4141 | shell_output->fade.view = shell_fade_create_surface_for_output(shell, shell_output); |
| 4142 | if (!shell_output->fade.view) |
| 4143 | continue; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4144 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4145 | weston_view_update_transform(shell_output->fade.view); |
| 4146 | weston_surface_damage(shell_output->fade.view->surface); |
| 4147 | |
| 4148 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4149 | shell_output->fade.startup_timer = |
| 4150 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4151 | wl_event_source_timer_update(shell_output->fade.startup_timer, 15000); |
| 4152 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4153 | } |
| 4154 | |
| 4155 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4156 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4157 | { |
| 4158 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4159 | container_of(listener, struct desktop_shell, idle_listener); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4160 | |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 4161 | struct weston_seat *seat; |
| 4162 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4163 | wl_list_for_each(seat, &shell->compositor->seat_list, link) |
| 4164 | weston_seat_break_desktop_grabs(seat); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4165 | |
| 4166 | shell_fade(shell, FADE_OUT); |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4167 | /* lock() is called from shell_fade_done_for_output() */ |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4171 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4172 | { |
| 4173 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4174 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4175 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4176 | unlock(shell); |
| 4177 | } |
| 4178 | |
| 4179 | static void |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4180 | transform_handler(struct wl_listener *listener, void *data) |
| 4181 | { |
| 4182 | struct weston_surface *surface = data; |
| 4183 | struct shell_surface *shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4184 | const struct weston_xwayland_surface_api *api; |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4185 | int x, y; |
| 4186 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4187 | if (!shsurf) |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4188 | return; |
| 4189 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4190 | api = shsurf->shell->xwayland_surface_api; |
| 4191 | if (!api) { |
| 4192 | api = weston_xwayland_surface_get_api(shsurf->shell->compositor); |
| 4193 | shsurf->shell->xwayland_surface_api = api; |
| 4194 | } |
| 4195 | |
| 4196 | if (!api || !api->is_xwayland_surface(surface)) |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4197 | return; |
| 4198 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4199 | if (!weston_view_is_mapped(shsurf->view)) |
| 4200 | return; |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4201 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4202 | x = shsurf->view->geometry.x; |
| 4203 | y = shsurf->view->geometry.y; |
| 4204 | |
| 4205 | api->send_position(surface, x, y); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4209 | weston_view_set_initial_position(struct weston_view *view, |
| 4210 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4211 | { |
| 4212 | struct weston_compositor *compositor = shell->compositor; |
| 4213 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4214 | int32_t range_x, range_y; |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4215 | int32_t x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4216 | struct weston_output *output, *target_output = NULL; |
| 4217 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4218 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4219 | |
| 4220 | /* As a heuristic place the new window on the same output as the |
| 4221 | * pointer. Falling back to the output containing 0, 0. |
| 4222 | * |
| 4223 | * TODO: Do something clever for touch too? |
| 4224 | */ |
| 4225 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4226 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 4227 | |
| 4228 | if (pointer) { |
| 4229 | ix = wl_fixed_to_int(pointer->x); |
| 4230 | iy = wl_fixed_to_int(pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4231 | break; |
| 4232 | } |
| 4233 | } |
| 4234 | |
| 4235 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4236 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4237 | target_output = output; |
| 4238 | break; |
| 4239 | } |
| 4240 | } |
| 4241 | |
| 4242 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4243 | weston_view_set_position(view, 10 + random() % 400, |
| 4244 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4245 | return; |
| 4246 | } |
| 4247 | |
| 4248 | /* Valid range within output where the surface will still be onscreen. |
| 4249 | * If this is negative it means that the surface is bigger than |
| 4250 | * output. |
| 4251 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4252 | get_output_work_area(shell, target_output, &area); |
| 4253 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4254 | x = area.x; |
| 4255 | y = area.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4256 | range_x = area.width - view->surface->width; |
| 4257 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4258 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4259 | if (range_x > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4260 | x += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4261 | |
| 4262 | if (range_y > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4263 | y += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4264 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4265 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4266 | } |
| 4267 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 4268 | static bool |
| 4269 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 4270 | { |
| 4271 | struct timespec now; |
| 4272 | |
| 4273 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 4274 | return false; |
| 4275 | |
| 4276 | /* |
| 4277 | * If the shell helper client dies before the session has been |
| 4278 | * up for roughly 30 seconds, better just make Weston shut down, |
| 4279 | * because the user likely has no way to interact with the desktop |
| 4280 | * anyway. |
| 4281 | */ |
| 4282 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 4283 | weston_log("Error: %s apparently cannot run at all.\n", |
| 4284 | shell->client); |
| 4285 | weston_log_continue(STAMP_SPACE "Quitting..."); |
Pekka Paalanen | 052032d | 2019-02-06 10:44:37 +0200 | [diff] [blame] | 4286 | weston_compositor_exit_with_code(shell->compositor, |
| 4287 | EXIT_FAILURE); |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 4288 | |
| 4289 | return true; |
| 4290 | } |
| 4291 | |
| 4292 | return false; |
| 4293 | } |
| 4294 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4295 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4296 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4297 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4298 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4299 | { |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 4300 | struct timespec time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4301 | |
| 4302 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 4303 | weston_compositor_get_time(&time); |
| 4304 | if (timespec_sub_to_msec(&time, &shell->child.deathstamp) > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4305 | shell->child.deathstamp = time; |
| 4306 | shell->child.deathcount = 0; |
| 4307 | } |
| 4308 | |
| 4309 | shell->child.deathcount++; |
| 4310 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4311 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4312 | return; |
| 4313 | } |
| 4314 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4315 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4316 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4317 | } |
| 4318 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4319 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4320 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 4321 | { |
| 4322 | struct desktop_shell *shell; |
| 4323 | |
| 4324 | shell = container_of(listener, struct desktop_shell, |
| 4325 | child.client_destroy_listener); |
| 4326 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4327 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4328 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4329 | /* |
| 4330 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 4331 | * before the respawned process has a chance to create a new |
| 4332 | * desktop_shell object, because we are being called from the |
| 4333 | * wl_client destructor which destroys all wl_resources before |
| 4334 | * returning. |
| 4335 | */ |
| 4336 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 4337 | if (!check_desktop_shell_crash_too_early(shell)) |
| 4338 | respawn_desktop_shell_process(shell); |
| 4339 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4340 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4344 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4345 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4346 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4347 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4348 | shell->child.client = weston_client_start(shell->compositor, |
| 4349 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4350 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 4351 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4352 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 4353 | return; |
| 4354 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4355 | |
| 4356 | shell->child.client_destroy_listener.notify = |
| 4357 | desktop_shell_client_destroy; |
| 4358 | wl_client_add_destroy_listener(shell->child.client, |
| 4359 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4360 | } |
| 4361 | |
| 4362 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4363 | unbind_desktop_shell(struct wl_resource *resource) |
| 4364 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4365 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4366 | |
| 4367 | if (shell->locked) |
| 4368 | resume_desktop(shell); |
| 4369 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4370 | shell->child.desktop_shell = NULL; |
| 4371 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4372 | } |
| 4373 | |
| 4374 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4375 | bind_desktop_shell(struct wl_client *client, |
| 4376 | void *data, uint32_t version, uint32_t id) |
| 4377 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4378 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4379 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4380 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4381 | resource = wl_resource_create(client, &weston_desktop_shell_interface, |
| 4382 | 1, id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4383 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4384 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4385 | wl_resource_set_implementation(resource, |
| 4386 | &desktop_shell_implementation, |
| 4387 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4388 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4389 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4390 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4391 | |
| 4392 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4393 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4394 | } |
| 4395 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4396 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4397 | struct desktop_shell *shell; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4398 | struct weston_view *current; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4399 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4400 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4401 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4402 | }; |
| 4403 | |
| 4404 | static void |
| 4405 | switcher_next(struct switcher *switcher) |
| 4406 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4407 | struct weston_view *view; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4408 | struct weston_view *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4409 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4410 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4411 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4412 | /* temporary re-display minimized surfaces */ |
| 4413 | struct weston_view *tmp; |
| 4414 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4415 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 4416 | weston_layer_entry_remove(&view->layer_link); |
| 4417 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4418 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 4419 | *minimized = view; |
| 4420 | } |
| 4421 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4422 | 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] | 4423 | shsurf = get_shell_surface(view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4424 | if (shsurf) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4425 | if (first == NULL) |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4426 | first = view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4427 | if (prev == switcher->current) |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4428 | next = view; |
| 4429 | prev = view; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4430 | view->alpha = 0.25; |
| 4431 | weston_view_geometry_dirty(view); |
| 4432 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4433 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4434 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 4435 | if (is_black_surface_view(view, NULL)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4436 | view->alpha = 0.25; |
| 4437 | weston_view_geometry_dirty(view); |
| 4438 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4439 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | if (next == NULL) |
| 4443 | next = first; |
| 4444 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4445 | if (next == NULL) |
| 4446 | return; |
| 4447 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4448 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4449 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4450 | |
| 4451 | switcher->current = next; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4452 | wl_list_for_each(view, &next->surface->views, surface_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4453 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4454 | |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4455 | shsurf = get_shell_surface(switcher->current->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4456 | if (shsurf && weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4457 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4458 | } |
| 4459 | |
| 4460 | static void |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4461 | switcher_handle_view_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4462 | { |
| 4463 | struct switcher *switcher = |
| 4464 | container_of(listener, struct switcher, listener); |
| 4465 | |
| 4466 | switcher_next(switcher); |
| 4467 | } |
| 4468 | |
| 4469 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4470 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4471 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4472 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4473 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4474 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4475 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4476 | 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] | 4477 | if (is_focus_view(view)) |
| 4478 | continue; |
| 4479 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4480 | view->alpha = 1.0; |
| 4481 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4482 | } |
| 4483 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 4484 | if (switcher->current) { |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 4485 | activate(switcher->shell, switcher->current, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 4486 | keyboard->seat, |
| 4487 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
| 4488 | } |
| 4489 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4490 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4491 | weston_keyboard_end_grab(keyboard); |
| 4492 | if (keyboard->input_method_resource) |
| 4493 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4494 | |
| 4495 | /* re-hide surfaces that were temporary shown during the switch */ |
| 4496 | struct weston_view **minimized; |
| 4497 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 4498 | /* with the exception of the current selected */ |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4499 | if ((*minimized)->surface != switcher->current->surface) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4500 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 4501 | 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] | 4502 | weston_view_damage_below(*minimized); |
| 4503 | } |
| 4504 | } |
| 4505 | wl_array_release(&switcher->minimized_array); |
| 4506 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4507 | free(switcher); |
| 4508 | } |
| 4509 | |
| 4510 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4511 | switcher_key(struct weston_keyboard_grab *grab, |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4512 | const struct timespec *time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4513 | { |
| 4514 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4515 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4516 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4517 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4518 | switcher_next(switcher); |
| 4519 | } |
| 4520 | |
| 4521 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4522 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4523 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4524 | uint32_t mods_locked, uint32_t group) |
| 4525 | { |
| 4526 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4527 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4528 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4529 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 4530 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 4531 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4532 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4533 | static void |
| 4534 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 4535 | { |
| 4536 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 4537 | |
| 4538 | switcher_destroy(switcher); |
| 4539 | } |
| 4540 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4541 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4542 | switcher_key, |
| 4543 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4544 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4545 | }; |
| 4546 | |
| 4547 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4548 | switcher_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4549 | uint32_t key, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4550 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4551 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4552 | struct switcher *switcher; |
| 4553 | |
| 4554 | switcher = malloc(sizeof *switcher); |
ganjing | c1e7151 | 2020-07-28 15:28:45 +0800 | [diff] [blame] | 4555 | if (!switcher) |
| 4556 | return; |
Pekka Paalanen | 4bb326b | 2021-05-14 14:37:46 +0300 | [diff] [blame] | 4557 | |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4558 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4559 | switcher->current = NULL; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4560 | switcher->listener.notify = switcher_handle_view_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4561 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4562 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4563 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 4564 | lower_fullscreen_layer(switcher->shell, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4565 | switcher->grab.interface = &switcher_grab; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4566 | weston_keyboard_start_grab(keyboard, &switcher->grab); |
| 4567 | weston_keyboard_set_focus(keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4568 | switcher_next(switcher); |
| 4569 | } |
| 4570 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4571 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4572 | backlight_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4573 | uint32_t key, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4574 | { |
| 4575 | struct weston_compositor *compositor = data; |
| 4576 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4577 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4578 | |
| 4579 | /* TODO: we're limiting to simple use cases, where we assume just |
| 4580 | * control on the primary display. We'd have to extend later if we |
| 4581 | * ever get support for setting backlights on random desktop LCD |
| 4582 | * panels though */ |
| 4583 | output = get_default_output(compositor); |
| 4584 | if (!output) |
| 4585 | return; |
| 4586 | |
| 4587 | if (!output->set_backlight) |
| 4588 | return; |
| 4589 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4590 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 4591 | backlight_new = output->backlight_current - 25; |
| 4592 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 4593 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4594 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4595 | if (backlight_new < 5) |
| 4596 | backlight_new = 5; |
| 4597 | if (backlight_new > 255) |
| 4598 | backlight_new = 255; |
| 4599 | |
| 4600 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4601 | output->set_backlight(output, output->backlight_current); |
| 4602 | } |
| 4603 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 4604 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4605 | force_kill_binding(struct weston_keyboard *keyboard, |
| 4606 | const struct timespec *time, uint32_t key, void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4607 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 4608 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4609 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 4610 | struct desktop_shell *shell = data; |
| 4611 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4612 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4613 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4614 | focus_surface = keyboard->focus; |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 4615 | if (!focus_surface) |
| 4616 | return; |
| 4617 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 4618 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 4619 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4620 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 4621 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 4622 | |
| 4623 | /* Skip clients that we launched ourselves (the credentials of |
| 4624 | * the socketpair is ours) */ |
| 4625 | if (pid == getpid()) |
| 4626 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4627 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4628 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4629 | } |
| 4630 | |
| 4631 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4632 | workspace_up_binding(struct weston_keyboard *keyboard, |
| 4633 | const struct timespec *time, uint32_t key, void *data) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4634 | { |
| 4635 | struct desktop_shell *shell = data; |
| 4636 | unsigned int new_index = shell->workspaces.current; |
| 4637 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4638 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4639 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4640 | if (new_index != 0) |
| 4641 | new_index--; |
| 4642 | |
| 4643 | change_workspace(shell, new_index); |
| 4644 | } |
| 4645 | |
| 4646 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4647 | workspace_down_binding(struct weston_keyboard *keyboard, |
| 4648 | const struct timespec *time, uint32_t key, void *data) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4649 | { |
| 4650 | struct desktop_shell *shell = data; |
| 4651 | unsigned int new_index = shell->workspaces.current; |
| 4652 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4653 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4654 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4655 | if (new_index < shell->workspaces.num - 1) |
| 4656 | new_index++; |
| 4657 | |
| 4658 | change_workspace(shell, new_index); |
| 4659 | } |
| 4660 | |
| 4661 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4662 | workspace_f_binding(struct weston_keyboard *keyboard, |
| 4663 | const struct timespec *time, uint32_t key, void *data) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4664 | { |
| 4665 | struct desktop_shell *shell = data; |
| 4666 | unsigned int new_index; |
| 4667 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4668 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4669 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4670 | new_index = key - KEY_F1; |
| 4671 | if (new_index >= shell->workspaces.num) |
| 4672 | new_index = shell->workspaces.num - 1; |
| 4673 | |
| 4674 | change_workspace(shell, new_index); |
| 4675 | } |
| 4676 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4677 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4678 | workspace_move_surface_up_binding(struct weston_keyboard *keyboard, |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4679 | const struct timespec *time, uint32_t key, |
| 4680 | void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4681 | { |
| 4682 | struct desktop_shell *shell = data; |
| 4683 | unsigned int new_index = shell->workspaces.current; |
| 4684 | |
| 4685 | if (shell->locked) |
| 4686 | return; |
| 4687 | |
| 4688 | if (new_index != 0) |
| 4689 | new_index--; |
| 4690 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4691 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4692 | } |
| 4693 | |
| 4694 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4695 | workspace_move_surface_down_binding(struct weston_keyboard *keyboard, |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4696 | const struct timespec *time, uint32_t key, |
| 4697 | void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4698 | { |
| 4699 | struct desktop_shell *shell = data; |
| 4700 | unsigned int new_index = shell->workspaces.current; |
| 4701 | |
| 4702 | if (shell->locked) |
| 4703 | return; |
| 4704 | |
| 4705 | if (new_index < shell->workspaces.num - 1) |
| 4706 | new_index++; |
| 4707 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4708 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4709 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4710 | |
| 4711 | static void |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4712 | shell_reposition_view_on_output_change(struct weston_view *view) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4713 | { |
| 4714 | struct weston_output *output, *first_output; |
| 4715 | struct weston_compositor *ec = view->surface->compositor; |
| 4716 | struct shell_surface *shsurf; |
| 4717 | float x, y; |
| 4718 | int visible; |
| 4719 | |
Harish Krupo | 2dff4dd | 2019-04-20 18:10:56 +0530 | [diff] [blame] | 4720 | if (wl_list_empty(&ec->output_list)) |
| 4721 | return; |
| 4722 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4723 | x = view->geometry.x; |
| 4724 | y = view->geometry.y; |
| 4725 | |
| 4726 | /* At this point the destroyed output is not in the list anymore. |
| 4727 | * If the view is still visible somewhere, we leave where it is, |
| 4728 | * otherwise, move it to the first output. */ |
| 4729 | visible = 0; |
| 4730 | wl_list_for_each(output, &ec->output_list, link) { |
| 4731 | if (pixman_region32_contains_point(&output->region, |
| 4732 | x, y, NULL)) { |
| 4733 | visible = 1; |
| 4734 | break; |
| 4735 | } |
| 4736 | } |
| 4737 | |
| 4738 | if (!visible) { |
| 4739 | first_output = container_of(ec->output_list.next, |
| 4740 | struct weston_output, link); |
| 4741 | |
| 4742 | x = first_output->x + first_output->width / 4; |
| 4743 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 4744 | |
| 4745 | weston_view_set_position(view, x, y); |
| 4746 | } else { |
| 4747 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4748 | } |
| 4749 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4750 | |
| 4751 | shsurf = get_shell_surface(view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4752 | if (!shsurf) |
| 4753 | return; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4754 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4755 | shsurf->saved_position_valid = false; |
| 4756 | set_maximized(shsurf, false); |
| 4757 | set_fullscreen(shsurf, false, NULL); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4758 | } |
| 4759 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4760 | void |
| 4761 | shell_for_each_layer(struct desktop_shell *shell, |
| 4762 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4763 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4764 | struct workspace **ws; |
| 4765 | |
| 4766 | func(shell, &shell->fullscreen_layer, data); |
| 4767 | func(shell, &shell->panel_layer, data); |
| 4768 | func(shell, &shell->background_layer, data); |
| 4769 | func(shell, &shell->lock_layer, data); |
| 4770 | func(shell, &shell->input_panel_layer, data); |
| 4771 | |
| 4772 | wl_array_for_each(ws, &shell->workspaces.array) |
| 4773 | func(shell, &(*ws)->layer, data); |
| 4774 | } |
| 4775 | |
| 4776 | static void |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4777 | shell_output_changed_move_layer(struct desktop_shell *shell, |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4778 | struct weston_layer *layer, |
| 4779 | void *data) |
| 4780 | { |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4781 | struct weston_view *view; |
| 4782 | |
Marius Vlad | ea40d6d | 2018-02-08 18:46:42 +0200 | [diff] [blame] | 4783 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4784 | shell_reposition_view_on_output_change(view); |
| 4785 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4786 | } |
| 4787 | |
| 4788 | static void |
Pekka Paalanen | 719ca87 | 2021-05-24 16:53:40 +0300 | [diff] [blame] | 4789 | shell_output_destroy(struct shell_output *shell_output) |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4790 | { |
Pekka Paalanen | 0d5e4ff | 2021-05-24 16:13:21 +0300 | [diff] [blame] | 4791 | struct desktop_shell *shell = shell_output->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4792 | |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4793 | shell_for_each_layer(shell, shell_output_changed_move_layer, NULL); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4794 | |
Pekka Paalanen | 719ca87 | 2021-05-24 16:53:40 +0300 | [diff] [blame] | 4795 | if (shell_output->fade.animation) { |
| 4796 | weston_view_animation_destroy(shell_output->fade.animation); |
| 4797 | shell_output->fade.animation = NULL; |
| 4798 | } |
| 4799 | |
| 4800 | if (shell_output->fade.view) { |
| 4801 | /* destroys the view as well */ |
| 4802 | weston_surface_destroy(shell_output->fade.view->surface); |
| 4803 | } |
| 4804 | |
| 4805 | if (shell_output->fade.startup_timer) |
| 4806 | wl_event_source_remove(shell_output->fade.startup_timer); |
| 4807 | |
Pekka Paalanen | 0d5e4ff | 2021-05-24 16:13:21 +0300 | [diff] [blame] | 4808 | if (shell_output->panel_surface) |
| 4809 | wl_list_remove(&shell_output->panel_surface_listener.link); |
| 4810 | if (shell_output->background_surface) |
| 4811 | wl_list_remove(&shell_output->background_surface_listener.link); |
| 4812 | wl_list_remove(&shell_output->destroy_listener.link); |
| 4813 | wl_list_remove(&shell_output->link); |
| 4814 | free(shell_output); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4815 | } |
| 4816 | |
| 4817 | static void |
Pekka Paalanen | 719ca87 | 2021-05-24 16:53:40 +0300 | [diff] [blame] | 4818 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 4819 | { |
| 4820 | struct shell_output *shell_output = |
| 4821 | container_of(listener, struct shell_output, destroy_listener); |
| 4822 | |
| 4823 | shell_output_destroy(shell_output); |
| 4824 | } |
| 4825 | |
| 4826 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4827 | shell_resize_surface_to_output(struct desktop_shell *shell, |
| 4828 | struct weston_surface *surface, |
| 4829 | const struct weston_output *output) |
| 4830 | { |
| 4831 | if (!surface) |
| 4832 | return; |
| 4833 | |
| 4834 | weston_desktop_shell_send_configure(shell->child.desktop_shell, 0, |
| 4835 | surface->resource, |
| 4836 | output->width, |
| 4837 | output->height); |
| 4838 | } |
| 4839 | |
| 4840 | |
| 4841 | static void |
| 4842 | handle_output_resized(struct wl_listener *listener, void *data) |
| 4843 | { |
| 4844 | struct desktop_shell *shell = |
| 4845 | container_of(listener, struct desktop_shell, resized_listener); |
| 4846 | struct weston_output *output = (struct weston_output *)data; |
| 4847 | struct shell_output *sh_output = find_shell_output_from_weston_output(shell, output); |
| 4848 | |
| 4849 | shell_resize_surface_to_output(shell, sh_output->background_surface, output); |
| 4850 | shell_resize_surface_to_output(shell, sh_output->panel_surface, output); |
| 4851 | } |
| 4852 | |
| 4853 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4854 | create_shell_output(struct desktop_shell *shell, |
| 4855 | struct weston_output *output) |
| 4856 | { |
| 4857 | struct shell_output *shell_output; |
| 4858 | |
| 4859 | shell_output = zalloc(sizeof *shell_output); |
| 4860 | if (shell_output == NULL) |
| 4861 | return; |
| 4862 | |
| 4863 | shell_output->output = output; |
| 4864 | shell_output->shell = shell; |
| 4865 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 4866 | wl_signal_add(&output->destroy_signal, |
| 4867 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 4868 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4869 | |
| 4870 | if (wl_list_length(&shell->output_list) == 1) |
| 4871 | shell_for_each_layer(shell, |
| 4872 | shell_output_changed_move_layer, NULL); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4873 | } |
| 4874 | |
| 4875 | static void |
| 4876 | handle_output_create(struct wl_listener *listener, void *data) |
| 4877 | { |
| 4878 | struct desktop_shell *shell = |
| 4879 | container_of(listener, struct desktop_shell, output_create_listener); |
| 4880 | struct weston_output *output = (struct weston_output *)data; |
| 4881 | |
| 4882 | create_shell_output(shell, output); |
| 4883 | } |
| 4884 | |
| 4885 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4886 | handle_output_move_layer(struct desktop_shell *shell, |
| 4887 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4888 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4889 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4890 | struct weston_view *view; |
| 4891 | float x, y; |
| 4892 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4893 | 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] | 4894 | if (view->output != output) |
| 4895 | continue; |
| 4896 | |
| 4897 | x = view->geometry.x + output->move_x; |
| 4898 | y = view->geometry.y + output->move_y; |
| 4899 | weston_view_set_position(view, x, y); |
| 4900 | } |
| 4901 | } |
| 4902 | |
| 4903 | static void |
| 4904 | handle_output_move(struct wl_listener *listener, void *data) |
| 4905 | { |
| 4906 | struct desktop_shell *shell; |
| 4907 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4908 | shell = container_of(listener, struct desktop_shell, |
| 4909 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4910 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4911 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4912 | } |
| 4913 | |
| 4914 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4915 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 4916 | struct desktop_shell *shell) |
| 4917 | { |
| 4918 | struct weston_output *output; |
| 4919 | |
| 4920 | wl_list_init(&shell->output_list); |
| 4921 | wl_list_for_each(output, &ec->output_list, link) |
| 4922 | create_shell_output(shell, output); |
| 4923 | |
| 4924 | shell->output_create_listener.notify = handle_output_create; |
| 4925 | wl_signal_add(&ec->output_created_signal, |
| 4926 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4927 | |
| 4928 | shell->output_move_listener.notify = handle_output_move; |
| 4929 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4933 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4934 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4935 | struct desktop_shell *shell = |
| 4936 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4937 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4938 | struct shell_output *shell_output, *tmp; |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 4939 | struct shell_seat *shseat, *shseat_next; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4940 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 4941 | /* Force state to unlocked so we don't try to fade */ |
| 4942 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4943 | |
| 4944 | if (shell->child.client) { |
| 4945 | /* disable respawn */ |
| 4946 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 4947 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4948 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 4949 | |
Harsha M M | b8b2c72 | 2018-08-07 19:05:02 +0530 | [diff] [blame] | 4950 | wl_list_remove(&shell->destroy_listener.link); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4951 | wl_list_remove(&shell->idle_listener.link); |
| 4952 | wl_list_remove(&shell->wake_listener.link); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4953 | wl_list_remove(&shell->transform_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 4954 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 4955 | text_backend_destroy(shell->text_backend); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 4956 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 4957 | |
Pekka Paalanen | 719ca87 | 2021-05-24 16:53:40 +0300 | [diff] [blame] | 4958 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) |
| 4959 | shell_output_destroy(shell_output); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4960 | |
| 4961 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 4962 | wl_list_remove(&shell->output_move_listener.link); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4963 | wl_list_remove(&shell->resized_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4964 | |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 4965 | wl_list_for_each_safe(shseat, shseat_next, &shell->seat_list, link) |
| 4966 | desktop_shell_destroy_seat(shseat); |
| 4967 | |
Pekka Paalanen | abd7292 | 2021-05-24 14:42:00 +0300 | [diff] [blame] | 4968 | weston_desktop_destroy(shell->desktop); |
| 4969 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4970 | wl_array_for_each(ws, &shell->workspaces.array) |
| 4971 | workspace_destroy(*ws); |
| 4972 | wl_array_release(&shell->workspaces.array); |
| 4973 | |
Pekka Paalanen | 4bb326b | 2021-05-14 14:37:46 +0300 | [diff] [blame] | 4974 | weston_layer_fini(&shell->fullscreen_layer); |
| 4975 | weston_layer_fini(&shell->panel_layer); |
| 4976 | weston_layer_fini(&shell->background_layer); |
| 4977 | weston_layer_fini(&shell->lock_layer); |
| 4978 | weston_layer_fini(&shell->input_panel_layer); |
| 4979 | weston_layer_fini(&shell->minimized_layer); |
| 4980 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4981 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4982 | free(shell); |
| 4983 | } |
| 4984 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4985 | static void |
| 4986 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 4987 | { |
| 4988 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4989 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4990 | |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 4991 | if (shell->allow_zap) |
| 4992 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 4993 | MODIFIER_CTRL | MODIFIER_ALT, |
| 4994 | terminate_binding, ec); |
| 4995 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4996 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4997 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 4998 | click_to_activate_binding, |
| 4999 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 5000 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 5001 | click_to_activate_binding, |
| 5002 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5003 | weston_compositor_add_touch_binding(ec, 0, |
| 5004 | touch_to_activate_binding, |
| 5005 | shell); |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 5006 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 5007 | backlight_binding, ec); |
| 5008 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 5009 | backlight_binding, ec); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5010 | |
| 5011 | /* configurable bindings */ |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 5012 | if (shell->exposay_modifier) |
| 5013 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 5014 | exposay_binding, shell); |
| 5015 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5016 | mod = shell->binding_modifier; |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 5017 | if (!mod) |
| 5018 | return; |
| 5019 | |
Ian Ray | 13404c4 | 2017-09-18 15:22:01 +0300 | [diff] [blame] | 5020 | /* This binding is not configurable, but is only enabled if there is a |
| 5021 | * valid binding modifier. */ |
| 5022 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5023 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5024 | surface_opacity_binding, NULL); |
| 5025 | |
Ian Ray | ab7c0b6 | 2017-09-18 15:22:00 +0300 | [diff] [blame] | 5026 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5027 | mod, zoom_axis_binding, |
| 5028 | NULL); |
| 5029 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5030 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5031 | zoom_key_binding, NULL); |
| 5032 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5033 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 5034 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 5035 | maximize_binding, NULL); |
| 5036 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 5037 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5038 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5039 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5040 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 5041 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5042 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 5043 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 5044 | mod | MODIFIER_SHIFT, |
| 5045 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5046 | |
| 5047 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 5048 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5049 | rotate_binding, NULL); |
| 5050 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5051 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5052 | shell); |
| 5053 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 5054 | ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5055 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 5056 | ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5057 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 5058 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5059 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 5060 | workspace_up_binding, shell); |
| 5061 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 5062 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5063 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 5064 | workspace_move_surface_up_binding, |
| 5065 | shell); |
| 5066 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 5067 | workspace_move_surface_down_binding, |
| 5068 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5069 | |
| 5070 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5071 | if (shell->workspaces.num > 1) { |
| 5072 | num_workspace_bindings = shell->workspaces.num; |
| 5073 | if (num_workspace_bindings > 6) |
| 5074 | num_workspace_bindings = 6; |
| 5075 | for (i = 0; i < num_workspace_bindings; i++) |
| 5076 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5077 | workspace_f_binding, |
| 5078 | shell); |
| 5079 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5080 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 5081 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5082 | } |
| 5083 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 5084 | static void |
| 5085 | handle_seat_created(struct wl_listener *listener, void *data) |
| 5086 | { |
| 5087 | struct weston_seat *seat = data; |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 5088 | struct desktop_shell *shell = |
| 5089 | container_of(listener, struct desktop_shell, seat_create_listener); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 5090 | |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 5091 | create_shell_seat(shell, seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 5092 | } |
| 5093 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5094 | WL_EXPORT int |
Quentin Glidic | da01c1d | 2016-12-02 14:17:08 +0100 | [diff] [blame] | 5095 | wet_shell_init(struct weston_compositor *ec, |
| 5096 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5097 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5098 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5099 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5100 | struct workspace **pws; |
| 5101 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5102 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5103 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 5104 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5105 | if (shell == NULL) |
| 5106 | return -1; |
| 5107 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5108 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5109 | |
Pekka Paalanen | 6ffbba3 | 2019-11-06 12:59:32 +0200 | [diff] [blame] | 5110 | if (!weston_compositor_add_destroy_listener_once(ec, |
| 5111 | &shell->destroy_listener, |
| 5112 | shell_destroy)) { |
| 5113 | free(shell); |
| 5114 | return 0; |
| 5115 | } |
| 5116 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5117 | shell->idle_listener.notify = idle_handler; |
| 5118 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 5119 | shell->wake_listener.notify = wake_handler; |
| 5120 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 5121 | shell->transform_listener.notify = transform_handler; |
| 5122 | wl_signal_add(&ec->transform_signal, &shell->transform_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5123 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 5124 | weston_layer_init(&shell->fullscreen_layer, ec); |
| 5125 | weston_layer_init(&shell->panel_layer, ec); |
| 5126 | weston_layer_init(&shell->background_layer, ec); |
| 5127 | weston_layer_init(&shell->lock_layer, ec); |
| 5128 | weston_layer_init(&shell->input_panel_layer, ec); |
| 5129 | |
| 5130 | weston_layer_set_position(&shell->fullscreen_layer, |
| 5131 | WESTON_LAYER_POSITION_FULLSCREEN); |
| 5132 | weston_layer_set_position(&shell->panel_layer, |
| 5133 | WESTON_LAYER_POSITION_UI); |
| 5134 | weston_layer_set_position(&shell->background_layer, |
| 5135 | WESTON_LAYER_POSITION_BACKGROUND); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5136 | |
| 5137 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5138 | wl_list_init(&shell->workspaces.client_list); |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 5139 | wl_list_init(&shell->seat_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5140 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5141 | if (input_panel_setup(shell) < 0) |
| 5142 | return -1; |
| 5143 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 5144 | shell->text_backend = text_backend_init(ec); |
| 5145 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 5146 | return -1; |
| 5147 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5148 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 5149 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5150 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 5151 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 5152 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5153 | for (i = 0; i < shell->workspaces.num; i++) { |
| 5154 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 5155 | if (pws == NULL) |
| 5156 | return -1; |
| 5157 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 5158 | *pws = workspace_create(shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5159 | if (*pws == NULL) |
| 5160 | return -1; |
| 5161 | } |
| 5162 | activate_workspace(shell, 0); |
| 5163 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 5164 | weston_layer_init(&shell->minimized_layer, ec); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 5165 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5166 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 5167 | wl_list_init(&shell->workspaces.animation.link); |
| 5168 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 5169 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 5170 | shell->desktop = weston_desktop_create(ec, &shell_desktop_api, shell); |
| 5171 | if (!shell->desktop) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5172 | return -1; |
| 5173 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5174 | if (wl_global_create(ec->wl_display, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5175 | &weston_desktop_shell_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5176 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5177 | return -1; |
| 5178 | |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 5179 | weston_compositor_get_time(&shell->child.deathstamp); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5180 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5181 | shell->panel_position = WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP; |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 5182 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5183 | setup_output_destroy_handler(ec, shell); |
| 5184 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5185 | loop = wl_display_get_event_loop(ec->wl_display); |
| 5186 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5187 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 5188 | wl_list_for_each(seat, &ec->seat_list, link) |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 5189 | create_shell_seat(shell, seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 5190 | shell->seat_create_listener.notify = handle_seat_created; |
| 5191 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 5192 | |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 5193 | shell->resized_listener.notify = handle_output_resized; |
| 5194 | wl_signal_add(&ec->output_resized_signal, &shell->resized_listener); |
| 5195 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 5196 | screenshooter_create(ec); |
| 5197 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5198 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5199 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5200 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5201 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5202 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 5203 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5204 | return 0; |
| 5205 | } |