Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2 | * Copyright © 2010-2012 Intel Corporation |
Pekka Paalanen | d581a8f | 2012-01-27 16:25:16 +0200 | [diff] [blame] | 3 | * Copyright © 2011-2012 Collabora, Ltd. |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4 | * Copyright © 2013 Raspberry Pi Foundation |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 12 | * |
Bryce Harrington | af637c2 | 2015-06-11 12:55:55 -0700 | [diff] [blame] | 13 | * The above copyright notice and this permission notice (including the next |
| 14 | * paragraph) shall be included in all copies or substantial portions of the |
| 15 | * Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | * DEALINGS IN THE SOFTWARE. |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 24 | */ |
| 25 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 26 | #include "config.h" |
| 27 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 28 | #include <stdlib.h> |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 29 | #include <stdint.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 30 | #include <stdio.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 31 | #include <string.h> |
| 32 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 33 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 34 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 35 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 36 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 37 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 38 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 39 | #include "shell.h" |
Pekka Paalanen | 58f98c9 | 2016-06-03 16:45:21 +0300 | [diff] [blame] | 40 | #include "compositor/weston.h" |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 41 | #include "weston-desktop-shell-server-protocol.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 42 | #include "shared/config-parser.h" |
Jon Cruz | d618f68 | 2015-06-15 15:37:09 -0700 | [diff] [blame] | 43 | #include "shared/helpers.h" |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 44 | #include "shared/timespec-util.h" |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [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 | |
Giulio Camuffo | 1aaf3e4 | 2013-12-09 22:47:58 +0100 | [diff] [blame] | 50 | #ifndef static_assert |
| 51 | #define static_assert(cond, msg) |
| 52 | #endif |
| 53 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 54 | struct focus_state { |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 55 | struct desktop_shell *shell; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 56 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 57 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 58 | struct weston_surface *keyboard_focus; |
| 59 | struct wl_list link; |
| 60 | struct wl_listener seat_destroy_listener; |
| 61 | struct wl_listener surface_destroy_listener; |
| 62 | }; |
| 63 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 64 | /* |
| 65 | * Surface stacking and ordering. |
| 66 | * |
| 67 | * This is handled using several linked lists of surfaces, organised into |
| 68 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 69 | * above all of the surfaces in the layer below. The set of layers is static and |
| 70 | * in the following order (top-most first): |
| 71 | * • Lock layer (only ever displayed on its own) |
| 72 | * • Cursor layer |
Manuel Bachmann | 805d2f5 | 2014-03-05 12:21:34 +0100 | [diff] [blame] | 73 | * • Input panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 74 | * • Fullscreen layer |
| 75 | * • Panel layer |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 76 | * • Workspace layers |
| 77 | * • Background layer |
| 78 | * |
| 79 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 80 | * display. For example, when locking the screen, all layers except the lock |
| 81 | * layer are removed. |
| 82 | * |
| 83 | * A surface’s layer is modified on configuring the surface, in |
| 84 | * set_surface_type() (which is only called when the surface’s type change is |
| 85 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 86 | * fullscreen) its layer changes too. |
| 87 | * |
| 88 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 89 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 90 | * linked list of its children. When a surface’s layer is updated, so are the |
| 91 | * layers of its children. Note that child surfaces are *not* the same as |
| 92 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 93 | * order. |
| 94 | * |
| 95 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 96 | * have the same parent) only contains weston_surfaces which have a |
| 97 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 98 | * weston_surfaces. This means that the following implication does *not* hold: |
| 99 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 100 | */ |
| 101 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 102 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 103 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 104 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 105 | struct weston_desktop_surface *desktop_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 106 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 107 | int32_t last_width, last_height; |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 108 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 109 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 110 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 111 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 112 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 113 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 114 | int unresponsive, grabbed; |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 115 | uint32_t resize_edges; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 116 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 117 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 118 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 119 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 120 | } rotation; |
| 121 | |
| 122 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 123 | struct weston_transform transform; /* matrix from x, y */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 124 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 125 | } fullscreen; |
| 126 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 127 | struct weston_transform workspace_transform; |
| 128 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 129 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 130 | struct weston_output *output; |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame^] | 131 | struct wl_listener output_destroy_listener; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 132 | |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 133 | struct surface_state { |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 134 | bool fullscreen; |
| 135 | bool maximized; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 136 | bool lowered; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 137 | } state; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 138 | |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 139 | struct { |
| 140 | bool is_set; |
| 141 | int32_t x; |
| 142 | int32_t y; |
| 143 | } xwayland; |
| 144 | |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 145 | int focus_count; |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 146 | |
| 147 | bool destroying; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 148 | }; |
| 149 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 150 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 151 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 152 | struct shell_surface *shsurf; |
| 153 | struct wl_listener shsurf_destroy_listener; |
| 154 | }; |
| 155 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 156 | struct shell_touch_grab { |
| 157 | struct weston_touch_grab grab; |
| 158 | struct shell_surface *shsurf; |
| 159 | struct wl_listener shsurf_destroy_listener; |
| 160 | struct weston_touch *touch; |
| 161 | }; |
| 162 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 163 | struct weston_move_grab { |
| 164 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 165 | wl_fixed_t dx, dy; |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 166 | bool client_initiated; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 167 | }; |
| 168 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 169 | struct weston_touch_move_grab { |
| 170 | struct shell_touch_grab base; |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 171 | int active; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 172 | wl_fixed_t dx, dy; |
| 173 | }; |
| 174 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 175 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 176 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 177 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 178 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 179 | float x; |
| 180 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 181 | } center; |
| 182 | }; |
| 183 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 184 | struct shell_seat { |
| 185 | struct weston_seat *seat; |
| 186 | struct wl_listener seat_destroy_listener; |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 187 | struct weston_surface *focused_surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 188 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 189 | struct wl_listener caps_changed_listener; |
| 190 | struct wl_listener pointer_focus_listener; |
| 191 | struct wl_listener keyboard_focus_listener; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 192 | }; |
| 193 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 194 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 195 | static struct desktop_shell * |
| 196 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 197 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 198 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 199 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 200 | |
| 201 | static void |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 202 | surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 203 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 204 | static void |
| 205 | shell_fade_startup(struct desktop_shell *shell); |
| 206 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 207 | static void |
| 208 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 209 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 210 | static struct shell_seat * |
| 211 | get_shell_seat(struct weston_seat *seat); |
| 212 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 213 | static void |
| 214 | get_output_panel_size(struct desktop_shell *shell, |
| 215 | struct weston_output *output, |
| 216 | int *width, int *height); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 217 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 218 | static void |
| 219 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 220 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 221 | static int |
| 222 | shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 223 | { |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 224 | const char *t, *c; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 225 | struct weston_desktop_surface *desktop_surface = |
| 226 | weston_surface_get_desktop_surface(surface); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 227 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 228 | t = weston_desktop_surface_get_title(desktop_surface); |
| 229 | c = weston_desktop_surface_get_app_id(desktop_surface); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 230 | |
| 231 | return snprintf(buf, len, "%s window%s%s%s%s%s", |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 232 | "top-level", |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 233 | t ? " '" : "", t ?: "", t ? "'" : "", |
| 234 | c ? " of " : "", c ?: ""); |
| 235 | } |
| 236 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 237 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 238 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 239 | { |
| 240 | struct shell_grab *grab; |
| 241 | |
| 242 | grab = container_of(listener, struct shell_grab, |
| 243 | shsurf_destroy_listener); |
| 244 | |
| 245 | grab->shsurf = NULL; |
| 246 | } |
| 247 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 248 | struct weston_view * |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 249 | get_default_view(struct weston_surface *surface) |
| 250 | { |
| 251 | struct shell_surface *shsurf; |
| 252 | struct weston_view *view; |
| 253 | |
| 254 | if (!surface || wl_list_empty(&surface->views)) |
| 255 | return NULL; |
| 256 | |
| 257 | shsurf = get_shell_surface(surface); |
| 258 | if (shsurf) |
| 259 | return shsurf->view; |
| 260 | |
| 261 | wl_list_for_each(view, &surface->views, surface_link) |
| 262 | if (weston_view_is_mapped(view)) |
| 263 | return view; |
| 264 | |
| 265 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 266 | } |
| 267 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 268 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 269 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 270 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 271 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 272 | struct weston_pointer *pointer, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 273 | enum weston_desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 274 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 275 | struct desktop_shell *shell = shsurf->shell; |
| 276 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 277 | weston_seat_break_desktop_grabs(pointer->seat); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 278 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 279 | grab->grab.interface = interface; |
| 280 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 281 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 282 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 283 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 284 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 285 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 286 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 287 | if (shell->child.desktop_shell) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 288 | weston_desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 289 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 290 | weston_pointer_set_focus(pointer, |
| 291 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 292 | wl_fixed_from_int(0), |
| 293 | wl_fixed_from_int(0)); |
| 294 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 295 | } |
| 296 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 297 | static void |
Quentin Glidic | 581df06 | 2016-06-23 18:55:19 +0200 | [diff] [blame] | 298 | get_panel_size(struct desktop_shell *shell, |
| 299 | struct weston_view *view, |
| 300 | int *width, |
| 301 | int *height) |
| 302 | { |
| 303 | float x1, y1; |
| 304 | float x2, y2; |
| 305 | weston_view_to_global_float(view, 0, 0, &x1, &y1); |
| 306 | weston_view_to_global_float(view, |
| 307 | view->surface->width, |
| 308 | view->surface->height, |
| 309 | &x2, &y2); |
| 310 | *width = (int)(x2 - x1); |
| 311 | *height = (int)(y2 - y1); |
| 312 | } |
| 313 | |
| 314 | static void |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 315 | get_output_panel_size(struct desktop_shell *shell, |
| 316 | struct weston_output *output, |
| 317 | int *width, |
| 318 | int *height) |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 319 | { |
| 320 | struct weston_view *view; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 321 | |
| 322 | *width = 0; |
| 323 | *height = 0; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 324 | |
| 325 | if (!output) |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 326 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 327 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 328 | 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] | 329 | if (view->surface->output == output) { |
| 330 | get_panel_size(shell, view, width, height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 331 | return; |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 335 | /* the correct view wasn't found */ |
| 336 | } |
| 337 | |
| 338 | static void |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 339 | get_output_work_area(struct desktop_shell *shell, |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 340 | struct weston_output *output, |
| 341 | pixman_rectangle32_t *area) |
| 342 | { |
| 343 | int32_t panel_width = 0, panel_height = 0; |
| 344 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 345 | area->x = output->x; |
| 346 | area->y = output->y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 347 | |
| 348 | get_output_panel_size(shell, output, &panel_width, &panel_height); |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 349 | switch (shell->panel_position) { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 350 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 351 | default: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 352 | area->y += panel_height; |
Daniel Stone | 2ef9b1a | 2017-03-13 16:31:36 +0000 | [diff] [blame] | 353 | /* fallthrough */ |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 354 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 355 | area->width = output->width; |
| 356 | area->height = output->height - panel_height; |
| 357 | break; |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 358 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 359 | area->x += panel_width; |
Daniel Stone | 2ef9b1a | 2017-03-13 16:31:36 +0000 | [diff] [blame] | 360 | /* fallthrough */ |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 361 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 362 | area->width = output->width - panel_width; |
| 363 | area->height = output->height; |
| 364 | break; |
| 365 | } |
Jasper St. Pierre | 6458ec3 | 2014-04-11 16:00:31 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 368 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 369 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 370 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 371 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 372 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 373 | grab->shsurf->grabbed = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 374 | |
| 375 | if (grab->shsurf->resize_edges) { |
| 376 | grab->shsurf->resize_edges = 0; |
Jasper St. Pierre | 5befdda | 2014-05-06 08:50:47 -0400 | [diff] [blame] | 377 | } |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 378 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 379 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 380 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 384 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 385 | const struct weston_touch_grab_interface *interface, |
| 386 | struct shell_surface *shsurf, |
| 387 | struct weston_touch *touch) |
| 388 | { |
| 389 | struct desktop_shell *shell = shsurf->shell; |
U. Artie Eoff | cf5737a | 2014-01-17 10:08:25 -0800 | [diff] [blame] | 390 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 391 | weston_seat_break_desktop_grabs(touch->seat); |
Kristian Høgsberg | 74071e0 | 2014-04-29 15:01:16 -0700 | [diff] [blame] | 392 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 393 | grab->grab.interface = interface; |
| 394 | grab->shsurf = shsurf; |
| 395 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 396 | wl_signal_add(&shsurf->destroy_signal, |
| 397 | &grab->shsurf_destroy_listener); |
| 398 | |
| 399 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 400 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 401 | |
| 402 | weston_touch_start_grab(touch, &grab->grab); |
| 403 | if (shell->child.desktop_shell) |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 404 | weston_touch_set_focus(touch, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 405 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | static void |
| 409 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 410 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 411 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 412 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 413 | grab->shsurf->grabbed = 0; |
| 414 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 415 | |
| 416 | weston_touch_end_grab(grab->touch); |
| 417 | } |
| 418 | |
| 419 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 420 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 421 | struct weston_output *output); |
| 422 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 423 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 424 | get_modifier(char *modifier) |
| 425 | { |
| 426 | if (!modifier) |
| 427 | return MODIFIER_SUPER; |
| 428 | |
| 429 | if (!strcmp("ctrl", modifier)) |
| 430 | return MODIFIER_CTRL; |
| 431 | else if (!strcmp("alt", modifier)) |
| 432 | return MODIFIER_ALT; |
| 433 | else if (!strcmp("super", modifier)) |
| 434 | return MODIFIER_SUPER; |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 435 | else if (!strcmp("none", modifier)) |
| 436 | return 0; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 437 | else |
| 438 | return MODIFIER_SUPER; |
| 439 | } |
| 440 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 441 | static enum animation_type |
| 442 | get_animation_type(char *animation) |
| 443 | { |
U. Artie Eoff | b571910 | 2014-01-15 14:26:31 -0800 | [diff] [blame] | 444 | if (!animation) |
| 445 | return ANIMATION_NONE; |
| 446 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 447 | if (!strcmp("zoom", animation)) |
| 448 | return ANIMATION_ZOOM; |
| 449 | else if (!strcmp("fade", animation)) |
| 450 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 451 | else if (!strcmp("dim-layer", animation)) |
| 452 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 453 | else |
| 454 | return ANIMATION_NONE; |
| 455 | } |
| 456 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 457 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 458 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 459 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 460 | struct weston_config_section *section; |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 461 | char *s, *client; |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 462 | int ret; |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 463 | int allow_zap; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 464 | |
Giulio Camuffo | d52f3b7 | 2016-06-02 21:48:11 +0300 | [diff] [blame] | 465 | section = weston_config_get_section(wet_get_config(shell->compositor), |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 466 | "shell", NULL, NULL); |
Pekka Paalanen | 974c094 | 2014-09-05 14:45:09 +0300 | [diff] [blame] | 467 | ret = asprintf(&client, "%s/%s", weston_config_get_libexec_dir(), |
| 468 | WESTON_SHELL_CLIENT); |
| 469 | if (ret < 0) |
| 470 | client = NULL; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 471 | weston_config_section_get_string(section, |
Derek Foreman | c721043 | 2014-08-21 11:32:38 -0500 | [diff] [blame] | 472 | "client", &s, client); |
| 473 | free(client); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 474 | shell->client = s; |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 475 | |
| 476 | weston_config_section_get_bool(section, |
| 477 | "allow-zap", &allow_zap, true); |
| 478 | shell->allow_zap = allow_zap; |
| 479 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 480 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 481 | "binding-modifier", &s, "super"); |
| 482 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 483 | free(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 484 | |
| 485 | weston_config_section_get_string(section, |
| 486 | "exposay-modifier", &s, "none"); |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 487 | shell->exposay_modifier = get_modifier(s); |
Kristian Høgsberg | d56ab4e | 2014-01-16 16:51:52 -0800 | [diff] [blame] | 488 | free(s); |
| 489 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 490 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 491 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 492 | free(s); |
Jonny Lamb | f322f8e | 2014-08-12 15:13:30 +0200 | [diff] [blame] | 493 | weston_config_section_get_string(section, "close-animation", &s, "fade"); |
| 494 | shell->win_close_animation_type = get_animation_type(s); |
| 495 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 496 | weston_config_section_get_string(section, |
| 497 | "startup-animation", &s, "fade"); |
| 498 | shell->startup_animation_type = get_animation_type(s); |
| 499 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 500 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 501 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 502 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 503 | shell->focus_animation_type = get_animation_type(s); |
| 504 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 505 | weston_config_section_get_uint(section, "num-workspaces", |
| 506 | &shell->workspaces.num, |
| 507 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 508 | } |
| 509 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 510 | struct weston_output * |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 511 | get_default_output(struct weston_compositor *compositor) |
| 512 | { |
Armin Krezović | 10b0618 | 2016-06-23 11:59:30 +0200 | [diff] [blame] | 513 | if (wl_list_empty(&compositor->output_list)) |
| 514 | return NULL; |
| 515 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 516 | return container_of(compositor->output_list.next, |
| 517 | struct weston_output, link); |
| 518 | } |
| 519 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 520 | static int |
| 521 | focus_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 522 | { |
| 523 | return snprintf(buf, len, "focus highlight effect for output %s", |
| 524 | surface->output->name); |
| 525 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 526 | |
| 527 | /* no-op func for checking focus surface */ |
| 528 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 529 | 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] | 530 | { |
| 531 | } |
| 532 | |
| 533 | static struct focus_surface * |
| 534 | get_focus_surface(struct weston_surface *surface) |
| 535 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 536 | if (surface->committed == focus_surface_committed) |
| 537 | return surface->committed_private; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 538 | else |
| 539 | return NULL; |
| 540 | } |
| 541 | |
| 542 | static bool |
| 543 | is_focus_surface (struct weston_surface *es) |
| 544 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 545 | return (es->committed == focus_surface_committed); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | static bool |
| 549 | is_focus_view (struct weston_view *view) |
| 550 | { |
| 551 | return is_focus_surface (view->surface); |
| 552 | } |
| 553 | |
| 554 | static struct focus_surface * |
| 555 | create_focus_surface(struct weston_compositor *ec, |
| 556 | struct weston_output *output) |
| 557 | { |
| 558 | struct focus_surface *fsurf = NULL; |
| 559 | struct weston_surface *surface = NULL; |
| 560 | |
| 561 | fsurf = malloc(sizeof *fsurf); |
| 562 | if (!fsurf) |
| 563 | return NULL; |
| 564 | |
| 565 | fsurf->surface = weston_surface_create(ec); |
| 566 | surface = fsurf->surface; |
| 567 | if (surface == NULL) { |
| 568 | free(fsurf); |
| 569 | return NULL; |
| 570 | } |
| 571 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 572 | surface->committed = focus_surface_committed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 573 | surface->output = output; |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 574 | surface->is_mapped = true; |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 575 | surface->committed_private = fsurf; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 576 | weston_surface_set_label_func(surface, focus_surface_get_label); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 577 | |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 578 | fsurf->view = weston_view_create(surface); |
| 579 | if (fsurf->view == NULL) { |
| 580 | weston_surface_destroy(surface); |
| 581 | free(fsurf); |
| 582 | return NULL; |
| 583 | } |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 584 | weston_view_set_output(fsurf->view, output); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 585 | fsurf->view->is_mapped = true; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 586 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 587 | weston_surface_set_size(surface, output->width, output->height); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 588 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 589 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 590 | pixman_region32_fini(&surface->opaque); |
| 591 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 592 | output->width, output->height); |
| 593 | pixman_region32_fini(&surface->input); |
| 594 | pixman_region32_init(&surface->input); |
| 595 | |
| 596 | wl_list_init(&fsurf->workspace_transform.link); |
| 597 | |
| 598 | return fsurf; |
| 599 | } |
| 600 | |
| 601 | static void |
| 602 | focus_surface_destroy(struct focus_surface *fsurf) |
| 603 | { |
| 604 | weston_surface_destroy(fsurf->surface); |
| 605 | free(fsurf); |
| 606 | } |
| 607 | |
| 608 | static void |
| 609 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 610 | { |
| 611 | struct workspace *ws = data; |
| 612 | |
| 613 | ws->focus_animation = NULL; |
| 614 | } |
| 615 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 616 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 617 | focus_state_destroy(struct focus_state *state) |
| 618 | { |
| 619 | wl_list_remove(&state->seat_destroy_listener.link); |
| 620 | wl_list_remove(&state->surface_destroy_listener.link); |
| 621 | free(state); |
| 622 | } |
| 623 | |
| 624 | static void |
| 625 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 626 | { |
| 627 | struct focus_state *state = container_of(listener, |
| 628 | struct focus_state, |
| 629 | seat_destroy_listener); |
| 630 | |
| 631 | wl_list_remove(&state->link); |
| 632 | focus_state_destroy(state); |
| 633 | } |
| 634 | |
| 635 | static void |
| 636 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 637 | { |
| 638 | struct focus_state *state = container_of(listener, |
| 639 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 640 | surface_destroy_listener); |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 641 | struct weston_surface *main_surface; |
| 642 | struct weston_view *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 643 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 644 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 645 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 646 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 647 | next = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 648 | wl_list_for_each(view, |
| 649 | &state->ws->layer.view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 650 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 651 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 652 | if (is_focus_view(view)) |
| 653 | continue; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 654 | if (!get_shell_surface(view->surface)) |
| 655 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 656 | |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 657 | next = view; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 658 | break; |
| 659 | } |
| 660 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 661 | /* if the focus was a sub-surface, activate its main surface */ |
| 662 | if (main_surface != state->keyboard_focus) |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 663 | next = get_default_view(main_surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 664 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 665 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 666 | state->keyboard_focus = NULL; |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 667 | activate(state->shell, next, state->seat, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 668 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 669 | } else { |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 670 | if (state->shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 671 | if (state->ws->focus_animation) |
| 672 | weston_view_animation_destroy(state->ws->focus_animation); |
| 673 | |
| 674 | state->ws->focus_animation = weston_fade_run( |
| 675 | state->ws->fsurf_front->view, |
| 676 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 677 | focus_animation_done, state->ws); |
| 678 | } |
| 679 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 680 | wl_list_remove(&state->link); |
| 681 | focus_state_destroy(state); |
| 682 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | static struct focus_state * |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 686 | focus_state_create(struct desktop_shell *shell, struct weston_seat *seat, |
| 687 | struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 688 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 689 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 690 | |
| 691 | state = malloc(sizeof *state); |
| 692 | if (state == NULL) |
| 693 | return NULL; |
| 694 | |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 695 | state->shell = shell; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 696 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 697 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 698 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 699 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 700 | |
| 701 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 702 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 703 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 704 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 705 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 706 | |
| 707 | return state; |
| 708 | } |
| 709 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 710 | static struct focus_state * |
| 711 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 712 | { |
| 713 | struct workspace *ws = get_current_workspace(shell); |
| 714 | struct focus_state *state; |
| 715 | |
| 716 | wl_list_for_each(state, &ws->focus_list, link) |
| 717 | if (state->seat == seat) |
| 718 | break; |
| 719 | |
| 720 | if (&state->link == &ws->focus_list) |
Quentin Glidic | fff3981 | 2016-08-15 10:56:52 +0200 | [diff] [blame] | 721 | state = focus_state_create(shell, seat, ws); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 722 | |
| 723 | return state; |
| 724 | } |
| 725 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 726 | static void |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 727 | focus_state_set_focus(struct focus_state *state, |
| 728 | struct weston_surface *surface) |
| 729 | { |
| 730 | if (state->keyboard_focus) { |
| 731 | wl_list_remove(&state->surface_destroy_listener.link); |
| 732 | wl_list_init(&state->surface_destroy_listener.link); |
| 733 | } |
| 734 | |
| 735 | state->keyboard_focus = surface; |
| 736 | if (surface) |
| 737 | wl_signal_add(&surface->destroy_signal, |
| 738 | &state->surface_destroy_listener); |
| 739 | } |
| 740 | |
| 741 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 742 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 743 | { |
| 744 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 745 | struct weston_surface *surface; |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 746 | struct wl_list pending_seat_list; |
| 747 | struct weston_seat *seat, *next_seat; |
| 748 | |
| 749 | /* Temporarily steal the list of seats so that we can keep |
| 750 | * track of the seats we've already processed */ |
| 751 | wl_list_init(&pending_seat_list); |
| 752 | wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); |
| 753 | wl_list_init(&shell->compositor->seat_list); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 754 | |
| 755 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 756 | struct weston_keyboard *keyboard = |
| 757 | weston_seat_get_keyboard(state->seat); |
| 758 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 759 | wl_list_remove(&state->seat->link); |
| 760 | wl_list_insert(&shell->compositor->seat_list, |
| 761 | &state->seat->link); |
| 762 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 763 | if (!keyboard) |
Kristian Høgsberg | e61d2f4 | 2014-01-17 12:18:53 -0800 | [diff] [blame] | 764 | continue; |
| 765 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 766 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 767 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 768 | weston_keyboard_set_focus(keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 769 | } |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 770 | |
| 771 | /* For any remaining seats that we don't have a focus state |
| 772 | * for we'll reset the keyboard focus to NULL */ |
| 773 | wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 774 | struct weston_keyboard *keyboard = |
| 775 | weston_seat_get_keyboard(seat); |
| 776 | |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 777 | wl_list_insert(&shell->compositor->seat_list, &seat->link); |
| 778 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 779 | if (!keyboard) |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 780 | continue; |
| 781 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 782 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | 4237f50 | 2014-04-09 16:33:31 +0100 | [diff] [blame] | 783 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 787 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 788 | struct weston_seat *seat) |
| 789 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 790 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 791 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 792 | |
| 793 | wl_list_for_each(state, &ws->focus_list, link) { |
| 794 | if (state->seat == seat) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 795 | focus_state_set_focus(state, keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 796 | return; |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | static void |
| 802 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 803 | struct weston_surface *surface) |
| 804 | { |
| 805 | struct focus_state *state; |
| 806 | |
| 807 | wl_list_for_each(state, &ws->focus_list, link) |
| 808 | if (state->keyboard_focus == surface) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 809 | focus_state_set_focus(state, NULL); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 813 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 814 | struct weston_view *from, struct weston_view *to) |
| 815 | { |
| 816 | struct weston_output *output; |
| 817 | bool focus_surface_created = false; |
| 818 | |
| 819 | /* FIXME: Only support dim animation using two layers */ |
| 820 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 821 | return; |
| 822 | |
| 823 | output = get_default_output(shell->compositor); |
| 824 | if (ws->fsurf_front == NULL && (from || to)) { |
| 825 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 826 | if (ws->fsurf_front == NULL) |
| 827 | return; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 828 | ws->fsurf_front->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 829 | |
| 830 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 831 | if (ws->fsurf_back == NULL) { |
| 832 | focus_surface_destroy(ws->fsurf_front); |
| 833 | return; |
| 834 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 835 | ws->fsurf_back->view->alpha = 0.0; |
U. Artie Eoff | 0b23b2b | 2014-01-15 14:45:59 -0800 | [diff] [blame] | 836 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 837 | focus_surface_created = true; |
| 838 | } else { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 839 | weston_layer_entry_remove(&ws->fsurf_front->view->layer_link); |
| 840 | weston_layer_entry_remove(&ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | if (ws->focus_animation) { |
| 844 | weston_view_animation_destroy(ws->focus_animation); |
| 845 | ws->focus_animation = NULL; |
| 846 | } |
| 847 | |
| 848 | if (to) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 849 | weston_layer_entry_insert(&to->layer_link, |
| 850 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 851 | else if (from) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 852 | weston_layer_entry_insert(&ws->layer.view_list, |
| 853 | &ws->fsurf_front->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 854 | |
| 855 | if (focus_surface_created) { |
| 856 | ws->focus_animation = weston_fade_run( |
| 857 | ws->fsurf_front->view, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 858 | ws->fsurf_front->view->alpha, 0.4, 300, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 859 | focus_animation_done, ws); |
| 860 | } else if (from) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 861 | weston_layer_entry_insert(&from->layer_link, |
| 862 | &ws->fsurf_back->view->layer_link); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 863 | ws->focus_animation = weston_stable_fade_run( |
| 864 | ws->fsurf_front->view, 0.0, |
Jonny Lamb | 7e7d485 | 2014-05-22 22:41:34 +0200 | [diff] [blame] | 865 | ws->fsurf_back->view, 0.4, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 866 | focus_animation_done, ws); |
| 867 | } else if (to) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 868 | weston_layer_entry_insert(&ws->layer.view_list, |
| 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 | } |
| 875 | } |
| 876 | |
| 877 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 878 | workspace_destroy(struct workspace *ws) |
| 879 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 880 | struct focus_state *state, *next; |
| 881 | |
| 882 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 883 | focus_state_destroy(state); |
| 884 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 885 | if (ws->fsurf_front) |
| 886 | focus_surface_destroy(ws->fsurf_front); |
| 887 | if (ws->fsurf_back) |
| 888 | focus_surface_destroy(ws->fsurf_back); |
| 889 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 890 | free(ws); |
| 891 | } |
| 892 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 893 | static void |
| 894 | seat_destroyed(struct wl_listener *listener, void *data) |
| 895 | { |
| 896 | struct weston_seat *seat = data; |
| 897 | struct focus_state *state, *next; |
| 898 | struct workspace *ws = container_of(listener, |
| 899 | struct workspace, |
| 900 | seat_destroyed_listener); |
| 901 | |
| 902 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 903 | if (state->seat == seat) |
| 904 | wl_list_remove(&state->link); |
| 905 | } |
| 906 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 907 | static struct workspace * |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 908 | workspace_create(struct desktop_shell *shell) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 909 | { |
| 910 | struct workspace *ws = malloc(sizeof *ws); |
| 911 | if (ws == NULL) |
| 912 | return NULL; |
| 913 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 914 | weston_layer_init(&ws->layer, shell->compositor); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 915 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 916 | wl_list_init(&ws->focus_list); |
| 917 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 918 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 919 | ws->fsurf_front = NULL; |
| 920 | ws->fsurf_back = NULL; |
| 921 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 922 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 923 | return ws; |
| 924 | } |
| 925 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 926 | static int |
| 927 | workspace_is_empty(struct workspace *ws) |
| 928 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 929 | return wl_list_empty(&ws->layer.view_list.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 930 | } |
| 931 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 932 | static struct workspace * |
| 933 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 934 | { |
| 935 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 936 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 937 | pws += index; |
| 938 | return *pws; |
| 939 | } |
| 940 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 941 | struct workspace * |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 942 | get_current_workspace(struct desktop_shell *shell) |
| 943 | { |
| 944 | return get_workspace(shell, shell->workspaces.current); |
| 945 | } |
| 946 | |
| 947 | static void |
| 948 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 949 | { |
| 950 | struct workspace *ws; |
| 951 | |
| 952 | ws = get_workspace(shell, index); |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 953 | weston_layer_set_position(&ws->layer, WESTON_LAYER_POSITION_NORMAL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 954 | |
| 955 | shell->workspaces.current = index; |
| 956 | } |
| 957 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 958 | static unsigned int |
| 959 | get_output_height(struct weston_output *output) |
| 960 | { |
| 961 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 962 | } |
| 963 | |
| 964 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 965 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 966 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 967 | struct weston_transform *transform; |
| 968 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 969 | if (is_focus_view(view)) { |
| 970 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 971 | transform = &fsurf->workspace_transform; |
| 972 | } else { |
| 973 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 974 | transform = &shsurf->workspace_transform; |
| 975 | } |
| 976 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 977 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 978 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 979 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 980 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 981 | weston_matrix_init(&transform->matrix); |
| 982 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 983 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 984 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | static void |
| 988 | workspace_translate_out(struct workspace *ws, double fraction) |
| 989 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 990 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 991 | unsigned int height; |
| 992 | double d; |
| 993 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 994 | 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] | 995 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 996 | d = height * fraction; |
| 997 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 998 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | static void |
| 1003 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1004 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1005 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1006 | unsigned int height; |
| 1007 | double d; |
| 1008 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1009 | 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] | 1010 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1011 | |
| 1012 | if (fraction > 0) |
| 1013 | d = -(height - height * fraction); |
| 1014 | else |
| 1015 | d = height + height * fraction; |
| 1016 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1017 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1022 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1023 | unsigned int index, |
| 1024 | struct workspace *from, |
| 1025 | struct workspace *to) |
| 1026 | { |
| 1027 | shell->workspaces.current = index; |
| 1028 | |
| 1029 | shell->workspaces.anim_to = to; |
| 1030 | shell->workspaces.anim_from = from; |
| 1031 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1032 | shell->workspaces.anim_timestamp = (struct timespec) { 0 }; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1033 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1034 | weston_layer_set_position(&to->layer, WESTON_LAYER_POSITION_NORMAL); |
| 1035 | weston_layer_set_position(&from->layer, WESTON_LAYER_POSITION_NORMAL - 1); |
| 1036 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1037 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | static void |
| 1041 | workspace_deactivate_transforms(struct workspace *ws) |
| 1042 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1043 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1044 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1045 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1046 | 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] | 1047 | if (is_focus_view(view)) { |
| 1048 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1049 | transform = &fsurf->workspace_transform; |
| 1050 | } else { |
| 1051 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1052 | transform = &shsurf->workspace_transform; |
| 1053 | } |
| 1054 | |
| 1055 | if (!wl_list_empty(&transform->link)) { |
| 1056 | wl_list_remove(&transform->link); |
| 1057 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1058 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1059 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | static void |
| 1064 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1065 | struct workspace *from, |
| 1066 | struct workspace *to) |
| 1067 | { |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1068 | struct weston_view *view; |
| 1069 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1070 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1071 | |
Ander Conselvan de Oliveira | 9c6217e | 2014-05-07 11:57:26 +0300 | [diff] [blame] | 1072 | /* Views that extend past the bottom of the output are still |
| 1073 | * visible after the workspace animation ends but before its layer |
| 1074 | * is hidden. In that case, we need to damage below those views so |
| 1075 | * that the screen is properly repainted. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1076 | 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] | 1077 | weston_view_damage_below(view); |
| 1078 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1079 | wl_list_remove(&shell->workspaces.animation.link); |
| 1080 | workspace_deactivate_transforms(from); |
| 1081 | workspace_deactivate_transforms(to); |
| 1082 | shell->workspaces.anim_to = NULL; |
| 1083 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1084 | weston_layer_unset_position(&shell->workspaces.anim_from->layer); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | static void |
| 1088 | animate_workspace_change_frame(struct weston_animation *animation, |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1089 | struct weston_output *output, |
| 1090 | const struct timespec *time) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1091 | { |
| 1092 | struct desktop_shell *shell = |
| 1093 | container_of(animation, struct desktop_shell, |
| 1094 | workspaces.animation); |
| 1095 | struct workspace *from = shell->workspaces.anim_from; |
| 1096 | struct workspace *to = shell->workspaces.anim_to; |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1097 | int64_t t; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1098 | double x, y; |
| 1099 | |
| 1100 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1101 | finish_workspace_change_animation(shell, from, to); |
| 1102 | return; |
| 1103 | } |
| 1104 | |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1105 | if (timespec_is_zero(&shell->workspaces.anim_timestamp)) { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1106 | if (shell->workspaces.anim_current == 0.0) |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1107 | shell->workspaces.anim_timestamp = *time; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1108 | else |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1109 | timespec_add_msec(&shell->workspaces.anim_timestamp, |
| 1110 | time, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1111 | /* Invers of movement function 'y' below. */ |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1112 | -(asin(1.0 - shell->workspaces.anim_current) * |
| 1113 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1114 | M_2_PI)); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1115 | } |
| 1116 | |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1117 | t = timespec_sub_to_msec(time, &shell->workspaces.anim_timestamp); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1118 | |
| 1119 | /* |
| 1120 | * x = [0, π/2] |
| 1121 | * y(x) = sin(x) |
| 1122 | */ |
| 1123 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1124 | y = sin(x); |
| 1125 | |
| 1126 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1127 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1128 | |
| 1129 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1130 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1131 | shell->workspaces.anim_current = y; |
| 1132 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1133 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1134 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1135 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1136 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | static void |
| 1140 | animate_workspace_change(struct desktop_shell *shell, |
| 1141 | unsigned int index, |
| 1142 | struct workspace *from, |
| 1143 | struct workspace *to) |
| 1144 | { |
| 1145 | struct weston_output *output; |
| 1146 | |
| 1147 | int dir; |
| 1148 | |
| 1149 | if (index > shell->workspaces.current) |
| 1150 | dir = -1; |
| 1151 | else |
| 1152 | dir = 1; |
| 1153 | |
| 1154 | shell->workspaces.current = index; |
| 1155 | |
| 1156 | shell->workspaces.anim_dir = dir; |
| 1157 | shell->workspaces.anim_from = from; |
| 1158 | shell->workspaces.anim_to = to; |
| 1159 | shell->workspaces.anim_current = 0.0; |
Alexandros Frantzis | 8250a61 | 2017-11-16 18:20:52 +0200 | [diff] [blame] | 1160 | shell->workspaces.anim_timestamp = (struct timespec) { 0 }; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1161 | |
| 1162 | output = container_of(shell->compositor->output_list.next, |
| 1163 | struct weston_output, link); |
| 1164 | wl_list_insert(&output->animation_list, |
| 1165 | &shell->workspaces.animation.link); |
| 1166 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1167 | weston_layer_set_position(&to->layer, WESTON_LAYER_POSITION_NORMAL); |
| 1168 | weston_layer_set_position(&from->layer, WESTON_LAYER_POSITION_NORMAL - 1); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1169 | |
| 1170 | workspace_translate_in(to, 0); |
| 1171 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1172 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1173 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1174 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1175 | } |
| 1176 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1177 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1178 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1179 | struct workspace *from, struct workspace *to) |
| 1180 | { |
| 1181 | shell->workspaces.current = index; |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 1182 | weston_layer_set_position(&to->layer, WESTON_LAYER_POSITION_NORMAL); |
| 1183 | weston_layer_unset_position(&from->layer); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1187 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1188 | { |
| 1189 | struct workspace *from; |
| 1190 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1191 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1192 | |
| 1193 | if (index == shell->workspaces.current) |
| 1194 | return; |
| 1195 | |
| 1196 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1197 | if (!wl_list_empty(&shell->fullscreen_layer.view_list.link)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1198 | return; |
| 1199 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1200 | from = get_current_workspace(shell); |
| 1201 | to = get_workspace(shell, index); |
| 1202 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1203 | if (shell->workspaces.anim_from == to && |
| 1204 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1205 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1206 | reverse_workspace_change_animation(shell, index, from, to); |
| 1207 | return; |
| 1208 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1209 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1210 | if (shell->workspaces.anim_to != NULL) |
| 1211 | finish_workspace_change_animation(shell, |
| 1212 | shell->workspaces.anim_from, |
| 1213 | shell->workspaces.anim_to); |
| 1214 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1215 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1216 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1217 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1218 | wl_list_for_each(state, &from->focus_list, link) |
| 1219 | if (state->keyboard_focus) |
| 1220 | animate_focus_change(shell, from, |
| 1221 | get_default_view(state->keyboard_focus), NULL); |
| 1222 | |
| 1223 | wl_list_for_each(state, &to->focus_list, link) |
| 1224 | if (state->keyboard_focus) |
| 1225 | animate_focus_change(shell, to, |
| 1226 | NULL, get_default_view(state->keyboard_focus)); |
| 1227 | } |
| 1228 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1229 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1230 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1231 | else |
| 1232 | animate_workspace_change(shell, index, from, to); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1233 | } |
| 1234 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1235 | static bool |
| 1236 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1237 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1238 | struct wl_list *list = &ws->layer.view_list.link; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1239 | struct wl_list *e; |
| 1240 | |
| 1241 | if (wl_list_empty(list)) |
| 1242 | return false; |
| 1243 | |
| 1244 | e = list->next; |
| 1245 | |
| 1246 | if (e->next != list) |
| 1247 | return false; |
| 1248 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1249 | return container_of(e, struct weston_view, layer_link.link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | static void |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 1253 | surface_keyboard_focus_lost(struct weston_surface *surface) |
| 1254 | { |
| 1255 | struct weston_compositor *compositor = surface->compositor; |
| 1256 | struct weston_seat *seat; |
| 1257 | struct weston_surface *focus; |
| 1258 | |
| 1259 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 1260 | struct weston_keyboard *keyboard = |
| 1261 | weston_seat_get_keyboard(seat); |
| 1262 | |
| 1263 | if (!keyboard) |
| 1264 | continue; |
| 1265 | |
| 1266 | focus = weston_surface_get_main_surface(keyboard->focus); |
| 1267 | if (focus == surface) |
| 1268 | weston_keyboard_set_focus(keyboard, NULL); |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1273 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1274 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1275 | unsigned int index) |
| 1276 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1277 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1278 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1279 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1280 | struct shell_surface *shsurf; |
| 1281 | struct workspace *from; |
| 1282 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1283 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1284 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1285 | surface = weston_surface_get_main_surface(keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1286 | view = get_default_view(surface); |
| 1287 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1288 | index == shell->workspaces.current || |
| 1289 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1290 | return; |
| 1291 | |
| 1292 | from = get_current_workspace(shell); |
| 1293 | to = get_workspace(shell, index); |
| 1294 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1295 | weston_layer_entry_remove(&view->layer_link); |
| 1296 | weston_layer_entry_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1297 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1298 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1299 | if (shsurf != NULL) |
| 1300 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1301 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1302 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1303 | drop_focus_state(shell, from, surface); |
| 1304 | |
| 1305 | if (shell->workspaces.anim_from == to && |
| 1306 | shell->workspaces.anim_to == from) { |
| 1307 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1308 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1309 | return; |
| 1310 | } |
| 1311 | |
| 1312 | if (shell->workspaces.anim_to != NULL) |
| 1313 | finish_workspace_change_animation(shell, |
| 1314 | shell->workspaces.anim_from, |
| 1315 | shell->workspaces.anim_to); |
| 1316 | |
| 1317 | if (workspace_is_empty(from) && |
| 1318 | workspace_has_only(to, surface)) |
| 1319 | update_workspace(shell, index, from, to); |
| 1320 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1321 | if (shsurf != NULL && |
| 1322 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1323 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1324 | &shsurf->workspace_transform.link); |
| 1325 | |
| 1326 | animate_workspace_change(shell, index, from, to); |
| 1327 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1328 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1329 | state = ensure_focus_state(shell, seat); |
| 1330 | if (state != NULL) |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 1331 | focus_state_set_focus(state, surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | static void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 1335 | touch_move_grab_down(struct weston_touch_grab *grab, |
| 1336 | const struct timespec *time, |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 1337 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1338 | { |
| 1339 | } |
| 1340 | |
| 1341 | static void |
Alexandros Frantzis | 27a51b8 | 2017-11-16 18:20:59 +0200 | [diff] [blame] | 1342 | touch_move_grab_up(struct weston_touch_grab *grab, const struct timespec *time, |
| 1343 | int touch_id) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1344 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1345 | struct weston_touch_move_grab *move = |
| 1346 | (struct weston_touch_move_grab *) container_of( |
| 1347 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1348 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1349 | if (touch_id == 0) |
| 1350 | move->active = 0; |
| 1351 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1352 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1353 | shell_touch_grab_end(&move->base); |
| 1354 | free(move); |
| 1355 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | static void |
Alexandros Frantzis | 7d2abcf | 2017-11-16 18:21:00 +0200 | [diff] [blame] | 1359 | touch_move_grab_motion(struct weston_touch_grab *grab, |
| 1360 | const struct timespec *time, int touch_id, |
| 1361 | wl_fixed_t x, wl_fixed_t y) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1362 | { |
| 1363 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1364 | struct shell_surface *shsurf = move->base.shsurf; |
| 1365 | struct weston_surface *es; |
| 1366 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1367 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1368 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1369 | if (!shsurf || !move->active) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1370 | return; |
| 1371 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1372 | es = weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1373 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1374 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1375 | |
| 1376 | weston_compositor_schedule_repaint(es->compositor); |
| 1377 | } |
| 1378 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1379 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1380 | touch_move_grab_frame(struct weston_touch_grab *grab) |
| 1381 | { |
| 1382 | } |
| 1383 | |
| 1384 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1385 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1386 | { |
| 1387 | struct weston_touch_move_grab *move = |
| 1388 | (struct weston_touch_move_grab *) container_of( |
| 1389 | grab, struct shell_touch_grab, grab); |
| 1390 | |
| 1391 | shell_touch_grab_end(&move->base); |
| 1392 | free(move); |
| 1393 | } |
| 1394 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1395 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1396 | touch_move_grab_down, |
| 1397 | touch_move_grab_up, |
| 1398 | touch_move_grab_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 1399 | touch_move_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1400 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1401 | }; |
| 1402 | |
| 1403 | static int |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1404 | surface_touch_move(struct shell_surface *shsurf, struct weston_touch *touch) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1405 | { |
| 1406 | struct weston_touch_move_grab *move; |
| 1407 | |
| 1408 | if (!shsurf) |
| 1409 | return -1; |
| 1410 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1411 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1412 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1413 | return 0; |
| 1414 | |
| 1415 | move = malloc(sizeof *move); |
| 1416 | if (!move) |
| 1417 | return -1; |
| 1418 | |
Kristian Høgsberg | 8e80a31 | 2014-01-17 15:18:10 -0800 | [diff] [blame] | 1419 | move->active = 1; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1420 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1421 | touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1422 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1423 | touch->grab_y; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1424 | |
| 1425 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 1426 | touch); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1427 | |
| 1428 | return 0; |
| 1429 | } |
| 1430 | |
| 1431 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1432 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1433 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | static void |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1437 | noop_grab_axis(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 1438 | const struct timespec *time, |
| 1439 | struct weston_pointer_axis_event *event) |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1440 | { |
| 1441 | } |
| 1442 | |
| 1443 | static void |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1444 | noop_grab_axis_source(struct weston_pointer_grab *grab, |
| 1445 | uint32_t source) |
| 1446 | { |
| 1447 | } |
| 1448 | |
| 1449 | static void |
| 1450 | noop_grab_frame(struct weston_pointer_grab *grab) |
| 1451 | { |
| 1452 | } |
| 1453 | |
| 1454 | static void |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1455 | constrain_position(struct weston_move_grab *move, int *cx, int *cy) |
| 1456 | { |
| 1457 | struct shell_surface *shsurf = move->base.shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1458 | struct weston_surface *surface = |
| 1459 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1460 | struct weston_pointer *pointer = move->base.grab.pointer; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1461 | int x, y, bottom; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1462 | const int safety = 50; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1463 | pixman_rectangle32_t area; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1464 | struct weston_geometry geometry; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1465 | |
| 1466 | x = wl_fixed_to_int(pointer->x + move->dx); |
| 1467 | y = wl_fixed_to_int(pointer->y + move->dy); |
| 1468 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1469 | if (shsurf->shell->panel_position == |
| 1470 | WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1471 | get_output_work_area(shsurf->shell, surface->output, &area); |
| 1472 | geometry = |
| 1473 | weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1474 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1475 | bottom = y + geometry.height + geometry.y; |
Derek Foreman | 6feb0f9 | 2015-04-15 12:23:56 -0500 | [diff] [blame] | 1476 | if (bottom - safety < area.y) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1477 | y = area.y + safety - geometry.height |
| 1478 | - geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1479 | |
| 1480 | if (move->client_initiated && |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1481 | y + geometry.y < area.y) |
| 1482 | y = area.y - geometry.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 1483 | } |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1484 | |
| 1485 | *cx = x; |
| 1486 | *cy = y; |
| 1487 | } |
| 1488 | |
| 1489 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 1490 | move_grab_motion(struct weston_pointer_grab *grab, |
| 1491 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1492 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1493 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1494 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1495 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1496 | struct shell_surface *shsurf = move->base.shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1497 | struct weston_surface *surface; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1498 | int cx, cy; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1499 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1500 | weston_pointer_move(pointer, event); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1501 | if (!shsurf) |
| 1502 | return; |
| 1503 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1504 | surface = weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 1505 | |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1506 | constrain_position(move, &cx, &cy); |
| 1507 | |
| 1508 | weston_view_set_position(shsurf->view, cx, cy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1509 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1510 | weston_compositor_schedule_repaint(surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1514 | move_grab_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 1515 | const struct timespec *time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1516 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1517 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1518 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1519 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1520 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1521 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1522 | if (pointer->button_count == 0 && |
| 1523 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1524 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1525 | free(grab); |
| 1526 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1527 | } |
| 1528 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1529 | static void |
| 1530 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1531 | { |
| 1532 | struct shell_grab *shell_grab = |
| 1533 | container_of(grab, struct shell_grab, grab); |
| 1534 | |
| 1535 | shell_grab_end(shell_grab); |
| 1536 | free(grab); |
| 1537 | } |
| 1538 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1539 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1540 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1541 | move_grab_motion, |
| 1542 | move_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1543 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1544 | noop_grab_axis_source, |
| 1545 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1546 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1547 | }; |
| 1548 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1549 | static int |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1550 | surface_move(struct shell_surface *shsurf, struct weston_pointer *pointer, |
Derek Foreman | cf7d95a | 2015-06-03 15:53:22 -0500 | [diff] [blame] | 1551 | bool client_initiated) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1552 | { |
| 1553 | struct weston_move_grab *move; |
| 1554 | |
| 1555 | if (!shsurf) |
| 1556 | return -1; |
| 1557 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1558 | if (shsurf->grabbed || |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1559 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1560 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1561 | return 0; |
| 1562 | |
| 1563 | move = malloc(sizeof *move); |
| 1564 | if (!move) |
| 1565 | return -1; |
| 1566 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1567 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1568 | pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1569 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1570 | pointer->grab_y; |
Kristian Høgsberg | ae356ae | 2014-04-29 16:03:54 -0700 | [diff] [blame] | 1571 | move->client_initiated = client_initiated; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1572 | |
| 1573 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 1574 | pointer, WESTON_DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1575 | |
| 1576 | return 0; |
| 1577 | } |
| 1578 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1579 | struct weston_resize_grab { |
| 1580 | struct shell_grab base; |
| 1581 | uint32_t edges; |
| 1582 | int32_t width, height; |
| 1583 | }; |
| 1584 | |
| 1585 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 1586 | resize_grab_motion(struct weston_pointer_grab *grab, |
| 1587 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1588 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1589 | { |
| 1590 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1591 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1592 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1593 | int32_t width, height; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1594 | struct weston_size min_size, max_size; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1595 | wl_fixed_t from_x, from_y; |
| 1596 | wl_fixed_t to_x, to_y; |
| 1597 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1598 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1599 | |
Kristian Høgsberg | e0b9d5b | 2014-04-30 13:45:49 -0700 | [diff] [blame] | 1600 | if (!shsurf) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1601 | return; |
| 1602 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1603 | weston_view_from_global_fixed(shsurf->view, |
| 1604 | pointer->grab_x, pointer->grab_y, |
| 1605 | &from_x, &from_y); |
| 1606 | weston_view_from_global_fixed(shsurf->view, |
| 1607 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1608 | |
| 1609 | width = resize->width; |
| 1610 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1611 | width += wl_fixed_to_int(from_x - to_x); |
| 1612 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1613 | width += wl_fixed_to_int(to_x - from_x); |
| 1614 | } |
| 1615 | |
| 1616 | height = resize->height; |
| 1617 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1618 | height += wl_fixed_to_int(from_y - to_y); |
| 1619 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1620 | height += wl_fixed_to_int(to_y - from_y); |
| 1621 | } |
| 1622 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1623 | max_size = weston_desktop_surface_get_max_size(shsurf->desktop_surface); |
| 1624 | min_size = weston_desktop_surface_get_min_size(shsurf->desktop_surface); |
| 1625 | |
| 1626 | min_size.width = MAX(1, min_size.width); |
| 1627 | min_size.height = MAX(1, min_size.height); |
| 1628 | |
| 1629 | if (width < min_size.width) |
| 1630 | width = min_size.width; |
| 1631 | else if (max_size.width > 0 && width > max_size.width) |
| 1632 | width = max_size.width; |
| 1633 | if (height < min_size.height) |
| 1634 | height = min_size.height; |
| 1635 | else if (max_size.width > 0 && width > max_size.width) |
| 1636 | width = max_size.width; |
| 1637 | weston_desktop_surface_set_size(shsurf->desktop_surface, width, height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1641 | resize_grab_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 1642 | const struct timespec *time, |
| 1643 | uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1644 | { |
| 1645 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1646 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1647 | enum wl_pointer_button_state state = state_w; |
Philipp Kerling | c5f1241 | 2017-07-28 14:11:58 +0200 | [diff] [blame] | 1648 | struct weston_desktop_surface *desktop_surface = |
| 1649 | resize->base.shsurf->desktop_surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1650 | |
| 1651 | if (pointer->button_count == 0 && |
| 1652 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Philipp Kerling | c5f1241 | 2017-07-28 14:11:58 +0200 | [diff] [blame] | 1653 | weston_desktop_surface_set_resizing(desktop_surface, false); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1654 | shell_grab_end(&resize->base); |
| 1655 | free(grab); |
| 1656 | } |
| 1657 | } |
| 1658 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1659 | static void |
| 1660 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1661 | { |
| 1662 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Philipp Kerling | c5f1241 | 2017-07-28 14:11:58 +0200 | [diff] [blame] | 1663 | struct weston_desktop_surface *desktop_surface = |
| 1664 | resize->base.shsurf->desktop_surface; |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1665 | |
Philipp Kerling | c5f1241 | 2017-07-28 14:11:58 +0200 | [diff] [blame] | 1666 | weston_desktop_surface_set_resizing(desktop_surface, false); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1667 | shell_grab_end(&resize->base); |
| 1668 | free(grab); |
| 1669 | } |
| 1670 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1671 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1672 | noop_grab_focus, |
| 1673 | resize_grab_motion, |
| 1674 | resize_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1675 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1676 | noop_grab_axis_source, |
| 1677 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1678 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1679 | }; |
| 1680 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1681 | /* |
| 1682 | * Returns the bounding box of a surface and all its sub-surfaces, |
Yong Bakos | bbb783a | 2016-04-28 11:59:06 -0500 | [diff] [blame] | 1683 | * in surface-local coordinates. */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1684 | static void |
| 1685 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1686 | int32_t *y, int32_t *w, int32_t *h) { |
| 1687 | pixman_region32_t region; |
| 1688 | pixman_box32_t *box; |
| 1689 | struct weston_subsurface *subsurface; |
| 1690 | |
| 1691 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1692 | surface->width, |
| 1693 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1694 | |
| 1695 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1696 | pixman_region32_union_rect(®ion, ®ion, |
| 1697 | subsurface->position.x, |
| 1698 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1699 | subsurface->surface->width, |
| 1700 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | box = pixman_region32_extents(®ion); |
| 1704 | if (x) |
| 1705 | *x = box->x1; |
| 1706 | if (y) |
| 1707 | *y = box->y1; |
| 1708 | if (w) |
| 1709 | *w = box->x2 - box->x1; |
| 1710 | if (h) |
| 1711 | *h = box->y2 - box->y1; |
| 1712 | |
| 1713 | pixman_region32_fini(®ion); |
| 1714 | } |
| 1715 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1716 | static int |
| 1717 | surface_resize(struct shell_surface *shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1718 | struct weston_pointer *pointer, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1719 | { |
| 1720 | struct weston_resize_grab *resize; |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1721 | const unsigned resize_topbottom = |
| 1722 | WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_BOTTOM; |
| 1723 | const unsigned resize_leftright = |
| 1724 | WL_SHELL_SURFACE_RESIZE_LEFT | WL_SHELL_SURFACE_RESIZE_RIGHT; |
| 1725 | const unsigned resize_any = resize_topbottom | resize_leftright; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1726 | struct weston_geometry geometry; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1727 | |
Kristian Høgsberg | a4b620e | 2014-04-30 16:05:49 -0700 | [diff] [blame] | 1728 | if (shsurf->grabbed || |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1729 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 1730 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1731 | return 0; |
| 1732 | |
Ondřej Majerech | ae9c4fc | 2014-08-21 15:47:22 +0200 | [diff] [blame] | 1733 | /* Check for invalid edge combinations. */ |
| 1734 | if (edges == WL_SHELL_SURFACE_RESIZE_NONE || edges > resize_any || |
| 1735 | (edges & resize_topbottom) == resize_topbottom || |
| 1736 | (edges & resize_leftright) == resize_leftright) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1737 | return 0; |
| 1738 | |
| 1739 | resize = malloc(sizeof *resize); |
| 1740 | if (!resize) |
| 1741 | return -1; |
| 1742 | |
| 1743 | resize->edges = edges; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1744 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1745 | geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
| 1746 | resize->width = geometry.width; |
| 1747 | resize->height = geometry.height; |
Jasper St. Pierre | bd65e50 | 2014-07-14 16:28:48 -0400 | [diff] [blame] | 1748 | |
Kristian Høgsberg | 44cd196 | 2014-02-05 21:36:04 -0800 | [diff] [blame] | 1749 | shsurf->resize_edges = edges; |
Philipp Kerling | c5f1241 | 2017-07-28 14:11:58 +0200 | [diff] [blame] | 1750 | weston_desktop_surface_set_resizing(shsurf->desktop_surface, true); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1751 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 1752 | pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1753 | |
| 1754 | return 0; |
| 1755 | } |
| 1756 | |
| 1757 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1758 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1759 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1760 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1761 | struct weston_pointer *pointer = base->pointer; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1762 | struct weston_desktop_surface *desktop_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1763 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1764 | wl_fixed_t sx, sy; |
| 1765 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1766 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1767 | pointer->x, pointer->y, |
| 1768 | &sx, &sy); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1769 | desktop_surface = weston_surface_get_desktop_surface(view->surface); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1770 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1771 | if (!grab->shsurf || grab->shsurf->desktop_surface != desktop_surface) { |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 1772 | shell_grab_end(grab); |
| 1773 | free(grab); |
| 1774 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 1778 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, |
| 1779 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1780 | struct weston_pointer_motion_event *event) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1781 | { |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1782 | weston_pointer_move(grab->pointer, event); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1783 | } |
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 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1786 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 1787 | const struct timespec *time, |
| 1788 | uint32_t button, uint32_t state) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1789 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1790 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1791 | struct shell_surface *shsurf = grab->shsurf; |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1792 | struct weston_pointer *pointer = grab->grab.pointer; |
| 1793 | struct weston_seat *seat = pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1794 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1795 | if (shsurf && button == BTN_LEFT && state) { |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 1796 | activate(shsurf->shell, shsurf->view, seat, |
| 1797 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 1798 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1799 | } else if (shsurf && button == BTN_RIGHT && state) { |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 1800 | activate(shsurf->shell, shsurf->view, seat, |
| 1801 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 1802 | surface_rotate(shsurf, pointer); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1803 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1804 | } |
| 1805 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1806 | static void |
| 1807 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1808 | { |
| 1809 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1810 | |
| 1811 | shell_grab_end(grab); |
| 1812 | free(grab); |
| 1813 | } |
| 1814 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1815 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1816 | busy_cursor_grab_focus, |
| 1817 | busy_cursor_grab_motion, |
| 1818 | busy_cursor_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 1819 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1820 | noop_grab_axis_source, |
| 1821 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1822 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1823 | }; |
| 1824 | |
| 1825 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1826 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1827 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1828 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1829 | struct weston_view *view = pointer->focus; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1830 | struct shell_surface *shsurf; |
| 1831 | struct weston_desktop_client *client; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1832 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1833 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1834 | return; |
| 1835 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1836 | shsurf = get_shell_surface(view->surface); |
| 1837 | if (!shsurf) |
| 1838 | return; |
| 1839 | |
| 1840 | client = weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 1841 | |
| 1842 | if (shsurf->unresponsive) |
| 1843 | set_busy_cursor(shsurf, pointer); |
| 1844 | else |
| 1845 | weston_desktop_client_ping(client); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | static void |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1849 | shell_surface_lose_keyboard_focus(struct shell_surface *shsurf) |
| 1850 | { |
| 1851 | if (--shsurf->focus_count == 0) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1852 | weston_desktop_surface_set_activated(shsurf->desktop_surface, false); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | static void |
| 1856 | shell_surface_gain_keyboard_focus(struct shell_surface *shsurf) |
| 1857 | { |
| 1858 | if (shsurf->focus_count++ == 0) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1859 | weston_desktop_surface_set_activated(shsurf->desktop_surface, true); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | static void |
| 1863 | handle_keyboard_focus(struct wl_listener *listener, void *data) |
| 1864 | { |
| 1865 | struct weston_keyboard *keyboard = data; |
| 1866 | struct shell_seat *seat = get_shell_seat(keyboard->seat); |
| 1867 | |
| 1868 | if (seat->focused_surface) { |
| 1869 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 1870 | if (shsurf) |
| 1871 | shell_surface_lose_keyboard_focus(shsurf); |
| 1872 | } |
| 1873 | |
Philipp Kerling | ba8a0d0 | 2017-07-26 12:02:15 +0200 | [diff] [blame] | 1874 | seat->focused_surface = weston_surface_get_main_surface(keyboard->focus); |
Jasper St. Pierre | faf27a9 | 2013-12-09 17:36:28 -0500 | [diff] [blame] | 1875 | |
| 1876 | if (seat->focused_surface) { |
| 1877 | struct shell_surface *shsurf = get_shell_surface(seat->focused_surface); |
| 1878 | if (shsurf) |
| 1879 | shell_surface_gain_keyboard_focus(shsurf); |
| 1880 | } |
| 1881 | } |
| 1882 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1883 | /* The surface will be inserted into the list immediately after the link |
| 1884 | * returned by this function (i.e. will be stacked immediately above the |
| 1885 | * returned link). */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1886 | static struct weston_layer_entry * |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1887 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 1888 | { |
| 1889 | struct workspace *ws; |
| 1890 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1891 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) && |
| 1892 | !shsurf->state.lowered) { |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 1893 | return &shsurf->shell->fullscreen_layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1894 | } |
| 1895 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1896 | /* Move the surface to a normal workspace layer so that surfaces |
| 1897 | * which were previously fullscreen or transient are no longer |
| 1898 | * rendered on top. */ |
| 1899 | ws = get_current_workspace(shsurf->shell); |
| 1900 | return &ws->layer.view_list; |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 1901 | } |
| 1902 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1903 | static void |
| 1904 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 1905 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1906 | weston_desktop_surface_propagate_layer(shsurf->desktop_surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1907 | } |
| 1908 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1909 | /* 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] | 1910 | * geometry to ensure the changes are redrawn. |
| 1911 | * |
| 1912 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 1913 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1914 | static void |
| 1915 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 1916 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1917 | struct weston_surface *surface = |
| 1918 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1919 | struct weston_layer_entry *new_layer_link; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1920 | |
| 1921 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 1922 | |
Ander Conselvan de Oliveira | ef6a7e4 | 2014-04-30 14:15:14 +0300 | [diff] [blame] | 1923 | if (new_layer_link == NULL) |
| 1924 | return; |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1925 | if (new_layer_link == &shsurf->view->layer_link) |
| 1926 | return; |
| 1927 | |
| 1928 | weston_view_geometry_dirty(shsurf->view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1929 | weston_layer_entry_remove(&shsurf->view->layer_link); |
| 1930 | weston_layer_entry_insert(new_layer_link, &shsurf->view->layer_link); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1931 | weston_view_geometry_dirty(shsurf->view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1932 | weston_surface_damage(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1933 | |
| 1934 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 1935 | } |
| 1936 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1937 | static void |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame^] | 1938 | notify_output_destroy(struct wl_listener *listener, void *data) |
| 1939 | { |
| 1940 | struct shell_surface *shsurf = |
| 1941 | container_of(listener, |
| 1942 | struct shell_surface, output_destroy_listener); |
| 1943 | |
| 1944 | shsurf->output = NULL; |
| 1945 | shsurf->output_destroy_listener.notify = NULL; |
| 1946 | } |
| 1947 | |
| 1948 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1949 | shell_surface_set_output(struct shell_surface *shsurf, |
| 1950 | struct weston_output *output) |
| 1951 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 1952 | struct weston_surface *es = |
| 1953 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1954 | |
| 1955 | /* get the default output, if the client set it as NULL |
Abdur Rehman | 7f1da1f | 2017-01-01 19:46:33 +0500 | [diff] [blame] | 1956 | check whether the output is available */ |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1957 | if (output) |
| 1958 | shsurf->output = output; |
| 1959 | else if (es->output) |
| 1960 | shsurf->output = es->output; |
| 1961 | else |
| 1962 | shsurf->output = get_default_output(es->compositor); |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame^] | 1963 | |
| 1964 | if (shsurf->output_destroy_listener.notify) { |
| 1965 | wl_list_remove(&shsurf->output_destroy_listener.link); |
| 1966 | shsurf->output_destroy_listener.notify = NULL; |
| 1967 | } |
| 1968 | |
| 1969 | if (!shsurf->output) |
| 1970 | return; |
| 1971 | |
| 1972 | shsurf->output_destroy_listener.notify = notify_output_destroy; |
| 1973 | wl_signal_add(&shsurf->output->destroy_signal, |
| 1974 | &shsurf->output_destroy_listener); |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | static void |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 1978 | weston_view_set_initial_position(struct weston_view *view, |
| 1979 | struct desktop_shell *shell); |
| 1980 | |
| 1981 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 1982 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1983 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 1984 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1985 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 1986 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 1987 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1988 | if (shsurf->fullscreen.black_view) |
| 1989 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 1990 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 1991 | |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 1992 | if (shsurf->saved_position_valid) |
| 1993 | weston_view_set_position(shsurf->view, |
| 1994 | shsurf->saved_x, shsurf->saved_y); |
| 1995 | else |
| 1996 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Quentin Glidic | 920cf04 | 2016-08-16 14:26:20 +0200 | [diff] [blame] | 1997 | shsurf->saved_position_valid = false; |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 1998 | |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 1999 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2000 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2001 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2002 | shsurf->saved_rotation_valid = false; |
| 2003 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2004 | } |
| 2005 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2006 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2007 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2008 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2009 | struct weston_surface *surface = |
| 2010 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2011 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2012 | /* undo all maximized things here */ |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame^] | 2013 | shell_surface_set_output(shsurf, get_default_output(surface->compositor)); |
Zhang, Xiong Y | 3123693 | 2013-12-13 22:10:57 +0200 | [diff] [blame] | 2014 | |
| 2015 | if (shsurf->saved_position_valid) |
| 2016 | weston_view_set_position(shsurf->view, |
| 2017 | shsurf->saved_x, shsurf->saved_y); |
| 2018 | else |
| 2019 | weston_view_set_initial_position(shsurf->view, shsurf->shell); |
Quentin Glidic | 920cf04 | 2016-08-16 14:26:20 +0200 | [diff] [blame] | 2020 | shsurf->saved_position_valid = false; |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2021 | |
| 2022 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2023 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2024 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2025 | shsurf->saved_rotation_valid = false; |
| 2026 | } |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2027 | } |
| 2028 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2029 | static void |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2030 | set_minimized(struct weston_surface *surface) |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2031 | { |
| 2032 | struct shell_surface *shsurf; |
| 2033 | struct workspace *current_ws; |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2034 | struct weston_view *view; |
| 2035 | |
| 2036 | view = get_default_view(surface); |
| 2037 | if (!view) |
| 2038 | return; |
| 2039 | |
| 2040 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 2041 | |
| 2042 | shsurf = get_shell_surface(surface); |
| 2043 | current_ws = get_current_workspace(shsurf->shell); |
| 2044 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2045 | weston_layer_entry_remove(&view->layer_link); |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2046 | 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] | 2047 | |
Manuel Bachmann | dc1c3e4 | 2015-02-16 11:52:13 +0100 | [diff] [blame] | 2048 | drop_focus_state(shsurf->shell, current_ws, view->surface); |
Jonas Ådahl | 22faea1 | 2014-10-15 22:02:06 +0200 | [diff] [blame] | 2049 | surface_keyboard_focus_lost(surface); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2050 | |
| 2051 | shell_surface_update_child_surface_layers(shsurf); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 2052 | weston_view_damage_below(view); |
| 2053 | } |
| 2054 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2055 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2056 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2057 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2058 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2059 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2060 | } |
| 2061 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2062 | static int |
| 2063 | black_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2064 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2065 | struct weston_view *fs_view = surface->committed_private; |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2066 | struct weston_surface *fs_surface = fs_view->surface; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2067 | int n; |
| 2068 | int rem; |
| 2069 | int ret; |
| 2070 | |
| 2071 | n = snprintf(buf, len, "black background surface for "); |
| 2072 | if (n < 0) |
| 2073 | return n; |
| 2074 | |
| 2075 | rem = (int)len - n; |
| 2076 | if (rem < 0) |
| 2077 | rem = 0; |
| 2078 | |
| 2079 | if (fs_surface->get_label) |
| 2080 | ret = fs_surface->get_label(fs_surface, buf + n, rem); |
| 2081 | else |
| 2082 | ret = snprintf(buf + n, rem, "<unknown>"); |
| 2083 | |
| 2084 | if (ret < 0) |
| 2085 | return n; |
| 2086 | |
| 2087 | return n + ret; |
| 2088 | } |
| 2089 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2090 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2091 | 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] | 2092 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2093 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2094 | create_black_surface(struct weston_compositor *ec, |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2095 | struct weston_view *fs_view, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2096 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2097 | { |
| 2098 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2099 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2100 | |
| 2101 | surface = weston_surface_create(ec); |
| 2102 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2103 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2104 | return NULL; |
| 2105 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2106 | view = weston_view_create(surface); |
| 2107 | if (surface == NULL) { |
| 2108 | weston_log("no memory\n"); |
| 2109 | weston_surface_destroy(surface); |
| 2110 | return NULL; |
| 2111 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2112 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2113 | surface->committed = black_surface_committed; |
| 2114 | surface->committed_private = fs_view; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2115 | weston_surface_set_label_func(surface, black_surface_get_label); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2116 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2117 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2118 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2119 | pixman_region32_fini(&surface->input); |
| 2120 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2121 | |
Jason Ekstrand | 6228ee2 | 2014-01-01 15:58:57 -0600 | [diff] [blame] | 2122 | weston_surface_set_size(surface, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2123 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2124 | |
| 2125 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2126 | } |
| 2127 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2128 | static void |
| 2129 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2130 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2131 | struct weston_surface *surface = |
| 2132 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2133 | struct weston_output *output = shsurf->fullscreen_output; |
| 2134 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2135 | assert(weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2136 | |
| 2137 | if (!shsurf->fullscreen.black_view) |
| 2138 | shsurf->fullscreen.black_view = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2139 | create_black_surface(surface->compositor, |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 2140 | shsurf->view, |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2141 | output->x, output->y, |
| 2142 | output->width, |
| 2143 | output->height); |
| 2144 | |
| 2145 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2146 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2147 | weston_layer_entry_insert(&shsurf->view->layer_link, |
| 2148 | &shsurf->fullscreen.black_view->layer_link); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2149 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2150 | weston_surface_damage(surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2151 | |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 2152 | shsurf->fullscreen.black_view->is_mapped = true; |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2153 | shsurf->state.lowered = false; |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2156 | /* Create black surface and append it to the associated fullscreen surface. |
| 2157 | * Handle size dismatch and positioning according to the method. */ |
| 2158 | static void |
| 2159 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2160 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2161 | struct weston_surface *surface = |
| 2162 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2163 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2164 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2165 | /* Reverse the effect of lower_fullscreen_layer() */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2166 | weston_layer_entry_remove(&shsurf->view->layer_link); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2167 | weston_layer_entry_insert(&shsurf->shell->fullscreen_layer.view_list, |
| 2168 | &shsurf->view->layer_link); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 2169 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2170 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2171 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2172 | surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2173 | &surf_width, &surf_height); |
| 2174 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2175 | if (surface->buffer_ref.buffer) |
| 2176 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2177 | } |
| 2178 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2179 | static void |
| 2180 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2181 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2182 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2183 | } |
| 2184 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2185 | static struct weston_output * |
| 2186 | get_focused_output(struct weston_compositor *compositor) |
| 2187 | { |
| 2188 | struct weston_seat *seat; |
| 2189 | struct weston_output *output = NULL; |
| 2190 | |
| 2191 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2192 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2193 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2194 | struct weston_keyboard *keyboard = |
| 2195 | weston_seat_get_keyboard(seat); |
| 2196 | |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2197 | /* Priority has touch focus, then pointer and |
| 2198 | * then keyboard focus. We should probably have |
| 2199 | * three for loops and check frist for touch, |
| 2200 | * then for pointer, etc. but unless somebody has some |
| 2201 | * objections, I think this is sufficient. */ |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2202 | if (touch && touch->focus) |
| 2203 | output = touch->focus->output; |
| 2204 | else if (pointer && pointer->focus) |
| 2205 | output = pointer->focus->output; |
| 2206 | else if (keyboard && keyboard->focus) |
| 2207 | output = keyboard->focus->output; |
Giulio Camuffo | 6b4b241 | 2015-01-29 19:06:49 +0200 | [diff] [blame] | 2208 | |
| 2209 | if (output) |
| 2210 | break; |
| 2211 | } |
| 2212 | |
| 2213 | return output; |
| 2214 | } |
| 2215 | |
| 2216 | static void |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2217 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2218 | { |
| 2219 | struct shell_seat *shseat = |
| 2220 | container_of(listener, |
| 2221 | struct shell_seat, seat_destroy_listener); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2222 | |
| 2223 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2224 | free(shseat); |
| 2225 | } |
| 2226 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2227 | static void |
| 2228 | shell_seat_caps_changed(struct wl_listener *listener, void *data) |
| 2229 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2230 | struct weston_keyboard *keyboard; |
| 2231 | struct weston_pointer *pointer; |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2232 | struct shell_seat *seat; |
| 2233 | |
| 2234 | seat = container_of(listener, struct shell_seat, caps_changed_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2235 | keyboard = weston_seat_get_keyboard(seat->seat); |
| 2236 | pointer = weston_seat_get_pointer(seat->seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2237 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2238 | if (keyboard && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2239 | wl_list_empty(&seat->keyboard_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2240 | wl_signal_add(&keyboard->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2241 | &seat->keyboard_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2242 | } else if (!keyboard) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 2243 | wl_list_remove(&seat->keyboard_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2244 | wl_list_init(&seat->keyboard_focus_listener.link); |
| 2245 | } |
| 2246 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2247 | if (pointer && |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2248 | wl_list_empty(&seat->pointer_focus_listener.link)) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2249 | wl_signal_add(&pointer->focus_signal, |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2250 | &seat->pointer_focus_listener); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2251 | } else if (!pointer) { |
Derek Foreman | 60d9731 | 2015-07-15 13:00:45 -0500 | [diff] [blame] | 2252 | wl_list_remove(&seat->pointer_focus_listener.link); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2253 | wl_list_init(&seat->pointer_focus_listener.link); |
| 2254 | } |
| 2255 | } |
| 2256 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2257 | static struct shell_seat * |
| 2258 | create_shell_seat(struct weston_seat *seat) |
| 2259 | { |
| 2260 | struct shell_seat *shseat; |
| 2261 | |
| 2262 | shseat = calloc(1, sizeof *shseat); |
| 2263 | if (!shseat) { |
| 2264 | weston_log("no memory to allocate shell seat\n"); |
| 2265 | return NULL; |
| 2266 | } |
| 2267 | |
| 2268 | shseat->seat = seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2269 | |
| 2270 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2271 | wl_signal_add(&seat->destroy_signal, |
| 2272 | &shseat->seat_destroy_listener); |
| 2273 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2274 | shseat->keyboard_focus_listener.notify = handle_keyboard_focus; |
| 2275 | wl_list_init(&shseat->keyboard_focus_listener.link); |
| 2276 | |
| 2277 | shseat->pointer_focus_listener.notify = handle_pointer_focus; |
| 2278 | wl_list_init(&shseat->pointer_focus_listener.link); |
| 2279 | |
| 2280 | shseat->caps_changed_listener.notify = shell_seat_caps_changed; |
| 2281 | wl_signal_add(&seat->updated_caps_signal, |
| 2282 | &shseat->caps_changed_listener); |
| 2283 | shell_seat_caps_changed(&shseat->caps_changed_listener, NULL); |
| 2284 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2285 | return shseat; |
| 2286 | } |
| 2287 | |
| 2288 | static struct shell_seat * |
| 2289 | get_shell_seat(struct weston_seat *seat) |
| 2290 | { |
| 2291 | struct wl_listener *listener; |
| 2292 | |
| 2293 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 2294 | assert(listener != NULL); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2295 | |
| 2296 | return container_of(listener, |
| 2297 | struct shell_seat, seat_destroy_listener); |
| 2298 | } |
| 2299 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2300 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2301 | fade_out_done_idle_cb(void *data) |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 2302 | { |
| 2303 | struct shell_surface *shsurf = data; |
| 2304 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2305 | weston_surface_destroy(shsurf->view->surface); |
| 2306 | free(shsurf); |
Kristian Høgsberg | 160fe75 | 2014-03-11 10:19:10 -0700 | [diff] [blame] | 2307 | } |
| 2308 | |
| 2309 | static void |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2310 | fade_out_done(struct weston_view_animation *animation, void *data) |
| 2311 | { |
| 2312 | struct shell_surface *shsurf = data; |
| 2313 | struct wl_event_loop *loop; |
| 2314 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2315 | loop = wl_display_get_event_loop(shsurf->shell->compositor->wl_display); |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2316 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2317 | if (weston_view_is_mapped(shsurf->view)) { |
| 2318 | shsurf->view->is_mapped = false; |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2319 | wl_event_loop_add_idle(loop, fade_out_done_idle_cb, shsurf); |
Derek Foreman | 039e9be | 2015-04-14 17:09:06 -0500 | [diff] [blame] | 2320 | } |
| 2321 | } |
| 2322 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 2323 | struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2324 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2325 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2326 | if (weston_surface_is_desktop_surface(surface)) { |
| 2327 | struct weston_desktop_surface *desktop_surface = |
| 2328 | weston_surface_get_desktop_surface(surface); |
| 2329 | return weston_desktop_surface_get_user_data(desktop_surface); |
| 2330 | } |
| 2331 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2332 | } |
| 2333 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2334 | /* |
| 2335 | * libweston-desktop |
| 2336 | */ |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2337 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2338 | static void |
| 2339 | desktop_surface_added(struct weston_desktop_surface *desktop_surface, |
| 2340 | void *shell) |
| 2341 | { |
| 2342 | struct weston_desktop_client *client = |
| 2343 | weston_desktop_surface_get_client(desktop_surface); |
| 2344 | struct wl_client *wl_client = |
| 2345 | weston_desktop_client_get_client(client); |
| 2346 | struct weston_view *view; |
| 2347 | struct shell_surface *shsurf; |
| 2348 | struct weston_surface *surface = |
| 2349 | weston_desktop_surface_get_surface(desktop_surface); |
| 2350 | |
| 2351 | view = weston_desktop_surface_create_view(desktop_surface); |
| 2352 | if (!view) |
| 2353 | return; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2354 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2355 | shsurf = calloc(1, sizeof *shsurf); |
| 2356 | if (!shsurf) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2357 | if (wl_client) |
| 2358 | wl_client_post_no_memory(wl_client); |
| 2359 | else |
| 2360 | weston_log("no memory to allocate shell surface\n"); |
| 2361 | return; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2362 | } |
| 2363 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2364 | weston_surface_set_label_func(surface, shell_surface_get_label); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2365 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2366 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2367 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2368 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2369 | shsurf->saved_rotation_valid = false; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2370 | shsurf->desktop_surface = desktop_surface; |
| 2371 | shsurf->view = view; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2372 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2373 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2374 | |
Semi Malinen | 99f8c08 | 2018-05-02 11:10:32 +0200 | [diff] [blame^] | 2375 | shell_surface_set_output( |
| 2376 | shsurf, get_default_output(shsurf->shell->compositor)); |
Jasper St. Pierre | 9aa8ce6 | 2014-04-11 16:18:54 -0700 | [diff] [blame] | 2377 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2378 | wl_signal_init(&shsurf->destroy_signal); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2379 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2380 | /* empty when not in use */ |
| 2381 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2382 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2383 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2384 | wl_list_init(&shsurf->workspace_transform.link); |
| 2385 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2386 | weston_desktop_surface_set_user_data(desktop_surface, shsurf); |
| 2387 | weston_desktop_surface_set_activated(desktop_surface, |
| 2388 | shsurf->focus_count > 0); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2389 | } |
| 2390 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2391 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2392 | desktop_surface_removed(struct weston_desktop_surface *desktop_surface, |
| 2393 | void *shell) |
| 2394 | { |
| 2395 | struct shell_surface *shsurf = |
| 2396 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2397 | struct weston_surface *surface = |
| 2398 | weston_desktop_surface_get_surface(desktop_surface); |
| 2399 | |
| 2400 | if (!shsurf) |
| 2401 | return; |
| 2402 | |
| 2403 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2404 | |
| 2405 | if (shsurf->fullscreen.black_view) |
| 2406 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2407 | |
| 2408 | weston_surface_set_label_func(surface, NULL); |
| 2409 | weston_desktop_surface_set_user_data(shsurf->desktop_surface, NULL); |
| 2410 | shsurf->desktop_surface = NULL; |
| 2411 | |
Quentin Glidic | f01ecee | 2016-08-16 10:52:46 +0200 | [diff] [blame] | 2412 | weston_desktop_surface_unlink_view(shsurf->view); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2413 | if (weston_surface_is_mapped(surface) && |
| 2414 | shsurf->shell->win_close_animation_type == ANIMATION_FADE) { |
| 2415 | pixman_region32_fini(&surface->pending.input); |
| 2416 | pixman_region32_init(&surface->pending.input); |
| 2417 | pixman_region32_fini(&surface->input); |
| 2418 | pixman_region32_init(&surface->input); |
| 2419 | weston_fade_run(shsurf->view, 1.0, 0.0, 300.0, |
| 2420 | fade_out_done, shsurf); |
| 2421 | } else { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2422 | weston_view_destroy(shsurf->view); |
| 2423 | free(shsurf); |
| 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | static void |
| 2428 | set_maximized_position(struct desktop_shell *shell, |
| 2429 | struct shell_surface *shsurf) |
| 2430 | { |
| 2431 | pixman_rectangle32_t area; |
| 2432 | struct weston_geometry geometry; |
| 2433 | |
| 2434 | get_output_work_area(shell, shsurf->output, &area); |
| 2435 | geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
| 2436 | |
| 2437 | weston_view_set_position(shsurf->view, |
| 2438 | area.x - geometry.x, |
| 2439 | area.y - geometry.y); |
| 2440 | } |
| 2441 | |
| 2442 | static void |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2443 | set_position_from_xwayland(struct shell_surface *shsurf) |
| 2444 | { |
| 2445 | struct weston_geometry geometry; |
| 2446 | float x; |
| 2447 | float y; |
| 2448 | |
| 2449 | assert(shsurf->xwayland.is_set); |
| 2450 | |
| 2451 | geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); |
| 2452 | x = shsurf->xwayland.x - geometry.x; |
| 2453 | y = shsurf->xwayland.y - geometry.y; |
| 2454 | |
| 2455 | weston_view_set_position(shsurf->view, x, y); |
| 2456 | |
| 2457 | #ifdef WM_DEBUG |
| 2458 | weston_log("%s: XWM %d, %d; geometry %d, %d; view %f, %f\n", |
| 2459 | __func__, shsurf->xwayland.x, shsurf->xwayland.y, |
| 2460 | geometry.x, geometry.y, x, y); |
| 2461 | #endif |
| 2462 | } |
| 2463 | |
| 2464 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2465 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
| 2466 | int32_t sx, int32_t sy) |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2467 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2468 | struct weston_surface *surface = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2469 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2470 | struct weston_compositor *compositor = shell->compositor; |
| 2471 | struct weston_seat *seat; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2472 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2473 | /* initial positioning, see also configure() */ |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2474 | if (shsurf->state.fullscreen) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2475 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 2476 | shell_map_fullscreen(shsurf); |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2477 | } else if (shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2478 | set_maximized_position(shell, shsurf); |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2479 | } else if (shsurf->xwayland.is_set) { |
| 2480 | set_position_from_xwayland(shsurf); |
Jasper St. Pierre | 66bc949 | 2015-02-13 14:01:55 +0800 | [diff] [blame] | 2481 | } else { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2482 | weston_view_set_initial_position(shsurf->view, shell); |
Marek Chalupa | 052917a | 2014-09-02 11:35:12 +0200 | [diff] [blame] | 2483 | } |
| 2484 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2485 | /* Surface stacking order, see also activate(). */ |
| 2486 | shell_surface_update_layer(shsurf); |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2487 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2488 | weston_view_update_transform(shsurf->view); |
| 2489 | shsurf->view->is_mapped = true; |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2490 | if (shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2491 | surface->output = shsurf->output; |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 2492 | weston_view_set_output(shsurf->view, shsurf->output); |
Jasper St. Pierre | 973d787 | 2014-05-06 08:44:29 -0400 | [diff] [blame] | 2493 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2494 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2495 | if (!shell->locked) { |
| 2496 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 2497 | activate(shell, shsurf->view, seat, |
| 2498 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
| 2499 | } |
Jasper St. Pierre | ab2c108 | 2014-04-10 10:41:46 -0700 | [diff] [blame] | 2500 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2501 | if (!shsurf->state.fullscreen && !shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2502 | switch (shell->win_animation_type) { |
| 2503 | case ANIMATION_FADE: |
| 2504 | weston_fade_run(shsurf->view, 0.0, 1.0, 300.0, NULL, NULL); |
| 2505 | break; |
| 2506 | case ANIMATION_ZOOM: |
| 2507 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
| 2508 | break; |
| 2509 | case ANIMATION_NONE: |
| 2510 | default: |
| 2511 | break; |
Jonas Ådahl | 49d77d2 | 2015-03-18 16:20:51 +0800 | [diff] [blame] | 2512 | } |
| 2513 | } |
Jasper St. Pierre | 084aa0b | 2015-02-13 14:02:00 +0800 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2517 | desktop_surface_committed(struct weston_desktop_surface *desktop_surface, |
| 2518 | int32_t sx, int32_t sy, void *data) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2519 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2520 | struct shell_surface *shsurf = |
| 2521 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2522 | struct weston_surface *surface = |
| 2523 | weston_desktop_surface_get_surface(desktop_surface); |
| 2524 | struct weston_view *view = shsurf->view; |
| 2525 | struct desktop_shell *shell = data; |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2526 | bool was_fullscreen; |
| 2527 | bool was_maximized; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2528 | |
| 2529 | if (surface->width == 0) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2530 | return; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2531 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2532 | was_fullscreen = shsurf->state.fullscreen; |
| 2533 | was_maximized = shsurf->state.maximized; |
| 2534 | |
| 2535 | shsurf->state.fullscreen = |
| 2536 | weston_desktop_surface_get_fullscreen(desktop_surface); |
| 2537 | shsurf->state.maximized = |
| 2538 | weston_desktop_surface_get_maximized(desktop_surface); |
| 2539 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2540 | if (!weston_surface_is_mapped(surface)) { |
| 2541 | map(shell, shsurf, sx, sy); |
| 2542 | surface->is_mapped = true; |
| 2543 | if (shsurf->shell->win_close_animation_type == ANIMATION_FADE) |
| 2544 | ++surface->ref_count; |
| 2545 | return; |
| 2546 | } |
| 2547 | |
| 2548 | if (sx == 0 && sy == 0 && |
| 2549 | shsurf->last_width == surface->width && |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2550 | shsurf->last_height == surface->height && |
| 2551 | was_fullscreen == shsurf->state.fullscreen && |
| 2552 | was_maximized == shsurf->state.maximized) |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2553 | return; |
| 2554 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2555 | if (was_fullscreen) |
| 2556 | unset_fullscreen(shsurf); |
| 2557 | if (was_maximized) |
| 2558 | unset_maximized(shsurf); |
| 2559 | |
Quentin Glidic | 920cf04 | 2016-08-16 14:26:20 +0200 | [diff] [blame] | 2560 | if ((shsurf->state.fullscreen || shsurf->state.maximized) && |
| 2561 | !shsurf->saved_position_valid) { |
| 2562 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2563 | shsurf->saved_y = shsurf->view->geometry.y; |
| 2564 | shsurf->saved_position_valid = true; |
| 2565 | |
| 2566 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2567 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2568 | wl_list_init(&shsurf->rotation.transform.link); |
| 2569 | weston_view_geometry_dirty(shsurf->view); |
| 2570 | shsurf->saved_rotation_valid = true; |
| 2571 | } |
| 2572 | } |
| 2573 | |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2574 | if (shsurf->state.fullscreen) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2575 | shell_configure_fullscreen(shsurf); |
Quentin Glidic | 18a81ac | 2016-08-16 14:26:03 +0200 | [diff] [blame] | 2576 | } else if (shsurf->state.maximized) { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2577 | set_maximized_position(shell, shsurf); |
| 2578 | surface->output = shsurf->output; |
| 2579 | } else { |
| 2580 | float from_x, from_y; |
| 2581 | float to_x, to_y; |
| 2582 | float x, y; |
| 2583 | |
| 2584 | if (shsurf->resize_edges) { |
| 2585 | sx = 0; |
| 2586 | sy = 0; |
| 2587 | } |
| 2588 | |
| 2589 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_LEFT) |
| 2590 | sx = shsurf->last_width - surface->width; |
| 2591 | if (shsurf->resize_edges & WL_SHELL_SURFACE_RESIZE_TOP) |
| 2592 | sy = shsurf->last_height - surface->height; |
| 2593 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2594 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 2595 | weston_view_to_global_float(shsurf->view, sx, sy, &to_x, &to_y); |
| 2596 | x = shsurf->view->geometry.x + to_x - from_x; |
| 2597 | y = shsurf->view->geometry.y + to_y - from_y; |
| 2598 | |
| 2599 | weston_view_set_position(shsurf->view, x, y); |
| 2600 | } |
| 2601 | |
Emmanuel Gil Peyrot | c394179 | 2017-04-04 18:49:33 +0100 | [diff] [blame] | 2602 | shsurf->last_width = surface->width; |
| 2603 | shsurf->last_height = surface->height; |
| 2604 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2605 | /* XXX: would a fullscreen surface need the same handling? */ |
| 2606 | if (surface->output) { |
| 2607 | wl_list_for_each(view, &surface->views, surface_link) |
| 2608 | weston_view_update_transform(view); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2609 | } |
| 2610 | } |
| 2611 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2612 | static void |
Derek Foreman | 927d9e2 | 2017-10-06 14:37:44 -0500 | [diff] [blame] | 2613 | get_maximized_size(struct shell_surface *shsurf, int32_t *width, int32_t *height) |
| 2614 | { |
| 2615 | struct desktop_shell *shell; |
| 2616 | pixman_rectangle32_t area; |
| 2617 | |
| 2618 | shell = shell_surface_get_shell(shsurf); |
| 2619 | get_output_work_area(shell, shsurf->output, &area); |
| 2620 | |
| 2621 | *width = area.width; |
| 2622 | *height = area.height; |
| 2623 | } |
| 2624 | |
| 2625 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2626 | set_fullscreen(struct shell_surface *shsurf, bool fullscreen, |
| 2627 | struct weston_output *output) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2628 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2629 | struct weston_desktop_surface *desktop_surface = shsurf->desktop_surface; |
| 2630 | struct weston_surface *surface = |
| 2631 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2632 | int32_t width = 0, height = 0; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2633 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2634 | if (fullscreen) { |
| 2635 | /* handle clients launching in fullscreen */ |
| 2636 | if (output == NULL && !weston_surface_is_mapped(surface)) { |
| 2637 | /* Set the output to the one that has focus currently. */ |
| 2638 | output = get_focused_output(surface->compositor); |
| 2639 | } |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 2640 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2641 | shell_surface_set_output(shsurf, output); |
| 2642 | shsurf->fullscreen_output = shsurf->output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2643 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2644 | width = shsurf->output->width; |
| 2645 | height = shsurf->output->height; |
Derek Foreman | e1af3d8 | 2017-10-06 14:37:45 -0500 | [diff] [blame] | 2646 | } else if (weston_desktop_surface_get_maximized(desktop_surface)) { |
| 2647 | get_maximized_size(shsurf, &width, &height); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2648 | } |
| 2649 | weston_desktop_surface_set_fullscreen(desktop_surface, fullscreen); |
| 2650 | weston_desktop_surface_set_size(desktop_surface, width, height); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2654 | desktop_surface_move(struct weston_desktop_surface *desktop_surface, |
| 2655 | struct weston_seat *seat, uint32_t serial, void *shell) |
| 2656 | { |
| 2657 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2658 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2659 | struct shell_surface *shsurf = |
| 2660 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2661 | struct weston_surface *surface = |
| 2662 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2663 | struct wl_resource *resource = surface->resource; |
| 2664 | struct weston_surface *focus; |
| 2665 | |
| 2666 | if (pointer && |
| 2667 | pointer->focus && |
| 2668 | pointer->button_count > 0 && |
| 2669 | pointer->grab_serial == serial) { |
| 2670 | focus = weston_surface_get_main_surface(pointer->focus->surface); |
| 2671 | if ((focus == surface) && |
| 2672 | (surface_move(shsurf, pointer, true) < 0)) |
| 2673 | wl_resource_post_no_memory(resource); |
| 2674 | } else if (touch && |
| 2675 | touch->focus && |
| 2676 | touch->grab_serial == serial) { |
| 2677 | focus = weston_surface_get_main_surface(touch->focus->surface); |
| 2678 | if ((focus == surface) && |
| 2679 | (surface_touch_move(shsurf, touch) < 0)) |
| 2680 | wl_resource_post_no_memory(resource); |
| 2681 | } |
| 2682 | } |
| 2683 | |
| 2684 | static void |
| 2685 | desktop_surface_resize(struct weston_desktop_surface *desktop_surface, |
| 2686 | struct weston_seat *seat, uint32_t serial, |
| 2687 | enum weston_desktop_surface_edge edges, void *shell) |
| 2688 | { |
| 2689 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2690 | struct shell_surface *shsurf = |
| 2691 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2692 | struct weston_surface *surface = |
| 2693 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2694 | struct wl_resource *resource = surface->resource; |
| 2695 | struct weston_surface *focus; |
| 2696 | |
| 2697 | if (!pointer || |
| 2698 | pointer->button_count == 0 || |
| 2699 | pointer->grab_serial != serial || |
| 2700 | pointer->focus == NULL) |
| 2701 | return; |
| 2702 | |
| 2703 | focus = weston_surface_get_main_surface(pointer->focus->surface); |
| 2704 | if (focus != surface) |
| 2705 | return; |
| 2706 | |
| 2707 | if (surface_resize(shsurf, pointer, edges) < 0) |
| 2708 | wl_resource_post_no_memory(resource); |
| 2709 | } |
| 2710 | |
| 2711 | static void |
| 2712 | desktop_surface_fullscreen_requested(struct weston_desktop_surface *desktop_surface, |
| 2713 | bool fullscreen, |
| 2714 | struct weston_output *output, void *shell) |
| 2715 | { |
| 2716 | struct shell_surface *shsurf = |
| 2717 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2718 | |
| 2719 | set_fullscreen(shsurf, fullscreen, output); |
| 2720 | } |
| 2721 | |
| 2722 | static void |
| 2723 | set_maximized(struct shell_surface *shsurf, bool maximized) |
| 2724 | { |
| 2725 | struct weston_desktop_surface *desktop_surface = shsurf->desktop_surface; |
| 2726 | struct weston_surface *surface = |
| 2727 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
| 2728 | int32_t width = 0, height = 0; |
| 2729 | |
| 2730 | if (maximized) { |
| 2731 | struct weston_output *output; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2732 | |
| 2733 | if (!weston_surface_is_mapped(surface)) |
| 2734 | output = get_focused_output(surface->compositor); |
| 2735 | else |
| 2736 | output = surface->output; |
| 2737 | |
| 2738 | shell_surface_set_output(shsurf, output); |
| 2739 | |
Derek Foreman | 927d9e2 | 2017-10-06 14:37:44 -0500 | [diff] [blame] | 2740 | get_maximized_size(shsurf, &width, &height); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2741 | } |
| 2742 | weston_desktop_surface_set_maximized(desktop_surface, maximized); |
| 2743 | weston_desktop_surface_set_size(desktop_surface, width, height); |
| 2744 | } |
| 2745 | |
| 2746 | static void |
| 2747 | desktop_surface_maximized_requested(struct weston_desktop_surface *desktop_surface, |
| 2748 | bool maximized, void *shell) |
| 2749 | { |
| 2750 | struct shell_surface *shsurf = |
| 2751 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2752 | |
| 2753 | set_maximized(shsurf, maximized); |
| 2754 | } |
| 2755 | |
| 2756 | static void |
| 2757 | desktop_surface_minimized_requested(struct weston_desktop_surface *desktop_surface, |
| 2758 | void *shell) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2759 | { |
| 2760 | struct weston_surface *surface = |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2761 | weston_desktop_surface_get_surface(desktop_surface); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2762 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2763 | /* apply compositor's own minimization logic (hide) */ |
| 2764 | set_minimized(surface); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2765 | } |
| 2766 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2767 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2768 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2769 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2770 | struct shell_grab *grab; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2771 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2772 | if (pointer->grab->interface == &busy_cursor_grab_interface) |
| 2773 | return; |
| 2774 | |
| 2775 | grab = malloc(sizeof *grab); |
| 2776 | if (!grab) |
| 2777 | return; |
| 2778 | |
| 2779 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 2780 | WESTON_DESKTOP_SHELL_CURSOR_BUSY); |
| 2781 | /* Mark the shsurf as ungrabbed so that button binding is able |
| 2782 | * to move it. */ |
| 2783 | shsurf->grabbed = 0; |
| 2784 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2785 | |
| 2786 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2787 | end_busy_cursor(struct weston_compositor *compositor, |
| 2788 | struct weston_desktop_client *desktop_client) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2789 | { |
Jonas Ådahl | ee45a55 | 2015-03-18 16:37:47 +0800 | [diff] [blame] | 2790 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2791 | struct shell_grab *grab; |
| 2792 | struct weston_seat *seat; |
Jonas Ådahl | 24185e2 | 2015-02-27 18:37:41 +0800 | [diff] [blame] | 2793 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2794 | wl_list_for_each(seat, &compositor->seat_list, link) { |
| 2795 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2796 | struct weston_desktop_client *grab_client; |
Pekka Paalanen | e972b27 | 2014-10-01 14:03:56 +0300 | [diff] [blame] | 2797 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2798 | if (!pointer) |
| 2799 | continue; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2800 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2801 | if (pointer->grab->interface != &busy_cursor_grab_interface) |
| 2802 | continue; |
| 2803 | |
| 2804 | grab = (struct shell_grab *) pointer->grab; |
| 2805 | shsurf = grab->shsurf; |
| 2806 | if (!shsurf) |
| 2807 | continue; |
| 2808 | |
| 2809 | grab_client = |
| 2810 | weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 2811 | if (grab_client == desktop_client) { |
| 2812 | shell_grab_end(grab); |
| 2813 | free(grab); |
| 2814 | } |
| 2815 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2816 | } |
| 2817 | |
| 2818 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2819 | desktop_surface_set_unresponsive(struct weston_desktop_surface *desktop_surface, |
| 2820 | void *user_data) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2821 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2822 | struct shell_surface *shsurf = |
| 2823 | weston_desktop_surface_get_user_data(desktop_surface); |
| 2824 | bool *unresponsive = user_data; |
| 2825 | |
| 2826 | shsurf->unresponsive = *unresponsive; |
| 2827 | } |
| 2828 | |
| 2829 | static void |
| 2830 | desktop_surface_ping_timeout(struct weston_desktop_client *desktop_client, |
| 2831 | void *shell_) |
| 2832 | { |
| 2833 | struct desktop_shell *shell = shell_; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2834 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2835 | struct weston_seat *seat; |
| 2836 | bool unresponsive = true; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2837 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2838 | weston_desktop_client_for_each_surface(desktop_client, |
| 2839 | desktop_surface_set_unresponsive, |
| 2840 | &unresponsive); |
| 2841 | |
| 2842 | |
| 2843 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 2844 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2845 | struct weston_desktop_client *grab_client; |
| 2846 | |
| 2847 | if (!pointer || !pointer->focus) |
| 2848 | continue; |
| 2849 | |
| 2850 | shsurf = get_shell_surface(pointer->focus->surface); |
| 2851 | if (!shsurf) |
| 2852 | continue; |
| 2853 | |
| 2854 | grab_client = |
| 2855 | weston_desktop_surface_get_client(shsurf->desktop_surface); |
| 2856 | if (grab_client == desktop_client) |
| 2857 | set_busy_cursor(shsurf, pointer); |
Jonas Ådahl | bf48e21 | 2015-02-06 10:15:28 +0800 | [diff] [blame] | 2858 | } |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2859 | } |
| 2860 | |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2861 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2862 | desktop_surface_pong(struct weston_desktop_client *desktop_client, |
| 2863 | void *shell_) |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2864 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2865 | struct desktop_shell *shell = shell_; |
| 2866 | bool unresponsive = false; |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2867 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2868 | weston_desktop_client_for_each_surface(desktop_client, |
| 2869 | desktop_surface_set_unresponsive, |
| 2870 | &unresponsive); |
| 2871 | end_busy_cursor(shell->compositor, desktop_client); |
Kristian Høgsberg | 2bff94e | 2014-02-11 12:22:51 -0800 | [diff] [blame] | 2872 | } |
| 2873 | |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2874 | static void |
| 2875 | desktop_surface_set_xwayland_position(struct weston_desktop_surface *surface, |
| 2876 | int32_t x, int32_t y, void *shell_) |
| 2877 | { |
| 2878 | struct shell_surface *shsurf = |
| 2879 | weston_desktop_surface_get_user_data(surface); |
| 2880 | |
| 2881 | shsurf->xwayland.x = x; |
| 2882 | shsurf->xwayland.y = y; |
| 2883 | shsurf->xwayland.is_set = true; |
| 2884 | } |
| 2885 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2886 | static const struct weston_desktop_api shell_desktop_api = { |
| 2887 | .struct_size = sizeof(struct weston_desktop_api), |
| 2888 | .surface_added = desktop_surface_added, |
| 2889 | .surface_removed = desktop_surface_removed, |
| 2890 | .committed = desktop_surface_committed, |
| 2891 | .move = desktop_surface_move, |
| 2892 | .resize = desktop_surface_resize, |
| 2893 | .fullscreen_requested = desktop_surface_fullscreen_requested, |
| 2894 | .maximized_requested = desktop_surface_maximized_requested, |
| 2895 | .minimized_requested = desktop_surface_minimized_requested, |
| 2896 | .ping_timeout = desktop_surface_ping_timeout, |
| 2897 | .pong = desktop_surface_pong, |
Pekka Paalanen | 77a6d95 | 2016-11-16 15:17:14 +0200 | [diff] [blame] | 2898 | .set_xwayland_position = desktop_surface_set_xwayland_position, |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2899 | }; |
| 2900 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2901 | /* ************************ * |
| 2902 | * end of libweston-desktop * |
| 2903 | * ************************ */ |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2904 | static void |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 2905 | 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] | 2906 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2907 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2908 | |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 2909 | if (!ev->output) |
| 2910 | return; |
| 2911 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2912 | 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] | 2913 | if (v->output == ev->output && v != ev) { |
| 2914 | weston_view_unmap(v); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2915 | v->surface->committed = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2916 | weston_surface_set_label_func(v->surface, NULL); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2917 | } |
| 2918 | } |
| 2919 | |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 2920 | 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] | 2921 | ev->surface->is_mapped = true; |
| 2922 | ev->is_mapped = true; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2923 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2924 | if (wl_list_empty(&ev->layer_link.link)) { |
| 2925 | weston_layer_entry_insert(&layer->view_list, &ev->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2926 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2927 | } |
| 2928 | } |
| 2929 | |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2930 | |
| 2931 | static struct shell_output * |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 2932 | find_shell_output_from_weston_output(struct desktop_shell *shell, |
| 2933 | struct weston_output *output) |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2934 | { |
| 2935 | struct shell_output *shell_output; |
| 2936 | |
| 2937 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 2938 | if (shell_output->output == output) |
| 2939 | return shell_output; |
| 2940 | } |
| 2941 | |
| 2942 | return NULL; |
| 2943 | } |
| 2944 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2945 | static int |
| 2946 | background_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2947 | { |
| 2948 | return snprintf(buf, len, "background for output %s", |
| 2949 | surface->output->name); |
| 2950 | } |
| 2951 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2952 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2953 | 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] | 2954 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2955 | struct desktop_shell *shell = es->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2956 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2957 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2958 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 2959 | |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 2960 | configure_static_view(view, &shell->background_layer, 0, 0); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2964 | handle_background_surface_destroy(struct wl_listener *listener, void *data) |
| 2965 | { |
| 2966 | struct shell_output *output = |
| 2967 | container_of(listener, struct shell_output, background_surface_listener); |
| 2968 | |
| 2969 | weston_log("background surface gone\n"); |
Tomohito Esaki | bf31f6c | 2018-01-31 15:15:45 +0900 | [diff] [blame] | 2970 | wl_list_remove(&output->background_surface_listener.link); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2971 | output->background_surface = NULL; |
| 2972 | } |
| 2973 | |
| 2974 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2975 | desktop_shell_set_background(struct wl_client *client, |
| 2976 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2977 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2978 | struct wl_resource *surface_resource) |
| 2979 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2980 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2981 | struct weston_surface *surface = |
| 2982 | wl_resource_get_user_data(surface_resource); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 2983 | struct shell_output *sh_output; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2984 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2985 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2986 | if (surface->committed) { |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2987 | wl_resource_post_error(surface_resource, |
| 2988 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2989 | "surface role already assigned"); |
| 2990 | return; |
| 2991 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2992 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2993 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 2994 | weston_view_destroy(view); |
| 2995 | view = weston_view_create(surface); |
| 2996 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2997 | surface->committed = background_committed; |
| 2998 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2999 | weston_surface_set_label_func(surface, background_get_label); |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 3000 | surface->output = weston_head_from_resource(output_resource)->output; |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 3001 | weston_view_set_output(view, surface->output); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3002 | |
| 3003 | sh_output = find_shell_output_from_weston_output(shell, surface->output); |
Pekka Paalanen | ff5e88d | 2017-12-07 11:44:18 +0200 | [diff] [blame] | 3004 | if (sh_output->background_surface) { |
| 3005 | /* The output already has a background, tell our helper |
| 3006 | * there is no need for another one. */ |
| 3007 | weston_desktop_shell_send_configure(resource, 0, |
| 3008 | surface_resource, |
| 3009 | 0, 0); |
| 3010 | } else { |
| 3011 | weston_desktop_shell_send_configure(resource, 0, |
| 3012 | surface_resource, |
| 3013 | surface->output->width, |
| 3014 | surface->output->height); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3015 | |
Pekka Paalanen | ff5e88d | 2017-12-07 11:44:18 +0200 | [diff] [blame] | 3016 | sh_output->background_surface = surface; |
| 3017 | |
| 3018 | sh_output->background_surface_listener.notify = |
| 3019 | handle_background_surface_destroy; |
| 3020 | wl_signal_add(&surface->destroy_signal, |
| 3021 | &sh_output->background_surface_listener); |
| 3022 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3023 | } |
| 3024 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3025 | static int |
| 3026 | panel_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3027 | { |
| 3028 | return snprintf(buf, len, "panel for output %s", |
| 3029 | surface->output->name); |
| 3030 | } |
| 3031 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3032 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3033 | 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] | 3034 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3035 | struct desktop_shell *shell = es->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3036 | struct weston_view *view; |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 3037 | int width, height; |
| 3038 | int x = 0, y = 0; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3039 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3040 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3041 | |
Quentin Glidic | e8bf959 | 2016-06-23 18:55:20 +0200 | [diff] [blame] | 3042 | get_panel_size(shell, view, &width, &height); |
| 3043 | switch (shell->panel_position) { |
| 3044 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP: |
| 3045 | break; |
| 3046 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM: |
| 3047 | y = view->output->height - height; |
| 3048 | break; |
| 3049 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT: |
| 3050 | break; |
| 3051 | case WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT: |
| 3052 | x = view->output->width - width; |
| 3053 | break; |
| 3054 | } |
| 3055 | |
| 3056 | configure_static_view(view, &shell->panel_layer, x, y); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3060 | handle_panel_surface_destroy(struct wl_listener *listener, void *data) |
| 3061 | { |
| 3062 | struct shell_output *output = |
| 3063 | container_of(listener, struct shell_output, panel_surface_listener); |
| 3064 | |
| 3065 | weston_log("panel surface gone\n"); |
Tomohito Esaki | bf31f6c | 2018-01-31 15:15:45 +0900 | [diff] [blame] | 3066 | wl_list_remove(&output->panel_surface_listener.link); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3067 | output->panel_surface = NULL; |
| 3068 | } |
| 3069 | |
| 3070 | |
| 3071 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3072 | desktop_shell_set_panel(struct wl_client *client, |
| 3073 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3074 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3075 | struct wl_resource *surface_resource) |
| 3076 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3077 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3078 | struct weston_surface *surface = |
| 3079 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3080 | struct weston_view *view, *next; |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3081 | struct shell_output *sh_output; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3082 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3083 | if (surface->committed) { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3084 | wl_resource_post_error(surface_resource, |
| 3085 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3086 | "surface role already assigned"); |
| 3087 | return; |
| 3088 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3089 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3090 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3091 | weston_view_destroy(view); |
| 3092 | view = weston_view_create(surface); |
| 3093 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3094 | surface->committed = panel_committed; |
| 3095 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3096 | weston_surface_set_label_func(surface, panel_get_label); |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 3097 | surface->output = weston_head_from_resource(output_resource)->output; |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 3098 | weston_view_set_output(view, surface->output); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3099 | |
| 3100 | sh_output = find_shell_output_from_weston_output(shell, surface->output); |
Pekka Paalanen | 1a0239e | 2017-12-07 11:54:11 +0200 | [diff] [blame] | 3101 | if (sh_output->panel_surface) { |
| 3102 | /* The output already has a panel, tell our helper |
| 3103 | * there is no need for another one. */ |
| 3104 | weston_desktop_shell_send_configure(resource, 0, |
| 3105 | surface_resource, |
| 3106 | 0, 0); |
| 3107 | } else { |
| 3108 | weston_desktop_shell_send_configure(resource, 0, |
| 3109 | surface_resource, |
| 3110 | surface->output->width, |
| 3111 | surface->output->height); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 3112 | |
Pekka Paalanen | 1a0239e | 2017-12-07 11:54:11 +0200 | [diff] [blame] | 3113 | sh_output->panel_surface = surface; |
| 3114 | |
| 3115 | sh_output->panel_surface_listener.notify = handle_panel_surface_destroy; |
| 3116 | wl_signal_add(&surface->destroy_signal, &sh_output->panel_surface_listener); |
| 3117 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3118 | } |
| 3119 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3120 | static int |
| 3121 | lock_surface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3122 | { |
| 3123 | return snprintf(buf, len, "lock window"); |
| 3124 | } |
| 3125 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3126 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3127 | 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] | 3128 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3129 | struct desktop_shell *shell = surface->committed_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3130 | struct weston_view *view; |
| 3131 | |
| 3132 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3133 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3134 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3135 | return; |
| 3136 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3137 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3138 | |
| 3139 | if (!weston_surface_is_mapped(surface)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3140 | weston_layer_entry_insert(&shell->lock_layer.view_list, |
| 3141 | &view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3142 | weston_view_update_transform(view); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 3143 | surface->is_mapped = true; |
| 3144 | view->is_mapped = true; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3145 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3146 | } |
| 3147 | } |
| 3148 | |
| 3149 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3150 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3151 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3152 | struct desktop_shell *shell = |
| 3153 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3154 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3155 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3156 | shell->lock_surface = NULL; |
| 3157 | } |
| 3158 | |
| 3159 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3160 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3161 | struct wl_resource *resource, |
| 3162 | struct wl_resource *surface_resource) |
| 3163 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3164 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3165 | struct weston_surface *surface = |
| 3166 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3167 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3168 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3169 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3170 | if (!shell->locked) |
| 3171 | return; |
| 3172 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3173 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3174 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3175 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3176 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3177 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3178 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3179 | weston_view_create(surface); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3180 | surface->committed = lock_surface_committed; |
| 3181 | surface->committed_private = shell; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3182 | weston_surface_set_label_func(surface, lock_surface_get_label); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3186 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3187 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3188 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3189 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3190 | weston_layer_unset_position(&shell->lock_layer); |
| 3191 | |
| 3192 | if (shell->showing_input_panels) |
| 3193 | weston_layer_set_position(&shell->input_panel_layer, |
| 3194 | WESTON_LAYER_POSITION_TOP_UI); |
| 3195 | weston_layer_set_position(&shell->fullscreen_layer, |
| 3196 | WESTON_LAYER_POSITION_FULLSCREEN); |
| 3197 | weston_layer_set_position(&shell->panel_layer, |
| 3198 | WESTON_LAYER_POSITION_UI); |
| 3199 | weston_layer_set_position(&ws->layer, WESTON_LAYER_POSITION_NORMAL); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3200 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3201 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3202 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3203 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3204 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3205 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3206 | } |
| 3207 | |
| 3208 | static void |
| 3209 | desktop_shell_unlock(struct wl_client *client, |
| 3210 | struct wl_resource *resource) |
| 3211 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3212 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3213 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3214 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3215 | |
| 3216 | if (shell->locked) |
| 3217 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3218 | } |
| 3219 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3220 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3221 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3222 | struct wl_resource *resource, |
| 3223 | struct wl_resource *surface_resource) |
| 3224 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3225 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3226 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3227 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3228 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3229 | } |
| 3230 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3231 | static void |
| 3232 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3233 | struct wl_resource *resource) |
| 3234 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3235 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3236 | |
| 3237 | shell_fade_startup(shell); |
| 3238 | } |
| 3239 | |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3240 | static void |
| 3241 | desktop_shell_set_panel_position(struct wl_client *client, |
| 3242 | struct wl_resource *resource, |
| 3243 | uint32_t position) |
| 3244 | { |
| 3245 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3246 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3247 | if (position != WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP && |
| 3248 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM && |
| 3249 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_LEFT && |
| 3250 | position != WESTON_DESKTOP_SHELL_PANEL_POSITION_RIGHT) { |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3251 | wl_resource_post_error(resource, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3252 | WESTON_DESKTOP_SHELL_ERROR_INVALID_ARGUMENT, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3253 | "bad position argument"); |
| 3254 | return; |
| 3255 | } |
| 3256 | |
| 3257 | shell->panel_position = position; |
| 3258 | } |
| 3259 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3260 | static const struct weston_desktop_shell_interface desktop_shell_implementation = { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3261 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3262 | desktop_shell_set_panel, |
| 3263 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3264 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3265 | desktop_shell_set_grab_surface, |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 3266 | desktop_shell_desktop_ready, |
| 3267 | desktop_shell_set_panel_position |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3268 | }; |
| 3269 | |
| 3270 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3271 | move_binding(struct weston_pointer *pointer, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3272 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3273 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3274 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3275 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3276 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3277 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3278 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3279 | return; |
| 3280 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3281 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3282 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3283 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3284 | if (surface == NULL) |
| 3285 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3286 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3287 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3288 | if (shsurf == NULL || |
| 3289 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3290 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3291 | return; |
| 3292 | |
Derek Foreman | 794fa0e | 2015-07-15 13:00:38 -0500 | [diff] [blame] | 3293 | surface_move(shsurf, pointer, false); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3294 | } |
| 3295 | |
| 3296 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3297 | maximize_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3298 | uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3299 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3300 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3301 | struct weston_surface *surface; |
| 3302 | struct shell_surface *shsurf; |
| 3303 | |
| 3304 | surface = weston_surface_get_main_surface(focus); |
| 3305 | if (surface == NULL) |
| 3306 | return; |
| 3307 | |
| 3308 | shsurf = get_shell_surface(surface); |
| 3309 | if (shsurf == NULL) |
| 3310 | return; |
| 3311 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3312 | set_maximized(shsurf, !weston_desktop_surface_get_maximized(shsurf->desktop_surface)); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3313 | } |
| 3314 | |
| 3315 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3316 | fullscreen_binding(struct weston_keyboard *keyboard, |
| 3317 | const struct timespec *time, uint32_t button, void *data) |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3318 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3319 | struct weston_surface *focus = keyboard->focus; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3320 | struct weston_surface *surface; |
| 3321 | struct shell_surface *shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3322 | bool fullscreen; |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3323 | |
| 3324 | surface = weston_surface_get_main_surface(focus); |
| 3325 | if (surface == NULL) |
| 3326 | return; |
| 3327 | |
| 3328 | shsurf = get_shell_surface(surface); |
| 3329 | if (shsurf == NULL) |
| 3330 | return; |
| 3331 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3332 | fullscreen = |
| 3333 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3334 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3335 | set_fullscreen(shsurf, !fullscreen, NULL); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | static void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 3339 | 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] | 3340 | { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 3341 | struct weston_surface *focus; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3342 | struct weston_surface *surface; |
| 3343 | struct shell_surface *shsurf; |
| 3344 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3345 | if (touch->focus == NULL) |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 3346 | return; |
| 3347 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3348 | focus = touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3349 | surface = weston_surface_get_main_surface(focus); |
| 3350 | if (surface == NULL) |
| 3351 | return; |
| 3352 | |
| 3353 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3354 | if (shsurf == NULL || |
| 3355 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3356 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3357 | return; |
| 3358 | |
Derek Foreman | b7674ae | 2015-07-15 13:00:37 -0500 | [diff] [blame] | 3359 | surface_touch_move(shsurf, touch); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3363 | resize_binding(struct weston_pointer *pointer, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3364 | uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3365 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3366 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3367 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3368 | uint32_t edges = 0; |
| 3369 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3370 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3371 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3372 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3373 | return; |
| 3374 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3375 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3376 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3377 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3378 | if (surface == NULL) |
| 3379 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3380 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3381 | shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3382 | if (shsurf == NULL || |
| 3383 | weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) || |
| 3384 | weston_desktop_surface_get_maximized(shsurf->desktop_surface)) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3385 | return; |
| 3386 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3387 | weston_view_from_global(shsurf->view, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3388 | wl_fixed_to_int(pointer->grab_x), |
| 3389 | wl_fixed_to_int(pointer->grab_y), |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3390 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3391 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3392 | if (x < surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3393 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3394 | else if (x < 2 * surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3395 | edges |= 0; |
| 3396 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3397 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3398 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3399 | if (y < surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3400 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3401 | else if (y < 2 * surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3402 | edges |= 0; |
| 3403 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3404 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3405 | |
Derek Foreman | 8fbebbd | 2015-07-15 13:00:40 -0500 | [diff] [blame] | 3406 | surface_resize(shsurf, pointer, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | static void |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 3410 | surface_opacity_binding(struct weston_pointer *pointer, |
| 3411 | const struct timespec *time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3412 | struct weston_pointer_axis_event *event, |
| 3413 | void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3414 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3415 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3416 | struct shell_surface *shsurf; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3417 | struct weston_surface *focus = pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3418 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3419 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3420 | /* XXX: broken for windows containing sub-surfaces */ |
| 3421 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3422 | if (surface == NULL) |
| 3423 | return; |
| 3424 | |
| 3425 | shsurf = get_shell_surface(surface); |
| 3426 | if (!shsurf) |
| 3427 | return; |
| 3428 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 3429 | shsurf->view->alpha -= event->value * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3430 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3431 | if (shsurf->view->alpha > 1.0) |
| 3432 | shsurf->view->alpha = 1.0; |
| 3433 | if (shsurf->view->alpha < step) |
| 3434 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3435 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3436 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3437 | weston_surface_damage(surface); |
| 3438 | } |
| 3439 | |
| 3440 | static void |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 3441 | do_zoom(struct weston_seat *seat, const struct timespec *time, uint32_t key, |
| 3442 | uint32_t axis, double value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3443 | { |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 3444 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3445 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3446 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3447 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3448 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3449 | if (!pointer) { |
Derek Foreman | 7ef3bed | 2015-01-06 14:28:13 -0600 | [diff] [blame] | 3450 | weston_log("Zoom hotkey pressed but seat '%s' contains no pointer.\n", seat->seat_name); |
| 3451 | return; |
| 3452 | } |
| 3453 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3454 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3455 | if (pixman_region32_contains_point(&output->region, |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3456 | wl_fixed_to_double(pointer->x), |
| 3457 | wl_fixed_to_double(pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3458 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3459 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3460 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3461 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3462 | increment = -output->zoom.increment; |
| 3463 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3464 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3465 | increment = output->zoom.increment * |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 3466 | -value / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3467 | else |
| 3468 | increment = 0; |
| 3469 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3470 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3471 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3472 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3473 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3474 | else if (output->zoom.level > output->zoom.max_level) |
| 3475 | output->zoom.level = output->zoom.max_level; |
Derek Foreman | 25bd8a7 | 2015-07-23 14:55:13 -0500 | [diff] [blame] | 3476 | |
| 3477 | if (!output->zoom.active) { |
| 3478 | if (output->zoom.level <= 0.0) |
| 3479 | continue; |
Derek Foreman | 22276a5 | 2015-07-23 14:55:15 -0500 | [diff] [blame] | 3480 | weston_output_activate_zoom(output, seat); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3481 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3482 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3483 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3484 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3485 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3486 | } |
| 3487 | } |
| 3488 | } |
| 3489 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3490 | static void |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 3491 | zoom_axis_binding(struct weston_pointer *pointer, const struct timespec *time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3492 | struct weston_pointer_axis_event *event, |
| 3493 | void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3494 | { |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 3495 | do_zoom(pointer->seat, time, 0, event->axis, event->value); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3496 | } |
| 3497 | |
| 3498 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3499 | zoom_key_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3500 | uint32_t key, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3501 | { |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3502 | do_zoom(keyboard->seat, time, key, 0, 0); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 3506 | terminate_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3507 | uint32_t key, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3508 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3509 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3510 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3511 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3512 | } |
| 3513 | |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3514 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 3515 | rotate_grab_motion(struct weston_pointer_grab *grab, |
| 3516 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3517 | struct weston_pointer_motion_event *event) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3518 | { |
| 3519 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3520 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3521 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3522 | struct shell_surface *shsurf = rotate->base.shsurf; |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3523 | struct weston_surface *surface = |
| 3524 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3525 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3526 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 3527 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3528 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3529 | if (!shsurf) |
| 3530 | return; |
| 3531 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3532 | cx = 0.5f * surface->width; |
| 3533 | cy = 0.5f * surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3534 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3535 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3536 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3537 | r = sqrtf(dx * dx + dy * dy); |
| 3538 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3539 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3540 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3541 | |
| 3542 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3543 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3544 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3545 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3546 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3547 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3548 | |
| 3549 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3550 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3551 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3552 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3553 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3554 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 3555 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3556 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3557 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3558 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3559 | wl_list_init(&shsurf->rotation.transform.link); |
| 3560 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3561 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3562 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3563 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3564 | /* We need to adjust the position of the surface |
| 3565 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3566 | cposx = shsurf->view->geometry.x + cx; |
| 3567 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3568 | dposx = rotate->center.x - cposx; |
| 3569 | dposy = rotate->center.y - cposy; |
| 3570 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3571 | weston_view_set_position(shsurf->view, |
| 3572 | shsurf->view->geometry.x + dposx, |
| 3573 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3574 | } |
| 3575 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 3576 | /* Repaint implies weston_view_update_transform(), which |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3577 | * lazily applies the damage due to rotation update. |
| 3578 | */ |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3579 | weston_compositor_schedule_repaint(surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3580 | } |
| 3581 | |
| 3582 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3583 | rotate_grab_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3584 | const struct timespec *time, |
| 3585 | uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3586 | { |
| 3587 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3588 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3589 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3590 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3591 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3592 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3593 | if (pointer->button_count == 0 && |
| 3594 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3595 | if (shsurf) |
| 3596 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 3597 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3598 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3599 | free(rotate); |
| 3600 | } |
| 3601 | } |
| 3602 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3603 | static void |
| 3604 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 3605 | { |
| 3606 | struct rotate_grab *rotate = |
| 3607 | container_of(grab, struct rotate_grab, base.grab); |
| 3608 | |
| 3609 | shell_grab_end(&rotate->base); |
| 3610 | free(rotate); |
| 3611 | } |
| 3612 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3613 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3614 | noop_grab_focus, |
| 3615 | rotate_grab_motion, |
| 3616 | rotate_grab_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 3617 | noop_grab_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 3618 | noop_grab_axis_source, |
| 3619 | noop_grab_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3620 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3621 | }; |
| 3622 | |
| 3623 | static void |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3624 | surface_rotate(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3625 | { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3626 | struct weston_surface *surface = |
| 3627 | weston_desktop_surface_get_surface(shsurf->desktop_surface); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3628 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3629 | float dx, dy; |
| 3630 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3631 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3632 | rotate = malloc(sizeof *rotate); |
| 3633 | if (!rotate) |
| 3634 | return; |
| 3635 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3636 | weston_view_to_global_float(shsurf->view, |
| 3637 | surface->width * 0.5f, |
| 3638 | surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3639 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3640 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 3641 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3642 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3643 | r = sqrtf(dx * dx + dy * dy); |
| 3644 | if (r > 20.0f) { |
| 3645 | struct weston_matrix inverse; |
| 3646 | |
| 3647 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3648 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3649 | weston_matrix_multiply(&shsurf->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3650 | |
| 3651 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3652 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3653 | } else { |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3654 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3655 | weston_matrix_init(&rotate->rotation); |
| 3656 | } |
| 3657 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3658 | shell_grab_start(&rotate->base, &rotate_grab_interface, shsurf, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3659 | pointer, WESTON_DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3663 | rotate_binding(struct weston_pointer *pointer, const struct timespec *time, |
| 3664 | uint32_t button, void *data) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3665 | { |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3666 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3667 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3668 | struct shell_surface *surface; |
| 3669 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3670 | if (pointer->focus == NULL) |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3671 | return; |
| 3672 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3673 | focus = pointer->focus->surface; |
Rafal Mielniczuk | b2917a2 | 2014-01-05 20:04:59 +0100 | [diff] [blame] | 3674 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3675 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3676 | if (base_surface == NULL) |
| 3677 | return; |
| 3678 | |
| 3679 | surface = get_shell_surface(base_surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3680 | if (surface == NULL || |
| 3681 | weston_desktop_surface_get_fullscreen(surface->desktop_surface) || |
| 3682 | weston_desktop_surface_get_maximized(surface->desktop_surface)) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3683 | return; |
| 3684 | |
Derek Foreman | 74de469 | 2015-07-15 13:00:39 -0500 | [diff] [blame] | 3685 | surface_rotate(surface, pointer); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3686 | } |
| 3687 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3688 | /* Move all fullscreen layers down to the current workspace and hide their |
| 3689 | * black views. The surfaces' state is set to both fullscreen and lowered, |
| 3690 | * and this is reversed when such a surface is re-configured, see |
| 3691 | * shell_configure_fullscreen() and shell_ensure_fullscreen_black_view(). |
| 3692 | * |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3693 | * lowering_output = NULL - Lower on all outputs, else only lower on the |
| 3694 | * specified output. |
| 3695 | * |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3696 | * This should be used when implementing shell-wide overlays, such as |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3697 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3698 | void |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3699 | lower_fullscreen_layer(struct desktop_shell *shell, |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3700 | struct weston_output *lowering_output) |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3701 | { |
| 3702 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3703 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3704 | |
| 3705 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3706 | wl_list_for_each_reverse_safe(view, prev, |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3707 | &shell->fullscreen_layer.view_list.link, |
| 3708 | layer_link.link) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3709 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 3710 | |
| 3711 | if (!shsurf) |
| 3712 | continue; |
| 3713 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3714 | /* Only lower surfaces which have lowering_output as their fullscreen |
| 3715 | * output, unless a NULL output asks for lowering on all outputs. |
| 3716 | */ |
| 3717 | if (lowering_output && (shsurf->fullscreen_output != lowering_output)) |
| 3718 | continue; |
| 3719 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3720 | /* We can have a non-fullscreen popup for a fullscreen surface |
| 3721 | * in the fullscreen layer. */ |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3722 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)) { |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3723 | /* Hide the black view */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3724 | weston_layer_entry_remove(&shsurf->fullscreen.black_view->layer_link); |
| 3725 | wl_list_init(&shsurf->fullscreen.black_view->layer_link.link); |
Kristian Høgsberg | c991513 | 2014-05-09 16:24:07 -0700 | [diff] [blame] | 3726 | weston_view_damage_below(shsurf->fullscreen.black_view); |
| 3727 | |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | /* Lower the view to the workspace layer */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3731 | weston_layer_entry_remove(&view->layer_link); |
| 3732 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3733 | weston_view_damage_below(view); |
| 3734 | weston_surface_damage(view->surface); |
Emilio Pozuelo Monfort | 9e7c759 | 2014-01-30 14:01:10 +0100 | [diff] [blame] | 3735 | |
| 3736 | shsurf->state.lowered = true; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3737 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3738 | } |
| 3739 | |
Kristian Høgsberg | 1ef2313 | 2013-12-04 00:20:01 -0800 | [diff] [blame] | 3740 | void |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 3741 | activate(struct desktop_shell *shell, struct weston_view *view, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3742 | struct weston_seat *seat, uint32_t flags) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3743 | { |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 3744 | struct weston_surface *es = view->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3745 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3746 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3747 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3748 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3749 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3750 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3751 | main_surface = weston_surface_get_main_surface(es); |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 3752 | shsurf = get_shell_surface(main_surface); |
| 3753 | assert(shsurf); |
| 3754 | |
| 3755 | /* Only demote fullscreen surfaces on the output of activated shsurf. |
| 3756 | * Leave fullscreen surfaces on unrelated outputs alone. */ |
| 3757 | lower_fullscreen_layer(shell, shsurf->output); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3758 | |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 3759 | weston_view_activate(view, seat, flags); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3760 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3761 | state = ensure_focus_state(shell, seat); |
| 3762 | if (state == NULL) |
| 3763 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3764 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3765 | old_es = state->keyboard_focus; |
Kristian Høgsberg | d500bf1 | 2014-01-22 12:25:20 -0800 | [diff] [blame] | 3766 | focus_state_set_focus(state, es); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3767 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3768 | if (weston_desktop_surface_get_fullscreen(shsurf->desktop_surface) && |
| 3769 | flags & WESTON_ACTIVATE_FLAG_CONFIGURE) |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3770 | shell_configure_fullscreen(shsurf); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3771 | |
Emilio Pozuelo Monfort | 7908bff | 2014-01-30 13:49:39 +0100 | [diff] [blame] | 3772 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 3773 | * order as appropriate. */ |
| 3774 | shell_surface_update_layer(shsurf); |
| 3775 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3776 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 3777 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3778 | 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] | 3779 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3780 | } |
| 3781 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3782 | /* no-op func for checking black surface */ |
| 3783 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3784 | 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] | 3785 | { |
| 3786 | } |
| 3787 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 3788 | static bool |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3789 | 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] | 3790 | { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3791 | struct weston_surface *surface = view->surface; |
| 3792 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3793 | if (surface->committed == black_surface_committed) { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3794 | if (fs_view) |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3795 | *fs_view = surface->committed_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3796 | return true; |
| 3797 | } |
| 3798 | return false; |
| 3799 | } |
| 3800 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3801 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3802 | activate_binding(struct weston_seat *seat, |
| 3803 | struct desktop_shell *shell, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3804 | struct weston_view *focus_view, |
| 3805 | uint32_t flags) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3806 | { |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3807 | struct weston_view *main_view; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3808 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3809 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3810 | if (!focus_view) |
| 3811 | return; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 3812 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3813 | if (is_black_surface_view(focus_view, &main_view)) |
| 3814 | focus_view = main_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3815 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 3816 | main_surface = weston_surface_get_main_surface(focus_view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 3817 | if (!get_shell_surface(main_surface)) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3818 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 3819 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3820 | activate(shell, focus_view, seat, flags); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3821 | } |
| 3822 | |
| 3823 | static void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3824 | click_to_activate_binding(struct weston_pointer *pointer, |
| 3825 | const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3826 | uint32_t button, void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3827 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3828 | if (pointer->grab != &pointer->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3829 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3830 | if (pointer->focus == NULL) |
Kristian Høgsberg | 7c4f6cc | 2014-01-01 16:28:32 -0800 | [diff] [blame] | 3831 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3832 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3833 | activate_binding(pointer->seat, data, pointer->focus, |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 3834 | WESTON_ACTIVATE_FLAG_CLICKED | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3835 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | static void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 3839 | touch_to_activate_binding(struct weston_touch *touch, |
| 3840 | const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3841 | void *data) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3842 | { |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3843 | if (touch->grab != &touch->default_grab) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3844 | return; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 3845 | if (touch->focus == NULL) |
Kristian Høgsberg | 0ed6750 | 2014-01-02 23:00:11 -0800 | [diff] [blame] | 3846 | return; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3847 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 3848 | activate_binding(touch->seat, data, touch->focus, |
| 3849 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3850 | } |
| 3851 | |
| 3852 | static void |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3853 | unfocus_all_seats(struct desktop_shell *shell) |
| 3854 | { |
| 3855 | struct weston_seat *seat, *next; |
| 3856 | |
| 3857 | wl_list_for_each_safe(seat, next, &shell->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3858 | struct weston_keyboard *keyboard = |
| 3859 | weston_seat_get_keyboard(seat); |
| 3860 | |
| 3861 | if (!keyboard) |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3862 | continue; |
| 3863 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3864 | weston_keyboard_set_focus(keyboard, NULL); |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3865 | } |
| 3866 | } |
| 3867 | |
| 3868 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3869 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3870 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3871 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3872 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3873 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3874 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3875 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3876 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3877 | |
| 3878 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3879 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3880 | /* Hide all surfaces by removing the fullscreen, panel and |
| 3881 | * toplevel layers. This way nothing else can show or receive |
| 3882 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3883 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3884 | weston_layer_unset_position(&shell->panel_layer); |
| 3885 | weston_layer_unset_position(&shell->fullscreen_layer); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3886 | if (shell->showing_input_panels) |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3887 | weston_layer_unset_position(&shell->input_panel_layer); |
| 3888 | weston_layer_unset_position(&ws->layer); |
| 3889 | |
| 3890 | weston_layer_set_position(&shell->lock_layer, |
| 3891 | WESTON_LAYER_POSITION_LOCK); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3892 | |
Derek Foreman | 004b4a1 | 2015-07-20 16:28:13 -0500 | [diff] [blame] | 3893 | weston_compositor_sleep(shell->compositor); |
| 3894 | |
Neil Roberts | b4a9170 | 2014-04-09 16:33:32 +0100 | [diff] [blame] | 3895 | /* Remove the keyboard focus on all seats. This will be |
| 3896 | * restored to the workspace's saved state via |
| 3897 | * restore_focus_state when the compositor is unlocked */ |
| 3898 | unfocus_all_seats(shell); |
| 3899 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3900 | /* TODO: disable bindings that should not work while locked. */ |
| 3901 | |
| 3902 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3903 | } |
| 3904 | |
| 3905 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3906 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3907 | { |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3908 | struct wl_resource *shell_resource; |
| 3909 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 3910 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3911 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3912 | return; |
| 3913 | } |
| 3914 | |
| 3915 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 3916 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3917 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3918 | return; |
| 3919 | } |
| 3920 | |
| 3921 | if (shell->prepare_event_sent) |
| 3922 | return; |
| 3923 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 3924 | shell_resource = shell->child.desktop_shell; |
| 3925 | weston_desktop_shell_send_prepare_lock_surface(shell_resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3926 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3927 | } |
| 3928 | |
| 3929 | static void |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 3930 | 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] | 3931 | { |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 3932 | struct shell_output *shell_output = data; |
| 3933 | struct desktop_shell *shell = shell_output->shell; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3934 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 3935 | shell_output->fade.animation = NULL; |
| 3936 | switch (shell_output->fade.type) { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3937 | case FADE_IN: |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 3938 | weston_surface_destroy(shell_output->fade.view->surface); |
| 3939 | shell_output->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3940 | break; |
| 3941 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3942 | lock(shell); |
| 3943 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 3944 | default: |
| 3945 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3946 | } |
| 3947 | } |
| 3948 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3949 | static struct weston_view * |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 3950 | 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] | 3951 | { |
| 3952 | struct weston_compositor *compositor = shell->compositor; |
| 3953 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3954 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3955 | |
| 3956 | surface = weston_surface_create(compositor); |
| 3957 | if (!surface) |
| 3958 | return NULL; |
| 3959 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3960 | view = weston_view_create(surface); |
| 3961 | if (!view) { |
| 3962 | weston_surface_destroy(surface); |
| 3963 | return NULL; |
| 3964 | } |
| 3965 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 3966 | weston_surface_set_size(surface, shell_output->output->width, shell_output->output->height); |
| 3967 | 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] | 3968 | 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] | 3969 | weston_layer_entry_insert(&compositor->fade_layer.view_list, |
| 3970 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3971 | pixman_region32_init(&surface->input); |
Armin Krezović | 4663aca | 2016-06-30 06:04:29 +0200 | [diff] [blame] | 3972 | surface->is_mapped = true; |
| 3973 | view->is_mapped = true; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3974 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3975 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | static void |
| 3979 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 3980 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3981 | float tint; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 3982 | struct shell_output *shell_output; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3983 | |
| 3984 | switch (type) { |
| 3985 | case FADE_IN: |
| 3986 | tint = 0.0; |
| 3987 | break; |
| 3988 | case FADE_OUT: |
| 3989 | tint = 1.0; |
| 3990 | break; |
| 3991 | default: |
Bryce Harrington | b3197f4 | 2016-08-30 12:05:27 -0700 | [diff] [blame] | 3992 | weston_log("shell: invalid fade type\n"); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3993 | return; |
| 3994 | } |
| 3995 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 3996 | /* Create a separate fade surface for each output */ |
| 3997 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 3998 | shell_output->fade.type = type; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3999 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4000 | if (shell_output->fade.view == NULL) { |
| 4001 | shell_output->fade.view = shell_fade_create_surface_for_output(shell, shell_output); |
| 4002 | if (!shell_output->fade.view) |
| 4003 | continue; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4004 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4005 | shell_output->fade.view->alpha = 1.0 - tint; |
| 4006 | weston_view_update_transform(shell_output->fade.view); |
| 4007 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4008 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4009 | if (shell_output->fade.view->output == NULL) { |
| 4010 | /* If the black view gets a NULL output, we lost the |
| 4011 | * last output and we'll just cancel the fade. This |
| 4012 | * happens when you close the last window under the |
| 4013 | * X11 or Wayland backends. */ |
| 4014 | shell->locked = false; |
| 4015 | weston_surface_destroy(shell_output->fade.view->surface); |
| 4016 | shell_output->fade.view = NULL; |
| 4017 | } else if (shell_output->fade.animation) { |
| 4018 | weston_fade_update(shell_output->fade.animation, tint); |
| 4019 | } else { |
| 4020 | shell_output->fade.animation = |
| 4021 | weston_fade_run(shell_output->fade.view, |
| 4022 | 1.0 - tint, tint, 300.0, |
| 4023 | shell_fade_done_for_output, shell_output); |
| 4024 | } |
Kristian Høgsberg | 87d3b61 | 2014-01-19 21:48:10 -0800 | [diff] [blame] | 4025 | } |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4026 | } |
| 4027 | |
| 4028 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4029 | do_shell_fade_startup(void *data) |
| 4030 | { |
| 4031 | struct desktop_shell *shell = data; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4032 | struct shell_output *shell_output; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4033 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 4034 | if (shell->startup_animation_type == ANIMATION_FADE) { |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4035 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 4036 | } else { |
| 4037 | weston_log("desktop shell: " |
| 4038 | "unexpected fade-in animation type %d\n", |
| 4039 | shell->startup_animation_type); |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4040 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4041 | weston_surface_destroy(shell_output->fade.view->surface); |
| 4042 | shell_output->fade.view = NULL; |
| 4043 | } |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4044 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | static void |
| 4048 | shell_fade_startup(struct desktop_shell *shell) |
| 4049 | { |
| 4050 | struct wl_event_loop *loop; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4051 | struct shell_output *shell_output; |
| 4052 | bool has_fade = false; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4053 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4054 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4055 | if (!shell_output->fade.startup_timer) |
| 4056 | continue; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4057 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4058 | wl_event_source_remove(shell_output->fade.startup_timer); |
| 4059 | shell_output->fade.startup_timer = NULL; |
| 4060 | has_fade = true; |
| 4061 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4062 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4063 | if (has_fade) { |
| 4064 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4065 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4066 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4067 | } |
| 4068 | |
| 4069 | static int |
| 4070 | fade_startup_timeout(void *data) |
| 4071 | { |
| 4072 | struct desktop_shell *shell = data; |
| 4073 | |
| 4074 | shell_fade_startup(shell); |
| 4075 | return 0; |
| 4076 | } |
| 4077 | |
| 4078 | static void |
| 4079 | shell_fade_init(struct desktop_shell *shell) |
| 4080 | { |
| 4081 | /* Make compositor output all black, and wait for the desktop-shell |
| 4082 | * client to signal it is ready, then fade in. The timer triggers a |
| 4083 | * fade-in, in case the desktop-shell client takes too long. |
| 4084 | */ |
| 4085 | |
| 4086 | struct wl_event_loop *loop; |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4087 | struct shell_output *shell_output; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4088 | |
Pekka Paalanen | 23ed5f2 | 2015-05-26 11:54:52 +0300 | [diff] [blame] | 4089 | if (shell->startup_animation_type == ANIMATION_NONE) |
| 4090 | return; |
| 4091 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4092 | wl_list_for_each(shell_output, &shell->output_list, link) { |
| 4093 | if (shell_output->fade.view != NULL) { |
| 4094 | weston_log("%s: warning: fade surface already exists\n", |
| 4095 | __func__); |
| 4096 | continue; |
| 4097 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4098 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4099 | shell_output->fade.view = shell_fade_create_surface_for_output(shell, shell_output); |
| 4100 | if (!shell_output->fade.view) |
| 4101 | continue; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4102 | |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4103 | weston_view_update_transform(shell_output->fade.view); |
| 4104 | weston_surface_damage(shell_output->fade.view->surface); |
| 4105 | |
| 4106 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4107 | shell_output->fade.startup_timer = |
| 4108 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4109 | wl_event_source_timer_update(shell_output->fade.startup_timer, 15000); |
| 4110 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4111 | } |
| 4112 | |
| 4113 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4114 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4115 | { |
| 4116 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4117 | container_of(listener, struct desktop_shell, idle_listener); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4118 | |
Kristian Høgsberg | 27d5fa8 | 2014-01-17 16:22:50 -0800 | [diff] [blame] | 4119 | struct weston_seat *seat; |
| 4120 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4121 | wl_list_for_each(seat, &shell->compositor->seat_list, link) |
| 4122 | weston_seat_break_desktop_grabs(seat); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4123 | |
| 4124 | shell_fade(shell, FADE_OUT); |
Bryce Harrington | 9ad4de1 | 2016-09-09 13:16:02 -0700 | [diff] [blame] | 4125 | /* lock() is called from shell_fade_done_for_output() */ |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4126 | } |
| 4127 | |
| 4128 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4129 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4130 | { |
| 4131 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4132 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4133 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4134 | unlock(shell); |
| 4135 | } |
| 4136 | |
| 4137 | static void |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4138 | transform_handler(struct wl_listener *listener, void *data) |
| 4139 | { |
| 4140 | struct weston_surface *surface = data; |
| 4141 | struct shell_surface *shsurf = get_shell_surface(surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4142 | const struct weston_xwayland_surface_api *api; |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4143 | int x, y; |
| 4144 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4145 | if (!shsurf) |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4146 | return; |
| 4147 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4148 | api = shsurf->shell->xwayland_surface_api; |
| 4149 | if (!api) { |
| 4150 | api = weston_xwayland_surface_get_api(shsurf->shell->compositor); |
| 4151 | shsurf->shell->xwayland_surface_api = api; |
| 4152 | } |
| 4153 | |
| 4154 | if (!api || !api->is_xwayland_surface(surface)) |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4155 | return; |
| 4156 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4157 | if (!weston_view_is_mapped(shsurf->view)) |
| 4158 | return; |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4159 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4160 | x = shsurf->view->geometry.x; |
| 4161 | y = shsurf->view->geometry.y; |
| 4162 | |
| 4163 | api->send_position(surface, x, y); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4167 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4168 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4169 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4170 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4171 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4172 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4173 | |
| 4174 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4175 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4176 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4177 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4178 | } |
| 4179 | |
| 4180 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4181 | weston_view_set_initial_position(struct weston_view *view, |
| 4182 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4183 | { |
| 4184 | struct weston_compositor *compositor = shell->compositor; |
| 4185 | int ix = 0, iy = 0; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4186 | int32_t range_x, range_y; |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4187 | int32_t x, y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4188 | struct weston_output *output, *target_output = NULL; |
| 4189 | struct weston_seat *seat; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4190 | pixman_rectangle32_t area; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4191 | |
| 4192 | /* As a heuristic place the new window on the same output as the |
| 4193 | * pointer. Falling back to the output containing 0, 0. |
| 4194 | * |
| 4195 | * TODO: Do something clever for touch too? |
| 4196 | */ |
| 4197 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 4198 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 4199 | |
| 4200 | if (pointer) { |
| 4201 | ix = wl_fixed_to_int(pointer->x); |
| 4202 | iy = wl_fixed_to_int(pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4203 | break; |
| 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4208 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4209 | target_output = output; |
| 4210 | break; |
| 4211 | } |
| 4212 | } |
| 4213 | |
| 4214 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4215 | weston_view_set_position(view, 10 + random() % 400, |
| 4216 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4217 | return; |
| 4218 | } |
| 4219 | |
| 4220 | /* Valid range within output where the surface will still be onscreen. |
| 4221 | * If this is negative it means that the surface is bigger than |
| 4222 | * output. |
| 4223 | */ |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4224 | get_output_work_area(shell, target_output, &area); |
| 4225 | |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4226 | x = area.x; |
| 4227 | y = area.y; |
Jonny Lamb | d73c694 | 2014-08-20 15:53:20 +0200 | [diff] [blame] | 4228 | range_x = area.width - view->surface->width; |
| 4229 | range_y = area.height - view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4230 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4231 | if (range_x > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4232 | x += random() % range_x; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4233 | |
| 4234 | if (range_y > 0) |
Derek Foreman | f814c5d | 2015-04-15 12:23:54 -0500 | [diff] [blame] | 4235 | y += random() % range_y; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4236 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4237 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4238 | } |
| 4239 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 4240 | static bool |
| 4241 | check_desktop_shell_crash_too_early(struct desktop_shell *shell) |
| 4242 | { |
| 4243 | struct timespec now; |
| 4244 | |
| 4245 | if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) |
| 4246 | return false; |
| 4247 | |
| 4248 | /* |
| 4249 | * If the shell helper client dies before the session has been |
| 4250 | * up for roughly 30 seconds, better just make Weston shut down, |
| 4251 | * because the user likely has no way to interact with the desktop |
| 4252 | * anyway. |
| 4253 | */ |
| 4254 | if (now.tv_sec - shell->startup_time.tv_sec < 30) { |
| 4255 | weston_log("Error: %s apparently cannot run at all.\n", |
| 4256 | shell->client); |
| 4257 | weston_log_continue(STAMP_SPACE "Quitting..."); |
| 4258 | wl_display_terminate(shell->compositor->wl_display); |
| 4259 | |
| 4260 | return true; |
| 4261 | } |
| 4262 | |
| 4263 | return false; |
| 4264 | } |
| 4265 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4266 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4267 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4268 | static void |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4269 | respawn_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4270 | { |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 4271 | struct timespec time; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4272 | |
| 4273 | /* 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] | 4274 | weston_compositor_get_time(&time); |
| 4275 | if (timespec_sub_to_msec(&time, &shell->child.deathstamp) > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4276 | shell->child.deathstamp = time; |
| 4277 | shell->child.deathcount = 0; |
| 4278 | } |
| 4279 | |
| 4280 | shell->child.deathcount++; |
| 4281 | if (shell->child.deathcount > 5) { |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4282 | weston_log("%s disconnected, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4283 | return; |
| 4284 | } |
| 4285 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4286 | weston_log("%s disconnected, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4287 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4288 | } |
| 4289 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4290 | static void |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4291 | desktop_shell_client_destroy(struct wl_listener *listener, void *data) |
| 4292 | { |
| 4293 | struct desktop_shell *shell; |
| 4294 | |
| 4295 | shell = container_of(listener, struct desktop_shell, |
| 4296 | child.client_destroy_listener); |
| 4297 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4298 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4299 | shell->child.client = NULL; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4300 | /* |
| 4301 | * unbind_desktop_shell() will reset shell->child.desktop_shell |
| 4302 | * before the respawned process has a chance to create a new |
| 4303 | * desktop_shell object, because we are being called from the |
| 4304 | * wl_client destructor which destroys all wl_resources before |
| 4305 | * returning. |
| 4306 | */ |
| 4307 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 4308 | if (!check_desktop_shell_crash_too_early(shell)) |
| 4309 | respawn_desktop_shell_process(shell); |
| 4310 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4311 | shell_fade_startup(shell); |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4312 | } |
| 4313 | |
| 4314 | static void |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4315 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4316 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4317 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4318 | |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4319 | shell->child.client = weston_client_start(shell->compositor, |
| 4320 | shell->client); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4321 | |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 4322 | if (!shell->child.client) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4323 | weston_log("not able to start %s\n", shell->client); |
Arnaud Vrac | 4263119 | 2014-08-25 20:56:46 +0200 | [diff] [blame] | 4324 | return; |
| 4325 | } |
Ander Conselvan de Oliveira | 312ea4c | 2013-12-20 21:07:01 +0200 | [diff] [blame] | 4326 | |
| 4327 | shell->child.client_destroy_listener.notify = |
| 4328 | desktop_shell_client_destroy; |
| 4329 | wl_client_add_destroy_listener(shell->child.client, |
| 4330 | &shell->child.client_destroy_listener); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4331 | } |
| 4332 | |
| 4333 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4334 | unbind_desktop_shell(struct wl_resource *resource) |
| 4335 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4336 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4337 | |
| 4338 | if (shell->locked) |
| 4339 | resume_desktop(shell); |
| 4340 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4341 | shell->child.desktop_shell = NULL; |
| 4342 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4343 | } |
| 4344 | |
| 4345 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4346 | bind_desktop_shell(struct wl_client *client, |
| 4347 | void *data, uint32_t version, uint32_t id) |
| 4348 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4349 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4350 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4351 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 4352 | resource = wl_resource_create(client, &weston_desktop_shell_interface, |
| 4353 | 1, id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4354 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4355 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4356 | wl_resource_set_implementation(resource, |
| 4357 | &desktop_shell_implementation, |
| 4358 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4359 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4360 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4361 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4362 | |
| 4363 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4364 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4365 | } |
| 4366 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4367 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4368 | struct desktop_shell *shell; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4369 | struct weston_view *current; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4370 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4371 | struct weston_keyboard_grab grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4372 | struct wl_array minimized_array; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4373 | }; |
| 4374 | |
| 4375 | static void |
| 4376 | switcher_next(struct switcher *switcher) |
| 4377 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4378 | struct weston_view *view; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4379 | struct weston_view *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4380 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4381 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4382 | |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4383 | /* temporary re-display minimized surfaces */ |
| 4384 | struct weston_view *tmp; |
| 4385 | struct weston_view **minimized; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4386 | wl_list_for_each_safe(view, tmp, &switcher->shell->minimized_layer.view_list.link, layer_link.link) { |
| 4387 | weston_layer_entry_remove(&view->layer_link); |
| 4388 | weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4389 | minimized = wl_array_add(&switcher->minimized_array, sizeof *minimized); |
| 4390 | *minimized = view; |
| 4391 | } |
| 4392 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4393 | 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] | 4394 | shsurf = get_shell_surface(view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4395 | if (shsurf) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4396 | if (first == NULL) |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4397 | first = view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4398 | if (prev == switcher->current) |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4399 | next = view; |
| 4400 | prev = view; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4401 | view->alpha = 0.25; |
| 4402 | weston_view_geometry_dirty(view); |
| 4403 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4404 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4405 | |
Jonas Ådahl | 7bfb113 | 2014-10-18 12:23:20 +0200 | [diff] [blame] | 4406 | if (is_black_surface_view(view, NULL)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4407 | view->alpha = 0.25; |
| 4408 | weston_view_geometry_dirty(view); |
| 4409 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4410 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4411 | } |
| 4412 | |
| 4413 | if (next == NULL) |
| 4414 | next = first; |
| 4415 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4416 | if (next == NULL) |
| 4417 | return; |
| 4418 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4419 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4420 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4421 | |
| 4422 | switcher->current = next; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4423 | wl_list_for_each(view, &next->surface->views, surface_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4424 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4425 | |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4426 | shsurf = get_shell_surface(switcher->current->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4427 | if (shsurf && weston_desktop_surface_get_fullscreen(shsurf->desktop_surface)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4428 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4429 | } |
| 4430 | |
| 4431 | static void |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4432 | switcher_handle_view_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4433 | { |
| 4434 | struct switcher *switcher = |
| 4435 | container_of(listener, struct switcher, listener); |
| 4436 | |
| 4437 | switcher_next(switcher); |
| 4438 | } |
| 4439 | |
| 4440 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4441 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4442 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4443 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4444 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4445 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4446 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4447 | 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] | 4448 | if (is_focus_view(view)) |
| 4449 | continue; |
| 4450 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4451 | view->alpha = 1.0; |
| 4452 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4453 | } |
| 4454 | |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 4455 | if (switcher->current) { |
Jonas Ådahl | 1fa6ded | 2014-10-18 13:24:53 +0200 | [diff] [blame] | 4456 | activate(switcher->shell, switcher->current, |
Jonas Ådahl | 4361b4e | 2014-10-18 18:20:16 +0200 | [diff] [blame] | 4457 | keyboard->seat, |
| 4458 | WESTON_ACTIVATE_FLAG_CONFIGURE); |
| 4459 | } |
| 4460 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4461 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4462 | weston_keyboard_end_grab(keyboard); |
| 4463 | if (keyboard->input_method_resource) |
| 4464 | keyboard->grab = &keyboard->input_method_grab; |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4465 | |
| 4466 | /* re-hide surfaces that were temporary shown during the switch */ |
| 4467 | struct weston_view **minimized; |
| 4468 | wl_array_for_each(minimized, &switcher->minimized_array) { |
| 4469 | /* with the exception of the current selected */ |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4470 | if ((*minimized)->surface != switcher->current->surface) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4471 | weston_layer_entry_remove(&(*minimized)->layer_link); |
| 4472 | 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] | 4473 | weston_view_damage_below(*minimized); |
| 4474 | } |
| 4475 | } |
| 4476 | wl_array_release(&switcher->minimized_array); |
| 4477 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4478 | free(switcher); |
| 4479 | } |
| 4480 | |
| 4481 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4482 | switcher_key(struct weston_keyboard_grab *grab, |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4483 | const struct timespec *time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4484 | { |
| 4485 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4486 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4487 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4488 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4489 | switcher_next(switcher); |
| 4490 | } |
| 4491 | |
| 4492 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4493 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4494 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4495 | uint32_t mods_locked, uint32_t group) |
| 4496 | { |
| 4497 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Derek Foreman | 8aeeac8 | 2015-01-30 13:24:36 -0600 | [diff] [blame] | 4498 | struct weston_seat *seat = grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4499 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4500 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 4501 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 4502 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4503 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4504 | static void |
| 4505 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 4506 | { |
| 4507 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 4508 | |
| 4509 | switcher_destroy(switcher); |
| 4510 | } |
| 4511 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4512 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4513 | switcher_key, |
| 4514 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4515 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4516 | }; |
| 4517 | |
| 4518 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4519 | switcher_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4520 | uint32_t key, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4521 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4522 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4523 | struct switcher *switcher; |
| 4524 | |
| 4525 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4526 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4527 | switcher->current = NULL; |
Jonas Ådahl | 90c90b2 | 2014-10-18 13:09:56 +0200 | [diff] [blame] | 4528 | switcher->listener.notify = switcher_handle_view_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4529 | wl_list_init(&switcher->listener.link); |
Manuel Bachmann | c1ae2e8 | 2014-02-26 15:53:11 +0100 | [diff] [blame] | 4530 | wl_array_init(&switcher->minimized_array); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4531 | |
Mario Kleiner | 9f4d655 | 2015-06-21 21:25:08 +0200 | [diff] [blame] | 4532 | lower_fullscreen_layer(switcher->shell, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4533 | switcher->grab.interface = &switcher_grab; |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4534 | weston_keyboard_start_grab(keyboard, &switcher->grab); |
| 4535 | weston_keyboard_set_focus(keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4536 | switcher_next(switcher); |
| 4537 | } |
| 4538 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4539 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4540 | backlight_binding(struct weston_keyboard *keyboard, const struct timespec *time, |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4541 | uint32_t key, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4542 | { |
| 4543 | struct weston_compositor *compositor = data; |
| 4544 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4545 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4546 | |
| 4547 | /* TODO: we're limiting to simple use cases, where we assume just |
| 4548 | * control on the primary display. We'd have to extend later if we |
| 4549 | * ever get support for setting backlights on random desktop LCD |
| 4550 | * panels though */ |
| 4551 | output = get_default_output(compositor); |
| 4552 | if (!output) |
| 4553 | return; |
| 4554 | |
| 4555 | if (!output->set_backlight) |
| 4556 | return; |
| 4557 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4558 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 4559 | backlight_new = output->backlight_current - 25; |
| 4560 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 4561 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4562 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4563 | if (backlight_new < 5) |
| 4564 | backlight_new = 5; |
| 4565 | if (backlight_new > 255) |
| 4566 | backlight_new = 255; |
| 4567 | |
| 4568 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4569 | output->set_backlight(output, output->backlight_current); |
| 4570 | } |
| 4571 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 4572 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4573 | force_kill_binding(struct weston_keyboard *keyboard, |
| 4574 | const struct timespec *time, uint32_t key, void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4575 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 4576 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4577 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 4578 | struct desktop_shell *shell = data; |
| 4579 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4580 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4581 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4582 | focus_surface = keyboard->focus; |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 4583 | if (!focus_surface) |
| 4584 | return; |
| 4585 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 4586 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 4587 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4588 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 4589 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 4590 | |
| 4591 | /* Skip clients that we launched ourselves (the credentials of |
| 4592 | * the socketpair is ours) */ |
| 4593 | if (pid == getpid()) |
| 4594 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4595 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4596 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4600 | workspace_up_binding(struct weston_keyboard *keyboard, |
| 4601 | const struct timespec *time, uint32_t key, void *data) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4602 | { |
| 4603 | struct desktop_shell *shell = data; |
| 4604 | unsigned int new_index = shell->workspaces.current; |
| 4605 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4606 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4607 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4608 | if (new_index != 0) |
| 4609 | new_index--; |
| 4610 | |
| 4611 | change_workspace(shell, new_index); |
| 4612 | } |
| 4613 | |
| 4614 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4615 | workspace_down_binding(struct weston_keyboard *keyboard, |
| 4616 | const struct timespec *time, uint32_t key, void *data) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4617 | { |
| 4618 | struct desktop_shell *shell = data; |
| 4619 | unsigned int new_index = shell->workspaces.current; |
| 4620 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4621 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4622 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4623 | if (new_index < shell->workspaces.num - 1) |
| 4624 | new_index++; |
| 4625 | |
| 4626 | change_workspace(shell, new_index); |
| 4627 | } |
| 4628 | |
| 4629 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4630 | workspace_f_binding(struct weston_keyboard *keyboard, |
| 4631 | const struct timespec *time, uint32_t key, void *data) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4632 | { |
| 4633 | struct desktop_shell *shell = data; |
| 4634 | unsigned int new_index; |
| 4635 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4636 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4637 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4638 | new_index = key - KEY_F1; |
| 4639 | if (new_index >= shell->workspaces.num) |
| 4640 | new_index = shell->workspaces.num - 1; |
| 4641 | |
| 4642 | change_workspace(shell, new_index); |
| 4643 | } |
| 4644 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4645 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4646 | workspace_move_surface_up_binding(struct weston_keyboard *keyboard, |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4647 | const struct timespec *time, uint32_t key, |
| 4648 | void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4649 | { |
| 4650 | struct desktop_shell *shell = data; |
| 4651 | unsigned int new_index = shell->workspaces.current; |
| 4652 | |
| 4653 | if (shell->locked) |
| 4654 | return; |
| 4655 | |
| 4656 | if (new_index != 0) |
| 4657 | new_index--; |
| 4658 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4659 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4663 | workspace_move_surface_down_binding(struct weston_keyboard *keyboard, |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 4664 | const struct timespec *time, uint32_t key, |
| 4665 | void *data) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4666 | { |
| 4667 | struct desktop_shell *shell = data; |
| 4668 | unsigned int new_index = shell->workspaces.current; |
| 4669 | |
| 4670 | if (shell->locked) |
| 4671 | return; |
| 4672 | |
| 4673 | if (new_index < shell->workspaces.num - 1) |
| 4674 | new_index++; |
| 4675 | |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 4676 | take_surface_to_workspace_by_seat(shell, keyboard->seat, new_index); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4677 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4678 | |
| 4679 | static void |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4680 | shell_reposition_view_on_output_destroy(struct weston_view *view) |
| 4681 | { |
| 4682 | struct weston_output *output, *first_output; |
| 4683 | struct weston_compositor *ec = view->surface->compositor; |
| 4684 | struct shell_surface *shsurf; |
| 4685 | float x, y; |
| 4686 | int visible; |
| 4687 | |
| 4688 | x = view->geometry.x; |
| 4689 | y = view->geometry.y; |
| 4690 | |
| 4691 | /* At this point the destroyed output is not in the list anymore. |
| 4692 | * If the view is still visible somewhere, we leave where it is, |
| 4693 | * otherwise, move it to the first output. */ |
| 4694 | visible = 0; |
| 4695 | wl_list_for_each(output, &ec->output_list, link) { |
| 4696 | if (pixman_region32_contains_point(&output->region, |
| 4697 | x, y, NULL)) { |
| 4698 | visible = 1; |
| 4699 | break; |
| 4700 | } |
| 4701 | } |
| 4702 | |
| 4703 | if (!visible) { |
| 4704 | first_output = container_of(ec->output_list.next, |
| 4705 | struct weston_output, link); |
| 4706 | |
| 4707 | x = first_output->x + first_output->width / 4; |
| 4708 | y = first_output->y + first_output->height / 4; |
Xiong Zhang | 62899f5 | 2014-03-07 16:27:19 +0800 | [diff] [blame] | 4709 | |
| 4710 | weston_view_set_position(view, x, y); |
| 4711 | } else { |
| 4712 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4713 | } |
| 4714 | |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4715 | |
| 4716 | shsurf = get_shell_surface(view->surface); |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4717 | if (!shsurf) |
| 4718 | return; |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4719 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 4720 | shsurf->saved_position_valid = false; |
| 4721 | set_maximized(shsurf, false); |
| 4722 | set_fullscreen(shsurf, false, NULL); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4723 | } |
| 4724 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4725 | void |
| 4726 | shell_for_each_layer(struct desktop_shell *shell, |
| 4727 | shell_for_each_layer_func_t func, void *data) |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4728 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4729 | struct workspace **ws; |
| 4730 | |
| 4731 | func(shell, &shell->fullscreen_layer, data); |
| 4732 | func(shell, &shell->panel_layer, data); |
| 4733 | func(shell, &shell->background_layer, data); |
| 4734 | func(shell, &shell->lock_layer, data); |
| 4735 | func(shell, &shell->input_panel_layer, data); |
| 4736 | |
| 4737 | wl_array_for_each(ws, &shell->workspaces.array) |
| 4738 | func(shell, &(*ws)->layer, data); |
| 4739 | } |
| 4740 | |
| 4741 | static void |
| 4742 | shell_output_destroy_move_layer(struct desktop_shell *shell, |
| 4743 | struct weston_layer *layer, |
| 4744 | void *data) |
| 4745 | { |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4746 | struct weston_view *view; |
| 4747 | |
Marius Vlad | ea40d6d | 2018-02-08 18:46:42 +0200 | [diff] [blame] | 4748 | 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] | 4749 | shell_reposition_view_on_output_destroy(view); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4753 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 4754 | { |
| 4755 | struct shell_output *output_listener = |
| 4756 | container_of(listener, struct shell_output, destroy_listener); |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4757 | struct desktop_shell *shell = output_listener->shell; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4758 | |
Pekka Paalanen | 9350bfd | 2018-02-13 16:18:05 +0200 | [diff] [blame] | 4759 | shell_for_each_layer(shell, shell_output_destroy_move_layer, NULL); |
Ander Conselvan de Oliveira | c94d622 | 2014-01-29 18:47:54 +0200 | [diff] [blame] | 4760 | |
Tomohito Esaki | bf31f6c | 2018-01-31 15:15:45 +0900 | [diff] [blame] | 4761 | if (output_listener->panel_surface) |
| 4762 | wl_list_remove(&output_listener->panel_surface_listener.link); |
| 4763 | if (output_listener->background_surface) |
| 4764 | wl_list_remove(&output_listener->background_surface_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4765 | wl_list_remove(&output_listener->destroy_listener.link); |
| 4766 | wl_list_remove(&output_listener->link); |
| 4767 | free(output_listener); |
| 4768 | } |
| 4769 | |
| 4770 | static void |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4771 | shell_resize_surface_to_output(struct desktop_shell *shell, |
| 4772 | struct weston_surface *surface, |
| 4773 | const struct weston_output *output) |
| 4774 | { |
| 4775 | if (!surface) |
| 4776 | return; |
| 4777 | |
| 4778 | weston_desktop_shell_send_configure(shell->child.desktop_shell, 0, |
| 4779 | surface->resource, |
| 4780 | output->width, |
| 4781 | output->height); |
| 4782 | } |
| 4783 | |
| 4784 | |
| 4785 | static void |
| 4786 | handle_output_resized(struct wl_listener *listener, void *data) |
| 4787 | { |
| 4788 | struct desktop_shell *shell = |
| 4789 | container_of(listener, struct desktop_shell, resized_listener); |
| 4790 | struct weston_output *output = (struct weston_output *)data; |
| 4791 | struct shell_output *sh_output = find_shell_output_from_weston_output(shell, output); |
| 4792 | |
| 4793 | shell_resize_surface_to_output(shell, sh_output->background_surface, output); |
| 4794 | shell_resize_surface_to_output(shell, sh_output->panel_surface, output); |
| 4795 | } |
| 4796 | |
| 4797 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4798 | create_shell_output(struct desktop_shell *shell, |
| 4799 | struct weston_output *output) |
| 4800 | { |
| 4801 | struct shell_output *shell_output; |
| 4802 | |
| 4803 | shell_output = zalloc(sizeof *shell_output); |
| 4804 | if (shell_output == NULL) |
| 4805 | return; |
| 4806 | |
| 4807 | shell_output->output = output; |
| 4808 | shell_output->shell = shell; |
| 4809 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 4810 | wl_signal_add(&output->destroy_signal, |
| 4811 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 4812 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4813 | } |
| 4814 | |
| 4815 | static void |
| 4816 | handle_output_create(struct wl_listener *listener, void *data) |
| 4817 | { |
| 4818 | struct desktop_shell *shell = |
| 4819 | container_of(listener, struct desktop_shell, output_create_listener); |
| 4820 | struct weston_output *output = (struct weston_output *)data; |
| 4821 | |
| 4822 | create_shell_output(shell, output); |
| 4823 | } |
| 4824 | |
| 4825 | static void |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4826 | handle_output_move_layer(struct desktop_shell *shell, |
| 4827 | struct weston_layer *layer, void *data) |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4828 | { |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4829 | struct weston_output *output = data; |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4830 | struct weston_view *view; |
| 4831 | float x, y; |
| 4832 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 4833 | 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] | 4834 | if (view->output != output) |
| 4835 | continue; |
| 4836 | |
| 4837 | x = view->geometry.x + output->move_x; |
| 4838 | y = view->geometry.y + output->move_y; |
| 4839 | weston_view_set_position(view, x, y); |
| 4840 | } |
| 4841 | } |
| 4842 | |
| 4843 | static void |
| 4844 | handle_output_move(struct wl_listener *listener, void *data) |
| 4845 | { |
| 4846 | struct desktop_shell *shell; |
| 4847 | |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4848 | shell = container_of(listener, struct desktop_shell, |
| 4849 | output_move_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4850 | |
Ander Conselvan de Oliveira | 304996d | 2014-04-11 13:57:15 +0300 | [diff] [blame] | 4851 | shell_for_each_layer(shell, handle_output_move_layer, data); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4852 | } |
| 4853 | |
| 4854 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4855 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 4856 | struct desktop_shell *shell) |
| 4857 | { |
| 4858 | struct weston_output *output; |
| 4859 | |
| 4860 | wl_list_init(&shell->output_list); |
| 4861 | wl_list_for_each(output, &ec->output_list, link) |
| 4862 | create_shell_output(shell, output); |
| 4863 | |
| 4864 | shell->output_create_listener.notify = handle_output_create; |
| 4865 | wl_signal_add(&ec->output_created_signal, |
| 4866 | &shell->output_create_listener); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4867 | |
| 4868 | shell->output_move_listener.notify = handle_output_move; |
| 4869 | wl_signal_add(&ec->output_moved_signal, &shell->output_move_listener); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4870 | } |
| 4871 | |
| 4872 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4873 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4874 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4875 | struct desktop_shell *shell = |
| 4876 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4877 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4878 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4879 | |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 4880 | /* Force state to unlocked so we don't try to fade */ |
| 4881 | shell->locked = false; |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4882 | |
| 4883 | if (shell->child.client) { |
| 4884 | /* disable respawn */ |
| 4885 | wl_list_remove(&shell->child.client_destroy_listener.link); |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 4886 | wl_client_destroy(shell->child.client); |
Pekka Paalanen | 826dc14 | 2014-08-27 12:11:53 +0300 | [diff] [blame] | 4887 | } |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 4888 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4889 | wl_list_remove(&shell->idle_listener.link); |
| 4890 | wl_list_remove(&shell->wake_listener.link); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 4891 | wl_list_remove(&shell->transform_listener.link); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 4892 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 4893 | text_backend_destroy(shell->text_backend); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 4894 | input_panel_destroy(shell); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 4895 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4896 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 4897 | wl_list_remove(&shell_output->destroy_listener.link); |
| 4898 | wl_list_remove(&shell_output->link); |
| 4899 | free(shell_output); |
| 4900 | } |
| 4901 | |
| 4902 | wl_list_remove(&shell->output_create_listener.link); |
Kristian Høgsberg | 6d50b0f | 2014-04-30 20:46:25 -0700 | [diff] [blame] | 4903 | wl_list_remove(&shell->output_move_listener.link); |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 4904 | wl_list_remove(&shell->resized_listener.link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 4905 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4906 | wl_array_for_each(ws, &shell->workspaces.array) |
| 4907 | workspace_destroy(*ws); |
| 4908 | wl_array_release(&shell->workspaces.array); |
| 4909 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4910 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4911 | free(shell); |
| 4912 | } |
| 4913 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4914 | static void |
| 4915 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 4916 | { |
| 4917 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4918 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4919 | |
Bob Ham | 744e653 | 2016-01-12 10:21:48 +0000 | [diff] [blame] | 4920 | if (shell->allow_zap) |
| 4921 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 4922 | MODIFIER_CTRL | MODIFIER_ALT, |
| 4923 | terminate_binding, ec); |
| 4924 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4925 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4926 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 4927 | click_to_activate_binding, |
| 4928 | shell); |
Kristian Høgsberg | f0ce581 | 2014-04-07 11:52:17 -0700 | [diff] [blame] | 4929 | weston_compositor_add_button_binding(ec, BTN_RIGHT, 0, |
| 4930 | click_to_activate_binding, |
| 4931 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4932 | weston_compositor_add_touch_binding(ec, 0, |
| 4933 | touch_to_activate_binding, |
| 4934 | shell); |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 4935 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 4936 | backlight_binding, ec); |
| 4937 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 4938 | backlight_binding, ec); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4939 | |
| 4940 | /* configurable bindings */ |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 4941 | if (shell->exposay_modifier) |
| 4942 | weston_compositor_add_modifier_binding(ec, shell->exposay_modifier, |
| 4943 | exposay_binding, shell); |
| 4944 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4945 | mod = shell->binding_modifier; |
Bob Ham | 553d124 | 2016-01-12 10:21:49 +0000 | [diff] [blame] | 4946 | if (!mod) |
| 4947 | return; |
| 4948 | |
Ian Ray | 13404c4 | 2017-09-18 15:22:01 +0300 | [diff] [blame] | 4949 | /* This binding is not configurable, but is only enabled if there is a |
| 4950 | * valid binding modifier. */ |
| 4951 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 4952 | MODIFIER_SUPER | MODIFIER_ALT, |
| 4953 | surface_opacity_binding, NULL); |
| 4954 | |
Ian Ray | ab7c0b6 | 2017-09-18 15:22:00 +0300 | [diff] [blame] | 4955 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 4956 | mod, zoom_axis_binding, |
| 4957 | NULL); |
| 4958 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4959 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 4960 | zoom_key_binding, NULL); |
| 4961 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 4962 | zoom_key_binding, NULL); |
Kristian Høgsberg | 211b517 | 2014-01-11 13:10:21 -0800 | [diff] [blame] | 4963 | weston_compositor_add_key_binding(ec, KEY_M, mod | MODIFIER_SHIFT, |
| 4964 | maximize_binding, NULL); |
| 4965 | weston_compositor_add_key_binding(ec, KEY_F, mod | MODIFIER_SHIFT, |
| 4966 | fullscreen_binding, NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4967 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 4968 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4969 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 4970 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4971 | resize_binding, shell); |
Kristian Høgsberg | 0837fa9 | 2014-01-20 10:35:26 -0800 | [diff] [blame] | 4972 | weston_compositor_add_button_binding(ec, BTN_LEFT, |
| 4973 | mod | MODIFIER_SHIFT, |
| 4974 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 4975 | |
| 4976 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
Derek Foreman | 2217f3f | 2015-06-25 16:03:30 -0500 | [diff] [blame] | 4977 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 4978 | rotate_binding, NULL); |
| 4979 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4980 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 4981 | shell); |
| 4982 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 4983 | ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4984 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 4985 | ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4986 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 4987 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4988 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 4989 | workspace_up_binding, shell); |
| 4990 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 4991 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4992 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 4993 | workspace_move_surface_up_binding, |
| 4994 | shell); |
| 4995 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 4996 | workspace_move_surface_down_binding, |
| 4997 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4998 | |
| 4999 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5000 | if (shell->workspaces.num > 1) { |
| 5001 | num_workspace_bindings = shell->workspaces.num; |
| 5002 | if (num_workspace_bindings > 6) |
| 5003 | num_workspace_bindings = 6; |
| 5004 | for (i = 0; i < num_workspace_bindings; i++) |
| 5005 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5006 | workspace_f_binding, |
| 5007 | shell); |
| 5008 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5009 | |
Pekka Paalanen | 2829f7c | 2015-02-19 17:02:13 +0200 | [diff] [blame] | 5010 | weston_install_debug_key_binding(ec, mod); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5011 | } |
| 5012 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 5013 | static void |
| 5014 | handle_seat_created(struct wl_listener *listener, void *data) |
| 5015 | { |
| 5016 | struct weston_seat *seat = data; |
| 5017 | |
| 5018 | create_shell_seat(seat); |
| 5019 | } |
| 5020 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5021 | WL_EXPORT int |
Quentin Glidic | da01c1d | 2016-12-02 14:17:08 +0100 | [diff] [blame] | 5022 | wet_shell_init(struct weston_compositor *ec, |
| 5023 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5024 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5025 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5026 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5027 | struct workspace **pws; |
| 5028 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5029 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5030 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 5031 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5032 | if (shell == NULL) |
| 5033 | return -1; |
| 5034 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5035 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5036 | |
| 5037 | shell->destroy_listener.notify = shell_destroy; |
| 5038 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5039 | shell->idle_listener.notify = idle_handler; |
| 5040 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 5041 | shell->wake_listener.notify = wake_handler; |
| 5042 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Giulio Camuffo | f05d18f | 2015-12-11 20:57:05 +0200 | [diff] [blame] | 5043 | shell->transform_listener.notify = transform_handler; |
| 5044 | wl_signal_add(&ec->transform_signal, &shell->transform_listener); |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5045 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 5046 | weston_layer_init(&shell->fullscreen_layer, ec); |
| 5047 | weston_layer_init(&shell->panel_layer, ec); |
| 5048 | weston_layer_init(&shell->background_layer, ec); |
| 5049 | weston_layer_init(&shell->lock_layer, ec); |
| 5050 | weston_layer_init(&shell->input_panel_layer, ec); |
| 5051 | |
| 5052 | weston_layer_set_position(&shell->fullscreen_layer, |
| 5053 | WESTON_LAYER_POSITION_FULLSCREEN); |
| 5054 | weston_layer_set_position(&shell->panel_layer, |
| 5055 | WESTON_LAYER_POSITION_UI); |
| 5056 | weston_layer_set_position(&shell->background_layer, |
| 5057 | WESTON_LAYER_POSITION_BACKGROUND); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5058 | |
| 5059 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5060 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5061 | |
Kristian Høgsberg | 677a5f5 | 2013-12-04 11:00:19 -0800 | [diff] [blame] | 5062 | if (input_panel_setup(shell) < 0) |
| 5063 | return -1; |
| 5064 | |
Pekka Paalanen | aa9536a | 2015-06-24 16:09:17 +0300 | [diff] [blame] | 5065 | shell->text_backend = text_backend_init(ec); |
| 5066 | if (!shell->text_backend) |
Murray Calavera | 9a51cd7 | 2015-06-10 21:16:02 +0000 | [diff] [blame] | 5067 | return -1; |
| 5068 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5069 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 5070 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5071 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 5072 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 5073 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5074 | for (i = 0; i < shell->workspaces.num; i++) { |
| 5075 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 5076 | if (pws == NULL) |
| 5077 | return -1; |
| 5078 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 5079 | *pws = workspace_create(shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5080 | if (*pws == NULL) |
| 5081 | return -1; |
| 5082 | } |
| 5083 | activate_workspace(shell, 0); |
| 5084 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 5085 | weston_layer_init(&shell->minimized_layer, ec); |
Manuel Bachmann | 50c87db | 2014-02-26 15:52:13 +0100 | [diff] [blame] | 5086 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5087 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 5088 | wl_list_init(&shell->workspaces.animation.link); |
| 5089 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 5090 | |
Quentin Glidic | 8f9d90a | 2016-08-12 10:41:36 +0200 | [diff] [blame] | 5091 | shell->desktop = weston_desktop_create(ec, &shell_desktop_api, shell); |
| 5092 | if (!shell->desktop) |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5093 | return -1; |
| 5094 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5095 | if (wl_global_create(ec->wl_display, |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5096 | &weston_desktop_shell_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5097 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5098 | return -1; |
| 5099 | |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 5100 | weston_compositor_get_time(&shell->child.deathstamp); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5101 | |
Jonas Ådahl | 6d6fb61 | 2015-11-17 16:00:33 +0800 | [diff] [blame] | 5102 | shell->panel_position = WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP; |
Jonny Lamb | 765760d | 2014-08-20 15:53:19 +0200 | [diff] [blame] | 5103 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5104 | setup_output_destroy_handler(ec, shell); |
| 5105 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5106 | loop = wl_display_get_event_loop(ec->wl_display); |
| 5107 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5108 | |
Jason Ekstrand | 024177c | 2014-04-21 19:42:58 -0500 | [diff] [blame] | 5109 | wl_list_for_each(seat, &ec->seat_list, link) |
| 5110 | handle_seat_created(NULL, seat); |
| 5111 | shell->seat_create_listener.notify = handle_seat_created; |
| 5112 | wl_signal_add(&ec->seat_created_signal, &shell->seat_create_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 5113 | |
David Fort | 50d962f | 2016-06-09 17:55:52 +0200 | [diff] [blame] | 5114 | shell->resized_listener.notify = handle_output_resized; |
| 5115 | wl_signal_add(&ec->output_resized_signal, &shell->resized_listener); |
| 5116 | |
Giulio Camuffo | c6ab3d5 | 2013-12-11 23:45:12 +0100 | [diff] [blame] | 5117 | screenshooter_create(ec); |
| 5118 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5119 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5120 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5121 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5122 | |
Pekka Paalanen | 2e62e4a | 2014-08-28 11:41:26 +0300 | [diff] [blame] | 5123 | clock_gettime(CLOCK_MONOTONIC, &shell->startup_time); |
| 5124 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5125 | return 0; |
| 5126 | } |