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