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