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