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. |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 4 | * |
| 5 | * Permission to use, copy, modify, distribute, and sell this software and |
| 6 | * its documentation for any purpose is hereby granted without fee, provided |
| 7 | * that the above copyright notice appear in all copies and that both that |
| 8 | * copyright notice and this permission notice appear in supporting |
| 9 | * documentation, and that the name of the copyright holders not be used in |
| 10 | * advertising or publicity pertaining to distribution of the software |
| 11 | * without specific, written prior permission. The copyright holders make |
| 12 | * no representations about the suitability of this software for any |
| 13 | * purpose. It is provided "as is" without express or implied warranty. |
| 14 | * |
| 15 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 16 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 18 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 19 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 20 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 21 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 25 | #include <stdio.h> |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 26 | #include <stdbool.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 27 | #include <string.h> |
| 28 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 29 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 30 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 31 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 32 | #include <math.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 33 | |
Pekka Paalanen | 50719bc | 2011-11-22 14:18:50 +0200 | [diff] [blame] | 34 | #include <wayland-server.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 35 | #include "compositor.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 36 | #include "desktop-shell-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 37 | #include "../shared/config-parser.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 38 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 39 | struct shell_surface; |
| 40 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 41 | struct wl_shell { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 42 | struct weston_compositor *compositor; |
| 43 | struct weston_shell shell; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 44 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 45 | struct weston_layer fullscreen_layer; |
| 46 | struct weston_layer panel_layer; |
| 47 | struct weston_layer toplevel_layer; |
| 48 | struct weston_layer background_layer; |
| 49 | struct weston_layer lock_layer; |
| 50 | |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 51 | struct { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 52 | struct weston_process process; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 53 | struct wl_client *client; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 54 | struct wl_resource *desktop_shell; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 55 | |
| 56 | unsigned deathcount; |
| 57 | uint32_t deathstamp; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 58 | } child; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 59 | |
| 60 | bool locked; |
| 61 | bool prepare_event_sent; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 62 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 63 | struct shell_surface *lock_surface; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 64 | struct wl_listener lock_surface_listener; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 65 | |
| 66 | struct wl_list backgrounds; |
| 67 | struct wl_list panels; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 68 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 69 | struct { |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 70 | char *path; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 71 | int duration; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 72 | struct wl_resource *binding; |
| 73 | struct wl_list surfaces; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 74 | struct weston_process process; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 75 | } screensaver; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 76 | |
| 77 | struct weston_surface *debug_repaint_surface; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 78 | }; |
| 79 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 80 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 81 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 82 | |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 83 | SHELL_SURFACE_PANEL, |
| 84 | SHELL_SURFACE_BACKGROUND, |
| 85 | SHELL_SURFACE_LOCK, |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 86 | SHELL_SURFACE_SCREENSAVER, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 87 | |
| 88 | SHELL_SURFACE_TOPLEVEL, |
| 89 | SHELL_SURFACE_TRANSIENT, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 90 | SHELL_SURFACE_FULLSCREEN, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 91 | SHELL_SURFACE_MAXIMIZED, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 92 | SHELL_SURFACE_POPUP |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 93 | }; |
| 94 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 95 | struct shell_surface { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 96 | struct wl_resource resource; |
| 97 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 98 | struct weston_surface *surface; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 99 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 100 | struct shell_surface *parent; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 101 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 102 | enum shell_surface_type type; |
| 103 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 104 | bool saved_position_valid; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 105 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 106 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 107 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 108 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 109 | } rotation; |
| 110 | |
| 111 | struct { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 112 | struct wl_pointer_grab grab; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 113 | uint32_t time; |
| 114 | int32_t x, y; |
Pekka Paalanen | 938269a | 2012-02-07 14:19:01 +0200 | [diff] [blame] | 115 | struct weston_transform parent_transform; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 116 | int32_t initial_up; |
| 117 | } popup; |
| 118 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 119 | struct { |
| 120 | enum wl_shell_surface_fullscreen_method type; |
| 121 | struct weston_transform transform; /* matrix from x, y */ |
| 122 | uint32_t framerate; |
| 123 | struct weston_surface *black_surface; |
| 124 | } fullscreen; |
| 125 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 126 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 127 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 128 | struct wl_list link; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 129 | }; |
| 130 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 131 | struct weston_move_grab { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 132 | struct wl_pointer_grab grab; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 133 | struct weston_surface *surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 134 | int32_t dx, dy; |
| 135 | }; |
| 136 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 137 | struct rotate_grab { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 138 | struct wl_pointer_grab grab; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 139 | struct shell_surface *surface; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 140 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 141 | struct { |
| 142 | int32_t x; |
| 143 | int32_t y; |
| 144 | } center; |
| 145 | }; |
| 146 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 147 | static void |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 148 | center_on_output(struct weston_surface *surface, |
| 149 | struct weston_output *output); |
| 150 | |
| 151 | static void |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 152 | shell_configuration(struct wl_shell *shell) |
| 153 | { |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 154 | char *config_file; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 155 | char *path = NULL; |
| 156 | int duration = 60; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 157 | |
| 158 | struct config_key saver_keys[] = { |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 159 | { "path", CONFIG_KEY_STRING, &path }, |
| 160 | { "duration", CONFIG_KEY_INTEGER, &duration }, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | struct config_section cs[] = { |
| 164 | { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL }, |
| 165 | }; |
| 166 | |
Kristian Høgsberg | 9724b51 | 2012-01-03 14:35:49 -0500 | [diff] [blame] | 167 | config_file = config_file_path("weston-desktop-shell.ini"); |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 168 | parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 169 | free(config_file); |
| 170 | |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 171 | shell->screensaver.path = path; |
| 172 | shell->screensaver.duration = duration; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 173 | } |
| 174 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 175 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 176 | noop_grab_focus(struct wl_pointer_grab *grab, uint32_t time, |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 177 | struct wl_surface *surface, int32_t x, int32_t y) |
| 178 | { |
| 179 | grab->focus = NULL; |
| 180 | } |
| 181 | |
| 182 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 183 | move_grab_motion(struct wl_pointer_grab *grab, |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 184 | uint32_t time, int32_t x, int32_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 185 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 186 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 187 | struct wl_input_device *device = grab->input_device; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 188 | struct weston_surface *es = move->surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 189 | |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 190 | weston_surface_configure(es, |
| 191 | device->x + move->dx, |
| 192 | device->y + move->dy, |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 193 | es->geometry.width, es->geometry.height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 197 | move_grab_button(struct wl_pointer_grab *grab, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 198 | uint32_t time, int32_t button, int32_t state) |
| 199 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 200 | struct wl_input_device *device = grab->input_device; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 201 | |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 202 | if (device->button_count == 0 && state == 0) { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 203 | wl_input_device_end_pointer_grab(device, time); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 204 | free(grab); |
| 205 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 206 | } |
| 207 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 208 | static const struct wl_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 209 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 210 | move_grab_motion, |
| 211 | move_grab_button, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 212 | }; |
| 213 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 214 | static int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 215 | weston_surface_move(struct weston_surface *es, |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 216 | struct weston_input_device *wd, uint32_t time) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 217 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 218 | struct weston_move_grab *move; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 219 | |
| 220 | move = malloc(sizeof *move); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 221 | if (!move) |
| 222 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 223 | |
| 224 | move->grab.interface = &move_grab_interface; |
Pekka Paalanen | ba3cf95 | 2012-01-25 16:22:05 +0200 | [diff] [blame] | 225 | move->dx = es->geometry.x - wd->input_device.grab_x; |
| 226 | move->dy = es->geometry.y - wd->input_device.grab_y; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 227 | move->surface = es; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 228 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 229 | wl_input_device_start_pointer_grab(&wd->input_device, &move->grab, time); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 230 | |
Pekka Paalanen | b29f412 | 2012-02-14 14:59:18 +0200 | [diff] [blame] | 231 | wl_input_device_set_pointer_focus(&wd->input_device, NULL, time, 0, 0); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 232 | |
| 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 237 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 238 | struct wl_resource *input_resource, uint32_t time) |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 239 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 240 | struct weston_input_device *wd = input_resource->data; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 241 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 242 | |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 243 | if (wd->input_device.button_count == 0 || |
| 244 | wd->input_device.grab_time != time || |
| 245 | wd->input_device.pointer_focus != &shsurf->surface->surface) |
| 246 | return; |
| 247 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 248 | if (weston_surface_move(shsurf->surface, wd, time) < 0) |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 249 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 250 | } |
| 251 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 252 | struct weston_resize_grab { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 253 | struct wl_pointer_grab grab; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 254 | uint32_t edges; |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 255 | int32_t width, height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 256 | struct shell_surface *shsurf; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 257 | }; |
| 258 | |
| 259 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 260 | resize_grab_motion(struct wl_pointer_grab *grab, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 261 | uint32_t time, int32_t x, int32_t y) |
| 262 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 263 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 264 | struct wl_input_device *device = grab->input_device; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 265 | int32_t width, height; |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 266 | int32_t from_x, from_y; |
| 267 | int32_t to_x, to_y; |
| 268 | |
| 269 | weston_surface_from_global(resize->shsurf->surface, |
| 270 | device->grab_x, device->grab_y, |
| 271 | &from_x, &from_y); |
| 272 | weston_surface_from_global(resize->shsurf->surface, |
| 273 | device->x, device->y, &to_x, &to_y); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 274 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 275 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 276 | width = resize->width + from_x - to_x; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 277 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 278 | width = resize->width + to_x - from_x; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 279 | } else { |
| 280 | width = resize->width; |
| 281 | } |
| 282 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 283 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 284 | height = resize->height + from_y - to_y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 285 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 286 | height = resize->height + to_y - from_y; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 287 | } else { |
| 288 | height = resize->height; |
| 289 | } |
| 290 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 291 | wl_shell_surface_send_configure(&resize->shsurf->resource, |
| 292 | time, resize->edges, width, height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 296 | resize_grab_button(struct wl_pointer_grab *grab, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 297 | uint32_t time, int32_t button, int32_t state) |
| 298 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 299 | struct wl_input_device *device = grab->input_device; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 300 | |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 301 | if (device->button_count == 0 && state == 0) { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 302 | wl_input_device_end_pointer_grab(device, time); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 303 | free(grab); |
| 304 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 305 | } |
| 306 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 307 | static const struct wl_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 308 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 309 | resize_grab_motion, |
| 310 | resize_grab_button, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 311 | }; |
| 312 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 313 | static int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 314 | weston_surface_resize(struct shell_surface *shsurf, |
| 315 | struct weston_input_device *wd, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 316 | uint32_t time, uint32_t edges) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 317 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 318 | struct weston_resize_grab *resize; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 319 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 320 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 321 | return 0; |
Kristian Høgsberg | 0ce2457 | 2011-01-28 15:18:33 -0500 | [diff] [blame] | 322 | |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 323 | if (edges == 0 || edges > 15 || |
| 324 | (edges & 3) == 3 || (edges & 12) == 12) |
| 325 | return 0; |
| 326 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 327 | resize = malloc(sizeof *resize); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 328 | if (!resize) |
| 329 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 330 | |
| 331 | resize->grab.interface = &resize_grab_interface; |
| 332 | resize->edges = edges; |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 333 | resize->width = shsurf->surface->geometry.width; |
| 334 | resize->height = shsurf->surface->geometry.height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 335 | resize->shsurf = shsurf; |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 336 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 337 | wl_input_device_start_pointer_grab(&wd->input_device, &resize->grab, time); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 338 | |
Pekka Paalanen | b29f412 | 2012-02-14 14:59:18 +0200 | [diff] [blame] | 339 | wl_input_device_set_pointer_focus(&wd->input_device, NULL, time, 0, 0); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 340 | |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 345 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 346 | struct wl_resource *input_resource, uint32_t time, |
| 347 | uint32_t edges) |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 348 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 349 | struct weston_input_device *wd = input_resource->data; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 350 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 351 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 352 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 353 | return; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 354 | |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 355 | if (wd->input_device.button_count == 0 || |
| 356 | wd->input_device.grab_time != time || |
| 357 | wd->input_device.pointer_focus != &shsurf->surface->surface) |
| 358 | return; |
| 359 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 360 | if (weston_surface_resize(shsurf, wd, time, edges) < 0) |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 361 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 362 | } |
| 363 | |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 364 | static struct weston_output * |
| 365 | get_default_output(struct weston_compositor *compositor) |
| 366 | { |
| 367 | return container_of(compositor->output_list.next, |
| 368 | struct weston_output, link); |
| 369 | } |
| 370 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 371 | static void |
| 372 | shell_unset_fullscreen(struct shell_surface *shsurf) |
| 373 | { |
| 374 | /* undo all fullscreen things here */ |
| 375 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 376 | shsurf->fullscreen.framerate = 0; |
| 377 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 378 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 379 | weston_surface_destroy(shsurf->fullscreen.black_surface); |
| 380 | shsurf->fullscreen.black_surface = NULL; |
| 381 | shsurf->fullscreen_output = NULL; |
| 382 | shsurf->surface->force_configure = 1; |
| 383 | weston_surface_set_position(shsurf->surface, |
| 384 | shsurf->saved_x, shsurf->saved_y); |
| 385 | } |
| 386 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 387 | static int |
| 388 | reset_shell_surface_type(struct shell_surface *surface) |
| 389 | { |
| 390 | switch (surface->type) { |
| 391 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 392 | shell_unset_fullscreen(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 393 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 394 | case SHELL_SURFACE_MAXIMIZED: |
| 395 | surface->output = get_default_output(surface->surface->compositor); |
| 396 | weston_surface_set_position(surface->surface, |
| 397 | surface->saved_x, |
| 398 | surface->saved_y); |
| 399 | break; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 400 | case SHELL_SURFACE_PANEL: |
| 401 | case SHELL_SURFACE_BACKGROUND: |
| 402 | wl_list_remove(&surface->link); |
| 403 | wl_list_init(&surface->link); |
| 404 | break; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 405 | case SHELL_SURFACE_SCREENSAVER: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 406 | case SHELL_SURFACE_LOCK: |
| 407 | wl_resource_post_error(&surface->resource, |
| 408 | WL_DISPLAY_ERROR_INVALID_METHOD, |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 409 | "cannot reassign surface type"); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 410 | return -1; |
| 411 | case SHELL_SURFACE_NONE: |
| 412 | case SHELL_SURFACE_TOPLEVEL: |
| 413 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 414 | case SHELL_SURFACE_POPUP: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 415 | break; |
| 416 | } |
| 417 | |
| 418 | surface->type = SHELL_SURFACE_NONE; |
| 419 | return 0; |
| 420 | } |
| 421 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 422 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 423 | shell_surface_set_toplevel(struct wl_client *client, |
| 424 | struct wl_resource *resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 425 | |
| 426 | { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 427 | struct shell_surface *surface = resource->data; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 428 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 429 | if (reset_shell_surface_type(surface)) |
| 430 | return; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 431 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 432 | surface->type = SHELL_SURFACE_TOPLEVEL; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 436 | shell_surface_set_transient(struct wl_client *client, |
| 437 | struct wl_resource *resource, |
| 438 | struct wl_resource *parent_resource, |
| 439 | int x, int y, uint32_t flags) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 440 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 441 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 442 | struct weston_surface *es = shsurf->surface; |
Pekka Paalanen | 01e7b00 | 2011-12-08 16:42:33 +0200 | [diff] [blame] | 443 | struct shell_surface *pshsurf = parent_resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 444 | struct weston_surface *pes = pshsurf->surface; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 445 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 446 | if (reset_shell_surface_type(shsurf)) |
| 447 | return; |
| 448 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 449 | /* assign to parents output */ |
Alex Wu | 88277d1 | 2012-02-22 14:50:46 +0800 | [diff] [blame] | 450 | shsurf->output = pes->output; |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 451 | weston_surface_set_position(es, pes->geometry.x + x, |
| 452 | pes->geometry.y + y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 453 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 454 | shsurf->type = SHELL_SURFACE_TRANSIENT; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 455 | } |
| 456 | |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 457 | static struct wl_shell * |
| 458 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 459 | { |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 460 | struct weston_surface *es = shsurf->surface; |
| 461 | struct weston_shell *shell = es->compositor->shell; |
| 462 | |
| 463 | return (struct wl_shell *)container_of(shell, struct wl_shell, shell); |
| 464 | } |
| 465 | |
| 466 | static int |
| 467 | get_output_panel_height(struct wl_shell *wlshell,struct weston_output *output) |
| 468 | { |
| 469 | struct shell_surface *priv; |
| 470 | int panel_height = 0; |
| 471 | |
| 472 | if (!output) |
| 473 | return 0; |
| 474 | |
| 475 | wl_list_for_each(priv, &wlshell->panels, link) { |
| 476 | if (priv->output == output) { |
| 477 | panel_height = priv->surface->geometry.height; |
| 478 | break; |
| 479 | } |
| 480 | } |
| 481 | return panel_height; |
| 482 | } |
| 483 | |
| 484 | static void |
| 485 | shell_surface_set_maximized(struct wl_client *client, |
| 486 | struct wl_resource *resource, |
| 487 | struct wl_resource *output_resource ) |
| 488 | { |
| 489 | struct shell_surface *shsurf = resource->data; |
| 490 | struct weston_surface *es = shsurf->surface; |
| 491 | struct wl_shell *wlshell = NULL; |
| 492 | uint32_t edges = 0, panel_height = 0; |
| 493 | |
| 494 | /* get the default output, if the client set it as NULL |
| 495 | check whether the ouput is available */ |
| 496 | if (output_resource) |
| 497 | shsurf->output = output_resource->data; |
| 498 | else |
| 499 | shsurf->output = get_default_output(es->compositor); |
| 500 | |
| 501 | if (reset_shell_surface_type(shsurf)) |
| 502 | return; |
| 503 | |
| 504 | shsurf->saved_x = es->geometry.x; |
| 505 | shsurf->saved_y = es->geometry.y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 506 | shsurf->saved_position_valid = true; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 507 | |
| 508 | wlshell = shell_surface_get_shell(shsurf); |
| 509 | panel_height = get_output_panel_height(wlshell, es->output); |
| 510 | edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT; |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 511 | |
| 512 | wl_shell_surface_send_configure(&shsurf->resource, |
| 513 | weston_compositor_get_time(), edges, |
| 514 | es->output->current->width, |
| 515 | es->output->current->height - panel_height); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 516 | |
| 517 | shsurf->type = SHELL_SURFACE_MAXIMIZED; |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 518 | } |
| 519 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 520 | static struct weston_surface * |
| 521 | create_black_surface(struct weston_compositor *ec, |
| 522 | GLfloat x, GLfloat y, int w, int h) |
| 523 | { |
| 524 | struct weston_surface *surface = NULL; |
| 525 | |
| 526 | surface = weston_surface_create(ec); |
| 527 | if (surface == NULL) { |
| 528 | fprintf(stderr, "no memory\n"); |
| 529 | return NULL; |
| 530 | } |
| 531 | |
| 532 | weston_surface_configure(surface, x, y, w, h); |
| 533 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
| 534 | return surface; |
| 535 | } |
| 536 | |
| 537 | /* Create black surface and append it to the associated fullscreen surface. |
| 538 | * Handle size dismatch and positioning according to the method. */ |
| 539 | static void |
| 540 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 541 | { |
| 542 | struct weston_output *output = shsurf->fullscreen_output; |
| 543 | struct weston_surface *surface = shsurf->surface; |
| 544 | struct weston_matrix *matrix; |
| 545 | float scale; |
| 546 | |
| 547 | center_on_output(surface, output); |
| 548 | |
| 549 | if (!shsurf->fullscreen.black_surface) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 550 | shsurf->fullscreen.black_surface = |
| 551 | create_black_surface(surface->compositor, |
| 552 | output->x, output->y, |
| 553 | output->current->width, |
| 554 | output->current->height); |
| 555 | |
| 556 | wl_list_remove(&shsurf->fullscreen.black_surface->layer_link); |
| 557 | wl_list_insert(&surface->layer_link, |
| 558 | &shsurf->fullscreen.black_surface->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 559 | shsurf->fullscreen.black_surface->output = output; |
| 560 | |
| 561 | switch (shsurf->fullscreen.type) { |
| 562 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
| 563 | break; |
| 564 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
| 565 | matrix = &shsurf->fullscreen.transform.matrix; |
| 566 | weston_matrix_init(matrix); |
| 567 | scale = (float)output->current->width/(float)surface->geometry.width; |
| 568 | weston_matrix_scale(matrix, scale, scale, 1); |
| 569 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 570 | wl_list_insert(surface->geometry.transformation_list.prev, |
| 571 | &shsurf->fullscreen.transform.link); |
| 572 | weston_surface_set_position(surface, output->x, output->y); |
| 573 | break; |
| 574 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
| 575 | break; |
| 576 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
| 577 | break; |
| 578 | default: |
| 579 | break; |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | /* make the fullscreen and black surface at the top */ |
| 584 | static void |
| 585 | shell_stack_fullscreen(struct shell_surface *shsurf) |
| 586 | { |
| 587 | struct weston_surface *surface = shsurf->surface; |
| 588 | struct wl_shell *shell = shell_surface_get_shell(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 589 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 590 | wl_list_remove(&surface->layer_link); |
| 591 | wl_list_remove(&shsurf->fullscreen.black_surface->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 592 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 593 | wl_list_insert(&shell->fullscreen_layer.surface_list, |
| 594 | &surface->layer_link); |
| 595 | wl_list_insert(&surface->layer_link, |
| 596 | &shsurf->fullscreen.black_surface->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 597 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 598 | weston_surface_damage(surface); |
| 599 | weston_surface_damage(shsurf->fullscreen.black_surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | static void |
| 603 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 604 | { |
| 605 | shell_configure_fullscreen(shsurf); |
| 606 | shell_stack_fullscreen(shsurf); |
| 607 | } |
| 608 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 609 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 610 | shell_surface_set_fullscreen(struct wl_client *client, |
Kristian Høgsberg | f856fd2 | 2012-02-16 15:58:14 -0500 | [diff] [blame] | 611 | struct wl_resource *resource, |
| 612 | uint32_t method, |
| 613 | uint32_t framerate, |
| 614 | struct wl_resource *output_resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 615 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 616 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 617 | struct weston_surface *es = shsurf->surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 618 | |
| 619 | if (output_resource) |
| 620 | shsurf->output = output_resource->data; |
| 621 | else |
| 622 | shsurf->output = get_default_output(es->compositor); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 623 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 624 | if (reset_shell_surface_type(shsurf)) |
| 625 | return; |
| 626 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 627 | shsurf->fullscreen_output = shsurf->output; |
| 628 | shsurf->fullscreen.type = method; |
| 629 | shsurf->fullscreen.framerate = framerate; |
| 630 | shsurf->type = SHELL_SURFACE_FULLSCREEN; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 631 | |
Pekka Paalanen | ba3cf95 | 2012-01-25 16:22:05 +0200 | [diff] [blame] | 632 | shsurf->saved_x = es->geometry.x; |
| 633 | shsurf->saved_y = es->geometry.y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 634 | shsurf->saved_position_valid = true; |
| 635 | |
| 636 | if (es->output) |
| 637 | shsurf->surface->force_configure = 1; |
Kristian Høgsberg | d5ae9f4 | 2012-02-16 23:38:14 -0500 | [diff] [blame] | 638 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 639 | wl_shell_surface_send_configure(&shsurf->resource, |
| 640 | weston_compositor_get_time(), 0, |
| 641 | shsurf->output->current->width, |
| 642 | shsurf->output->current->height); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 643 | } |
| 644 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 645 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 646 | popup_grab_focus(struct wl_pointer_grab *grab, uint32_t time, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 647 | struct wl_surface *surface, int32_t x, int32_t y) |
| 648 | { |
| 649 | struct wl_input_device *device = grab->input_device; |
| 650 | struct shell_surface *priv = |
| 651 | container_of(grab, struct shell_surface, popup.grab); |
| 652 | struct wl_client *client = priv->surface->surface.resource.client; |
| 653 | |
Pekka Paalanen | cb10843 | 2012-01-19 16:25:40 +0200 | [diff] [blame] | 654 | if (surface && surface->resource.client == client) { |
Pekka Paalanen | b29f412 | 2012-02-14 14:59:18 +0200 | [diff] [blame] | 655 | wl_input_device_set_pointer_focus(device, surface, time, x, y); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 656 | grab->focus = surface; |
| 657 | } else { |
Pekka Paalanen | b29f412 | 2012-02-14 14:59:18 +0200 | [diff] [blame] | 658 | wl_input_device_set_pointer_focus(device, NULL, time, 0, 0); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 659 | grab->focus = NULL; |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 664 | popup_grab_motion(struct wl_pointer_grab *grab, |
Pekka Paalanen | b29f412 | 2012-02-14 14:59:18 +0200 | [diff] [blame] | 665 | uint32_t time, int32_t sx, int32_t sy) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 666 | { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 667 | struct wl_resource *resource; |
| 668 | |
| 669 | resource = grab->input_device->pointer_focus_resource; |
| 670 | if (resource) |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 671 | wl_input_device_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 675 | popup_grab_button(struct wl_pointer_grab *grab, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 676 | uint32_t time, int32_t button, int32_t state) |
| 677 | { |
| 678 | struct wl_resource *resource; |
| 679 | struct shell_surface *shsurf = |
| 680 | container_of(grab, struct shell_surface, popup.grab); |
| 681 | |
| 682 | resource = grab->input_device->pointer_focus_resource; |
| 683 | if (resource) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 684 | wl_input_device_send_button(resource, time, button, state); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 685 | } else if (state == 0 && |
| 686 | (shsurf->popup.initial_up || |
| 687 | time - shsurf->popup.time > 500)) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 688 | wl_shell_surface_send_popup_done(&shsurf->resource); |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 689 | wl_input_device_end_pointer_grab(grab->input_device, time); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 690 | shsurf->popup.grab.input_device = NULL; |
| 691 | } |
| 692 | |
| 693 | if (state == 0) |
| 694 | shsurf->popup.initial_up = 1; |
| 695 | } |
| 696 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 697 | static const struct wl_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 698 | popup_grab_focus, |
| 699 | popup_grab_motion, |
| 700 | popup_grab_button, |
| 701 | }; |
| 702 | |
| 703 | static void |
| 704 | shell_map_popup(struct shell_surface *shsurf, uint32_t time) |
| 705 | { |
| 706 | struct wl_input_device *device; |
| 707 | struct weston_surface *es = shsurf->surface; |
| 708 | struct weston_surface *parent = shsurf->parent->surface; |
| 709 | |
| 710 | es->output = parent->output; |
| 711 | |
| 712 | shsurf->popup.grab.interface = &popup_grab_interface; |
| 713 | device = es->compositor->input_device; |
| 714 | |
Pekka Paalanen | 938269a | 2012-02-07 14:19:01 +0200 | [diff] [blame] | 715 | weston_surface_update_transform(parent); |
| 716 | if (parent->transform.enabled) { |
| 717 | shsurf->popup.parent_transform.matrix = |
| 718 | parent->transform.matrix; |
| 719 | } else { |
| 720 | /* construct x, y translation matrix */ |
| 721 | weston_matrix_init(&shsurf->popup.parent_transform.matrix); |
| 722 | shsurf->popup.parent_transform.matrix.d[12] = |
| 723 | parent->geometry.x; |
| 724 | shsurf->popup.parent_transform.matrix.d[13] = |
| 725 | parent->geometry.y; |
| 726 | } |
| 727 | wl_list_insert(es->geometry.transformation_list.prev, |
| 728 | &shsurf->popup.parent_transform.link); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 729 | weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 730 | |
| 731 | shsurf->popup.grab.input_device = device; |
| 732 | shsurf->popup.time = device->grab_time; |
| 733 | shsurf->popup.initial_up = 0; |
| 734 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 735 | wl_input_device_start_pointer_grab(shsurf->popup.grab.input_device, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 736 | &shsurf->popup.grab, shsurf->popup.time); |
| 737 | } |
| 738 | |
| 739 | static void |
| 740 | shell_surface_set_popup(struct wl_client *client, |
| 741 | struct wl_resource *resource, |
| 742 | struct wl_resource *input_device_resource, |
| 743 | uint32_t time, |
| 744 | struct wl_resource *parent_resource, |
| 745 | int32_t x, int32_t y, uint32_t flags) |
| 746 | { |
| 747 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 748 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 749 | shsurf->type = SHELL_SURFACE_POPUP; |
| 750 | shsurf->parent = parent_resource->data; |
| 751 | shsurf->popup.x = x; |
| 752 | shsurf->popup.y = y; |
| 753 | } |
| 754 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 755 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
| 756 | shell_surface_move, |
| 757 | shell_surface_resize, |
| 758 | shell_surface_set_toplevel, |
| 759 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 760 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 761 | shell_surface_set_popup, |
| 762 | shell_surface_set_maximized |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 763 | }; |
| 764 | |
| 765 | static void |
| 766 | destroy_shell_surface(struct wl_resource *resource) |
| 767 | { |
| 768 | struct shell_surface *shsurf = resource->data; |
| 769 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 770 | if (shsurf->popup.grab.input_device) |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 771 | wl_input_device_end_pointer_grab(shsurf->popup.grab.input_device, 0); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 772 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 773 | /* in case cleaning up a dead client destroys shell_surface first */ |
| 774 | if (shsurf->surface) |
| 775 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 776 | |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 777 | if (shsurf->fullscreen.black_surface) |
| 778 | weston_surface_destroy(shsurf->fullscreen.black_surface); |
| 779 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 780 | wl_list_remove(&shsurf->link); |
| 781 | free(shsurf); |
| 782 | } |
| 783 | |
| 784 | static void |
| 785 | shell_handle_surface_destroy(struct wl_listener *listener, |
| 786 | struct wl_resource *resource, uint32_t time) |
| 787 | { |
| 788 | struct shell_surface *shsurf = container_of(listener, |
| 789 | struct shell_surface, |
| 790 | surface_destroy_listener); |
| 791 | |
| 792 | shsurf->surface = NULL; |
| 793 | wl_resource_destroy(&shsurf->resource, time); |
| 794 | } |
| 795 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 796 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 797 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 798 | { |
| 799 | struct wl_list *lst = &surface->surface.resource.destroy_listener_list; |
| 800 | struct wl_listener *listener; |
| 801 | |
| 802 | /* search the destroy listener list for our callback */ |
| 803 | wl_list_for_each(listener, lst, link) { |
| 804 | if (listener->func == shell_handle_surface_destroy) { |
| 805 | return container_of(listener, struct shell_surface, |
| 806 | surface_destroy_listener); |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | return NULL; |
| 811 | } |
| 812 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 813 | static void |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 814 | shell_get_shell_surface(struct wl_client *client, |
| 815 | struct wl_resource *resource, |
| 816 | uint32_t id, |
| 817 | struct wl_resource *surface_resource) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 818 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 819 | struct weston_surface *surface = surface_resource->data; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 820 | struct shell_surface *shsurf; |
| 821 | |
Pekka Paalanen | f32f1fc | 2011-11-29 16:05:28 +0200 | [diff] [blame] | 822 | if (get_shell_surface(surface)) { |
| 823 | wl_resource_post_error(surface_resource, |
| 824 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 825 | "wl_shell::get_shell_surface already requested"); |
| 826 | return; |
| 827 | } |
| 828 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 829 | shsurf = calloc(1, sizeof *shsurf); |
| 830 | if (!shsurf) { |
| 831 | wl_resource_post_no_memory(resource); |
| 832 | return; |
| 833 | } |
| 834 | |
| 835 | shsurf->resource.destroy = destroy_shell_surface; |
| 836 | shsurf->resource.object.id = id; |
| 837 | shsurf->resource.object.interface = &wl_shell_surface_interface; |
| 838 | shsurf->resource.object.implementation = |
| 839 | (void (**)(void)) &shell_surface_implementation; |
| 840 | shsurf->resource.data = shsurf; |
| 841 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 842 | shsurf->saved_position_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 843 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 844 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 845 | shsurf->fullscreen.framerate = 0; |
| 846 | shsurf->fullscreen.black_surface = NULL; |
| 847 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 848 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 849 | shsurf->surface_destroy_listener.func = shell_handle_surface_destroy; |
| 850 | wl_list_insert(surface->surface.resource.destroy_listener_list.prev, |
| 851 | &shsurf->surface_destroy_listener.link); |
| 852 | |
| 853 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 854 | wl_list_init(&shsurf->link); |
| 855 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 856 | /* empty when not in use */ |
| 857 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 858 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 859 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 860 | shsurf->type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 861 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 862 | wl_client_add_resource(client, &shsurf->resource); |
| 863 | } |
| 864 | |
| 865 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 866 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 867 | }; |
| 868 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 869 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 870 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 871 | { |
| 872 | proc->pid = 0; |
| 873 | } |
| 874 | |
| 875 | static void |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 876 | launch_screensaver(struct wl_shell *shell) |
| 877 | { |
| 878 | if (shell->screensaver.binding) |
| 879 | return; |
| 880 | |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 881 | if (!shell->screensaver.path) |
| 882 | return; |
| 883 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 884 | if (shell->screensaver.process.pid != 0) { |
| 885 | fprintf(stderr, "old screensaver still running\n"); |
| 886 | return; |
| 887 | } |
| 888 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 889 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 890 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 891 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 892 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | static void |
| 896 | terminate_screensaver(struct wl_shell *shell) |
| 897 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 898 | if (shell->screensaver.process.pid == 0) |
| 899 | return; |
| 900 | |
| 901 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | static void |
| 905 | show_screensaver(struct wl_shell *shell, struct shell_surface *surface) |
| 906 | { |
| 907 | struct wl_list *list; |
| 908 | |
| 909 | if (shell->lock_surface) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 910 | list = &shell->lock_surface->surface->layer_link; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 911 | else |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 912 | list = &shell->lock_layer.surface_list; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 913 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 914 | wl_list_remove(&surface->surface->layer_link); |
| 915 | wl_list_insert(list, &surface->surface->layer_link); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 916 | surface->surface->output = surface->output; |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 917 | weston_surface_damage(surface->surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | static void |
| 921 | hide_screensaver(struct wl_shell *shell, struct shell_surface *surface) |
| 922 | { |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 923 | wl_list_remove(&surface->surface->layer_link); |
| 924 | wl_list_init(&surface->surface->layer_link); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 925 | surface->surface->output = NULL; |
| 926 | } |
| 927 | |
| 928 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 929 | desktop_shell_set_background(struct wl_client *client, |
| 930 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 931 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 932 | struct wl_resource *surface_resource) |
| 933 | { |
| 934 | struct wl_shell *shell = resource->data; |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 935 | struct shell_surface *shsurf = surface_resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 936 | struct weston_surface *surface = shsurf->surface; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 937 | struct shell_surface *priv; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 938 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 939 | if (reset_shell_surface_type(shsurf)) |
| 940 | return; |
| 941 | |
Benjamin Franzke | f02bb64 | 2011-11-23 20:46:40 +0100 | [diff] [blame] | 942 | wl_list_for_each(priv, &shell->backgrounds, link) { |
| 943 | if (priv->output == output_resource->data) { |
| 944 | priv->surface->output = NULL; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 945 | wl_list_remove(&priv->surface->layer_link); |
Benjamin Franzke | f02bb64 | 2011-11-23 20:46:40 +0100 | [diff] [blame] | 946 | wl_list_remove(&priv->link); |
| 947 | break; |
| 948 | } |
| 949 | } |
| 950 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 951 | shsurf->type = SHELL_SURFACE_BACKGROUND; |
| 952 | shsurf->output = output_resource->data; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 953 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 954 | wl_list_insert(&shell->backgrounds, &shsurf->link); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 955 | |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 956 | weston_surface_set_position(surface, shsurf->output->x, |
| 957 | shsurf->output->y); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 958 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 959 | desktop_shell_send_configure(resource, |
| 960 | weston_compositor_get_time(), 0, |
| 961 | surface_resource, |
| 962 | shsurf->output->current->width, |
| 963 | shsurf->output->current->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | static void |
| 967 | desktop_shell_set_panel(struct wl_client *client, |
| 968 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 969 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 970 | struct wl_resource *surface_resource) |
| 971 | { |
| 972 | struct wl_shell *shell = resource->data; |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 973 | struct shell_surface *shsurf = surface_resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 974 | struct weston_surface *surface = shsurf->surface; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 975 | struct shell_surface *priv; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 976 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 977 | if (reset_shell_surface_type(shsurf)) |
| 978 | return; |
| 979 | |
Benjamin Franzke | f02bb64 | 2011-11-23 20:46:40 +0100 | [diff] [blame] | 980 | wl_list_for_each(priv, &shell->panels, link) { |
| 981 | if (priv->output == output_resource->data) { |
| 982 | priv->surface->output = NULL; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 983 | wl_list_remove(&priv->surface->layer_link); |
Benjamin Franzke | f02bb64 | 2011-11-23 20:46:40 +0100 | [diff] [blame] | 984 | wl_list_remove(&priv->link); |
| 985 | break; |
| 986 | } |
| 987 | } |
| 988 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 989 | shsurf->type = SHELL_SURFACE_PANEL; |
| 990 | shsurf->output = output_resource->data; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 991 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 992 | wl_list_insert(&shell->panels, &shsurf->link); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 993 | |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 994 | weston_surface_set_position(surface, shsurf->output->x, |
| 995 | shsurf->output->y); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 996 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 997 | desktop_shell_send_configure(resource, |
| 998 | weston_compositor_get_time(), 0, |
| 999 | surface_resource, |
| 1000 | shsurf->output->current->width, |
| 1001 | shsurf->output->current->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1002 | } |
| 1003 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1004 | static void |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1005 | handle_lock_surface_destroy(struct wl_listener *listener, |
| 1006 | struct wl_resource *resource, uint32_t time) |
| 1007 | { |
| 1008 | struct wl_shell *shell = |
Pekka Paalanen | 2ca8630 | 2011-11-16 13:47:35 +0200 | [diff] [blame] | 1009 | container_of(listener, struct wl_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1010 | |
| 1011 | fprintf(stderr, "lock surface gone\n"); |
| 1012 | shell->lock_surface = NULL; |
| 1013 | } |
| 1014 | |
| 1015 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1016 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 1017 | struct wl_resource *resource, |
| 1018 | struct wl_resource *surface_resource) |
| 1019 | { |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 1020 | struct wl_shell *shell = resource->data; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1021 | struct shell_surface *surface = surface_resource->data; |
| 1022 | |
| 1023 | if (reset_shell_surface_type(surface)) |
| 1024 | return; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 1025 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1026 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 1027 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1028 | if (!shell->locked) |
| 1029 | return; |
| 1030 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1031 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1032 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1033 | shell->lock_surface_listener.func = handle_lock_surface_destroy; |
| 1034 | wl_list_insert(&surface_resource->destroy_listener_list, |
| 1035 | &shell->lock_surface_listener.link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1036 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 1037 | shell->lock_surface->type = SHELL_SURFACE_LOCK; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | static void |
| 1041 | resume_desktop(struct wl_shell *shell) |
| 1042 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1043 | struct shell_surface *tmp; |
| 1044 | |
| 1045 | wl_list_for_each(tmp, &shell->screensaver.surfaces, link) |
| 1046 | hide_screensaver(shell, tmp); |
| 1047 | |
| 1048 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1049 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1050 | wl_list_remove(&shell->lock_layer.link); |
| 1051 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 1052 | &shell->fullscreen_layer.link); |
| 1053 | wl_list_insert(&shell->fullscreen_layer.link, |
| 1054 | &shell->panel_layer.link); |
| 1055 | wl_list_insert(&shell->panel_layer.link, &shell->toplevel_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1056 | |
| 1057 | shell->locked = false; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 1058 | shell->compositor->idle_time = shell->compositor->option_idle_time; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1059 | weston_compositor_wake(shell->compositor); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 1060 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | static void |
| 1064 | desktop_shell_unlock(struct wl_client *client, |
| 1065 | struct wl_resource *resource) |
| 1066 | { |
| 1067 | struct wl_shell *shell = resource->data; |
| 1068 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1069 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1070 | |
| 1071 | if (shell->locked) |
| 1072 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1073 | } |
| 1074 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1075 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 1076 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1077 | desktop_shell_set_panel, |
| 1078 | desktop_shell_set_lock_surface, |
| 1079 | desktop_shell_unlock |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1080 | }; |
| 1081 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1082 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1083 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1084 | { |
| 1085 | struct shell_surface *shsurf; |
| 1086 | |
| 1087 | shsurf = get_shell_surface(surface); |
| 1088 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1089 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1090 | return shsurf->type; |
| 1091 | } |
| 1092 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1093 | static void |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1094 | move_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 1095 | uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1096 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1097 | struct weston_surface *surface = |
| 1098 | (struct weston_surface *) device->pointer_focus; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 1099 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1100 | if (surface == NULL) |
| 1101 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1102 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1103 | switch (get_shell_surface_type(surface)) { |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1104 | case SHELL_SURFACE_PANEL: |
| 1105 | case SHELL_SURFACE_BACKGROUND: |
| 1106 | case SHELL_SURFACE_FULLSCREEN: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1107 | case SHELL_SURFACE_SCREENSAVER: |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1108 | return; |
| 1109 | default: |
| 1110 | break; |
| 1111 | } |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 1112 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1113 | weston_surface_move(surface, (struct weston_input_device *) device, time); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | static void |
| 1117 | resize_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 1118 | uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1119 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1120 | struct weston_surface *surface = |
| 1121 | (struct weston_surface *) device->pointer_focus; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1122 | uint32_t edges = 0; |
| 1123 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1124 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 1125 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1126 | if (surface == NULL) |
| 1127 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1128 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1129 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1130 | if (!shsurf) |
| 1131 | return; |
| 1132 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1133 | switch (shsurf->type) { |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1134 | case SHELL_SURFACE_PANEL: |
| 1135 | case SHELL_SURFACE_BACKGROUND: |
| 1136 | case SHELL_SURFACE_FULLSCREEN: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1137 | case SHELL_SURFACE_SCREENSAVER: |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1138 | return; |
| 1139 | default: |
| 1140 | break; |
| 1141 | } |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 1142 | |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 1143 | weston_surface_from_global(surface, |
| 1144 | device->grab_x, device->grab_y, &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1145 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1146 | if (x < surface->geometry.width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1147 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1148 | else if (x < 2 * surface->geometry.width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1149 | edges |= 0; |
| 1150 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1151 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1152 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1153 | if (y < surface->geometry.height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1154 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1155 | else if (y < 2 * surface->geometry.height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1156 | edges |= 0; |
| 1157 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1158 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1159 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1160 | weston_surface_resize(shsurf, (struct weston_input_device *) device, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1161 | time, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | static void |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 1165 | surface_opacity_binding(struct wl_input_device *device, uint32_t time, |
| 1166 | uint32_t key, uint32_t button, uint32_t axis, int32_t value, void *data) |
| 1167 | { |
| 1168 | int step = 15; |
| 1169 | struct shell_surface *shsurf; |
| 1170 | struct weston_surface *surface = |
| 1171 | (struct weston_surface *) device->pointer_focus; |
| 1172 | |
| 1173 | if (surface == NULL) |
| 1174 | return; |
| 1175 | |
| 1176 | shsurf = get_shell_surface(surface); |
| 1177 | if (!shsurf) |
| 1178 | return; |
| 1179 | |
| 1180 | switch (shsurf->type) { |
| 1181 | case SHELL_SURFACE_BACKGROUND: |
| 1182 | case SHELL_SURFACE_SCREENSAVER: |
| 1183 | return; |
| 1184 | default: |
| 1185 | break; |
| 1186 | } |
| 1187 | |
| 1188 | surface->alpha += value * step; |
| 1189 | |
| 1190 | if (surface->alpha > 255) |
| 1191 | surface->alpha = 255; |
| 1192 | if (surface->alpha < step) |
| 1193 | surface->alpha = step; |
| 1194 | |
| 1195 | surface->geometry.dirty = 1; |
| 1196 | weston_surface_damage(surface); |
| 1197 | } |
| 1198 | |
| 1199 | static void |
Kristian Høgsberg | abcef3c | 2012-03-05 17:47:15 -0500 | [diff] [blame] | 1200 | zoom_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 1b45a79 | 2012-03-22 10:58:23 -0600 | [diff] [blame] | 1201 | uint32_t key, uint32_t button, uint32_t axis, int32_t value, void *data) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 1202 | { |
| 1203 | struct weston_input_device *wd = (struct weston_input_device *) device; |
| 1204 | struct weston_compositor *compositor = wd->compositor; |
| 1205 | struct weston_output *output; |
| 1206 | |
| 1207 | wl_list_for_each(output, &compositor->output_list, link) { |
| 1208 | if (pixman_region32_contains_point(&output->region, |
| 1209 | device->x, device->y, NULL)) { |
Scott Moreau | 1b45a79 | 2012-03-22 10:58:23 -0600 | [diff] [blame] | 1210 | output->zoom.active = 1; |
| 1211 | output->zoom.level += output->zoom.increment * -value; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 1212 | |
| 1213 | if (output->zoom.level >= 1.0) { |
| 1214 | output->zoom.active = 0; |
| 1215 | output->zoom.level = 1.0; |
| 1216 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 1217 | |
| 1218 | if (output->zoom.level < output->zoom.increment) |
| 1219 | output->zoom.level = output->zoom.increment; |
| 1220 | |
| 1221 | weston_output_update_zoom(output, device->x, device->y); |
| 1222 | } |
| 1223 | } |
| 1224 | } |
| 1225 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 1226 | static void |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 1227 | terminate_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 1228 | uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 1229 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1230 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 1231 | |
| 1232 | if (state) |
| 1233 | wl_display_terminate(compositor->wl_display); |
| 1234 | } |
| 1235 | |
| 1236 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1237 | rotate_grab_motion(struct wl_pointer_grab *grab, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1238 | uint32_t time, int32_t x, int32_t y) |
| 1239 | { |
| 1240 | struct rotate_grab *rotate = |
| 1241 | container_of(grab, struct rotate_grab, grab); |
| 1242 | struct wl_input_device *device = grab->input_device; |
| 1243 | struct shell_surface *surface = rotate->surface; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame^] | 1244 | struct weston_surface *base_surface = surface->surface; |
| 1245 | GLfloat cx = 0.5f * base_surface->geometry.width; |
| 1246 | GLfloat cy = 0.5f * base_surface->geometry.height; |
| 1247 | GLfloat dx, dy, cposx, cposy, dposx, dposy; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1248 | GLfloat r; |
| 1249 | |
| 1250 | dx = device->x - rotate->center.x; |
| 1251 | dy = device->y - rotate->center.y; |
| 1252 | r = sqrtf(dx * dx + dy * dy); |
| 1253 | |
| 1254 | wl_list_remove(&surface->rotation.transform.link); |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 1255 | surface->surface->geometry.dirty = 1; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1256 | |
| 1257 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1258 | struct weston_matrix *matrix = |
| 1259 | &surface->rotation.transform.matrix; |
| 1260 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1261 | weston_matrix_init(&rotate->rotation); |
| 1262 | rotate->rotation.d[0] = dx / r; |
| 1263 | rotate->rotation.d[4] = -dy / r; |
| 1264 | rotate->rotation.d[1] = -rotate->rotation.d[4]; |
| 1265 | rotate->rotation.d[5] = rotate->rotation.d[0]; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1266 | |
| 1267 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 1268 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1269 | weston_matrix_multiply(matrix, &surface->rotation.rotation); |
| 1270 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 1271 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1272 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 1273 | wl_list_insert( |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 1274 | &surface->surface->geometry.transformation_list, |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 1275 | &surface->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1276 | } else { |
| 1277 | wl_list_init(&surface->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1278 | weston_matrix_init(&surface->rotation.rotation); |
| 1279 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1280 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 1281 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame^] | 1282 | /* We need to adjust the position of the surface |
| 1283 | * in case it was resized in a rotated state before */ |
| 1284 | cposx = base_surface->geometry.x + cx; |
| 1285 | cposy = base_surface->geometry.y + cy; |
| 1286 | dposx = rotate->center.x - cposx; |
| 1287 | dposy = rotate->center.y - cposy; |
| 1288 | if (dposx != 0.0f || dposy != 0.0f) { |
| 1289 | weston_surface_set_position(base_surface, |
| 1290 | base_surface->geometry.x + dposx, |
| 1291 | base_surface->geometry.y + dposy); |
| 1292 | } |
| 1293 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 1294 | /* Repaint implies weston_surface_update_transform(), which |
| 1295 | * lazily applies the damage due to rotation update. |
| 1296 | */ |
| 1297 | weston_compositor_schedule_repaint(surface->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1301 | rotate_grab_button(struct wl_pointer_grab *grab, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1302 | uint32_t time, int32_t button, int32_t state) |
| 1303 | { |
| 1304 | struct rotate_grab *rotate = |
| 1305 | container_of(grab, struct rotate_grab, grab); |
| 1306 | struct wl_input_device *device = grab->input_device; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1307 | struct shell_surface *surface = rotate->surface; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1308 | |
| 1309 | if (device->button_count == 0 && state == 0) { |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1310 | weston_matrix_multiply(&surface->rotation.rotation, |
| 1311 | &rotate->rotation); |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1312 | wl_input_device_end_pointer_grab(device, time); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1313 | free(rotate); |
| 1314 | } |
| 1315 | } |
| 1316 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1317 | static const struct wl_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1318 | noop_grab_focus, |
| 1319 | rotate_grab_motion, |
| 1320 | rotate_grab_button, |
| 1321 | }; |
| 1322 | |
| 1323 | static void |
| 1324 | rotate_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 1325 | uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1326 | { |
| 1327 | struct weston_surface *base_surface = |
| 1328 | (struct weston_surface *) device->pointer_focus; |
| 1329 | struct shell_surface *surface; |
| 1330 | struct rotate_grab *rotate; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame^] | 1331 | GLfloat dx, dy; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1332 | GLfloat r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1333 | |
| 1334 | if (base_surface == NULL) |
| 1335 | return; |
| 1336 | |
| 1337 | surface = get_shell_surface(base_surface); |
| 1338 | if (!surface) |
| 1339 | return; |
| 1340 | |
| 1341 | switch (surface->type) { |
| 1342 | case SHELL_SURFACE_PANEL: |
| 1343 | case SHELL_SURFACE_BACKGROUND: |
| 1344 | case SHELL_SURFACE_FULLSCREEN: |
| 1345 | case SHELL_SURFACE_SCREENSAVER: |
| 1346 | return; |
| 1347 | default: |
| 1348 | break; |
| 1349 | } |
| 1350 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1351 | rotate = malloc(sizeof *rotate); |
| 1352 | if (!rotate) |
| 1353 | return; |
| 1354 | |
| 1355 | rotate->grab.interface = &rotate_grab_interface; |
| 1356 | rotate->surface = surface; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1357 | |
| 1358 | weston_surface_to_global(surface->surface, |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1359 | surface->surface->geometry.width / 2, |
| 1360 | surface->surface->geometry.height / 2, |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1361 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1362 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1363 | wl_input_device_start_pointer_grab(device, &rotate->grab, time); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1364 | |
| 1365 | dx = device->x - rotate->center.x; |
| 1366 | dy = device->y - rotate->center.y; |
| 1367 | r = sqrtf(dx * dx + dy * dy); |
| 1368 | if (r > 20.0f) { |
| 1369 | struct weston_matrix inverse; |
| 1370 | |
| 1371 | weston_matrix_init(&inverse); |
| 1372 | inverse.d[0] = dx / r; |
| 1373 | inverse.d[4] = dy / r; |
| 1374 | inverse.d[1] = -inverse.d[4]; |
| 1375 | inverse.d[5] = inverse.d[0]; |
| 1376 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame^] | 1377 | |
| 1378 | weston_matrix_init(&rotate->rotation); |
| 1379 | rotate->rotation.d[0] = dx / r; |
| 1380 | rotate->rotation.d[4] = -dy / r; |
| 1381 | rotate->rotation.d[1] = -rotate->rotation.d[4]; |
| 1382 | rotate->rotation.d[5] = rotate->rotation.d[0]; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1383 | } else { |
| 1384 | weston_matrix_init(&surface->rotation.rotation); |
| 1385 | weston_matrix_init(&rotate->rotation); |
| 1386 | } |
| 1387 | |
Pekka Paalanen | b29f412 | 2012-02-14 14:59:18 +0200 | [diff] [blame] | 1388 | wl_input_device_set_pointer_focus(device, NULL, time, 0, 0); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1392 | activate(struct weston_shell *base, struct weston_surface *es, |
| 1393 | struct weston_input_device *device, uint32_t time) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1394 | { |
| 1395 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1396 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1397 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1398 | weston_surface_activate(es, device, time); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1399 | |
Kristian Høgsberg | d6e5525 | 2011-10-11 23:41:17 -0400 | [diff] [blame] | 1400 | if (compositor->wxs) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1401 | weston_xserver_surface_activate(es); |
Kristian Høgsberg | d6e5525 | 2011-10-11 23:41:17 -0400 | [diff] [blame] | 1402 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1403 | switch (get_shell_surface_type(es)) { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1404 | case SHELL_SURFACE_BACKGROUND: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1405 | case SHELL_SURFACE_PANEL: |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1406 | case SHELL_SURFACE_LOCK: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1407 | break; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1408 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1409 | case SHELL_SURFACE_SCREENSAVER: |
| 1410 | /* always below lock surface */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1411 | if (shell->lock_surface) |
| 1412 | weston_surface_restack(es, |
| 1413 | &shell->lock_surface->surface->layer_link); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1414 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1415 | case SHELL_SURFACE_FULLSCREEN: |
| 1416 | /* should on top of panels */ |
| 1417 | break; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1418 | default: |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1419 | weston_surface_restack(es, |
| 1420 | &shell->toplevel_layer.surface_list); |
| 1421 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | static void |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 1426 | click_to_activate_binding(struct wl_input_device *device, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1427 | uint32_t time, uint32_t key, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 1428 | uint32_t button, uint32_t axis, int32_t state, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 1429 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1430 | struct weston_input_device *wd = (struct weston_input_device *) device; |
| 1431 | struct weston_compositor *compositor = data; |
| 1432 | struct weston_surface *focus; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1433 | struct weston_surface *upper; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 1434 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1435 | focus = (struct weston_surface *) device->pointer_focus; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 1436 | if (!focus) |
| 1437 | return; |
| 1438 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1439 | upper = container_of(focus->link.prev, struct weston_surface, link); |
| 1440 | if (focus->link.prev != &compositor->surface_list && |
| 1441 | get_shell_surface_type(upper) == SHELL_SURFACE_FULLSCREEN) { |
| 1442 | printf("%s: focus is black surface, raise its fullscreen surface\n", __func__); |
| 1443 | shell_stack_fullscreen(get_shell_surface(upper)); |
| 1444 | focus = upper; |
| 1445 | } |
| 1446 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 1447 | if (state && device->pointer_grab == &device->default_pointer_grab) |
Kristian Høgsberg | 2a25cd4 | 2011-12-19 15:19:54 -0500 | [diff] [blame] | 1448 | activate(compositor->shell, focus, wd, time); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1452 | lock(struct weston_shell *base) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1453 | { |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1454 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1455 | struct weston_input_device *device; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1456 | struct shell_surface *shsurf; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1457 | struct weston_output *output; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1458 | uint32_t time; |
| 1459 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1460 | if (shell->locked) { |
| 1461 | wl_list_for_each(output, &shell->compositor->output_list, link) |
| 1462 | /* TODO: find a way to jump to other DPMS levels */ |
| 1463 | if (output->set_dpms) |
| 1464 | output->set_dpms(output, WESTON_DPMS_STANDBY); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1465 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1466 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1467 | |
| 1468 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1469 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1470 | /* Hide all surfaces by removing the fullscreen, panel and |
| 1471 | * toplevel layers. This way nothing else can show or receive |
| 1472 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1473 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1474 | wl_list_remove(&shell->panel_layer.link); |
| 1475 | wl_list_remove(&shell->toplevel_layer.link); |
| 1476 | wl_list_remove(&shell->fullscreen_layer.link); |
| 1477 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 1478 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1479 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1480 | launch_screensaver(shell); |
| 1481 | |
| 1482 | wl_list_for_each(shsurf, &shell->screensaver.surfaces, link) |
| 1483 | show_screensaver(shell, shsurf); |
| 1484 | |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 1485 | if (!wl_list_empty(&shell->screensaver.surfaces)) { |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 1486 | shell->compositor->idle_time = shell->screensaver.duration; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1487 | weston_compositor_wake(shell->compositor); |
| 1488 | shell->compositor->state = WESTON_COMPOSITOR_IDLE; |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 1489 | } |
Pekka Paalanen | baeb6a1 | 2011-12-01 16:23:57 +0200 | [diff] [blame] | 1490 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1491 | /* reset pointer foci */ |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 1492 | weston_compositor_schedule_repaint(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1493 | |
| 1494 | /* reset keyboard foci */ |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1495 | time = weston_compositor_get_time(); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1496 | wl_list_for_each(device, &shell->compositor->input_device_list, link) { |
| 1497 | wl_input_device_set_keyboard_focus(&device->input_device, |
| 1498 | NULL, time); |
| 1499 | } |
| 1500 | |
| 1501 | /* TODO: disable bindings that should not work while locked. */ |
| 1502 | |
| 1503 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1507 | unlock(struct weston_shell *base) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1508 | { |
| 1509 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
| 1510 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 1511 | if (!shell->locked || shell->lock_surface) { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1512 | weston_compositor_wake(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1513 | return; |
| 1514 | } |
| 1515 | |
| 1516 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 1517 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1518 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1519 | return; |
| 1520 | } |
| 1521 | |
| 1522 | if (shell->prepare_event_sent) |
| 1523 | return; |
| 1524 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1525 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1526 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1530 | center_on_output(struct weston_surface *surface, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1531 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1532 | struct weston_mode *mode = output->current; |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1533 | GLfloat x = (mode->width - surface->geometry.width) / 2; |
| 1534 | GLfloat y = (mode->height - surface->geometry.height) / 2; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1535 | |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1536 | weston_surface_set_position(surface, output->x + x, output->y + y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | static void |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 1540 | map(struct weston_shell *base, struct weston_surface *surface, |
| 1541 | int32_t width, int32_t height, int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1542 | { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1543 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1544 | struct weston_compositor *compositor = shell->compositor; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1545 | struct shell_surface *shsurf; |
| 1546 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 1547 | struct weston_surface *parent; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1548 | int panel_height = 0; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1549 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1550 | shsurf = get_shell_surface(surface); |
| 1551 | if (shsurf) |
| 1552 | surface_type = shsurf->type; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1553 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1554 | surface->geometry.width = width; |
| 1555 | surface->geometry.height = height; |
| 1556 | surface->geometry.dirty = 1; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1557 | |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 1558 | weston_compositor_update_drag_surfaces(compositor); |
| 1559 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1560 | /* initial positioning, see also configure() */ |
| 1561 | switch (surface_type) { |
| 1562 | case SHELL_SURFACE_TOPLEVEL: |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1563 | weston_surface_set_position(surface, 10 + random() % 400, |
| 1564 | 10 + random() % 400); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1565 | break; |
| 1566 | case SHELL_SURFACE_SCREENSAVER: |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 1567 | center_on_output(surface, shsurf->fullscreen_output); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1568 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1569 | case SHELL_SURFACE_FULLSCREEN: |
| 1570 | shell_map_fullscreen(shsurf); |
| 1571 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1572 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1573 | /* use surface configure to set the geometry */ |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1574 | panel_height = get_output_panel_height(shell,surface->output); |
| 1575 | weston_surface_set_position(surface, surface->output->x, |
| 1576 | surface->output->y + panel_height); |
| 1577 | break; |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 1578 | case SHELL_SURFACE_LOCK: |
| 1579 | center_on_output(surface, get_default_output(compositor)); |
| 1580 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 1581 | case SHELL_SURFACE_POPUP: |
| 1582 | shell_map_popup(shsurf, shsurf->popup.time); |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 1583 | case SHELL_SURFACE_NONE: |
| 1584 | weston_surface_set_position(surface, |
| 1585 | surface->geometry.x + sx, |
| 1586 | surface->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 1587 | break; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1588 | default: |
| 1589 | ; |
| 1590 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1591 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 1592 | /* surface stacking order, see also activate() */ |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1593 | switch (surface_type) { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1594 | case SHELL_SURFACE_BACKGROUND: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 1595 | /* background always visible, at the bottom */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1596 | wl_list_insert(&shell->background_layer.surface_list, |
| 1597 | &surface->layer_link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1598 | break; |
| 1599 | case SHELL_SURFACE_PANEL: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 1600 | /* panel always on top, hidden while locked */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1601 | wl_list_insert(&shell->panel_layer.surface_list, |
| 1602 | &surface->layer_link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1603 | break; |
| 1604 | case SHELL_SURFACE_LOCK: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 1605 | /* lock surface always visible, on top */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1606 | wl_list_insert(&shell->lock_layer.surface_list, |
| 1607 | &surface->layer_link); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1608 | weston_compositor_wake(compositor); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1609 | break; |
| 1610 | case SHELL_SURFACE_SCREENSAVER: |
| 1611 | /* If locked, show it. */ |
Pekka Paalanen | baeb6a1 | 2011-12-01 16:23:57 +0200 | [diff] [blame] | 1612 | if (shell->locked) { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1613 | show_screensaver(shell, shsurf); |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 1614 | compositor->idle_time = shell->screensaver.duration; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1615 | weston_compositor_wake(compositor); |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 1616 | if (!shell->lock_surface) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1617 | compositor->state = WESTON_COMPOSITOR_IDLE; |
Pekka Paalanen | baeb6a1 | 2011-12-01 16:23:57 +0200 | [diff] [blame] | 1618 | } |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1619 | break; |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 1620 | case SHELL_SURFACE_POPUP: |
| 1621 | case SHELL_SURFACE_TRANSIENT: |
| 1622 | parent = shsurf->parent->surface; |
| 1623 | wl_list_insert(parent->layer_link.prev, &surface->layer_link); |
| 1624 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1625 | case SHELL_SURFACE_FULLSCREEN: |
Ander Conselvan de Oliveira | a1ff53b | 2012-02-15 17:02:54 +0200 | [diff] [blame] | 1626 | case SHELL_SURFACE_NONE: |
| 1627 | break; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1628 | default: |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1629 | wl_list_insert(&shell->toplevel_layer.surface_list, |
| 1630 | &surface->layer_link); |
| 1631 | break; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1632 | } |
| 1633 | |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 1634 | if (surface_type != SHELL_SURFACE_NONE) { |
| 1635 | weston_surface_assign_output(surface); |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 1636 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
| 1637 | surface->output = shsurf->output; |
| 1638 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 1639 | |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 1640 | switch (surface_type) { |
| 1641 | case SHELL_SURFACE_TOPLEVEL: |
| 1642 | case SHELL_SURFACE_TRANSIENT: |
| 1643 | case SHELL_SURFACE_FULLSCREEN: |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1644 | case SHELL_SURFACE_MAXIMIZED: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 1645 | if (!shell->locked) |
| 1646 | activate(base, surface, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1647 | (struct weston_input_device *) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1648 | compositor->input_device, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1649 | weston_compositor_get_time()); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 1650 | break; |
| 1651 | default: |
| 1652 | break; |
| 1653 | } |
| 1654 | |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 1655 | if (surface_type == SHELL_SURFACE_TOPLEVEL) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1656 | weston_zoom_run(surface, 0.8, 1.0, NULL, NULL); |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1660 | configure(struct weston_shell *base, struct weston_surface *surface, |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 1661 | GLfloat x, GLfloat y, int32_t width, int32_t height) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 1662 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1663 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1664 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1665 | enum shell_surface_type prev_surface_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1666 | struct shell_surface *shsurf; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 1667 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1668 | shsurf = get_shell_surface(surface); |
| 1669 | if (shsurf) |
| 1670 | surface_type = shsurf->type; |
| 1671 | |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 1672 | surface->geometry.x = x; |
| 1673 | surface->geometry.y = y; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1674 | surface->geometry.width = width; |
| 1675 | surface->geometry.height = height; |
| 1676 | surface->geometry.dirty = 1; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1677 | |
| 1678 | switch (surface_type) { |
| 1679 | case SHELL_SURFACE_SCREENSAVER: |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 1680 | center_on_output(surface, shsurf->fullscreen_output); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 1681 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1682 | case SHELL_SURFACE_FULLSCREEN: |
| 1683 | shell_configure_fullscreen(shsurf); |
| 1684 | if (prev_surface_type != SHELL_SURFACE_FULLSCREEN) |
| 1685 | shell_stack_fullscreen(shsurf); |
| 1686 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1687 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1688 | /* setting x, y and using configure to change that geometry */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 1689 | surface->geometry.x = surface->output->x; |
| 1690 | surface->geometry.y = surface->output->y + |
| 1691 | get_output_panel_height(shell,surface->output); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1692 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1693 | case SHELL_SURFACE_TOPLEVEL: |
| 1694 | break; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 1695 | default: |
| 1696 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1697 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 1698 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1699 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 1700 | if (surface->output) { |
Pekka Paalanen | f07cb5d | 2012-02-10 13:34:36 +0200 | [diff] [blame] | 1701 | weston_surface_assign_output(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1702 | |
| 1703 | if (surface_type == SHELL_SURFACE_SCREENSAVER) |
| 1704 | surface->output = shsurf->output; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1705 | else if (surface_type == SHELL_SURFACE_MAXIMIZED) |
| 1706 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1707 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1708 | } |
| 1709 | |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 1710 | static int launch_desktop_shell_process(struct wl_shell *shell); |
| 1711 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1712 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1713 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 1714 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 1715 | uint32_t time; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 1716 | struct wl_shell *shell = |
| 1717 | container_of(process, struct wl_shell, child.process); |
| 1718 | |
| 1719 | shell->child.process.pid = 0; |
| 1720 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 1721 | |
| 1722 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 1723 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 1724 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 1725 | shell->child.deathstamp = time; |
| 1726 | shell->child.deathcount = 0; |
| 1727 | } |
| 1728 | |
| 1729 | shell->child.deathcount++; |
| 1730 | if (shell->child.deathcount > 5) { |
| 1731 | fprintf(stderr, "weston-desktop-shell died, giving up.\n"); |
| 1732 | return; |
| 1733 | } |
| 1734 | |
| 1735 | fprintf(stderr, "weston-desktop-shell died, respawning...\n"); |
| 1736 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | static int |
| 1740 | launch_desktop_shell_process(struct wl_shell *shell) |
| 1741 | { |
Kristian Høgsberg | 9724b51 | 2012-01-03 14:35:49 -0500 | [diff] [blame] | 1742 | const char *shell_exe = LIBEXECDIR "/weston-desktop-shell"; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 1743 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1744 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 1745 | &shell->child.process, |
| 1746 | shell_exe, |
| 1747 | desktop_shell_sigchld); |
| 1748 | |
| 1749 | if (!shell->child.client) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 1750 | return -1; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 1751 | return 0; |
| 1752 | } |
| 1753 | |
| 1754 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1755 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 1756 | { |
| 1757 | struct wl_shell *shell = data; |
| 1758 | |
| 1759 | wl_client_add_object(client, &wl_shell_interface, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1760 | &shell_implementation, id, shell); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1761 | } |
| 1762 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1763 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1764 | unbind_desktop_shell(struct wl_resource *resource) |
| 1765 | { |
| 1766 | struct wl_shell *shell = resource->data; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1767 | |
| 1768 | if (shell->locked) |
| 1769 | resume_desktop(shell); |
| 1770 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1771 | shell->child.desktop_shell = NULL; |
| 1772 | shell->prepare_event_sent = false; |
| 1773 | free(resource); |
| 1774 | } |
| 1775 | |
| 1776 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1777 | bind_desktop_shell(struct wl_client *client, |
| 1778 | void *data, uint32_t version, uint32_t id) |
| 1779 | { |
| 1780 | struct wl_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 1781 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1782 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 1783 | resource = wl_client_add_object(client, &desktop_shell_interface, |
| 1784 | &desktop_shell_implementation, |
| 1785 | id, shell); |
| 1786 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1787 | if (client == shell->child.client) { |
| 1788 | resource->destroy = unbind_desktop_shell; |
| 1789 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 1790 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1791 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 1792 | |
| 1793 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1794 | "permission to bind desktop_shell denied"); |
| 1795 | wl_resource_destroy(resource, 0); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1796 | } |
| 1797 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 1798 | static void |
| 1799 | screensaver_set_surface(struct wl_client *client, |
| 1800 | struct wl_resource *resource, |
| 1801 | struct wl_resource *shell_surface_resource, |
| 1802 | struct wl_resource *output_resource) |
| 1803 | { |
| 1804 | struct wl_shell *shell = resource->data; |
| 1805 | struct shell_surface *surface = shell_surface_resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1806 | struct weston_output *output = output_resource->data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 1807 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1808 | if (reset_shell_surface_type(surface)) |
| 1809 | return; |
| 1810 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1811 | surface->type = SHELL_SURFACE_SCREENSAVER; |
| 1812 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 1813 | surface->fullscreen_output = output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1814 | surface->output = output; |
| 1815 | wl_list_insert(shell->screensaver.surfaces.prev, &surface->link); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | static const struct screensaver_interface screensaver_implementation = { |
| 1819 | screensaver_set_surface |
| 1820 | }; |
| 1821 | |
| 1822 | static void |
| 1823 | unbind_screensaver(struct wl_resource *resource) |
| 1824 | { |
| 1825 | struct wl_shell *shell = resource->data; |
| 1826 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1827 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 1828 | free(resource); |
| 1829 | } |
| 1830 | |
| 1831 | static void |
| 1832 | bind_screensaver(struct wl_client *client, |
| 1833 | void *data, uint32_t version, uint32_t id) |
| 1834 | { |
| 1835 | struct wl_shell *shell = data; |
| 1836 | struct wl_resource *resource; |
| 1837 | |
| 1838 | resource = wl_client_add_object(client, &screensaver_interface, |
| 1839 | &screensaver_implementation, |
| 1840 | id, shell); |
| 1841 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1842 | if (shell->screensaver.binding == NULL) { |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 1843 | resource->destroy = unbind_screensaver; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1844 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 1845 | return; |
| 1846 | } |
| 1847 | |
| 1848 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1849 | "interface object already bound"); |
| 1850 | wl_resource_destroy(resource, 0); |
| 1851 | } |
| 1852 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 1853 | struct switcher { |
| 1854 | struct weston_compositor *compositor; |
| 1855 | struct weston_surface *current; |
| 1856 | struct wl_listener listener; |
| 1857 | struct wl_keyboard_grab grab; |
| 1858 | }; |
| 1859 | |
| 1860 | static void |
| 1861 | switcher_next(struct switcher *switcher) |
| 1862 | { |
| 1863 | struct weston_compositor *compositor = switcher->compositor; |
| 1864 | struct weston_surface *surface; |
| 1865 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
| 1866 | |
| 1867 | wl_list_for_each(surface, &compositor->surface_list, link) { |
| 1868 | /* Workaround for cursor surfaces. */ |
| 1869 | if (surface->surface.resource.destroy_listener_list.next == NULL) |
| 1870 | continue; |
| 1871 | |
| 1872 | switch (get_shell_surface_type(surface)) { |
| 1873 | case SHELL_SURFACE_TOPLEVEL: |
| 1874 | case SHELL_SURFACE_FULLSCREEN: |
| 1875 | case SHELL_SURFACE_MAXIMIZED: |
| 1876 | if (first == NULL) |
| 1877 | first = surface; |
| 1878 | if (prev == switcher->current) |
| 1879 | next = surface; |
| 1880 | prev = surface; |
| 1881 | surface->alpha = 64; |
Kristian Høgsberg | cacb7cd | 2012-02-28 09:20:21 -0500 | [diff] [blame] | 1882 | surface->geometry.dirty = 1; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 1883 | weston_surface_damage(surface); |
| 1884 | break; |
| 1885 | default: |
| 1886 | break; |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | if (next == NULL) |
| 1891 | next = first; |
| 1892 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 1893 | if (next == NULL) |
| 1894 | return; |
| 1895 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 1896 | wl_list_remove(&switcher->listener.link); |
| 1897 | wl_list_insert(next->surface.resource.destroy_listener_list.prev, |
| 1898 | &switcher->listener.link); |
| 1899 | |
| 1900 | switcher->current = next; |
| 1901 | next->alpha = 255; |
| 1902 | } |
| 1903 | |
| 1904 | static void |
| 1905 | switcher_handle_surface_destroy(struct wl_listener *listener, |
| 1906 | struct wl_resource *resource, uint32_t time) |
| 1907 | { |
| 1908 | struct switcher *switcher = |
| 1909 | container_of(listener, struct switcher, listener); |
| 1910 | |
| 1911 | switcher_next(switcher); |
| 1912 | } |
| 1913 | |
| 1914 | static void |
| 1915 | switcher_destroy(struct switcher *switcher, uint32_t time) |
| 1916 | { |
| 1917 | struct weston_compositor *compositor = switcher->compositor; |
| 1918 | struct weston_surface *surface; |
| 1919 | struct weston_input_device *device = |
| 1920 | (struct weston_input_device *) switcher->grab.input_device; |
| 1921 | |
| 1922 | wl_list_for_each(surface, &compositor->surface_list, link) { |
| 1923 | surface->alpha = 255; |
| 1924 | weston_surface_damage(surface); |
| 1925 | } |
| 1926 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 1927 | if (switcher->current) |
| 1928 | activate(compositor->shell, switcher->current, device, time); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 1929 | wl_list_remove(&switcher->listener.link); |
| 1930 | wl_input_device_end_keyboard_grab(&device->input_device, time); |
| 1931 | free(switcher); |
| 1932 | } |
| 1933 | |
| 1934 | static void |
| 1935 | switcher_key(struct wl_keyboard_grab *grab, |
| 1936 | uint32_t time, uint32_t key, int32_t state) |
| 1937 | { |
| 1938 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 1939 | struct weston_input_device *device = |
| 1940 | (struct weston_input_device *) grab->input_device; |
| 1941 | |
| 1942 | if ((device->modifier_state & MODIFIER_SUPER) == 0) { |
| 1943 | switcher_destroy(switcher, time); |
| 1944 | } else if (key == KEY_TAB && state) { |
| 1945 | switcher_next(switcher); |
| 1946 | } |
| 1947 | }; |
| 1948 | |
| 1949 | static const struct wl_keyboard_grab_interface switcher_grab = { |
| 1950 | switcher_key |
| 1951 | }; |
| 1952 | |
| 1953 | static void |
| 1954 | switcher_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 1955 | uint32_t key, uint32_t button, uint32_t axis, |
| 1956 | int32_t state, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 1957 | { |
| 1958 | struct weston_compositor *compositor = data; |
| 1959 | struct switcher *switcher; |
| 1960 | |
| 1961 | switcher = malloc(sizeof *switcher); |
| 1962 | switcher->compositor = compositor; |
| 1963 | switcher->current = NULL; |
| 1964 | switcher->listener.func = switcher_handle_surface_destroy; |
| 1965 | wl_list_init(&switcher->listener.link); |
| 1966 | |
| 1967 | switcher->grab.interface = &switcher_grab; |
| 1968 | wl_input_device_start_keyboard_grab(device, &switcher->grab, time); |
Kristian Høgsberg | abcef3c | 2012-03-05 17:47:15 -0500 | [diff] [blame] | 1969 | wl_input_device_set_keyboard_focus(device, NULL, |
| 1970 | weston_compositor_get_time()); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 1971 | switcher_next(switcher); |
| 1972 | } |
| 1973 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 1974 | static void |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1975 | backlight_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 1976 | uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1977 | { |
| 1978 | struct weston_compositor *compositor = data; |
| 1979 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1980 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1981 | |
| 1982 | /* TODO: we're limiting to simple use cases, where we assume just |
| 1983 | * control on the primary display. We'd have to extend later if we |
| 1984 | * ever get support for setting backlights on random desktop LCD |
| 1985 | * panels though */ |
| 1986 | output = get_default_output(compositor); |
| 1987 | if (!output) |
| 1988 | return; |
| 1989 | |
| 1990 | if (!output->set_backlight) |
| 1991 | return; |
| 1992 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1993 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 1994 | backlight_new = output->backlight_current - 25; |
| 1995 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 1996 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1997 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 1998 | if (backlight_new < 5) |
| 1999 | backlight_new = 5; |
| 2000 | if (backlight_new > 255) |
| 2001 | backlight_new = 255; |
| 2002 | |
| 2003 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2004 | output->set_backlight(output, output->backlight_current); |
| 2005 | } |
| 2006 | |
| 2007 | static void |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 2008 | debug_repaint_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 2009 | uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 2010 | { |
| 2011 | struct weston_compositor *compositor = data; |
| 2012 | struct wl_shell *shell = |
| 2013 | container_of(compositor->shell, struct wl_shell, shell); |
| 2014 | struct weston_surface *surface; |
| 2015 | |
| 2016 | if (shell->debug_repaint_surface) { |
| 2017 | weston_surface_destroy(shell->debug_repaint_surface); |
| 2018 | shell->debug_repaint_surface = NULL; |
| 2019 | } else { |
| 2020 | surface = weston_surface_create(compositor); |
| 2021 | weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2); |
| 2022 | weston_surface_configure(surface, 0, 0, 8192, 8192); |
| 2023 | wl_list_insert(&compositor->fade_layer.surface_list, |
| 2024 | &surface->layer_link); |
| 2025 | weston_surface_assign_output(surface); |
| 2026 | pixman_region32_init(&surface->input); |
| 2027 | |
| 2028 | /* Here's the dirty little trick that makes the |
| 2029 | * repaint debugging work: we force an |
| 2030 | * update_transform first to update dependent state |
| 2031 | * and clear the geometry.dirty bit. Then we clear |
| 2032 | * the surface damage so it only gets repainted |
| 2033 | * piecewise as we repaint other things. */ |
| 2034 | |
| 2035 | weston_surface_update_transform(surface); |
| 2036 | pixman_region32_fini(&surface->damage); |
| 2037 | pixman_region32_init(&surface->damage); |
| 2038 | shell->debug_repaint_surface = surface; |
| 2039 | } |
| 2040 | } |
| 2041 | |
| 2042 | static void |
Kristian Høgsberg | 3466bc8 | 2012-01-03 11:29:15 -0500 | [diff] [blame] | 2043 | shell_destroy(struct weston_shell *base) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 2044 | { |
| 2045 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
| 2046 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 2047 | if (shell->child.client) |
| 2048 | wl_client_destroy(shell->child.client); |
| 2049 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 2050 | free(shell->screensaver.path); |
| 2051 | free(shell); |
| 2052 | } |
| 2053 | |
Kristian Høgsberg | 6c709a3 | 2011-05-06 14:52:41 -0400 | [diff] [blame] | 2054 | int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2055 | shell_init(struct weston_compositor *ec); |
Kristian Høgsberg | 6c709a3 | 2011-05-06 14:52:41 -0400 | [diff] [blame] | 2056 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2057 | WL_EXPORT int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2058 | shell_init(struct weston_compositor *ec) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2059 | { |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2060 | struct wl_shell *shell; |
| 2061 | |
| 2062 | shell = malloc(sizeof *shell); |
| 2063 | if (shell == NULL) |
| 2064 | return -1; |
| 2065 | |
Kristian Høgsberg | f0d9116 | 2011-10-11 22:44:23 -0400 | [diff] [blame] | 2066 | memset(shell, 0, sizeof *shell); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2067 | shell->compositor = ec; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2068 | shell->shell.lock = lock; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2069 | shell->shell.unlock = unlock; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 2070 | shell->shell.map = map; |
| 2071 | shell->shell.configure = configure; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 2072 | shell->shell.destroy = shell_destroy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2073 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2074 | wl_list_init(&shell->backgrounds); |
| 2075 | wl_list_init(&shell->panels); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2076 | wl_list_init(&shell->screensaver.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2077 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2078 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 2079 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
| 2080 | weston_layer_init(&shell->toplevel_layer, &shell->panel_layer.link); |
| 2081 | weston_layer_init(&shell->background_layer, |
| 2082 | &shell->toplevel_layer.link); |
| 2083 | wl_list_init(&shell->lock_layer.surface_list); |
| 2084 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 2085 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2086 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2087 | if (wl_display_add_global(ec->wl_display, &wl_shell_interface, |
| 2088 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2089 | return -1; |
| 2090 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2091 | if (wl_display_add_global(ec->wl_display, |
| 2092 | &desktop_shell_interface, |
| 2093 | shell, bind_desktop_shell) == NULL) |
| 2094 | return -1; |
| 2095 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2096 | if (wl_display_add_global(ec->wl_display, &screensaver_interface, |
| 2097 | shell, bind_screensaver) == NULL) |
| 2098 | return -1; |
| 2099 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 2100 | shell->child.deathstamp = weston_compositor_get_time(); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2101 | if (launch_desktop_shell_process(shell) != 0) |
| 2102 | return -1; |
| 2103 | |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 2104 | weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, MODIFIER_SUPER, |
| 2105 | move_binding, shell); |
| 2106 | weston_compositor_add_binding(ec, 0, BTN_MIDDLE, 0, MODIFIER_SUPER, |
| 2107 | resize_binding, shell); |
| 2108 | weston_compositor_add_binding(ec, KEY_BACKSPACE, 0, 0, |
| 2109 | MODIFIER_CTRL | MODIFIER_ALT, |
| 2110 | terminate_binding, ec); |
| 2111 | weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, 0, |
| 2112 | click_to_activate_binding, ec); |
Scott Moreau | 1b45a79 | 2012-03-22 10:58:23 -0600 | [diff] [blame] | 2113 | weston_compositor_add_binding(ec, 0, 0, WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL, |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2114 | MODIFIER_SUPER | MODIFIER_ALT, |
| 2115 | surface_opacity_binding, NULL); |
| 2116 | weston_compositor_add_binding(ec, 0, 0, WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL, |
Scott Moreau | 1b45a79 | 2012-03-22 10:58:23 -0600 | [diff] [blame] | 2117 | MODIFIER_SUPER, zoom_binding, NULL); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2118 | weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 2119 | MODIFIER_SUPER | MODIFIER_ALT, |
| 2120 | rotate_binding, NULL); |
| 2121 | weston_compositor_add_binding(ec, KEY_TAB, 0, 0, MODIFIER_SUPER, |
| 2122 | switcher_binding, ec); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2123 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2124 | /* brightness */ |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 2125 | weston_compositor_add_binding(ec, KEY_F9, 0, 0, MODIFIER_CTRL, |
| 2126 | backlight_binding, ec); |
| 2127 | weston_compositor_add_binding(ec, KEY_BRIGHTNESSDOWN, 0, 0, 0, |
| 2128 | backlight_binding, ec); |
| 2129 | weston_compositor_add_binding(ec, KEY_F10, 0, 0, MODIFIER_CTRL, |
| 2130 | backlight_binding, ec); |
| 2131 | weston_compositor_add_binding(ec, KEY_BRIGHTNESSUP, 0, 0, 0, |
| 2132 | backlight_binding, ec); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2133 | |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 2134 | weston_compositor_add_binding(ec, KEY_SPACE, 0, 0, MODIFIER_SUPER, |
| 2135 | debug_repaint_binding, ec); |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 2136 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2137 | ec->shell = &shell->shell; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2138 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2139 | return 0; |
| 2140 | } |