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