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" |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 44 | #include "shared/timespec-util.h" |
Pekka Paalanen | 8ebd981 | 2019-04-04 16:02:14 +0300 | [diff] [blame] | 45 | #include <libweston-desktop/libweston-desktop.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 46 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 47 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 48 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 49 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 50 | struct focus_state { |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 51 | struct desktop_shell *shell; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 52 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 53 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 54 | struct weston_surface *keyboard_focus; |
| 55 | struct wl_list link; |
| 56 | struct wl_listener seat_destroy_listener; |
| 57 | struct wl_listener surface_destroy_listener; |
| 58 | }; |
| 59 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 60 | /* |
| 61 | * Surface stacking and ordering. |
| 62 | * |
| 63 | * This is handled using several linked lists of surfaces, organised into |
| 64 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 65 | * above all of the surfaces in the layer below. The set of layers is static and |
| 66 | * in the following order (top-most first): |
| 67 | * • Lock layer (only ever displayed on its own) |
| 68 | * • Cursor layer |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 69 | * • Input panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 70 | * • Fullscreen layer |
| 71 | * • Panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 72 | * • Workspace layers |
| 73 | * • Background layer |
| 74 | * |
| 75 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 76 | * display. For example, when locking the screen, all layers except the lock |
| 77 | * layer are removed. |
| 78 | * |
| 79 | * A surface’s layer is modified on configuring the surface, in |
| 80 | * set_surface_type() (which is only called when the surface’s type change is |
| 81 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 82 | * fullscreen) its layer changes too. |
| 83 | * |
| 84 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 85 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 86 | * linked list of its children. When a surface’s layer is updated, so are the |
| 87 | * layers of its children. Note that child surfaces are *not* the same as |
| 88 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 89 | * order. |
| 90 | * |
| 91 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 92 | * have the same parent) only contains weston_surfaces which have a |
| 93 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 94 | * weston_surfaces. This means that the following implication does *not* hold: |
| 95 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 96 | */ |
| 97 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 98 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 99 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 100 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 101 | struct weston_desktop_surface *desktop_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 102 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 103 | int32_t last_width, last_height; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 104 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 105 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 106 | |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 107 | struct wl_list children_list; |
| 108 | struct wl_list children_link; |
| 109 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 110 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 111 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 112 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 113 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 114 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 115 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 116 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 117 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 118 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 119 | } rotation; |
| 120 | |
| 121 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 122 | struct weston_transform transform; /* matrix from x, y */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 123 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 124 | } fullscreen; |
| 125 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 126 | struct weston_transform workspace_transform; |
| 127 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 128 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 129 | struct weston_output *output; |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame] | 130 | struct wl_listener output_destroy_listener; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 131 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 132 | struct surface_state { |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 133 | bool fullscreen; |
| 134 | bool maximized; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 135 | bool lowered; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 136 | } state; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 137 | |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 138 | struct { |
| 139 | bool is_set; |
| 140 | int32_t x; |
| 141 | int32_t y; |
| 142 | } xwayland; |
| 143 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 144 | int focus_count; |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 145 | |
| 146 | bool destroying; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 147 | }; |
| 148 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 149 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 150 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 151 | struct shell_surface *shsurf; |
| 152 | struct wl_listener shsurf_destroy_listener; |
| 153 | }; |
| 154 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 155 | struct shell_touch_grab { |
| 156 | struct weston_touch_grab grab; |
| 157 | struct shell_surface *shsurf; |
| 158 | struct wl_listener shsurf_destroy_listener; |
| 159 | struct weston_touch *touch; |
| 160 | }; |
| 161 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 162 | struct weston_move_grab { |
| 163 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 164 | wl_fixed_t dx, dy; |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 165 | bool client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 166 | }; |
| 167 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 168 | struct weston_touch_move_grab { |
| 169 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 170 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 171 | wl_fixed_t dx, dy; |
| 172 | }; |
| 173 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 174 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 175 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 176 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 177 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 178 | float x; |
| 179 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 180 | } center; |
| 181 | }; |
| 182 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 183 | struct shell_seat { |
| 184 | struct weston_seat *seat; |
| 185 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 186 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 187 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 188 | struct wl_listener caps_changed_listener; |
| 189 | struct wl_listener pointer_focus_listener; |
| 190 | struct wl_listener keyboard_focus_listener; |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 191 | |
| 192 | struct wl_list link; /** shell::seat_list */ |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 193 | }; |
| 194 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 195 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 196 | static struct desktop_shell * |
| 197 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 198 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 199 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 200 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 201 | |
| 202 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 203 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 204 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 205 | static void |
| 206 | shell_fade_startup(struct desktop_shell *shell); |
| 207 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 208 | static void |
| 209 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 210 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 211 | static struct shell_seat * |
| 212 | get_shell_seat(struct weston_seat *seat); |
| 213 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 214 | static void |
| 215 | get_output_panel_size(struct desktop_shell *shell, |
| 216 | struct weston_output *output, |
| 217 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 218 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 219 | static void |
| 220 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 221 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 222 | static int |
| 223 | shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 224 | { |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 225 | const char *t, *c; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 226 | struct weston_desktop_surface *desktop_surface = |
| 227 | weston_surface_get_desktop_surface(surface); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 228 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 229 | t = weston_desktop_surface_get_title(desktop_surface); |
| 230 | c = weston_desktop_surface_get_app_id(desktop_surface); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 231 | |
| 232 | return snprintf(buf, len, "%s window%s%s%s%s%s", |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 233 | "top-level", |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 234 | t ? " '" : "", t ?: "", t ? "'" : "", |
| 235 | c ? " of " : "", c ?: ""); |
| 236 | } |
| 237 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 238 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 239 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 240 | { |
| 241 | struct shell_grab *grab; |
| 242 | |
| 243 | grab = container_of(listener, struct shell_grab, |
| 244 | shsurf_destroy_listener); |
| 245 | |
| 246 | grab->shsurf = NULL; |
| 247 | } |
| 248 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 249 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 250 | get_default_view(struct weston_surface *surface) |
| 251 | { |
| 252 | struct shell_surface *shsurf; |
| 253 | struct weston_view *view; |
| 254 | |
| 255 | if (!surface || wl_list_empty(&surface->views)) |
| 256 | return NULL; |
| 257 | |
| 258 | shsurf = get_shell_surface(surface); |
| 259 | if (shsurf) |
| 260 | return shsurf->view; |
| 261 | |
| 262 | wl_list_for_each(view, &surface->views, surface_link) |
| 263 | if (weston_view_is_mapped(view)) |
| 264 | return view; |
| 265 | |
| 266 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 267 | } |
| 268 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 269 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 270 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 271 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 272 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 273 | struct weston_pointer *pointer, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 274 | enum weston_desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 275 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 276 | struct desktop_shell *shell = shsurf->shell; |
| 277 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 278 | weston_seat_break_desktop_grabs(pointer->seat); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 279 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 280 | grab->grab.interface = interface; |
| 281 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 282 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 283 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 284 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 285 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 286 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 287 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 288 | if (shell->child.desktop_shell) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 289 | weston_desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 290 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 291 | weston_pointer_set_focus(pointer, |
| 292 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 293 | wl_fixed_from_int(0), |
| 294 | wl_fixed_from_int(0)); |
| 295 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 296 | } |
| 297 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 298 | static void |
Quentin Glidic | 581df06 | 2016-06-23 18:55:19 +0200 | [diff] [blame] | 299 | get_panel_size(struct desktop_shell *shell, |
| 300 | struct weston_view *view, |
| 301 | int *width, |
| 302 | int *height) |
| 303 | { |
| 304 | float x1, y1; |
| 305 | float x2, y2; |
| 306 | weston_view_to_global_float(view, 0, 0, &x1, &y1); |
| 307 | weston_view_to_global_float(view, |
| 308 | view->surface->width, |
| 309 | view->surface->height, |
| 310 | &x2, &y2); |
| 311 | *width = (int)(x2 - x1); |
| 312 | *height = (int)(y2 - y1); |
| 313 | } |
| 314 | |
| 315 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 316 | get_output_panel_size(struct desktop_shell *shell, |
| 317 | struct weston_output *output, |
| 318 | int *width, |
| 319 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 320 | { |
| 321 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 322 | |
| 323 | *width = 0; |
| 324 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 325 | |
| 326 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 327 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 328 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 329 | 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] | 330 | if (view->surface->output == output) { |
| 331 | get_panel_size(shell, view, width, height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 332 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 336 | /* the correct view wasn't found */ |
| 337 | } |
| 338 | |
Leandro Ribeiro | 0c59e92 | 2020-01-24 17:53:44 -0300 | [diff] [blame] | 339 | void |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 340 | get_output_work_area(struct desktop_shell *shell, |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 341 | struct weston_output *output, |
| 342 | pixman_rectangle32_t *area) |
| 343 | { |
| 344 | int32_t panel_width = 0, panel_height = 0; |
| 345 | |
Pekka Paalanen | 99372ba | 2018-05-02 10:21:55 +0200 | [diff] [blame] | 346 | if (!output) { |
| 347 | area->x = 0; |
| 348 | area->y = 0; |
| 349 | area->width = 0; |
| 350 | area->height = 0; |
| 351 | |
| 352 | return; |
| 353 | } |
| 354 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 355 | area->x = output->x; |
| 356 | area->y = output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 357 | |
| 358 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 359 | switch (shell->panel_position) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 360 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 361 | default: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 362 | area->y += panel_height; |
Daniel Stone | 2ef9b1a | 2017-03-13 16:31:36 +0000 | [diff] [blame] | 363 | /* fallthrough */ |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 364 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 365 | area->width = output->width; |
| 366 | area->height = output->height - panel_height; |
| 367 | break; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 368 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 369 | area->x += panel_width; |
Daniel Stone | 2ef9b1a | 2017-03-13 16:31:36 +0000 | [diff] [blame] | 370 | /* fallthrough */ |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 371 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 372 | area->width = output->width - panel_width; |
| 373 | area->height = output->height; |
| 374 | break; |
| 375 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 378 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 379 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 380 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 381 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 382 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 383 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 384 | |
| 385 | if (grab->shsurf->resize_edges) { |
| 386 | grab->shsurf->resize_edges = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 387 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 388 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 389 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 390 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 394 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 395 | const struct weston_touch_grab_interface *interface, |
| 396 | struct shell_surface *shsurf, |
| 397 | struct weston_touch *touch) |
| 398 | { |
| 399 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 400 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 401 | weston_seat_break_desktop_grabs(touch->seat); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 402 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 403 | grab->grab.interface = interface; |
| 404 | grab->shsurf = shsurf; |
| 405 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 406 | wl_signal_add(&shsurf->destroy_signal, |
| 407 | &grab->shsurf_destroy_listener); |
| 408 | |
| 409 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 410 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 411 | |
| 412 | weston_touch_start_grab(touch, &grab->grab); |
| 413 | if (shell->child.desktop_shell) |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 414 | weston_touch_set_focus(touch, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 415 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | static void |
| 419 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 420 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 421 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 422 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 423 | grab->shsurf->grabbed = 0; |
| 424 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 425 | |
| 426 | weston_touch_end_grab(grab->touch); |
| 427 | } |
| 428 | |
| 429 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 430 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 431 | struct weston_output *output); |
| 432 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 433 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 434 | get_modifier(char *modifier) |
| 435 | { |
| 436 | if (!modifier) |
| 437 | return MODIFIER_SUPER; |
| 438 | |
| 439 | if (!strcmp("ctrl", modifier)) |
| 440 | return MODIFIER_CTRL; |
| 441 | else if (!strcmp("alt", modifier)) |
| 442 | return MODIFIER_ALT; |
| 443 | else if (!strcmp("super", modifier)) |
| 444 | return MODIFIER_SUPER; |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 445 | else if (!strcmp("none", modifier)) |
| 446 | return 0; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 447 | else |
| 448 | return MODIFIER_SUPER; |
| 449 | } |
| 450 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 451 | static enum animation_type |
| 452 | get_animation_type(char *animation) |
| 453 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 454 | if (!animation) |
| 455 | return ANIMATION_NONE; |
| 456 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 457 | if (!strcmp("zoom", animation)) |
| 458 | return ANIMATION_ZOOM; |
| 459 | else if (!strcmp("fade", animation)) |
| 460 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 461 | else if (!strcmp("dim-layer", animation)) |
| 462 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 463 | else |
| 464 | return ANIMATION_NONE; |
| 465 | } |
| 466 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 467 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 468 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 469 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 470 | struct weston_config_section *section; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 471 | char *s, *client; |
Daniel Stone | 51d995a | 2019-11-26 00:14:24 +0000 | [diff] [blame] | 472 | bool allow_zap; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 473 | |
Giulio Camuffo | d52f3b7 | 2016-06-02 21:48:11 +0300 | [diff] [blame] | 474 | section = weston_config_get_section(wet_get_config(shell->compositor), |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 475 | "shell", NULL, NULL); |
Marius Vlad | 64fbd0f | 2018-12-15 15:51:57 +0200 | [diff] [blame] | 476 | client = wet_get_libexec_path(WESTON_SHELL_CLIENT); |
Daniel Stone | e03c111 | 2016-11-24 20:45:45 +0000 | [diff] [blame] | 477 | weston_config_section_get_string(section, "client", &s, client); |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 478 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 479 | shell->client = s; |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 480 | |
| 481 | weston_config_section_get_bool(section, |
| 482 | "allow-zap", &allow_zap, true); |
| 483 | shell->allow_zap = allow_zap; |
| 484 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 485 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 486 | "binding-modifier", &s, "super"); |
| 487 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 488 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 489 | |
| 490 | weston_config_section_get_string(section, |
| 491 | "exposay-modifier", &s, "none"); |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 492 | shell->exposay_modifier = get_modifier(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 493 | free(s); |
| 494 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 495 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 496 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 497 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 498 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 499 | shell->win_close_animation_type = get_animation_type(s); |
| 500 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 501 | weston_config_section_get_string(section, |
| 502 | "startup-animation", &s, "fade"); |
| 503 | shell->startup_animation_type = get_animation_type(s); |
| 504 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 505 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 506 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 507 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 508 | shell->focus_animation_type = get_animation_type(s); |
| 509 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 510 | weston_config_section_get_uint(section, "num-workspaces", |
| 511 | &shell->workspaces.num, |
| 512 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 513 | } |
| 514 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 515 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 516 | get_default_output(struct weston_compositor *compositor) |
| 517 | { |
Armin Krezović | 10b0618 | 2016-06-23 11:59:30 +0200 | [diff] [blame] | 518 | if (wl_list_empty(&compositor->output_list)) |
| 519 | return NULL; |
| 520 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 521 | return container_of(compositor->output_list.next, |
| 522 | struct weston_output, link); |
| 523 | } |
| 524 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 525 | static int |
| 526 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 527 | { |
| 528 | return snprintf(buf, len, "focus highlight effect for output %s", |
Miguel A. Vico | 620f68d | 2019-09-25 11:23:13 -0700 | [diff] [blame] | 529 | (surface->output ? surface->output->name : "NULL")); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 530 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 531 | |
| 532 | /* no-op func for checking focus surface */ |
| 533 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 534 | 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] | 535 | { |
| 536 | } |
| 537 | |
| 538 | static struct focus_surface * |
| 539 | get_focus_surface(struct weston_surface *surface) |
| 540 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 541 | if (surface->committed == focus_surface_committed) |
| 542 | return surface->committed_private; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 543 | else |
| 544 | return NULL; |
| 545 | } |
| 546 | |
| 547 | static bool |
| 548 | is_focus_surface (struct weston_surface *es) |
| 549 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 550 | return (es->committed == focus_surface_committed); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | static bool |
| 554 | is_focus_view (struct weston_view *view) |
| 555 | { |
| 556 | return is_focus_surface (view->surface); |
| 557 | } |
| 558 | |
| 559 | static struct focus_surface * |
| 560 | create_focus_surface(struct weston_compositor *ec, |
| 561 | struct weston_output *output) |
| 562 | { |
| 563 | struct focus_surface *fsurf = NULL; |
| 564 | struct weston_surface *surface = NULL; |
| 565 | |
| 566 | fsurf = malloc(sizeof *fsurf); |
| 567 | if (!fsurf) |
| 568 | return NULL; |
| 569 | |
| 570 | fsurf->surface = weston_surface_create(ec); |
| 571 | surface = fsurf->surface; |
| 572 | if (surface == NULL) { |
| 573 | free(fsurf); |
| 574 | return NULL; |
| 575 | } |
| 576 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 577 | surface->committed = focus_surface_committed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 578 | surface->output = output; |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 579 | surface->is_mapped = true; |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 580 | surface->committed_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 581 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 582 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 583 | fsurf->view = weston_view_create(surface); |
| 584 | if (fsurf->view == NULL) { |
| 585 | weston_surface_destroy(surface); |
| 586 | free(fsurf); |
| 587 | return NULL; |
| 588 | } |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 589 | weston_view_set_output(fsurf->view, output); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 590 | fsurf->view->is_mapped = true; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 591 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 592 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 593 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 594 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 595 | pixman_region32_fini(&surface->opaque); |
| 596 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 597 | output->width, output->height); |
| 598 | pixman_region32_fini(&surface->input); |
| 599 | pixman_region32_init(&surface->input); |
| 600 | |
| 601 | wl_list_init(&fsurf->workspace_transform.link); |
| 602 | |
| 603 | return fsurf; |
| 604 | } |
| 605 | |
| 606 | static void |
| 607 | focus_surface_destroy(struct focus_surface *fsurf) |
| 608 | { |
| 609 | weston_surface_destroy(fsurf->surface); |
| 610 | free(fsurf); |
| 611 | } |
| 612 | |
| 613 | static void |
| 614 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 615 | { |
| 616 | struct workspace *ws = data; |
| 617 | |
| 618 | ws->focus_animation = NULL; |
| 619 | } |
| 620 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 621 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 622 | focus_state_destroy(struct focus_state *state) |
| 623 | { |
| 624 | wl_list_remove(&state->seat_destroy_listener.link); |
| 625 | wl_list_remove(&state->surface_destroy_listener.link); |
| 626 | free(state); |
| 627 | } |
| 628 | |
| 629 | static void |
| 630 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 631 | { |
| 632 | struct focus_state *state = container_of(listener, |
| 633 | struct focus_state, |
| 634 | seat_destroy_listener); |
| 635 | |
| 636 | wl_list_remove(&state->link); |
| 637 | focus_state_destroy(state); |
| 638 | } |
| 639 | |
| 640 | static void |
| 641 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 642 | { |
| 643 | struct focus_state *state = container_of(listener, |
| 644 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 645 | surface_destroy_listener); |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 646 | struct weston_surface *main_surface; |
| 647 | struct weston_view *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 648 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 649 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 650 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 651 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 652 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 653 | wl_list_for_each(view, |
| 654 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 655 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 656 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 657 | if (is_focus_view(view)) |
| 658 | continue; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 659 | if (!get_shell_surface(view->surface)) |
| 660 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 661 | |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 662 | next = view; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 663 | break; |
| 664 | } |
| 665 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 666 | /* if the focus was a sub-surface, activate its main surface */ |
| 667 | if (main_surface != state->keyboard_focus) |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 668 | next = get_default_view(main_surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 669 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 670 | if (next) { |
Greg V | 15d3d30 | 2018-12-07 01:33:34 +0300 | [diff] [blame] | 671 | if (state->keyboard_focus) { |
| 672 | wl_list_remove(&state->surface_destroy_listener.link); |
| 673 | wl_list_init(&state->surface_destroy_listener.link); |
| 674 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 675 | state->keyboard_focus = NULL; |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 676 | activate(state->shell, next, state->seat, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 677 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 678 | } else { |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 679 | if (state->shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 680 | if (state->ws->focus_animation) |
| 681 | weston_view_animation_destroy(state->ws->focus_animation); |
| 682 | |
| 683 | state->ws->focus_animation = weston_fade_run( |
| 684 | state->ws->fsurf_front->view, |
| 685 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 686 | focus_animation_done, state->ws); |
| 687 | } |
| 688 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 689 | wl_list_remove(&state->link); |
| 690 | focus_state_destroy(state); |
| 691 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | static struct focus_state * |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 695 | focus_state_create(struct desktop_shell *shell, struct weston_seat *seat, |
| 696 | struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 697 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 698 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 699 | |
| 700 | state = malloc(sizeof *state); |
| 701 | if (state == NULL) |
| 702 | return NULL; |
| 703 | |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 704 | state->shell = shell; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 705 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 706 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 707 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 708 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 709 | |
| 710 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 711 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 712 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 713 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 714 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 715 | |
| 716 | return state; |
| 717 | } |
| 718 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 719 | static struct focus_state * |
| 720 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 721 | { |
| 722 | struct workspace *ws = get_current_workspace(shell); |
| 723 | struct focus_state *state; |
| 724 | |
| 725 | wl_list_for_each(state, &ws->focus_list, link) |
| 726 | if (state->seat == seat) |
| 727 | break; |
| 728 | |
| 729 | if (&state->link == &ws->focus_list) |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 730 | state = focus_state_create(shell, seat, ws); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 731 | |
| 732 | return state; |
| 733 | } |
| 734 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 735 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 736 | focus_state_set_focus(struct focus_state *state, |
| 737 | struct weston_surface *surface) |
| 738 | { |
| 739 | if (state->keyboard_focus) { |
| 740 | wl_list_remove(&state->surface_destroy_listener.link); |
| 741 | wl_list_init(&state->surface_destroy_listener.link); |
| 742 | } |
| 743 | |
| 744 | state->keyboard_focus = surface; |
| 745 | if (surface) |
| 746 | wl_signal_add(&surface->destroy_signal, |
| 747 | &state->surface_destroy_listener); |
| 748 | } |
| 749 | |
| 750 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 751 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 752 | { |
| 753 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 754 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 755 | struct wl_list pending_seat_list; |
| 756 | struct weston_seat *seat, *next_seat; |
| 757 | |
| 758 | /* Temporarily steal the list of seats so that we can keep |
| 759 | * track of the seats we've already processed */ |
| 760 | wl_list_init(&pending_seat_list); |
| 761 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 762 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 763 | |
| 764 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 765 | struct weston_keyboard *keyboard = |
| 766 | weston_seat_get_keyboard(state->seat); |
| 767 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 768 | wl_list_remove(&state->seat->link); |
| 769 | wl_list_insert(&shell->compositor->seat_list, |
| 770 | &state->seat->link); |
| 771 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 772 | if (!keyboard) |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 773 | continue; |
| 774 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 775 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 776 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 777 | weston_keyboard_set_focus(keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 778 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 779 | |
| 780 | /* For any remaining seats that we don't have a focus state |
| 781 | * for we'll reset the keyboard focus to NULL */ |
| 782 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 783 | struct weston_keyboard *keyboard = |
| 784 | weston_seat_get_keyboard(seat); |
| 785 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 786 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 787 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 788 | if (!keyboard) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 789 | continue; |
| 790 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 791 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 792 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 796 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 797 | struct weston_seat *seat) |
| 798 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 799 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 800 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 801 | |
| 802 | wl_list_for_each(state, &ws->focus_list, link) { |
| 803 | if (state->seat == seat) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 804 | focus_state_set_focus(state, keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 805 | return; |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | static void |
| 811 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 812 | struct weston_surface *surface) |
| 813 | { |
| 814 | struct focus_state *state; |
| 815 | |
| 816 | wl_list_for_each(state, &ws->focus_list, link) |
| 817 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 818 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 822 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 823 | struct weston_view *from, struct weston_view *to) |
| 824 | { |
| 825 | struct weston_output *output; |
| 826 | bool focus_surface_created = false; |
| 827 | |
| 828 | /* FIXME: Only support dim animation using two layers */ |
| 829 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 830 | return; |
| 831 | |
| 832 | output = get_default_output(shell->compositor); |
| 833 | if (ws->fsurf_front == NULL && (from || to)) { |
| 834 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 835 | if (ws->fsurf_front == NULL) |
| 836 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 837 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 838 | |
| 839 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 840 | if (ws->fsurf_back == NULL) { |
| 841 | focus_surface_destroy(ws->fsurf_front); |
| 842 | return; |
| 843 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 844 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 845 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 846 | focus_surface_created = true; |
| 847 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 848 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 849 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | if (ws->focus_animation) { |
| 853 | weston_view_animation_destroy(ws->focus_animation); |
| 854 | ws->focus_animation = NULL; |
| 855 | } |
| 856 | |
| 857 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 858 | weston_layer_entry_insert(&to->layer_link, |
| 859 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 860 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 861 | weston_layer_entry_insert(&ws->layer.view_list, |
| 862 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 863 | |
| 864 | if (focus_surface_created) { |
| 865 | ws->focus_animation = weston_fade_run( |
| 866 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 867 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 868 | focus_animation_done, ws); |
| 869 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 870 | weston_layer_entry_insert(&from->layer_link, |
| 871 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 872 | ws->focus_animation = weston_stable_fade_run( |
| 873 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 874 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 875 | focus_animation_done, ws); |
| 876 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 877 | weston_layer_entry_insert(&ws->layer.view_list, |
| 878 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 879 | ws->focus_animation = weston_stable_fade_run( |
| 880 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 881 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 882 | focus_animation_done, ws); |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 887 | workspace_destroy(struct workspace *ws) |
| 888 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 889 | struct focus_state *state, *next; |
| 890 | |
| 891 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 892 | focus_state_destroy(state); |
| 893 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 894 | if (ws->fsurf_front) |
| 895 | focus_surface_destroy(ws->fsurf_front); |
| 896 | if (ws->fsurf_back) |
| 897 | focus_surface_destroy(ws->fsurf_back); |
| 898 | |
Pekka Paalanen | 4bb326b | 2021-05-14 14:37:46 +0300 | [diff] [blame] | 899 | weston_layer_fini(&ws->layer); |
| 900 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 901 | free(ws); |
| 902 | } |
| 903 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 904 | static void |
| 905 | seat_destroyed(struct wl_listener *listener, void *data) |
| 906 | { |
| 907 | struct weston_seat *seat = data; |
| 908 | struct focus_state *state, *next; |
| 909 | struct workspace *ws = container_of(listener, |
| 910 | struct workspace, |
| 911 | seat_destroyed_listener); |
| 912 | |
| 913 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 914 | if (state->seat == seat) |
| 915 | wl_list_remove(&state->link); |
| 916 | } |
| 917 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 918 | static struct workspace * |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 919 | workspace_create(struct desktop_shell *shell) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 920 | { |
| 921 | struct workspace *ws = malloc(sizeof *ws); |
| 922 | if (ws == NULL) |
| 923 | return NULL; |
| 924 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 925 | weston_layer_init(&ws->layer, shell->compositor); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 926 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 927 | wl_list_init(&ws->focus_list); |
| 928 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 929 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 930 | ws->fsurf_front = NULL; |
| 931 | ws->fsurf_back = NULL; |
| 932 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 933 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 934 | return ws; |
| 935 | } |
| 936 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 937 | static int |
| 938 | workspace_is_empty(struct workspace *ws) |
| 939 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 940 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 941 | } |
| 942 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 943 | static struct workspace * |
| 944 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 945 | { |
| 946 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 947 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 948 | pws += index; |
| 949 | return *pws; |
| 950 | } |
| 951 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 952 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 953 | get_current_workspace(struct desktop_shell *shell) |
| 954 | { |
| 955 | return get_workspace(shell, shell->workspaces.current); |
| 956 | } |
| 957 | |
| 958 | static void |
| 959 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 960 | { |
| 961 | struct workspace *ws; |
| 962 | |
| 963 | ws = get_workspace(shell, index); |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 964 | weston_layer_set_position(&ws->layer, WESTON_LAYER_POSITION_NORMAL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 965 | |
| 966 | shell->workspaces.current = index; |
| 967 | } |
| 968 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 969 | static unsigned int |
| 970 | get_output_height(struct weston_output *output) |
| 971 | { |
| 972 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 973 | } |
| 974 | |
Greg V | f57774e | 2018-07-24 23:21:55 +0300 | [diff] [blame] | 975 | static struct weston_transform * |
| 976 | view_get_transform(struct weston_view *view) |
| 977 | { |
| 978 | struct focus_surface *fsurf = NULL; |
| 979 | struct shell_surface *shsurf = NULL; |
| 980 | |
| 981 | if (is_focus_view(view)) { |
| 982 | fsurf = get_focus_surface(view->surface); |
| 983 | return &fsurf->workspace_transform; |
| 984 | } |
| 985 | |
| 986 | shsurf = get_shell_surface(view->surface); |
| 987 | if (shsurf) |
| 988 | return &shsurf->workspace_transform; |
| 989 | |
| 990 | return NULL; |
| 991 | } |
| 992 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 993 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 994 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 995 | { |
Greg V | f57774e | 2018-07-24 23:21:55 +0300 | [diff] [blame] | 996 | struct weston_transform *transform = view_get_transform(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 997 | |
Greg V | f57774e | 2018-07-24 23:21:55 +0300 | [diff] [blame] | 998 | if (!transform) |
| 999 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1000 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1001 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1002 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1003 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1004 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1005 | weston_matrix_init(&transform->matrix); |
| 1006 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1007 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1008 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | static void |
| 1012 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1013 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1014 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1015 | unsigned int height; |
| 1016 | double d; |
| 1017 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1018 | 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] | 1019 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1020 | d = height * fraction; |
| 1021 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1022 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | static void |
| 1027 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1028 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1029 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1030 | unsigned int height; |
| 1031 | double d; |
| 1032 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1033 | 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] | 1034 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1035 | |
| 1036 | if (fraction > 0) |
| 1037 | d = -(height - height * fraction); |
| 1038 | else |
| 1039 | d = height + height * fraction; |
| 1040 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1041 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1046 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1047 | unsigned int index, |
| 1048 | struct workspace *from, |
| 1049 | struct workspace *to) |
| 1050 | { |
| 1051 | shell->workspaces.current = index; |
| 1052 | |
| 1053 | shell->workspaces.anim_to = to; |
| 1054 | shell->workspaces.anim_from = from; |
| 1055 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1056 | shell->workspaces.anim_timestamp = (struct timespec) { 0 }; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1057 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1058 | weston_layer_set_position(&to->layer, WESTON_LAYER_POSITION_NORMAL); |
| 1059 | weston_layer_set_position(&from->layer, WESTON_LAYER_POSITION_NORMAL - 1); |
| 1060 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1061 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | static void |
| 1065 | workspace_deactivate_transforms(struct workspace *ws) |
| 1066 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1067 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1068 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1069 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1070 | 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] | 1071 | transform = view_get_transform(view); |
| 1072 | if (!transform) |
| 1073 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1074 | |
| 1075 | if (!wl_list_empty(&transform->link)) { |
| 1076 | wl_list_remove(&transform->link); |
| 1077 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1078 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1079 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | static void |
| 1084 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1085 | struct workspace *from, |
| 1086 | struct workspace *to) |
| 1087 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1088 | struct weston_view *view; |
| 1089 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1090 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1091 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1092 | /* Views that extend past the bottom of the output are still |
| 1093 | * visible after the workspace animation ends but before its layer |
| 1094 | * is hidden. In that case, we need to damage below those views so |
| 1095 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1096 | 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] | 1097 | weston_view_damage_below(view); |
| 1098 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1099 | wl_list_remove(&shell->workspaces.animation.link); |
| 1100 | workspace_deactivate_transforms(from); |
| 1101 | workspace_deactivate_transforms(to); |
| 1102 | shell->workspaces.anim_to = NULL; |
| 1103 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1104 | weston_layer_unset_position(&shell->workspaces.anim_from->layer); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | static void |
| 1108 | animate_workspace_change_frame(struct weston_animation *animation, |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1109 | struct weston_output *output, |
| 1110 | const struct timespec *time) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1111 | { |
| 1112 | struct desktop_shell *shell = |
| 1113 | container_of(animation, struct desktop_shell, |
| 1114 | workspaces.animation); |
| 1115 | struct workspace *from = shell->workspaces.anim_from; |
| 1116 | struct workspace *to = shell->workspaces.anim_to; |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1117 | int64_t t; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1118 | double x, y; |
| 1119 | |
| 1120 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1121 | finish_workspace_change_animation(shell, from, to); |
| 1122 | return; |
| 1123 | } |
| 1124 | |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1125 | if (timespec_is_zero(&shell->workspaces.anim_timestamp)) { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1126 | if (shell->workspaces.anim_current == 0.0) |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1127 | shell->workspaces.anim_timestamp = *time; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1128 | else |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1129 | timespec_add_msec(&shell->workspaces.anim_timestamp, |
| 1130 | time, |
Emmanuel Gil Peyrot | 426c246 | 2019-02-20 16:33:32 +0100 | [diff] [blame] | 1131 | /* Inverse of movement function 'y' below. */ |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1132 | -(asin(1.0 - shell->workspaces.anim_current) * |
| 1133 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1134 | M_2_PI)); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1135 | } |
| 1136 | |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1137 | t = timespec_sub_to_msec(time, &shell->workspaces.anim_timestamp); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1138 | |
| 1139 | /* |
| 1140 | * x = [0, π/2] |
| 1141 | * y(x) = sin(x) |
| 1142 | */ |
| 1143 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1144 | y = sin(x); |
| 1145 | |
| 1146 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1147 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1148 | |
| 1149 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1150 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1151 | shell->workspaces.anim_current = y; |
| 1152 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1153 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1154 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1155 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1156 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | static void |
| 1160 | animate_workspace_change(struct desktop_shell *shell, |
| 1161 | unsigned int index, |
| 1162 | struct workspace *from, |
| 1163 | struct workspace *to) |
| 1164 | { |
| 1165 | struct weston_output *output; |
| 1166 | |
| 1167 | int dir; |
| 1168 | |
| 1169 | if (index > shell->workspaces.current) |
| 1170 | dir = -1; |
| 1171 | else |
| 1172 | dir = 1; |
| 1173 | |
| 1174 | shell->workspaces.current = index; |
| 1175 | |
| 1176 | shell->workspaces.anim_dir = dir; |
| 1177 | shell->workspaces.anim_from = from; |
| 1178 | shell->workspaces.anim_to = to; |
| 1179 | shell->workspaces.anim_current = 0.0; |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1180 | shell->workspaces.anim_timestamp = (struct timespec) { 0 }; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1181 | |
| 1182 | output = container_of(shell->compositor->output_list.next, |
| 1183 | struct weston_output, link); |
| 1184 | wl_list_insert(&output->animation_list, |
| 1185 | &shell->workspaces.animation.link); |
| 1186 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1187 | weston_layer_set_position(&to->layer, WESTON_LAYER_POSITION_NORMAL); |
| 1188 | weston_layer_set_position(&from->layer, WESTON_LAYER_POSITION_NORMAL - 1); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1189 | |
| 1190 | workspace_translate_in(to, 0); |
| 1191 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1192 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1193 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1194 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1195 | } |
| 1196 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1197 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1198 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1199 | struct workspace *from, struct workspace *to) |
| 1200 | { |
| 1201 | shell->workspaces.current = index; |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1202 | weston_layer_set_position(&to->layer, WESTON_LAYER_POSITION_NORMAL); |
| 1203 | weston_layer_unset_position(&from->layer); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1207 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1208 | { |
| 1209 | struct workspace *from; |
| 1210 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1211 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1212 | |
| 1213 | if (index == shell->workspaces.current) |
| 1214 | return; |
| 1215 | |
| 1216 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1217 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1218 | return; |
| 1219 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1220 | from = get_current_workspace(shell); |
| 1221 | to = get_workspace(shell, index); |
| 1222 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1223 | if (shell->workspaces.anim_from == to && |
| 1224 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1225 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1226 | reverse_workspace_change_animation(shell, index, from, to); |
| 1227 | return; |
| 1228 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1229 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1230 | if (shell->workspaces.anim_to != NULL) |
| 1231 | finish_workspace_change_animation(shell, |
| 1232 | shell->workspaces.anim_from, |
| 1233 | shell->workspaces.anim_to); |
| 1234 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1235 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1236 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1237 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1238 | wl_list_for_each(state, &from->focus_list, link) |
| 1239 | if (state->keyboard_focus) |
| 1240 | animate_focus_change(shell, from, |
| 1241 | get_default_view(state->keyboard_focus), NULL); |
| 1242 | |
| 1243 | wl_list_for_each(state, &to->focus_list, link) |
| 1244 | if (state->keyboard_focus) |
| 1245 | animate_focus_change(shell, to, |
| 1246 | NULL, get_default_view(state->keyboard_focus)); |
| 1247 | } |
| 1248 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1249 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1250 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1251 | else |
| 1252 | animate_workspace_change(shell, index, from, to); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1253 | } |
| 1254 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1255 | static bool |
| 1256 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1257 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1258 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1259 | struct wl_list *e; |
| 1260 | |
| 1261 | if (wl_list_empty(list)) |
| 1262 | return false; |
| 1263 | |
| 1264 | e = list->next; |
| 1265 | |
| 1266 | if (e->next != list) |
| 1267 | return false; |
| 1268 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1269 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | static void |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 1273 | surface_keyboard_focus_lost(struct weston_surface *surface) |
| 1274 | { |
| 1275 | struct weston_compositor *compositor = surface->compositor; |
| 1276 | struct weston_seat *seat; |
| 1277 | struct weston_surface *focus; |
| 1278 | |
| 1279 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 1280 | struct weston_keyboard *keyboard = |
| 1281 | weston_seat_get_keyboard(seat); |
| 1282 | |
| 1283 | if (!keyboard) |
| 1284 | continue; |
| 1285 | |
| 1286 | focus = weston_surface_get_main_surface(keyboard->focus); |
| 1287 | if (focus == surface) |
| 1288 | weston_keyboard_set_focus(keyboard, NULL); |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1293 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1294 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1295 | unsigned int index) |
| 1296 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1297 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1298 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1299 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1300 | struct shell_surface *shsurf; |
| 1301 | struct workspace *from; |
| 1302 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1303 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1304 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1305 | surface = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1306 | view = get_default_view(surface); |
| 1307 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1308 | index == shell->workspaces.current || |
| 1309 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1310 | return; |
| 1311 | |
| 1312 | from = get_current_workspace(shell); |
| 1313 | to = get_workspace(shell, index); |
| 1314 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1315 | weston_layer_entry_remove(&view->layer_link); |
| 1316 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1317 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1318 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1319 | if (shsurf != NULL) |
| 1320 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1321 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1322 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1323 | drop_focus_state(shell, from, surface); |
| 1324 | |
| 1325 | if (shell->workspaces.anim_from == to && |
| 1326 | shell->workspaces.anim_to == from) { |
| 1327 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1328 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1329 | return; |
| 1330 | } |
| 1331 | |
| 1332 | if (shell->workspaces.anim_to != NULL) |
| 1333 | finish_workspace_change_animation(shell, |
| 1334 | shell->workspaces.anim_from, |
| 1335 | shell->workspaces.anim_to); |
| 1336 | |
| 1337 | if (workspace_is_empty(from) && |
| 1338 | workspace_has_only(to, surface)) |
| 1339 | update_workspace(shell, index, from, to); |
| 1340 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1341 | if (shsurf != NULL && |
| 1342 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1343 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1344 | &shsurf->workspace_transform.link); |
| 1345 | |
| 1346 | animate_workspace_change(shell, index, from, to); |
| 1347 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1348 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1349 | state = ensure_focus_state(shell, seat); |
| 1350 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1351 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | static void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 1355 | touch_move_grab_down(struct weston_touch_grab *grab, |
| 1356 | const struct timespec *time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1357 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1358 | { |
| 1359 | } |
| 1360 | |
| 1361 | static void |
Alexandros Frantzis | 27a51b8 | 2017-11-16 18:20:59 +0200 | [diff] [blame] | 1362 | touch_move_grab_up(struct weston_touch_grab *grab, const struct timespec *time, |
| 1363 | int touch_id) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1364 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1365 | struct weston_touch_move_grab *move = |
| 1366 | (struct weston_touch_move_grab *) container_of( |
| 1367 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1368 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1369 | if (touch_id == 0) |
| 1370 | move->active = 0; |
| 1371 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1372 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1373 | shell_touch_grab_end(&move->base); |
| 1374 | free(move); |
| 1375 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | static void |
Alexandros Frantzis | 7d2abcf | 2017-11-16 18:21:00 +0200 | [diff] [blame] | 1379 | touch_move_grab_motion(struct weston_touch_grab *grab, |
| 1380 | const struct timespec *time, int touch_id, |
| 1381 | wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1382 | { |
| 1383 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1384 | struct shell_surface *shsurf = move->base.shsurf; |
| 1385 | struct weston_surface *es; |
| 1386 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1387 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1388 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1389 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1390 | return; |
| 1391 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1392 | es = weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1393 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1394 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1395 | |
| 1396 | weston_compositor_schedule_repaint(es->compositor); |
| 1397 | } |
| 1398 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1399 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1400 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1401 | { |
| 1402 | } |
| 1403 | |
| 1404 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1405 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1406 | { |
| 1407 | struct weston_touch_move_grab *move = |
| 1408 | (struct weston_touch_move_grab *) container_of( |
| 1409 | grab, struct shell_touch_grab, grab); |
| 1410 | |
| 1411 | shell_touch_grab_end(&move->base); |
| 1412 | free(move); |
| 1413 | } |
| 1414 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1415 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1416 | touch_move_grab_down, |
| 1417 | touch_move_grab_up, |
| 1418 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1419 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1420 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1421 | }; |
| 1422 | |
| 1423 | static int |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1424 | surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1425 | { |
| 1426 | struct weston_touch_move_grab *move; |
| 1427 | |
| 1428 | if (!shsurf) |
| 1429 | return -1; |
| 1430 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1431 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1432 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1433 | return 0; |
| 1434 | |
| 1435 | move = malloc(sizeof *move); |
| 1436 | if (!move) |
| 1437 | return -1; |
| 1438 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1439 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1440 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1441 | touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1442 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1443 | touch->grab_y; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1444 | |
| 1445 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1446 | touch); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1447 | |
| 1448 | return 0; |
| 1449 | } |
| 1450 | |
| 1451 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1452 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1453 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | static void |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1457 | noop_grab_axis(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 1458 | const struct timespec *time, |
| 1459 | struct weston_pointer_axis_event *event) |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1460 | { |
| 1461 | } |
| 1462 | |
| 1463 | static void |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1464 | noop_grab_axis_source(struct weston_pointer_grab *grab, |
| 1465 | uint32_t source) |
| 1466 | { |
| 1467 | } |
| 1468 | |
| 1469 | static void |
| 1470 | noop_grab_frame(struct weston_pointer_grab *grab) |
| 1471 | { |
| 1472 | } |
| 1473 | |
| 1474 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1475 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1476 | { |
| 1477 | struct shell_surface *shsurf = move->base.shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1478 | struct weston_surface *surface = |
| 1479 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1480 | struct weston_pointer *pointer = move->base.grab.pointer; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1481 | int x, y, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1482 | const int safety = 50; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1483 | pixman_rectangle32_t area; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1484 | struct weston_geometry geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1485 | |
| 1486 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1487 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1488 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1489 | if (shsurf->shell->panel_position == |
| 1490 | WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1491 | get_output_work_area(shsurf->shell, surface->output, &area); |
| 1492 | geometry = |
| 1493 | weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1494 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1495 | bottom = y + geometry.height + geometry.y; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1496 | if (bottom - safety < area.y) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1497 | y = area.y + safety - geometry.height |
| 1498 | - geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1499 | |
| 1500 | if (move->client_initiated && |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1501 | y + geometry.y < area.y) |
| 1502 | y = area.y - geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1503 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1504 | |
| 1505 | *cx = x; |
| 1506 | *cy = y; |
| 1507 | } |
| 1508 | |
| 1509 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 1510 | move_grab_motion(struct weston_pointer_grab *grab, |
| 1511 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1512 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1513 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1514 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1515 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1516 | struct shell_surface *shsurf = move->base.shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1517 | struct weston_surface *surface; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1518 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1519 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1520 | weston_pointer_move(pointer, event); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1521 | if (!shsurf) |
| 1522 | return; |
| 1523 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1524 | surface = weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 1525 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1526 | constrain_position(move, &cx, &cy); |
| 1527 | |
| 1528 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1529 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1530 | weston_compositor_schedule_repaint(surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1534 | move_grab_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 1535 | const struct timespec *time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1536 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1537 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1538 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1539 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1540 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1541 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1542 | if (pointer->button_count == 0 && |
| 1543 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1544 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1545 | free(grab); |
| 1546 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1547 | } |
| 1548 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1549 | static void |
| 1550 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1551 | { |
| 1552 | struct shell_grab *shell_grab = |
| 1553 | container_of(grab, struct shell_grab, grab); |
| 1554 | |
| 1555 | shell_grab_end(shell_grab); |
| 1556 | free(grab); |
| 1557 | } |
| 1558 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1559 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1560 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1561 | move_grab_motion, |
| 1562 | move_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1563 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1564 | noop_grab_axis_source, |
| 1565 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1566 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1567 | }; |
| 1568 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1569 | static int |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1570 | surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 1571 | bool client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1572 | { |
| 1573 | struct weston_move_grab *move; |
| 1574 | |
| 1575 | if (!shsurf) |
| 1576 | return -1; |
| 1577 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1578 | if (shsurf->grabbed || |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1579 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1580 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1581 | return 0; |
| 1582 | |
| 1583 | move = malloc(sizeof *move); |
| 1584 | if (!move) |
| 1585 | return -1; |
| 1586 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1587 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1588 | pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1589 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1590 | pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1591 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1592 | |
| 1593 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1594 | pointer, WESTON_DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1595 | |
| 1596 | return 0; |
| 1597 | } |
| 1598 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1599 | struct weston_resize_grab { |
| 1600 | struct shell_grab base; |
| 1601 | uint32_t edges; |
| 1602 | int32_t width, height; |
| 1603 | }; |
| 1604 | |
| 1605 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 1606 | resize_grab_motion(struct weston_pointer_grab *grab, |
| 1607 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1608 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1609 | { |
| 1610 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1611 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1612 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1613 | int32_t width, height; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1614 | struct weston_size min_size, max_size; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1615 | wl_fixed_t from_x, from_y; |
| 1616 | wl_fixed_t to_x, to_y; |
| 1617 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1618 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1619 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1620 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1621 | return; |
| 1622 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1623 | weston_view_from_global_fixed(shsurf->view, |
| 1624 | pointer->grab_x, pointer->grab_y, |
| 1625 | &from_x, &from_y); |
| 1626 | weston_view_from_global_fixed(shsurf->view, |
| 1627 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1628 | |
| 1629 | width = resize->width; |
| 1630 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1631 | width += wl_fixed_to_int(from_x - to_x); |
| 1632 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1633 | width += wl_fixed_to_int(to_x - from_x); |
| 1634 | } |
| 1635 | |
| 1636 | height = resize->height; |
| 1637 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1638 | height += wl_fixed_to_int(from_y - to_y); |
| 1639 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1640 | height += wl_fixed_to_int(to_y - from_y); |
| 1641 | } |
| 1642 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1643 | max_size = weston_desktop_surface_get_max_size(shsurf->desktop_surface); |
| 1644 | min_size = weston_desktop_surface_get_min_size(shsurf->desktop_surface); |
| 1645 | |
| 1646 | min_size.width = MAX(1, min_size.width); |
| 1647 | min_size.height = MAX(1, min_size.height); |
| 1648 | |
| 1649 | if (width < min_size.width) |
| 1650 | width = min_size.width; |
| 1651 | else if (max_size.width > 0 && width > max_size.width) |
| 1652 | width = max_size.width; |
| 1653 | if (height < min_size.height) |
| 1654 | height = min_size.height; |
| 1655 | else if (max_size.width > 0 && width > max_size.width) |
| 1656 | width = max_size.width; |
| 1657 | weston_desktop_surface_set_size(shsurf->desktop_surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1661 | resize_grab_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 1662 | const struct timespec *time, |
| 1663 | uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1664 | { |
| 1665 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1666 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1667 | enum wl_pointer_button_state state = state_w; |
| 1668 | |
| 1669 | if (pointer->button_count == 0 && |
| 1670 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Greg V | ec3f779 | 2018-11-08 00:24:56 +0300 | [diff] [blame] | 1671 | if (resize->base.shsurf != NULL) { |
| 1672 | struct weston_desktop_surface *desktop_surface = |
| 1673 | resize->base.shsurf->desktop_surface; |
| 1674 | weston_desktop_surface_set_resizing(desktop_surface, |
| 1675 | false); |
| 1676 | } |
| 1677 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1678 | shell_grab_end(&resize->base); |
| 1679 | free(grab); |
| 1680 | } |
| 1681 | } |
| 1682 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1683 | static void |
| 1684 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1685 | { |
| 1686 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1687 | |
Greg V | ec3f779 | 2018-11-08 00:24:56 +0300 | [diff] [blame] | 1688 | if (resize->base.shsurf != NULL) { |
| 1689 | struct weston_desktop_surface *desktop_surface = |
| 1690 | resize->base.shsurf->desktop_surface; |
| 1691 | weston_desktop_surface_set_resizing(desktop_surface, false); |
| 1692 | } |
| 1693 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1694 | shell_grab_end(&resize->base); |
| 1695 | free(grab); |
| 1696 | } |
| 1697 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1698 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1699 | noop_grab_focus, |
| 1700 | resize_grab_motion, |
| 1701 | resize_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1702 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1703 | noop_grab_axis_source, |
| 1704 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1705 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1706 | }; |
| 1707 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1708 | /* |
| 1709 | * Returns the bounding box of a surface and all its sub-surfaces, |
Yong Bakos | bbb783a | 2016-04-28 11:59:06 -0500 | [diff] [blame] | 1710 | * in surface-local coordinates. */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1711 | static void |
| 1712 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1713 | int32_t *y, int32_t *w, int32_t *h) { |
| 1714 | pixman_region32_t region; |
| 1715 | pixman_box32_t *box; |
| 1716 | struct weston_subsurface *subsurface; |
| 1717 | |
| 1718 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1719 | surface->width, |
| 1720 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1721 | |
| 1722 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1723 | pixman_region32_union_rect(®ion, ®ion, |
| 1724 | subsurface->position.x, |
| 1725 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1726 | subsurface->surface->width, |
| 1727 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | box = pixman_region32_extents(®ion); |
| 1731 | if (x) |
| 1732 | *x = box->x1; |
| 1733 | if (y) |
| 1734 | *y = box->y1; |
| 1735 | if (w) |
| 1736 | *w = box->x2 - box->x1; |
| 1737 | if (h) |
| 1738 | *h = box->y2 - box->y1; |
| 1739 | |
| 1740 | pixman_region32_fini(®ion); |
| 1741 | } |
| 1742 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1743 | static int |
| 1744 | surface_resize(struct shell_surface *shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1745 | struct weston_pointer *pointer, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1746 | { |
| 1747 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1748 | const unsigned resize_topbottom = |
| 1749 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1750 | const unsigned resize_leftright = |
| 1751 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1752 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1753 | struct weston_geometry geometry; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1754 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1755 | if (shsurf->grabbed || |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1756 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1757 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1758 | return 0; |
| 1759 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1760 | /* Check for invalid edge combinations. */ |
| 1761 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1762 | (edges & resize_topbottom) == resize_topbottom || |
| 1763 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1764 | return 0; |
| 1765 | |
| 1766 | resize = malloc(sizeof *resize); |
| 1767 | if (!resize) |
| 1768 | return -1; |
| 1769 | |
| 1770 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1771 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1772 | geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
| 1773 | resize->width = geometry.width; |
| 1774 | resize->height = geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1775 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1776 | shsurf->resize_edges = edges; |
Philipp Kerling | c5f1241 | 2017-07-28 14:11:58 +0200 | [diff] [blame] | 1777 | weston_desktop_surface_set_resizing(shsurf->desktop_surface, true); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1778 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1779 | pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1780 | |
| 1781 | return 0; |
| 1782 | } |
| 1783 | |
| 1784 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1785 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1786 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1787 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1788 | struct weston_pointer *pointer = base->pointer; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1789 | struct weston_desktop_surface *desktop_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1790 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1791 | wl_fixed_t sx, sy; |
| 1792 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1793 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1794 | pointer->x, pointer->y, |
| 1795 | &sx, &sy); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1796 | desktop_surface = weston_surface_get_desktop_surface(view->surface); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1797 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1798 | if (!grab->shsurf || grab->shsurf->desktop_surface != desktop_surface) { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1799 | shell_grab_end(grab); |
| 1800 | free(grab); |
| 1801 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 1805 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, |
| 1806 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1807 | struct weston_pointer_motion_event *event) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1808 | { |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1809 | weston_pointer_move(grab->pointer, event); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1810 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1811 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1812 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1813 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 1814 | const struct timespec *time, |
| 1815 | uint32_t button, uint32_t state) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1816 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1817 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1818 | struct shell_surface *shsurf = grab->shsurf; |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1819 | struct weston_pointer *pointer = grab->grab.pointer; |
| 1820 | struct weston_seat *seat = pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1821 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1822 | if (shsurf && button == BTN_LEFT && state) { |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 1823 | activate(shsurf->shell, shsurf->view, seat, |
| 1824 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1825 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1826 | } else if (shsurf && button == BTN_RIGHT && state) { |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 1827 | activate(shsurf->shell, shsurf->view, seat, |
| 1828 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 1829 | surface_rotate(shsurf, pointer); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1830 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1831 | } |
| 1832 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1833 | static void |
| 1834 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1835 | { |
| 1836 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1837 | |
| 1838 | shell_grab_end(grab); |
| 1839 | free(grab); |
| 1840 | } |
| 1841 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1842 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1843 | busy_cursor_grab_focus, |
| 1844 | busy_cursor_grab_motion, |
| 1845 | busy_cursor_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1846 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1847 | noop_grab_axis_source, |
| 1848 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1849 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1850 | }; |
| 1851 | |
| 1852 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1853 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1854 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1855 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1856 | struct weston_view *view = pointer->focus; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1857 | struct shell_surface *shsurf; |
| 1858 | struct weston_desktop_client *client; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1859 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1860 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1861 | return; |
| 1862 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1863 | shsurf = get_shell_surface(view->surface); |
| 1864 | if (!shsurf) |
| 1865 | return; |
| 1866 | |
| 1867 | client = weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 1868 | |
| 1869 | if (shsurf->unresponsive) |
| 1870 | set_busy_cursor(shsurf, pointer); |
| 1871 | else |
| 1872 | weston_desktop_client_ping(client); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1876 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 1877 | { |
| 1878 | if (--shsurf->focus_count == 0) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1879 | weston_desktop_surface_set_activated(shsurf->desktop_surface, false); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | static void |
| 1883 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 1884 | { |
| 1885 | if (shsurf->focus_count++ == 0) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1886 | weston_desktop_surface_set_activated(shsurf->desktop_surface, true); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | static void |
| 1890 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 1891 | { |
| 1892 | struct weston_keyboard *keyboard = data; |
| 1893 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 1894 | |
| 1895 | if (seat->focused_surface) { |
| 1896 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 1897 | if (shsurf) |
| 1898 | shell_surface_lose_keyboard_focus(shsurf); |
| 1899 | } |
| 1900 | |
Philipp Kerling | ba8a0d0 | 2017-07-26 12:02:15 +0200 | [diff] [blame] | 1901 | seat->focused_surface = weston_surface_get_main_surface(keyboard->focus); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1902 | |
| 1903 | if (seat->focused_surface) { |
| 1904 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 1905 | if (shsurf) |
| 1906 | shell_surface_gain_keyboard_focus(shsurf); |
| 1907 | } |
| 1908 | } |
| 1909 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1910 | /* The surface will be inserted into the list immediately after the link |
| 1911 | * returned by this function (i.e. will be stacked immediately above the |
| 1912 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1913 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1914 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 1915 | { |
| 1916 | struct workspace *ws; |
| 1917 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1918 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) && |
| 1919 | !shsurf->state.lowered) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 1920 | return &shsurf->shell->fullscreen_layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1923 | /* Move the surface to a normal workspace layer so that surfaces |
| 1924 | * which were previously fullscreen or transient are no longer |
| 1925 | * rendered on top. */ |
| 1926 | ws = get_current_workspace(shsurf->shell); |
| 1927 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1930 | static void |
| 1931 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 1932 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1933 | weston_desktop_surface_propagate_layer(shsurf->desktop_surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1936 | /* 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] | 1937 | * geometry to ensure the changes are redrawn. |
| 1938 | * |
| 1939 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 1940 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1941 | static void |
| 1942 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 1943 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1944 | struct weston_surface *surface = |
| 1945 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1946 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1947 | |
| 1948 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 1949 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 1950 | if (new_layer_link == NULL) |
| 1951 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1952 | if (new_layer_link == &shsurf->view->layer_link) |
| 1953 | return; |
| 1954 | |
| 1955 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1956 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 1957 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1958 | weston_view_geometry_dirty(shsurf->view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1959 | weston_surface_damage(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1960 | |
| 1961 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1964 | static void |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame] | 1965 | notify_output_destroy(struct wl_listener *listener, void *data) |
| 1966 | { |
| 1967 | struct shell_surface *shsurf = |
| 1968 | container_of(listener, |
| 1969 | struct shell_surface, output_destroy_listener); |
| 1970 | |
| 1971 | shsurf->output = NULL; |
| 1972 | shsurf->output_destroy_listener.notify = NULL; |
| 1973 | } |
| 1974 | |
| 1975 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1976 | shell_surface_set_output(struct shell_surface *shsurf, |
| 1977 | struct weston_output *output) |
| 1978 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1979 | struct weston_surface *es = |
| 1980 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1981 | |
| 1982 | /* get the default output, if the client set it as NULL |
Abdur Rehman | 7f1da1f | 2017-01-01 19:46:33 +0500 | [diff] [blame] | 1983 | check whether the output is available */ |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1984 | if (output) |
| 1985 | shsurf->output = output; |
| 1986 | else if (es->output) |
| 1987 | shsurf->output = es->output; |
| 1988 | else |
| 1989 | shsurf->output = get_default_output(es->compositor); |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame] | 1990 | |
| 1991 | if (shsurf->output_destroy_listener.notify) { |
| 1992 | wl_list_remove(&shsurf->output_destroy_listener.link); |
| 1993 | shsurf->output_destroy_listener.notify = NULL; |
| 1994 | } |
| 1995 | |
| 1996 | if (!shsurf->output) |
| 1997 | return; |
| 1998 | |
| 1999 | shsurf->output_destroy_listener.notify = notify_output_destroy; |
| 2000 | wl_signal_add(&shsurf->output->destroy_signal, |
| 2001 | &shsurf->output_destroy_listener); |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2005 | weston_view_set_initial_position(struct weston_view *view, |
| 2006 | struct desktop_shell *shell); |
| 2007 | |
| 2008 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2009 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2010 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2011 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2012 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2013 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2014 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2015 | if (shsurf->fullscreen.black_view) |
| 2016 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2017 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2018 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2019 | if (shsurf->saved_position_valid) |
| 2020 | weston_view_set_position(shsurf->view, |
| 2021 | shsurf->saved_x, shsurf->saved_y); |
| 2022 | else |
| 2023 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Quentin Glidic | 920cf04 | 2016-08-16 14:26:20 +0200 | [diff] [blame] | 2024 | shsurf->saved_position_valid = false; |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2025 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2026 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2027 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2028 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2029 | shsurf->saved_rotation_valid = false; |
| 2030 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2031 | } |
| 2032 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2033 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2034 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2035 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2036 | struct weston_surface *surface = |
| 2037 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2038 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2039 | /* undo all maximized things here */ |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame] | 2040 | shell_surface_set_output(shsurf, get_default_output(surface->compositor)); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2041 | |
| 2042 | if (shsurf->saved_position_valid) |
| 2043 | weston_view_set_position(shsurf->view, |
| 2044 | shsurf->saved_x, shsurf->saved_y); |
| 2045 | else |
| 2046 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Quentin Glidic | 920cf04 | 2016-08-16 14:26:20 +0200 | [diff] [blame] | 2047 | shsurf->saved_position_valid = false; |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2048 | |
| 2049 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2050 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2051 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2052 | shsurf->saved_rotation_valid = false; |
| 2053 | } |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2054 | } |
| 2055 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2056 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2057 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2058 | { |
| 2059 | struct shell_surface *shsurf; |
| 2060 | struct workspace *current_ws; |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2061 | struct weston_view *view; |
Jonas Ådahl | 56958aa | 2021-10-01 11:12:21 +0200 | [diff] [blame] | 2062 | struct weston_subsurface *subsurface; |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2063 | |
| 2064 | view = get_default_view(surface); |
| 2065 | if (!view) |
| 2066 | return; |
| 2067 | |
| 2068 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2069 | |
| 2070 | shsurf = get_shell_surface(surface); |
| 2071 | current_ws = get_current_workspace(shsurf->shell); |
| 2072 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2073 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2074 | 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] | 2075 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2076 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 2077 | surface_keyboard_focus_lost(surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2078 | |
| 2079 | shell_surface_update_child_surface_layers(shsurf); |
Jonas Ådahl | 56958aa | 2021-10-01 11:12:21 +0200 | [diff] [blame] | 2080 | |
| 2081 | weston_view_damage_below(shsurf->view); |
| 2082 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 2083 | wl_list_for_each(view, &subsurface->surface->views, surface_link) |
| 2084 | weston_view_damage_below(view); |
| 2085 | } |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2086 | } |
| 2087 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2088 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2089 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2090 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2091 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2092 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2093 | } |
| 2094 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2095 | static int |
| 2096 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2097 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2098 | struct weston_view *fs_view = surface->committed_private; |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2099 | struct weston_surface *fs_surface = fs_view->surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2100 | int n; |
| 2101 | int rem; |
| 2102 | int ret; |
| 2103 | |
| 2104 | n = snprintf(buf, len, "black background surface for "); |
| 2105 | if (n < 0) |
| 2106 | return n; |
| 2107 | |
| 2108 | rem = (int)len - n; |
| 2109 | if (rem < 0) |
| 2110 | rem = 0; |
| 2111 | |
| 2112 | if (fs_surface->get_label) |
| 2113 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2114 | else |
| 2115 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2116 | |
| 2117 | if (ret < 0) |
| 2118 | return n; |
| 2119 | |
| 2120 | return n + ret; |
| 2121 | } |
| 2122 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2123 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2124 | 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] | 2125 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2126 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2127 | create_black_surface(struct weston_compositor *ec, |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2128 | struct weston_view *fs_view, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2129 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2130 | { |
| 2131 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2132 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2133 | |
| 2134 | surface = weston_surface_create(ec); |
| 2135 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2136 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2137 | return NULL; |
| 2138 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2139 | view = weston_view_create(surface); |
| 2140 | if (surface == NULL) { |
| 2141 | weston_log("no memory\n"); |
| 2142 | weston_surface_destroy(surface); |
| 2143 | return NULL; |
| 2144 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2145 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2146 | surface->committed = black_surface_committed; |
| 2147 | surface->committed_private = fs_view; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2148 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2149 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2150 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2151 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2152 | pixman_region32_fini(&surface->input); |
| 2153 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2154 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2155 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2156 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2157 | |
| 2158 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2159 | } |
| 2160 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2161 | static void |
| 2162 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2163 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2164 | struct weston_surface *surface = |
| 2165 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2166 | struct weston_output *output = shsurf->fullscreen_output; |
| 2167 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2168 | assert(weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2169 | |
| 2170 | if (!shsurf->fullscreen.black_view) |
| 2171 | shsurf->fullscreen.black_view = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2172 | create_black_surface(surface->compositor, |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2173 | shsurf->view, |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2174 | output->x, output->y, |
| 2175 | output->width, |
| 2176 | output->height); |
| 2177 | |
| 2178 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2179 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2180 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2181 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2182 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2183 | weston_surface_damage(surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2184 | |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 2185 | shsurf->fullscreen.black_view->is_mapped = true; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2186 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2187 | } |
| 2188 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2189 | /* Create black surface and append it to the associated fullscreen surface. |
| 2190 | * Handle size dismatch and positioning according to the method. */ |
| 2191 | static void |
| 2192 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2193 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2194 | struct weston_surface *surface = |
| 2195 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2196 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2197 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2198 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2199 | weston_layer_entry_remove(&shsurf->view->layer_link); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2200 | weston_layer_entry_insert(&shsurf->shell->fullscreen_layer.view_list, |
| 2201 | &shsurf->view->layer_link); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2202 | |
Pekka Paalanen | c63acc4 | 2018-05-02 10:21:58 +0200 | [diff] [blame] | 2203 | if (!shsurf->fullscreen_output) { |
| 2204 | /* If there is no output, there's not much we can do. |
| 2205 | * Position the window somewhere, whatever. */ |
| 2206 | weston_view_set_position(shsurf->view, 0, 0); |
| 2207 | return; |
| 2208 | } |
| 2209 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2210 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2211 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2212 | surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2213 | &surf_width, &surf_height); |
| 2214 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2215 | if (surface->buffer_ref.buffer) |
| 2216 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2217 | } |
| 2218 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2219 | static void |
| 2220 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2221 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2222 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2223 | } |
| 2224 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2225 | static struct weston_output * |
| 2226 | get_focused_output(struct weston_compositor *compositor) |
| 2227 | { |
| 2228 | struct weston_seat *seat; |
| 2229 | struct weston_output *output = NULL; |
| 2230 | |
| 2231 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2232 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2233 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2234 | struct weston_keyboard *keyboard = |
| 2235 | weston_seat_get_keyboard(seat); |
| 2236 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2237 | /* Priority has touch focus, then pointer and |
| 2238 | * then keyboard focus. We should probably have |
Emmanuel Gil Peyrot | 426c246 | 2019-02-20 16:33:32 +0100 | [diff] [blame] | 2239 | * three for loops and check first for touch, |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2240 | * then for pointer, etc. but unless somebody has some |
| 2241 | * objections, I think this is sufficient. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2242 | if (touch && touch->focus) |
| 2243 | output = touch->focus->output; |
| 2244 | else if (pointer && pointer->focus) |
| 2245 | output = pointer->focus->output; |
| 2246 | else if (keyboard && keyboard->focus) |
| 2247 | output = keyboard->focus->output; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2248 | |
| 2249 | if (output) |
| 2250 | break; |
| 2251 | } |
| 2252 | |
| 2253 | return output; |
| 2254 | } |
| 2255 | |
| 2256 | static void |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 2257 | desktop_shell_destroy_seat(struct shell_seat *shseat) |
| 2258 | { |
Marius Vlad | a7392c8 | 2021-08-26 16:38:43 +0300 | [diff] [blame^] | 2259 | wl_list_remove(&shseat->keyboard_focus_listener.link); |
| 2260 | wl_list_remove(&shseat->caps_changed_listener.link); |
| 2261 | wl_list_remove(&shseat->pointer_focus_listener.link); |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 2262 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2263 | |
| 2264 | wl_list_remove(&shseat->link); |
| 2265 | free(shseat); |
| 2266 | } |
| 2267 | |
| 2268 | static void |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2269 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2270 | { |
| 2271 | struct shell_seat *shseat = |
| 2272 | container_of(listener, |
| 2273 | struct shell_seat, seat_destroy_listener); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2274 | |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 2275 | desktop_shell_destroy_seat(shseat); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2276 | } |
| 2277 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2278 | static void |
| 2279 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 2280 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2281 | struct weston_keyboard *keyboard; |
| 2282 | struct weston_pointer *pointer; |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2283 | struct shell_seat *seat; |
| 2284 | |
| 2285 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2286 | keyboard = weston_seat_get_keyboard(seat->seat); |
| 2287 | pointer = weston_seat_get_pointer(seat->seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2288 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2289 | if (keyboard && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2290 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2291 | wl_signal_add(&keyboard->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2292 | &seat->keyboard_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2293 | } else if (!keyboard) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 2294 | wl_list_remove(&seat->keyboard_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2295 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 2296 | } |
| 2297 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2298 | if (pointer && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2299 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2300 | wl_signal_add(&pointer->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2301 | &seat->pointer_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2302 | } else if (!pointer) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 2303 | wl_list_remove(&seat->pointer_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2304 | wl_list_init(&seat->pointer_focus_listener.link); |
| 2305 | } |
| 2306 | } |
| 2307 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2308 | static struct shell_seat * |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 2309 | create_shell_seat(struct desktop_shell *shell, struct weston_seat *seat) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2310 | { |
| 2311 | struct shell_seat *shseat; |
| 2312 | |
| 2313 | shseat = calloc(1, sizeof *shseat); |
| 2314 | if (!shseat) { |
| 2315 | weston_log("no memory to allocate shell seat\n"); |
| 2316 | return NULL; |
| 2317 | } |
| 2318 | |
| 2319 | shseat->seat = seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2320 | |
| 2321 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2322 | wl_signal_add(&seat->destroy_signal, |
| 2323 | &shseat->seat_destroy_listener); |
| 2324 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2325 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 2326 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 2327 | |
| 2328 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 2329 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 2330 | |
| 2331 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 2332 | wl_signal_add(&seat->updated_caps_signal, |
| 2333 | &shseat->caps_changed_listener); |
| 2334 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 2335 | |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 2336 | wl_list_insert(&shell->seat_list, &shseat->link); |
| 2337 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2338 | return shseat; |
| 2339 | } |
| 2340 | |
| 2341 | static struct shell_seat * |
| 2342 | get_shell_seat(struct weston_seat *seat) |
| 2343 | { |
| 2344 | struct wl_listener *listener; |
| 2345 | |
| 2346 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2347 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2348 | |
| 2349 | return container_of(listener, |
| 2350 | struct shell_seat, seat_destroy_listener); |
| 2351 | } |
| 2352 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2353 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2354 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 2355 | { |
| 2356 | struct shell_surface *shsurf = data; |
| 2357 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2358 | weston_surface_destroy(shsurf->view->surface); |
Pekka Paalanen | 9962800 | 2018-05-22 12:48:35 +0300 | [diff] [blame] | 2359 | |
| 2360 | if (shsurf->output_destroy_listener.notify) { |
| 2361 | wl_list_remove(&shsurf->output_destroy_listener.link); |
| 2362 | shsurf->output_destroy_listener.notify = NULL; |
| 2363 | } |
| 2364 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2365 | free(shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2369 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 2370 | { |
| 2371 | struct shell_surface *shsurf = data; |
| 2372 | struct wl_event_loop *loop; |
| 2373 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2374 | loop = wl_display_get_event_loop(shsurf->shell->compositor->wl_display); |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2375 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2376 | if (weston_view_is_mapped(shsurf->view)) { |
Tomohito Esaki | 5898cd3 | 2019-04-01 17:50:14 +0900 | [diff] [blame] | 2377 | weston_view_unmap(shsurf->view); |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2378 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2379 | } |
| 2380 | } |
| 2381 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 2382 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2383 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2384 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2385 | if (weston_surface_is_desktop_surface(surface)) { |
| 2386 | struct weston_desktop_surface *desktop_surface = |
| 2387 | weston_surface_get_desktop_surface(surface); |
| 2388 | return weston_desktop_surface_get_user_data(desktop_surface); |
| 2389 | } |
| 2390 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2391 | } |
| 2392 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2393 | /* |
| 2394 | * libweston-desktop |
| 2395 | */ |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2396 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2397 | static void |
| 2398 | desktop_surface_added(struct weston_desktop_surface *desktop_surface, |
| 2399 | void *shell) |
| 2400 | { |
| 2401 | struct weston_desktop_client *client = |
| 2402 | weston_desktop_surface_get_client(desktop_surface); |
| 2403 | struct wl_client *wl_client = |
| 2404 | weston_desktop_client_get_client(client); |
| 2405 | struct weston_view *view; |
| 2406 | struct shell_surface *shsurf; |
| 2407 | struct weston_surface *surface = |
| 2408 | weston_desktop_surface_get_surface(desktop_surface); |
| 2409 | |
| 2410 | view = weston_desktop_surface_create_view(desktop_surface); |
| 2411 | if (!view) |
| 2412 | return; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2413 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2414 | shsurf = calloc(1, sizeof *shsurf); |
| 2415 | if (!shsurf) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2416 | if (wl_client) |
| 2417 | wl_client_post_no_memory(wl_client); |
| 2418 | else |
| 2419 | weston_log("no memory to allocate shell surface\n"); |
| 2420 | return; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2421 | } |
| 2422 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2423 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2424 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2425 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2426 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2427 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2428 | shsurf->saved_rotation_valid = false; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2429 | shsurf->desktop_surface = desktop_surface; |
| 2430 | shsurf->view = view; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2431 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2432 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2433 | |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame] | 2434 | shell_surface_set_output( |
| 2435 | shsurf, get_default_output(shsurf->shell->compositor)); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2436 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2437 | wl_signal_init(&shsurf->destroy_signal); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2438 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2439 | /* empty when not in use */ |
| 2440 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2441 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2442 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2443 | wl_list_init(&shsurf->workspace_transform.link); |
| 2444 | |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2445 | /* |
| 2446 | * initialize list as well as link. The latter allows to use |
| 2447 | * wl_list_remove() even when this surface is not in another list. |
| 2448 | */ |
| 2449 | wl_list_init(&shsurf->children_list); |
| 2450 | wl_list_init(&shsurf->children_link); |
| 2451 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2452 | weston_desktop_surface_set_user_data(desktop_surface, shsurf); |
| 2453 | weston_desktop_surface_set_activated(desktop_surface, |
| 2454 | shsurf->focus_count > 0); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2455 | } |
| 2456 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2457 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2458 | desktop_surface_removed(struct weston_desktop_surface *desktop_surface, |
| 2459 | void *shell) |
| 2460 | { |
| 2461 | struct shell_surface *shsurf = |
| 2462 | weston_desktop_surface_get_user_data(desktop_surface); |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2463 | struct shell_surface *shsurf_child, *tmp; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2464 | struct weston_surface *surface = |
| 2465 | weston_desktop_surface_get_surface(desktop_surface); |
| 2466 | |
| 2467 | if (!shsurf) |
| 2468 | return; |
| 2469 | |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2470 | wl_list_for_each_safe(shsurf_child, tmp, &shsurf->children_list, children_link) { |
| 2471 | wl_list_remove(&shsurf_child->children_link); |
| 2472 | wl_list_init(&shsurf_child->children_link); |
| 2473 | } |
| 2474 | wl_list_remove(&shsurf->children_link); |
| 2475 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2476 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2477 | |
| 2478 | if (shsurf->fullscreen.black_view) |
| 2479 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2480 | |
| 2481 | weston_surface_set_label_func(surface, NULL); |
| 2482 | weston_desktop_surface_set_user_data(shsurf->desktop_surface, NULL); |
| 2483 | shsurf->desktop_surface = NULL; |
| 2484 | |
Quentin Glidic | f01ecee | 2016-08-16 10:52:46 +0200 | [diff] [blame] | 2485 | weston_desktop_surface_unlink_view(shsurf->view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2486 | if (weston_surface_is_mapped(surface) && |
| 2487 | shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
Erik Kurzinger | 04918f3 | 2021-05-18 11:49:37 -0400 | [diff] [blame] | 2488 | |
Emmanuel Gil Peyrot | eff793a | 2021-07-31 17:25:41 +0200 | [diff] [blame] | 2489 | if (shsurf->shell->compositor->state == WESTON_COMPOSITOR_ACTIVE) { |
| 2490 | pixman_region32_fini(&surface->pending.input); |
| 2491 | pixman_region32_init(&surface->pending.input); |
| 2492 | pixman_region32_fini(&surface->input); |
| 2493 | pixman_region32_init(&surface->input); |
| 2494 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 2495 | fade_out_done, shsurf); |
| 2496 | return; |
| 2497 | } else { |
Marius Vlad | c30cb29 | 2021-08-02 15:47:16 +0300 | [diff] [blame] | 2498 | weston_surface_destroy(surface); |
Emmanuel Gil Peyrot | eff793a | 2021-07-31 17:25:41 +0200 | [diff] [blame] | 2499 | } |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2500 | } |
Erik Kurzinger | 04918f3 | 2021-05-18 11:49:37 -0400 | [diff] [blame] | 2501 | |
Marius Vlad | c30cb29 | 2021-08-02 15:47:16 +0300 | [diff] [blame] | 2502 | weston_view_destroy(shsurf->view); |
Erik Kurzinger | 04918f3 | 2021-05-18 11:49:37 -0400 | [diff] [blame] | 2503 | |
| 2504 | if (shsurf->output_destroy_listener.notify) { |
| 2505 | wl_list_remove(&shsurf->output_destroy_listener.link); |
| 2506 | shsurf->output_destroy_listener.notify = NULL; |
| 2507 | } |
| 2508 | |
| 2509 | free(shsurf); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | static void |
| 2513 | set_maximized_position(struct desktop_shell *shell, |
| 2514 | struct shell_surface *shsurf) |
| 2515 | { |
| 2516 | pixman_rectangle32_t area; |
| 2517 | struct weston_geometry geometry; |
| 2518 | |
| 2519 | get_output_work_area(shell, shsurf->output, &area); |
| 2520 | geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
| 2521 | |
| 2522 | weston_view_set_position(shsurf->view, |
| 2523 | area.x - geometry.x, |
| 2524 | area.y - geometry.y); |
| 2525 | } |
| 2526 | |
| 2527 | static void |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2528 | set_position_from_xwayland(struct shell_surface *shsurf) |
| 2529 | { |
| 2530 | struct weston_geometry geometry; |
| 2531 | float x; |
| 2532 | float y; |
| 2533 | |
| 2534 | assert(shsurf->xwayland.is_set); |
| 2535 | |
| 2536 | geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
| 2537 | x = shsurf->xwayland.x - geometry.x; |
| 2538 | y = shsurf->xwayland.y - geometry.y; |
| 2539 | |
| 2540 | weston_view_set_position(shsurf->view, x, y); |
| 2541 | |
| 2542 | #ifdef WM_DEBUG |
| 2543 | weston_log("%s: XWM %d, %d; geometry %d, %d; view %f, %f\n", |
| 2544 | __func__, shsurf->xwayland.x, shsurf->xwayland.y, |
| 2545 | geometry.x, geometry.y, x, y); |
| 2546 | #endif |
| 2547 | } |
| 2548 | |
| 2549 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2550 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
| 2551 | int32_t sx, int32_t sy) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2552 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2553 | struct weston_surface *surface = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2554 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2555 | struct weston_compositor *compositor = shell->compositor; |
| 2556 | struct weston_seat *seat; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2557 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2558 | /* initial positioning, see also configure() */ |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2559 | if (shsurf->state.fullscreen) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2560 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 2561 | shell_map_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); |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2564 | } else if (shsurf->xwayland.is_set) { |
| 2565 | set_position_from_xwayland(shsurf); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 2566 | } else { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2567 | weston_view_set_initial_position(shsurf->view, shell); |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 2568 | } |
| 2569 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2570 | /* Surface stacking order, see also activate(). */ |
| 2571 | shell_surface_update_layer(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2572 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2573 | weston_view_update_transform(shsurf->view); |
| 2574 | shsurf->view->is_mapped = true; |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2575 | if (shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2576 | surface->output = shsurf->output; |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 2577 | weston_view_set_output(shsurf->view, shsurf->output); |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2578 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2579 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2580 | if (!shell->locked) { |
| 2581 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 2582 | activate(shell, shsurf->view, seat, |
| 2583 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
| 2584 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2585 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2586 | if (!shsurf->state.fullscreen && !shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2587 | switch (shell->win_animation_type) { |
| 2588 | case ANIMATION_FADE: |
| 2589 | weston_fade_run(shsurf->view, 0.0, 1.0, 300.0, NULL, NULL); |
| 2590 | break; |
| 2591 | case ANIMATION_ZOOM: |
| 2592 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
| 2593 | break; |
| 2594 | case ANIMATION_NONE: |
| 2595 | default: |
| 2596 | break; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 2597 | } |
| 2598 | } |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2602 | desktop_surface_committed(struct weston_desktop_surface *desktop_surface, |
| 2603 | int32_t sx, int32_t sy, void *data) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2604 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2605 | struct shell_surface *shsurf = |
| 2606 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2607 | struct weston_surface *surface = |
| 2608 | weston_desktop_surface_get_surface(desktop_surface); |
| 2609 | struct weston_view *view = shsurf->view; |
| 2610 | struct desktop_shell *shell = data; |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2611 | bool was_fullscreen; |
| 2612 | bool was_maximized; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2613 | |
| 2614 | if (surface->width == 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2615 | return; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2616 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2617 | was_fullscreen = shsurf->state.fullscreen; |
| 2618 | was_maximized = shsurf->state.maximized; |
| 2619 | |
| 2620 | shsurf->state.fullscreen = |
| 2621 | weston_desktop_surface_get_fullscreen(desktop_surface); |
| 2622 | shsurf->state.maximized = |
| 2623 | weston_desktop_surface_get_maximized(desktop_surface); |
| 2624 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2625 | if (!weston_surface_is_mapped(surface)) { |
| 2626 | map(shell, shsurf, sx, sy); |
| 2627 | surface->is_mapped = true; |
| 2628 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) |
| 2629 | ++surface->ref_count; |
| 2630 | return; |
| 2631 | } |
| 2632 | |
| 2633 | if (sx == 0 && sy == 0 && |
| 2634 | shsurf->last_width == surface->width && |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2635 | shsurf->last_height == surface->height && |
| 2636 | was_fullscreen == shsurf->state.fullscreen && |
| 2637 | was_maximized == shsurf->state.maximized) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2638 | return; |
| 2639 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2640 | if (was_fullscreen) |
| 2641 | unset_fullscreen(shsurf); |
| 2642 | if (was_maximized) |
| 2643 | unset_maximized(shsurf); |
| 2644 | |
Quentin Glidic | 920cf04 | 2016-08-16 14:26:20 +0200 | [diff] [blame] | 2645 | if ((shsurf->state.fullscreen || shsurf->state.maximized) && |
| 2646 | !shsurf->saved_position_valid) { |
| 2647 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2648 | shsurf->saved_y = shsurf->view->geometry.y; |
| 2649 | shsurf->saved_position_valid = true; |
| 2650 | |
| 2651 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2652 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2653 | wl_list_init(&shsurf->rotation.transform.link); |
| 2654 | weston_view_geometry_dirty(shsurf->view); |
| 2655 | shsurf->saved_rotation_valid = true; |
| 2656 | } |
| 2657 | } |
| 2658 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2659 | if (shsurf->state.fullscreen) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2660 | shell_configure_fullscreen(shsurf); |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2661 | } else if (shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2662 | set_maximized_position(shell, shsurf); |
| 2663 | surface->output = shsurf->output; |
| 2664 | } else { |
| 2665 | float from_x, from_y; |
| 2666 | float to_x, to_y; |
| 2667 | float x, y; |
| 2668 | |
| 2669 | if (shsurf->resize_edges) { |
| 2670 | sx = 0; |
| 2671 | sy = 0; |
| 2672 | } |
| 2673 | |
| 2674 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 2675 | sx = shsurf->last_width - surface->width; |
| 2676 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 2677 | sy = shsurf->last_height - surface->height; |
| 2678 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2679 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 2680 | weston_view_to_global_float(shsurf->view, sx, sy, &to_x, &to_y); |
| 2681 | x = shsurf->view->geometry.x + to_x - from_x; |
| 2682 | y = shsurf->view->geometry.y + to_y - from_y; |
| 2683 | |
| 2684 | weston_view_set_position(shsurf->view, x, y); |
| 2685 | } |
| 2686 | |
Emmanuel Gil Peyrot | c394179 | 2017-04-04 18:49:33 +0100 | [diff] [blame] | 2687 | shsurf->last_width = surface->width; |
| 2688 | shsurf->last_height = surface->height; |
| 2689 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2690 | /* XXX: would a fullscreen surface need the same handling? */ |
| 2691 | if (surface->output) { |
| 2692 | wl_list_for_each(view, &surface->views, surface_link) |
| 2693 | weston_view_update_transform(view); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2694 | } |
| 2695 | } |
| 2696 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2697 | static void |
Derek Foreman | 927d9e2 | 2017-10-06 14:37:44 -0500 | [diff] [blame] | 2698 | get_maximized_size(struct shell_surface *shsurf, int32_t *width, int32_t *height) |
| 2699 | { |
| 2700 | struct desktop_shell *shell; |
| 2701 | pixman_rectangle32_t area; |
| 2702 | |
| 2703 | shell = shell_surface_get_shell(shsurf); |
| 2704 | get_output_work_area(shell, shsurf->output, &area); |
| 2705 | |
| 2706 | *width = area.width; |
| 2707 | *height = area.height; |
| 2708 | } |
| 2709 | |
| 2710 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2711 | set_fullscreen(struct shell_surface *shsurf, bool fullscreen, |
| 2712 | struct weston_output *output) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2713 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2714 | struct weston_desktop_surface *desktop_surface = shsurf->desktop_surface; |
| 2715 | struct weston_surface *surface = |
| 2716 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2717 | int32_t width = 0, height = 0; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2718 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2719 | if (fullscreen) { |
| 2720 | /* handle clients launching in fullscreen */ |
| 2721 | if (output == NULL && !weston_surface_is_mapped(surface)) { |
| 2722 | /* Set the output to the one that has focus currently. */ |
| 2723 | output = get_focused_output(surface->compositor); |
| 2724 | } |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 2725 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2726 | shell_surface_set_output(shsurf, output); |
| 2727 | shsurf->fullscreen_output = shsurf->output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2728 | |
Marius Vlad | 6ebda36 | 2020-03-28 00:23:14 +0200 | [diff] [blame] | 2729 | if (shsurf->output) { |
| 2730 | width = shsurf->output->width; |
| 2731 | height = shsurf->output->height; |
| 2732 | } |
Derek Foreman | e1af3d8 | 2017-10-06 14:37:45 -0500 | [diff] [blame] | 2733 | } else if (weston_desktop_surface_get_maximized(desktop_surface)) { |
| 2734 | get_maximized_size(shsurf, &width, &height); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2735 | } |
| 2736 | weston_desktop_surface_set_fullscreen(desktop_surface, fullscreen); |
| 2737 | weston_desktop_surface_set_size(desktop_surface, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2741 | desktop_surface_move(struct weston_desktop_surface *desktop_surface, |
| 2742 | struct weston_seat *seat, uint32_t serial, void *shell) |
| 2743 | { |
| 2744 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2745 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2746 | struct shell_surface *shsurf = |
| 2747 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2748 | struct weston_surface *surface = |
| 2749 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2750 | struct wl_resource *resource = surface->resource; |
| 2751 | struct weston_surface *focus; |
| 2752 | |
| 2753 | if (pointer && |
| 2754 | pointer->focus && |
| 2755 | pointer->button_count > 0 && |
| 2756 | pointer->grab_serial == serial) { |
| 2757 | focus = weston_surface_get_main_surface(pointer->focus->surface); |
| 2758 | if ((focus == surface) && |
| 2759 | (surface_move(shsurf, pointer, true) < 0)) |
| 2760 | wl_resource_post_no_memory(resource); |
| 2761 | } else if (touch && |
| 2762 | touch->focus && |
| 2763 | touch->grab_serial == serial) { |
| 2764 | focus = weston_surface_get_main_surface(touch->focus->surface); |
| 2765 | if ((focus == surface) && |
| 2766 | (surface_touch_move(shsurf, touch) < 0)) |
| 2767 | wl_resource_post_no_memory(resource); |
| 2768 | } |
| 2769 | } |
| 2770 | |
| 2771 | static void |
| 2772 | desktop_surface_resize(struct weston_desktop_surface *desktop_surface, |
| 2773 | struct weston_seat *seat, uint32_t serial, |
| 2774 | enum weston_desktop_surface_edge edges, void *shell) |
| 2775 | { |
| 2776 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2777 | struct shell_surface *shsurf = |
| 2778 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2779 | struct weston_surface *surface = |
| 2780 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2781 | struct wl_resource *resource = surface->resource; |
| 2782 | struct weston_surface *focus; |
| 2783 | |
| 2784 | if (!pointer || |
| 2785 | pointer->button_count == 0 || |
| 2786 | pointer->grab_serial != serial || |
| 2787 | pointer->focus == NULL) |
| 2788 | return; |
| 2789 | |
| 2790 | focus = weston_surface_get_main_surface(pointer->focus->surface); |
| 2791 | if (focus != surface) |
| 2792 | return; |
| 2793 | |
| 2794 | if (surface_resize(shsurf, pointer, edges) < 0) |
| 2795 | wl_resource_post_no_memory(resource); |
| 2796 | } |
| 2797 | |
| 2798 | static void |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2799 | desktop_surface_set_parent(struct weston_desktop_surface *desktop_surface, |
| 2800 | struct weston_desktop_surface *parent, |
| 2801 | void *shell) |
| 2802 | { |
Marius Vlad | a27658e | 2020-01-17 12:32:55 +0200 | [diff] [blame] | 2803 | struct shell_surface *shsurf_parent; |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2804 | struct shell_surface *shsurf = |
| 2805 | weston_desktop_surface_get_user_data(desktop_surface); |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2806 | |
Marius Vlad | a27658e | 2020-01-17 12:32:55 +0200 | [diff] [blame] | 2807 | /* unlink any potential child */ |
| 2808 | wl_list_remove(&shsurf->children_link); |
| 2809 | |
| 2810 | if (parent) { |
| 2811 | shsurf_parent = weston_desktop_surface_get_user_data(parent); |
| 2812 | wl_list_insert(shsurf_parent->children_list.prev, |
| 2813 | &shsurf->children_link); |
| 2814 | } else { |
| 2815 | wl_list_init(&shsurf->children_link); |
| 2816 | } |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2820 | desktop_surface_fullscreen_requested(struct weston_desktop_surface *desktop_surface, |
| 2821 | bool fullscreen, |
| 2822 | struct weston_output *output, void *shell) |
| 2823 | { |
| 2824 | struct shell_surface *shsurf = |
| 2825 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2826 | |
| 2827 | set_fullscreen(shsurf, fullscreen, output); |
| 2828 | } |
| 2829 | |
| 2830 | static void |
| 2831 | set_maximized(struct shell_surface *shsurf, bool maximized) |
| 2832 | { |
| 2833 | struct weston_desktop_surface *desktop_surface = shsurf->desktop_surface; |
| 2834 | struct weston_surface *surface = |
| 2835 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2836 | int32_t width = 0, height = 0; |
| 2837 | |
| 2838 | if (maximized) { |
| 2839 | struct weston_output *output; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2840 | |
| 2841 | if (!weston_surface_is_mapped(surface)) |
| 2842 | output = get_focused_output(surface->compositor); |
| 2843 | else |
| 2844 | output = surface->output; |
| 2845 | |
| 2846 | shell_surface_set_output(shsurf, output); |
| 2847 | |
Derek Foreman | 927d9e2 | 2017-10-06 14:37:44 -0500 | [diff] [blame] | 2848 | get_maximized_size(shsurf, &width, &height); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2849 | } |
| 2850 | weston_desktop_surface_set_maximized(desktop_surface, maximized); |
| 2851 | weston_desktop_surface_set_size(desktop_surface, width, height); |
| 2852 | } |
| 2853 | |
| 2854 | static void |
| 2855 | desktop_surface_maximized_requested(struct weston_desktop_surface *desktop_surface, |
| 2856 | bool maximized, void *shell) |
| 2857 | { |
| 2858 | struct shell_surface *shsurf = |
| 2859 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2860 | |
| 2861 | set_maximized(shsurf, maximized); |
| 2862 | } |
| 2863 | |
| 2864 | static void |
| 2865 | desktop_surface_minimized_requested(struct weston_desktop_surface *desktop_surface, |
| 2866 | void *shell) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2867 | { |
| 2868 | struct weston_surface *surface = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2869 | weston_desktop_surface_get_surface(desktop_surface); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2870 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2871 | /* apply compositor's own minimization logic (hide) */ |
| 2872 | set_minimized(surface); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2873 | } |
| 2874 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2875 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2876 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2877 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2878 | struct shell_grab *grab; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2879 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2880 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2881 | return; |
| 2882 | |
| 2883 | grab = malloc(sizeof *grab); |
| 2884 | if (!grab) |
| 2885 | return; |
| 2886 | |
| 2887 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2888 | WESTON_DESKTOP_SHELL_CURSOR_BUSY); |
| 2889 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2890 | * to move it. */ |
| 2891 | shsurf->grabbed = 0; |
| 2892 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2893 | |
| 2894 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2895 | end_busy_cursor(struct weston_compositor *compositor, |
| 2896 | struct weston_desktop_client *desktop_client) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2897 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 2898 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2899 | struct shell_grab *grab; |
| 2900 | struct weston_seat *seat; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 2901 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2902 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 2903 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2904 | struct weston_desktop_client *grab_client; |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 2905 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2906 | if (!pointer) |
| 2907 | continue; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2908 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2909 | if (pointer->grab->interface != &busy_cursor_grab_interface) |
| 2910 | continue; |
| 2911 | |
| 2912 | grab = (struct shell_grab *) pointer->grab; |
| 2913 | shsurf = grab->shsurf; |
| 2914 | if (!shsurf) |
| 2915 | continue; |
| 2916 | |
| 2917 | grab_client = |
| 2918 | weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 2919 | if (grab_client == desktop_client) { |
| 2920 | shell_grab_end(grab); |
| 2921 | free(grab); |
| 2922 | } |
| 2923 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2927 | desktop_surface_set_unresponsive(struct weston_desktop_surface *desktop_surface, |
| 2928 | void *user_data) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2929 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2930 | struct shell_surface *shsurf = |
| 2931 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2932 | bool *unresponsive = user_data; |
| 2933 | |
| 2934 | shsurf->unresponsive = *unresponsive; |
| 2935 | } |
| 2936 | |
| 2937 | static void |
| 2938 | desktop_surface_ping_timeout(struct weston_desktop_client *desktop_client, |
| 2939 | void *shell_) |
| 2940 | { |
| 2941 | struct desktop_shell *shell = shell_; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2942 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2943 | struct weston_seat *seat; |
| 2944 | bool unresponsive = true; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2945 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2946 | weston_desktop_client_for_each_surface(desktop_client, |
| 2947 | desktop_surface_set_unresponsive, |
| 2948 | &unresponsive); |
| 2949 | |
| 2950 | |
| 2951 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 2952 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2953 | struct weston_desktop_client *grab_client; |
| 2954 | |
| 2955 | if (!pointer || !pointer->focus) |
| 2956 | continue; |
| 2957 | |
| 2958 | shsurf = get_shell_surface(pointer->focus->surface); |
| 2959 | if (!shsurf) |
| 2960 | continue; |
| 2961 | |
| 2962 | grab_client = |
| 2963 | weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 2964 | if (grab_client == desktop_client) |
| 2965 | set_busy_cursor(shsurf, pointer); |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 2966 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2967 | } |
| 2968 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2969 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2970 | desktop_surface_pong(struct weston_desktop_client *desktop_client, |
| 2971 | void *shell_) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2972 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2973 | struct desktop_shell *shell = shell_; |
| 2974 | bool unresponsive = false; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2975 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2976 | weston_desktop_client_for_each_surface(desktop_client, |
| 2977 | desktop_surface_set_unresponsive, |
| 2978 | &unresponsive); |
| 2979 | end_busy_cursor(shell->compositor, desktop_client); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2980 | } |
| 2981 | |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2982 | static void |
| 2983 | desktop_surface_set_xwayland_position(struct weston_desktop_surface *surface, |
| 2984 | int32_t x, int32_t y, void *shell_) |
| 2985 | { |
| 2986 | struct shell_surface *shsurf = |
| 2987 | weston_desktop_surface_get_user_data(surface); |
| 2988 | |
| 2989 | shsurf->xwayland.x = x; |
| 2990 | shsurf->xwayland.y = y; |
| 2991 | shsurf->xwayland.is_set = true; |
| 2992 | } |
| 2993 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2994 | static const struct weston_desktop_api shell_desktop_api = { |
| 2995 | .struct_size = sizeof(struct weston_desktop_api), |
| 2996 | .surface_added = desktop_surface_added, |
| 2997 | .surface_removed = desktop_surface_removed, |
| 2998 | .committed = desktop_surface_committed, |
| 2999 | .move = desktop_surface_move, |
| 3000 | .resize = desktop_surface_resize, |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 3001 | .set_parent = desktop_surface_set_parent, |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3002 | .fullscreen_requested = desktop_surface_fullscreen_requested, |
| 3003 | .maximized_requested = desktop_surface_maximized_requested, |
| 3004 | .minimized_requested = desktop_surface_minimized_requested, |
| 3005 | .ping_timeout = desktop_surface_ping_timeout, |
| 3006 | .pong = desktop_surface_pong, |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 3007 | .set_xwayland_position = desktop_surface_set_xwayland_position, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3008 | }; |
| 3009 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3010 | /* ************************ * |
| 3011 | * end of libweston-desktop * |
| 3012 | * ************************ */ |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3013 | static void |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 3014 | 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] | 3015 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3016 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3017 | |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 3018 | if (!ev->output) |
| 3019 | return; |
| 3020 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3021 | 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] | 3022 | if (v->output == ev->output && v != ev) { |
| 3023 | weston_view_unmap(v); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3024 | v->surface->committed = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3025 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3026 | } |
| 3027 | } |
| 3028 | |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 3029 | 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] | 3030 | ev->surface->is_mapped = true; |
| 3031 | ev->is_mapped = true; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3032 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3033 | if (wl_list_empty(&ev->layer_link.link)) { |
| 3034 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3035 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3036 | } |
| 3037 | } |
| 3038 | |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3039 | |
| 3040 | static struct shell_output * |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3041 | find_shell_output_from_weston_output(struct desktop_shell *shell, |
| 3042 | struct weston_output *output) |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3043 | { |
| 3044 | struct shell_output *shell_output; |
| 3045 | |
| 3046 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 3047 | if (shell_output->output == output) |
| 3048 | return shell_output; |
| 3049 | } |
| 3050 | |
| 3051 | return NULL; |
| 3052 | } |
| 3053 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3054 | static int |
| 3055 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3056 | { |
| 3057 | return snprintf(buf, len, "background for output %s", |
Miguel A. Vico | 620f68d | 2019-09-25 11:23:13 -0700 | [diff] [blame] | 3058 | (surface->output ? surface->output->name : "NULL")); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3059 | } |
| 3060 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3061 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3062 | 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] | 3063 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3064 | struct desktop_shell *shell = es->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3065 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3066 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3067 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3068 | |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 3069 | configure_static_view(view, &shell->background_layer, 0, 0); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3070 | } |
| 3071 | |
| 3072 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3073 | handle_background_surface_destroy(struct wl_listener *listener, void *data) |
| 3074 | { |
| 3075 | struct shell_output *output = |
| 3076 | container_of(listener, struct shell_output, background_surface_listener); |
| 3077 | |
| 3078 | weston_log("background surface gone\n"); |
Tomohito Esaki | bf31f6c | 2018-01-31 15:15:45 +0900 | [diff] [blame] | 3079 | wl_list_remove(&output->background_surface_listener.link); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3080 | output->background_surface = NULL; |
| 3081 | } |
| 3082 | |
| 3083 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3084 | desktop_shell_set_background(struct wl_client *client, |
| 3085 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3086 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3087 | struct wl_resource *surface_resource) |
| 3088 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3089 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3090 | struct weston_surface *surface = |
| 3091 | wl_resource_get_user_data(surface_resource); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3092 | struct shell_output *sh_output; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3093 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3094 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3095 | if (surface->committed) { |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3096 | wl_resource_post_error(surface_resource, |
| 3097 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3098 | "surface role already assigned"); |
| 3099 | return; |
| 3100 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3101 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3102 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3103 | weston_view_destroy(view); |
| 3104 | view = weston_view_create(surface); |
| 3105 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3106 | surface->committed = background_committed; |
| 3107 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3108 | weston_surface_set_label_func(surface, background_get_label); |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 3109 | surface->output = weston_head_from_resource(output_resource)->output; |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 3110 | weston_view_set_output(view, surface->output); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3111 | |
| 3112 | sh_output = find_shell_output_from_weston_output(shell, surface->output); |
Pekka Paalanen | ff5e88d | 2017-12-07 11:44:18 +0200 | [diff] [blame] | 3113 | if (sh_output->background_surface) { |
| 3114 | /* The output already has a background, tell our helper |
| 3115 | * there is no need for another one. */ |
| 3116 | weston_desktop_shell_send_configure(resource, 0, |
| 3117 | surface_resource, |
| 3118 | 0, 0); |
| 3119 | } else { |
| 3120 | weston_desktop_shell_send_configure(resource, 0, |
| 3121 | surface_resource, |
| 3122 | surface->output->width, |
| 3123 | surface->output->height); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3124 | |
Pekka Paalanen | ff5e88d | 2017-12-07 11:44:18 +0200 | [diff] [blame] | 3125 | sh_output->background_surface = surface; |
| 3126 | |
| 3127 | sh_output->background_surface_listener.notify = |
| 3128 | handle_background_surface_destroy; |
| 3129 | wl_signal_add(&surface->destroy_signal, |
| 3130 | &sh_output->background_surface_listener); |
| 3131 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3132 | } |
| 3133 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3134 | static int |
| 3135 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3136 | { |
| 3137 | return snprintf(buf, len, "panel for output %s", |
Miguel A. Vico | 620f68d | 2019-09-25 11:23:13 -0700 | [diff] [blame] | 3138 | (surface->output ? surface->output->name : "NULL")); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3139 | } |
| 3140 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3141 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3142 | 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] | 3143 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3144 | struct desktop_shell *shell = es->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3145 | struct weston_view *view; |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 3146 | int width, height; |
| 3147 | int x = 0, y = 0; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3148 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3149 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3150 | |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 3151 | get_panel_size(shell, view, &width, &height); |
| 3152 | switch (shell->panel_position) { |
| 3153 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 3154 | break; |
| 3155 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 3156 | y = view->output->height - height; |
| 3157 | break; |
| 3158 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 3159 | break; |
| 3160 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 3161 | x = view->output->width - width; |
| 3162 | break; |
| 3163 | } |
| 3164 | |
| 3165 | configure_static_view(view, &shell->panel_layer, x, y); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3169 | handle_panel_surface_destroy(struct wl_listener *listener, void *data) |
| 3170 | { |
| 3171 | struct shell_output *output = |
| 3172 | container_of(listener, struct shell_output, panel_surface_listener); |
| 3173 | |
| 3174 | weston_log("panel surface gone\n"); |
Tomohito Esaki | bf31f6c | 2018-01-31 15:15:45 +0900 | [diff] [blame] | 3175 | wl_list_remove(&output->panel_surface_listener.link); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3176 | output->panel_surface = NULL; |
| 3177 | } |
| 3178 | |
| 3179 | |
| 3180 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3181 | desktop_shell_set_panel(struct wl_client *client, |
| 3182 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3183 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3184 | struct wl_resource *surface_resource) |
| 3185 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3186 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3187 | struct weston_surface *surface = |
| 3188 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3189 | struct weston_view *view, *next; |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3190 | struct shell_output *sh_output; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3191 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3192 | if (surface->committed) { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3193 | wl_resource_post_error(surface_resource, |
| 3194 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3195 | "surface role already assigned"); |
| 3196 | return; |
| 3197 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3198 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3199 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3200 | weston_view_destroy(view); |
| 3201 | view = weston_view_create(surface); |
| 3202 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3203 | surface->committed = panel_committed; |
| 3204 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3205 | weston_surface_set_label_func(surface, panel_get_label); |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 3206 | surface->output = weston_head_from_resource(output_resource)->output; |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 3207 | weston_view_set_output(view, surface->output); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3208 | |
| 3209 | sh_output = find_shell_output_from_weston_output(shell, surface->output); |
Pekka Paalanen | 1a0239e | 2017-12-07 11:54:11 +0200 | [diff] [blame] | 3210 | if (sh_output->panel_surface) { |
| 3211 | /* The output already has a panel, tell our helper |
| 3212 | * there is no need for another one. */ |
| 3213 | weston_desktop_shell_send_configure(resource, 0, |
| 3214 | surface_resource, |
| 3215 | 0, 0); |
| 3216 | } else { |
| 3217 | weston_desktop_shell_send_configure(resource, 0, |
| 3218 | surface_resource, |
| 3219 | surface->output->width, |
| 3220 | surface->output->height); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3221 | |
Pekka Paalanen | 1a0239e | 2017-12-07 11:54:11 +0200 | [diff] [blame] | 3222 | sh_output->panel_surface = surface; |
| 3223 | |
| 3224 | sh_output->panel_surface_listener.notify = handle_panel_surface_destroy; |
| 3225 | wl_signal_add(&surface->destroy_signal, &sh_output->panel_surface_listener); |
| 3226 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3227 | } |
| 3228 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3229 | static int |
| 3230 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3231 | { |
| 3232 | return snprintf(buf, len, "lock window"); |
| 3233 | } |
| 3234 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3235 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3236 | 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] | 3237 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3238 | struct desktop_shell *shell = surface->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3239 | struct weston_view *view; |
| 3240 | |
| 3241 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3242 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3243 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3244 | return; |
| 3245 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3246 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3247 | |
| 3248 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3249 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 3250 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3251 | weston_view_update_transform(view); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 3252 | surface->is_mapped = true; |
| 3253 | view->is_mapped = true; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3254 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3255 | } |
| 3256 | } |
| 3257 | |
| 3258 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3259 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3260 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3261 | struct desktop_shell *shell = |
| 3262 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3263 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3264 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3265 | shell->lock_surface = NULL; |
| 3266 | } |
| 3267 | |
| 3268 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3269 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3270 | struct wl_resource *resource, |
| 3271 | struct wl_resource *surface_resource) |
| 3272 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3273 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3274 | struct weston_surface *surface = |
| 3275 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3276 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3277 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3278 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3279 | if (!shell->locked) |
| 3280 | return; |
| 3281 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3282 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3283 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3284 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3285 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3286 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3287 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3288 | weston_view_create(surface); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3289 | surface->committed = lock_surface_committed; |
| 3290 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3291 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3292 | } |
| 3293 | |
| 3294 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3295 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3296 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3297 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3298 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3299 | weston_layer_unset_position(&shell->lock_layer); |
| 3300 | |
| 3301 | if (shell->showing_input_panels) |
| 3302 | weston_layer_set_position(&shell->input_panel_layer, |
| 3303 | WESTON_LAYER_POSITION_TOP_UI); |
| 3304 | weston_layer_set_position(&shell->fullscreen_layer, |
| 3305 | WESTON_LAYER_POSITION_FULLSCREEN); |
| 3306 | weston_layer_set_position(&shell->panel_layer, |
| 3307 | WESTON_LAYER_POSITION_UI); |
| 3308 | weston_layer_set_position(&ws->layer, WESTON_LAYER_POSITION_NORMAL); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3309 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3310 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3311 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3312 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3313 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3314 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | static void |
| 3318 | desktop_shell_unlock(struct wl_client *client, |
| 3319 | struct wl_resource *resource) |
| 3320 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3321 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3322 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3323 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3324 | |
| 3325 | if (shell->locked) |
| 3326 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3327 | } |
| 3328 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3329 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3330 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3331 | struct wl_resource *resource, |
| 3332 | struct wl_resource *surface_resource) |
| 3333 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3334 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3335 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3336 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3337 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3338 | } |
| 3339 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3340 | static void |
| 3341 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3342 | struct wl_resource *resource) |
| 3343 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3344 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3345 | |
| 3346 | shell_fade_startup(shell); |
| 3347 | } |
| 3348 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3349 | static void |
| 3350 | desktop_shell_set_panel_position(struct wl_client *client, |
| 3351 | struct wl_resource *resource, |
| 3352 | uint32_t position) |
| 3353 | { |
| 3354 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3355 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3356 | if (position != WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 3357 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 3358 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 3359 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3360 | wl_resource_post_error(resource, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3361 | WESTON_DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3362 | "bad position argument"); |
| 3363 | return; |
| 3364 | } |
| 3365 | |
| 3366 | shell->panel_position = position; |
| 3367 | } |
| 3368 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3369 | static const struct weston_desktop_shell_interface desktop_shell_implementation = { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3370 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3371 | desktop_shell_set_panel, |
| 3372 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3373 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3374 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3375 | desktop_shell_desktop_ready, |
| 3376 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3377 | }; |
| 3378 | |
| 3379 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3380 | move_binding(struct weston_pointer *pointer, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3381 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3382 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3383 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3384 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3385 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3386 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3387 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3388 | return; |
| 3389 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3390 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3391 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3392 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3393 | if (surface == NULL) |
| 3394 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3395 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3396 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3397 | if (shsurf == NULL || |
| 3398 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3399 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3400 | return; |
| 3401 | |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 3402 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3406 | maximize_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3407 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3408 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3409 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3410 | struct weston_surface *surface; |
| 3411 | struct shell_surface *shsurf; |
| 3412 | |
| 3413 | surface = weston_surface_get_main_surface(focus); |
| 3414 | if (surface == NULL) |
| 3415 | return; |
| 3416 | |
| 3417 | shsurf = get_shell_surface(surface); |
| 3418 | if (shsurf == NULL) |
| 3419 | return; |
| 3420 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3421 | set_maximized(shsurf, !weston_desktop_surface_get_maximized(shsurf->desktop_surface)); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3425 | fullscreen_binding(struct weston_keyboard *keyboard, |
| 3426 | const struct timespec *time, uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3427 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3428 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3429 | struct weston_surface *surface; |
| 3430 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3431 | bool fullscreen; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3432 | |
| 3433 | surface = weston_surface_get_main_surface(focus); |
| 3434 | if (surface == NULL) |
| 3435 | return; |
| 3436 | |
| 3437 | shsurf = get_shell_surface(surface); |
| 3438 | if (shsurf == NULL) |
| 3439 | return; |
| 3440 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3441 | fullscreen = |
| 3442 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3443 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3444 | set_fullscreen(shsurf, !fullscreen, NULL); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3445 | } |
| 3446 | |
| 3447 | static void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 3448 | 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] | 3449 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 3450 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3451 | struct weston_surface *surface; |
| 3452 | struct shell_surface *shsurf; |
| 3453 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3454 | if (touch->focus == NULL) |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 3455 | return; |
| 3456 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3457 | focus = touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3458 | surface = weston_surface_get_main_surface(focus); |
| 3459 | if (surface == NULL) |
| 3460 | return; |
| 3461 | |
| 3462 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3463 | if (shsurf == NULL || |
| 3464 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3465 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3466 | return; |
| 3467 | |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 3468 | surface_touch_move(shsurf, touch); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3472 | resize_binding(struct weston_pointer *pointer, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3473 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3474 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3475 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3476 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3477 | uint32_t edges = 0; |
| 3478 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3479 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3480 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3481 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3482 | return; |
| 3483 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3484 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3485 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3486 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3487 | if (surface == NULL) |
| 3488 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3489 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3490 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3491 | if (shsurf == NULL || |
| 3492 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3493 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3494 | return; |
| 3495 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3496 | weston_view_from_global(shsurf->view, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3497 | wl_fixed_to_int(pointer->grab_x), |
| 3498 | wl_fixed_to_int(pointer->grab_y), |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3499 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3500 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3501 | if (x < surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3502 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3503 | else if (x < 2 * surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3504 | edges |= 0; |
| 3505 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3506 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3507 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3508 | if (y < surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3509 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3510 | else if (y < 2 * surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3511 | edges |= 0; |
| 3512 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3513 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3514 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3515 | surface_resize(shsurf, pointer, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | static void |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 3519 | surface_opacity_binding(struct weston_pointer *pointer, |
| 3520 | const struct timespec *time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3521 | struct weston_pointer_axis_event *event, |
| 3522 | void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3523 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3524 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3525 | struct shell_surface *shsurf; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3526 | struct weston_surface *focus = pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3527 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3528 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3529 | /* XXX: broken for windows containing sub-surfaces */ |
| 3530 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3531 | if (surface == NULL) |
| 3532 | return; |
| 3533 | |
| 3534 | shsurf = get_shell_surface(surface); |
| 3535 | if (!shsurf) |
| 3536 | return; |
| 3537 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 3538 | shsurf->view->alpha -= event->value * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3539 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3540 | if (shsurf->view->alpha > 1.0) |
| 3541 | shsurf->view->alpha = 1.0; |
| 3542 | if (shsurf->view->alpha < step) |
| 3543 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3544 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3545 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3546 | weston_surface_damage(surface); |
| 3547 | } |
| 3548 | |
| 3549 | static void |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 3550 | do_zoom(struct weston_seat *seat, const struct timespec *time, uint32_t key, |
| 3551 | uint32_t axis, double value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3552 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 3553 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3554 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3555 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3556 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3557 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3558 | if (!pointer) { |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 3559 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 3560 | return; |
| 3561 | } |
| 3562 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3563 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3564 | if (pixman_region32_contains_point(&output->region, |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3565 | wl_fixed_to_double(pointer->x), |
| 3566 | wl_fixed_to_double(pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3567 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3568 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3569 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3570 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3571 | increment = -output->zoom.increment; |
| 3572 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3573 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3574 | increment = output->zoom.increment * |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 3575 | -value / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3576 | else |
| 3577 | increment = 0; |
| 3578 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3579 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3580 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3581 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3582 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3583 | else if (output->zoom.level > output->zoom.max_level) |
| 3584 | output->zoom.level = output->zoom.max_level; |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 3585 | |
| 3586 | if (!output->zoom.active) { |
| 3587 | if (output->zoom.level <= 0.0) |
| 3588 | continue; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 3589 | weston_output_activate_zoom(output, seat); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3590 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3591 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3592 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3593 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3594 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3595 | } |
| 3596 | } |
| 3597 | } |
| 3598 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3599 | static void |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 3600 | zoom_axis_binding(struct weston_pointer *pointer, const struct timespec *time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3601 | struct weston_pointer_axis_event *event, |
| 3602 | void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3603 | { |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3604 | do_zoom(pointer->seat, time, 0, event->axis, event->value); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3608 | zoom_key_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3609 | uint32_t key, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3610 | { |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3611 | do_zoom(keyboard->seat, time, key, 0, 0); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3615 | terminate_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3616 | uint32_t key, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3617 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3618 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3619 | |
Pekka Paalanen | 052032d | 2019-02-06 10:44:37 +0200 | [diff] [blame] | 3620 | weston_compositor_exit(compositor); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3621 | } |
| 3622 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3623 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 3624 | rotate_grab_motion(struct weston_pointer_grab *grab, |
| 3625 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3626 | struct weston_pointer_motion_event *event) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3627 | { |
| 3628 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3629 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3630 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3631 | struct shell_surface *shsurf = rotate->base.shsurf; |
Sergey Bugaev | 14ef201 | 2019-02-11 22:55:09 +0300 | [diff] [blame] | 3632 | struct weston_surface *surface; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3633 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3634 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3635 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3636 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3637 | if (!shsurf) |
| 3638 | return; |
| 3639 | |
Sergey Bugaev | 14ef201 | 2019-02-11 22:55:09 +0300 | [diff] [blame] | 3640 | surface = weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 3641 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3642 | cx = 0.5f * surface->width; |
| 3643 | cy = 0.5f * surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3644 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3645 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3646 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3647 | r = sqrtf(dx * dx + dy * dy); |
| 3648 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3649 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3650 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3651 | |
| 3652 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3653 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3654 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3655 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3656 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3657 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3658 | |
| 3659 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3660 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3661 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3662 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3663 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3664 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 3665 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3666 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3667 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3668 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3669 | wl_list_init(&shsurf->rotation.transform.link); |
| 3670 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3671 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3672 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3673 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3674 | /* We need to adjust the position of the surface |
| 3675 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3676 | cposx = shsurf->view->geometry.x + cx; |
| 3677 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3678 | dposx = rotate->center.x - cposx; |
| 3679 | dposy = rotate->center.y - cposy; |
| 3680 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3681 | weston_view_set_position(shsurf->view, |
| 3682 | shsurf->view->geometry.x + dposx, |
| 3683 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3684 | } |
| 3685 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 3686 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3687 | * lazily applies the damage due to rotation update. |
| 3688 | */ |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3689 | weston_compositor_schedule_repaint(surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3690 | } |
| 3691 | |
| 3692 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3693 | rotate_grab_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3694 | const struct timespec *time, |
| 3695 | uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3696 | { |
| 3697 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3698 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3699 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3700 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3701 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3702 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3703 | if (pointer->button_count == 0 && |
| 3704 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3705 | if (shsurf) |
| 3706 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 3707 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3708 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3709 | free(rotate); |
| 3710 | } |
| 3711 | } |
| 3712 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3713 | static void |
| 3714 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 3715 | { |
| 3716 | struct rotate_grab *rotate = |
| 3717 | container_of(grab, struct rotate_grab, base.grab); |
| 3718 | |
| 3719 | shell_grab_end(&rotate->base); |
| 3720 | free(rotate); |
| 3721 | } |
| 3722 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3723 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3724 | noop_grab_focus, |
| 3725 | rotate_grab_motion, |
| 3726 | rotate_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3727 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 3728 | noop_grab_axis_source, |
| 3729 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3730 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3731 | }; |
| 3732 | |
| 3733 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3734 | surface_rotate(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3735 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3736 | struct weston_surface *surface = |
| 3737 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3738 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3739 | float dx, dy; |
| 3740 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3741 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3742 | rotate = malloc(sizeof *rotate); |
| 3743 | if (!rotate) |
| 3744 | return; |
| 3745 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3746 | weston_view_to_global_float(shsurf->view, |
| 3747 | surface->width * 0.5f, |
| 3748 | surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3749 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3750 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 3751 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3752 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3753 | r = sqrtf(dx * dx + dy * dy); |
| 3754 | if (r > 20.0f) { |
| 3755 | struct weston_matrix inverse; |
| 3756 | |
| 3757 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3758 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3759 | weston_matrix_multiply(&shsurf->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3760 | |
| 3761 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3762 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3763 | } else { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3764 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3765 | weston_matrix_init(&rotate->rotation); |
| 3766 | } |
| 3767 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3768 | shell_grab_start(&rotate->base, &rotate_grab_interface, shsurf, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3769 | pointer, WESTON_DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3773 | rotate_binding(struct weston_pointer *pointer, const struct timespec *time, |
| 3774 | uint32_t button, void *data) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3775 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3776 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3777 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3778 | struct shell_surface *surface; |
| 3779 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3780 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3781 | return; |
| 3782 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3783 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3784 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3785 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3786 | if (base_surface == NULL) |
| 3787 | return; |
| 3788 | |
| 3789 | surface = get_shell_surface(base_surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3790 | if (surface == NULL || |
| 3791 | weston_desktop_surface_get_fullscreen(surface->desktop_surface) || |
| 3792 | weston_desktop_surface_get_maximized(surface->desktop_surface)) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3793 | return; |
| 3794 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 3795 | surface_rotate(surface, pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3796 | } |
| 3797 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3798 | /* Move all fullscreen layers down to the current workspace and hide their |
| 3799 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 3800 | * and this is reversed when such a surface is re-configured, see |
| 3801 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 3802 | * |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3803 | * lowering_output = NULL - Lower on all outputs, else only lower on the |
| 3804 | * specified output. |
| 3805 | * |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3806 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3807 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3808 | void |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3809 | lower_fullscreen_layer(struct desktop_shell *shell, |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3810 | struct weston_output *lowering_output) |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3811 | { |
| 3812 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3813 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3814 | |
| 3815 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3816 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3817 | &shell->fullscreen_layer.view_list.link, |
| 3818 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3819 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 3820 | |
| 3821 | if (!shsurf) |
| 3822 | continue; |
| 3823 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3824 | /* Only lower surfaces which have lowering_output as their fullscreen |
| 3825 | * output, unless a NULL output asks for lowering on all outputs. |
| 3826 | */ |
| 3827 | if (lowering_output && (shsurf->fullscreen_output != lowering_output)) |
| 3828 | continue; |
| 3829 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3830 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 3831 | * in the fullscreen layer. */ |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3832 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3833 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3834 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 3835 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 3836 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 3837 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3838 | } |
| 3839 | |
| 3840 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3841 | weston_layer_entry_remove(&view->layer_link); |
| 3842 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3843 | weston_view_damage_below(view); |
| 3844 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3845 | |
| 3846 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3847 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3848 | } |
| 3849 | |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 3850 | static struct shell_surface *get_last_child(struct shell_surface *shsurf) |
| 3851 | { |
| 3852 | struct shell_surface *shsurf_child; |
| 3853 | |
| 3854 | wl_list_for_each_reverse(shsurf_child, &shsurf->children_list, children_link) { |
| 3855 | if (weston_view_is_mapped(shsurf_child->view)) |
| 3856 | return shsurf_child; |
| 3857 | } |
| 3858 | |
| 3859 | return NULL; |
| 3860 | } |
| 3861 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3862 | void |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 3863 | activate(struct desktop_shell *shell, struct weston_view *view, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3864 | struct weston_seat *seat, uint32_t flags) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3865 | { |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 3866 | struct weston_surface *es = view->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3867 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3868 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3869 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3870 | struct weston_surface *old_es; |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 3871 | struct shell_surface *shsurf, *shsurf_child; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3872 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3873 | main_surface = weston_surface_get_main_surface(es); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3874 | shsurf = get_shell_surface(main_surface); |
| 3875 | assert(shsurf); |
| 3876 | |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 3877 | shsurf_child = get_last_child(shsurf); |
| 3878 | if (shsurf_child) { |
| 3879 | /* Activate last xdg child instead of parent. */ |
| 3880 | activate(shell, shsurf_child->view, seat, flags); |
| 3881 | return; |
| 3882 | } |
| 3883 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3884 | /* Only demote fullscreen surfaces on the output of activated shsurf. |
| 3885 | * Leave fullscreen surfaces on unrelated outputs alone. */ |
Pekka Paalanen | 87860c2 | 2018-05-02 10:21:57 +0200 | [diff] [blame] | 3886 | if (shsurf->output) |
| 3887 | lower_fullscreen_layer(shell, shsurf->output); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3888 | |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 3889 | weston_view_activate(view, seat, flags); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3890 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3891 | state = ensure_focus_state(shell, seat); |
| 3892 | if (state == NULL) |
| 3893 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3894 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3895 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 3896 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3897 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3898 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) && |
| 3899 | flags & WESTON_ACTIVATE_FLAG_CONFIGURE) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3900 | shell_configure_fullscreen(shsurf); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3901 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 3902 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 3903 | * order as appropriate. */ |
| 3904 | shell_surface_update_layer(shsurf); |
| 3905 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3906 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 3907 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3908 | 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] | 3909 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3910 | } |
| 3911 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3912 | /* no-op func for checking black surface */ |
| 3913 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3914 | 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] | 3915 | { |
| 3916 | } |
| 3917 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 3918 | static bool |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3919 | 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] | 3920 | { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3921 | struct weston_surface *surface = view->surface; |
| 3922 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3923 | if (surface->committed == black_surface_committed) { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3924 | if (fs_view) |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3925 | *fs_view = surface->committed_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3926 | return true; |
| 3927 | } |
| 3928 | return false; |
| 3929 | } |
| 3930 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3931 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3932 | activate_binding(struct weston_seat *seat, |
| 3933 | struct desktop_shell *shell, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3934 | struct weston_view *focus_view, |
| 3935 | uint32_t flags) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3936 | { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3937 | struct weston_view *main_view; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3938 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3939 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3940 | if (!focus_view) |
| 3941 | return; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 3942 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3943 | if (is_black_surface_view(focus_view, &main_view)) |
| 3944 | focus_view = main_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3945 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3946 | main_surface = weston_surface_get_main_surface(focus_view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3947 | if (!get_shell_surface(main_surface)) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3948 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 3949 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3950 | activate(shell, focus_view, seat, flags); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3954 | click_to_activate_binding(struct weston_pointer *pointer, |
| 3955 | const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3956 | uint32_t button, void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3957 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3958 | if (pointer->grab != &pointer->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3959 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3960 | if (pointer->focus == NULL) |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 3961 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3962 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3963 | activate_binding(pointer->seat, data, pointer->focus, |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 3964 | WESTON_ACTIVATE_FLAG_CLICKED | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3965 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3966 | } |
| 3967 | |
| 3968 | static void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 3969 | touch_to_activate_binding(struct weston_touch *touch, |
| 3970 | const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3971 | void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3972 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3973 | if (touch->grab != &touch->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3974 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3975 | if (touch->focus == NULL) |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 3976 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3977 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3978 | activate_binding(touch->seat, data, touch->focus, |
| 3979 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3980 | } |
| 3981 | |
| 3982 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3983 | unfocus_all_seats(struct desktop_shell *shell) |
| 3984 | { |
| 3985 | struct weston_seat *seat, *next; |
| 3986 | |
| 3987 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3988 | struct weston_keyboard *keyboard = |
| 3989 | weston_seat_get_keyboard(seat); |
| 3990 | |
| 3991 | if (!keyboard) |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3992 | continue; |
| 3993 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3994 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3995 | } |
| 3996 | } |
| 3997 | |
| 3998 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3999 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4000 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4001 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4002 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4003 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4004 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4005 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4006 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4007 | |
| 4008 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4009 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4010 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4011 | * toplevel layers. This way nothing else can show or receive |
| 4012 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4013 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 4014 | weston_layer_unset_position(&shell->panel_layer); |
| 4015 | weston_layer_unset_position(&shell->fullscreen_layer); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4016 | if (shell->showing_input_panels) |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 4017 | weston_layer_unset_position(&shell->input_panel_layer); |
| 4018 | weston_layer_unset_position(&ws->layer); |
| 4019 | |
| 4020 | weston_layer_set_position(&shell->lock_layer, |
| 4021 | WESTON_LAYER_POSITION_LOCK); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4022 | |
Derek Foreman | 004b4a1 | 2015-07-20 16:28:13 -0500 | [diff] [blame] | 4023 | weston_compositor_sleep(shell->compositor); |
| 4024 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 4025 | /* Remove the keyboard focus on all seats. This will be |
| 4026 | * restored to the workspace's saved state via |
| 4027 | * restore_focus_state when the compositor is unlocked */ |
| 4028 | unfocus_all_seats(shell); |
| 4029 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4030 | /* TODO: disable bindings that should not work while locked. */ |
| 4031 | |
| 4032 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4036 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4037 | { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4038 | struct wl_resource *shell_resource; |
| 4039 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4040 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4041 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4042 | return; |
| 4043 | } |
| 4044 | |
| 4045 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4046 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4047 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4048 | return; |
| 4049 | } |
| 4050 | |
| 4051 | if (shell->prepare_event_sent) |
| 4052 | return; |
| 4053 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4054 | shell_resource = shell->child.desktop_shell; |
| 4055 | weston_desktop_shell_send_prepare_lock_surface(shell_resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4056 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4057 | } |
| 4058 | |
| 4059 | static void |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4060 | 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] | 4061 | { |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4062 | struct shell_output *shell_output = data; |
| 4063 | struct desktop_shell *shell = shell_output->shell; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4064 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4065 | shell_output->fade.animation = NULL; |
| 4066 | switch (shell_output->fade.type) { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4067 | case FADE_IN: |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4068 | weston_surface_destroy(shell_output->fade.view->surface); |
| 4069 | shell_output->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4070 | break; |
| 4071 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4072 | lock(shell); |
| 4073 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4074 | default: |
| 4075 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4076 | } |
| 4077 | } |
| 4078 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4079 | static struct weston_view * |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4080 | 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] | 4081 | { |
| 4082 | struct weston_compositor *compositor = shell->compositor; |
| 4083 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4084 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4085 | |
| 4086 | surface = weston_surface_create(compositor); |
| 4087 | if (!surface) |
| 4088 | return NULL; |
| 4089 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4090 | view = weston_view_create(surface); |
| 4091 | if (!view) { |
| 4092 | weston_surface_destroy(surface); |
| 4093 | return NULL; |
| 4094 | } |
| 4095 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4096 | weston_surface_set_size(surface, shell_output->output->width, shell_output->output->height); |
| 4097 | 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] | 4098 | 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] | 4099 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 4100 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4101 | pixman_region32_init(&surface->input); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 4102 | surface->is_mapped = true; |
| 4103 | view->is_mapped = true; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4104 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4105 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | static void |
| 4109 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4110 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4111 | float tint; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4112 | struct shell_output *shell_output; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4113 | |
| 4114 | switch (type) { |
| 4115 | case FADE_IN: |
| 4116 | tint = 0.0; |
| 4117 | break; |
| 4118 | case FADE_OUT: |
| 4119 | tint = 1.0; |
| 4120 | break; |
| 4121 | default: |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 4122 | weston_log("shell: invalid fade type\n"); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4123 | return; |
| 4124 | } |
| 4125 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4126 | /* Create a separate fade surface for each output */ |
| 4127 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4128 | shell_output->fade.type = type; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4129 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4130 | if (shell_output->fade.view == NULL) { |
| 4131 | shell_output->fade.view = shell_fade_create_surface_for_output(shell, shell_output); |
| 4132 | if (!shell_output->fade.view) |
| 4133 | continue; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4134 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4135 | shell_output->fade.view->alpha = 1.0 - tint; |
| 4136 | weston_view_update_transform(shell_output->fade.view); |
| 4137 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4138 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4139 | if (shell_output->fade.view->output == NULL) { |
| 4140 | /* If the black view gets a NULL output, we lost the |
| 4141 | * last output and we'll just cancel the fade. This |
| 4142 | * happens when you close the last window under the |
| 4143 | * X11 or Wayland backends. */ |
| 4144 | shell->locked = false; |
| 4145 | weston_surface_destroy(shell_output->fade.view->surface); |
| 4146 | shell_output->fade.view = NULL; |
| 4147 | } else if (shell_output->fade.animation) { |
| 4148 | weston_fade_update(shell_output->fade.animation, tint); |
| 4149 | } else { |
| 4150 | shell_output->fade.animation = |
| 4151 | weston_fade_run(shell_output->fade.view, |
| 4152 | 1.0 - tint, tint, 300.0, |
| 4153 | shell_fade_done_for_output, shell_output); |
| 4154 | } |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4155 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4159 | do_shell_fade_startup(void *data) |
| 4160 | { |
| 4161 | struct desktop_shell *shell = data; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4162 | struct shell_output *shell_output; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4163 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 4164 | if (shell->startup_animation_type == ANIMATION_FADE) { |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4165 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 4166 | } else { |
| 4167 | weston_log("desktop shell: " |
| 4168 | "unexpected fade-in animation type %d\n", |
| 4169 | shell->startup_animation_type); |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4170 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4171 | weston_surface_destroy(shell_output->fade.view->surface); |
| 4172 | shell_output->fade.view = NULL; |
| 4173 | } |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4174 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | static void |
| 4178 | shell_fade_startup(struct desktop_shell *shell) |
| 4179 | { |
| 4180 | struct wl_event_loop *loop; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4181 | struct shell_output *shell_output; |
| 4182 | bool has_fade = false; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4183 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4184 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4185 | if (!shell_output->fade.startup_timer) |
| 4186 | continue; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4187 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4188 | wl_event_source_remove(shell_output->fade.startup_timer); |
| 4189 | shell_output->fade.startup_timer = NULL; |
| 4190 | has_fade = true; |
| 4191 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4192 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4193 | if (has_fade) { |
| 4194 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4195 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4196 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4197 | } |
| 4198 | |
| 4199 | static int |
| 4200 | fade_startup_timeout(void *data) |
| 4201 | { |
| 4202 | struct desktop_shell *shell = data; |
| 4203 | |
| 4204 | shell_fade_startup(shell); |
| 4205 | return 0; |
| 4206 | } |
| 4207 | |
| 4208 | static void |
| 4209 | shell_fade_init(struct desktop_shell *shell) |
| 4210 | { |
| 4211 | /* Make compositor output all black, and wait for the desktop-shell |
| 4212 | * client to signal it is ready, then fade in. The timer triggers a |
| 4213 | * fade-in, in case the desktop-shell client takes too long. |
| 4214 | */ |
| 4215 | |
| 4216 | struct wl_event_loop *loop; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4217 | struct shell_output *shell_output; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4218 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 4219 | if (shell->startup_animation_type == ANIMATION_NONE) |
| 4220 | return; |
| 4221 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4222 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4223 | if (shell_output->fade.view != NULL) { |
| 4224 | weston_log("%s: warning: fade surface already exists\n", |
| 4225 | __func__); |
| 4226 | continue; |
| 4227 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4228 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4229 | shell_output->fade.view = shell_fade_create_surface_for_output(shell, shell_output); |
| 4230 | if (!shell_output->fade.view) |
| 4231 | continue; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4232 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4233 | weston_view_update_transform(shell_output->fade.view); |
| 4234 | weston_surface_damage(shell_output->fade.view->surface); |
| 4235 | |
| 4236 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4237 | shell_output->fade.startup_timer = |
| 4238 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4239 | wl_event_source_timer_update(shell_output->fade.startup_timer, 15000); |
| 4240 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4241 | } |
| 4242 | |
| 4243 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4244 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4245 | { |
| 4246 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4247 | container_of(listener, struct desktop_shell, idle_listener); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4248 | |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 4249 | struct weston_seat *seat; |
| 4250 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4251 | wl_list_for_each(seat, &shell->compositor->seat_list, link) |
| 4252 | weston_seat_break_desktop_grabs(seat); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4253 | |
| 4254 | shell_fade(shell, FADE_OUT); |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4255 | /* lock() is called from shell_fade_done_for_output() */ |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4256 | } |
| 4257 | |
| 4258 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4259 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4260 | { |
| 4261 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4262 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4263 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4264 | unlock(shell); |
| 4265 | } |
| 4266 | |
| 4267 | static void |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4268 | transform_handler(struct wl_listener *listener, void *data) |
| 4269 | { |
| 4270 | struct weston_surface *surface = data; |
| 4271 | struct shell_surface *shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4272 | const struct weston_xwayland_surface_api *api; |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4273 | int x, y; |
| 4274 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4275 | if (!shsurf) |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4276 | return; |
| 4277 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4278 | api = shsurf->shell->xwayland_surface_api; |
| 4279 | if (!api) { |
| 4280 | api = weston_xwayland_surface_get_api(shsurf->shell->compositor); |
| 4281 | shsurf->shell->xwayland_surface_api = api; |
| 4282 | } |
| 4283 | |
| 4284 | if (!api || !api->is_xwayland_surface(surface)) |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4285 | return; |
| 4286 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4287 | if (!weston_view_is_mapped(shsurf->view)) |
| 4288 | return; |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4289 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4290 | x = shsurf->view->geometry.x; |
| 4291 | y = shsurf->view->geometry.y; |
| 4292 | |
| 4293 | api->send_position(surface, x, y); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4294 | } |
| 4295 | |
| 4296 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4297 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4298 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4299 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4300 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4301 | |
Pekka Paalanen | 30aa597 | 2018-05-02 10:21:56 +0200 | [diff] [blame] | 4302 | if (!output) { |
| 4303 | weston_view_set_position(view, 0, 0); |
| 4304 | return; |
| 4305 | } |
| 4306 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4307 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4308 | |
| 4309 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4310 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4311 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4312 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4313 | } |
| 4314 | |
| 4315 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4316 | weston_view_set_initial_position(struct weston_view *view, |
| 4317 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4318 | { |
| 4319 | struct weston_compositor *compositor = shell->compositor; |
| 4320 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4321 | int32_t range_x, range_y; |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4322 | int32_t x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4323 | struct weston_output *output, *target_output = NULL; |
| 4324 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4325 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4326 | |
| 4327 | /* As a heuristic place the new window on the same output as the |
| 4328 | * pointer. Falling back to the output containing 0, 0. |
| 4329 | * |
| 4330 | * TODO: Do something clever for touch too? |
| 4331 | */ |
| 4332 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4333 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 4334 | |
| 4335 | if (pointer) { |
| 4336 | ix = wl_fixed_to_int(pointer->x); |
| 4337 | iy = wl_fixed_to_int(pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4338 | break; |
| 4339 | } |
| 4340 | } |
| 4341 | |
| 4342 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4343 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4344 | target_output = output; |
| 4345 | break; |
| 4346 | } |
| 4347 | } |
| 4348 | |
| 4349 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4350 | weston_view_set_position(view, 10 + random() % 400, |
| 4351 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4352 | return; |
| 4353 | } |
| 4354 | |
| 4355 | /* Valid range within output where the surface will still be onscreen. |
| 4356 | * If this is negative it means that the surface is bigger than |
| 4357 | * output. |
| 4358 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4359 | get_output_work_area(shell, target_output, &area); |
| 4360 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4361 | x = area.x; |
| 4362 | y = area.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4363 | range_x = area.width - view->surface->width; |
| 4364 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4365 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4366 | if (range_x > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4367 | x += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4368 | |
| 4369 | if (range_y > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4370 | y += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4371 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4372 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4373 | } |
| 4374 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 4375 | static bool |
| 4376 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 4377 | { |
| 4378 | struct timespec now; |
| 4379 | |
| 4380 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 4381 | return false; |
| 4382 | |
| 4383 | /* |
| 4384 | * If the shell helper client dies before the session has been |
| 4385 | * up for roughly 30 seconds, better just make Weston shut down, |
| 4386 | * because the user likely has no way to interact with the desktop |
| 4387 | * anyway. |
| 4388 | */ |
| 4389 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 4390 | weston_log("Error: %s apparently cannot run at all.\n", |
| 4391 | shell->client); |
| 4392 | weston_log_continue(STAMP_SPACE "Quitting..."); |
Pekka Paalanen | 052032d | 2019-02-06 10:44:37 +0200 | [diff] [blame] | 4393 | weston_compositor_exit_with_code(shell->compositor, |
| 4394 | EXIT_FAILURE); |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 4395 | |
| 4396 | return true; |
| 4397 | } |
| 4398 | |
| 4399 | return false; |
| 4400 | } |
| 4401 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4402 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4403 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4404 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4405 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4406 | { |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 4407 | struct timespec time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4408 | |
| 4409 | /* 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] | 4410 | weston_compositor_get_time(&time); |
| 4411 | if (timespec_sub_to_msec(&time, &shell->child.deathstamp) > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4412 | shell->child.deathstamp = time; |
| 4413 | shell->child.deathcount = 0; |
| 4414 | } |
| 4415 | |
| 4416 | shell->child.deathcount++; |
| 4417 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4418 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4419 | return; |
| 4420 | } |
| 4421 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4422 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4423 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4424 | } |
| 4425 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4426 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4427 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 4428 | { |
| 4429 | struct desktop_shell *shell; |
| 4430 | |
| 4431 | shell = container_of(listener, struct desktop_shell, |
| 4432 | child.client_destroy_listener); |
| 4433 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4434 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4435 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4436 | /* |
| 4437 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 4438 | * before the respawned process has a chance to create a new |
| 4439 | * desktop_shell object, because we are being called from the |
| 4440 | * wl_client destructor which destroys all wl_resources before |
| 4441 | * returning. |
| 4442 | */ |
| 4443 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 4444 | if (!check_desktop_shell_crash_too_early(shell)) |
| 4445 | respawn_desktop_shell_process(shell); |
| 4446 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4447 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4448 | } |
| 4449 | |
| 4450 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4451 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4452 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4453 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4454 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4455 | shell->child.client = weston_client_start(shell->compositor, |
| 4456 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4457 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 4458 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4459 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 4460 | return; |
| 4461 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4462 | |
| 4463 | shell->child.client_destroy_listener.notify = |
| 4464 | desktop_shell_client_destroy; |
| 4465 | wl_client_add_destroy_listener(shell->child.client, |
| 4466 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4467 | } |
| 4468 | |
| 4469 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4470 | unbind_desktop_shell(struct wl_resource *resource) |
| 4471 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4472 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4473 | |
| 4474 | if (shell->locked) |
| 4475 | resume_desktop(shell); |
| 4476 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4477 | shell->child.desktop_shell = NULL; |
| 4478 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4482 | bind_desktop_shell(struct wl_client *client, |
| 4483 | void *data, uint32_t version, uint32_t id) |
| 4484 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4485 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4486 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4487 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4488 | resource = wl_resource_create(client, &weston_desktop_shell_interface, |
| 4489 | 1, id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4490 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4491 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4492 | wl_resource_set_implementation(resource, |
| 4493 | &desktop_shell_implementation, |
| 4494 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4495 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4496 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4497 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4498 | |
| 4499 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4500 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4501 | } |
| 4502 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4503 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4504 | struct desktop_shell *shell; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4505 | struct weston_view *current; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4506 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4507 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4508 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4509 | }; |
| 4510 | |
| 4511 | static void |
| 4512 | switcher_next(struct switcher *switcher) |
| 4513 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4514 | struct weston_view *view; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4515 | struct weston_view *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4516 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4517 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4518 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4519 | /* temporary re-display minimized surfaces */ |
| 4520 | struct weston_view *tmp; |
| 4521 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4522 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 4523 | weston_layer_entry_remove(&view->layer_link); |
| 4524 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4525 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 4526 | *minimized = view; |
| 4527 | } |
| 4528 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4529 | 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] | 4530 | shsurf = get_shell_surface(view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4531 | if (shsurf) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4532 | if (first == NULL) |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4533 | first = view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4534 | if (prev == switcher->current) |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4535 | next = view; |
| 4536 | prev = view; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4537 | view->alpha = 0.25; |
| 4538 | weston_view_geometry_dirty(view); |
| 4539 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4540 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4541 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 4542 | if (is_black_surface_view(view, NULL)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4543 | view->alpha = 0.25; |
| 4544 | weston_view_geometry_dirty(view); |
| 4545 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4546 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4547 | } |
| 4548 | |
| 4549 | if (next == NULL) |
| 4550 | next = first; |
| 4551 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4552 | if (next == NULL) |
| 4553 | return; |
| 4554 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4555 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4556 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4557 | |
| 4558 | switcher->current = next; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4559 | wl_list_for_each(view, &next->surface->views, surface_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4560 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4561 | |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4562 | shsurf = get_shell_surface(switcher->current->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4563 | if (shsurf && weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4564 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4565 | } |
| 4566 | |
| 4567 | static void |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4568 | switcher_handle_view_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4569 | { |
| 4570 | struct switcher *switcher = |
| 4571 | container_of(listener, struct switcher, listener); |
| 4572 | |
| 4573 | switcher_next(switcher); |
| 4574 | } |
| 4575 | |
| 4576 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4577 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4578 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4579 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4580 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4581 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4582 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4583 | 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] | 4584 | if (is_focus_view(view)) |
| 4585 | continue; |
| 4586 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4587 | view->alpha = 1.0; |
| 4588 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4589 | } |
| 4590 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 4591 | if (switcher->current) { |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 4592 | activate(switcher->shell, switcher->current, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 4593 | keyboard->seat, |
| 4594 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
| 4595 | } |
| 4596 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4597 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4598 | weston_keyboard_end_grab(keyboard); |
| 4599 | if (keyboard->input_method_resource) |
| 4600 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4601 | |
| 4602 | /* re-hide surfaces that were temporary shown during the switch */ |
| 4603 | struct weston_view **minimized; |
| 4604 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 4605 | /* with the exception of the current selected */ |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4606 | if ((*minimized)->surface != switcher->current->surface) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4607 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 4608 | 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] | 4609 | weston_view_damage_below(*minimized); |
| 4610 | } |
| 4611 | } |
| 4612 | wl_array_release(&switcher->minimized_array); |
| 4613 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4614 | free(switcher); |
| 4615 | } |
| 4616 | |
| 4617 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4618 | switcher_key(struct weston_keyboard_grab *grab, |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4619 | const struct timespec *time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4620 | { |
| 4621 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4622 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4623 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4624 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4625 | switcher_next(switcher); |
| 4626 | } |
| 4627 | |
| 4628 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4629 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4630 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4631 | uint32_t mods_locked, uint32_t group) |
| 4632 | { |
| 4633 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4634 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4635 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4636 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 4637 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 4638 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4639 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4640 | static void |
| 4641 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 4642 | { |
| 4643 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 4644 | |
| 4645 | switcher_destroy(switcher); |
| 4646 | } |
| 4647 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4648 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4649 | switcher_key, |
| 4650 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4651 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4652 | }; |
| 4653 | |
| 4654 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4655 | switcher_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4656 | uint32_t key, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4657 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4658 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4659 | struct switcher *switcher; |
| 4660 | |
| 4661 | switcher = malloc(sizeof *switcher); |
ganjing | c1e7151 | 2020-07-28 15:28:45 +0800 | [diff] [blame] | 4662 | if (!switcher) |
| 4663 | return; |
Pekka Paalanen | 4bb326b | 2021-05-14 14:37:46 +0300 | [diff] [blame] | 4664 | |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4665 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4666 | switcher->current = NULL; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4667 | switcher->listener.notify = switcher_handle_view_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4668 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4669 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4670 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 4671 | lower_fullscreen_layer(switcher->shell, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4672 | switcher->grab.interface = &switcher_grab; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4673 | weston_keyboard_start_grab(keyboard, &switcher->grab); |
| 4674 | weston_keyboard_set_focus(keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4675 | switcher_next(switcher); |
| 4676 | } |
| 4677 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4678 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4679 | backlight_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4680 | uint32_t key, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4681 | { |
| 4682 | struct weston_compositor *compositor = data; |
| 4683 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4684 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4685 | |
| 4686 | /* TODO: we're limiting to simple use cases, where we assume just |
| 4687 | * control on the primary display. We'd have to extend later if we |
| 4688 | * ever get support for setting backlights on random desktop LCD |
| 4689 | * panels though */ |
| 4690 | output = get_default_output(compositor); |
| 4691 | if (!output) |
| 4692 | return; |
| 4693 | |
| 4694 | if (!output->set_backlight) |
| 4695 | return; |
| 4696 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4697 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 4698 | backlight_new = output->backlight_current - 25; |
| 4699 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 4700 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4701 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4702 | if (backlight_new < 5) |
| 4703 | backlight_new = 5; |
| 4704 | if (backlight_new > 255) |
| 4705 | backlight_new = 255; |
| 4706 | |
| 4707 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4708 | output->set_backlight(output, output->backlight_current); |
| 4709 | } |
| 4710 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 4711 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4712 | force_kill_binding(struct weston_keyboard *keyboard, |
| 4713 | const struct timespec *time, uint32_t key, void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4714 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 4715 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4716 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 4717 | struct desktop_shell *shell = data; |
| 4718 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4719 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4720 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4721 | focus_surface = keyboard->focus; |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 4722 | if (!focus_surface) |
| 4723 | return; |
| 4724 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 4725 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 4726 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4727 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 4728 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 4729 | |
| 4730 | /* Skip clients that we launched ourselves (the credentials of |
| 4731 | * the socketpair is ours) */ |
| 4732 | if (pid == getpid()) |
| 4733 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4734 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4735 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4739 | workspace_up_binding(struct weston_keyboard *keyboard, |
| 4740 | const struct timespec *time, uint32_t key, void *data) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4741 | { |
| 4742 | struct desktop_shell *shell = data; |
| 4743 | unsigned int new_index = shell->workspaces.current; |
| 4744 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4745 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4746 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4747 | if (new_index != 0) |
| 4748 | new_index--; |
| 4749 | |
| 4750 | change_workspace(shell, new_index); |
| 4751 | } |
| 4752 | |
| 4753 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4754 | workspace_down_binding(struct weston_keyboard *keyboard, |
| 4755 | const struct timespec *time, uint32_t key, void *data) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4756 | { |
| 4757 | struct desktop_shell *shell = data; |
| 4758 | unsigned int new_index = shell->workspaces.current; |
| 4759 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4760 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4761 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4762 | if (new_index < shell->workspaces.num - 1) |
| 4763 | new_index++; |
| 4764 | |
| 4765 | change_workspace(shell, new_index); |
| 4766 | } |
| 4767 | |
| 4768 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4769 | workspace_f_binding(struct weston_keyboard *keyboard, |
| 4770 | const struct timespec *time, uint32_t key, void *data) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4771 | { |
| 4772 | struct desktop_shell *shell = data; |
| 4773 | unsigned int new_index; |
| 4774 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4775 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4776 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4777 | new_index = key - KEY_F1; |
| 4778 | if (new_index >= shell->workspaces.num) |
| 4779 | new_index = shell->workspaces.num - 1; |
| 4780 | |
| 4781 | change_workspace(shell, new_index); |
| 4782 | } |
| 4783 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4784 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4785 | workspace_move_surface_up_binding(struct weston_keyboard *keyboard, |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4786 | const struct timespec *time, uint32_t key, |
| 4787 | void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4788 | { |
| 4789 | struct desktop_shell *shell = data; |
| 4790 | unsigned int new_index = shell->workspaces.current; |
| 4791 | |
| 4792 | if (shell->locked) |
| 4793 | return; |
| 4794 | |
| 4795 | if (new_index != 0) |
| 4796 | new_index--; |
| 4797 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4798 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4802 | workspace_move_surface_down_binding(struct weston_keyboard *keyboard, |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4803 | const struct timespec *time, uint32_t key, |
| 4804 | void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4805 | { |
| 4806 | struct desktop_shell *shell = data; |
| 4807 | unsigned int new_index = shell->workspaces.current; |
| 4808 | |
| 4809 | if (shell->locked) |
| 4810 | return; |
| 4811 | |
| 4812 | if (new_index < shell->workspaces.num - 1) |
| 4813 | new_index++; |
| 4814 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4815 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4816 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4817 | |
| 4818 | static void |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4819 | shell_reposition_view_on_output_change(struct weston_view *view) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4820 | { |
| 4821 | struct weston_output *output, *first_output; |
| 4822 | struct weston_compositor *ec = view->surface->compositor; |
| 4823 | struct shell_surface *shsurf; |
| 4824 | float x, y; |
| 4825 | int visible; |
| 4826 | |
Harish Krupo | 2dff4dd | 2019-04-20 18:10:56 +0530 | [diff] [blame] | 4827 | if (wl_list_empty(&ec->output_list)) |
| 4828 | return; |
| 4829 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4830 | x = view->geometry.x; |
| 4831 | y = view->geometry.y; |
| 4832 | |
| 4833 | /* At this point the destroyed output is not in the list anymore. |
| 4834 | * If the view is still visible somewhere, we leave where it is, |
| 4835 | * otherwise, move it to the first output. */ |
| 4836 | visible = 0; |
| 4837 | wl_list_for_each(output, &ec->output_list, link) { |
| 4838 | if (pixman_region32_contains_point(&output->region, |
| 4839 | x, y, NULL)) { |
| 4840 | visible = 1; |
| 4841 | break; |
| 4842 | } |
| 4843 | } |
| 4844 | |
| 4845 | if (!visible) { |
| 4846 | first_output = container_of(ec->output_list.next, |
| 4847 | struct weston_output, link); |
| 4848 | |
| 4849 | x = first_output->x + first_output->width / 4; |
| 4850 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 4851 | |
| 4852 | weston_view_set_position(view, x, y); |
| 4853 | } else { |
| 4854 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4855 | } |
| 4856 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4857 | |
| 4858 | shsurf = get_shell_surface(view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4859 | if (!shsurf) |
| 4860 | return; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4861 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4862 | shsurf->saved_position_valid = false; |
| 4863 | set_maximized(shsurf, false); |
| 4864 | set_fullscreen(shsurf, false, NULL); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4865 | } |
| 4866 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4867 | void |
| 4868 | shell_for_each_layer(struct desktop_shell *shell, |
| 4869 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4870 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4871 | struct workspace **ws; |
| 4872 | |
| 4873 | func(shell, &shell->fullscreen_layer, data); |
| 4874 | func(shell, &shell->panel_layer, data); |
| 4875 | func(shell, &shell->background_layer, data); |
| 4876 | func(shell, &shell->lock_layer, data); |
| 4877 | func(shell, &shell->input_panel_layer, data); |
| 4878 | |
| 4879 | wl_array_for_each(ws, &shell->workspaces.array) |
| 4880 | func(shell, &(*ws)->layer, data); |
| 4881 | } |
| 4882 | |
| 4883 | static void |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4884 | shell_output_changed_move_layer(struct desktop_shell *shell, |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4885 | struct weston_layer *layer, |
| 4886 | void *data) |
| 4887 | { |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4888 | struct weston_view *view; |
| 4889 | |
Marius Vlad | ea40d6d | 2018-02-08 18:46:42 +0200 | [diff] [blame] | 4890 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4891 | shell_reposition_view_on_output_change(view); |
| 4892 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4893 | } |
| 4894 | |
| 4895 | static void |
Pekka Paalanen | 719ca87 | 2021-05-24 16:53:40 +0300 | [diff] [blame] | 4896 | shell_output_destroy(struct shell_output *shell_output) |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4897 | { |
Pekka Paalanen | 0d5e4ff | 2021-05-24 16:13:21 +0300 | [diff] [blame] | 4898 | struct desktop_shell *shell = shell_output->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4899 | |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4900 | 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] | 4901 | |
Pekka Paalanen | 719ca87 | 2021-05-24 16:53:40 +0300 | [diff] [blame] | 4902 | if (shell_output->fade.animation) { |
| 4903 | weston_view_animation_destroy(shell_output->fade.animation); |
| 4904 | shell_output->fade.animation = NULL; |
| 4905 | } |
| 4906 | |
| 4907 | if (shell_output->fade.view) { |
| 4908 | /* destroys the view as well */ |
| 4909 | weston_surface_destroy(shell_output->fade.view->surface); |
| 4910 | } |
| 4911 | |
| 4912 | if (shell_output->fade.startup_timer) |
| 4913 | wl_event_source_remove(shell_output->fade.startup_timer); |
| 4914 | |
Pekka Paalanen | 0d5e4ff | 2021-05-24 16:13:21 +0300 | [diff] [blame] | 4915 | if (shell_output->panel_surface) |
| 4916 | wl_list_remove(&shell_output->panel_surface_listener.link); |
| 4917 | if (shell_output->background_surface) |
| 4918 | wl_list_remove(&shell_output->background_surface_listener.link); |
| 4919 | wl_list_remove(&shell_output->destroy_listener.link); |
| 4920 | wl_list_remove(&shell_output->link); |
| 4921 | free(shell_output); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4922 | } |
| 4923 | |
| 4924 | static void |
Pekka Paalanen | 719ca87 | 2021-05-24 16:53:40 +0300 | [diff] [blame] | 4925 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 4926 | { |
| 4927 | struct shell_output *shell_output = |
| 4928 | container_of(listener, struct shell_output, destroy_listener); |
| 4929 | |
| 4930 | shell_output_destroy(shell_output); |
| 4931 | } |
| 4932 | |
| 4933 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4934 | shell_resize_surface_to_output(struct desktop_shell *shell, |
| 4935 | struct weston_surface *surface, |
| 4936 | const struct weston_output *output) |
| 4937 | { |
| 4938 | if (!surface) |
| 4939 | return; |
| 4940 | |
| 4941 | weston_desktop_shell_send_configure(shell->child.desktop_shell, 0, |
| 4942 | surface->resource, |
| 4943 | output->width, |
| 4944 | output->height); |
| 4945 | } |
| 4946 | |
| 4947 | |
| 4948 | static void |
| 4949 | handle_output_resized(struct wl_listener *listener, void *data) |
| 4950 | { |
| 4951 | struct desktop_shell *shell = |
| 4952 | container_of(listener, struct desktop_shell, resized_listener); |
| 4953 | struct weston_output *output = (struct weston_output *)data; |
| 4954 | struct shell_output *sh_output = find_shell_output_from_weston_output(shell, output); |
| 4955 | |
| 4956 | shell_resize_surface_to_output(shell, sh_output->background_surface, output); |
| 4957 | shell_resize_surface_to_output(shell, sh_output->panel_surface, output); |
| 4958 | } |
| 4959 | |
| 4960 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4961 | create_shell_output(struct desktop_shell *shell, |
| 4962 | struct weston_output *output) |
| 4963 | { |
| 4964 | struct shell_output *shell_output; |
| 4965 | |
| 4966 | shell_output = zalloc(sizeof *shell_output); |
| 4967 | if (shell_output == NULL) |
| 4968 | return; |
| 4969 | |
| 4970 | shell_output->output = output; |
| 4971 | shell_output->shell = shell; |
| 4972 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 4973 | wl_signal_add(&output->destroy_signal, |
| 4974 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 4975 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4976 | |
| 4977 | if (wl_list_length(&shell->output_list) == 1) |
| 4978 | shell_for_each_layer(shell, |
| 4979 | shell_output_changed_move_layer, NULL); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4980 | } |
| 4981 | |
| 4982 | static void |
| 4983 | handle_output_create(struct wl_listener *listener, void *data) |
| 4984 | { |
| 4985 | struct desktop_shell *shell = |
| 4986 | container_of(listener, struct desktop_shell, output_create_listener); |
| 4987 | struct weston_output *output = (struct weston_output *)data; |
| 4988 | |
| 4989 | create_shell_output(shell, output); |
| 4990 | } |
| 4991 | |
| 4992 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4993 | handle_output_move_layer(struct desktop_shell *shell, |
| 4994 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4995 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4996 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4997 | struct weston_view *view; |
| 4998 | float x, y; |
| 4999 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 5000 | 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] | 5001 | if (view->output != output) |
| 5002 | continue; |
| 5003 | |
| 5004 | x = view->geometry.x + output->move_x; |
| 5005 | y = view->geometry.y + output->move_y; |
| 5006 | weston_view_set_position(view, x, y); |
| 5007 | } |
| 5008 | } |
| 5009 | |
| 5010 | static void |
| 5011 | handle_output_move(struct wl_listener *listener, void *data) |
| 5012 | { |
| 5013 | struct desktop_shell *shell; |
| 5014 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5015 | shell = container_of(listener, struct desktop_shell, |
| 5016 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5017 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 5018 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5019 | } |
| 5020 | |
| 5021 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5022 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5023 | struct desktop_shell *shell) |
| 5024 | { |
| 5025 | struct weston_output *output; |
| 5026 | |
| 5027 | wl_list_init(&shell->output_list); |
| 5028 | wl_list_for_each(output, &ec->output_list, link) |
| 5029 | create_shell_output(shell, output); |
| 5030 | |
| 5031 | shell->output_create_listener.notify = handle_output_create; |
| 5032 | wl_signal_add(&ec->output_created_signal, |
| 5033 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5034 | |
| 5035 | shell->output_move_listener.notify = handle_output_move; |
| 5036 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5040 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5041 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5042 | struct desktop_shell *shell = |
| 5043 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5044 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5045 | struct shell_output *shell_output, *tmp; |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 5046 | struct shell_seat *shseat, *shseat_next; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5047 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 5048 | /* Force state to unlocked so we don't try to fade */ |
| 5049 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5050 | |
| 5051 | if (shell->child.client) { |
| 5052 | /* disable respawn */ |
| 5053 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5054 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5055 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5056 | |
Harsha M M | b8b2c72 | 2018-08-07 19:05:02 +0530 | [diff] [blame] | 5057 | wl_list_remove(&shell->destroy_listener.link); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5058 | wl_list_remove(&shell->idle_listener.link); |
| 5059 | wl_list_remove(&shell->wake_listener.link); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 5060 | wl_list_remove(&shell->transform_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5061 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 5062 | text_backend_destroy(shell->text_backend); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5063 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5064 | |
Pekka Paalanen | 719ca87 | 2021-05-24 16:53:40 +0300 | [diff] [blame] | 5065 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) |
| 5066 | shell_output_destroy(shell_output); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5067 | |
| 5068 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 5069 | wl_list_remove(&shell->output_move_listener.link); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 5070 | wl_list_remove(&shell->resized_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5071 | |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 5072 | wl_list_for_each_safe(shseat, shseat_next, &shell->seat_list, link) |
| 5073 | desktop_shell_destroy_seat(shseat); |
| 5074 | |
Pekka Paalanen | abd7292 | 2021-05-24 14:42:00 +0300 | [diff] [blame] | 5075 | weston_desktop_destroy(shell->desktop); |
| 5076 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5077 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5078 | workspace_destroy(*ws); |
| 5079 | wl_array_release(&shell->workspaces.array); |
| 5080 | |
Pekka Paalanen | 4bb326b | 2021-05-14 14:37:46 +0300 | [diff] [blame] | 5081 | weston_layer_fini(&shell->fullscreen_layer); |
| 5082 | weston_layer_fini(&shell->panel_layer); |
| 5083 | weston_layer_fini(&shell->background_layer); |
| 5084 | weston_layer_fini(&shell->lock_layer); |
| 5085 | weston_layer_fini(&shell->input_panel_layer); |
| 5086 | weston_layer_fini(&shell->minimized_layer); |
| 5087 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5088 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5089 | free(shell); |
| 5090 | } |
| 5091 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5092 | static void |
| 5093 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5094 | { |
| 5095 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5096 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5097 | |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 5098 | if (shell->allow_zap) |
| 5099 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5100 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5101 | terminate_binding, ec); |
| 5102 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5103 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5104 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5105 | click_to_activate_binding, |
| 5106 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 5107 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 5108 | click_to_activate_binding, |
| 5109 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5110 | weston_compositor_add_touch_binding(ec, 0, |
| 5111 | touch_to_activate_binding, |
| 5112 | shell); |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 5113 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 5114 | backlight_binding, ec); |
| 5115 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 5116 | backlight_binding, ec); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5117 | |
| 5118 | /* configurable bindings */ |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 5119 | if (shell->exposay_modifier) |
| 5120 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 5121 | exposay_binding, shell); |
| 5122 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5123 | mod = shell->binding_modifier; |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 5124 | if (!mod) |
| 5125 | return; |
| 5126 | |
Ian Ray | 13404c4 | 2017-09-18 15:22:01 +0300 | [diff] [blame] | 5127 | /* This binding is not configurable, but is only enabled if there is a |
| 5128 | * valid binding modifier. */ |
| 5129 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5130 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5131 | surface_opacity_binding, NULL); |
| 5132 | |
Ian Ray | ab7c0b6 | 2017-09-18 15:22:00 +0300 | [diff] [blame] | 5133 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5134 | mod, zoom_axis_binding, |
| 5135 | NULL); |
| 5136 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5137 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5138 | zoom_key_binding, NULL); |
| 5139 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5140 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 5141 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 5142 | maximize_binding, NULL); |
| 5143 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 5144 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5145 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5146 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5147 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 5148 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5149 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 5150 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 5151 | mod | MODIFIER_SHIFT, |
| 5152 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5153 | |
| 5154 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 5155 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5156 | rotate_binding, NULL); |
| 5157 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5158 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5159 | shell); |
| 5160 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 5161 | ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5162 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 5163 | ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5164 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 5165 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5166 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 5167 | workspace_up_binding, shell); |
| 5168 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 5169 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5170 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 5171 | workspace_move_surface_up_binding, |
| 5172 | shell); |
| 5173 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 5174 | workspace_move_surface_down_binding, |
| 5175 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5176 | |
| 5177 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5178 | if (shell->workspaces.num > 1) { |
| 5179 | num_workspace_bindings = shell->workspaces.num; |
| 5180 | if (num_workspace_bindings > 6) |
| 5181 | num_workspace_bindings = 6; |
| 5182 | for (i = 0; i < num_workspace_bindings; i++) |
| 5183 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5184 | workspace_f_binding, |
| 5185 | shell); |
| 5186 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5187 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 5188 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5189 | } |
| 5190 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 5191 | static void |
| 5192 | handle_seat_created(struct wl_listener *listener, void *data) |
| 5193 | { |
| 5194 | struct weston_seat *seat = data; |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 5195 | struct desktop_shell *shell = |
| 5196 | container_of(listener, struct desktop_shell, seat_create_listener); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 5197 | |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 5198 | create_shell_seat(shell, seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 5199 | } |
| 5200 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5201 | WL_EXPORT int |
Quentin Glidic | da01c1d | 2016-12-02 14:17:08 +0100 | [diff] [blame] | 5202 | wet_shell_init(struct weston_compositor *ec, |
| 5203 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5204 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5205 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5206 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5207 | struct workspace **pws; |
| 5208 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5209 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5210 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 5211 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5212 | if (shell == NULL) |
| 5213 | return -1; |
| 5214 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5215 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5216 | |
Pekka Paalanen | 6ffbba3 | 2019-11-06 12:59:32 +0200 | [diff] [blame] | 5217 | if (!weston_compositor_add_destroy_listener_once(ec, |
| 5218 | &shell->destroy_listener, |
| 5219 | shell_destroy)) { |
| 5220 | free(shell); |
| 5221 | return 0; |
| 5222 | } |
| 5223 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5224 | shell->idle_listener.notify = idle_handler; |
| 5225 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 5226 | shell->wake_listener.notify = wake_handler; |
| 5227 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 5228 | shell->transform_listener.notify = transform_handler; |
| 5229 | wl_signal_add(&ec->transform_signal, &shell->transform_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5230 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 5231 | weston_layer_init(&shell->fullscreen_layer, ec); |
| 5232 | weston_layer_init(&shell->panel_layer, ec); |
| 5233 | weston_layer_init(&shell->background_layer, ec); |
| 5234 | weston_layer_init(&shell->lock_layer, ec); |
| 5235 | weston_layer_init(&shell->input_panel_layer, ec); |
| 5236 | |
| 5237 | weston_layer_set_position(&shell->fullscreen_layer, |
| 5238 | WESTON_LAYER_POSITION_FULLSCREEN); |
| 5239 | weston_layer_set_position(&shell->panel_layer, |
| 5240 | WESTON_LAYER_POSITION_UI); |
| 5241 | weston_layer_set_position(&shell->background_layer, |
| 5242 | WESTON_LAYER_POSITION_BACKGROUND); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5243 | |
| 5244 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5245 | wl_list_init(&shell->workspaces.client_list); |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 5246 | wl_list_init(&shell->seat_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5247 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5248 | if (input_panel_setup(shell) < 0) |
| 5249 | return -1; |
| 5250 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 5251 | shell->text_backend = text_backend_init(ec); |
| 5252 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 5253 | return -1; |
| 5254 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5255 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 5256 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5257 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 5258 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 5259 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5260 | for (i = 0; i < shell->workspaces.num; i++) { |
| 5261 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 5262 | if (pws == NULL) |
| 5263 | return -1; |
| 5264 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 5265 | *pws = workspace_create(shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5266 | if (*pws == NULL) |
| 5267 | return -1; |
| 5268 | } |
| 5269 | activate_workspace(shell, 0); |
| 5270 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 5271 | weston_layer_init(&shell->minimized_layer, ec); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 5272 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5273 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 5274 | wl_list_init(&shell->workspaces.animation.link); |
| 5275 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 5276 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 5277 | shell->desktop = weston_desktop_create(ec, &shell_desktop_api, shell); |
| 5278 | if (!shell->desktop) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5279 | return -1; |
| 5280 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5281 | if (wl_global_create(ec->wl_display, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5282 | &weston_desktop_shell_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5283 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5284 | return -1; |
| 5285 | |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 5286 | weston_compositor_get_time(&shell->child.deathstamp); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5287 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5288 | shell->panel_position = WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP; |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 5289 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5290 | setup_output_destroy_handler(ec, shell); |
| 5291 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5292 | loop = wl_display_get_event_loop(ec->wl_display); |
| 5293 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5294 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 5295 | wl_list_for_each(seat, &ec->seat_list, link) |
Marius Vlad | c114fd6 | 2021-08-26 16:37:24 +0300 | [diff] [blame] | 5296 | create_shell_seat(shell, seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 5297 | shell->seat_create_listener.notify = handle_seat_created; |
| 5298 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 5299 | |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 5300 | shell->resized_listener.notify = handle_output_resized; |
| 5301 | wl_signal_add(&ec->output_resized_signal, &shell->resized_listener); |
| 5302 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 5303 | screenshooter_create(ec); |
| 5304 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5305 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5306 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5307 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5308 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5309 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 5310 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5311 | return 0; |
| 5312 | } |