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; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 191 | }; |
| 192 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 193 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 194 | static struct desktop_shell * |
| 195 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 196 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 197 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 198 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 199 | |
| 200 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 201 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 202 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 203 | static void |
| 204 | shell_fade_startup(struct desktop_shell *shell); |
| 205 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 206 | static void |
| 207 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 208 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 209 | static struct shell_seat * |
| 210 | get_shell_seat(struct weston_seat *seat); |
| 211 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 212 | static void |
| 213 | get_output_panel_size(struct desktop_shell *shell, |
| 214 | struct weston_output *output, |
| 215 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 216 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 217 | static void |
| 218 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 219 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 220 | static int |
| 221 | shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 222 | { |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 223 | const char *t, *c; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 224 | struct weston_desktop_surface *desktop_surface = |
| 225 | weston_surface_get_desktop_surface(surface); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 226 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 227 | t = weston_desktop_surface_get_title(desktop_surface); |
| 228 | c = weston_desktop_surface_get_app_id(desktop_surface); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 229 | |
| 230 | return snprintf(buf, len, "%s window%s%s%s%s%s", |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 231 | "top-level", |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 232 | t ? " '" : "", t ?: "", t ? "'" : "", |
| 233 | c ? " of " : "", c ?: ""); |
| 234 | } |
| 235 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 236 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 237 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 238 | { |
| 239 | struct shell_grab *grab; |
| 240 | |
| 241 | grab = container_of(listener, struct shell_grab, |
| 242 | shsurf_destroy_listener); |
| 243 | |
| 244 | grab->shsurf = NULL; |
| 245 | } |
| 246 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 247 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 248 | get_default_view(struct weston_surface *surface) |
| 249 | { |
| 250 | struct shell_surface *shsurf; |
| 251 | struct weston_view *view; |
| 252 | |
| 253 | if (!surface || wl_list_empty(&surface->views)) |
| 254 | return NULL; |
| 255 | |
| 256 | shsurf = get_shell_surface(surface); |
| 257 | if (shsurf) |
| 258 | return shsurf->view; |
| 259 | |
| 260 | wl_list_for_each(view, &surface->views, surface_link) |
| 261 | if (weston_view_is_mapped(view)) |
| 262 | return view; |
| 263 | |
| 264 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 265 | } |
| 266 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 267 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 268 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 269 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 270 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 271 | struct weston_pointer *pointer, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 272 | enum weston_desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 273 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 274 | struct desktop_shell *shell = shsurf->shell; |
| 275 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 276 | weston_seat_break_desktop_grabs(pointer->seat); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 277 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 278 | grab->grab.interface = interface; |
| 279 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 280 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 281 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 282 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 283 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 284 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 285 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 286 | if (shell->child.desktop_shell) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 287 | weston_desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 288 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 289 | weston_pointer_set_focus(pointer, |
| 290 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 291 | wl_fixed_from_int(0), |
| 292 | wl_fixed_from_int(0)); |
| 293 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 294 | } |
| 295 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 296 | static void |
Quentin Glidic | 581df06 | 2016-06-23 18:55:19 +0200 | [diff] [blame] | 297 | get_panel_size(struct desktop_shell *shell, |
| 298 | struct weston_view *view, |
| 299 | int *width, |
| 300 | int *height) |
| 301 | { |
| 302 | float x1, y1; |
| 303 | float x2, y2; |
| 304 | weston_view_to_global_float(view, 0, 0, &x1, &y1); |
| 305 | weston_view_to_global_float(view, |
| 306 | view->surface->width, |
| 307 | view->surface->height, |
| 308 | &x2, &y2); |
| 309 | *width = (int)(x2 - x1); |
| 310 | *height = (int)(y2 - y1); |
| 311 | } |
| 312 | |
| 313 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 314 | get_output_panel_size(struct desktop_shell *shell, |
| 315 | struct weston_output *output, |
| 316 | int *width, |
| 317 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 318 | { |
| 319 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 320 | |
| 321 | *width = 0; |
| 322 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 323 | |
| 324 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 325 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 326 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 327 | 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] | 328 | if (view->surface->output == output) { |
| 329 | get_panel_size(shell, view, width, height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 330 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 334 | /* the correct view wasn't found */ |
| 335 | } |
| 336 | |
Leandro Ribeiro | 0c59e92 | 2020-01-24 17:53:44 -0300 | [diff] [blame] | 337 | void |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 338 | get_output_work_area(struct desktop_shell *shell, |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 339 | struct weston_output *output, |
| 340 | pixman_rectangle32_t *area) |
| 341 | { |
| 342 | int32_t panel_width = 0, panel_height = 0; |
| 343 | |
Pekka Paalanen | 99372ba | 2018-05-02 10:21:55 +0200 | [diff] [blame] | 344 | if (!output) { |
| 345 | area->x = 0; |
| 346 | area->y = 0; |
| 347 | area->width = 0; |
| 348 | area->height = 0; |
| 349 | |
| 350 | return; |
| 351 | } |
| 352 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 353 | area->x = output->x; |
| 354 | area->y = output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 355 | |
| 356 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 357 | switch (shell->panel_position) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 358 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 359 | default: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 360 | area->y += panel_height; |
Daniel Stone | 2ef9b1a | 2017-03-13 16:31:36 +0000 | [diff] [blame] | 361 | /* fallthrough */ |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 362 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 363 | area->width = output->width; |
| 364 | area->height = output->height - panel_height; |
| 365 | break; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 366 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 367 | area->x += panel_width; |
Daniel Stone | 2ef9b1a | 2017-03-13 16:31:36 +0000 | [diff] [blame] | 368 | /* fallthrough */ |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 369 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 370 | area->width = output->width - panel_width; |
| 371 | area->height = output->height; |
| 372 | break; |
| 373 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 376 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 377 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 378 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 379 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 380 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 381 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 382 | |
| 383 | if (grab->shsurf->resize_edges) { |
| 384 | grab->shsurf->resize_edges = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 385 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 386 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 387 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 388 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 392 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 393 | const struct weston_touch_grab_interface *interface, |
| 394 | struct shell_surface *shsurf, |
| 395 | struct weston_touch *touch) |
| 396 | { |
| 397 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 398 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 399 | weston_seat_break_desktop_grabs(touch->seat); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 400 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 401 | grab->grab.interface = interface; |
| 402 | grab->shsurf = shsurf; |
| 403 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 404 | wl_signal_add(&shsurf->destroy_signal, |
| 405 | &grab->shsurf_destroy_listener); |
| 406 | |
| 407 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 408 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 409 | |
| 410 | weston_touch_start_grab(touch, &grab->grab); |
| 411 | if (shell->child.desktop_shell) |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 412 | weston_touch_set_focus(touch, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 413 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | static void |
| 417 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 418 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 419 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 420 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 421 | grab->shsurf->grabbed = 0; |
| 422 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 423 | |
| 424 | weston_touch_end_grab(grab->touch); |
| 425 | } |
| 426 | |
| 427 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 428 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 429 | struct weston_output *output); |
| 430 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 431 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 432 | get_modifier(char *modifier) |
| 433 | { |
| 434 | if (!modifier) |
| 435 | return MODIFIER_SUPER; |
| 436 | |
| 437 | if (!strcmp("ctrl", modifier)) |
| 438 | return MODIFIER_CTRL; |
| 439 | else if (!strcmp("alt", modifier)) |
| 440 | return MODIFIER_ALT; |
| 441 | else if (!strcmp("super", modifier)) |
| 442 | return MODIFIER_SUPER; |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 443 | else if (!strcmp("none", modifier)) |
| 444 | return 0; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 445 | else |
| 446 | return MODIFIER_SUPER; |
| 447 | } |
| 448 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 449 | static enum animation_type |
| 450 | get_animation_type(char *animation) |
| 451 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 452 | if (!animation) |
| 453 | return ANIMATION_NONE; |
| 454 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 455 | if (!strcmp("zoom", animation)) |
| 456 | return ANIMATION_ZOOM; |
| 457 | else if (!strcmp("fade", animation)) |
| 458 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 459 | else if (!strcmp("dim-layer", animation)) |
| 460 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 461 | else |
| 462 | return ANIMATION_NONE; |
| 463 | } |
| 464 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 465 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 466 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 467 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 468 | struct weston_config_section *section; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 469 | char *s, *client; |
Daniel Stone | 51d995a | 2019-11-26 00:14:24 +0000 | [diff] [blame] | 470 | bool allow_zap; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 471 | |
Giulio Camuffo | d52f3b7 | 2016-06-02 21:48:11 +0300 | [diff] [blame] | 472 | section = weston_config_get_section(wet_get_config(shell->compositor), |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 473 | "shell", NULL, NULL); |
Marius Vlad | 64fbd0f | 2018-12-15 15:51:57 +0200 | [diff] [blame] | 474 | client = wet_get_libexec_path(WESTON_SHELL_CLIENT); |
Daniel Stone | e03c111 | 2016-11-24 20:45:45 +0000 | [diff] [blame] | 475 | weston_config_section_get_string(section, "client", &s, client); |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 476 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 477 | shell->client = s; |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 478 | |
| 479 | weston_config_section_get_bool(section, |
| 480 | "allow-zap", &allow_zap, true); |
| 481 | shell->allow_zap = allow_zap; |
| 482 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 483 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 484 | "binding-modifier", &s, "super"); |
| 485 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 486 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 487 | |
| 488 | weston_config_section_get_string(section, |
| 489 | "exposay-modifier", &s, "none"); |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 490 | shell->exposay_modifier = get_modifier(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 491 | free(s); |
| 492 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 493 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 494 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 495 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 496 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 497 | shell->win_close_animation_type = get_animation_type(s); |
| 498 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 499 | weston_config_section_get_string(section, |
| 500 | "startup-animation", &s, "fade"); |
| 501 | shell->startup_animation_type = get_animation_type(s); |
| 502 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 503 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 504 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 505 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 506 | shell->focus_animation_type = get_animation_type(s); |
| 507 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 508 | weston_config_section_get_uint(section, "num-workspaces", |
| 509 | &shell->workspaces.num, |
| 510 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 511 | } |
| 512 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 513 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 514 | get_default_output(struct weston_compositor *compositor) |
| 515 | { |
Armin Krezović | 10b0618 | 2016-06-23 11:59:30 +0200 | [diff] [blame] | 516 | if (wl_list_empty(&compositor->output_list)) |
| 517 | return NULL; |
| 518 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 519 | return container_of(compositor->output_list.next, |
| 520 | struct weston_output, link); |
| 521 | } |
| 522 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 523 | static int |
| 524 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 525 | { |
| 526 | return snprintf(buf, len, "focus highlight effect for output %s", |
Miguel A. Vico | 620f68d | 2019-09-25 11:23:13 -0700 | [diff] [blame] | 527 | (surface->output ? surface->output->name : "NULL")); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 528 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 529 | |
| 530 | /* no-op func for checking focus surface */ |
| 531 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 532 | 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] | 533 | { |
| 534 | } |
| 535 | |
| 536 | static struct focus_surface * |
| 537 | get_focus_surface(struct weston_surface *surface) |
| 538 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 539 | if (surface->committed == focus_surface_committed) |
| 540 | return surface->committed_private; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 541 | else |
| 542 | return NULL; |
| 543 | } |
| 544 | |
| 545 | static bool |
| 546 | is_focus_surface (struct weston_surface *es) |
| 547 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 548 | return (es->committed == focus_surface_committed); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static bool |
| 552 | is_focus_view (struct weston_view *view) |
| 553 | { |
| 554 | return is_focus_surface (view->surface); |
| 555 | } |
| 556 | |
| 557 | static struct focus_surface * |
| 558 | create_focus_surface(struct weston_compositor *ec, |
| 559 | struct weston_output *output) |
| 560 | { |
| 561 | struct focus_surface *fsurf = NULL; |
| 562 | struct weston_surface *surface = NULL; |
| 563 | |
| 564 | fsurf = malloc(sizeof *fsurf); |
| 565 | if (!fsurf) |
| 566 | return NULL; |
| 567 | |
| 568 | fsurf->surface = weston_surface_create(ec); |
| 569 | surface = fsurf->surface; |
| 570 | if (surface == NULL) { |
| 571 | free(fsurf); |
| 572 | return NULL; |
| 573 | } |
| 574 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 575 | surface->committed = focus_surface_committed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 576 | surface->output = output; |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 577 | surface->is_mapped = true; |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 578 | surface->committed_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 579 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 580 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 581 | fsurf->view = weston_view_create(surface); |
| 582 | if (fsurf->view == NULL) { |
| 583 | weston_surface_destroy(surface); |
| 584 | free(fsurf); |
| 585 | return NULL; |
| 586 | } |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 587 | weston_view_set_output(fsurf->view, output); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 588 | fsurf->view->is_mapped = true; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 589 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 590 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 591 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 592 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 593 | pixman_region32_fini(&surface->opaque); |
| 594 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 595 | output->width, output->height); |
| 596 | pixman_region32_fini(&surface->input); |
| 597 | pixman_region32_init(&surface->input); |
| 598 | |
| 599 | wl_list_init(&fsurf->workspace_transform.link); |
| 600 | |
| 601 | return fsurf; |
| 602 | } |
| 603 | |
| 604 | static void |
| 605 | focus_surface_destroy(struct focus_surface *fsurf) |
| 606 | { |
| 607 | weston_surface_destroy(fsurf->surface); |
| 608 | free(fsurf); |
| 609 | } |
| 610 | |
| 611 | static void |
| 612 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 613 | { |
| 614 | struct workspace *ws = data; |
| 615 | |
| 616 | ws->focus_animation = NULL; |
| 617 | } |
| 618 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 619 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 620 | focus_state_destroy(struct focus_state *state) |
| 621 | { |
| 622 | wl_list_remove(&state->seat_destroy_listener.link); |
| 623 | wl_list_remove(&state->surface_destroy_listener.link); |
| 624 | free(state); |
| 625 | } |
| 626 | |
| 627 | static void |
| 628 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 629 | { |
| 630 | struct focus_state *state = container_of(listener, |
| 631 | struct focus_state, |
| 632 | seat_destroy_listener); |
| 633 | |
| 634 | wl_list_remove(&state->link); |
| 635 | focus_state_destroy(state); |
| 636 | } |
| 637 | |
| 638 | static void |
| 639 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 640 | { |
| 641 | struct focus_state *state = container_of(listener, |
| 642 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 643 | surface_destroy_listener); |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 644 | struct weston_surface *main_surface; |
| 645 | struct weston_view *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 646 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 647 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 648 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 649 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 650 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 651 | wl_list_for_each(view, |
| 652 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 653 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 654 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 655 | if (is_focus_view(view)) |
| 656 | continue; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 657 | if (!get_shell_surface(view->surface)) |
| 658 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 659 | |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 660 | next = view; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 661 | break; |
| 662 | } |
| 663 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 664 | /* if the focus was a sub-surface, activate its main surface */ |
| 665 | if (main_surface != state->keyboard_focus) |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 666 | next = get_default_view(main_surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 667 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 668 | if (next) { |
Greg V | 15d3d30 | 2018-12-07 01:33:34 +0300 | [diff] [blame] | 669 | if (state->keyboard_focus) { |
| 670 | wl_list_remove(&state->surface_destroy_listener.link); |
| 671 | wl_list_init(&state->surface_destroy_listener.link); |
| 672 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 673 | state->keyboard_focus = NULL; |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 674 | activate(state->shell, next, state->seat, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 675 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 676 | } else { |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 677 | if (state->shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 678 | if (state->ws->focus_animation) |
| 679 | weston_view_animation_destroy(state->ws->focus_animation); |
| 680 | |
| 681 | state->ws->focus_animation = weston_fade_run( |
| 682 | state->ws->fsurf_front->view, |
| 683 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 684 | focus_animation_done, state->ws); |
| 685 | } |
| 686 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 687 | wl_list_remove(&state->link); |
| 688 | focus_state_destroy(state); |
| 689 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | static struct focus_state * |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 693 | focus_state_create(struct desktop_shell *shell, struct weston_seat *seat, |
| 694 | struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 695 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 696 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 697 | |
| 698 | state = malloc(sizeof *state); |
| 699 | if (state == NULL) |
| 700 | return NULL; |
| 701 | |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 702 | state->shell = shell; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 703 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 704 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 705 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 706 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 707 | |
| 708 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 709 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 710 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 711 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 712 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 713 | |
| 714 | return state; |
| 715 | } |
| 716 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 717 | static struct focus_state * |
| 718 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 719 | { |
| 720 | struct workspace *ws = get_current_workspace(shell); |
| 721 | struct focus_state *state; |
| 722 | |
| 723 | wl_list_for_each(state, &ws->focus_list, link) |
| 724 | if (state->seat == seat) |
| 725 | break; |
| 726 | |
| 727 | if (&state->link == &ws->focus_list) |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 728 | state = focus_state_create(shell, seat, ws); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 729 | |
| 730 | return state; |
| 731 | } |
| 732 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 733 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 734 | focus_state_set_focus(struct focus_state *state, |
| 735 | struct weston_surface *surface) |
| 736 | { |
| 737 | if (state->keyboard_focus) { |
| 738 | wl_list_remove(&state->surface_destroy_listener.link); |
| 739 | wl_list_init(&state->surface_destroy_listener.link); |
| 740 | } |
| 741 | |
| 742 | state->keyboard_focus = surface; |
| 743 | if (surface) |
| 744 | wl_signal_add(&surface->destroy_signal, |
| 745 | &state->surface_destroy_listener); |
| 746 | } |
| 747 | |
| 748 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 749 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 750 | { |
| 751 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 752 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 753 | struct wl_list pending_seat_list; |
| 754 | struct weston_seat *seat, *next_seat; |
| 755 | |
| 756 | /* Temporarily steal the list of seats so that we can keep |
| 757 | * track of the seats we've already processed */ |
| 758 | wl_list_init(&pending_seat_list); |
| 759 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 760 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 761 | |
| 762 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 763 | struct weston_keyboard *keyboard = |
| 764 | weston_seat_get_keyboard(state->seat); |
| 765 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 766 | wl_list_remove(&state->seat->link); |
| 767 | wl_list_insert(&shell->compositor->seat_list, |
| 768 | &state->seat->link); |
| 769 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 770 | if (!keyboard) |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 771 | continue; |
| 772 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 773 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 774 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 775 | weston_keyboard_set_focus(keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 776 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 777 | |
| 778 | /* For any remaining seats that we don't have a focus state |
| 779 | * for we'll reset the keyboard focus to NULL */ |
| 780 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 781 | struct weston_keyboard *keyboard = |
| 782 | weston_seat_get_keyboard(seat); |
| 783 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 784 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 785 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 786 | if (!keyboard) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 787 | continue; |
| 788 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 789 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 790 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 794 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 795 | struct weston_seat *seat) |
| 796 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 797 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 798 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 799 | |
| 800 | wl_list_for_each(state, &ws->focus_list, link) { |
| 801 | if (state->seat == seat) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 802 | focus_state_set_focus(state, keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 803 | return; |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | static void |
| 809 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 810 | struct weston_surface *surface) |
| 811 | { |
| 812 | struct focus_state *state; |
| 813 | |
| 814 | wl_list_for_each(state, &ws->focus_list, link) |
| 815 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 816 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 820 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 821 | struct weston_view *from, struct weston_view *to) |
| 822 | { |
| 823 | struct weston_output *output; |
| 824 | bool focus_surface_created = false; |
| 825 | |
| 826 | /* FIXME: Only support dim animation using two layers */ |
| 827 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 828 | return; |
| 829 | |
| 830 | output = get_default_output(shell->compositor); |
| 831 | if (ws->fsurf_front == NULL && (from || to)) { |
| 832 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 833 | if (ws->fsurf_front == NULL) |
| 834 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 835 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 836 | |
| 837 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 838 | if (ws->fsurf_back == NULL) { |
| 839 | focus_surface_destroy(ws->fsurf_front); |
| 840 | return; |
| 841 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 842 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 843 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 844 | focus_surface_created = true; |
| 845 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 846 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 847 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | if (ws->focus_animation) { |
| 851 | weston_view_animation_destroy(ws->focus_animation); |
| 852 | ws->focus_animation = NULL; |
| 853 | } |
| 854 | |
| 855 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 856 | weston_layer_entry_insert(&to->layer_link, |
| 857 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 858 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 859 | weston_layer_entry_insert(&ws->layer.view_list, |
| 860 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 861 | |
| 862 | if (focus_surface_created) { |
| 863 | ws->focus_animation = weston_fade_run( |
| 864 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 865 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 866 | focus_animation_done, ws); |
| 867 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 868 | weston_layer_entry_insert(&from->layer_link, |
| 869 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 870 | ws->focus_animation = weston_stable_fade_run( |
| 871 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 872 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 873 | focus_animation_done, ws); |
| 874 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 875 | weston_layer_entry_insert(&ws->layer.view_list, |
| 876 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 877 | ws->focus_animation = weston_stable_fade_run( |
| 878 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 879 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 880 | focus_animation_done, ws); |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 885 | workspace_destroy(struct workspace *ws) |
| 886 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 887 | struct focus_state *state, *next; |
| 888 | |
| 889 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 890 | focus_state_destroy(state); |
| 891 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 892 | if (ws->fsurf_front) |
| 893 | focus_surface_destroy(ws->fsurf_front); |
| 894 | if (ws->fsurf_back) |
| 895 | focus_surface_destroy(ws->fsurf_back); |
| 896 | |
Pekka Paalanen | 4bb326b | 2021-05-14 14:37:46 +0300 | [diff] [blame] | 897 | weston_layer_fini(&ws->layer); |
| 898 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 899 | free(ws); |
| 900 | } |
| 901 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 902 | static void |
| 903 | seat_destroyed(struct wl_listener *listener, void *data) |
| 904 | { |
| 905 | struct weston_seat *seat = data; |
| 906 | struct focus_state *state, *next; |
| 907 | struct workspace *ws = container_of(listener, |
| 908 | struct workspace, |
| 909 | seat_destroyed_listener); |
| 910 | |
| 911 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 912 | if (state->seat == seat) |
| 913 | wl_list_remove(&state->link); |
| 914 | } |
| 915 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 916 | static struct workspace * |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 917 | workspace_create(struct desktop_shell *shell) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 918 | { |
| 919 | struct workspace *ws = malloc(sizeof *ws); |
| 920 | if (ws == NULL) |
| 921 | return NULL; |
| 922 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 923 | weston_layer_init(&ws->layer, shell->compositor); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 924 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 925 | wl_list_init(&ws->focus_list); |
| 926 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 927 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 928 | ws->fsurf_front = NULL; |
| 929 | ws->fsurf_back = NULL; |
| 930 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 931 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 932 | return ws; |
| 933 | } |
| 934 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 935 | static int |
| 936 | workspace_is_empty(struct workspace *ws) |
| 937 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 938 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 939 | } |
| 940 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 941 | static struct workspace * |
| 942 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 943 | { |
| 944 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 945 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 946 | pws += index; |
| 947 | return *pws; |
| 948 | } |
| 949 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 950 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 951 | get_current_workspace(struct desktop_shell *shell) |
| 952 | { |
| 953 | return get_workspace(shell, shell->workspaces.current); |
| 954 | } |
| 955 | |
| 956 | static void |
| 957 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 958 | { |
| 959 | struct workspace *ws; |
| 960 | |
| 961 | ws = get_workspace(shell, index); |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 962 | weston_layer_set_position(&ws->layer, WESTON_LAYER_POSITION_NORMAL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 963 | |
| 964 | shell->workspaces.current = index; |
| 965 | } |
| 966 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 967 | static unsigned int |
| 968 | get_output_height(struct weston_output *output) |
| 969 | { |
| 970 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 971 | } |
| 972 | |
Greg V | f57774e | 2018-07-24 23:21:55 +0300 | [diff] [blame] | 973 | static struct weston_transform * |
| 974 | view_get_transform(struct weston_view *view) |
| 975 | { |
| 976 | struct focus_surface *fsurf = NULL; |
| 977 | struct shell_surface *shsurf = NULL; |
| 978 | |
| 979 | if (is_focus_view(view)) { |
| 980 | fsurf = get_focus_surface(view->surface); |
| 981 | return &fsurf->workspace_transform; |
| 982 | } |
| 983 | |
| 984 | shsurf = get_shell_surface(view->surface); |
| 985 | if (shsurf) |
| 986 | return &shsurf->workspace_transform; |
| 987 | |
| 988 | return NULL; |
| 989 | } |
| 990 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 991 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 992 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 993 | { |
Greg V | f57774e | 2018-07-24 23:21:55 +0300 | [diff] [blame] | 994 | struct weston_transform *transform = view_get_transform(view); |
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 | if (!transform) |
| 997 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 998 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 999 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1000 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1001 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1002 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1003 | weston_matrix_init(&transform->matrix); |
| 1004 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1005 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1006 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | static void |
| 1010 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1011 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1012 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1013 | unsigned int height; |
| 1014 | double d; |
| 1015 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1016 | 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] | 1017 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1018 | d = height * fraction; |
| 1019 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1020 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | static void |
| 1025 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1026 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1027 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1028 | unsigned int height; |
| 1029 | double d; |
| 1030 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1031 | 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] | 1032 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1033 | |
| 1034 | if (fraction > 0) |
| 1035 | d = -(height - height * fraction); |
| 1036 | else |
| 1037 | d = height + height * fraction; |
| 1038 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1039 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1044 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1045 | unsigned int index, |
| 1046 | struct workspace *from, |
| 1047 | struct workspace *to) |
| 1048 | { |
| 1049 | shell->workspaces.current = index; |
| 1050 | |
| 1051 | shell->workspaces.anim_to = to; |
| 1052 | shell->workspaces.anim_from = from; |
| 1053 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1054 | shell->workspaces.anim_timestamp = (struct timespec) { 0 }; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1055 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1056 | weston_layer_set_position(&to->layer, WESTON_LAYER_POSITION_NORMAL); |
| 1057 | weston_layer_set_position(&from->layer, WESTON_LAYER_POSITION_NORMAL - 1); |
| 1058 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1059 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | static void |
| 1063 | workspace_deactivate_transforms(struct workspace *ws) |
| 1064 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1065 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1066 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1067 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1068 | 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] | 1069 | transform = view_get_transform(view); |
| 1070 | if (!transform) |
| 1071 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1072 | |
| 1073 | if (!wl_list_empty(&transform->link)) { |
| 1074 | wl_list_remove(&transform->link); |
| 1075 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1076 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1077 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | static void |
| 1082 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1083 | struct workspace *from, |
| 1084 | struct workspace *to) |
| 1085 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1086 | struct weston_view *view; |
| 1087 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1088 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1089 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1090 | /* Views that extend past the bottom of the output are still |
| 1091 | * visible after the workspace animation ends but before its layer |
| 1092 | * is hidden. In that case, we need to damage below those views so |
| 1093 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1094 | 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] | 1095 | weston_view_damage_below(view); |
| 1096 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1097 | wl_list_remove(&shell->workspaces.animation.link); |
| 1098 | workspace_deactivate_transforms(from); |
| 1099 | workspace_deactivate_transforms(to); |
| 1100 | shell->workspaces.anim_to = NULL; |
| 1101 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1102 | weston_layer_unset_position(&shell->workspaces.anim_from->layer); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | static void |
| 1106 | animate_workspace_change_frame(struct weston_animation *animation, |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1107 | struct weston_output *output, |
| 1108 | const struct timespec *time) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1109 | { |
| 1110 | struct desktop_shell *shell = |
| 1111 | container_of(animation, struct desktop_shell, |
| 1112 | workspaces.animation); |
| 1113 | struct workspace *from = shell->workspaces.anim_from; |
| 1114 | struct workspace *to = shell->workspaces.anim_to; |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1115 | int64_t t; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1116 | double x, y; |
| 1117 | |
| 1118 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1119 | finish_workspace_change_animation(shell, from, to); |
| 1120 | return; |
| 1121 | } |
| 1122 | |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1123 | if (timespec_is_zero(&shell->workspaces.anim_timestamp)) { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1124 | if (shell->workspaces.anim_current == 0.0) |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1125 | shell->workspaces.anim_timestamp = *time; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1126 | else |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1127 | timespec_add_msec(&shell->workspaces.anim_timestamp, |
| 1128 | time, |
Emmanuel Gil Peyrot | 426c246 | 2019-02-20 16:33:32 +0100 | [diff] [blame] | 1129 | /* Inverse of movement function 'y' below. */ |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1130 | -(asin(1.0 - shell->workspaces.anim_current) * |
| 1131 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1132 | M_2_PI)); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1133 | } |
| 1134 | |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1135 | t = timespec_sub_to_msec(time, &shell->workspaces.anim_timestamp); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1136 | |
| 1137 | /* |
| 1138 | * x = [0, π/2] |
| 1139 | * y(x) = sin(x) |
| 1140 | */ |
| 1141 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1142 | y = sin(x); |
| 1143 | |
| 1144 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1145 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1146 | |
| 1147 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1148 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1149 | shell->workspaces.anim_current = y; |
| 1150 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1151 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1152 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1153 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1154 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | static void |
| 1158 | animate_workspace_change(struct desktop_shell *shell, |
| 1159 | unsigned int index, |
| 1160 | struct workspace *from, |
| 1161 | struct workspace *to) |
| 1162 | { |
| 1163 | struct weston_output *output; |
| 1164 | |
| 1165 | int dir; |
| 1166 | |
| 1167 | if (index > shell->workspaces.current) |
| 1168 | dir = -1; |
| 1169 | else |
| 1170 | dir = 1; |
| 1171 | |
| 1172 | shell->workspaces.current = index; |
| 1173 | |
| 1174 | shell->workspaces.anim_dir = dir; |
| 1175 | shell->workspaces.anim_from = from; |
| 1176 | shell->workspaces.anim_to = to; |
| 1177 | shell->workspaces.anim_current = 0.0; |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1178 | shell->workspaces.anim_timestamp = (struct timespec) { 0 }; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1179 | |
| 1180 | output = container_of(shell->compositor->output_list.next, |
| 1181 | struct weston_output, link); |
| 1182 | wl_list_insert(&output->animation_list, |
| 1183 | &shell->workspaces.animation.link); |
| 1184 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1185 | weston_layer_set_position(&to->layer, WESTON_LAYER_POSITION_NORMAL); |
| 1186 | weston_layer_set_position(&from->layer, WESTON_LAYER_POSITION_NORMAL - 1); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1187 | |
| 1188 | workspace_translate_in(to, 0); |
| 1189 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1190 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1191 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1192 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1193 | } |
| 1194 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1195 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1196 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1197 | struct workspace *from, struct workspace *to) |
| 1198 | { |
| 1199 | shell->workspaces.current = index; |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1200 | weston_layer_set_position(&to->layer, WESTON_LAYER_POSITION_NORMAL); |
| 1201 | weston_layer_unset_position(&from->layer); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1205 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1206 | { |
| 1207 | struct workspace *from; |
| 1208 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1209 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1210 | |
| 1211 | if (index == shell->workspaces.current) |
| 1212 | return; |
| 1213 | |
| 1214 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1215 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1216 | return; |
| 1217 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1218 | from = get_current_workspace(shell); |
| 1219 | to = get_workspace(shell, index); |
| 1220 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1221 | if (shell->workspaces.anim_from == to && |
| 1222 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1223 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1224 | reverse_workspace_change_animation(shell, index, from, to); |
| 1225 | return; |
| 1226 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1227 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1228 | if (shell->workspaces.anim_to != NULL) |
| 1229 | finish_workspace_change_animation(shell, |
| 1230 | shell->workspaces.anim_from, |
| 1231 | shell->workspaces.anim_to); |
| 1232 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1233 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1234 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1235 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1236 | wl_list_for_each(state, &from->focus_list, link) |
| 1237 | if (state->keyboard_focus) |
| 1238 | animate_focus_change(shell, from, |
| 1239 | get_default_view(state->keyboard_focus), NULL); |
| 1240 | |
| 1241 | wl_list_for_each(state, &to->focus_list, link) |
| 1242 | if (state->keyboard_focus) |
| 1243 | animate_focus_change(shell, to, |
| 1244 | NULL, get_default_view(state->keyboard_focus)); |
| 1245 | } |
| 1246 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1247 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1248 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1249 | else |
| 1250 | animate_workspace_change(shell, index, from, to); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1251 | } |
| 1252 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1253 | static bool |
| 1254 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1255 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1256 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1257 | struct wl_list *e; |
| 1258 | |
| 1259 | if (wl_list_empty(list)) |
| 1260 | return false; |
| 1261 | |
| 1262 | e = list->next; |
| 1263 | |
| 1264 | if (e->next != list) |
| 1265 | return false; |
| 1266 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1267 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | static void |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 1271 | surface_keyboard_focus_lost(struct weston_surface *surface) |
| 1272 | { |
| 1273 | struct weston_compositor *compositor = surface->compositor; |
| 1274 | struct weston_seat *seat; |
| 1275 | struct weston_surface *focus; |
| 1276 | |
| 1277 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 1278 | struct weston_keyboard *keyboard = |
| 1279 | weston_seat_get_keyboard(seat); |
| 1280 | |
| 1281 | if (!keyboard) |
| 1282 | continue; |
| 1283 | |
| 1284 | focus = weston_surface_get_main_surface(keyboard->focus); |
| 1285 | if (focus == surface) |
| 1286 | weston_keyboard_set_focus(keyboard, NULL); |
| 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1291 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1292 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1293 | unsigned int index) |
| 1294 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1295 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1296 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1297 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1298 | struct shell_surface *shsurf; |
| 1299 | struct workspace *from; |
| 1300 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1301 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1302 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1303 | surface = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1304 | view = get_default_view(surface); |
| 1305 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1306 | index == shell->workspaces.current || |
| 1307 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1308 | return; |
| 1309 | |
| 1310 | from = get_current_workspace(shell); |
| 1311 | to = get_workspace(shell, index); |
| 1312 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1313 | weston_layer_entry_remove(&view->layer_link); |
| 1314 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1315 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1316 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1317 | if (shsurf != NULL) |
| 1318 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1319 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1320 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1321 | drop_focus_state(shell, from, surface); |
| 1322 | |
| 1323 | if (shell->workspaces.anim_from == to && |
| 1324 | shell->workspaces.anim_to == from) { |
| 1325 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1326 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1327 | return; |
| 1328 | } |
| 1329 | |
| 1330 | if (shell->workspaces.anim_to != NULL) |
| 1331 | finish_workspace_change_animation(shell, |
| 1332 | shell->workspaces.anim_from, |
| 1333 | shell->workspaces.anim_to); |
| 1334 | |
| 1335 | if (workspace_is_empty(from) && |
| 1336 | workspace_has_only(to, surface)) |
| 1337 | update_workspace(shell, index, from, to); |
| 1338 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1339 | if (shsurf != NULL && |
| 1340 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1341 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1342 | &shsurf->workspace_transform.link); |
| 1343 | |
| 1344 | animate_workspace_change(shell, index, from, to); |
| 1345 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1346 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1347 | state = ensure_focus_state(shell, seat); |
| 1348 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1349 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | static void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 1353 | touch_move_grab_down(struct weston_touch_grab *grab, |
| 1354 | const struct timespec *time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1355 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1356 | { |
| 1357 | } |
| 1358 | |
| 1359 | static void |
Alexandros Frantzis | 27a51b8 | 2017-11-16 18:20:59 +0200 | [diff] [blame] | 1360 | touch_move_grab_up(struct weston_touch_grab *grab, const struct timespec *time, |
| 1361 | int touch_id) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1362 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1363 | struct weston_touch_move_grab *move = |
| 1364 | (struct weston_touch_move_grab *) container_of( |
| 1365 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1366 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1367 | if (touch_id == 0) |
| 1368 | move->active = 0; |
| 1369 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1370 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1371 | shell_touch_grab_end(&move->base); |
| 1372 | free(move); |
| 1373 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | static void |
Alexandros Frantzis | 7d2abcf | 2017-11-16 18:21:00 +0200 | [diff] [blame] | 1377 | touch_move_grab_motion(struct weston_touch_grab *grab, |
| 1378 | const struct timespec *time, int touch_id, |
| 1379 | wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1380 | { |
| 1381 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1382 | struct shell_surface *shsurf = move->base.shsurf; |
| 1383 | struct weston_surface *es; |
| 1384 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1385 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1386 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1387 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1388 | return; |
| 1389 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1390 | es = weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1391 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1392 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1393 | |
| 1394 | weston_compositor_schedule_repaint(es->compositor); |
| 1395 | } |
| 1396 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1397 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1398 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1399 | { |
| 1400 | } |
| 1401 | |
| 1402 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1403 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1404 | { |
| 1405 | struct weston_touch_move_grab *move = |
| 1406 | (struct weston_touch_move_grab *) container_of( |
| 1407 | grab, struct shell_touch_grab, grab); |
| 1408 | |
| 1409 | shell_touch_grab_end(&move->base); |
| 1410 | free(move); |
| 1411 | } |
| 1412 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1413 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1414 | touch_move_grab_down, |
| 1415 | touch_move_grab_up, |
| 1416 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1417 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1418 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1419 | }; |
| 1420 | |
| 1421 | static int |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1422 | surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1423 | { |
| 1424 | struct weston_touch_move_grab *move; |
| 1425 | |
| 1426 | if (!shsurf) |
| 1427 | return -1; |
| 1428 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1429 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1430 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1431 | return 0; |
| 1432 | |
| 1433 | move = malloc(sizeof *move); |
| 1434 | if (!move) |
| 1435 | return -1; |
| 1436 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1437 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1438 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1439 | touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1440 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1441 | touch->grab_y; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1442 | |
| 1443 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1444 | touch); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1445 | |
| 1446 | return 0; |
| 1447 | } |
| 1448 | |
| 1449 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1450 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1451 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | static void |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1455 | noop_grab_axis(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 1456 | const struct timespec *time, |
| 1457 | struct weston_pointer_axis_event *event) |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1458 | { |
| 1459 | } |
| 1460 | |
| 1461 | static void |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1462 | noop_grab_axis_source(struct weston_pointer_grab *grab, |
| 1463 | uint32_t source) |
| 1464 | { |
| 1465 | } |
| 1466 | |
| 1467 | static void |
| 1468 | noop_grab_frame(struct weston_pointer_grab *grab) |
| 1469 | { |
| 1470 | } |
| 1471 | |
| 1472 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1473 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1474 | { |
| 1475 | struct shell_surface *shsurf = move->base.shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1476 | struct weston_surface *surface = |
| 1477 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1478 | struct weston_pointer *pointer = move->base.grab.pointer; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1479 | int x, y, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1480 | const int safety = 50; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1481 | pixman_rectangle32_t area; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1482 | struct weston_geometry geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1483 | |
| 1484 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1485 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1486 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1487 | if (shsurf->shell->panel_position == |
| 1488 | WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1489 | get_output_work_area(shsurf->shell, surface->output, &area); |
| 1490 | geometry = |
| 1491 | weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1492 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1493 | bottom = y + geometry.height + geometry.y; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1494 | if (bottom - safety < area.y) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1495 | y = area.y + safety - geometry.height |
| 1496 | - geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1497 | |
| 1498 | if (move->client_initiated && |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1499 | y + geometry.y < area.y) |
| 1500 | y = area.y - geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1501 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1502 | |
| 1503 | *cx = x; |
| 1504 | *cy = y; |
| 1505 | } |
| 1506 | |
| 1507 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 1508 | move_grab_motion(struct weston_pointer_grab *grab, |
| 1509 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1510 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1511 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1512 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1513 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1514 | struct shell_surface *shsurf = move->base.shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1515 | struct weston_surface *surface; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1516 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1517 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1518 | weston_pointer_move(pointer, event); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1519 | if (!shsurf) |
| 1520 | return; |
| 1521 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1522 | surface = weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 1523 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1524 | constrain_position(move, &cx, &cy); |
| 1525 | |
| 1526 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1527 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1528 | weston_compositor_schedule_repaint(surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1532 | move_grab_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 1533 | const struct timespec *time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1534 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1535 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1536 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1537 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1538 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1539 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1540 | if (pointer->button_count == 0 && |
| 1541 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1542 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1543 | free(grab); |
| 1544 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1545 | } |
| 1546 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1547 | static void |
| 1548 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1549 | { |
| 1550 | struct shell_grab *shell_grab = |
| 1551 | container_of(grab, struct shell_grab, grab); |
| 1552 | |
| 1553 | shell_grab_end(shell_grab); |
| 1554 | free(grab); |
| 1555 | } |
| 1556 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1557 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1558 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1559 | move_grab_motion, |
| 1560 | move_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1561 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1562 | noop_grab_axis_source, |
| 1563 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1564 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1565 | }; |
| 1566 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1567 | static int |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1568 | surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 1569 | bool client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1570 | { |
| 1571 | struct weston_move_grab *move; |
| 1572 | |
| 1573 | if (!shsurf) |
| 1574 | return -1; |
| 1575 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1576 | if (shsurf->grabbed || |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1577 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1578 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1579 | return 0; |
| 1580 | |
| 1581 | move = malloc(sizeof *move); |
| 1582 | if (!move) |
| 1583 | return -1; |
| 1584 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1585 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1586 | pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1587 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1588 | pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1589 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1590 | |
| 1591 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1592 | pointer, WESTON_DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1593 | |
| 1594 | return 0; |
| 1595 | } |
| 1596 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1597 | struct weston_resize_grab { |
| 1598 | struct shell_grab base; |
| 1599 | uint32_t edges; |
| 1600 | int32_t width, height; |
| 1601 | }; |
| 1602 | |
| 1603 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 1604 | resize_grab_motion(struct weston_pointer_grab *grab, |
| 1605 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1606 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1607 | { |
| 1608 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1609 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1610 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1611 | int32_t width, height; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1612 | struct weston_size min_size, max_size; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1613 | wl_fixed_t from_x, from_y; |
| 1614 | wl_fixed_t to_x, to_y; |
| 1615 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1616 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1617 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1618 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1619 | return; |
| 1620 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1621 | weston_view_from_global_fixed(shsurf->view, |
| 1622 | pointer->grab_x, pointer->grab_y, |
| 1623 | &from_x, &from_y); |
| 1624 | weston_view_from_global_fixed(shsurf->view, |
| 1625 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1626 | |
| 1627 | width = resize->width; |
| 1628 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1629 | width += wl_fixed_to_int(from_x - to_x); |
| 1630 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1631 | width += wl_fixed_to_int(to_x - from_x); |
| 1632 | } |
| 1633 | |
| 1634 | height = resize->height; |
| 1635 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1636 | height += wl_fixed_to_int(from_y - to_y); |
| 1637 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1638 | height += wl_fixed_to_int(to_y - from_y); |
| 1639 | } |
| 1640 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1641 | max_size = weston_desktop_surface_get_max_size(shsurf->desktop_surface); |
| 1642 | min_size = weston_desktop_surface_get_min_size(shsurf->desktop_surface); |
| 1643 | |
| 1644 | min_size.width = MAX(1, min_size.width); |
| 1645 | min_size.height = MAX(1, min_size.height); |
| 1646 | |
| 1647 | if (width < min_size.width) |
| 1648 | width = min_size.width; |
| 1649 | else if (max_size.width > 0 && width > max_size.width) |
| 1650 | width = max_size.width; |
| 1651 | if (height < min_size.height) |
| 1652 | height = min_size.height; |
| 1653 | else if (max_size.width > 0 && width > max_size.width) |
| 1654 | width = max_size.width; |
| 1655 | weston_desktop_surface_set_size(shsurf->desktop_surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1659 | resize_grab_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 1660 | const struct timespec *time, |
| 1661 | uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1662 | { |
| 1663 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1664 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1665 | enum wl_pointer_button_state state = state_w; |
| 1666 | |
| 1667 | if (pointer->button_count == 0 && |
| 1668 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Greg V | ec3f779 | 2018-11-08 00:24:56 +0300 | [diff] [blame] | 1669 | if (resize->base.shsurf != NULL) { |
| 1670 | struct weston_desktop_surface *desktop_surface = |
| 1671 | resize->base.shsurf->desktop_surface; |
| 1672 | weston_desktop_surface_set_resizing(desktop_surface, |
| 1673 | false); |
| 1674 | } |
| 1675 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1676 | shell_grab_end(&resize->base); |
| 1677 | free(grab); |
| 1678 | } |
| 1679 | } |
| 1680 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1681 | static void |
| 1682 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1683 | { |
| 1684 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1685 | |
Greg V | ec3f779 | 2018-11-08 00:24:56 +0300 | [diff] [blame] | 1686 | if (resize->base.shsurf != NULL) { |
| 1687 | struct weston_desktop_surface *desktop_surface = |
| 1688 | resize->base.shsurf->desktop_surface; |
| 1689 | weston_desktop_surface_set_resizing(desktop_surface, false); |
| 1690 | } |
| 1691 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1692 | shell_grab_end(&resize->base); |
| 1693 | free(grab); |
| 1694 | } |
| 1695 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1696 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1697 | noop_grab_focus, |
| 1698 | resize_grab_motion, |
| 1699 | resize_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1700 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1701 | noop_grab_axis_source, |
| 1702 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1703 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1704 | }; |
| 1705 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1706 | /* |
| 1707 | * Returns the bounding box of a surface and all its sub-surfaces, |
Yong Bakos | bbb783a | 2016-04-28 11:59:06 -0500 | [diff] [blame] | 1708 | * in surface-local coordinates. */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1709 | static void |
| 1710 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1711 | int32_t *y, int32_t *w, int32_t *h) { |
| 1712 | pixman_region32_t region; |
| 1713 | pixman_box32_t *box; |
| 1714 | struct weston_subsurface *subsurface; |
| 1715 | |
| 1716 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1717 | surface->width, |
| 1718 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1719 | |
| 1720 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1721 | pixman_region32_union_rect(®ion, ®ion, |
| 1722 | subsurface->position.x, |
| 1723 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1724 | subsurface->surface->width, |
| 1725 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | box = pixman_region32_extents(®ion); |
| 1729 | if (x) |
| 1730 | *x = box->x1; |
| 1731 | if (y) |
| 1732 | *y = box->y1; |
| 1733 | if (w) |
| 1734 | *w = box->x2 - box->x1; |
| 1735 | if (h) |
| 1736 | *h = box->y2 - box->y1; |
| 1737 | |
| 1738 | pixman_region32_fini(®ion); |
| 1739 | } |
| 1740 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1741 | static int |
| 1742 | surface_resize(struct shell_surface *shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1743 | struct weston_pointer *pointer, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1744 | { |
| 1745 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1746 | const unsigned resize_topbottom = |
| 1747 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1748 | const unsigned resize_leftright = |
| 1749 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1750 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1751 | struct weston_geometry geometry; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1752 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1753 | if (shsurf->grabbed || |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1754 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1755 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1756 | return 0; |
| 1757 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1758 | /* Check for invalid edge combinations. */ |
| 1759 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1760 | (edges & resize_topbottom) == resize_topbottom || |
| 1761 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1762 | return 0; |
| 1763 | |
| 1764 | resize = malloc(sizeof *resize); |
| 1765 | if (!resize) |
| 1766 | return -1; |
| 1767 | |
| 1768 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1769 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1770 | geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
| 1771 | resize->width = geometry.width; |
| 1772 | resize->height = geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1773 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1774 | shsurf->resize_edges = edges; |
Philipp Kerling | c5f1241 | 2017-07-28 14:11:58 +0200 | [diff] [blame] | 1775 | weston_desktop_surface_set_resizing(shsurf->desktop_surface, true); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1776 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1777 | pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1778 | |
| 1779 | return 0; |
| 1780 | } |
| 1781 | |
| 1782 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1783 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1784 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1785 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1786 | struct weston_pointer *pointer = base->pointer; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1787 | struct weston_desktop_surface *desktop_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1788 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1789 | wl_fixed_t sx, sy; |
| 1790 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1791 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1792 | pointer->x, pointer->y, |
| 1793 | &sx, &sy); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1794 | desktop_surface = weston_surface_get_desktop_surface(view->surface); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1795 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1796 | if (!grab->shsurf || grab->shsurf->desktop_surface != desktop_surface) { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1797 | shell_grab_end(grab); |
| 1798 | free(grab); |
| 1799 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 1803 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, |
| 1804 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1805 | struct weston_pointer_motion_event *event) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1806 | { |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1807 | weston_pointer_move(grab->pointer, event); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1808 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1809 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1810 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1811 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 1812 | const struct timespec *time, |
| 1813 | uint32_t button, uint32_t state) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1814 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1815 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1816 | struct shell_surface *shsurf = grab->shsurf; |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1817 | struct weston_pointer *pointer = grab->grab.pointer; |
| 1818 | struct weston_seat *seat = pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1819 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1820 | if (shsurf && button == BTN_LEFT && state) { |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 1821 | activate(shsurf->shell, shsurf->view, seat, |
| 1822 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1823 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1824 | } else if (shsurf && button == BTN_RIGHT && state) { |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 1825 | activate(shsurf->shell, shsurf->view, seat, |
| 1826 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 1827 | surface_rotate(shsurf, pointer); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1828 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1829 | } |
| 1830 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1831 | static void |
| 1832 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1833 | { |
| 1834 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1835 | |
| 1836 | shell_grab_end(grab); |
| 1837 | free(grab); |
| 1838 | } |
| 1839 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1840 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1841 | busy_cursor_grab_focus, |
| 1842 | busy_cursor_grab_motion, |
| 1843 | busy_cursor_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1844 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1845 | noop_grab_axis_source, |
| 1846 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1847 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1848 | }; |
| 1849 | |
| 1850 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1851 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1852 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1853 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1854 | struct weston_view *view = pointer->focus; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1855 | struct shell_surface *shsurf; |
| 1856 | struct weston_desktop_client *client; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1857 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1858 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1859 | return; |
| 1860 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1861 | shsurf = get_shell_surface(view->surface); |
| 1862 | if (!shsurf) |
| 1863 | return; |
| 1864 | |
| 1865 | client = weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 1866 | |
| 1867 | if (shsurf->unresponsive) |
| 1868 | set_busy_cursor(shsurf, pointer); |
| 1869 | else |
| 1870 | weston_desktop_client_ping(client); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1874 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 1875 | { |
| 1876 | if (--shsurf->focus_count == 0) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1877 | weston_desktop_surface_set_activated(shsurf->desktop_surface, false); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | static void |
| 1881 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 1882 | { |
| 1883 | if (shsurf->focus_count++ == 0) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1884 | weston_desktop_surface_set_activated(shsurf->desktop_surface, true); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | static void |
| 1888 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 1889 | { |
| 1890 | struct weston_keyboard *keyboard = data; |
| 1891 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 1892 | |
| 1893 | if (seat->focused_surface) { |
| 1894 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 1895 | if (shsurf) |
| 1896 | shell_surface_lose_keyboard_focus(shsurf); |
| 1897 | } |
| 1898 | |
Philipp Kerling | ba8a0d0 | 2017-07-26 12:02:15 +0200 | [diff] [blame] | 1899 | seat->focused_surface = weston_surface_get_main_surface(keyboard->focus); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1900 | |
| 1901 | if (seat->focused_surface) { |
| 1902 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 1903 | if (shsurf) |
| 1904 | shell_surface_gain_keyboard_focus(shsurf); |
| 1905 | } |
| 1906 | } |
| 1907 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1908 | /* The surface will be inserted into the list immediately after the link |
| 1909 | * returned by this function (i.e. will be stacked immediately above the |
| 1910 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1911 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1912 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 1913 | { |
| 1914 | struct workspace *ws; |
| 1915 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1916 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) && |
| 1917 | !shsurf->state.lowered) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 1918 | return &shsurf->shell->fullscreen_layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1919 | } |
| 1920 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1921 | /* Move the surface to a normal workspace layer so that surfaces |
| 1922 | * which were previously fullscreen or transient are no longer |
| 1923 | * rendered on top. */ |
| 1924 | ws = get_current_workspace(shsurf->shell); |
| 1925 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1926 | } |
| 1927 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1928 | static void |
| 1929 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 1930 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1931 | weston_desktop_surface_propagate_layer(shsurf->desktop_surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1932 | } |
| 1933 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1934 | /* 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] | 1935 | * geometry to ensure the changes are redrawn. |
| 1936 | * |
| 1937 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 1938 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1939 | static void |
| 1940 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 1941 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1942 | struct weston_surface *surface = |
| 1943 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1944 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1945 | |
| 1946 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 1947 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 1948 | if (new_layer_link == NULL) |
| 1949 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1950 | if (new_layer_link == &shsurf->view->layer_link) |
| 1951 | return; |
| 1952 | |
| 1953 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1954 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 1955 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1956 | weston_view_geometry_dirty(shsurf->view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1957 | weston_surface_damage(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1958 | |
| 1959 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1960 | } |
| 1961 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1962 | static void |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame] | 1963 | notify_output_destroy(struct wl_listener *listener, void *data) |
| 1964 | { |
| 1965 | struct shell_surface *shsurf = |
| 1966 | container_of(listener, |
| 1967 | struct shell_surface, output_destroy_listener); |
| 1968 | |
| 1969 | shsurf->output = NULL; |
| 1970 | shsurf->output_destroy_listener.notify = NULL; |
| 1971 | } |
| 1972 | |
| 1973 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1974 | shell_surface_set_output(struct shell_surface *shsurf, |
| 1975 | struct weston_output *output) |
| 1976 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1977 | struct weston_surface *es = |
| 1978 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1979 | |
| 1980 | /* get the default output, if the client set it as NULL |
Abdur Rehman | 7f1da1f | 2017-01-01 19:46:33 +0500 | [diff] [blame] | 1981 | check whether the output is available */ |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1982 | if (output) |
| 1983 | shsurf->output = output; |
| 1984 | else if (es->output) |
| 1985 | shsurf->output = es->output; |
| 1986 | else |
| 1987 | shsurf->output = get_default_output(es->compositor); |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame] | 1988 | |
| 1989 | if (shsurf->output_destroy_listener.notify) { |
| 1990 | wl_list_remove(&shsurf->output_destroy_listener.link); |
| 1991 | shsurf->output_destroy_listener.notify = NULL; |
| 1992 | } |
| 1993 | |
| 1994 | if (!shsurf->output) |
| 1995 | return; |
| 1996 | |
| 1997 | shsurf->output_destroy_listener.notify = notify_output_destroy; |
| 1998 | wl_signal_add(&shsurf->output->destroy_signal, |
| 1999 | &shsurf->output_destroy_listener); |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2003 | weston_view_set_initial_position(struct weston_view *view, |
| 2004 | struct desktop_shell *shell); |
| 2005 | |
| 2006 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2007 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2008 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2009 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2010 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2011 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2012 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2013 | if (shsurf->fullscreen.black_view) |
| 2014 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2015 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2016 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2017 | if (shsurf->saved_position_valid) |
| 2018 | weston_view_set_position(shsurf->view, |
| 2019 | shsurf->saved_x, shsurf->saved_y); |
| 2020 | else |
| 2021 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Quentin Glidic | 920cf04 | 2016-08-16 14:26:20 +0200 | [diff] [blame] | 2022 | shsurf->saved_position_valid = false; |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2023 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2024 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2025 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2026 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2027 | shsurf->saved_rotation_valid = false; |
| 2028 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2029 | } |
| 2030 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2031 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2032 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2033 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2034 | struct weston_surface *surface = |
| 2035 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2036 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2037 | /* undo all maximized things here */ |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame] | 2038 | shell_surface_set_output(shsurf, get_default_output(surface->compositor)); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2039 | |
| 2040 | if (shsurf->saved_position_valid) |
| 2041 | weston_view_set_position(shsurf->view, |
| 2042 | shsurf->saved_x, shsurf->saved_y); |
| 2043 | else |
| 2044 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Quentin Glidic | 920cf04 | 2016-08-16 14:26:20 +0200 | [diff] [blame] | 2045 | shsurf->saved_position_valid = false; |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2046 | |
| 2047 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2048 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2049 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2050 | shsurf->saved_rotation_valid = false; |
| 2051 | } |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2052 | } |
| 2053 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2054 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2055 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2056 | { |
| 2057 | struct shell_surface *shsurf; |
| 2058 | struct workspace *current_ws; |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2059 | struct weston_view *view; |
| 2060 | |
| 2061 | view = get_default_view(surface); |
| 2062 | if (!view) |
| 2063 | return; |
| 2064 | |
| 2065 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2066 | |
| 2067 | shsurf = get_shell_surface(surface); |
| 2068 | current_ws = get_current_workspace(shsurf->shell); |
| 2069 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2070 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2071 | 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] | 2072 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2073 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 2074 | surface_keyboard_focus_lost(surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2075 | |
| 2076 | shell_surface_update_child_surface_layers(shsurf); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2077 | weston_view_damage_below(view); |
| 2078 | } |
| 2079 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2080 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2081 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2082 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2083 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2084 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2085 | } |
| 2086 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2087 | static int |
| 2088 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2089 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2090 | struct weston_view *fs_view = surface->committed_private; |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2091 | struct weston_surface *fs_surface = fs_view->surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2092 | int n; |
| 2093 | int rem; |
| 2094 | int ret; |
| 2095 | |
| 2096 | n = snprintf(buf, len, "black background surface for "); |
| 2097 | if (n < 0) |
| 2098 | return n; |
| 2099 | |
| 2100 | rem = (int)len - n; |
| 2101 | if (rem < 0) |
| 2102 | rem = 0; |
| 2103 | |
| 2104 | if (fs_surface->get_label) |
| 2105 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2106 | else |
| 2107 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2108 | |
| 2109 | if (ret < 0) |
| 2110 | return n; |
| 2111 | |
| 2112 | return n + ret; |
| 2113 | } |
| 2114 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2115 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2116 | 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] | 2117 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2118 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2119 | create_black_surface(struct weston_compositor *ec, |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2120 | struct weston_view *fs_view, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2121 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2122 | { |
| 2123 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2124 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2125 | |
| 2126 | surface = weston_surface_create(ec); |
| 2127 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2128 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2129 | return NULL; |
| 2130 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2131 | view = weston_view_create(surface); |
| 2132 | if (surface == NULL) { |
| 2133 | weston_log("no memory\n"); |
| 2134 | weston_surface_destroy(surface); |
| 2135 | return NULL; |
| 2136 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2137 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2138 | surface->committed = black_surface_committed; |
| 2139 | surface->committed_private = fs_view; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2140 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2141 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2142 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2143 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2144 | pixman_region32_fini(&surface->input); |
| 2145 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2146 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2147 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2148 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2149 | |
| 2150 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2151 | } |
| 2152 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2153 | static void |
| 2154 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2155 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2156 | struct weston_surface *surface = |
| 2157 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2158 | struct weston_output *output = shsurf->fullscreen_output; |
| 2159 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2160 | assert(weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2161 | |
| 2162 | if (!shsurf->fullscreen.black_view) |
| 2163 | shsurf->fullscreen.black_view = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2164 | create_black_surface(surface->compositor, |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2165 | shsurf->view, |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2166 | output->x, output->y, |
| 2167 | output->width, |
| 2168 | output->height); |
| 2169 | |
| 2170 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2171 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2172 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2173 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2174 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2175 | weston_surface_damage(surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2176 | |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 2177 | shsurf->fullscreen.black_view->is_mapped = true; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2178 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2179 | } |
| 2180 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2181 | /* Create black surface and append it to the associated fullscreen surface. |
| 2182 | * Handle size dismatch and positioning according to the method. */ |
| 2183 | static void |
| 2184 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2185 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2186 | struct weston_surface *surface = |
| 2187 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2188 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2189 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2190 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2191 | weston_layer_entry_remove(&shsurf->view->layer_link); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2192 | weston_layer_entry_insert(&shsurf->shell->fullscreen_layer.view_list, |
| 2193 | &shsurf->view->layer_link); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2194 | |
Pekka Paalanen | c63acc4 | 2018-05-02 10:21:58 +0200 | [diff] [blame] | 2195 | if (!shsurf->fullscreen_output) { |
| 2196 | /* If there is no output, there's not much we can do. |
| 2197 | * Position the window somewhere, whatever. */ |
| 2198 | weston_view_set_position(shsurf->view, 0, 0); |
| 2199 | return; |
| 2200 | } |
| 2201 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2202 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2203 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2204 | surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2205 | &surf_width, &surf_height); |
| 2206 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2207 | if (surface->buffer_ref.buffer) |
| 2208 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2209 | } |
| 2210 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2211 | static void |
| 2212 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2213 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2214 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2215 | } |
| 2216 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2217 | static struct weston_output * |
| 2218 | get_focused_output(struct weston_compositor *compositor) |
| 2219 | { |
| 2220 | struct weston_seat *seat; |
| 2221 | struct weston_output *output = NULL; |
| 2222 | |
| 2223 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2224 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2225 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2226 | struct weston_keyboard *keyboard = |
| 2227 | weston_seat_get_keyboard(seat); |
| 2228 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2229 | /* Priority has touch focus, then pointer and |
| 2230 | * then keyboard focus. We should probably have |
Emmanuel Gil Peyrot | 426c246 | 2019-02-20 16:33:32 +0100 | [diff] [blame] | 2231 | * three for loops and check first for touch, |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2232 | * then for pointer, etc. but unless somebody has some |
| 2233 | * objections, I think this is sufficient. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2234 | if (touch && touch->focus) |
| 2235 | output = touch->focus->output; |
| 2236 | else if (pointer && pointer->focus) |
| 2237 | output = pointer->focus->output; |
| 2238 | else if (keyboard && keyboard->focus) |
| 2239 | output = keyboard->focus->output; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2240 | |
| 2241 | if (output) |
| 2242 | break; |
| 2243 | } |
| 2244 | |
| 2245 | return output; |
| 2246 | } |
| 2247 | |
| 2248 | static void |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2249 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2250 | { |
| 2251 | struct shell_seat *shseat = |
| 2252 | container_of(listener, |
| 2253 | struct shell_seat, seat_destroy_listener); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2254 | |
| 2255 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2256 | free(shseat); |
| 2257 | } |
| 2258 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2259 | static void |
| 2260 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 2261 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2262 | struct weston_keyboard *keyboard; |
| 2263 | struct weston_pointer *pointer; |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2264 | struct shell_seat *seat; |
| 2265 | |
| 2266 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2267 | keyboard = weston_seat_get_keyboard(seat->seat); |
| 2268 | pointer = weston_seat_get_pointer(seat->seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2269 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2270 | if (keyboard && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2271 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2272 | wl_signal_add(&keyboard->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2273 | &seat->keyboard_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2274 | } else if (!keyboard) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 2275 | wl_list_remove(&seat->keyboard_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2276 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 2277 | } |
| 2278 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2279 | if (pointer && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2280 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2281 | wl_signal_add(&pointer->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2282 | &seat->pointer_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2283 | } else if (!pointer) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 2284 | wl_list_remove(&seat->pointer_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2285 | wl_list_init(&seat->pointer_focus_listener.link); |
| 2286 | } |
| 2287 | } |
| 2288 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2289 | static struct shell_seat * |
| 2290 | create_shell_seat(struct weston_seat *seat) |
| 2291 | { |
| 2292 | struct shell_seat *shseat; |
| 2293 | |
| 2294 | shseat = calloc(1, sizeof *shseat); |
| 2295 | if (!shseat) { |
| 2296 | weston_log("no memory to allocate shell seat\n"); |
| 2297 | return NULL; |
| 2298 | } |
| 2299 | |
| 2300 | shseat->seat = seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2301 | |
| 2302 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2303 | wl_signal_add(&seat->destroy_signal, |
| 2304 | &shseat->seat_destroy_listener); |
| 2305 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2306 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 2307 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 2308 | |
| 2309 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 2310 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 2311 | |
| 2312 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 2313 | wl_signal_add(&seat->updated_caps_signal, |
| 2314 | &shseat->caps_changed_listener); |
| 2315 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 2316 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2317 | return shseat; |
| 2318 | } |
| 2319 | |
| 2320 | static struct shell_seat * |
| 2321 | get_shell_seat(struct weston_seat *seat) |
| 2322 | { |
| 2323 | struct wl_listener *listener; |
| 2324 | |
| 2325 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2326 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2327 | |
| 2328 | return container_of(listener, |
| 2329 | struct shell_seat, seat_destroy_listener); |
| 2330 | } |
| 2331 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2332 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2333 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 2334 | { |
| 2335 | struct shell_surface *shsurf = data; |
| 2336 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2337 | weston_surface_destroy(shsurf->view->surface); |
Pekka Paalanen | 9962800 | 2018-05-22 12:48:35 +0300 | [diff] [blame] | 2338 | |
| 2339 | if (shsurf->output_destroy_listener.notify) { |
| 2340 | wl_list_remove(&shsurf->output_destroy_listener.link); |
| 2341 | shsurf->output_destroy_listener.notify = NULL; |
| 2342 | } |
| 2343 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2344 | free(shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2348 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 2349 | { |
| 2350 | struct shell_surface *shsurf = data; |
| 2351 | struct wl_event_loop *loop; |
| 2352 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2353 | loop = wl_display_get_event_loop(shsurf->shell->compositor->wl_display); |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2354 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2355 | if (weston_view_is_mapped(shsurf->view)) { |
Tomohito Esaki | 5898cd3 | 2019-04-01 17:50:14 +0900 | [diff] [blame] | 2356 | weston_view_unmap(shsurf->view); |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2357 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2358 | } |
| 2359 | } |
| 2360 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 2361 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2362 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2363 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2364 | if (weston_surface_is_desktop_surface(surface)) { |
| 2365 | struct weston_desktop_surface *desktop_surface = |
| 2366 | weston_surface_get_desktop_surface(surface); |
| 2367 | return weston_desktop_surface_get_user_data(desktop_surface); |
| 2368 | } |
| 2369 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2370 | } |
| 2371 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2372 | /* |
| 2373 | * libweston-desktop |
| 2374 | */ |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2375 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2376 | static void |
| 2377 | desktop_surface_added(struct weston_desktop_surface *desktop_surface, |
| 2378 | void *shell) |
| 2379 | { |
| 2380 | struct weston_desktop_client *client = |
| 2381 | weston_desktop_surface_get_client(desktop_surface); |
| 2382 | struct wl_client *wl_client = |
| 2383 | weston_desktop_client_get_client(client); |
| 2384 | struct weston_view *view; |
| 2385 | struct shell_surface *shsurf; |
| 2386 | struct weston_surface *surface = |
| 2387 | weston_desktop_surface_get_surface(desktop_surface); |
| 2388 | |
| 2389 | view = weston_desktop_surface_create_view(desktop_surface); |
| 2390 | if (!view) |
| 2391 | return; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2392 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2393 | shsurf = calloc(1, sizeof *shsurf); |
| 2394 | if (!shsurf) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2395 | if (wl_client) |
| 2396 | wl_client_post_no_memory(wl_client); |
| 2397 | else |
| 2398 | weston_log("no memory to allocate shell surface\n"); |
| 2399 | return; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2400 | } |
| 2401 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2402 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2403 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2404 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2405 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2406 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2407 | shsurf->saved_rotation_valid = false; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2408 | shsurf->desktop_surface = desktop_surface; |
| 2409 | shsurf->view = view; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2410 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2411 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2412 | |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame] | 2413 | shell_surface_set_output( |
| 2414 | shsurf, get_default_output(shsurf->shell->compositor)); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2415 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2416 | wl_signal_init(&shsurf->destroy_signal); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2417 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2418 | /* empty when not in use */ |
| 2419 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2420 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2421 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2422 | wl_list_init(&shsurf->workspace_transform.link); |
| 2423 | |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2424 | /* |
| 2425 | * initialize list as well as link. The latter allows to use |
| 2426 | * wl_list_remove() even when this surface is not in another list. |
| 2427 | */ |
| 2428 | wl_list_init(&shsurf->children_list); |
| 2429 | wl_list_init(&shsurf->children_link); |
| 2430 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2431 | weston_desktop_surface_set_user_data(desktop_surface, shsurf); |
| 2432 | weston_desktop_surface_set_activated(desktop_surface, |
| 2433 | shsurf->focus_count > 0); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2434 | } |
| 2435 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2436 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2437 | desktop_surface_removed(struct weston_desktop_surface *desktop_surface, |
| 2438 | void *shell) |
| 2439 | { |
| 2440 | struct shell_surface *shsurf = |
| 2441 | weston_desktop_surface_get_user_data(desktop_surface); |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2442 | struct shell_surface *shsurf_child, *tmp; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2443 | struct weston_surface *surface = |
| 2444 | weston_desktop_surface_get_surface(desktop_surface); |
| 2445 | |
| 2446 | if (!shsurf) |
| 2447 | return; |
| 2448 | |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2449 | wl_list_for_each_safe(shsurf_child, tmp, &shsurf->children_list, children_link) { |
| 2450 | wl_list_remove(&shsurf_child->children_link); |
| 2451 | wl_list_init(&shsurf_child->children_link); |
| 2452 | } |
| 2453 | wl_list_remove(&shsurf->children_link); |
| 2454 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2455 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2456 | |
| 2457 | if (shsurf->fullscreen.black_view) |
| 2458 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2459 | |
| 2460 | weston_surface_set_label_func(surface, NULL); |
| 2461 | weston_desktop_surface_set_user_data(shsurf->desktop_surface, NULL); |
| 2462 | shsurf->desktop_surface = NULL; |
| 2463 | |
Quentin Glidic | f01ecee | 2016-08-16 10:52:46 +0200 | [diff] [blame] | 2464 | weston_desktop_surface_unlink_view(shsurf->view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2465 | if (weston_surface_is_mapped(surface) && |
| 2466 | shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
Erik Kurzinger | 04918f3 | 2021-05-18 11:49:37 -0400 | [diff] [blame] | 2467 | |
Emmanuel Gil Peyrot | eff793a | 2021-07-31 17:25:41 +0200 | [diff] [blame] | 2468 | if (shsurf->shell->compositor->state == WESTON_COMPOSITOR_ACTIVE) { |
| 2469 | pixman_region32_fini(&surface->pending.input); |
| 2470 | pixman_region32_init(&surface->pending.input); |
| 2471 | pixman_region32_fini(&surface->input); |
| 2472 | pixman_region32_init(&surface->input); |
| 2473 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 2474 | fade_out_done, shsurf); |
| 2475 | return; |
| 2476 | } else { |
Marius Vlad | c30cb29 | 2021-08-02 15:47:16 +0300 | [diff] [blame^] | 2477 | weston_surface_destroy(surface); |
Emmanuel Gil Peyrot | eff793a | 2021-07-31 17:25:41 +0200 | [diff] [blame] | 2478 | } |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2479 | } |
Erik Kurzinger | 04918f3 | 2021-05-18 11:49:37 -0400 | [diff] [blame] | 2480 | |
Marius Vlad | c30cb29 | 2021-08-02 15:47:16 +0300 | [diff] [blame^] | 2481 | weston_view_destroy(shsurf->view); |
Erik Kurzinger | 04918f3 | 2021-05-18 11:49:37 -0400 | [diff] [blame] | 2482 | |
| 2483 | if (shsurf->output_destroy_listener.notify) { |
| 2484 | wl_list_remove(&shsurf->output_destroy_listener.link); |
| 2485 | shsurf->output_destroy_listener.notify = NULL; |
| 2486 | } |
| 2487 | |
| 2488 | free(shsurf); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | static void |
| 2492 | set_maximized_position(struct desktop_shell *shell, |
| 2493 | struct shell_surface *shsurf) |
| 2494 | { |
| 2495 | pixman_rectangle32_t area; |
| 2496 | struct weston_geometry geometry; |
| 2497 | |
| 2498 | get_output_work_area(shell, shsurf->output, &area); |
| 2499 | geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
| 2500 | |
| 2501 | weston_view_set_position(shsurf->view, |
| 2502 | area.x - geometry.x, |
| 2503 | area.y - geometry.y); |
| 2504 | } |
| 2505 | |
| 2506 | static void |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2507 | set_position_from_xwayland(struct shell_surface *shsurf) |
| 2508 | { |
| 2509 | struct weston_geometry geometry; |
| 2510 | float x; |
| 2511 | float y; |
| 2512 | |
| 2513 | assert(shsurf->xwayland.is_set); |
| 2514 | |
| 2515 | geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
| 2516 | x = shsurf->xwayland.x - geometry.x; |
| 2517 | y = shsurf->xwayland.y - geometry.y; |
| 2518 | |
| 2519 | weston_view_set_position(shsurf->view, x, y); |
| 2520 | |
| 2521 | #ifdef WM_DEBUG |
| 2522 | weston_log("%s: XWM %d, %d; geometry %d, %d; view %f, %f\n", |
| 2523 | __func__, shsurf->xwayland.x, shsurf->xwayland.y, |
| 2524 | geometry.x, geometry.y, x, y); |
| 2525 | #endif |
| 2526 | } |
| 2527 | |
| 2528 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2529 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
| 2530 | int32_t sx, int32_t sy) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2531 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2532 | struct weston_surface *surface = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2533 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2534 | struct weston_compositor *compositor = shell->compositor; |
| 2535 | struct weston_seat *seat; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2536 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2537 | /* initial positioning, see also configure() */ |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2538 | if (shsurf->state.fullscreen) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2539 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 2540 | shell_map_fullscreen(shsurf); |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2541 | } else if (shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2542 | set_maximized_position(shell, shsurf); |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2543 | } else if (shsurf->xwayland.is_set) { |
| 2544 | set_position_from_xwayland(shsurf); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 2545 | } else { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2546 | weston_view_set_initial_position(shsurf->view, shell); |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 2547 | } |
| 2548 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2549 | /* Surface stacking order, see also activate(). */ |
| 2550 | shell_surface_update_layer(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2551 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2552 | weston_view_update_transform(shsurf->view); |
| 2553 | shsurf->view->is_mapped = true; |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2554 | if (shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2555 | surface->output = shsurf->output; |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 2556 | weston_view_set_output(shsurf->view, shsurf->output); |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2557 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2558 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2559 | if (!shell->locked) { |
| 2560 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 2561 | activate(shell, shsurf->view, seat, |
| 2562 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
| 2563 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2564 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2565 | if (!shsurf->state.fullscreen && !shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2566 | switch (shell->win_animation_type) { |
| 2567 | case ANIMATION_FADE: |
| 2568 | weston_fade_run(shsurf->view, 0.0, 1.0, 300.0, NULL, NULL); |
| 2569 | break; |
| 2570 | case ANIMATION_ZOOM: |
| 2571 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
| 2572 | break; |
| 2573 | case ANIMATION_NONE: |
| 2574 | default: |
| 2575 | break; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 2576 | } |
| 2577 | } |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2581 | desktop_surface_committed(struct weston_desktop_surface *desktop_surface, |
| 2582 | int32_t sx, int32_t sy, void *data) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2583 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2584 | struct shell_surface *shsurf = |
| 2585 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2586 | struct weston_surface *surface = |
| 2587 | weston_desktop_surface_get_surface(desktop_surface); |
| 2588 | struct weston_view *view = shsurf->view; |
| 2589 | struct desktop_shell *shell = data; |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2590 | bool was_fullscreen; |
| 2591 | bool was_maximized; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2592 | |
| 2593 | if (surface->width == 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2594 | return; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2595 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2596 | was_fullscreen = shsurf->state.fullscreen; |
| 2597 | was_maximized = shsurf->state.maximized; |
| 2598 | |
| 2599 | shsurf->state.fullscreen = |
| 2600 | weston_desktop_surface_get_fullscreen(desktop_surface); |
| 2601 | shsurf->state.maximized = |
| 2602 | weston_desktop_surface_get_maximized(desktop_surface); |
| 2603 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2604 | if (!weston_surface_is_mapped(surface)) { |
| 2605 | map(shell, shsurf, sx, sy); |
| 2606 | surface->is_mapped = true; |
| 2607 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) |
| 2608 | ++surface->ref_count; |
| 2609 | return; |
| 2610 | } |
| 2611 | |
| 2612 | if (sx == 0 && sy == 0 && |
| 2613 | shsurf->last_width == surface->width && |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2614 | shsurf->last_height == surface->height && |
| 2615 | was_fullscreen == shsurf->state.fullscreen && |
| 2616 | was_maximized == shsurf->state.maximized) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2617 | return; |
| 2618 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2619 | if (was_fullscreen) |
| 2620 | unset_fullscreen(shsurf); |
| 2621 | if (was_maximized) |
| 2622 | unset_maximized(shsurf); |
| 2623 | |
Quentin Glidic | 920cf04 | 2016-08-16 14:26:20 +0200 | [diff] [blame] | 2624 | if ((shsurf->state.fullscreen || shsurf->state.maximized) && |
| 2625 | !shsurf->saved_position_valid) { |
| 2626 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2627 | shsurf->saved_y = shsurf->view->geometry.y; |
| 2628 | shsurf->saved_position_valid = true; |
| 2629 | |
| 2630 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2631 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2632 | wl_list_init(&shsurf->rotation.transform.link); |
| 2633 | weston_view_geometry_dirty(shsurf->view); |
| 2634 | shsurf->saved_rotation_valid = true; |
| 2635 | } |
| 2636 | } |
| 2637 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2638 | if (shsurf->state.fullscreen) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2639 | shell_configure_fullscreen(shsurf); |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2640 | } else if (shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2641 | set_maximized_position(shell, shsurf); |
| 2642 | surface->output = shsurf->output; |
| 2643 | } else { |
| 2644 | float from_x, from_y; |
| 2645 | float to_x, to_y; |
| 2646 | float x, y; |
| 2647 | |
| 2648 | if (shsurf->resize_edges) { |
| 2649 | sx = 0; |
| 2650 | sy = 0; |
| 2651 | } |
| 2652 | |
| 2653 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 2654 | sx = shsurf->last_width - surface->width; |
| 2655 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 2656 | sy = shsurf->last_height - surface->height; |
| 2657 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2658 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 2659 | weston_view_to_global_float(shsurf->view, sx, sy, &to_x, &to_y); |
| 2660 | x = shsurf->view->geometry.x + to_x - from_x; |
| 2661 | y = shsurf->view->geometry.y + to_y - from_y; |
| 2662 | |
| 2663 | weston_view_set_position(shsurf->view, x, y); |
| 2664 | } |
| 2665 | |
Emmanuel Gil Peyrot | c394179 | 2017-04-04 18:49:33 +0100 | [diff] [blame] | 2666 | shsurf->last_width = surface->width; |
| 2667 | shsurf->last_height = surface->height; |
| 2668 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2669 | /* XXX: would a fullscreen surface need the same handling? */ |
| 2670 | if (surface->output) { |
| 2671 | wl_list_for_each(view, &surface->views, surface_link) |
| 2672 | weston_view_update_transform(view); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2673 | } |
| 2674 | } |
| 2675 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2676 | static void |
Derek Foreman | 927d9e2 | 2017-10-06 14:37:44 -0500 | [diff] [blame] | 2677 | get_maximized_size(struct shell_surface *shsurf, int32_t *width, int32_t *height) |
| 2678 | { |
| 2679 | struct desktop_shell *shell; |
| 2680 | pixman_rectangle32_t area; |
| 2681 | |
| 2682 | shell = shell_surface_get_shell(shsurf); |
| 2683 | get_output_work_area(shell, shsurf->output, &area); |
| 2684 | |
| 2685 | *width = area.width; |
| 2686 | *height = area.height; |
| 2687 | } |
| 2688 | |
| 2689 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2690 | set_fullscreen(struct shell_surface *shsurf, bool fullscreen, |
| 2691 | struct weston_output *output) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2692 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2693 | struct weston_desktop_surface *desktop_surface = shsurf->desktop_surface; |
| 2694 | struct weston_surface *surface = |
| 2695 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2696 | int32_t width = 0, height = 0; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2697 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2698 | if (fullscreen) { |
| 2699 | /* handle clients launching in fullscreen */ |
| 2700 | if (output == NULL && !weston_surface_is_mapped(surface)) { |
| 2701 | /* Set the output to the one that has focus currently. */ |
| 2702 | output = get_focused_output(surface->compositor); |
| 2703 | } |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 2704 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2705 | shell_surface_set_output(shsurf, output); |
| 2706 | shsurf->fullscreen_output = shsurf->output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2707 | |
Marius Vlad | 6ebda36 | 2020-03-28 00:23:14 +0200 | [diff] [blame] | 2708 | if (shsurf->output) { |
| 2709 | width = shsurf->output->width; |
| 2710 | height = shsurf->output->height; |
| 2711 | } |
Derek Foreman | e1af3d8 | 2017-10-06 14:37:45 -0500 | [diff] [blame] | 2712 | } else if (weston_desktop_surface_get_maximized(desktop_surface)) { |
| 2713 | get_maximized_size(shsurf, &width, &height); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2714 | } |
| 2715 | weston_desktop_surface_set_fullscreen(desktop_surface, fullscreen); |
| 2716 | weston_desktop_surface_set_size(desktop_surface, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2717 | } |
| 2718 | |
| 2719 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2720 | desktop_surface_move(struct weston_desktop_surface *desktop_surface, |
| 2721 | struct weston_seat *seat, uint32_t serial, void *shell) |
| 2722 | { |
| 2723 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2724 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2725 | struct shell_surface *shsurf = |
| 2726 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2727 | struct weston_surface *surface = |
| 2728 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2729 | struct wl_resource *resource = surface->resource; |
| 2730 | struct weston_surface *focus; |
| 2731 | |
| 2732 | if (pointer && |
| 2733 | pointer->focus && |
| 2734 | pointer->button_count > 0 && |
| 2735 | pointer->grab_serial == serial) { |
| 2736 | focus = weston_surface_get_main_surface(pointer->focus->surface); |
| 2737 | if ((focus == surface) && |
| 2738 | (surface_move(shsurf, pointer, true) < 0)) |
| 2739 | wl_resource_post_no_memory(resource); |
| 2740 | } else if (touch && |
| 2741 | touch->focus && |
| 2742 | touch->grab_serial == serial) { |
| 2743 | focus = weston_surface_get_main_surface(touch->focus->surface); |
| 2744 | if ((focus == surface) && |
| 2745 | (surface_touch_move(shsurf, touch) < 0)) |
| 2746 | wl_resource_post_no_memory(resource); |
| 2747 | } |
| 2748 | } |
| 2749 | |
| 2750 | static void |
| 2751 | desktop_surface_resize(struct weston_desktop_surface *desktop_surface, |
| 2752 | struct weston_seat *seat, uint32_t serial, |
| 2753 | enum weston_desktop_surface_edge edges, void *shell) |
| 2754 | { |
| 2755 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2756 | struct shell_surface *shsurf = |
| 2757 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2758 | struct weston_surface *surface = |
| 2759 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2760 | struct wl_resource *resource = surface->resource; |
| 2761 | struct weston_surface *focus; |
| 2762 | |
| 2763 | if (!pointer || |
| 2764 | pointer->button_count == 0 || |
| 2765 | pointer->grab_serial != serial || |
| 2766 | pointer->focus == NULL) |
| 2767 | return; |
| 2768 | |
| 2769 | focus = weston_surface_get_main_surface(pointer->focus->surface); |
| 2770 | if (focus != surface) |
| 2771 | return; |
| 2772 | |
| 2773 | if (surface_resize(shsurf, pointer, edges) < 0) |
| 2774 | wl_resource_post_no_memory(resource); |
| 2775 | } |
| 2776 | |
| 2777 | static void |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2778 | desktop_surface_set_parent(struct weston_desktop_surface *desktop_surface, |
| 2779 | struct weston_desktop_surface *parent, |
| 2780 | void *shell) |
| 2781 | { |
Marius Vlad | a27658e | 2020-01-17 12:32:55 +0200 | [diff] [blame] | 2782 | struct shell_surface *shsurf_parent; |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2783 | struct shell_surface *shsurf = |
| 2784 | weston_desktop_surface_get_user_data(desktop_surface); |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2785 | |
Marius Vlad | a27658e | 2020-01-17 12:32:55 +0200 | [diff] [blame] | 2786 | /* unlink any potential child */ |
| 2787 | wl_list_remove(&shsurf->children_link); |
| 2788 | |
| 2789 | if (parent) { |
| 2790 | shsurf_parent = weston_desktop_surface_get_user_data(parent); |
| 2791 | wl_list_insert(shsurf_parent->children_list.prev, |
| 2792 | &shsurf->children_link); |
| 2793 | } else { |
| 2794 | wl_list_init(&shsurf->children_link); |
| 2795 | } |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2796 | } |
| 2797 | |
| 2798 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2799 | desktop_surface_fullscreen_requested(struct weston_desktop_surface *desktop_surface, |
| 2800 | bool fullscreen, |
| 2801 | struct weston_output *output, void *shell) |
| 2802 | { |
| 2803 | struct shell_surface *shsurf = |
| 2804 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2805 | |
| 2806 | set_fullscreen(shsurf, fullscreen, output); |
| 2807 | } |
| 2808 | |
| 2809 | static void |
| 2810 | set_maximized(struct shell_surface *shsurf, bool maximized) |
| 2811 | { |
| 2812 | struct weston_desktop_surface *desktop_surface = shsurf->desktop_surface; |
| 2813 | struct weston_surface *surface = |
| 2814 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2815 | int32_t width = 0, height = 0; |
| 2816 | |
| 2817 | if (maximized) { |
| 2818 | struct weston_output *output; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2819 | |
| 2820 | if (!weston_surface_is_mapped(surface)) |
| 2821 | output = get_focused_output(surface->compositor); |
| 2822 | else |
| 2823 | output = surface->output; |
| 2824 | |
| 2825 | shell_surface_set_output(shsurf, output); |
| 2826 | |
Derek Foreman | 927d9e2 | 2017-10-06 14:37:44 -0500 | [diff] [blame] | 2827 | get_maximized_size(shsurf, &width, &height); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2828 | } |
| 2829 | weston_desktop_surface_set_maximized(desktop_surface, maximized); |
| 2830 | weston_desktop_surface_set_size(desktop_surface, width, height); |
| 2831 | } |
| 2832 | |
| 2833 | static void |
| 2834 | desktop_surface_maximized_requested(struct weston_desktop_surface *desktop_surface, |
| 2835 | bool maximized, void *shell) |
| 2836 | { |
| 2837 | struct shell_surface *shsurf = |
| 2838 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2839 | |
| 2840 | set_maximized(shsurf, maximized); |
| 2841 | } |
| 2842 | |
| 2843 | static void |
| 2844 | desktop_surface_minimized_requested(struct weston_desktop_surface *desktop_surface, |
| 2845 | void *shell) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2846 | { |
| 2847 | struct weston_surface *surface = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2848 | weston_desktop_surface_get_surface(desktop_surface); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2849 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2850 | /* apply compositor's own minimization logic (hide) */ |
| 2851 | set_minimized(surface); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2852 | } |
| 2853 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2854 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2855 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2856 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2857 | struct shell_grab *grab; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2858 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2859 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2860 | return; |
| 2861 | |
| 2862 | grab = malloc(sizeof *grab); |
| 2863 | if (!grab) |
| 2864 | return; |
| 2865 | |
| 2866 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2867 | WESTON_DESKTOP_SHELL_CURSOR_BUSY); |
| 2868 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2869 | * to move it. */ |
| 2870 | shsurf->grabbed = 0; |
| 2871 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2872 | |
| 2873 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2874 | end_busy_cursor(struct weston_compositor *compositor, |
| 2875 | struct weston_desktop_client *desktop_client) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2876 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 2877 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2878 | struct shell_grab *grab; |
| 2879 | struct weston_seat *seat; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 2880 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2881 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 2882 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2883 | struct weston_desktop_client *grab_client; |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 2884 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2885 | if (!pointer) |
| 2886 | continue; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2887 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2888 | if (pointer->grab->interface != &busy_cursor_grab_interface) |
| 2889 | continue; |
| 2890 | |
| 2891 | grab = (struct shell_grab *) pointer->grab; |
| 2892 | shsurf = grab->shsurf; |
| 2893 | if (!shsurf) |
| 2894 | continue; |
| 2895 | |
| 2896 | grab_client = |
| 2897 | weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 2898 | if (grab_client == desktop_client) { |
| 2899 | shell_grab_end(grab); |
| 2900 | free(grab); |
| 2901 | } |
| 2902 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2906 | desktop_surface_set_unresponsive(struct weston_desktop_surface *desktop_surface, |
| 2907 | void *user_data) |
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 | struct shell_surface *shsurf = |
| 2910 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2911 | bool *unresponsive = user_data; |
| 2912 | |
| 2913 | shsurf->unresponsive = *unresponsive; |
| 2914 | } |
| 2915 | |
| 2916 | static void |
| 2917 | desktop_surface_ping_timeout(struct weston_desktop_client *desktop_client, |
| 2918 | void *shell_) |
| 2919 | { |
| 2920 | struct desktop_shell *shell = shell_; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2921 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2922 | struct weston_seat *seat; |
| 2923 | bool unresponsive = true; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2924 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2925 | weston_desktop_client_for_each_surface(desktop_client, |
| 2926 | desktop_surface_set_unresponsive, |
| 2927 | &unresponsive); |
| 2928 | |
| 2929 | |
| 2930 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 2931 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2932 | struct weston_desktop_client *grab_client; |
| 2933 | |
| 2934 | if (!pointer || !pointer->focus) |
| 2935 | continue; |
| 2936 | |
| 2937 | shsurf = get_shell_surface(pointer->focus->surface); |
| 2938 | if (!shsurf) |
| 2939 | continue; |
| 2940 | |
| 2941 | grab_client = |
| 2942 | weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 2943 | if (grab_client == desktop_client) |
| 2944 | set_busy_cursor(shsurf, pointer); |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 2945 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2946 | } |
| 2947 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2948 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2949 | desktop_surface_pong(struct weston_desktop_client *desktop_client, |
| 2950 | void *shell_) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2951 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2952 | struct desktop_shell *shell = shell_; |
| 2953 | bool unresponsive = false; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2954 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2955 | weston_desktop_client_for_each_surface(desktop_client, |
| 2956 | desktop_surface_set_unresponsive, |
| 2957 | &unresponsive); |
| 2958 | end_busy_cursor(shell->compositor, desktop_client); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2959 | } |
| 2960 | |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2961 | static void |
| 2962 | desktop_surface_set_xwayland_position(struct weston_desktop_surface *surface, |
| 2963 | int32_t x, int32_t y, void *shell_) |
| 2964 | { |
| 2965 | struct shell_surface *shsurf = |
| 2966 | weston_desktop_surface_get_user_data(surface); |
| 2967 | |
| 2968 | shsurf->xwayland.x = x; |
| 2969 | shsurf->xwayland.y = y; |
| 2970 | shsurf->xwayland.is_set = true; |
| 2971 | } |
| 2972 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2973 | static const struct weston_desktop_api shell_desktop_api = { |
| 2974 | .struct_size = sizeof(struct weston_desktop_api), |
| 2975 | .surface_added = desktop_surface_added, |
| 2976 | .surface_removed = desktop_surface_removed, |
| 2977 | .committed = desktop_surface_committed, |
| 2978 | .move = desktop_surface_move, |
| 2979 | .resize = desktop_surface_resize, |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 2980 | .set_parent = desktop_surface_set_parent, |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2981 | .fullscreen_requested = desktop_surface_fullscreen_requested, |
| 2982 | .maximized_requested = desktop_surface_maximized_requested, |
| 2983 | .minimized_requested = desktop_surface_minimized_requested, |
| 2984 | .ping_timeout = desktop_surface_ping_timeout, |
| 2985 | .pong = desktop_surface_pong, |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2986 | .set_xwayland_position = desktop_surface_set_xwayland_position, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2987 | }; |
| 2988 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2989 | /* ************************ * |
| 2990 | * end of libweston-desktop * |
| 2991 | * ************************ */ |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2992 | static void |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 2993 | 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] | 2994 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2995 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2996 | |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 2997 | if (!ev->output) |
| 2998 | return; |
| 2999 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3000 | 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] | 3001 | if (v->output == ev->output && v != ev) { |
| 3002 | weston_view_unmap(v); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3003 | v->surface->committed = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3004 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3005 | } |
| 3006 | } |
| 3007 | |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 3008 | 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] | 3009 | ev->surface->is_mapped = true; |
| 3010 | ev->is_mapped = true; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3011 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3012 | if (wl_list_empty(&ev->layer_link.link)) { |
| 3013 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3014 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3015 | } |
| 3016 | } |
| 3017 | |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3018 | |
| 3019 | static struct shell_output * |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3020 | find_shell_output_from_weston_output(struct desktop_shell *shell, |
| 3021 | struct weston_output *output) |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3022 | { |
| 3023 | struct shell_output *shell_output; |
| 3024 | |
| 3025 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 3026 | if (shell_output->output == output) |
| 3027 | return shell_output; |
| 3028 | } |
| 3029 | |
| 3030 | return NULL; |
| 3031 | } |
| 3032 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3033 | static int |
| 3034 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3035 | { |
| 3036 | return snprintf(buf, len, "background for output %s", |
Miguel A. Vico | 620f68d | 2019-09-25 11:23:13 -0700 | [diff] [blame] | 3037 | (surface->output ? surface->output->name : "NULL")); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3038 | } |
| 3039 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3040 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3041 | 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] | 3042 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3043 | struct desktop_shell *shell = es->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3044 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3045 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3046 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3047 | |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 3048 | configure_static_view(view, &shell->background_layer, 0, 0); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3052 | handle_background_surface_destroy(struct wl_listener *listener, void *data) |
| 3053 | { |
| 3054 | struct shell_output *output = |
| 3055 | container_of(listener, struct shell_output, background_surface_listener); |
| 3056 | |
| 3057 | weston_log("background surface gone\n"); |
Tomohito Esaki | bf31f6c | 2018-01-31 15:15:45 +0900 | [diff] [blame] | 3058 | wl_list_remove(&output->background_surface_listener.link); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3059 | output->background_surface = NULL; |
| 3060 | } |
| 3061 | |
| 3062 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3063 | desktop_shell_set_background(struct wl_client *client, |
| 3064 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3065 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3066 | struct wl_resource *surface_resource) |
| 3067 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3068 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3069 | struct weston_surface *surface = |
| 3070 | wl_resource_get_user_data(surface_resource); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3071 | struct shell_output *sh_output; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3072 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3073 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3074 | if (surface->committed) { |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3075 | wl_resource_post_error(surface_resource, |
| 3076 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3077 | "surface role already assigned"); |
| 3078 | return; |
| 3079 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3080 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3081 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3082 | weston_view_destroy(view); |
| 3083 | view = weston_view_create(surface); |
| 3084 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3085 | surface->committed = background_committed; |
| 3086 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3087 | weston_surface_set_label_func(surface, background_get_label); |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 3088 | surface->output = weston_head_from_resource(output_resource)->output; |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 3089 | weston_view_set_output(view, surface->output); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3090 | |
| 3091 | sh_output = find_shell_output_from_weston_output(shell, surface->output); |
Pekka Paalanen | ff5e88d | 2017-12-07 11:44:18 +0200 | [diff] [blame] | 3092 | if (sh_output->background_surface) { |
| 3093 | /* The output already has a background, tell our helper |
| 3094 | * there is no need for another one. */ |
| 3095 | weston_desktop_shell_send_configure(resource, 0, |
| 3096 | surface_resource, |
| 3097 | 0, 0); |
| 3098 | } else { |
| 3099 | weston_desktop_shell_send_configure(resource, 0, |
| 3100 | surface_resource, |
| 3101 | surface->output->width, |
| 3102 | surface->output->height); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3103 | |
Pekka Paalanen | ff5e88d | 2017-12-07 11:44:18 +0200 | [diff] [blame] | 3104 | sh_output->background_surface = surface; |
| 3105 | |
| 3106 | sh_output->background_surface_listener.notify = |
| 3107 | handle_background_surface_destroy; |
| 3108 | wl_signal_add(&surface->destroy_signal, |
| 3109 | &sh_output->background_surface_listener); |
| 3110 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3111 | } |
| 3112 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3113 | static int |
| 3114 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3115 | { |
| 3116 | return snprintf(buf, len, "panel for output %s", |
Miguel A. Vico | 620f68d | 2019-09-25 11:23:13 -0700 | [diff] [blame] | 3117 | (surface->output ? surface->output->name : "NULL")); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3118 | } |
| 3119 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3120 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3121 | 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] | 3122 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3123 | struct desktop_shell *shell = es->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3124 | struct weston_view *view; |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 3125 | int width, height; |
| 3126 | int x = 0, y = 0; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3127 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3128 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3129 | |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 3130 | get_panel_size(shell, view, &width, &height); |
| 3131 | switch (shell->panel_position) { |
| 3132 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 3133 | break; |
| 3134 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 3135 | y = view->output->height - height; |
| 3136 | break; |
| 3137 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 3138 | break; |
| 3139 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 3140 | x = view->output->width - width; |
| 3141 | break; |
| 3142 | } |
| 3143 | |
| 3144 | configure_static_view(view, &shell->panel_layer, x, y); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3148 | handle_panel_surface_destroy(struct wl_listener *listener, void *data) |
| 3149 | { |
| 3150 | struct shell_output *output = |
| 3151 | container_of(listener, struct shell_output, panel_surface_listener); |
| 3152 | |
| 3153 | weston_log("panel surface gone\n"); |
Tomohito Esaki | bf31f6c | 2018-01-31 15:15:45 +0900 | [diff] [blame] | 3154 | wl_list_remove(&output->panel_surface_listener.link); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3155 | output->panel_surface = NULL; |
| 3156 | } |
| 3157 | |
| 3158 | |
| 3159 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3160 | desktop_shell_set_panel(struct wl_client *client, |
| 3161 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3162 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3163 | struct wl_resource *surface_resource) |
| 3164 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3165 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3166 | struct weston_surface *surface = |
| 3167 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3168 | struct weston_view *view, *next; |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3169 | struct shell_output *sh_output; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3170 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3171 | if (surface->committed) { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3172 | wl_resource_post_error(surface_resource, |
| 3173 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3174 | "surface role already assigned"); |
| 3175 | return; |
| 3176 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3177 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3178 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3179 | weston_view_destroy(view); |
| 3180 | view = weston_view_create(surface); |
| 3181 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3182 | surface->committed = panel_committed; |
| 3183 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3184 | weston_surface_set_label_func(surface, panel_get_label); |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 3185 | surface->output = weston_head_from_resource(output_resource)->output; |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 3186 | weston_view_set_output(view, surface->output); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3187 | |
| 3188 | sh_output = find_shell_output_from_weston_output(shell, surface->output); |
Pekka Paalanen | 1a0239e | 2017-12-07 11:54:11 +0200 | [diff] [blame] | 3189 | if (sh_output->panel_surface) { |
| 3190 | /* The output already has a panel, tell our helper |
| 3191 | * there is no need for another one. */ |
| 3192 | weston_desktop_shell_send_configure(resource, 0, |
| 3193 | surface_resource, |
| 3194 | 0, 0); |
| 3195 | } else { |
| 3196 | weston_desktop_shell_send_configure(resource, 0, |
| 3197 | surface_resource, |
| 3198 | surface->output->width, |
| 3199 | surface->output->height); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3200 | |
Pekka Paalanen | 1a0239e | 2017-12-07 11:54:11 +0200 | [diff] [blame] | 3201 | sh_output->panel_surface = surface; |
| 3202 | |
| 3203 | sh_output->panel_surface_listener.notify = handle_panel_surface_destroy; |
| 3204 | wl_signal_add(&surface->destroy_signal, &sh_output->panel_surface_listener); |
| 3205 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3206 | } |
| 3207 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3208 | static int |
| 3209 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3210 | { |
| 3211 | return snprintf(buf, len, "lock window"); |
| 3212 | } |
| 3213 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3214 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3215 | 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] | 3216 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3217 | struct desktop_shell *shell = surface->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3218 | struct weston_view *view; |
| 3219 | |
| 3220 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3221 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3222 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3223 | return; |
| 3224 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3225 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3226 | |
| 3227 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3228 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 3229 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3230 | weston_view_update_transform(view); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 3231 | surface->is_mapped = true; |
| 3232 | view->is_mapped = true; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3233 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3234 | } |
| 3235 | } |
| 3236 | |
| 3237 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3238 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3239 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3240 | struct desktop_shell *shell = |
| 3241 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3242 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3243 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3244 | shell->lock_surface = NULL; |
| 3245 | } |
| 3246 | |
| 3247 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3248 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3249 | struct wl_resource *resource, |
| 3250 | struct wl_resource *surface_resource) |
| 3251 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3252 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3253 | struct weston_surface *surface = |
| 3254 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3255 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3256 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3257 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3258 | if (!shell->locked) |
| 3259 | return; |
| 3260 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3261 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3262 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3263 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3264 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3265 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3266 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3267 | weston_view_create(surface); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3268 | surface->committed = lock_surface_committed; |
| 3269 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3270 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3274 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3275 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3276 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3277 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3278 | weston_layer_unset_position(&shell->lock_layer); |
| 3279 | |
| 3280 | if (shell->showing_input_panels) |
| 3281 | weston_layer_set_position(&shell->input_panel_layer, |
| 3282 | WESTON_LAYER_POSITION_TOP_UI); |
| 3283 | weston_layer_set_position(&shell->fullscreen_layer, |
| 3284 | WESTON_LAYER_POSITION_FULLSCREEN); |
| 3285 | weston_layer_set_position(&shell->panel_layer, |
| 3286 | WESTON_LAYER_POSITION_UI); |
| 3287 | weston_layer_set_position(&ws->layer, WESTON_LAYER_POSITION_NORMAL); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3288 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3289 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3290 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3291 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3292 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3293 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3294 | } |
| 3295 | |
| 3296 | static void |
| 3297 | desktop_shell_unlock(struct wl_client *client, |
| 3298 | struct wl_resource *resource) |
| 3299 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3300 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3301 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3302 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3303 | |
| 3304 | if (shell->locked) |
| 3305 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3306 | } |
| 3307 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3308 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3309 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3310 | struct wl_resource *resource, |
| 3311 | struct wl_resource *surface_resource) |
| 3312 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3313 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3314 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3315 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3316 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3317 | } |
| 3318 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3319 | static void |
| 3320 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3321 | struct wl_resource *resource) |
| 3322 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3323 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3324 | |
| 3325 | shell_fade_startup(shell); |
| 3326 | } |
| 3327 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3328 | static void |
| 3329 | desktop_shell_set_panel_position(struct wl_client *client, |
| 3330 | struct wl_resource *resource, |
| 3331 | uint32_t position) |
| 3332 | { |
| 3333 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3334 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3335 | if (position != WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 3336 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 3337 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 3338 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3339 | wl_resource_post_error(resource, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3340 | WESTON_DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3341 | "bad position argument"); |
| 3342 | return; |
| 3343 | } |
| 3344 | |
| 3345 | shell->panel_position = position; |
| 3346 | } |
| 3347 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3348 | static const struct weston_desktop_shell_interface desktop_shell_implementation = { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3349 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3350 | desktop_shell_set_panel, |
| 3351 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3352 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3353 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3354 | desktop_shell_desktop_ready, |
| 3355 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3356 | }; |
| 3357 | |
| 3358 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3359 | move_binding(struct weston_pointer *pointer, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3360 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3361 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3362 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3363 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3364 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3365 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3366 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3367 | return; |
| 3368 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3369 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3370 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3371 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3372 | if (surface == NULL) |
| 3373 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3374 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3375 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3376 | if (shsurf == NULL || |
| 3377 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3378 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3379 | return; |
| 3380 | |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 3381 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3382 | } |
| 3383 | |
| 3384 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3385 | maximize_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3386 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3387 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3388 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3389 | struct weston_surface *surface; |
| 3390 | struct shell_surface *shsurf; |
| 3391 | |
| 3392 | surface = weston_surface_get_main_surface(focus); |
| 3393 | if (surface == NULL) |
| 3394 | return; |
| 3395 | |
| 3396 | shsurf = get_shell_surface(surface); |
| 3397 | if (shsurf == NULL) |
| 3398 | return; |
| 3399 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3400 | set_maximized(shsurf, !weston_desktop_surface_get_maximized(shsurf->desktop_surface)); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3404 | fullscreen_binding(struct weston_keyboard *keyboard, |
| 3405 | const struct timespec *time, uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3406 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3407 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3408 | struct weston_surface *surface; |
| 3409 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3410 | bool fullscreen; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3411 | |
| 3412 | surface = weston_surface_get_main_surface(focus); |
| 3413 | if (surface == NULL) |
| 3414 | return; |
| 3415 | |
| 3416 | shsurf = get_shell_surface(surface); |
| 3417 | if (shsurf == NULL) |
| 3418 | return; |
| 3419 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3420 | fullscreen = |
| 3421 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3422 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3423 | set_fullscreen(shsurf, !fullscreen, NULL); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | static void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 3427 | 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] | 3428 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 3429 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3430 | struct weston_surface *surface; |
| 3431 | struct shell_surface *shsurf; |
| 3432 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3433 | if (touch->focus == NULL) |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 3434 | return; |
| 3435 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3436 | focus = touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3437 | surface = weston_surface_get_main_surface(focus); |
| 3438 | if (surface == NULL) |
| 3439 | return; |
| 3440 | |
| 3441 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3442 | if (shsurf == NULL || |
| 3443 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3444 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3445 | return; |
| 3446 | |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 3447 | surface_touch_move(shsurf, touch); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3451 | resize_binding(struct weston_pointer *pointer, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3452 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3453 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3454 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3455 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3456 | uint32_t edges = 0; |
| 3457 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3458 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3459 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3460 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3461 | return; |
| 3462 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3463 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3464 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3465 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3466 | if (surface == NULL) |
| 3467 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3468 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3469 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3470 | if (shsurf == NULL || |
| 3471 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3472 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3473 | return; |
| 3474 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3475 | weston_view_from_global(shsurf->view, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3476 | wl_fixed_to_int(pointer->grab_x), |
| 3477 | wl_fixed_to_int(pointer->grab_y), |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3478 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3479 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3480 | if (x < surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3481 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3482 | else if (x < 2 * surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3483 | edges |= 0; |
| 3484 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3485 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3486 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3487 | if (y < surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3488 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3489 | else if (y < 2 * surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3490 | edges |= 0; |
| 3491 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3492 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3493 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3494 | surface_resize(shsurf, pointer, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | static void |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 3498 | surface_opacity_binding(struct weston_pointer *pointer, |
| 3499 | const struct timespec *time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3500 | struct weston_pointer_axis_event *event, |
| 3501 | void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3502 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3503 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3504 | struct shell_surface *shsurf; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3505 | struct weston_surface *focus = pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3506 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3507 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3508 | /* XXX: broken for windows containing sub-surfaces */ |
| 3509 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3510 | if (surface == NULL) |
| 3511 | return; |
| 3512 | |
| 3513 | shsurf = get_shell_surface(surface); |
| 3514 | if (!shsurf) |
| 3515 | return; |
| 3516 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 3517 | shsurf->view->alpha -= event->value * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3518 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3519 | if (shsurf->view->alpha > 1.0) |
| 3520 | shsurf->view->alpha = 1.0; |
| 3521 | if (shsurf->view->alpha < step) |
| 3522 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3523 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3524 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3525 | weston_surface_damage(surface); |
| 3526 | } |
| 3527 | |
| 3528 | static void |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 3529 | do_zoom(struct weston_seat *seat, const struct timespec *time, uint32_t key, |
| 3530 | uint32_t axis, double value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3531 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 3532 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3533 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3534 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3535 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3536 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3537 | if (!pointer) { |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 3538 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 3539 | return; |
| 3540 | } |
| 3541 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3542 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3543 | if (pixman_region32_contains_point(&output->region, |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3544 | wl_fixed_to_double(pointer->x), |
| 3545 | wl_fixed_to_double(pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3546 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3547 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3548 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3549 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3550 | increment = -output->zoom.increment; |
| 3551 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3552 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3553 | increment = output->zoom.increment * |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 3554 | -value / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3555 | else |
| 3556 | increment = 0; |
| 3557 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3558 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3559 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3560 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3561 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3562 | else if (output->zoom.level > output->zoom.max_level) |
| 3563 | output->zoom.level = output->zoom.max_level; |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 3564 | |
| 3565 | if (!output->zoom.active) { |
| 3566 | if (output->zoom.level <= 0.0) |
| 3567 | continue; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 3568 | weston_output_activate_zoom(output, seat); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3569 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3570 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3571 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3572 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3573 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3574 | } |
| 3575 | } |
| 3576 | } |
| 3577 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3578 | static void |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 3579 | zoom_axis_binding(struct weston_pointer *pointer, const struct timespec *time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3580 | struct weston_pointer_axis_event *event, |
| 3581 | void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3582 | { |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3583 | do_zoom(pointer->seat, time, 0, event->axis, event->value); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3584 | } |
| 3585 | |
| 3586 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3587 | zoom_key_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3588 | uint32_t key, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3589 | { |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3590 | do_zoom(keyboard->seat, time, key, 0, 0); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3591 | } |
| 3592 | |
| 3593 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3594 | terminate_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3595 | uint32_t key, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3596 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3597 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3598 | |
Pekka Paalanen | 052032d | 2019-02-06 10:44:37 +0200 | [diff] [blame] | 3599 | weston_compositor_exit(compositor); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3600 | } |
| 3601 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3602 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 3603 | rotate_grab_motion(struct weston_pointer_grab *grab, |
| 3604 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3605 | struct weston_pointer_motion_event *event) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3606 | { |
| 3607 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3608 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3609 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3610 | struct shell_surface *shsurf = rotate->base.shsurf; |
Sergey Bugaev | 14ef201 | 2019-02-11 22:55:09 +0300 | [diff] [blame] | 3611 | struct weston_surface *surface; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3612 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3613 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3614 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3615 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3616 | if (!shsurf) |
| 3617 | return; |
| 3618 | |
Sergey Bugaev | 14ef201 | 2019-02-11 22:55:09 +0300 | [diff] [blame] | 3619 | surface = weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 3620 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3621 | cx = 0.5f * surface->width; |
| 3622 | cy = 0.5f * surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3623 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3624 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3625 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3626 | r = sqrtf(dx * dx + dy * dy); |
| 3627 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3628 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3629 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3630 | |
| 3631 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3632 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3633 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3634 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3635 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3636 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3637 | |
| 3638 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3639 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3640 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3641 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3642 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3643 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 3644 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3645 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3646 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3647 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3648 | wl_list_init(&shsurf->rotation.transform.link); |
| 3649 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3650 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3651 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3652 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3653 | /* We need to adjust the position of the surface |
| 3654 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3655 | cposx = shsurf->view->geometry.x + cx; |
| 3656 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3657 | dposx = rotate->center.x - cposx; |
| 3658 | dposy = rotate->center.y - cposy; |
| 3659 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3660 | weston_view_set_position(shsurf->view, |
| 3661 | shsurf->view->geometry.x + dposx, |
| 3662 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3663 | } |
| 3664 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 3665 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3666 | * lazily applies the damage due to rotation update. |
| 3667 | */ |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3668 | weston_compositor_schedule_repaint(surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3672 | rotate_grab_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3673 | const struct timespec *time, |
| 3674 | uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3675 | { |
| 3676 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3677 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3678 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3679 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3680 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3681 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3682 | if (pointer->button_count == 0 && |
| 3683 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3684 | if (shsurf) |
| 3685 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 3686 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3687 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3688 | free(rotate); |
| 3689 | } |
| 3690 | } |
| 3691 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3692 | static void |
| 3693 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 3694 | { |
| 3695 | struct rotate_grab *rotate = |
| 3696 | container_of(grab, struct rotate_grab, base.grab); |
| 3697 | |
| 3698 | shell_grab_end(&rotate->base); |
| 3699 | free(rotate); |
| 3700 | } |
| 3701 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3702 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3703 | noop_grab_focus, |
| 3704 | rotate_grab_motion, |
| 3705 | rotate_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3706 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 3707 | noop_grab_axis_source, |
| 3708 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3709 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3710 | }; |
| 3711 | |
| 3712 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3713 | surface_rotate(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3714 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3715 | struct weston_surface *surface = |
| 3716 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3717 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3718 | float dx, dy; |
| 3719 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3720 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3721 | rotate = malloc(sizeof *rotate); |
| 3722 | if (!rotate) |
| 3723 | return; |
| 3724 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3725 | weston_view_to_global_float(shsurf->view, |
| 3726 | surface->width * 0.5f, |
| 3727 | surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3728 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3729 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 3730 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3731 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3732 | r = sqrtf(dx * dx + dy * dy); |
| 3733 | if (r > 20.0f) { |
| 3734 | struct weston_matrix inverse; |
| 3735 | |
| 3736 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3737 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3738 | weston_matrix_multiply(&shsurf->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3739 | |
| 3740 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3741 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3742 | } else { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3743 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3744 | weston_matrix_init(&rotate->rotation); |
| 3745 | } |
| 3746 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3747 | shell_grab_start(&rotate->base, &rotate_grab_interface, shsurf, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3748 | pointer, WESTON_DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3752 | rotate_binding(struct weston_pointer *pointer, const struct timespec *time, |
| 3753 | uint32_t button, void *data) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3754 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3755 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3756 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3757 | struct shell_surface *surface; |
| 3758 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3759 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3760 | return; |
| 3761 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3762 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3763 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3764 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3765 | if (base_surface == NULL) |
| 3766 | return; |
| 3767 | |
| 3768 | surface = get_shell_surface(base_surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3769 | if (surface == NULL || |
| 3770 | weston_desktop_surface_get_fullscreen(surface->desktop_surface) || |
| 3771 | weston_desktop_surface_get_maximized(surface->desktop_surface)) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3772 | return; |
| 3773 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 3774 | surface_rotate(surface, pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3775 | } |
| 3776 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3777 | /* Move all fullscreen layers down to the current workspace and hide their |
| 3778 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 3779 | * and this is reversed when such a surface is re-configured, see |
| 3780 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 3781 | * |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3782 | * lowering_output = NULL - Lower on all outputs, else only lower on the |
| 3783 | * specified output. |
| 3784 | * |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3785 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3786 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3787 | void |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3788 | lower_fullscreen_layer(struct desktop_shell *shell, |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3789 | struct weston_output *lowering_output) |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3790 | { |
| 3791 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3792 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3793 | |
| 3794 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3795 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3796 | &shell->fullscreen_layer.view_list.link, |
| 3797 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3798 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 3799 | |
| 3800 | if (!shsurf) |
| 3801 | continue; |
| 3802 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3803 | /* Only lower surfaces which have lowering_output as their fullscreen |
| 3804 | * output, unless a NULL output asks for lowering on all outputs. |
| 3805 | */ |
| 3806 | if (lowering_output && (shsurf->fullscreen_output != lowering_output)) |
| 3807 | continue; |
| 3808 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3809 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 3810 | * in the fullscreen layer. */ |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3811 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3812 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3813 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 3814 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 3815 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 3816 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3820 | weston_layer_entry_remove(&view->layer_link); |
| 3821 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3822 | weston_view_damage_below(view); |
| 3823 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3824 | |
| 3825 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3826 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3827 | } |
| 3828 | |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 3829 | static struct shell_surface *get_last_child(struct shell_surface *shsurf) |
| 3830 | { |
| 3831 | struct shell_surface *shsurf_child; |
| 3832 | |
| 3833 | wl_list_for_each_reverse(shsurf_child, &shsurf->children_list, children_link) { |
| 3834 | if (weston_view_is_mapped(shsurf_child->view)) |
| 3835 | return shsurf_child; |
| 3836 | } |
| 3837 | |
| 3838 | return NULL; |
| 3839 | } |
| 3840 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3841 | void |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 3842 | activate(struct desktop_shell *shell, struct weston_view *view, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3843 | struct weston_seat *seat, uint32_t flags) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3844 | { |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 3845 | struct weston_surface *es = view->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3846 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3847 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3848 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3849 | struct weston_surface *old_es; |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 3850 | struct shell_surface *shsurf, *shsurf_child; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3851 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3852 | main_surface = weston_surface_get_main_surface(es); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3853 | shsurf = get_shell_surface(main_surface); |
| 3854 | assert(shsurf); |
| 3855 | |
Stefan Agner | a8da208 | 2019-06-23 14:53:59 +0200 | [diff] [blame] | 3856 | shsurf_child = get_last_child(shsurf); |
| 3857 | if (shsurf_child) { |
| 3858 | /* Activate last xdg child instead of parent. */ |
| 3859 | activate(shell, shsurf_child->view, seat, flags); |
| 3860 | return; |
| 3861 | } |
| 3862 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3863 | /* Only demote fullscreen surfaces on the output of activated shsurf. |
| 3864 | * Leave fullscreen surfaces on unrelated outputs alone. */ |
Pekka Paalanen | 87860c2 | 2018-05-02 10:21:57 +0200 | [diff] [blame] | 3865 | if (shsurf->output) |
| 3866 | lower_fullscreen_layer(shell, shsurf->output); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3867 | |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 3868 | weston_view_activate(view, seat, flags); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3869 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3870 | state = ensure_focus_state(shell, seat); |
| 3871 | if (state == NULL) |
| 3872 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3873 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3874 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 3875 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3876 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3877 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) && |
| 3878 | flags & WESTON_ACTIVATE_FLAG_CONFIGURE) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3879 | shell_configure_fullscreen(shsurf); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3880 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 3881 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 3882 | * order as appropriate. */ |
| 3883 | shell_surface_update_layer(shsurf); |
| 3884 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3885 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 3886 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3887 | 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] | 3888 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3889 | } |
| 3890 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3891 | /* no-op func for checking black surface */ |
| 3892 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3893 | 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] | 3894 | { |
| 3895 | } |
| 3896 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 3897 | static bool |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3898 | 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] | 3899 | { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3900 | struct weston_surface *surface = view->surface; |
| 3901 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3902 | if (surface->committed == black_surface_committed) { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3903 | if (fs_view) |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3904 | *fs_view = surface->committed_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3905 | return true; |
| 3906 | } |
| 3907 | return false; |
| 3908 | } |
| 3909 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3910 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3911 | activate_binding(struct weston_seat *seat, |
| 3912 | struct desktop_shell *shell, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3913 | struct weston_view *focus_view, |
| 3914 | uint32_t flags) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3915 | { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3916 | struct weston_view *main_view; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3917 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3918 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3919 | if (!focus_view) |
| 3920 | return; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 3921 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3922 | if (is_black_surface_view(focus_view, &main_view)) |
| 3923 | focus_view = main_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3924 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3925 | main_surface = weston_surface_get_main_surface(focus_view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3926 | if (!get_shell_surface(main_surface)) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3927 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 3928 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3929 | activate(shell, focus_view, seat, flags); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3930 | } |
| 3931 | |
| 3932 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3933 | click_to_activate_binding(struct weston_pointer *pointer, |
| 3934 | const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3935 | uint32_t button, void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3936 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3937 | if (pointer->grab != &pointer->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3938 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3939 | if (pointer->focus == NULL) |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 3940 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3941 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3942 | activate_binding(pointer->seat, data, pointer->focus, |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 3943 | WESTON_ACTIVATE_FLAG_CLICKED | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3944 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | static void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 3948 | touch_to_activate_binding(struct weston_touch *touch, |
| 3949 | const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3950 | void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3951 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3952 | if (touch->grab != &touch->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3953 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3954 | if (touch->focus == NULL) |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 3955 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3956 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3957 | activate_binding(touch->seat, data, touch->focus, |
| 3958 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3959 | } |
| 3960 | |
| 3961 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3962 | unfocus_all_seats(struct desktop_shell *shell) |
| 3963 | { |
| 3964 | struct weston_seat *seat, *next; |
| 3965 | |
| 3966 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3967 | struct weston_keyboard *keyboard = |
| 3968 | weston_seat_get_keyboard(seat); |
| 3969 | |
| 3970 | if (!keyboard) |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3971 | continue; |
| 3972 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3973 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3974 | } |
| 3975 | } |
| 3976 | |
| 3977 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3978 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3979 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3980 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3981 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3982 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3983 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3984 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3985 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3986 | |
| 3987 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3988 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3989 | /* Hide all surfaces by removing the fullscreen, panel and |
| 3990 | * toplevel layers. This way nothing else can show or receive |
| 3991 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3992 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3993 | weston_layer_unset_position(&shell->panel_layer); |
| 3994 | weston_layer_unset_position(&shell->fullscreen_layer); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3995 | if (shell->showing_input_panels) |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3996 | weston_layer_unset_position(&shell->input_panel_layer); |
| 3997 | weston_layer_unset_position(&ws->layer); |
| 3998 | |
| 3999 | weston_layer_set_position(&shell->lock_layer, |
| 4000 | WESTON_LAYER_POSITION_LOCK); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4001 | |
Derek Foreman | 004b4a1 | 2015-07-20 16:28:13 -0500 | [diff] [blame] | 4002 | weston_compositor_sleep(shell->compositor); |
| 4003 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 4004 | /* Remove the keyboard focus on all seats. This will be |
| 4005 | * restored to the workspace's saved state via |
| 4006 | * restore_focus_state when the compositor is unlocked */ |
| 4007 | unfocus_all_seats(shell); |
| 4008 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4009 | /* TODO: disable bindings that should not work while locked. */ |
| 4010 | |
| 4011 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4015 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4016 | { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4017 | struct wl_resource *shell_resource; |
| 4018 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4019 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4020 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4021 | return; |
| 4022 | } |
| 4023 | |
| 4024 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4025 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4026 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4027 | return; |
| 4028 | } |
| 4029 | |
| 4030 | if (shell->prepare_event_sent) |
| 4031 | return; |
| 4032 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4033 | shell_resource = shell->child.desktop_shell; |
| 4034 | weston_desktop_shell_send_prepare_lock_surface(shell_resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4035 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | static void |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4039 | 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] | 4040 | { |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4041 | struct shell_output *shell_output = data; |
| 4042 | struct desktop_shell *shell = shell_output->shell; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4043 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4044 | shell_output->fade.animation = NULL; |
| 4045 | switch (shell_output->fade.type) { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4046 | case FADE_IN: |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4047 | weston_surface_destroy(shell_output->fade.view->surface); |
| 4048 | shell_output->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4049 | break; |
| 4050 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4051 | lock(shell); |
| 4052 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4053 | default: |
| 4054 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4055 | } |
| 4056 | } |
| 4057 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4058 | static struct weston_view * |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4059 | 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] | 4060 | { |
| 4061 | struct weston_compositor *compositor = shell->compositor; |
| 4062 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4063 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4064 | |
| 4065 | surface = weston_surface_create(compositor); |
| 4066 | if (!surface) |
| 4067 | return NULL; |
| 4068 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4069 | view = weston_view_create(surface); |
| 4070 | if (!view) { |
| 4071 | weston_surface_destroy(surface); |
| 4072 | return NULL; |
| 4073 | } |
| 4074 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4075 | weston_surface_set_size(surface, shell_output->output->width, shell_output->output->height); |
| 4076 | 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] | 4077 | 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] | 4078 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 4079 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4080 | pixman_region32_init(&surface->input); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 4081 | surface->is_mapped = true; |
| 4082 | view->is_mapped = true; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4083 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4084 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4085 | } |
| 4086 | |
| 4087 | static void |
| 4088 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4089 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4090 | float tint; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4091 | struct shell_output *shell_output; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4092 | |
| 4093 | switch (type) { |
| 4094 | case FADE_IN: |
| 4095 | tint = 0.0; |
| 4096 | break; |
| 4097 | case FADE_OUT: |
| 4098 | tint = 1.0; |
| 4099 | break; |
| 4100 | default: |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 4101 | weston_log("shell: invalid fade type\n"); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4102 | return; |
| 4103 | } |
| 4104 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4105 | /* Create a separate fade surface for each output */ |
| 4106 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4107 | shell_output->fade.type = type; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4108 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4109 | if (shell_output->fade.view == NULL) { |
| 4110 | shell_output->fade.view = shell_fade_create_surface_for_output(shell, shell_output); |
| 4111 | if (!shell_output->fade.view) |
| 4112 | continue; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4113 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4114 | shell_output->fade.view->alpha = 1.0 - tint; |
| 4115 | weston_view_update_transform(shell_output->fade.view); |
| 4116 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4117 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4118 | if (shell_output->fade.view->output == NULL) { |
| 4119 | /* If the black view gets a NULL output, we lost the |
| 4120 | * last output and we'll just cancel the fade. This |
| 4121 | * happens when you close the last window under the |
| 4122 | * X11 or Wayland backends. */ |
| 4123 | shell->locked = false; |
| 4124 | weston_surface_destroy(shell_output->fade.view->surface); |
| 4125 | shell_output->fade.view = NULL; |
| 4126 | } else if (shell_output->fade.animation) { |
| 4127 | weston_fade_update(shell_output->fade.animation, tint); |
| 4128 | } else { |
| 4129 | shell_output->fade.animation = |
| 4130 | weston_fade_run(shell_output->fade.view, |
| 4131 | 1.0 - tint, tint, 300.0, |
| 4132 | shell_fade_done_for_output, shell_output); |
| 4133 | } |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4134 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4135 | } |
| 4136 | |
| 4137 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4138 | do_shell_fade_startup(void *data) |
| 4139 | { |
| 4140 | struct desktop_shell *shell = data; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4141 | struct shell_output *shell_output; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4142 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 4143 | if (shell->startup_animation_type == ANIMATION_FADE) { |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4144 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 4145 | } else { |
| 4146 | weston_log("desktop shell: " |
| 4147 | "unexpected fade-in animation type %d\n", |
| 4148 | shell->startup_animation_type); |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4149 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4150 | weston_surface_destroy(shell_output->fade.view->surface); |
| 4151 | shell_output->fade.view = NULL; |
| 4152 | } |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4153 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4154 | } |
| 4155 | |
| 4156 | static void |
| 4157 | shell_fade_startup(struct desktop_shell *shell) |
| 4158 | { |
| 4159 | struct wl_event_loop *loop; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4160 | struct shell_output *shell_output; |
| 4161 | bool has_fade = false; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4162 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4163 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4164 | if (!shell_output->fade.startup_timer) |
| 4165 | continue; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4166 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4167 | wl_event_source_remove(shell_output->fade.startup_timer); |
| 4168 | shell_output->fade.startup_timer = NULL; |
| 4169 | has_fade = true; |
| 4170 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4171 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4172 | if (has_fade) { |
| 4173 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4174 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4175 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4176 | } |
| 4177 | |
| 4178 | static int |
| 4179 | fade_startup_timeout(void *data) |
| 4180 | { |
| 4181 | struct desktop_shell *shell = data; |
| 4182 | |
| 4183 | shell_fade_startup(shell); |
| 4184 | return 0; |
| 4185 | } |
| 4186 | |
| 4187 | static void |
| 4188 | shell_fade_init(struct desktop_shell *shell) |
| 4189 | { |
| 4190 | /* Make compositor output all black, and wait for the desktop-shell |
| 4191 | * client to signal it is ready, then fade in. The timer triggers a |
| 4192 | * fade-in, in case the desktop-shell client takes too long. |
| 4193 | */ |
| 4194 | |
| 4195 | struct wl_event_loop *loop; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4196 | struct shell_output *shell_output; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4197 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 4198 | if (shell->startup_animation_type == ANIMATION_NONE) |
| 4199 | return; |
| 4200 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4201 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4202 | if (shell_output->fade.view != NULL) { |
| 4203 | weston_log("%s: warning: fade surface already exists\n", |
| 4204 | __func__); |
| 4205 | continue; |
| 4206 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4207 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4208 | shell_output->fade.view = shell_fade_create_surface_for_output(shell, shell_output); |
| 4209 | if (!shell_output->fade.view) |
| 4210 | continue; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4211 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4212 | weston_view_update_transform(shell_output->fade.view); |
| 4213 | weston_surface_damage(shell_output->fade.view->surface); |
| 4214 | |
| 4215 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4216 | shell_output->fade.startup_timer = |
| 4217 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4218 | wl_event_source_timer_update(shell_output->fade.startup_timer, 15000); |
| 4219 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4220 | } |
| 4221 | |
| 4222 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4223 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4224 | { |
| 4225 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4226 | container_of(listener, struct desktop_shell, idle_listener); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4227 | |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 4228 | struct weston_seat *seat; |
| 4229 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4230 | wl_list_for_each(seat, &shell->compositor->seat_list, link) |
| 4231 | weston_seat_break_desktop_grabs(seat); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4232 | |
| 4233 | shell_fade(shell, FADE_OUT); |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4234 | /* lock() is called from shell_fade_done_for_output() */ |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4235 | } |
| 4236 | |
| 4237 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4238 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4239 | { |
| 4240 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4241 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4242 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4243 | unlock(shell); |
| 4244 | } |
| 4245 | |
| 4246 | static void |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4247 | transform_handler(struct wl_listener *listener, void *data) |
| 4248 | { |
| 4249 | struct weston_surface *surface = data; |
| 4250 | struct shell_surface *shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4251 | const struct weston_xwayland_surface_api *api; |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4252 | int x, y; |
| 4253 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4254 | if (!shsurf) |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4255 | return; |
| 4256 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4257 | api = shsurf->shell->xwayland_surface_api; |
| 4258 | if (!api) { |
| 4259 | api = weston_xwayland_surface_get_api(shsurf->shell->compositor); |
| 4260 | shsurf->shell->xwayland_surface_api = api; |
| 4261 | } |
| 4262 | |
| 4263 | if (!api || !api->is_xwayland_surface(surface)) |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4264 | return; |
| 4265 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4266 | if (!weston_view_is_mapped(shsurf->view)) |
| 4267 | return; |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4268 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4269 | x = shsurf->view->geometry.x; |
| 4270 | y = shsurf->view->geometry.y; |
| 4271 | |
| 4272 | api->send_position(surface, x, y); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4273 | } |
| 4274 | |
| 4275 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4276 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4277 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4278 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4279 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4280 | |
Pekka Paalanen | 30aa597 | 2018-05-02 10:21:56 +0200 | [diff] [blame] | 4281 | if (!output) { |
| 4282 | weston_view_set_position(view, 0, 0); |
| 4283 | return; |
| 4284 | } |
| 4285 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4286 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4287 | |
| 4288 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4289 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4290 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4291 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4292 | } |
| 4293 | |
| 4294 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4295 | weston_view_set_initial_position(struct weston_view *view, |
| 4296 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4297 | { |
| 4298 | struct weston_compositor *compositor = shell->compositor; |
| 4299 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4300 | int32_t range_x, range_y; |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4301 | int32_t x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4302 | struct weston_output *output, *target_output = NULL; |
| 4303 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4304 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4305 | |
| 4306 | /* As a heuristic place the new window on the same output as the |
| 4307 | * pointer. Falling back to the output containing 0, 0. |
| 4308 | * |
| 4309 | * TODO: Do something clever for touch too? |
| 4310 | */ |
| 4311 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4312 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 4313 | |
| 4314 | if (pointer) { |
| 4315 | ix = wl_fixed_to_int(pointer->x); |
| 4316 | iy = wl_fixed_to_int(pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4317 | break; |
| 4318 | } |
| 4319 | } |
| 4320 | |
| 4321 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4322 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4323 | target_output = output; |
| 4324 | break; |
| 4325 | } |
| 4326 | } |
| 4327 | |
| 4328 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4329 | weston_view_set_position(view, 10 + random() % 400, |
| 4330 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4331 | return; |
| 4332 | } |
| 4333 | |
| 4334 | /* Valid range within output where the surface will still be onscreen. |
| 4335 | * If this is negative it means that the surface is bigger than |
| 4336 | * output. |
| 4337 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4338 | get_output_work_area(shell, target_output, &area); |
| 4339 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4340 | x = area.x; |
| 4341 | y = area.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4342 | range_x = area.width - view->surface->width; |
| 4343 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4344 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4345 | if (range_x > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4346 | x += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4347 | |
| 4348 | if (range_y > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4349 | y += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4350 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4351 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4352 | } |
| 4353 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 4354 | static bool |
| 4355 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 4356 | { |
| 4357 | struct timespec now; |
| 4358 | |
| 4359 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 4360 | return false; |
| 4361 | |
| 4362 | /* |
| 4363 | * If the shell helper client dies before the session has been |
| 4364 | * up for roughly 30 seconds, better just make Weston shut down, |
| 4365 | * because the user likely has no way to interact with the desktop |
| 4366 | * anyway. |
| 4367 | */ |
| 4368 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 4369 | weston_log("Error: %s apparently cannot run at all.\n", |
| 4370 | shell->client); |
| 4371 | weston_log_continue(STAMP_SPACE "Quitting..."); |
Pekka Paalanen | 052032d | 2019-02-06 10:44:37 +0200 | [diff] [blame] | 4372 | weston_compositor_exit_with_code(shell->compositor, |
| 4373 | EXIT_FAILURE); |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 4374 | |
| 4375 | return true; |
| 4376 | } |
| 4377 | |
| 4378 | return false; |
| 4379 | } |
| 4380 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4381 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4382 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4383 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4384 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4385 | { |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 4386 | struct timespec time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4387 | |
| 4388 | /* 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] | 4389 | weston_compositor_get_time(&time); |
| 4390 | if (timespec_sub_to_msec(&time, &shell->child.deathstamp) > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4391 | shell->child.deathstamp = time; |
| 4392 | shell->child.deathcount = 0; |
| 4393 | } |
| 4394 | |
| 4395 | shell->child.deathcount++; |
| 4396 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4397 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4398 | return; |
| 4399 | } |
| 4400 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4401 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4402 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4403 | } |
| 4404 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4405 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4406 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 4407 | { |
| 4408 | struct desktop_shell *shell; |
| 4409 | |
| 4410 | shell = container_of(listener, struct desktop_shell, |
| 4411 | child.client_destroy_listener); |
| 4412 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4413 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4414 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4415 | /* |
| 4416 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 4417 | * before the respawned process has a chance to create a new |
| 4418 | * desktop_shell object, because we are being called from the |
| 4419 | * wl_client destructor which destroys all wl_resources before |
| 4420 | * returning. |
| 4421 | */ |
| 4422 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 4423 | if (!check_desktop_shell_crash_too_early(shell)) |
| 4424 | respawn_desktop_shell_process(shell); |
| 4425 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4426 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4427 | } |
| 4428 | |
| 4429 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4430 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4431 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4432 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4433 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4434 | shell->child.client = weston_client_start(shell->compositor, |
| 4435 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4436 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 4437 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4438 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 4439 | return; |
| 4440 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4441 | |
| 4442 | shell->child.client_destroy_listener.notify = |
| 4443 | desktop_shell_client_destroy; |
| 4444 | wl_client_add_destroy_listener(shell->child.client, |
| 4445 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4446 | } |
| 4447 | |
| 4448 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4449 | unbind_desktop_shell(struct wl_resource *resource) |
| 4450 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4451 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4452 | |
| 4453 | if (shell->locked) |
| 4454 | resume_desktop(shell); |
| 4455 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4456 | shell->child.desktop_shell = NULL; |
| 4457 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4458 | } |
| 4459 | |
| 4460 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4461 | bind_desktop_shell(struct wl_client *client, |
| 4462 | void *data, uint32_t version, uint32_t id) |
| 4463 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4464 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4465 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4466 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4467 | resource = wl_resource_create(client, &weston_desktop_shell_interface, |
| 4468 | 1, id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4469 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4470 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4471 | wl_resource_set_implementation(resource, |
| 4472 | &desktop_shell_implementation, |
| 4473 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4474 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4475 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4476 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4477 | |
| 4478 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4479 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4480 | } |
| 4481 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4482 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4483 | struct desktop_shell *shell; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4484 | struct weston_view *current; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4485 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4486 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4487 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4488 | }; |
| 4489 | |
| 4490 | static void |
| 4491 | switcher_next(struct switcher *switcher) |
| 4492 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4493 | struct weston_view *view; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4494 | struct weston_view *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4495 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4496 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4497 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4498 | /* temporary re-display minimized surfaces */ |
| 4499 | struct weston_view *tmp; |
| 4500 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4501 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 4502 | weston_layer_entry_remove(&view->layer_link); |
| 4503 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4504 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 4505 | *minimized = view; |
| 4506 | } |
| 4507 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4508 | 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] | 4509 | shsurf = get_shell_surface(view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4510 | if (shsurf) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4511 | if (first == NULL) |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4512 | first = view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4513 | if (prev == switcher->current) |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4514 | next = view; |
| 4515 | prev = view; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4516 | view->alpha = 0.25; |
| 4517 | weston_view_geometry_dirty(view); |
| 4518 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4519 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4520 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 4521 | if (is_black_surface_view(view, NULL)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4522 | view->alpha = 0.25; |
| 4523 | weston_view_geometry_dirty(view); |
| 4524 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4525 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4526 | } |
| 4527 | |
| 4528 | if (next == NULL) |
| 4529 | next = first; |
| 4530 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4531 | if (next == NULL) |
| 4532 | return; |
| 4533 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4534 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4535 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4536 | |
| 4537 | switcher->current = next; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4538 | wl_list_for_each(view, &next->surface->views, surface_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4539 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4540 | |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4541 | shsurf = get_shell_surface(switcher->current->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4542 | if (shsurf && weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4543 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4544 | } |
| 4545 | |
| 4546 | static void |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4547 | switcher_handle_view_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4548 | { |
| 4549 | struct switcher *switcher = |
| 4550 | container_of(listener, struct switcher, listener); |
| 4551 | |
| 4552 | switcher_next(switcher); |
| 4553 | } |
| 4554 | |
| 4555 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4556 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4557 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4558 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4559 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4560 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4561 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4562 | 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] | 4563 | if (is_focus_view(view)) |
| 4564 | continue; |
| 4565 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4566 | view->alpha = 1.0; |
| 4567 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4568 | } |
| 4569 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 4570 | if (switcher->current) { |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 4571 | activate(switcher->shell, switcher->current, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 4572 | keyboard->seat, |
| 4573 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
| 4574 | } |
| 4575 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4576 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4577 | weston_keyboard_end_grab(keyboard); |
| 4578 | if (keyboard->input_method_resource) |
| 4579 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4580 | |
| 4581 | /* re-hide surfaces that were temporary shown during the switch */ |
| 4582 | struct weston_view **minimized; |
| 4583 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 4584 | /* with the exception of the current selected */ |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4585 | if ((*minimized)->surface != switcher->current->surface) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4586 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 4587 | 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] | 4588 | weston_view_damage_below(*minimized); |
| 4589 | } |
| 4590 | } |
| 4591 | wl_array_release(&switcher->minimized_array); |
| 4592 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4593 | free(switcher); |
| 4594 | } |
| 4595 | |
| 4596 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4597 | switcher_key(struct weston_keyboard_grab *grab, |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4598 | const struct timespec *time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4599 | { |
| 4600 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4601 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4602 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4603 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4604 | switcher_next(switcher); |
| 4605 | } |
| 4606 | |
| 4607 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4608 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4609 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4610 | uint32_t mods_locked, uint32_t group) |
| 4611 | { |
| 4612 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4613 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4614 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4615 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 4616 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 4617 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4618 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4619 | static void |
| 4620 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 4621 | { |
| 4622 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 4623 | |
| 4624 | switcher_destroy(switcher); |
| 4625 | } |
| 4626 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4627 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4628 | switcher_key, |
| 4629 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4630 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4631 | }; |
| 4632 | |
| 4633 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4634 | switcher_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4635 | uint32_t key, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4636 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4637 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4638 | struct switcher *switcher; |
| 4639 | |
| 4640 | switcher = malloc(sizeof *switcher); |
ganjing | c1e7151 | 2020-07-28 15:28:45 +0800 | [diff] [blame] | 4641 | if (!switcher) |
| 4642 | return; |
Pekka Paalanen | 4bb326b | 2021-05-14 14:37:46 +0300 | [diff] [blame] | 4643 | |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4644 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4645 | switcher->current = NULL; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4646 | switcher->listener.notify = switcher_handle_view_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4647 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4648 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4649 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 4650 | lower_fullscreen_layer(switcher->shell, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4651 | switcher->grab.interface = &switcher_grab; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4652 | weston_keyboard_start_grab(keyboard, &switcher->grab); |
| 4653 | weston_keyboard_set_focus(keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4654 | switcher_next(switcher); |
| 4655 | } |
| 4656 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4657 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4658 | backlight_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4659 | uint32_t key, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4660 | { |
| 4661 | struct weston_compositor *compositor = data; |
| 4662 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4663 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4664 | |
| 4665 | /* TODO: we're limiting to simple use cases, where we assume just |
| 4666 | * control on the primary display. We'd have to extend later if we |
| 4667 | * ever get support for setting backlights on random desktop LCD |
| 4668 | * panels though */ |
| 4669 | output = get_default_output(compositor); |
| 4670 | if (!output) |
| 4671 | return; |
| 4672 | |
| 4673 | if (!output->set_backlight) |
| 4674 | return; |
| 4675 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4676 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 4677 | backlight_new = output->backlight_current - 25; |
| 4678 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 4679 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4680 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4681 | if (backlight_new < 5) |
| 4682 | backlight_new = 5; |
| 4683 | if (backlight_new > 255) |
| 4684 | backlight_new = 255; |
| 4685 | |
| 4686 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4687 | output->set_backlight(output, output->backlight_current); |
| 4688 | } |
| 4689 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 4690 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4691 | force_kill_binding(struct weston_keyboard *keyboard, |
| 4692 | const struct timespec *time, uint32_t key, void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4693 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 4694 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4695 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 4696 | struct desktop_shell *shell = data; |
| 4697 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4698 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4699 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4700 | focus_surface = keyboard->focus; |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 4701 | if (!focus_surface) |
| 4702 | return; |
| 4703 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 4704 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 4705 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4706 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 4707 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 4708 | |
| 4709 | /* Skip clients that we launched ourselves (the credentials of |
| 4710 | * the socketpair is ours) */ |
| 4711 | if (pid == getpid()) |
| 4712 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4713 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4714 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4718 | workspace_up_binding(struct weston_keyboard *keyboard, |
| 4719 | const struct timespec *time, uint32_t key, void *data) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4720 | { |
| 4721 | struct desktop_shell *shell = data; |
| 4722 | unsigned int new_index = shell->workspaces.current; |
| 4723 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4724 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4725 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4726 | if (new_index != 0) |
| 4727 | new_index--; |
| 4728 | |
| 4729 | change_workspace(shell, new_index); |
| 4730 | } |
| 4731 | |
| 4732 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4733 | workspace_down_binding(struct weston_keyboard *keyboard, |
| 4734 | const struct timespec *time, uint32_t key, void *data) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4735 | { |
| 4736 | struct desktop_shell *shell = data; |
| 4737 | unsigned int new_index = shell->workspaces.current; |
| 4738 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4739 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4740 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4741 | if (new_index < shell->workspaces.num - 1) |
| 4742 | new_index++; |
| 4743 | |
| 4744 | change_workspace(shell, new_index); |
| 4745 | } |
| 4746 | |
| 4747 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4748 | workspace_f_binding(struct weston_keyboard *keyboard, |
| 4749 | const struct timespec *time, uint32_t key, void *data) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4750 | { |
| 4751 | struct desktop_shell *shell = data; |
| 4752 | unsigned int new_index; |
| 4753 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4754 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4755 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4756 | new_index = key - KEY_F1; |
| 4757 | if (new_index >= shell->workspaces.num) |
| 4758 | new_index = shell->workspaces.num - 1; |
| 4759 | |
| 4760 | change_workspace(shell, new_index); |
| 4761 | } |
| 4762 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4763 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4764 | workspace_move_surface_up_binding(struct weston_keyboard *keyboard, |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4765 | const struct timespec *time, uint32_t key, |
| 4766 | void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4767 | { |
| 4768 | struct desktop_shell *shell = data; |
| 4769 | unsigned int new_index = shell->workspaces.current; |
| 4770 | |
| 4771 | if (shell->locked) |
| 4772 | return; |
| 4773 | |
| 4774 | if (new_index != 0) |
| 4775 | new_index--; |
| 4776 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4777 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4778 | } |
| 4779 | |
| 4780 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4781 | workspace_move_surface_down_binding(struct weston_keyboard *keyboard, |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4782 | const struct timespec *time, uint32_t key, |
| 4783 | void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4784 | { |
| 4785 | struct desktop_shell *shell = data; |
| 4786 | unsigned int new_index = shell->workspaces.current; |
| 4787 | |
| 4788 | if (shell->locked) |
| 4789 | return; |
| 4790 | |
| 4791 | if (new_index < shell->workspaces.num - 1) |
| 4792 | new_index++; |
| 4793 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4794 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4795 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4796 | |
| 4797 | static void |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4798 | shell_reposition_view_on_output_change(struct weston_view *view) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4799 | { |
| 4800 | struct weston_output *output, *first_output; |
| 4801 | struct weston_compositor *ec = view->surface->compositor; |
| 4802 | struct shell_surface *shsurf; |
| 4803 | float x, y; |
| 4804 | int visible; |
| 4805 | |
Harish Krupo | 2dff4dd | 2019-04-20 18:10:56 +0530 | [diff] [blame] | 4806 | if (wl_list_empty(&ec->output_list)) |
| 4807 | return; |
| 4808 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4809 | x = view->geometry.x; |
| 4810 | y = view->geometry.y; |
| 4811 | |
| 4812 | /* At this point the destroyed output is not in the list anymore. |
| 4813 | * If the view is still visible somewhere, we leave where it is, |
| 4814 | * otherwise, move it to the first output. */ |
| 4815 | visible = 0; |
| 4816 | wl_list_for_each(output, &ec->output_list, link) { |
| 4817 | if (pixman_region32_contains_point(&output->region, |
| 4818 | x, y, NULL)) { |
| 4819 | visible = 1; |
| 4820 | break; |
| 4821 | } |
| 4822 | } |
| 4823 | |
| 4824 | if (!visible) { |
| 4825 | first_output = container_of(ec->output_list.next, |
| 4826 | struct weston_output, link); |
| 4827 | |
| 4828 | x = first_output->x + first_output->width / 4; |
| 4829 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 4830 | |
| 4831 | weston_view_set_position(view, x, y); |
| 4832 | } else { |
| 4833 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4834 | } |
| 4835 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4836 | |
| 4837 | shsurf = get_shell_surface(view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4838 | if (!shsurf) |
| 4839 | return; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4840 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4841 | shsurf->saved_position_valid = false; |
| 4842 | set_maximized(shsurf, false); |
| 4843 | set_fullscreen(shsurf, false, NULL); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4844 | } |
| 4845 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4846 | void |
| 4847 | shell_for_each_layer(struct desktop_shell *shell, |
| 4848 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4849 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4850 | struct workspace **ws; |
| 4851 | |
| 4852 | func(shell, &shell->fullscreen_layer, data); |
| 4853 | func(shell, &shell->panel_layer, data); |
| 4854 | func(shell, &shell->background_layer, data); |
| 4855 | func(shell, &shell->lock_layer, data); |
| 4856 | func(shell, &shell->input_panel_layer, data); |
| 4857 | |
| 4858 | wl_array_for_each(ws, &shell->workspaces.array) |
| 4859 | func(shell, &(*ws)->layer, data); |
| 4860 | } |
| 4861 | |
| 4862 | static void |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4863 | shell_output_changed_move_layer(struct desktop_shell *shell, |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4864 | struct weston_layer *layer, |
| 4865 | void *data) |
| 4866 | { |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4867 | struct weston_view *view; |
| 4868 | |
Marius Vlad | ea40d6d | 2018-02-08 18:46:42 +0200 | [diff] [blame] | 4869 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4870 | shell_reposition_view_on_output_change(view); |
| 4871 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | static void |
Pekka Paalanen | 719ca87 | 2021-05-24 16:53:40 +0300 | [diff] [blame] | 4875 | shell_output_destroy(struct shell_output *shell_output) |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4876 | { |
Pekka Paalanen | 0d5e4ff | 2021-05-24 16:13:21 +0300 | [diff] [blame] | 4877 | struct desktop_shell *shell = shell_output->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4878 | |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4879 | 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] | 4880 | |
Pekka Paalanen | 719ca87 | 2021-05-24 16:53:40 +0300 | [diff] [blame] | 4881 | if (shell_output->fade.animation) { |
| 4882 | weston_view_animation_destroy(shell_output->fade.animation); |
| 4883 | shell_output->fade.animation = NULL; |
| 4884 | } |
| 4885 | |
| 4886 | if (shell_output->fade.view) { |
| 4887 | /* destroys the view as well */ |
| 4888 | weston_surface_destroy(shell_output->fade.view->surface); |
| 4889 | } |
| 4890 | |
| 4891 | if (shell_output->fade.startup_timer) |
| 4892 | wl_event_source_remove(shell_output->fade.startup_timer); |
| 4893 | |
Pekka Paalanen | 0d5e4ff | 2021-05-24 16:13:21 +0300 | [diff] [blame] | 4894 | if (shell_output->panel_surface) |
| 4895 | wl_list_remove(&shell_output->panel_surface_listener.link); |
| 4896 | if (shell_output->background_surface) |
| 4897 | wl_list_remove(&shell_output->background_surface_listener.link); |
| 4898 | wl_list_remove(&shell_output->destroy_listener.link); |
| 4899 | wl_list_remove(&shell_output->link); |
| 4900 | free(shell_output); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4901 | } |
| 4902 | |
| 4903 | static void |
Pekka Paalanen | 719ca87 | 2021-05-24 16:53:40 +0300 | [diff] [blame] | 4904 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 4905 | { |
| 4906 | struct shell_output *shell_output = |
| 4907 | container_of(listener, struct shell_output, destroy_listener); |
| 4908 | |
| 4909 | shell_output_destroy(shell_output); |
| 4910 | } |
| 4911 | |
| 4912 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4913 | shell_resize_surface_to_output(struct desktop_shell *shell, |
| 4914 | struct weston_surface *surface, |
| 4915 | const struct weston_output *output) |
| 4916 | { |
| 4917 | if (!surface) |
| 4918 | return; |
| 4919 | |
| 4920 | weston_desktop_shell_send_configure(shell->child.desktop_shell, 0, |
| 4921 | surface->resource, |
| 4922 | output->width, |
| 4923 | output->height); |
| 4924 | } |
| 4925 | |
| 4926 | |
| 4927 | static void |
| 4928 | handle_output_resized(struct wl_listener *listener, void *data) |
| 4929 | { |
| 4930 | struct desktop_shell *shell = |
| 4931 | container_of(listener, struct desktop_shell, resized_listener); |
| 4932 | struct weston_output *output = (struct weston_output *)data; |
| 4933 | struct shell_output *sh_output = find_shell_output_from_weston_output(shell, output); |
| 4934 | |
| 4935 | shell_resize_surface_to_output(shell, sh_output->background_surface, output); |
| 4936 | shell_resize_surface_to_output(shell, sh_output->panel_surface, output); |
| 4937 | } |
| 4938 | |
| 4939 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4940 | create_shell_output(struct desktop_shell *shell, |
| 4941 | struct weston_output *output) |
| 4942 | { |
| 4943 | struct shell_output *shell_output; |
| 4944 | |
| 4945 | shell_output = zalloc(sizeof *shell_output); |
| 4946 | if (shell_output == NULL) |
| 4947 | return; |
| 4948 | |
| 4949 | shell_output->output = output; |
| 4950 | shell_output->shell = shell; |
| 4951 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 4952 | wl_signal_add(&output->destroy_signal, |
| 4953 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 4954 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Harish Krupo | dc3edc0 | 2019-04-20 17:50:18 +0530 | [diff] [blame] | 4955 | |
| 4956 | if (wl_list_length(&shell->output_list) == 1) |
| 4957 | shell_for_each_layer(shell, |
| 4958 | shell_output_changed_move_layer, NULL); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | static void |
| 4962 | handle_output_create(struct wl_listener *listener, void *data) |
| 4963 | { |
| 4964 | struct desktop_shell *shell = |
| 4965 | container_of(listener, struct desktop_shell, output_create_listener); |
| 4966 | struct weston_output *output = (struct weston_output *)data; |
| 4967 | |
| 4968 | create_shell_output(shell, output); |
| 4969 | } |
| 4970 | |
| 4971 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4972 | handle_output_move_layer(struct desktop_shell *shell, |
| 4973 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4974 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4975 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4976 | struct weston_view *view; |
| 4977 | float x, y; |
| 4978 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4979 | 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] | 4980 | if (view->output != output) |
| 4981 | continue; |
| 4982 | |
| 4983 | x = view->geometry.x + output->move_x; |
| 4984 | y = view->geometry.y + output->move_y; |
| 4985 | weston_view_set_position(view, x, y); |
| 4986 | } |
| 4987 | } |
| 4988 | |
| 4989 | static void |
| 4990 | handle_output_move(struct wl_listener *listener, void *data) |
| 4991 | { |
| 4992 | struct desktop_shell *shell; |
| 4993 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4994 | shell = container_of(listener, struct desktop_shell, |
| 4995 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4996 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4997 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5001 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5002 | struct desktop_shell *shell) |
| 5003 | { |
| 5004 | struct weston_output *output; |
| 5005 | |
| 5006 | wl_list_init(&shell->output_list); |
| 5007 | wl_list_for_each(output, &ec->output_list, link) |
| 5008 | create_shell_output(shell, output); |
| 5009 | |
| 5010 | shell->output_create_listener.notify = handle_output_create; |
| 5011 | wl_signal_add(&ec->output_created_signal, |
| 5012 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5013 | |
| 5014 | shell->output_move_listener.notify = handle_output_move; |
| 5015 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5016 | } |
| 5017 | |
| 5018 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5019 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5020 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5021 | struct desktop_shell *shell = |
| 5022 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5023 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5024 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5025 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 5026 | /* Force state to unlocked so we don't try to fade */ |
| 5027 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5028 | |
| 5029 | if (shell->child.client) { |
| 5030 | /* disable respawn */ |
| 5031 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5032 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 5033 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5034 | |
Harsha M M | b8b2c72 | 2018-08-07 19:05:02 +0530 | [diff] [blame] | 5035 | wl_list_remove(&shell->destroy_listener.link); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5036 | wl_list_remove(&shell->idle_listener.link); |
| 5037 | wl_list_remove(&shell->wake_listener.link); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 5038 | wl_list_remove(&shell->transform_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5039 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 5040 | text_backend_destroy(shell->text_backend); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5041 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5042 | |
Pekka Paalanen | 719ca87 | 2021-05-24 16:53:40 +0300 | [diff] [blame] | 5043 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) |
| 5044 | shell_output_destroy(shell_output); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5045 | |
| 5046 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 5047 | wl_list_remove(&shell->output_move_listener.link); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 5048 | wl_list_remove(&shell->resized_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5049 | |
Pekka Paalanen | abd7292 | 2021-05-24 14:42:00 +0300 | [diff] [blame] | 5050 | weston_desktop_destroy(shell->desktop); |
| 5051 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5052 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5053 | workspace_destroy(*ws); |
| 5054 | wl_array_release(&shell->workspaces.array); |
| 5055 | |
Pekka Paalanen | 4bb326b | 2021-05-14 14:37:46 +0300 | [diff] [blame] | 5056 | weston_layer_fini(&shell->fullscreen_layer); |
| 5057 | weston_layer_fini(&shell->panel_layer); |
| 5058 | weston_layer_fini(&shell->background_layer); |
| 5059 | weston_layer_fini(&shell->lock_layer); |
| 5060 | weston_layer_fini(&shell->input_panel_layer); |
| 5061 | weston_layer_fini(&shell->minimized_layer); |
| 5062 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5063 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5064 | free(shell); |
| 5065 | } |
| 5066 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5067 | static void |
| 5068 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5069 | { |
| 5070 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5071 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5072 | |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 5073 | if (shell->allow_zap) |
| 5074 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5075 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5076 | terminate_binding, ec); |
| 5077 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5078 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5079 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5080 | click_to_activate_binding, |
| 5081 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 5082 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 5083 | click_to_activate_binding, |
| 5084 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5085 | weston_compositor_add_touch_binding(ec, 0, |
| 5086 | touch_to_activate_binding, |
| 5087 | shell); |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 5088 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 5089 | backlight_binding, ec); |
| 5090 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 5091 | backlight_binding, ec); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5092 | |
| 5093 | /* configurable bindings */ |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 5094 | if (shell->exposay_modifier) |
| 5095 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 5096 | exposay_binding, shell); |
| 5097 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5098 | mod = shell->binding_modifier; |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 5099 | if (!mod) |
| 5100 | return; |
| 5101 | |
Ian Ray | 13404c4 | 2017-09-18 15:22:01 +0300 | [diff] [blame] | 5102 | /* This binding is not configurable, but is only enabled if there is a |
| 5103 | * valid binding modifier. */ |
| 5104 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5105 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5106 | surface_opacity_binding, NULL); |
| 5107 | |
Ian Ray | ab7c0b6 | 2017-09-18 15:22:00 +0300 | [diff] [blame] | 5108 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5109 | mod, zoom_axis_binding, |
| 5110 | NULL); |
| 5111 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5112 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5113 | zoom_key_binding, NULL); |
| 5114 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5115 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 5116 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 5117 | maximize_binding, NULL); |
| 5118 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 5119 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5120 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5121 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5122 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 5123 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5124 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 5125 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 5126 | mod | MODIFIER_SHIFT, |
| 5127 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5128 | |
| 5129 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 5130 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5131 | rotate_binding, NULL); |
| 5132 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5133 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5134 | shell); |
| 5135 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 5136 | ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5137 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 5138 | ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5139 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 5140 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5141 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 5142 | workspace_up_binding, shell); |
| 5143 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 5144 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5145 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 5146 | workspace_move_surface_up_binding, |
| 5147 | shell); |
| 5148 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 5149 | workspace_move_surface_down_binding, |
| 5150 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5151 | |
| 5152 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5153 | if (shell->workspaces.num > 1) { |
| 5154 | num_workspace_bindings = shell->workspaces.num; |
| 5155 | if (num_workspace_bindings > 6) |
| 5156 | num_workspace_bindings = 6; |
| 5157 | for (i = 0; i < num_workspace_bindings; i++) |
| 5158 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5159 | workspace_f_binding, |
| 5160 | shell); |
| 5161 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5162 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 5163 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5164 | } |
| 5165 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 5166 | static void |
| 5167 | handle_seat_created(struct wl_listener *listener, void *data) |
| 5168 | { |
| 5169 | struct weston_seat *seat = data; |
| 5170 | |
| 5171 | create_shell_seat(seat); |
| 5172 | } |
| 5173 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5174 | WL_EXPORT int |
Quentin Glidic | da01c1d | 2016-12-02 14:17:08 +0100 | [diff] [blame] | 5175 | wet_shell_init(struct weston_compositor *ec, |
| 5176 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5177 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5178 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5179 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5180 | struct workspace **pws; |
| 5181 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5182 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5183 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 5184 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5185 | if (shell == NULL) |
| 5186 | return -1; |
| 5187 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5188 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5189 | |
Pekka Paalanen | 6ffbba3 | 2019-11-06 12:59:32 +0200 | [diff] [blame] | 5190 | if (!weston_compositor_add_destroy_listener_once(ec, |
| 5191 | &shell->destroy_listener, |
| 5192 | shell_destroy)) { |
| 5193 | free(shell); |
| 5194 | return 0; |
| 5195 | } |
| 5196 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5197 | shell->idle_listener.notify = idle_handler; |
| 5198 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 5199 | shell->wake_listener.notify = wake_handler; |
| 5200 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 5201 | shell->transform_listener.notify = transform_handler; |
| 5202 | wl_signal_add(&ec->transform_signal, &shell->transform_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5203 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 5204 | weston_layer_init(&shell->fullscreen_layer, ec); |
| 5205 | weston_layer_init(&shell->panel_layer, ec); |
| 5206 | weston_layer_init(&shell->background_layer, ec); |
| 5207 | weston_layer_init(&shell->lock_layer, ec); |
| 5208 | weston_layer_init(&shell->input_panel_layer, ec); |
| 5209 | |
| 5210 | weston_layer_set_position(&shell->fullscreen_layer, |
| 5211 | WESTON_LAYER_POSITION_FULLSCREEN); |
| 5212 | weston_layer_set_position(&shell->panel_layer, |
| 5213 | WESTON_LAYER_POSITION_UI); |
| 5214 | weston_layer_set_position(&shell->background_layer, |
| 5215 | WESTON_LAYER_POSITION_BACKGROUND); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5216 | |
| 5217 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5218 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5219 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5220 | if (input_panel_setup(shell) < 0) |
| 5221 | return -1; |
| 5222 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 5223 | shell->text_backend = text_backend_init(ec); |
| 5224 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 5225 | return -1; |
| 5226 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5227 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 5228 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5229 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 5230 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 5231 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5232 | for (i = 0; i < shell->workspaces.num; i++) { |
| 5233 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 5234 | if (pws == NULL) |
| 5235 | return -1; |
| 5236 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 5237 | *pws = workspace_create(shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5238 | if (*pws == NULL) |
| 5239 | return -1; |
| 5240 | } |
| 5241 | activate_workspace(shell, 0); |
| 5242 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 5243 | weston_layer_init(&shell->minimized_layer, ec); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 5244 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5245 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 5246 | wl_list_init(&shell->workspaces.animation.link); |
| 5247 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 5248 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 5249 | shell->desktop = weston_desktop_create(ec, &shell_desktop_api, shell); |
| 5250 | if (!shell->desktop) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5251 | return -1; |
| 5252 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5253 | if (wl_global_create(ec->wl_display, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5254 | &weston_desktop_shell_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5255 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5256 | return -1; |
| 5257 | |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 5258 | weston_compositor_get_time(&shell->child.deathstamp); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5259 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5260 | shell->panel_position = WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP; |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 5261 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5262 | setup_output_destroy_handler(ec, shell); |
| 5263 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5264 | loop = wl_display_get_event_loop(ec->wl_display); |
| 5265 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5266 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 5267 | wl_list_for_each(seat, &ec->seat_list, link) |
| 5268 | handle_seat_created(NULL, seat); |
| 5269 | shell->seat_create_listener.notify = handle_seat_created; |
| 5270 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 5271 | |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 5272 | shell->resized_listener.notify = handle_output_resized; |
| 5273 | wl_signal_add(&ec->output_resized_signal, &shell->resized_listener); |
| 5274 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 5275 | screenshooter_create(ec); |
| 5276 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5277 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5278 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5279 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5280 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5281 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 5282 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5283 | return 0; |
| 5284 | } |