Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 2 | * Copyright © 2010-2011 Intel Corporation |
| 3 | * Copyright © 2008-2011 Kristian Høgsberg |
Pekka Paalanen | d581a8f | 2012-01-27 16:25:16 +0200 | [diff] [blame] | 4 | * Copyright © 2012 Collabora, Ltd. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 5 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 6 | * Permission to use, copy, modify, distribute, and sell this software and |
| 7 | * its documentation for any purpose is hereby granted without fee, provided |
| 8 | * that the above copyright notice appear in all copies and that both that |
| 9 | * copyright notice and this permission notice appear in supporting |
| 10 | * documentation, and that the name of the copyright holders not be used in |
| 11 | * advertising or publicity pertaining to distribution of the software |
| 12 | * without specific, written prior permission. The copyright holders make |
| 13 | * no representations about the suitability of this software for any |
| 14 | * purpose. It is provided "as is" without express or implied warranty. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 15 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 16 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 17 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 18 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 20 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 21 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 22 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 23 | */ |
| 24 | |
Kristian Høgsberg | 06bc264 | 2010-12-01 09:50:16 -0500 | [diff] [blame] | 25 | #define _GNU_SOURCE |
| 26 | |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 27 | #include "config.h" |
| 28 | |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 29 | #include <fcntl.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 30 | #include <stdio.h> |
| 31 | #include <string.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <stdint.h> |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 34 | #include <limits.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 35 | #include <stdarg.h> |
Benjamin Franzke | 6f5fc69 | 2011-06-21 19:34:19 +0200 | [diff] [blame] | 36 | #include <assert.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 37 | #include <sys/ioctl.h> |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 38 | #include <sys/mman.h> |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 39 | #include <sys/wait.h> |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 40 | #include <sys/socket.h> |
Martin Minarik | f12c287 | 2012-06-11 00:57:39 +0200 | [diff] [blame] | 41 | #include <sys/utsname.h> |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 42 | #include <sys/stat.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 43 | #include <unistd.h> |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 44 | #include <math.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 45 | #include <linux/input.h> |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 46 | #include <dlfcn.h> |
Kristian Høgsberg | 8544903 | 2011-05-02 12:11:07 -0400 | [diff] [blame] | 47 | #include <signal.h> |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 48 | #include <setjmp.h> |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 49 | #include <sys/time.h> |
| 50 | #include <time.h> |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 51 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 52 | #ifdef HAVE_LIBUNWIND |
| 53 | #define UNW_LOCAL_ONLY |
| 54 | #include <libunwind.h> |
| 55 | #endif |
| 56 | |
Pekka Paalanen | 50719bc | 2011-11-22 14:18:50 +0200 | [diff] [blame] | 57 | #include <wayland-server.h> |
Kristian Høgsberg | 8286302 | 2010-06-04 21:52:02 -0400 | [diff] [blame] | 58 | #include "compositor.h" |
Pekka Paalanen | 51aaf64 | 2012-05-30 15:53:41 +0300 | [diff] [blame] | 59 | #include "../shared/os-compatibility.h" |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 60 | #include "git-version.h" |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 61 | #include "version.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 62 | |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 63 | static struct wl_list child_process_list; |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 64 | static struct weston_compositor *segv_compositor; |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 65 | |
| 66 | static int |
| 67 | sigchld_handler(int signal_number, void *data) |
| 68 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 69 | struct weston_process *p; |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 70 | int status; |
| 71 | pid_t pid; |
| 72 | |
Bill Spitzak | 027b962 | 2012-03-17 15:22:03 -0700 | [diff] [blame] | 73 | pid = waitpid(-1, &status, WNOHANG); |
| 74 | if (!pid) |
| 75 | return 1; |
| 76 | |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 77 | wl_list_for_each(p, &child_process_list, link) { |
| 78 | if (p->pid == pid) |
| 79 | break; |
| 80 | } |
| 81 | |
| 82 | if (&p->link == &child_process_list) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 83 | weston_log("unknown child process exited\n"); |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 84 | return 1; |
| 85 | } |
| 86 | |
| 87 | wl_list_remove(&p->link); |
| 88 | p->cleanup(p, status); |
| 89 | |
| 90 | return 1; |
| 91 | } |
| 92 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 93 | static void |
| 94 | weston_output_transform_init(struct weston_output *output, uint32_t transform); |
| 95 | |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 96 | WL_EXPORT int |
| 97 | weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode) |
| 98 | { |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 99 | struct weston_seat *seat; |
| 100 | pixman_region32_t old_output_region; |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 101 | int ret; |
| 102 | |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 103 | if (!output->switch_mode) |
| 104 | return -1; |
| 105 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 106 | ret = output->switch_mode(output, mode); |
| 107 | if (ret < 0) |
| 108 | return ret; |
| 109 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 110 | pixman_region32_init(&old_output_region); |
| 111 | pixman_region32_copy(&old_output_region, &output->region); |
| 112 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 113 | /* Update output region and transformation matrix */ |
| 114 | weston_output_transform_init(output, output->transform); |
| 115 | |
| 116 | pixman_region32_init(&output->previous_damage); |
| 117 | pixman_region32_init_rect(&output->region, output->x, output->y, |
| 118 | output->width, output->height); |
| 119 | |
| 120 | weston_output_update_matrix(output); |
| 121 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 122 | /* If a pointer falls outside the outputs new geometry, move it to its |
| 123 | * lower-right corner */ |
| 124 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
| 125 | struct wl_pointer *pointer = seat->seat.pointer; |
| 126 | int32_t x, y; |
| 127 | |
| 128 | if (!pointer) |
| 129 | continue; |
| 130 | |
| 131 | x = wl_fixed_to_int(pointer->x); |
| 132 | y = wl_fixed_to_int(pointer->y); |
| 133 | |
| 134 | if (!pixman_region32_contains_point(&old_output_region, |
| 135 | x, y, NULL) || |
| 136 | pixman_region32_contains_point(&output->region, |
| 137 | x, y, NULL)) |
| 138 | continue; |
| 139 | |
| 140 | if (x >= output->x + output->width) |
| 141 | x = output->x + output->width - 1; |
| 142 | if (y >= output->y + output->height) |
| 143 | y = output->y + output->height - 1; |
| 144 | |
| 145 | pointer->x = wl_fixed_from_int(x); |
| 146 | pointer->y = wl_fixed_from_int(y); |
| 147 | } |
| 148 | |
| 149 | pixman_region32_fini(&old_output_region); |
| 150 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 151 | return ret; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 152 | } |
| 153 | |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 154 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 155 | weston_watch_process(struct weston_process *process) |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 156 | { |
| 157 | wl_list_insert(&child_process_list, &process->link); |
| 158 | } |
| 159 | |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 160 | static void |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 161 | child_client_exec(int sockfd, const char *path) |
| 162 | { |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 163 | int clientfd; |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 164 | char s[32]; |
Pekka Paalanen | c47ddfd | 2011-12-08 10:44:56 +0200 | [diff] [blame] | 165 | sigset_t allsigs; |
| 166 | |
| 167 | /* do not give our signal mask to the new process */ |
| 168 | sigfillset(&allsigs); |
| 169 | sigprocmask(SIG_UNBLOCK, &allsigs, NULL); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 170 | |
Kristian Høgsberg | eb76484 | 2012-01-31 22:17:25 -0500 | [diff] [blame] | 171 | /* Launch clients as the user. */ |
| 172 | seteuid(getuid()); |
| 173 | |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 174 | /* SOCK_CLOEXEC closes both ends, so we dup the fd to get a |
| 175 | * non-CLOEXEC fd to pass through exec. */ |
| 176 | clientfd = dup(sockfd); |
| 177 | if (clientfd == -1) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 178 | weston_log("compositor: dup failed: %m\n"); |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 179 | return; |
| 180 | } |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 181 | |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 182 | snprintf(s, sizeof s, "%d", clientfd); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 183 | setenv("WAYLAND_SOCKET", s, 1); |
| 184 | |
| 185 | if (execl(path, path, NULL) < 0) |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 186 | weston_log("compositor: executing '%s' failed: %m\n", |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 187 | path); |
| 188 | } |
| 189 | |
| 190 | WL_EXPORT struct wl_client * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 191 | weston_client_launch(struct weston_compositor *compositor, |
| 192 | struct weston_process *proc, |
| 193 | const char *path, |
| 194 | weston_process_cleanup_func_t cleanup) |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 195 | { |
| 196 | int sv[2]; |
| 197 | pid_t pid; |
| 198 | struct wl_client *client; |
| 199 | |
Pekka Paalanen | df1fd36 | 2012-08-06 14:57:03 +0300 | [diff] [blame] | 200 | weston_log("launching '%s'\n", path); |
| 201 | |
Pekka Paalanen | 51aaf64 | 2012-05-30 15:53:41 +0300 | [diff] [blame] | 202 | if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sv) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 203 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 204 | "socketpair failed while launching '%s': %m\n", |
| 205 | path); |
| 206 | return NULL; |
| 207 | } |
| 208 | |
| 209 | pid = fork(); |
| 210 | if (pid == -1) { |
| 211 | close(sv[0]); |
| 212 | close(sv[1]); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 213 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 214 | "fork failed while launching '%s': %m\n", path); |
| 215 | return NULL; |
| 216 | } |
| 217 | |
| 218 | if (pid == 0) { |
| 219 | child_client_exec(sv[1], path); |
| 220 | exit(-1); |
| 221 | } |
| 222 | |
| 223 | close(sv[1]); |
| 224 | |
| 225 | client = wl_client_create(compositor->wl_display, sv[0]); |
| 226 | if (!client) { |
| 227 | close(sv[0]); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 228 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 229 | "wl_client_create failed while launching '%s'.\n", |
| 230 | path); |
| 231 | return NULL; |
| 232 | } |
| 233 | |
| 234 | proc->pid = pid; |
| 235 | proc->cleanup = cleanup; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 236 | weston_watch_process(proc); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 237 | |
| 238 | return client; |
| 239 | } |
| 240 | |
| 241 | static void |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 242 | surface_handle_pending_buffer_destroy(struct wl_listener *listener, void *data) |
| 243 | { |
| 244 | struct weston_surface *surface = |
| 245 | container_of(listener, struct weston_surface, |
| 246 | pending.buffer_destroy_listener); |
| 247 | |
| 248 | surface->pending.buffer = NULL; |
| 249 | } |
| 250 | |
Ander Conselvan de Oliveira | 90fbbd7 | 2012-02-28 17:59:33 +0200 | [diff] [blame] | 251 | static void |
| 252 | empty_region(pixman_region32_t *region) |
| 253 | { |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 254 | pixman_region32_fini(region); |
Ander Conselvan de Oliveira | 90fbbd7 | 2012-02-28 17:59:33 +0200 | [diff] [blame] | 255 | pixman_region32_init(region); |
| 256 | } |
| 257 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 258 | static void |
| 259 | region_init_infinite(pixman_region32_t *region) |
| 260 | { |
| 261 | pixman_region32_init_rect(region, INT32_MIN, INT32_MIN, |
| 262 | UINT32_MAX, UINT32_MAX); |
| 263 | } |
| 264 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 265 | WL_EXPORT struct weston_surface * |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 266 | weston_surface_create(struct weston_compositor *compositor) |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 267 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 268 | struct weston_surface *surface; |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 269 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 270 | surface = calloc(1, sizeof *surface); |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 271 | if (surface == NULL) |
| 272 | return NULL; |
| 273 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 274 | wl_signal_init(&surface->surface.resource.destroy_signal); |
Kristian Høgsberg | 4889154 | 2012-02-23 17:38:33 -0500 | [diff] [blame] | 275 | |
Kristian Høgsberg | f6b1471 | 2011-01-06 15:32:14 -0500 | [diff] [blame] | 276 | wl_list_init(&surface->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 277 | wl_list_init(&surface->layer_link); |
Kristian Høgsberg | c551bd2 | 2010-12-06 16:43:16 -0500 | [diff] [blame] | 278 | |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 279 | surface->surface.resource.client = NULL; |
Kristian Høgsberg | 8244b44 | 2011-06-23 15:44:14 -0400 | [diff] [blame] | 280 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 281 | surface->compositor = compositor; |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 282 | surface->alpha = 1.0; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 283 | |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 284 | if (compositor->renderer->create_surface(surface) < 0) { |
| 285 | free(surface); |
| 286 | return NULL; |
| 287 | } |
| 288 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 289 | surface->buffer_transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 290 | surface->pending.buffer_transform = surface->buffer_transform; |
Kristian Høgsberg | 6f7179c | 2011-08-29 16:09:32 -0400 | [diff] [blame] | 291 | surface->output = NULL; |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 292 | surface->plane = &compositor->primary_plane; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 293 | surface->pending.newly_attached = 0; |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 294 | |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 295 | pixman_region32_init(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 296 | pixman_region32_init(&surface->opaque); |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 297 | pixman_region32_init(&surface->clip); |
Pekka Paalanen | 8ec4ab6 | 2012-10-10 12:49:32 +0300 | [diff] [blame] | 298 | region_init_infinite(&surface->input); |
Pekka Paalanen | 730d87e | 2012-02-09 16:39:38 +0200 | [diff] [blame] | 299 | pixman_region32_init(&surface->transform.opaque); |
Kristian Høgsberg | 496433b | 2011-11-15 13:50:21 -0500 | [diff] [blame] | 300 | wl_list_init(&surface->frame_callback_list); |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 301 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 302 | wl_list_init(&surface->geometry.transformation_list); |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 303 | wl_list_insert(&surface->geometry.transformation_list, |
| 304 | &surface->transform.position.link); |
| 305 | weston_matrix_init(&surface->transform.position.matrix); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 306 | pixman_region32_init(&surface->transform.boundingbox); |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 307 | surface->geometry.dirty = 1; |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 308 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 309 | surface->pending.buffer_destroy_listener.notify = |
| 310 | surface_handle_pending_buffer_destroy; |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 311 | pixman_region32_init(&surface->pending.damage); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 312 | pixman_region32_init(&surface->pending.opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 313 | region_init_infinite(&surface->pending.input); |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 314 | wl_list_init(&surface->pending.frame_callback_list); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 315 | |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 316 | return surface; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 317 | } |
| 318 | |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 319 | WL_EXPORT void |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 320 | weston_surface_set_color(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 321 | float red, float green, float blue, float alpha) |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 322 | { |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 323 | surface->compositor->renderer->surface_set_color(surface, red, green, blue, alpha); |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 324 | } |
| 325 | |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 326 | WL_EXPORT void |
| 327 | weston_surface_to_global_float(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 328 | float sx, float sy, float *x, float *y) |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 329 | { |
| 330 | if (surface->transform.enabled) { |
| 331 | struct weston_vector v = { { sx, sy, 0.0f, 1.0f } }; |
| 332 | |
| 333 | weston_matrix_transform(&surface->transform.matrix, &v); |
| 334 | |
| 335 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 336 | weston_log("warning: numerical instability in " |
Scott Moreau | 088c62e | 2013-02-11 04:45:38 -0700 | [diff] [blame] | 337 | "%s(), divisor = %g\n", __func__, |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 338 | v.f[3]); |
| 339 | *x = 0; |
| 340 | *y = 0; |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | *x = v.f[0] / v.f[3]; |
| 345 | *y = v.f[1] / v.f[3]; |
| 346 | } else { |
| 347 | *x = sx + surface->geometry.x; |
| 348 | *y = sy + surface->geometry.y; |
| 349 | } |
| 350 | } |
| 351 | |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 352 | WL_EXPORT void |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 353 | weston_transformed_coord(int width, int height, |
| 354 | enum wl_output_transform transform, |
| 355 | float sx, float sy, float *bx, float *by) |
| 356 | { |
| 357 | switch (transform) { |
| 358 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 359 | default: |
| 360 | *bx = sx; |
| 361 | *by = sy; |
| 362 | break; |
| 363 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 364 | *bx = width - sx; |
| 365 | *by = sy; |
| 366 | break; |
| 367 | case WL_OUTPUT_TRANSFORM_90: |
| 368 | *bx = height - sy; |
| 369 | *by = sx; |
| 370 | break; |
| 371 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 372 | *bx = height - sy; |
| 373 | *by = width - sx; |
| 374 | break; |
| 375 | case WL_OUTPUT_TRANSFORM_180: |
| 376 | *bx = width - sx; |
| 377 | *by = height - sy; |
| 378 | break; |
| 379 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 380 | *bx = sx; |
| 381 | *by = height - sy; |
| 382 | break; |
| 383 | case WL_OUTPUT_TRANSFORM_270: |
| 384 | *bx = sy; |
| 385 | *by = width - sx; |
| 386 | break; |
| 387 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 388 | *bx = sy; |
| 389 | *by = sx; |
| 390 | break; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | WL_EXPORT pixman_box32_t |
| 395 | weston_transformed_rect(int width, int height, |
| 396 | enum wl_output_transform transform, |
| 397 | pixman_box32_t rect) |
| 398 | { |
| 399 | float x1, x2, y1, y2; |
| 400 | |
| 401 | pixman_box32_t ret; |
| 402 | |
| 403 | weston_transformed_coord(width, height, transform, |
| 404 | rect.x1, rect.y1, &x1, &y1); |
| 405 | weston_transformed_coord(width, height, transform, |
| 406 | rect.x2, rect.y2, &x2, &y2); |
| 407 | |
| 408 | if (x1 <= x2) { |
| 409 | ret.x1 = x1; |
| 410 | ret.x2 = x2; |
| 411 | } else { |
| 412 | ret.x1 = x2; |
| 413 | ret.x2 = x1; |
| 414 | } |
| 415 | |
| 416 | if (y1 <= y2) { |
| 417 | ret.y1 = y1; |
| 418 | ret.y2 = y2; |
| 419 | } else { |
| 420 | ret.y1 = y2; |
| 421 | ret.y2 = y1; |
| 422 | } |
| 423 | |
| 424 | return ret; |
| 425 | } |
| 426 | |
| 427 | WL_EXPORT void |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 428 | weston_surface_to_buffer_float(struct weston_surface *surface, |
| 429 | float sx, float sy, float *bx, float *by) |
| 430 | { |
Ander Conselvan de Oliveira | 409eebf | 2012-12-05 15:14:04 +0200 | [diff] [blame] | 431 | weston_transformed_coord(surface->geometry.width, |
| 432 | surface->geometry.height, |
| 433 | surface->buffer_transform, |
| 434 | sx, sy, bx, by); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | WL_EXPORT pixman_box32_t |
| 438 | weston_surface_to_buffer_rect(struct weston_surface *surface, |
| 439 | pixman_box32_t rect) |
| 440 | { |
Ander Conselvan de Oliveira | 409eebf | 2012-12-05 15:14:04 +0200 | [diff] [blame] | 441 | return weston_transformed_rect(surface->geometry.width, |
| 442 | surface->geometry.height, |
| 443 | surface->buffer_transform, rect); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | WL_EXPORT void |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 447 | weston_surface_move_to_plane(struct weston_surface *surface, |
| 448 | struct weston_plane *plane) |
| 449 | { |
| 450 | if (surface->plane == plane) |
| 451 | return; |
| 452 | |
| 453 | weston_surface_damage_below(surface); |
| 454 | surface->plane = plane; |
| 455 | weston_surface_damage(surface); |
| 456 | } |
| 457 | |
| 458 | WL_EXPORT void |
Kristian Høgsberg | 323ee04 | 2012-02-17 12:45:43 -0500 | [diff] [blame] | 459 | weston_surface_damage_below(struct weston_surface *surface) |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 460 | { |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 461 | pixman_region32_t damage; |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 462 | |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 463 | pixman_region32_init(&damage); |
| 464 | pixman_region32_subtract(&damage, &surface->transform.boundingbox, |
| 465 | &surface->clip); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 466 | pixman_region32_union(&surface->plane->damage, |
| 467 | &surface->plane->damage, &damage); |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 468 | pixman_region32_fini(&damage); |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 469 | } |
| 470 | |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 471 | static struct wl_resource * |
| 472 | find_resource_for_client(struct wl_list *list, struct wl_client *client) |
| 473 | { |
| 474 | struct wl_resource *r; |
| 475 | |
| 476 | wl_list_for_each(r, list, link) { |
| 477 | if (r->client == client) |
| 478 | return r; |
| 479 | } |
| 480 | |
| 481 | return NULL; |
| 482 | } |
| 483 | |
| 484 | static void |
| 485 | weston_surface_update_output_mask(struct weston_surface *es, uint32_t mask) |
| 486 | { |
| 487 | uint32_t different = es->output_mask ^ mask; |
| 488 | uint32_t entered = mask & different; |
| 489 | uint32_t left = es->output_mask & different; |
| 490 | struct weston_output *output; |
| 491 | struct wl_resource *resource = NULL; |
| 492 | struct wl_client *client = es->surface.resource.client; |
| 493 | |
| 494 | es->output_mask = mask; |
| 495 | if (es->surface.resource.client == NULL) |
| 496 | return; |
| 497 | if (different == 0) |
| 498 | return; |
| 499 | |
| 500 | wl_list_for_each(output, &es->compositor->output_list, link) { |
| 501 | if (1 << output->id & different) |
| 502 | resource = |
| 503 | find_resource_for_client(&output->resource_list, |
| 504 | client); |
| 505 | if (resource == NULL) |
| 506 | continue; |
| 507 | if (1 << output->id & entered) |
| 508 | wl_surface_send_enter(&es->surface.resource, resource); |
| 509 | if (1 << output->id & left) |
| 510 | wl_surface_send_leave(&es->surface.resource, resource); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | static void |
| 515 | weston_surface_assign_output(struct weston_surface *es) |
| 516 | { |
| 517 | struct weston_compositor *ec = es->compositor; |
| 518 | struct weston_output *output, *new_output; |
| 519 | pixman_region32_t region; |
| 520 | uint32_t max, area, mask; |
| 521 | pixman_box32_t *e; |
| 522 | |
| 523 | new_output = NULL; |
| 524 | max = 0; |
| 525 | mask = 0; |
| 526 | pixman_region32_init(®ion); |
| 527 | wl_list_for_each(output, &ec->output_list, link) { |
| 528 | pixman_region32_intersect(®ion, &es->transform.boundingbox, |
| 529 | &output->region); |
| 530 | |
| 531 | e = pixman_region32_extents(®ion); |
| 532 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 533 | |
| 534 | if (area > 0) |
| 535 | mask |= 1 << output->id; |
| 536 | |
| 537 | if (area >= max) { |
| 538 | new_output = output; |
| 539 | max = area; |
| 540 | } |
| 541 | } |
| 542 | pixman_region32_fini(®ion); |
| 543 | |
| 544 | es->output = new_output; |
| 545 | weston_surface_update_output_mask(es, mask); |
| 546 | } |
| 547 | |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 548 | static void |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 549 | surface_compute_bbox(struct weston_surface *surface, int32_t sx, int32_t sy, |
| 550 | int32_t width, int32_t height, |
| 551 | pixman_region32_t *bbox) |
| 552 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 553 | float min_x = HUGE_VALF, min_y = HUGE_VALF; |
| 554 | float max_x = -HUGE_VALF, max_y = -HUGE_VALF; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 555 | int32_t s[4][2] = { |
| 556 | { sx, sy }, |
| 557 | { sx, sy + height }, |
| 558 | { sx + width, sy }, |
| 559 | { sx + width, sy + height } |
| 560 | }; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 561 | float int_x, int_y; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 562 | int i; |
| 563 | |
Pekka Paalanen | 7c7d464 | 2012-09-04 13:55:44 +0300 | [diff] [blame] | 564 | if (width == 0 || height == 0) { |
| 565 | /* avoid rounding empty bbox to 1x1 */ |
| 566 | pixman_region32_init(bbox); |
| 567 | return; |
| 568 | } |
| 569 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 570 | for (i = 0; i < 4; ++i) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 571 | float x, y; |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 572 | weston_surface_to_global_float(surface, |
| 573 | s[i][0], s[i][1], &x, &y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 574 | if (x < min_x) |
| 575 | min_x = x; |
| 576 | if (x > max_x) |
| 577 | max_x = x; |
| 578 | if (y < min_y) |
| 579 | min_y = y; |
| 580 | if (y > max_y) |
| 581 | max_y = y; |
| 582 | } |
| 583 | |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 584 | int_x = floorf(min_x); |
| 585 | int_y = floorf(min_y); |
| 586 | pixman_region32_init_rect(bbox, int_x, int_y, |
| 587 | ceilf(max_x) - int_x, ceilf(max_y) - int_y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 588 | } |
| 589 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 590 | static void |
| 591 | weston_surface_update_transform_disable(struct weston_surface *surface) |
| 592 | { |
| 593 | surface->transform.enabled = 0; |
| 594 | |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 595 | /* round off fractions when not transformed */ |
| 596 | surface->geometry.x = roundf(surface->geometry.x); |
| 597 | surface->geometry.y = roundf(surface->geometry.y); |
| 598 | |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 599 | /* Otherwise identity matrix, but with x and y translation. */ |
| 600 | surface->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 601 | surface->transform.position.matrix.d[12] = surface->geometry.x; |
| 602 | surface->transform.position.matrix.d[13] = surface->geometry.y; |
| 603 | |
| 604 | surface->transform.matrix = surface->transform.position.matrix; |
| 605 | |
Kristian Høgsberg | 9bcaaeb | 2013-02-28 14:56:43 -0500 | [diff] [blame] | 606 | surface->transform.inverse = surface->transform.position.matrix; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 607 | surface->transform.inverse.d[12] = -surface->geometry.x; |
| 608 | surface->transform.inverse.d[13] = -surface->geometry.y; |
| 609 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 610 | pixman_region32_init_rect(&surface->transform.boundingbox, |
| 611 | surface->geometry.x, |
| 612 | surface->geometry.y, |
| 613 | surface->geometry.width, |
| 614 | surface->geometry.height); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 615 | |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 616 | if (surface->alpha == 1.0) { |
Kristian Høgsberg | 3b4af20 | 2012-02-28 09:19:39 -0500 | [diff] [blame] | 617 | pixman_region32_copy(&surface->transform.opaque, |
| 618 | &surface->opaque); |
| 619 | pixman_region32_translate(&surface->transform.opaque, |
| 620 | surface->geometry.x, |
| 621 | surface->geometry.y); |
| 622 | } |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | static int |
| 626 | weston_surface_update_transform_enable(struct weston_surface *surface) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 627 | { |
| 628 | struct weston_matrix *matrix = &surface->transform.matrix; |
| 629 | struct weston_matrix *inverse = &surface->transform.inverse; |
| 630 | struct weston_transform *tform; |
| 631 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 632 | surface->transform.enabled = 1; |
| 633 | |
| 634 | /* Otherwise identity matrix, but with x and y translation. */ |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 635 | surface->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 636 | surface->transform.position.matrix.d[12] = surface->geometry.x; |
| 637 | surface->transform.position.matrix.d[13] = surface->geometry.y; |
| 638 | |
| 639 | weston_matrix_init(matrix); |
| 640 | wl_list_for_each(tform, &surface->geometry.transformation_list, link) |
| 641 | weston_matrix_multiply(matrix, &tform->matrix); |
| 642 | |
| 643 | if (weston_matrix_invert(inverse, matrix) < 0) { |
| 644 | /* Oops, bad total transformation, not invertible */ |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 645 | weston_log("error: weston_surface %p" |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 646 | " transformation not invertible.\n", surface); |
| 647 | return -1; |
| 648 | } |
| 649 | |
| 650 | surface_compute_bbox(surface, 0, 0, surface->geometry.width, |
| 651 | surface->geometry.height, |
| 652 | &surface->transform.boundingbox); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 653 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | WL_EXPORT void |
| 658 | weston_surface_update_transform(struct weston_surface *surface) |
| 659 | { |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 660 | if (!surface->geometry.dirty) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 661 | return; |
| 662 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 663 | surface->geometry.dirty = 0; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 664 | |
Kristian Høgsberg | 323ee04 | 2012-02-17 12:45:43 -0500 | [diff] [blame] | 665 | weston_surface_damage_below(surface); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 666 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 667 | pixman_region32_fini(&surface->transform.boundingbox); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 668 | pixman_region32_fini(&surface->transform.opaque); |
| 669 | pixman_region32_init(&surface->transform.opaque); |
| 670 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 671 | /* transform.position is always in transformation_list */ |
| 672 | if (surface->geometry.transformation_list.next == |
| 673 | &surface->transform.position.link && |
| 674 | surface->geometry.transformation_list.prev == |
| 675 | &surface->transform.position.link) { |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 676 | weston_surface_update_transform_disable(surface); |
| 677 | } else { |
| 678 | if (weston_surface_update_transform_enable(surface) < 0) |
| 679 | weston_surface_update_transform_disable(surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 680 | } |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 681 | |
Kristian Høgsberg | f1ea63f | 2012-07-18 12:02:51 -0400 | [diff] [blame] | 682 | weston_surface_damage_below(surface); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 683 | |
Ander Conselvan de Oliveira | 231ba17 | 2012-09-14 16:12:04 +0300 | [diff] [blame] | 684 | weston_surface_assign_output(surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 685 | } |
| 686 | |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 687 | WL_EXPORT void |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 688 | weston_surface_to_global_fixed(struct weston_surface *surface, |
| 689 | wl_fixed_t sx, wl_fixed_t sy, |
| 690 | wl_fixed_t *x, wl_fixed_t *y) |
| 691 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 692 | float xf, yf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 693 | |
| 694 | weston_surface_to_global_float(surface, |
| 695 | wl_fixed_to_double(sx), |
| 696 | wl_fixed_to_double(sy), |
| 697 | &xf, &yf); |
| 698 | *x = wl_fixed_from_double(xf); |
| 699 | *y = wl_fixed_from_double(yf); |
| 700 | } |
| 701 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 702 | WL_EXPORT void |
| 703 | weston_surface_from_global_float(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 704 | float x, float y, float *sx, float *sy) |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 705 | { |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 706 | if (surface->transform.enabled) { |
| 707 | struct weston_vector v = { { x, y, 0.0f, 1.0f } }; |
| 708 | |
| 709 | weston_matrix_transform(&surface->transform.inverse, &v); |
| 710 | |
| 711 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 712 | weston_log("warning: numerical instability in " |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 713 | "weston_surface_from_global(), divisor = %g\n", |
| 714 | v.f[3]); |
| 715 | *sx = 0; |
| 716 | *sy = 0; |
| 717 | return; |
| 718 | } |
| 719 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 720 | *sx = v.f[0] / v.f[3]; |
| 721 | *sy = v.f[1] / v.f[3]; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 722 | } else { |
Pekka Paalanen | ba3cf95 | 2012-01-25 16:22:05 +0200 | [diff] [blame] | 723 | *sx = x - surface->geometry.x; |
| 724 | *sy = y - surface->geometry.y; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 725 | } |
| 726 | } |
| 727 | |
| 728 | WL_EXPORT void |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 729 | weston_surface_from_global_fixed(struct weston_surface *surface, |
| 730 | wl_fixed_t x, wl_fixed_t y, |
| 731 | wl_fixed_t *sx, wl_fixed_t *sy) |
| 732 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 733 | float sxf, syf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 734 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 735 | weston_surface_from_global_float(surface, |
| 736 | wl_fixed_to_double(x), |
| 737 | wl_fixed_to_double(y), |
| 738 | &sxf, &syf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 739 | *sx = wl_fixed_from_double(sxf); |
| 740 | *sy = wl_fixed_from_double(syf); |
| 741 | } |
| 742 | |
| 743 | WL_EXPORT void |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 744 | weston_surface_from_global(struct weston_surface *surface, |
| 745 | int32_t x, int32_t y, int32_t *sx, int32_t *sy) |
| 746 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 747 | float sxf, syf; |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 748 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 749 | weston_surface_from_global_float(surface, x, y, &sxf, &syf); |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 750 | *sx = floorf(sxf); |
| 751 | *sy = floorf(syf); |
| 752 | } |
| 753 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 754 | WL_EXPORT void |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 755 | weston_surface_schedule_repaint(struct weston_surface *surface) |
| 756 | { |
| 757 | struct weston_output *output; |
| 758 | |
| 759 | wl_list_for_each(output, &surface->compositor->output_list, link) |
| 760 | if (surface->output_mask & (1 << output->id)) |
| 761 | weston_output_schedule_repaint(output); |
| 762 | } |
| 763 | |
| 764 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 765 | weston_surface_damage(struct weston_surface *surface) |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 766 | { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 767 | pixman_region32_union_rect(&surface->damage, &surface->damage, |
| 768 | 0, 0, surface->geometry.width, |
| 769 | surface->geometry.height); |
Pekka Paalanen | 2267d45 | 2012-01-26 13:12:45 +0200 | [diff] [blame] | 770 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 771 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 772 | } |
| 773 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 774 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 775 | weston_surface_configure(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 776 | float x, float y, int width, int height) |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 777 | { |
Pekka Paalanen | ba3cf95 | 2012-01-25 16:22:05 +0200 | [diff] [blame] | 778 | surface->geometry.x = x; |
| 779 | surface->geometry.y = y; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 780 | surface->geometry.width = width; |
| 781 | surface->geometry.height = height; |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 782 | surface->geometry.dirty = 1; |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 783 | } |
| 784 | |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 785 | WL_EXPORT void |
| 786 | weston_surface_set_position(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 787 | float x, float y) |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 788 | { |
| 789 | surface->geometry.x = x; |
| 790 | surface->geometry.y = y; |
| 791 | surface->geometry.dirty = 1; |
| 792 | } |
| 793 | |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 794 | WL_EXPORT int |
| 795 | weston_surface_is_mapped(struct weston_surface *surface) |
| 796 | { |
| 797 | if (surface->output) |
| 798 | return 1; |
| 799 | else |
| 800 | return 0; |
| 801 | } |
| 802 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 803 | WL_EXPORT int32_t |
| 804 | weston_surface_buffer_width(struct weston_surface *surface) |
| 805 | { |
| 806 | switch (surface->buffer_transform) { |
| 807 | case WL_OUTPUT_TRANSFORM_90: |
| 808 | case WL_OUTPUT_TRANSFORM_270: |
| 809 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 810 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 811 | return surface->buffer_ref.buffer->height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 812 | default: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 813 | return surface->buffer_ref.buffer->width; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 814 | } |
| 815 | } |
| 816 | |
| 817 | WL_EXPORT int32_t |
| 818 | weston_surface_buffer_height(struct weston_surface *surface) |
| 819 | { |
| 820 | switch (surface->buffer_transform) { |
| 821 | case WL_OUTPUT_TRANSFORM_90: |
| 822 | case WL_OUTPUT_TRANSFORM_270: |
| 823 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 824 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 825 | return surface->buffer_ref.buffer->width; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 826 | default: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 827 | return surface->buffer_ref.buffer->height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 831 | WL_EXPORT uint32_t |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 832 | weston_compositor_get_time(void) |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 833 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 834 | struct timeval tv; |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 835 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 836 | gettimeofday(&tv, NULL); |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 837 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 838 | return tv.tv_sec * 1000 + tv.tv_usec / 1000; |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 839 | } |
| 840 | |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 841 | static struct weston_surface * |
| 842 | weston_compositor_pick_surface(struct weston_compositor *compositor, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 843 | wl_fixed_t x, wl_fixed_t y, |
| 844 | wl_fixed_t *sx, wl_fixed_t *sy) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 845 | { |
| 846 | struct weston_surface *surface; |
| 847 | |
| 848 | wl_list_for_each(surface, &compositor->surface_list, link) { |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 849 | weston_surface_from_global_fixed(surface, x, y, sx, sy); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 850 | if (pixman_region32_contains_point(&surface->input, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 851 | wl_fixed_to_int(*sx), |
| 852 | wl_fixed_to_int(*sy), |
| 853 | NULL)) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 854 | return surface; |
| 855 | } |
| 856 | |
| 857 | return NULL; |
| 858 | } |
| 859 | |
| 860 | static void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 861 | weston_device_repick(struct weston_seat *seat) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 862 | { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 863 | const struct wl_pointer_grab_interface *interface; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 864 | struct weston_surface *surface, *focus; |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 865 | struct wl_pointer *pointer = seat->seat.pointer; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 866 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 867 | if (!pointer) |
Daniel Stone | e9e92d2 | 2012-06-04 11:40:47 +0100 | [diff] [blame] | 868 | return; |
| 869 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 870 | surface = weston_compositor_pick_surface(seat->compositor, |
| 871 | pointer->x, |
| 872 | pointer->y, |
| 873 | &pointer->current_x, |
| 874 | &pointer->current_y); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 875 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 876 | if (&surface->surface != pointer->current) { |
| 877 | interface = pointer->grab->interface; |
| 878 | pointer->current = &surface->surface; |
| 879 | interface->focus(pointer->grab, &surface->surface, |
| 880 | pointer->current_x, |
| 881 | pointer->current_y); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 882 | } |
| 883 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 884 | focus = (struct weston_surface *) pointer->grab->focus; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 885 | if (focus) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 886 | weston_surface_from_global_fixed(focus, |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 887 | pointer->x, |
| 888 | pointer->y, |
| 889 | &pointer->grab->x, |
| 890 | &pointer->grab->y); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 891 | } |
| 892 | |
Kristian Høgsberg | 4ff5a74 | 2012-06-18 16:48:27 -0400 | [diff] [blame] | 893 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 894 | weston_compositor_repick(struct weston_compositor *compositor) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 895 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 896 | struct weston_seat *seat; |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 897 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 898 | if (!compositor->focus) |
| 899 | return; |
| 900 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 901 | wl_list_for_each(seat, &compositor->seat_list, link) |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 902 | weston_device_repick(seat); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 903 | } |
| 904 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 905 | WL_EXPORT void |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 906 | weston_surface_unmap(struct weston_surface *surface) |
| 907 | { |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 908 | struct weston_seat *seat; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 909 | |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 910 | weston_surface_damage_below(surface); |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 911 | surface->output = NULL; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 912 | wl_list_remove(&surface->layer_link); |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 913 | |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 914 | wl_list_for_each(seat, &surface->compositor->seat_list, link) { |
Daniel Stone | e9e92d2 | 2012-06-04 11:40:47 +0100 | [diff] [blame] | 915 | if (seat->seat.keyboard && |
| 916 | seat->seat.keyboard->focus == &surface->surface) |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 917 | wl_keyboard_set_focus(seat->seat.keyboard, NULL); |
Daniel Stone | e9e92d2 | 2012-06-04 11:40:47 +0100 | [diff] [blame] | 918 | if (seat->seat.pointer && |
| 919 | seat->seat.pointer->focus == &surface->surface) |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 920 | wl_pointer_set_focus(seat->seat.pointer, |
| 921 | NULL, |
| 922 | wl_fixed_from_int(0), |
| 923 | wl_fixed_from_int(0)); |
| 924 | } |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 925 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 926 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 927 | } |
| 928 | |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 929 | struct weston_frame_callback { |
| 930 | struct wl_resource resource; |
| 931 | struct wl_list link; |
| 932 | }; |
| 933 | |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 934 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 935 | destroy_surface(struct wl_resource *resource) |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 936 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 937 | struct weston_surface *surface = |
| 938 | container_of(resource, |
| 939 | struct weston_surface, surface.resource); |
| 940 | struct weston_compositor *compositor = surface->compositor; |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 941 | struct weston_frame_callback *cb, *next; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 942 | |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 943 | if (weston_surface_is_mapped(surface)) |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 944 | weston_surface_unmap(surface); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 945 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 946 | wl_list_for_each_safe(cb, next, |
| 947 | &surface->pending.frame_callback_list, link) |
| 948 | wl_resource_destroy(&cb->resource); |
| 949 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 950 | pixman_region32_fini(&surface->pending.input); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 951 | pixman_region32_fini(&surface->pending.opaque); |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 952 | pixman_region32_fini(&surface->pending.damage); |
| 953 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 954 | if (surface->pending.buffer) |
| 955 | wl_list_remove(&surface->pending.buffer_destroy_listener.link); |
| 956 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 957 | weston_buffer_reference(&surface->buffer_ref, NULL); |
Kristian Høgsberg | 3f8f39c | 2009-09-18 17:05:13 -0400 | [diff] [blame] | 958 | |
Kristian Høgsberg | 4226385 | 2012-09-06 21:59:29 -0400 | [diff] [blame] | 959 | compositor->renderer->destroy_surface(surface); |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 960 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 961 | pixman_region32_fini(&surface->transform.boundingbox); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 962 | pixman_region32_fini(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 963 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 964 | pixman_region32_fini(&surface->clip); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 965 | pixman_region32_fini(&surface->input); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 966 | |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 967 | wl_list_for_each_safe(cb, next, &surface->frame_callback_list, link) |
| 968 | wl_resource_destroy(&cb->resource); |
| 969 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 970 | free(surface); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 971 | } |
| 972 | |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 973 | WL_EXPORT void |
| 974 | weston_surface_destroy(struct weston_surface *surface) |
| 975 | { |
| 976 | /* Not a valid way to destroy a client surface */ |
| 977 | assert(surface->surface.resource.client == NULL); |
| 978 | |
Kristian Høgsberg | 9a050af | 2012-06-07 18:17:42 -0400 | [diff] [blame] | 979 | wl_signal_emit(&surface->surface.resource.destroy_signal, |
| 980 | &surface->surface.resource); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 981 | destroy_surface(&surface->surface.resource); |
| 982 | } |
| 983 | |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 984 | static void |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 985 | weston_buffer_reference_handle_destroy(struct wl_listener *listener, |
| 986 | void *data) |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 987 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 988 | struct weston_buffer_reference *ref = |
| 989 | container_of(listener, struct weston_buffer_reference, |
| 990 | destroy_listener); |
| 991 | |
| 992 | assert((struct wl_buffer *)data == ref->buffer); |
| 993 | ref->buffer = NULL; |
| 994 | } |
| 995 | |
| 996 | WL_EXPORT void |
| 997 | weston_buffer_reference(struct weston_buffer_reference *ref, |
| 998 | struct wl_buffer *buffer) |
| 999 | { |
| 1000 | if (ref->buffer && buffer != ref->buffer) { |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame^] | 1001 | ref->buffer->busy_count--; |
| 1002 | if (ref->buffer->busy_count == 0) { |
| 1003 | assert(ref->buffer->resource.client != NULL); |
| 1004 | wl_resource_queue_event(&ref->buffer->resource, |
| 1005 | WL_BUFFER_RELEASE); |
| 1006 | } |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1007 | wl_list_remove(&ref->destroy_listener.link); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1008 | } |
| 1009 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1010 | if (buffer && buffer != ref->buffer) { |
Kristian Høgsberg | b7b77e6 | 2012-09-05 22:38:18 -0400 | [diff] [blame] | 1011 | buffer->busy_count++; |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1012 | wl_signal_add(&buffer->resource.destroy_signal, |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1013 | &ref->destroy_listener); |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 1014 | } |
| 1015 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1016 | ref->buffer = buffer; |
| 1017 | ref->destroy_listener.notify = weston_buffer_reference_handle_destroy; |
| 1018 | } |
| 1019 | |
| 1020 | static void |
| 1021 | weston_surface_attach(struct weston_surface *surface, struct wl_buffer *buffer) |
| 1022 | { |
| 1023 | weston_buffer_reference(&surface->buffer_ref, buffer); |
| 1024 | |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 1025 | if (!buffer) { |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1026 | if (weston_surface_is_mapped(surface)) |
| 1027 | weston_surface_unmap(surface); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1028 | } |
| 1029 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1030 | surface->compositor->renderer->attach(surface, buffer); |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 1031 | } |
| 1032 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1033 | WL_EXPORT void |
| 1034 | weston_surface_restack(struct weston_surface *surface, struct wl_list *below) |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1035 | { |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1036 | wl_list_remove(&surface->layer_link); |
| 1037 | wl_list_insert(below, &surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1038 | weston_surface_damage_below(surface); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1039 | weston_surface_damage(surface); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1042 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1043 | weston_compositor_damage_all(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1044 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1045 | struct weston_output *output; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1046 | |
| 1047 | wl_list_for_each(output, &compositor->output_list, link) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1048 | weston_output_damage(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1049 | } |
| 1050 | |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 1051 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1052 | weston_output_damage(struct weston_output *output) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1053 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1054 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1055 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1056 | pixman_region32_union(&compositor->primary_plane.damage, |
| 1057 | &compositor->primary_plane.damage, |
| 1058 | &output->region); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1059 | weston_output_schedule_repaint(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1060 | } |
| 1061 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 1062 | static void |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1063 | surface_accumulate_damage(struct weston_surface *surface, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1064 | pixman_region32_t *opaque) |
| 1065 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1066 | if (surface->buffer_ref.buffer && |
| 1067 | wl_buffer_is_shm(surface->buffer_ref.buffer)) |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 1068 | surface->compositor->renderer->flush_damage(surface); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1069 | |
| 1070 | if (surface->transform.enabled) { |
| 1071 | pixman_box32_t *extents; |
| 1072 | |
| 1073 | extents = pixman_region32_extents(&surface->damage); |
| 1074 | surface_compute_bbox(surface, extents->x1, extents->y1, |
| 1075 | extents->x2 - extents->x1, |
| 1076 | extents->y2 - extents->y1, |
| 1077 | &surface->damage); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1078 | pixman_region32_translate(&surface->damage, |
| 1079 | -surface->plane->x, |
| 1080 | -surface->plane->y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1081 | } else { |
| 1082 | pixman_region32_translate(&surface->damage, |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1083 | surface->geometry.x - surface->plane->x, |
| 1084 | surface->geometry.y - surface->plane->y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1085 | } |
| 1086 | |
Ander Conselvan de Oliveira | 4bcf3a5 | 2012-10-31 17:55:45 +0200 | [diff] [blame] | 1087 | pixman_region32_subtract(&surface->damage, |
| 1088 | &surface->damage, &surface->plane->opaque); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1089 | pixman_region32_union(&surface->plane->damage, |
| 1090 | &surface->plane->damage, &surface->damage); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1091 | empty_region(&surface->damage); |
| 1092 | pixman_region32_copy(&surface->clip, opaque); |
Ander Conselvan de Oliveira | 4bcf3a5 | 2012-10-31 17:55:45 +0200 | [diff] [blame] | 1093 | pixman_region32_union(&surface->plane->opaque, |
| 1094 | &surface->plane->opaque, |
| 1095 | &surface->transform.opaque); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 1096 | pixman_region32_union(opaque, opaque, &surface->transform.opaque); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1097 | } |
| 1098 | |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1099 | static void |
Rob Bradford | 0fb7975 | 2012-08-02 15:36:57 +0100 | [diff] [blame] | 1100 | weston_output_repaint(struct weston_output *output, uint32_t msecs) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1101 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1102 | struct weston_compositor *ec = output->compositor; |
Kristian Høgsberg | 681f9f4 | 2012-01-26 10:55:10 -0500 | [diff] [blame] | 1103 | struct weston_surface *es; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1104 | struct weston_layer *layer; |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 1105 | struct weston_animation *animation, *next; |
| 1106 | struct weston_frame_callback *cb, *cnext; |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 1107 | struct wl_list frame_callback_list; |
Ander Conselvan de Oliveira | 8ea818f | 2012-09-14 16:12:03 +0300 | [diff] [blame] | 1108 | pixman_region32_t opaque, output_damage; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1109 | |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 1110 | weston_compositor_update_drag_surfaces(ec); |
| 1111 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1112 | /* Rebuild the surface list and update surface transforms up front. */ |
| 1113 | wl_list_init(&ec->surface_list); |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 1114 | wl_list_init(&frame_callback_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1115 | wl_list_for_each(layer, &ec->layer_list, link) { |
| 1116 | wl_list_for_each(es, &layer->surface_list, layer_link) { |
| 1117 | weston_surface_update_transform(es); |
| 1118 | wl_list_insert(ec->surface_list.prev, &es->link); |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 1119 | if (es->output == output) { |
| 1120 | wl_list_insert_list(&frame_callback_list, |
| 1121 | &es->frame_callback_list); |
| 1122 | wl_list_init(&es->frame_callback_list); |
| 1123 | } |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1124 | } |
| 1125 | } |
Pekka Paalanen | 15d60ef | 2012-01-27 14:38:33 +0200 | [diff] [blame] | 1126 | |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 1127 | if (output->assign_planes && !output->disable_planes) |
Jesse Barnes | 5308a5e | 2012-02-09 13:12:57 -0800 | [diff] [blame] | 1128 | output->assign_planes(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 1129 | else |
| 1130 | wl_list_for_each(es, &ec->surface_list, link) |
| 1131 | weston_surface_move_to_plane(es, &ec->primary_plane); |
| 1132 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 1133 | pixman_region32_init(&opaque); |
| 1134 | |
Ander Conselvan de Oliveira | 4bcf3a5 | 2012-10-31 17:55:45 +0200 | [diff] [blame] | 1135 | pixman_region32_fini(&ec->primary_plane.opaque); |
| 1136 | pixman_region32_init(&ec->primary_plane.opaque); |
| 1137 | |
Pekka Paalanen | ccfeae2 | 2012-12-04 15:58:14 +0200 | [diff] [blame] | 1138 | wl_list_for_each(es, &ec->surface_list, link) { |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1139 | surface_accumulate_damage(es, &opaque); |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 1140 | |
Pekka Paalanen | ccfeae2 | 2012-12-04 15:58:14 +0200 | [diff] [blame] | 1141 | /* Both the renderer and the backend have seen the buffer |
| 1142 | * by now. If renderer needs the buffer, it has its own |
| 1143 | * reference set. If the backend wants to keep the buffer |
| 1144 | * around for migrating the surface into a non-primary plane |
| 1145 | * later, keep_buffer is true. Otherwise, drop the core |
| 1146 | * reference now, and allow early buffer release. This enables |
| 1147 | * clients to use single-buffering. |
| 1148 | */ |
| 1149 | if (!es->keep_buffer) |
| 1150 | weston_buffer_reference(&es->buffer_ref, NULL); |
| 1151 | } |
| 1152 | |
Kristian Høgsberg | 7341e9b | 2011-07-01 22:12:11 -0400 | [diff] [blame] | 1153 | pixman_region32_fini(&opaque); |
Kristian Høgsberg | 53df1d8 | 2011-06-23 21:11:19 -0400 | [diff] [blame] | 1154 | |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 1155 | pixman_region32_init(&output_damage); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 1156 | pixman_region32_intersect(&output_damage, |
| 1157 | &ec->primary_plane.damage, &output->region); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 1158 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 1159 | if (output->dirty) |
| 1160 | weston_output_update_matrix(output); |
| 1161 | |
Kristian Høgsberg | d7c1726 | 2012-09-05 21:54:15 -0400 | [diff] [blame] | 1162 | output->repaint(output, &output_damage); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1163 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 1164 | pixman_region32_fini(&output_damage); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1165 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1166 | output->repaint_needed = 0; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 1167 | |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 1168 | weston_compositor_repick(ec); |
| 1169 | wl_event_loop_dispatch(ec->input_loop, 0); |
| 1170 | |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 1171 | wl_list_for_each_safe(cb, cnext, &frame_callback_list, link) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1172 | wl_callback_send_done(&cb->resource, msecs); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1173 | wl_resource_destroy(&cb->resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1174 | } |
| 1175 | |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 1176 | wl_list_for_each_safe(animation, next, &output->animation_list, link) { |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 1177 | animation->frame_counter++; |
Scott Moreau | 94b0b0c | 2012-06-14 01:01:56 -0600 | [diff] [blame] | 1178 | animation->frame(animation, output, msecs); |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 1179 | } |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1180 | } |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 1181 | |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1182 | static int |
| 1183 | weston_compositor_read_input(int fd, uint32_t mask, void *data) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1184 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1185 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 1186 | |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1187 | wl_event_loop_dispatch(compositor->input_loop, 0); |
| 1188 | |
| 1189 | return 1; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | WL_EXPORT void |
Rob Bradford | 0fb7975 | 2012-08-02 15:36:57 +0100 | [diff] [blame] | 1193 | weston_output_finish_frame(struct weston_output *output, uint32_t msecs) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1194 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1195 | struct weston_compositor *compositor = output->compositor; |
| 1196 | struct wl_event_loop *loop = |
| 1197 | wl_display_get_event_loop(compositor->wl_display); |
| 1198 | int fd; |
| 1199 | |
Kristian Høgsberg | e9d0492 | 2012-06-19 23:54:26 -0400 | [diff] [blame] | 1200 | output->frame_time = msecs; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1201 | if (output->repaint_needed) { |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 1202 | weston_output_repaint(output, msecs); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1203 | return; |
| 1204 | } |
| 1205 | |
| 1206 | output->repaint_scheduled = 0; |
| 1207 | if (compositor->input_loop_source) |
| 1208 | return; |
| 1209 | |
| 1210 | fd = wl_event_loop_get_fd(compositor->input_loop); |
| 1211 | compositor->input_loop_source = |
| 1212 | wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, |
| 1213 | weston_compositor_read_input, compositor); |
| 1214 | } |
| 1215 | |
| 1216 | static void |
| 1217 | idle_repaint(void *data) |
| 1218 | { |
| 1219 | struct weston_output *output = data; |
| 1220 | |
| 1221 | weston_output_finish_frame(output, weston_compositor_get_time()); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1222 | } |
| 1223 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1224 | WL_EXPORT void |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1225 | weston_layer_init(struct weston_layer *layer, struct wl_list *below) |
| 1226 | { |
| 1227 | wl_list_init(&layer->surface_list); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1228 | if (below != NULL) |
| 1229 | wl_list_insert(below, &layer->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1233 | weston_output_schedule_repaint(struct weston_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1234 | { |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1235 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1236 | struct wl_event_loop *loop; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 1237 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1238 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1239 | return; |
| 1240 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1241 | loop = wl_display_get_event_loop(compositor->wl_display); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1242 | output->repaint_needed = 1; |
| 1243 | if (output->repaint_scheduled) |
| 1244 | return; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 1245 | |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1246 | wl_event_loop_add_idle(loop, idle_repaint, output); |
| 1247 | output->repaint_scheduled = 1; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1248 | |
| 1249 | if (compositor->input_loop_source) { |
| 1250 | wl_event_source_remove(compositor->input_loop_source); |
| 1251 | compositor->input_loop_source = NULL; |
| 1252 | } |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1253 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 1254 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1255 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1256 | weston_compositor_schedule_repaint(struct weston_compositor *compositor) |
| 1257 | { |
| 1258 | struct weston_output *output; |
| 1259 | |
| 1260 | wl_list_for_each(output, &compositor->output_list, link) |
| 1261 | weston_output_schedule_repaint(output); |
| 1262 | } |
| 1263 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 1264 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1265 | surface_destroy(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1266 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1267 | wl_resource_destroy(resource); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1268 | } |
| 1269 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 1270 | static void |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1271 | surface_attach(struct wl_client *client, |
| 1272 | struct wl_resource *resource, |
| 1273 | struct wl_resource *buffer_resource, int32_t sx, int32_t sy) |
| 1274 | { |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1275 | struct weston_surface *surface = resource->data; |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1276 | struct wl_buffer *buffer = NULL; |
| 1277 | |
| 1278 | if (buffer_resource) |
| 1279 | buffer = buffer_resource->data; |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 1280 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1281 | /* Attach, attach, without commit in between does not send |
| 1282 | * wl_buffer.release. */ |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1283 | if (surface->pending.buffer) |
| 1284 | wl_list_remove(&surface->pending.buffer_destroy_listener.link); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1285 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1286 | surface->pending.sx = sx; |
| 1287 | surface->pending.sy = sy; |
| 1288 | surface->pending.buffer = buffer; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 1289 | surface->pending.newly_attached = 1; |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1290 | if (buffer) { |
| 1291 | wl_signal_add(&buffer->resource.destroy_signal, |
| 1292 | &surface->pending.buffer_destroy_listener); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1293 | } |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 1294 | } |
| 1295 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 1296 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1297 | surface_damage(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1298 | struct wl_resource *resource, |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1299 | int32_t x, int32_t y, int32_t width, int32_t height) |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 1300 | { |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 1301 | struct weston_surface *surface = resource->data; |
Kristian Høgsberg | 9d69f8e | 2010-09-03 14:46:38 -0400 | [diff] [blame] | 1302 | |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 1303 | pixman_region32_union_rect(&surface->pending.damage, |
| 1304 | &surface->pending.damage, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1305 | x, y, width, height); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1306 | } |
| 1307 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1308 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1309 | destroy_frame_callback(struct wl_resource *resource) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1310 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1311 | struct weston_frame_callback *cb = resource->data; |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1312 | |
| 1313 | wl_list_remove(&cb->link); |
Pekka Paalanen | 8c19645 | 2011-11-15 11:45:42 +0200 | [diff] [blame] | 1314 | free(cb); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | static void |
| 1318 | surface_frame(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1319 | struct wl_resource *resource, uint32_t callback) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1320 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1321 | struct weston_frame_callback *cb; |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 1322 | struct weston_surface *surface = resource->data; |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1323 | |
| 1324 | cb = malloc(sizeof *cb); |
| 1325 | if (cb == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 1326 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1327 | return; |
| 1328 | } |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 1329 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1330 | cb->resource.object.interface = &wl_callback_interface; |
| 1331 | cb->resource.object.id = callback; |
| 1332 | cb->resource.destroy = destroy_frame_callback; |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1333 | cb->resource.client = client; |
| 1334 | cb->resource.data = cb; |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1335 | |
| 1336 | wl_client_add_resource(client, &cb->resource); |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 1337 | wl_list_insert(surface->pending.frame_callback_list.prev, &cb->link); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1338 | } |
| 1339 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1340 | static void |
| 1341 | surface_set_opaque_region(struct wl_client *client, |
| 1342 | struct wl_resource *resource, |
| 1343 | struct wl_resource *region_resource) |
| 1344 | { |
| 1345 | struct weston_surface *surface = resource->data; |
| 1346 | struct weston_region *region; |
| 1347 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1348 | if (region_resource) { |
| 1349 | region = region_resource->data; |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 1350 | pixman_region32_copy(&surface->pending.opaque, |
| 1351 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1352 | } else { |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 1353 | empty_region(&surface->pending.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1354 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | static void |
| 1358 | surface_set_input_region(struct wl_client *client, |
| 1359 | struct wl_resource *resource, |
| 1360 | struct wl_resource *region_resource) |
| 1361 | { |
| 1362 | struct weston_surface *surface = resource->data; |
Kristian Høgsberg | 010f98b | 2012-02-23 17:30:45 -0500 | [diff] [blame] | 1363 | struct weston_region *region; |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1364 | |
| 1365 | if (region_resource) { |
| 1366 | region = region_resource->data; |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1367 | pixman_region32_copy(&surface->pending.input, |
| 1368 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1369 | } else { |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1370 | pixman_region32_fini(&surface->pending.input); |
| 1371 | region_init_infinite(&surface->pending.input); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1372 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1373 | } |
| 1374 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1375 | static int |
| 1376 | surface_pending_buffer_has_different_size(struct weston_surface *surface) |
| 1377 | { |
| 1378 | int width, height; |
| 1379 | |
| 1380 | switch (surface->pending.buffer_transform) { |
| 1381 | case WL_OUTPUT_TRANSFORM_90: |
| 1382 | case WL_OUTPUT_TRANSFORM_270: |
| 1383 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 1384 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 1385 | height = surface->pending.buffer->width; |
| 1386 | width = surface->pending.buffer->height; |
| 1387 | break; |
| 1388 | default: |
| 1389 | width = surface->pending.buffer->width; |
| 1390 | height = surface->pending.buffer->height; |
| 1391 | } |
| 1392 | |
| 1393 | if (width == surface->geometry.width && |
| 1394 | height == surface->geometry.height) |
| 1395 | return 0; |
| 1396 | else |
| 1397 | return 1; |
| 1398 | } |
| 1399 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1400 | static void |
| 1401 | surface_commit(struct wl_client *client, struct wl_resource *resource) |
| 1402 | { |
| 1403 | struct weston_surface *surface = resource->data; |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 1404 | pixman_region32_t opaque; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 1405 | int buffer_width = 0; |
| 1406 | int buffer_height = 0; |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 1407 | |
| 1408 | if (surface->pending.sx || surface->pending.sy || |
| 1409 | (surface->pending.buffer && |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1410 | surface_pending_buffer_has_different_size(surface))) |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 1411 | surface->geometry.dirty = 1; |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1412 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1413 | /* wl_surface.set_buffer_rotation */ |
| 1414 | surface->buffer_transform = surface->pending.buffer_transform; |
| 1415 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1416 | /* wl_surface.attach */ |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 1417 | if (surface->pending.buffer || surface->pending.newly_attached) |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1418 | weston_surface_attach(surface, surface->pending.buffer); |
| 1419 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 1420 | if (surface->buffer_ref.buffer) { |
| 1421 | buffer_width = weston_surface_buffer_width(surface); |
| 1422 | buffer_height = weston_surface_buffer_height(surface); |
| 1423 | } |
| 1424 | |
| 1425 | if (surface->configure && surface->pending.newly_attached) |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1426 | surface->configure(surface, surface->pending.sx, |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 1427 | surface->pending.sy, buffer_width, buffer_height); |
| 1428 | |
Daniel Stone | b4f4a59 | 2012-11-07 17:51:44 +1100 | [diff] [blame] | 1429 | surface->pending.sx = 0; |
| 1430 | surface->pending.sy = 0; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 1431 | surface->pending.newly_attached = 0; |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 1432 | |
| 1433 | /* wl_surface.damage */ |
| 1434 | pixman_region32_union(&surface->damage, &surface->damage, |
| 1435 | &surface->pending.damage); |
Kristian Høgsberg | 4d0214c | 2012-11-08 11:36:02 -0500 | [diff] [blame] | 1436 | pixman_region32_intersect_rect(&surface->damage, &surface->damage, |
| 1437 | 0, 0, |
| 1438 | surface->geometry.width, |
| 1439 | surface->geometry.height); |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 1440 | empty_region(&surface->pending.damage); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 1441 | |
| 1442 | /* wl_surface.set_opaque_region */ |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 1443 | pixman_region32_init_rect(&opaque, 0, 0, |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 1444 | surface->geometry.width, |
| 1445 | surface->geometry.height); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 1446 | pixman_region32_intersect(&opaque, |
| 1447 | &opaque, &surface->pending.opaque); |
| 1448 | |
| 1449 | if (!pixman_region32_equal(&opaque, &surface->opaque)) { |
| 1450 | pixman_region32_copy(&surface->opaque, &opaque); |
| 1451 | surface->geometry.dirty = 1; |
| 1452 | } |
| 1453 | |
| 1454 | pixman_region32_fini(&opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1455 | |
| 1456 | /* wl_surface.set_input_region */ |
| 1457 | pixman_region32_fini(&surface->input); |
| 1458 | pixman_region32_init_rect(&surface->input, 0, 0, |
| 1459 | surface->geometry.width, |
| 1460 | surface->geometry.height); |
| 1461 | pixman_region32_intersect(&surface->input, |
| 1462 | &surface->input, &surface->pending.input); |
| 1463 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 1464 | /* wl_surface.frame */ |
| 1465 | wl_list_insert_list(&surface->frame_callback_list, |
| 1466 | &surface->pending.frame_callback_list); |
| 1467 | wl_list_init(&surface->pending.frame_callback_list); |
| 1468 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1469 | weston_surface_schedule_repaint(surface); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1470 | } |
| 1471 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1472 | static void |
| 1473 | surface_set_buffer_transform(struct wl_client *client, |
| 1474 | struct wl_resource *resource, int transform) |
| 1475 | { |
| 1476 | struct weston_surface *surface = resource->data; |
| 1477 | |
| 1478 | surface->pending.buffer_transform = transform; |
| 1479 | } |
| 1480 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1481 | static const struct wl_surface_interface surface_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1482 | surface_destroy, |
| 1483 | surface_attach, |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1484 | surface_damage, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1485 | surface_frame, |
| 1486 | surface_set_opaque_region, |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1487 | surface_set_input_region, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1488 | surface_commit, |
| 1489 | surface_set_buffer_transform |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1490 | }; |
| 1491 | |
| 1492 | static void |
| 1493 | compositor_create_surface(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1494 | struct wl_resource *resource, uint32_t id) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1495 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1496 | struct weston_compositor *ec = resource->data; |
| 1497 | struct weston_surface *surface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1498 | |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 1499 | surface = weston_surface_create(ec); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 1500 | if (surface == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 1501 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1502 | return; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 1503 | } |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1504 | |
Kristian Høgsberg | b313b02 | 2010-12-01 17:07:41 -0500 | [diff] [blame] | 1505 | surface->surface.resource.destroy = destroy_surface; |
Kristian Høgsberg | f66d0f4 | 2010-09-02 20:27:16 -0400 | [diff] [blame] | 1506 | |
Kristian Høgsberg | b313b02 | 2010-12-01 17:07:41 -0500 | [diff] [blame] | 1507 | surface->surface.resource.object.id = id; |
| 1508 | surface->surface.resource.object.interface = &wl_surface_interface; |
| 1509 | surface->surface.resource.object.implementation = |
Kristian Høgsberg | f66d0f4 | 2010-09-02 20:27:16 -0400 | [diff] [blame] | 1510 | (void (**)(void)) &surface_interface; |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1511 | surface->surface.resource.data = surface; |
Kristian Høgsberg | f66d0f4 | 2010-09-02 20:27:16 -0400 | [diff] [blame] | 1512 | |
Kristian Høgsberg | b313b02 | 2010-12-01 17:07:41 -0500 | [diff] [blame] | 1513 | wl_client_add_resource(client, &surface->surface.resource); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1514 | } |
| 1515 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1516 | static void |
| 1517 | destroy_region(struct wl_resource *resource) |
| 1518 | { |
| 1519 | struct weston_region *region = |
| 1520 | container_of(resource, struct weston_region, resource); |
| 1521 | |
| 1522 | pixman_region32_fini(®ion->region); |
| 1523 | free(region); |
| 1524 | } |
| 1525 | |
| 1526 | static void |
| 1527 | region_destroy(struct wl_client *client, struct wl_resource *resource) |
| 1528 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1529 | wl_resource_destroy(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | static void |
| 1533 | region_add(struct wl_client *client, struct wl_resource *resource, |
| 1534 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 1535 | { |
| 1536 | struct weston_region *region = resource->data; |
| 1537 | |
| 1538 | pixman_region32_union_rect(®ion->region, ®ion->region, |
| 1539 | x, y, width, height); |
| 1540 | } |
| 1541 | |
| 1542 | static void |
| 1543 | region_subtract(struct wl_client *client, struct wl_resource *resource, |
| 1544 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 1545 | { |
| 1546 | struct weston_region *region = resource->data; |
| 1547 | pixman_region32_t rect; |
| 1548 | |
| 1549 | pixman_region32_init_rect(&rect, x, y, width, height); |
| 1550 | pixman_region32_subtract(®ion->region, ®ion->region, &rect); |
| 1551 | pixman_region32_fini(&rect); |
| 1552 | } |
| 1553 | |
| 1554 | static const struct wl_region_interface region_interface = { |
| 1555 | region_destroy, |
| 1556 | region_add, |
| 1557 | region_subtract |
| 1558 | }; |
| 1559 | |
| 1560 | static void |
| 1561 | compositor_create_region(struct wl_client *client, |
| 1562 | struct wl_resource *resource, uint32_t id) |
| 1563 | { |
| 1564 | struct weston_region *region; |
| 1565 | |
| 1566 | region = malloc(sizeof *region); |
| 1567 | if (region == NULL) { |
| 1568 | wl_resource_post_no_memory(resource); |
| 1569 | return; |
| 1570 | } |
| 1571 | |
| 1572 | region->resource.destroy = destroy_region; |
| 1573 | |
| 1574 | region->resource.object.id = id; |
| 1575 | region->resource.object.interface = &wl_region_interface; |
| 1576 | region->resource.object.implementation = |
| 1577 | (void (**)(void)) ®ion_interface; |
| 1578 | region->resource.data = region; |
| 1579 | |
| 1580 | pixman_region32_init(®ion->region); |
| 1581 | |
| 1582 | wl_client_add_resource(client, ®ion->resource); |
| 1583 | } |
| 1584 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1585 | static const struct wl_compositor_interface compositor_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1586 | compositor_create_surface, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1587 | compositor_create_region |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1588 | }; |
| 1589 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1590 | static void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 1591 | weston_compositor_dpms(struct weston_compositor *compositor, |
| 1592 | enum dpms_enum state) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1593 | { |
| 1594 | struct weston_output *output; |
| 1595 | |
| 1596 | wl_list_for_each(output, &compositor->output_list, link) |
| 1597 | if (output->set_dpms) |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 1598 | output->set_dpms(output, state); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1599 | } |
| 1600 | |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 1601 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 1602 | weston_compositor_wake(struct weston_compositor *compositor) |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 1603 | { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 1604 | switch (compositor->state) { |
| 1605 | case WESTON_COMPOSITOR_SLEEPING: |
| 1606 | weston_compositor_dpms(compositor, WESTON_DPMS_ON); |
| 1607 | /* fall through */ |
| 1608 | case WESTON_COMPOSITOR_IDLE: |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 1609 | wl_signal_emit(&compositor->wake_signal, compositor); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 1610 | /* fall through */ |
| 1611 | default: |
| 1612 | compositor->state = WESTON_COMPOSITOR_ACTIVE; |
| 1613 | wl_event_source_timer_update(compositor->idle_source, |
| 1614 | compositor->idle_time * 1000); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 1615 | } |
| 1616 | } |
| 1617 | |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 1618 | WL_EXPORT void |
| 1619 | weston_compositor_sleep(struct weston_compositor *compositor) |
| 1620 | { |
| 1621 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING) |
| 1622 | return; |
| 1623 | |
| 1624 | compositor->state = WESTON_COMPOSITOR_SLEEPING; |
| 1625 | weston_compositor_dpms(compositor, WESTON_DPMS_OFF); |
| 1626 | } |
| 1627 | |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1628 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1629 | weston_compositor_idle_inhibit(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1630 | { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 1631 | weston_compositor_wake(compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1632 | compositor->idle_inhibit++; |
| 1633 | } |
| 1634 | |
| 1635 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1636 | weston_compositor_idle_release(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1637 | { |
| 1638 | compositor->idle_inhibit--; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 1639 | weston_compositor_wake(compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | static int |
| 1643 | idle_handler(void *data) |
| 1644 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1645 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1646 | |
| 1647 | if (compositor->idle_inhibit) |
| 1648 | return 1; |
| 1649 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 1650 | compositor->state = WESTON_COMPOSITOR_IDLE; |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 1651 | wl_signal_emit(&compositor->idle_signal, compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1652 | |
| 1653 | return 1; |
| 1654 | } |
| 1655 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1656 | WL_EXPORT void |
| 1657 | weston_plane_init(struct weston_plane *plane, int32_t x, int32_t y) |
| 1658 | { |
| 1659 | pixman_region32_init(&plane->damage); |
Ander Conselvan de Oliveira | 4bcf3a5 | 2012-10-31 17:55:45 +0200 | [diff] [blame] | 1660 | pixman_region32_init(&plane->opaque); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1661 | plane->x = x; |
| 1662 | plane->y = y; |
| 1663 | } |
| 1664 | |
| 1665 | WL_EXPORT void |
| 1666 | weston_plane_release(struct weston_plane *plane) |
| 1667 | { |
| 1668 | pixman_region32_fini(&plane->damage); |
Ander Conselvan de Oliveira | 4bcf3a5 | 2012-10-31 17:55:45 +0200 | [diff] [blame] | 1669 | pixman_region32_fini(&plane->opaque); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1670 | } |
| 1671 | |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 1672 | static void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1673 | weston_seat_update_drag_surface(struct weston_seat *seat, int dx, int dy); |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 1674 | |
Kristian Høgsberg | 1f37601 | 2012-05-09 11:43:11 -0400 | [diff] [blame] | 1675 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1676 | clip_pointer_motion(struct weston_seat *seat, wl_fixed_t *fx, wl_fixed_t *fy) |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 1677 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1678 | struct weston_compositor *ec = seat->compositor; |
Kristian Høgsberg | 34829de | 2012-05-09 22:21:14 -0400 | [diff] [blame] | 1679 | struct weston_output *output, *prev = NULL; |
| 1680 | int x, y, old_x, old_y, valid = 0; |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 1681 | |
Kristian Høgsberg | 34829de | 2012-05-09 22:21:14 -0400 | [diff] [blame] | 1682 | x = wl_fixed_to_int(*fx); |
| 1683 | y = wl_fixed_to_int(*fy); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1684 | old_x = wl_fixed_to_int(seat->seat.pointer->x); |
| 1685 | old_y = wl_fixed_to_int(seat->seat.pointer->y); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1686 | |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1687 | wl_list_for_each(output, &ec->output_list, link) { |
Kristian Høgsberg | 34829de | 2012-05-09 22:21:14 -0400 | [diff] [blame] | 1688 | if (pixman_region32_contains_point(&output->region, |
| 1689 | x, y, NULL)) |
| 1690 | valid = 1; |
| 1691 | if (pixman_region32_contains_point(&output->region, |
| 1692 | old_x, old_y, NULL)) |
| 1693 | prev = output; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1694 | } |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1695 | |
Kristian Høgsberg | 34829de | 2012-05-09 22:21:14 -0400 | [diff] [blame] | 1696 | if (!valid) { |
| 1697 | if (x < prev->x) |
| 1698 | *fx = wl_fixed_from_int(prev->x); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1699 | else if (x >= prev->x + prev->width) |
Kristian Høgsberg | 34829de | 2012-05-09 22:21:14 -0400 | [diff] [blame] | 1700 | *fx = wl_fixed_from_int(prev->x + |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1701 | prev->width - 1); |
Kristian Høgsberg | 34829de | 2012-05-09 22:21:14 -0400 | [diff] [blame] | 1702 | if (y < prev->y) |
| 1703 | *fy = wl_fixed_from_int(prev->y); |
| 1704 | else if (y >= prev->y + prev->current->height) |
| 1705 | *fy = wl_fixed_from_int(prev->y + |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1706 | prev->height - 1); |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 1707 | } |
Kristian Høgsberg | 1f37601 | 2012-05-09 11:43:11 -0400 | [diff] [blame] | 1708 | } |
| 1709 | |
Kristian Høgsberg | e2464fd | 2013-02-25 16:49:29 -0500 | [diff] [blame] | 1710 | static void |
Kristian Høgsberg | 068b61c | 2013-02-25 17:04:47 -0500 | [diff] [blame] | 1711 | move_pointer(struct weston_seat *seat, wl_fixed_t dx, wl_fixed_t dy) |
Kristian Høgsberg | 1f37601 | 2012-05-09 11:43:11 -0400 | [diff] [blame] | 1712 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1713 | struct weston_compositor *ec = seat->compositor; |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1714 | struct wl_pointer *pointer = seat->seat.pointer; |
Kristian Høgsberg | e2464fd | 2013-02-25 16:49:29 -0500 | [diff] [blame] | 1715 | struct weston_output *output; |
Kristian Høgsberg | 068b61c | 2013-02-25 17:04:47 -0500 | [diff] [blame] | 1716 | wl_fixed_t x, y; |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 1717 | int32_t ix, iy; |
Kristian Høgsberg | 1f37601 | 2012-05-09 11:43:11 -0400 | [diff] [blame] | 1718 | |
Kristian Høgsberg | 068b61c | 2013-02-25 17:04:47 -0500 | [diff] [blame] | 1719 | x = pointer->x + dx; |
| 1720 | y = pointer->y + dy; |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1721 | clip_pointer_motion(seat, &x, &y); |
Kristian Høgsberg | 1f37601 | 2012-05-09 11:43:11 -0400 | [diff] [blame] | 1722 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1723 | weston_seat_update_drag_surface(seat, x - pointer->x, y - pointer->y); |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 1724 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1725 | pointer->x = x; |
| 1726 | pointer->y = y; |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 1727 | |
| 1728 | ix = wl_fixed_to_int(x); |
| 1729 | iy = wl_fixed_to_int(y); |
Kristian Høgsberg | db6c2f3 | 2009-02-22 21:51:24 -0500 | [diff] [blame] | 1730 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 1731 | wl_list_for_each(output, &ec->output_list, link) |
| 1732 | if (output->zoom.active && |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 1733 | pixman_region32_contains_point(&output->region, |
| 1734 | ix, iy, NULL)) |
Scott Moreau | 8dacaab | 2012-06-17 18:10:58 -0600 | [diff] [blame] | 1735 | weston_output_update_zoom(output, ZOOM_FOCUS_POINTER); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 1736 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1737 | weston_device_repick(seat); |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 1738 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1739 | if (seat->sprite) { |
| 1740 | weston_surface_set_position(seat->sprite, |
| 1741 | ix - seat->hotspot_x, |
| 1742 | iy - seat->hotspot_y); |
| 1743 | weston_surface_schedule_repaint(seat->sprite); |
Kristian Høgsberg | cd9ac1d | 2011-12-15 09:14:34 -0500 | [diff] [blame] | 1744 | } |
Kristian Høgsberg | 715a081 | 2008-12-10 10:42:04 -0500 | [diff] [blame] | 1745 | } |
| 1746 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1747 | WL_EXPORT void |
Kristian Høgsberg | e2464fd | 2013-02-25 16:49:29 -0500 | [diff] [blame] | 1748 | notify_motion(struct weston_seat *seat, |
Kristian Høgsberg | 068b61c | 2013-02-25 17:04:47 -0500 | [diff] [blame] | 1749 | uint32_t time, wl_fixed_t dx, wl_fixed_t dy) |
Kristian Høgsberg | e2464fd | 2013-02-25 16:49:29 -0500 | [diff] [blame] | 1750 | { |
| 1751 | const struct wl_pointer_grab_interface *interface; |
| 1752 | struct weston_compositor *ec = seat->compositor; |
| 1753 | struct wl_pointer *pointer = seat->seat.pointer; |
| 1754 | |
| 1755 | weston_compositor_wake(ec); |
| 1756 | |
Kristian Høgsberg | 068b61c | 2013-02-25 17:04:47 -0500 | [diff] [blame] | 1757 | move_pointer(seat, dx, dy); |
Kristian Høgsberg | e2464fd | 2013-02-25 16:49:29 -0500 | [diff] [blame] | 1758 | |
| 1759 | interface = pointer->grab->interface; |
| 1760 | interface->motion(pointer->grab, time, |
| 1761 | pointer->grab->x, pointer->grab->y); |
| 1762 | } |
| 1763 | |
| 1764 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1765 | weston_surface_activate(struct weston_surface *surface, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1766 | struct weston_seat *seat) |
Kristian Høgsberg | c9824dd | 2011-02-06 16:54:59 -0500 | [diff] [blame] | 1767 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1768 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 1769 | |
Pekka Paalanen | bdc7cd0 | 2012-06-07 15:07:07 +0300 | [diff] [blame] | 1770 | if (seat->seat.keyboard) { |
| 1771 | wl_keyboard_set_focus(seat->seat.keyboard, &surface->surface); |
| 1772 | wl_data_device_set_keyboard_focus(&seat->seat); |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 1773 | } |
| 1774 | |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 1775 | wl_signal_emit(&compositor->activate_signal, surface); |
Kristian Høgsberg | c9824dd | 2011-02-06 16:54:59 -0500 | [diff] [blame] | 1776 | } |
| 1777 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1778 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1779 | notify_button(struct weston_seat *seat, uint32_t time, int32_t button, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1780 | enum wl_pointer_button_state state) |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 1781 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1782 | struct weston_compositor *compositor = seat->compositor; |
| 1783 | struct wl_pointer *pointer = seat->seat.pointer; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1784 | struct weston_surface *focus = |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1785 | (struct weston_surface *) pointer->focus; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1786 | uint32_t serial = wl_display_next_serial(compositor->wl_display); |
Kristian Høgsberg | ea08115 | 2010-12-07 08:59:51 -0500 | [diff] [blame] | 1787 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1788 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1789 | if (compositor->ping_handler && focus) |
| 1790 | compositor->ping_handler(focus, serial); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1791 | weston_compositor_idle_inhibit(compositor); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1792 | if (pointer->button_count == 0) { |
| 1793 | pointer->grab_button = button; |
| 1794 | pointer->grab_time = time; |
| 1795 | pointer->grab_x = pointer->x; |
| 1796 | pointer->grab_y = pointer->y; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1797 | } |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1798 | pointer->button_count++; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1799 | } else { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1800 | weston_compositor_idle_release(compositor); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1801 | pointer->button_count--; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1802 | } |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1803 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1804 | weston_compositor_run_button_binding(compositor, seat, time, button, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 1805 | state); |
Kristian Høgsberg | b3fc757 | 2010-12-08 11:07:57 -0500 | [diff] [blame] | 1806 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1807 | pointer->grab->interface->button(pointer->grab, time, button, state); |
Kristian Høgsberg | 5a5f007 | 2011-12-19 14:54:11 -0500 | [diff] [blame] | 1808 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1809 | if (pointer->button_count == 1) |
| 1810 | pointer->grab_serial = |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1811 | wl_display_get_serial(compositor->wl_display); |
Kristian Høgsberg | eac149a | 2008-12-10 00:24:18 -0500 | [diff] [blame] | 1812 | } |
| 1813 | |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 1814 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1815 | notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis, |
Daniel Stone | 878f0b7 | 2012-05-30 16:31:57 +0100 | [diff] [blame] | 1816 | wl_fixed_t value) |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 1817 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1818 | struct weston_compositor *compositor = seat->compositor; |
| 1819 | struct wl_pointer *pointer = seat->seat.pointer; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1820 | struct weston_surface *focus = |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1821 | (struct weston_surface *) pointer->focus; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1822 | uint32_t serial = wl_display_next_serial(compositor->wl_display); |
| 1823 | |
| 1824 | if (compositor->ping_handler && focus) |
| 1825 | compositor->ping_handler(focus, serial); |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 1826 | |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 1827 | weston_compositor_wake(compositor); |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 1828 | |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 1829 | if (value) |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1830 | weston_compositor_run_axis_binding(compositor, seat, |
| 1831 | time, axis, value); |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 1832 | else |
| 1833 | return; |
| 1834 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1835 | if (pointer->focus_resource) |
| 1836 | wl_pointer_send_axis(pointer->focus_resource, time, axis, |
Daniel Stone | 2fce402 | 2012-05-30 16:32:00 +0100 | [diff] [blame] | 1837 | value); |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 1838 | } |
| 1839 | |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 1840 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1841 | notify_modifiers(struct weston_seat *seat, uint32_t serial) |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 1842 | { |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 1843 | struct wl_keyboard *keyboard = &seat->keyboard.keyboard; |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 1844 | struct wl_keyboard_grab *grab = keyboard->grab; |
Daniel Stone | 7ace390 | 2012-05-30 16:31:40 +0100 | [diff] [blame] | 1845 | uint32_t mods_depressed, mods_latched, mods_locked, group; |
Daniel Stone | e3f15ed | 2012-05-30 16:31:44 +0100 | [diff] [blame] | 1846 | uint32_t mods_lookup; |
Daniel Stone | 8c8164f | 2012-05-30 16:31:45 +0100 | [diff] [blame] | 1847 | enum weston_led leds = 0; |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 1848 | int changed = 0; |
Daniel Stone | 7ace390 | 2012-05-30 16:31:40 +0100 | [diff] [blame] | 1849 | |
Daniel Stone | e3f15ed | 2012-05-30 16:31:44 +0100 | [diff] [blame] | 1850 | /* Serialize and update our internal state, checking to see if it's |
| 1851 | * different to the previous state. */ |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 1852 | mods_depressed = xkb_state_serialize_mods(seat->xkb_state.state, |
| 1853 | XKB_STATE_DEPRESSED); |
| 1854 | mods_latched = xkb_state_serialize_mods(seat->xkb_state.state, |
| 1855 | XKB_STATE_LATCHED); |
| 1856 | mods_locked = xkb_state_serialize_mods(seat->xkb_state.state, |
| 1857 | XKB_STATE_LOCKED); |
| 1858 | group = xkb_state_serialize_group(seat->xkb_state.state, |
Daniel Stone | 7ace390 | 2012-05-30 16:31:40 +0100 | [diff] [blame] | 1859 | XKB_STATE_EFFECTIVE); |
| 1860 | |
Daniel Stone | 71c3877 | 2012-06-22 13:21:30 +0100 | [diff] [blame] | 1861 | if (mods_depressed != seat->seat.keyboard->modifiers.mods_depressed || |
| 1862 | mods_latched != seat->seat.keyboard->modifiers.mods_latched || |
| 1863 | mods_locked != seat->seat.keyboard->modifiers.mods_locked || |
| 1864 | group != seat->seat.keyboard->modifiers.group) |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 1865 | changed = 1; |
Daniel Stone | 7ace390 | 2012-05-30 16:31:40 +0100 | [diff] [blame] | 1866 | |
Daniel Stone | 71c3877 | 2012-06-22 13:21:30 +0100 | [diff] [blame] | 1867 | seat->seat.keyboard->modifiers.mods_depressed = mods_depressed; |
| 1868 | seat->seat.keyboard->modifiers.mods_latched = mods_latched; |
| 1869 | seat->seat.keyboard->modifiers.mods_locked = mods_locked; |
| 1870 | seat->seat.keyboard->modifiers.group = group; |
Kristian Høgsberg | ab909ae | 2001-01-01 22:24:24 -0500 | [diff] [blame] | 1871 | |
Daniel Stone | e3f15ed | 2012-05-30 16:31:44 +0100 | [diff] [blame] | 1872 | /* And update the modifier_state for bindings. */ |
| 1873 | mods_lookup = mods_depressed | mods_latched; |
| 1874 | seat->modifier_state = 0; |
Daniel Stone | 8db7969 | 2012-06-01 12:13:58 +0100 | [diff] [blame] | 1875 | if (mods_lookup & (1 << seat->xkb_info.ctrl_mod)) |
Daniel Stone | e3f15ed | 2012-05-30 16:31:44 +0100 | [diff] [blame] | 1876 | seat->modifier_state |= MODIFIER_CTRL; |
Daniel Stone | 8db7969 | 2012-06-01 12:13:58 +0100 | [diff] [blame] | 1877 | if (mods_lookup & (1 << seat->xkb_info.alt_mod)) |
Daniel Stone | e3f15ed | 2012-05-30 16:31:44 +0100 | [diff] [blame] | 1878 | seat->modifier_state |= MODIFIER_ALT; |
Daniel Stone | 8db7969 | 2012-06-01 12:13:58 +0100 | [diff] [blame] | 1879 | if (mods_lookup & (1 << seat->xkb_info.super_mod)) |
Daniel Stone | e3f15ed | 2012-05-30 16:31:44 +0100 | [diff] [blame] | 1880 | seat->modifier_state |= MODIFIER_SUPER; |
Kristian Høgsberg | 73694c8 | 2012-06-28 14:13:10 -0400 | [diff] [blame] | 1881 | if (mods_lookup & (1 << seat->xkb_info.shift_mod)) |
| 1882 | seat->modifier_state |= MODIFIER_SHIFT; |
Daniel Stone | 7ace390 | 2012-05-30 16:31:40 +0100 | [diff] [blame] | 1883 | |
Daniel Stone | 8c8164f | 2012-05-30 16:31:45 +0100 | [diff] [blame] | 1884 | /* Finally, notify the compositor that LEDs have changed. */ |
| 1885 | if (xkb_state_led_index_is_active(seat->xkb_state.state, |
Daniel Stone | d65b909 | 2012-05-30 16:32:05 +0100 | [diff] [blame] | 1886 | seat->xkb_info.num_led)) |
Daniel Stone | 8c8164f | 2012-05-30 16:31:45 +0100 | [diff] [blame] | 1887 | leds |= LED_NUM_LOCK; |
| 1888 | if (xkb_state_led_index_is_active(seat->xkb_state.state, |
Daniel Stone | d65b909 | 2012-05-30 16:32:05 +0100 | [diff] [blame] | 1889 | seat->xkb_info.caps_led)) |
Daniel Stone | 8c8164f | 2012-05-30 16:31:45 +0100 | [diff] [blame] | 1890 | leds |= LED_CAPS_LOCK; |
| 1891 | if (xkb_state_led_index_is_active(seat->xkb_state.state, |
Daniel Stone | d65b909 | 2012-05-30 16:32:05 +0100 | [diff] [blame] | 1892 | seat->xkb_info.scroll_led)) |
Daniel Stone | 8c8164f | 2012-05-30 16:31:45 +0100 | [diff] [blame] | 1893 | leds |= LED_SCROLL_LOCK; |
| 1894 | if (leds != seat->xkb_state.leds && seat->led_update) |
Daniel Stone | bbf63bf | 2012-06-04 11:40:48 +0100 | [diff] [blame] | 1895 | seat->led_update(seat, leds); |
Daniel Stone | 8c8164f | 2012-05-30 16:31:45 +0100 | [diff] [blame] | 1896 | seat->xkb_state.leds = leds; |
| 1897 | |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 1898 | if (changed) { |
| 1899 | grab->interface->modifiers(grab, |
| 1900 | serial, |
| 1901 | keyboard->modifiers.mods_depressed, |
| 1902 | keyboard->modifiers.mods_latched, |
| 1903 | keyboard->modifiers.mods_locked, |
| 1904 | keyboard->modifiers.group); |
| 1905 | } |
Kristian Høgsberg | f512d07 | 2011-04-12 17:16:00 -0400 | [diff] [blame] | 1906 | } |
Kristian Høgsberg | 2cbedd1 | 2009-09-18 17:29:49 -0400 | [diff] [blame] | 1907 | |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 1908 | static void |
| 1909 | update_modifier_state(struct weston_seat *seat, uint32_t serial, uint32_t key, |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 1910 | enum wl_keyboard_key_state state) |
| 1911 | { |
| 1912 | enum xkb_key_direction direction; |
| 1913 | |
| 1914 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 1915 | direction = XKB_KEY_DOWN; |
| 1916 | else |
| 1917 | direction = XKB_KEY_UP; |
| 1918 | |
| 1919 | /* Offset the keycode by 8, as the evdev XKB rules reflect X's |
| 1920 | * broken keycode system, which starts at 8. */ |
| 1921 | xkb_state_update_key(seat->xkb_state.state, key + 8, direction); |
| 1922 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1923 | notify_modifiers(seat, serial); |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 1924 | } |
| 1925 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1926 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1927 | notify_key(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 1b4e11f | 2012-06-22 13:21:37 +0100 | [diff] [blame] | 1928 | enum wl_keyboard_key_state state, |
| 1929 | enum weston_key_state_update update_state) |
Kristian Høgsberg | f512d07 | 2011-04-12 17:16:00 -0400 | [diff] [blame] | 1930 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1931 | struct weston_compositor *compositor = seat->compositor; |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 1932 | struct weston_keyboard *keyboard = &seat->keyboard; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1933 | struct weston_surface *focus = |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 1934 | (struct weston_surface *) keyboard->keyboard.focus; |
| 1935 | struct wl_keyboard_grab *grab = keyboard->keyboard.grab; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1936 | uint32_t serial = wl_display_next_serial(compositor->wl_display); |
Kristian Høgsberg | f512d07 | 2011-04-12 17:16:00 -0400 | [diff] [blame] | 1937 | uint32_t *k, *end; |
Kristian Høgsberg | f512d07 | 2011-04-12 17:16:00 -0400 | [diff] [blame] | 1938 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 1939 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1940 | if (compositor->ping_handler && focus) |
| 1941 | compositor->ping_handler(focus, serial); |
| 1942 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1943 | weston_compositor_idle_inhibit(compositor); |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 1944 | keyboard->keyboard.grab_key = key; |
| 1945 | keyboard->keyboard.grab_time = time; |
Scott Moreau | ec286eb | 2012-02-18 05:05:30 -0700 | [diff] [blame] | 1946 | } else { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1947 | weston_compositor_idle_release(compositor); |
Scott Moreau | ec286eb | 2012-02-18 05:05:30 -0700 | [diff] [blame] | 1948 | } |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1949 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 1950 | end = keyboard->keyboard.keys.data + keyboard->keyboard.keys.size; |
| 1951 | for (k = keyboard->keyboard.keys.data; k < end; k++) { |
Daniel Stone | c6587ea | 2012-06-22 13:21:31 +0100 | [diff] [blame] | 1952 | if (*k == key) { |
| 1953 | /* Ignore server-generated repeats. */ |
| 1954 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 1955 | return; |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 1956 | *k = *--end; |
Daniel Stone | c6587ea | 2012-06-22 13:21:31 +0100 | [diff] [blame] | 1957 | } |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 1958 | } |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 1959 | keyboard->keyboard.keys.size = (void *) end - keyboard->keyboard.keys.data; |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 1960 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 1961 | k = wl_array_add(&keyboard->keyboard.keys, sizeof *k); |
Kristian Høgsberg | 3c38fa0 | 2009-02-23 22:30:29 -0500 | [diff] [blame] | 1962 | *k = key; |
| 1963 | } |
Ray Strode | e96dcb8 | 2008-12-20 02:00:49 -0500 | [diff] [blame] | 1964 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 1965 | if (grab == &keyboard->keyboard.default_grab || |
| 1966 | grab == &keyboard->input_method_grab) { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1967 | weston_compositor_run_key_binding(compositor, seat, time, key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 1968 | state); |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 1969 | grab = keyboard->keyboard.grab; |
Scott Moreau | befa653 | 2012-06-11 14:59:31 -0600 | [diff] [blame] | 1970 | } |
Kristian Høgsberg | abcef3c | 2012-03-05 17:47:15 -0500 | [diff] [blame] | 1971 | |
Daniel Stone | 7ace390 | 2012-05-30 16:31:40 +0100 | [diff] [blame] | 1972 | grab->interface->key(grab, time, key, state); |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 1973 | |
| 1974 | if (update_state == STATE_UPDATE_AUTOMATIC) { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1975 | update_modifier_state(seat, |
Daniel Stone | 05d5868 | 2012-06-22 13:21:38 +0100 | [diff] [blame] | 1976 | wl_display_get_serial(compositor->wl_display), |
| 1977 | key, |
| 1978 | state); |
| 1979 | } |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 1980 | } |
| 1981 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1982 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1983 | notify_pointer_focus(struct weston_seat *seat, struct weston_output *output, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1984 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 1985 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1986 | struct weston_compositor *compositor = seat->compositor; |
| 1987 | struct wl_pointer *pointer = seat->seat.pointer; |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 1988 | |
| 1989 | if (output) { |
Kristian Høgsberg | 00fbbe6 | 2012-10-23 13:04:09 -0400 | [diff] [blame] | 1990 | clip_pointer_motion(seat, &x, &y); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1991 | weston_seat_update_drag_surface(seat, |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1992 | x - pointer->x, |
| 1993 | y - pointer->y); |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 1994 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1995 | pointer->x = x; |
| 1996 | pointer->y = y; |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 1997 | compositor->focus = 1; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1998 | weston_compositor_repick(compositor); |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 1999 | } else { |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 2000 | compositor->focus = 0; |
Tiago Vignatti | cd717b5 | 2012-07-12 00:46:10 +0300 | [diff] [blame] | 2001 | /* FIXME: We should call wl_pointer_set_focus(seat, |
| 2002 | * NULL) here, but somehow that breaks re-entry... */ |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 2003 | } |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 2004 | } |
| 2005 | |
Ander Conselvan de Oliveira | 71b1d0c | 2012-03-16 17:25:11 +0200 | [diff] [blame] | 2006 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2007 | destroy_device_saved_kbd_focus(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 71b1d0c | 2012-03-16 17:25:11 +0200 | [diff] [blame] | 2008 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2009 | struct weston_seat *ws; |
Ander Conselvan de Oliveira | 71b1d0c | 2012-03-16 17:25:11 +0200 | [diff] [blame] | 2010 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2011 | ws = container_of(listener, struct weston_seat, |
Ander Conselvan de Oliveira | 71b1d0c | 2012-03-16 17:25:11 +0200 | [diff] [blame] | 2012 | saved_kbd_focus_listener); |
| 2013 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2014 | ws->saved_kbd_focus = NULL; |
Ander Conselvan de Oliveira | 71b1d0c | 2012-03-16 17:25:11 +0200 | [diff] [blame] | 2015 | } |
| 2016 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2017 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2018 | notify_keyboard_focus_in(struct weston_seat *seat, struct wl_array *keys, |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2019 | enum weston_key_state_update update_state) |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 2020 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2021 | struct weston_compositor *compositor = seat->compositor; |
| 2022 | struct wl_keyboard *keyboard = seat->seat.keyboard; |
Kristian Høgsberg | afee221 | 2012-03-20 17:28:20 -0400 | [diff] [blame] | 2023 | struct wl_surface *surface; |
Kristian Høgsberg | c7cd626 | 2012-06-28 13:46:09 -0400 | [diff] [blame] | 2024 | uint32_t *k, serial; |
Kristian Høgsberg | f992b2f | 2011-01-28 15:53:07 -0500 | [diff] [blame] | 2025 | |
Kristian Høgsberg | c7cd626 | 2012-06-28 13:46:09 -0400 | [diff] [blame] | 2026 | serial = wl_display_next_serial(compositor->wl_display); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2027 | wl_array_copy(&keyboard->keys, keys); |
| 2028 | wl_array_for_each(k, &keyboard->keys) { |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2029 | weston_compositor_idle_inhibit(compositor); |
| 2030 | if (update_state == STATE_UPDATE_AUTOMATIC) |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2031 | update_modifier_state(seat, serial, *k, |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2032 | WL_KEYBOARD_KEY_STATE_PRESSED); |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 2033 | } |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2034 | |
Daniel Stone | ef17267 | 2012-06-22 13:21:32 +0100 | [diff] [blame] | 2035 | /* Run key bindings after we've updated the state. */ |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2036 | wl_array_for_each(k, &keyboard->keys) { |
| 2037 | weston_compositor_run_key_binding(compositor, seat, 0, *k, |
Daniel Stone | ef17267 | 2012-06-22 13:21:32 +0100 | [diff] [blame] | 2038 | WL_KEYBOARD_KEY_STATE_PRESSED); |
| 2039 | } |
| 2040 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2041 | surface = seat->saved_kbd_focus; |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2042 | |
| 2043 | if (surface) { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2044 | wl_list_remove(&seat->saved_kbd_focus_listener.link); |
| 2045 | wl_keyboard_set_focus(keyboard, surface); |
| 2046 | seat->saved_kbd_focus = NULL; |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2051 | notify_keyboard_focus_out(struct weston_seat *seat) |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2052 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2053 | struct weston_compositor *compositor = seat->compositor; |
| 2054 | struct wl_keyboard *keyboard = seat->seat.keyboard; |
Kristian Høgsberg | c7cd626 | 2012-06-28 13:46:09 -0400 | [diff] [blame] | 2055 | uint32_t *k, serial; |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2056 | |
Kristian Høgsberg | c7cd626 | 2012-06-28 13:46:09 -0400 | [diff] [blame] | 2057 | serial = wl_display_next_serial(compositor->wl_display); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2058 | wl_array_for_each(k, &keyboard->keys) { |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2059 | weston_compositor_idle_release(compositor); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2060 | update_modifier_state(seat, serial, *k, |
Kristian Høgsberg | c7cd626 | 2012-06-28 13:46:09 -0400 | [diff] [blame] | 2061 | WL_KEYBOARD_KEY_STATE_RELEASED); |
| 2062 | } |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2063 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2064 | seat->modifier_state = 0; |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2065 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2066 | if (keyboard->focus) { |
| 2067 | seat->saved_kbd_focus = keyboard->focus; |
| 2068 | seat->saved_kbd_focus_listener.notify = |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2069 | destroy_device_saved_kbd_focus; |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2070 | wl_signal_add(&keyboard->focus->resource.destroy_signal, |
| 2071 | &seat->saved_kbd_focus_listener); |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2072 | } |
| 2073 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2074 | wl_keyboard_set_focus(keyboard, NULL); |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 2075 | /* FIXME: We really need keyboard grab cancel here to |
| 2076 | * let the grab shut down properly. As it is we leak |
| 2077 | * the grab data. */ |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2078 | wl_keyboard_end_grab(keyboard); |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 2079 | } |
| 2080 | |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2081 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2082 | touch_set_focus(struct weston_seat *ws, struct wl_surface *surface) |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2083 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2084 | struct wl_seat *seat = &ws->seat; |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2085 | struct wl_resource *resource; |
| 2086 | |
Pekka Paalanen | 5646425 | 2012-07-31 13:21:08 +0300 | [diff] [blame] | 2087 | if (seat->touch->focus == surface) |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2088 | return; |
| 2089 | |
Pekka Paalanen | 5646425 | 2012-07-31 13:21:08 +0300 | [diff] [blame] | 2090 | if (seat->touch->focus_resource) |
| 2091 | wl_list_remove(&seat->touch->focus_listener.link); |
| 2092 | seat->touch->focus = NULL; |
| 2093 | seat->touch->focus_resource = NULL; |
| 2094 | |
Kristian Høgsberg | 03cb5cf | 2011-12-22 14:43:09 -0500 | [diff] [blame] | 2095 | if (surface) { |
| 2096 | resource = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2097 | find_resource_for_client(&seat->touch->resource_list, |
Casey Dahlin | 96d8a75 | 2012-04-19 22:50:07 -0400 | [diff] [blame] | 2098 | surface->resource.client); |
Kristian Høgsberg | 03cb5cf | 2011-12-22 14:43:09 -0500 | [diff] [blame] | 2099 | if (!resource) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2100 | weston_log("couldn't find resource\n"); |
Kristian Høgsberg | 03cb5cf | 2011-12-22 14:43:09 -0500 | [diff] [blame] | 2101 | return; |
| 2102 | } |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2103 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2104 | seat->touch->focus = surface; |
| 2105 | seat->touch->focus_resource = resource; |
Pekka Paalanen | 5646425 | 2012-07-31 13:21:08 +0300 | [diff] [blame] | 2106 | wl_signal_add(&resource->destroy_signal, |
| 2107 | &seat->touch->focus_listener); |
Kristian Høgsberg | 03cb5cf | 2011-12-22 14:43:09 -0500 | [diff] [blame] | 2108 | } |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2109 | } |
| 2110 | |
Tiago Vignatti | 22c6bce | 2011-12-21 19:34:09 +0200 | [diff] [blame] | 2111 | /** |
| 2112 | * notify_touch - emulates button touches and notifies surfaces accordingly. |
| 2113 | * |
| 2114 | * It assumes always the correct cycle sequence until it gets here: touch_down |
| 2115 | * → touch_update → ... → touch_update → touch_end. The driver is responsible |
| 2116 | * for sending along such order. |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2117 | * |
Tiago Vignatti | 22c6bce | 2011-12-21 19:34:09 +0200 | [diff] [blame] | 2118 | */ |
| 2119 | WL_EXPORT void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2120 | notify_touch(struct weston_seat *seat, uint32_t time, int touch_id, |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 2121 | wl_fixed_t x, wl_fixed_t y, int touch_type) |
Tiago Vignatti | 22c6bce | 2011-12-21 19:34:09 +0200 | [diff] [blame] | 2122 | { |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2123 | struct weston_compositor *ec = seat->compositor; |
| 2124 | struct wl_touch *touch = seat->seat.touch; |
Matt Roper | 47c1b98 | 2012-10-10 16:56:53 -0700 | [diff] [blame] | 2125 | struct wl_touch_grab *grab = touch->grab; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2126 | struct weston_surface *es; |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 2127 | wl_fixed_t sx, sy; |
Matt Roper | 47c1b98 | 2012-10-10 16:56:53 -0700 | [diff] [blame] | 2128 | |
| 2129 | /* Update grab's global coordinates. */ |
| 2130 | touch->grab_x = x; |
| 2131 | touch->grab_y = y; |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2132 | |
| 2133 | switch (touch_type) { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2134 | case WL_TOUCH_DOWN: |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2135 | weston_compositor_idle_inhibit(ec); |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2136 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2137 | seat->num_tp++; |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2138 | |
| 2139 | /* the first finger down picks the surface, and all further go |
| 2140 | * to that surface for the remainder of the touch session i.e. |
| 2141 | * until all touch points are up again. */ |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2142 | if (seat->num_tp == 1) { |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 2143 | es = weston_compositor_pick_surface(ec, x, y, &sx, &sy); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2144 | touch_set_focus(seat, &es->surface); |
| 2145 | } else if (touch->focus) { |
| 2146 | es = (struct weston_surface *) touch->focus; |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 2147 | weston_surface_from_global_fixed(es, x, y, &sx, &sy); |
Rob Bradford | 26e009c | 2012-12-05 18:47:05 +0000 | [diff] [blame] | 2148 | } else { |
| 2149 | /* Unexpected condition: We have non-initial touch but |
| 2150 | * there is no focused surface. |
| 2151 | */ |
| 2152 | weston_log("touch event received with %d points down" |
| 2153 | "but no surface focused\n", seat->num_tp); |
| 2154 | return; |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2155 | } |
Kristian Høgsberg | 03cb5cf | 2011-12-22 14:43:09 -0500 | [diff] [blame] | 2156 | |
Matt Roper | 47c1b98 | 2012-10-10 16:56:53 -0700 | [diff] [blame] | 2157 | grab->interface->down(grab, time, touch_id, sx, sy); |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2158 | break; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2159 | case WL_TOUCH_MOTION: |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2160 | es = (struct weston_surface *) touch->focus; |
Kristian Høgsberg | 03cb5cf | 2011-12-22 14:43:09 -0500 | [diff] [blame] | 2161 | if (!es) |
| 2162 | break; |
| 2163 | |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 2164 | weston_surface_from_global_fixed(es, x, y, &sx, &sy); |
Matt Roper | 47c1b98 | 2012-10-10 16:56:53 -0700 | [diff] [blame] | 2165 | grab->interface->motion(grab, time, touch_id, sx, sy); |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2166 | break; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2167 | case WL_TOUCH_UP: |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2168 | weston_compositor_idle_release(ec); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2169 | seat->num_tp--; |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2170 | |
Matt Roper | 47c1b98 | 2012-10-10 16:56:53 -0700 | [diff] [blame] | 2171 | grab->interface->up(grab, time, touch_id); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2172 | if (seat->num_tp == 0) |
| 2173 | touch_set_focus(seat, NULL); |
Tiago Vignatti | 1f221ff | 2011-12-21 19:34:10 +0200 | [diff] [blame] | 2174 | break; |
| 2175 | } |
Tiago Vignatti | 22c6bce | 2011-12-21 19:34:09 +0200 | [diff] [blame] | 2176 | } |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 2177 | |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 2178 | static void |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2179 | pointer_handle_sprite_destroy(struct wl_listener *listener, void *data) |
| 2180 | { |
| 2181 | struct weston_seat *seat = container_of(listener, struct weston_seat, |
| 2182 | sprite_destroy_listener); |
| 2183 | |
| 2184 | seat->sprite = NULL; |
| 2185 | } |
| 2186 | |
| 2187 | static void |
| 2188 | pointer_cursor_surface_configure(struct weston_surface *es, |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2189 | int32_t dx, int32_t dy, int32_t width, int32_t height) |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2190 | { |
| 2191 | struct weston_seat *seat = es->private; |
| 2192 | int x, y; |
| 2193 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2194 | if (width == 0) |
| 2195 | return; |
| 2196 | |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2197 | assert(es == seat->sprite); |
| 2198 | |
| 2199 | seat->hotspot_x -= dx; |
| 2200 | seat->hotspot_y -= dy; |
| 2201 | |
| 2202 | x = wl_fixed_to_int(seat->seat.pointer->x) - seat->hotspot_x; |
| 2203 | y = wl_fixed_to_int(seat->seat.pointer->y) - seat->hotspot_y; |
| 2204 | |
| 2205 | weston_surface_configure(seat->sprite, x, y, |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2206 | width, height); |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2207 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2208 | empty_region(&es->pending.input); |
Ander Conselvan de Oliveira | f1c00c0 | 2012-07-04 15:48:29 +0300 | [diff] [blame] | 2209 | |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2210 | if (!weston_surface_is_mapped(es)) { |
| 2211 | wl_list_insert(&es->compositor->cursor_layer.surface_list, |
| 2212 | &es->layer_link); |
Ander Conselvan de Oliveira | 231ba17 | 2012-09-14 16:12:04 +0300 | [diff] [blame] | 2213 | weston_surface_update_transform(es); |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2214 | } |
| 2215 | } |
| 2216 | |
| 2217 | static void |
| 2218 | pointer_unmap_sprite(struct weston_seat *seat) |
| 2219 | { |
| 2220 | if (weston_surface_is_mapped(seat->sprite)) |
| 2221 | weston_surface_unmap(seat->sprite); |
| 2222 | |
| 2223 | wl_list_remove(&seat->sprite_destroy_listener.link); |
| 2224 | seat->sprite->configure = NULL; |
| 2225 | seat->sprite->private = NULL; |
| 2226 | seat->sprite = NULL; |
| 2227 | } |
| 2228 | |
| 2229 | static void |
| 2230 | pointer_set_cursor(struct wl_client *client, struct wl_resource *resource, |
| 2231 | uint32_t serial, struct wl_resource *surface_resource, |
| 2232 | int32_t x, int32_t y) |
Kristian Høgsberg | ab1862d | 2010-12-09 11:29:40 -0500 | [diff] [blame] | 2233 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2234 | struct weston_seat *seat = resource->data; |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2235 | struct weston_surface *surface = NULL; |
Kristian Høgsberg | ab1862d | 2010-12-09 11:29:40 -0500 | [diff] [blame] | 2236 | |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2237 | if (surface_resource) |
Pekka Paalanen | 6c71ee1 | 2012-10-10 12:49:30 +0300 | [diff] [blame] | 2238 | surface = surface_resource->data; |
Kristian Høgsberg | 9629fe3 | 2012-03-26 15:56:39 -0400 | [diff] [blame] | 2239 | |
Kristian Høgsberg | 649e1ce | 2012-08-01 09:46:12 -0400 | [diff] [blame] | 2240 | if (seat->seat.pointer->focus == NULL) |
| 2241 | return; |
| 2242 | if (seat->seat.pointer->focus->resource.client != client) |
| 2243 | return; |
Kristian Høgsberg | 2e96d3c | 2012-08-01 09:39:11 -0400 | [diff] [blame] | 2244 | if (seat->seat.pointer->focus_serial - serial > UINT32_MAX / 2) |
Kristian Høgsberg | ab1862d | 2010-12-09 11:29:40 -0500 | [diff] [blame] | 2245 | return; |
Ander Conselvan de Oliveira | 1fbda0e | 2012-06-28 18:08:04 +0300 | [diff] [blame] | 2246 | |
| 2247 | if (surface && surface != seat->sprite) { |
Ander Conselvan de Oliveira | 1fbda0e | 2012-06-28 18:08:04 +0300 | [diff] [blame] | 2248 | if (surface->configure) { |
| 2249 | wl_resource_post_error(&surface->surface.resource, |
| 2250 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2251 | "surface->configure already " |
| 2252 | "set"); |
| 2253 | return; |
| 2254 | } |
Pekka Paalanen | f07cb5d | 2012-02-10 13:34:36 +0200 | [diff] [blame] | 2255 | } |
Kristian Høgsberg | cd9ac1d | 2011-12-15 09:14:34 -0500 | [diff] [blame] | 2256 | |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2257 | if (seat->sprite) |
| 2258 | pointer_unmap_sprite(seat); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2259 | |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2260 | if (!surface) |
| 2261 | return; |
| 2262 | |
| 2263 | wl_signal_add(&surface->surface.resource.destroy_signal, |
| 2264 | &seat->sprite_destroy_listener); |
| 2265 | |
| 2266 | surface->configure = pointer_cursor_surface_configure; |
| 2267 | surface->private = seat; |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2268 | seat->sprite = surface; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2269 | seat->hotspot_x = x; |
| 2270 | seat->hotspot_y = y; |
Kristian Høgsberg | cd9ac1d | 2011-12-15 09:14:34 -0500 | [diff] [blame] | 2271 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2272 | if (surface->buffer_ref.buffer) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2273 | pointer_cursor_surface_configure(surface, 0, 0, weston_surface_buffer_width(surface), |
| 2274 | weston_surface_buffer_height(surface)); |
Kristian Høgsberg | ab1862d | 2010-12-09 11:29:40 -0500 | [diff] [blame] | 2275 | } |
| 2276 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2277 | static const struct wl_pointer_interface pointer_interface = { |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2278 | pointer_set_cursor |
Kristian Høgsberg | ab1862d | 2010-12-09 11:29:40 -0500 | [diff] [blame] | 2279 | }; |
| 2280 | |
Ander Conselvan de Oliveira | c5fb9a7 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2281 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2282 | handle_drag_surface_destroy(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | c5fb9a7 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2283 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2284 | struct weston_seat *seat; |
Ander Conselvan de Oliveira | c5fb9a7 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2285 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2286 | seat = container_of(listener, struct weston_seat, |
| 2287 | drag_surface_destroy_listener); |
Ander Conselvan de Oliveira | c5fb9a7 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2288 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2289 | seat->drag_surface = NULL; |
Ander Conselvan de Oliveira | c5fb9a7 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2290 | } |
| 2291 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 2292 | static void unbind_resource(struct wl_resource *resource) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2293 | { |
| 2294 | wl_list_remove(&resource->link); |
| 2295 | free(resource); |
| 2296 | } |
| 2297 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2298 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2299 | seat_get_pointer(struct wl_client *client, struct wl_resource *resource, |
| 2300 | uint32_t id) |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2301 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2302 | struct weston_seat *seat = resource->data; |
| 2303 | struct wl_resource *cr; |
Kristian Høgsberg | 8e6d712 | 2011-08-29 16:04:39 -0400 | [diff] [blame] | 2304 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2305 | if (!seat->seat.pointer) |
| 2306 | return; |
| 2307 | |
| 2308 | cr = wl_client_add_object(client, &wl_pointer_interface, |
| 2309 | &pointer_interface, id, seat); |
| 2310 | wl_list_insert(&seat->seat.pointer->resource_list, &cr->link); |
Kristian Høgsberg | b93b6cf | 2012-05-16 22:32:40 -0400 | [diff] [blame] | 2311 | cr->destroy = unbind_resource; |
Daniel Stone | 17b13bd | 2012-05-30 16:31:39 +0100 | [diff] [blame] | 2312 | |
| 2313 | if (seat->seat.pointer->focus && |
| 2314 | seat->seat.pointer->focus->resource.client == client) { |
| 2315 | struct weston_surface *surface; |
| 2316 | wl_fixed_t sx, sy; |
| 2317 | |
| 2318 | surface = (struct weston_surface *) seat->seat.pointer->focus; |
| 2319 | weston_surface_from_global_fixed(surface, |
| 2320 | seat->seat.pointer->x, |
| 2321 | seat->seat.pointer->y, |
| 2322 | &sx, |
| 2323 | &sy); |
| 2324 | wl_pointer_set_focus(seat->seat.pointer, |
| 2325 | seat->seat.pointer->focus, |
| 2326 | sx, |
| 2327 | sy); |
| 2328 | } |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | static void |
| 2332 | seat_get_keyboard(struct wl_client *client, struct wl_resource *resource, |
| 2333 | uint32_t id) |
| 2334 | { |
| 2335 | struct weston_seat *seat = resource->data; |
| 2336 | struct wl_resource *cr; |
| 2337 | |
| 2338 | if (!seat->seat.keyboard) |
| 2339 | return; |
| 2340 | |
| 2341 | cr = wl_client_add_object(client, &wl_keyboard_interface, NULL, id, |
| 2342 | seat); |
| 2343 | wl_list_insert(&seat->seat.keyboard->resource_list, &cr->link); |
Kristian Høgsberg | b93b6cf | 2012-05-16 22:32:40 -0400 | [diff] [blame] | 2344 | cr->destroy = unbind_resource; |
Daniel Stone | 17b13bd | 2012-05-30 16:31:39 +0100 | [diff] [blame] | 2345 | |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2346 | wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
| 2347 | seat->xkb_info.keymap_fd, |
| 2348 | seat->xkb_info.keymap_size); |
| 2349 | |
Daniel Stone | 17b13bd | 2012-05-30 16:31:39 +0100 | [diff] [blame] | 2350 | if (seat->seat.keyboard->focus && |
| 2351 | seat->seat.keyboard->focus->resource.client == client) { |
| 2352 | wl_keyboard_set_focus(seat->seat.keyboard, |
| 2353 | seat->seat.keyboard->focus); |
Rafal Mielniczuk | db79057 | 2013-02-17 15:55:55 +0100 | [diff] [blame] | 2354 | wl_data_device_set_keyboard_focus(&seat->seat); |
Daniel Stone | 17b13bd | 2012-05-30 16:31:39 +0100 | [diff] [blame] | 2355 | } |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | static void |
| 2359 | seat_get_touch(struct wl_client *client, struct wl_resource *resource, |
| 2360 | uint32_t id) |
| 2361 | { |
| 2362 | struct weston_seat *seat = resource->data; |
| 2363 | struct wl_resource *cr; |
| 2364 | |
| 2365 | if (!seat->seat.touch) |
| 2366 | return; |
| 2367 | |
| 2368 | cr = wl_client_add_object(client, &wl_touch_interface, NULL, id, seat); |
| 2369 | wl_list_insert(&seat->seat.touch->resource_list, &cr->link); |
Kristian Høgsberg | b93b6cf | 2012-05-16 22:32:40 -0400 | [diff] [blame] | 2370 | cr->destroy = unbind_resource; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | static const struct wl_seat_interface seat_interface = { |
| 2374 | seat_get_pointer, |
| 2375 | seat_get_keyboard, |
| 2376 | seat_get_touch, |
| 2377 | }; |
| 2378 | |
| 2379 | static void |
| 2380 | bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 2381 | { |
| 2382 | struct wl_seat *seat = data; |
| 2383 | struct wl_resource *resource; |
| 2384 | enum wl_seat_capability caps = 0; |
| 2385 | |
| 2386 | resource = wl_client_add_object(client, &wl_seat_interface, |
| 2387 | &seat_interface, id, data); |
| 2388 | wl_list_insert(&seat->base_resource_list, &resource->link); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 2389 | resource->destroy = unbind_resource; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2390 | |
| 2391 | if (seat->pointer) |
| 2392 | caps |= WL_SEAT_CAPABILITY_POINTER; |
| 2393 | if (seat->keyboard) |
| 2394 | caps |= WL_SEAT_CAPABILITY_KEYBOARD; |
| 2395 | if (seat->touch) |
| 2396 | caps |= WL_SEAT_CAPABILITY_TOUCH; |
| 2397 | |
| 2398 | wl_seat_send_capabilities(resource, caps); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2399 | } |
| 2400 | |
Ander Conselvan de Oliveira | d6ea33d | 2012-03-27 17:36:39 +0300 | [diff] [blame] | 2401 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2402 | device_handle_new_drag_icon(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | d6ea33d | 2012-03-27 17:36:39 +0300 | [diff] [blame] | 2403 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2404 | struct weston_seat *seat; |
Ander Conselvan de Oliveira | d6ea33d | 2012-03-27 17:36:39 +0300 | [diff] [blame] | 2405 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2406 | seat = container_of(listener, struct weston_seat, |
| 2407 | new_drag_icon_listener); |
Ander Conselvan de Oliveira | d6ea33d | 2012-03-27 17:36:39 +0300 | [diff] [blame] | 2408 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2409 | weston_seat_update_drag_surface(seat, 0, 0); |
Ander Conselvan de Oliveira | d6ea33d | 2012-03-27 17:36:39 +0300 | [diff] [blame] | 2410 | } |
| 2411 | |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2412 | static int |
| 2413 | weston_compositor_xkb_init(struct weston_compositor *ec, |
| 2414 | struct xkb_rule_names *names) |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2415 | { |
Daniel Stone | e379da9 | 2012-05-30 16:32:04 +0100 | [diff] [blame] | 2416 | if (ec->xkb_context == NULL) { |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2417 | ec->xkb_context = xkb_context_new(0); |
| 2418 | if (ec->xkb_context == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2419 | weston_log("failed to create XKB context\n"); |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2420 | return -1; |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2421 | } |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | if (names) |
Daniel Stone | e379da9 | 2012-05-30 16:32:04 +0100 | [diff] [blame] | 2425 | ec->xkb_names = *names; |
| 2426 | if (!ec->xkb_names.rules) |
| 2427 | ec->xkb_names.rules = strdup("evdev"); |
| 2428 | if (!ec->xkb_names.model) |
| 2429 | ec->xkb_names.model = strdup("pc105"); |
| 2430 | if (!ec->xkb_names.layout) |
| 2431 | ec->xkb_names.layout = strdup("us"); |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2432 | |
| 2433 | return 0; |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2434 | } |
| 2435 | |
Daniel Stone | e379da9 | 2012-05-30 16:32:04 +0100 | [diff] [blame] | 2436 | static void xkb_info_destroy(struct weston_xkb_info *xkb_info) |
| 2437 | { |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2438 | if (xkb_info->keymap) |
| 2439 | xkb_map_unref(xkb_info->keymap); |
| 2440 | |
| 2441 | if (xkb_info->keymap_area) |
| 2442 | munmap(xkb_info->keymap_area, xkb_info->keymap_size); |
| 2443 | if (xkb_info->keymap_fd >= 0) |
| 2444 | close(xkb_info->keymap_fd); |
Daniel Stone | e379da9 | 2012-05-30 16:32:04 +0100 | [diff] [blame] | 2445 | } |
| 2446 | |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2447 | static void weston_compositor_xkb_destroy(struct weston_compositor *ec) |
| 2448 | { |
Daniel Stone | e379da9 | 2012-05-30 16:32:04 +0100 | [diff] [blame] | 2449 | free((char *) ec->xkb_names.rules); |
| 2450 | free((char *) ec->xkb_names.model); |
| 2451 | free((char *) ec->xkb_names.layout); |
| 2452 | free((char *) ec->xkb_names.variant); |
| 2453 | free((char *) ec->xkb_names.options); |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2454 | |
Daniel Stone | e379da9 | 2012-05-30 16:32:04 +0100 | [diff] [blame] | 2455 | xkb_info_destroy(&ec->xkb_info); |
| 2456 | xkb_context_unref(ec->xkb_context); |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2457 | } |
| 2458 | |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2459 | static int |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2460 | weston_xkb_info_new_keymap(struct weston_xkb_info *xkb_info) |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2461 | { |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2462 | char *keymap_str; |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2463 | |
Daniel Stone | abb9dcd | 2012-06-22 13:21:33 +0100 | [diff] [blame] | 2464 | xkb_info->shift_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 2465 | XKB_MOD_NAME_SHIFT); |
| 2466 | xkb_info->caps_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 2467 | XKB_MOD_NAME_CAPS); |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2468 | xkb_info->ctrl_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 2469 | XKB_MOD_NAME_CTRL); |
| 2470 | xkb_info->alt_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 2471 | XKB_MOD_NAME_ALT); |
Daniel Stone | abb9dcd | 2012-06-22 13:21:33 +0100 | [diff] [blame] | 2472 | xkb_info->mod2_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod2"); |
| 2473 | xkb_info->mod3_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod3"); |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2474 | xkb_info->super_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 2475 | XKB_MOD_NAME_LOGO); |
Daniel Stone | abb9dcd | 2012-06-22 13:21:33 +0100 | [diff] [blame] | 2476 | xkb_info->mod5_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod5"); |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2477 | |
| 2478 | xkb_info->num_led = xkb_map_led_get_index(xkb_info->keymap, |
| 2479 | XKB_LED_NAME_NUM); |
| 2480 | xkb_info->caps_led = xkb_map_led_get_index(xkb_info->keymap, |
| 2481 | XKB_LED_NAME_CAPS); |
| 2482 | xkb_info->scroll_led = xkb_map_led_get_index(xkb_info->keymap, |
| 2483 | XKB_LED_NAME_SCROLL); |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2484 | |
| 2485 | keymap_str = xkb_map_get_as_string(xkb_info->keymap); |
| 2486 | if (keymap_str == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2487 | weston_log("failed to get string version of keymap\n"); |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2488 | return -1; |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2489 | } |
| 2490 | xkb_info->keymap_size = strlen(keymap_str) + 1; |
| 2491 | |
Pekka Paalanen | 1da1b8f | 2012-06-06 16:59:43 +0300 | [diff] [blame] | 2492 | xkb_info->keymap_fd = os_create_anonymous_file(xkb_info->keymap_size); |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2493 | if (xkb_info->keymap_fd < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2494 | weston_log("creating a keymap file for %lu bytes failed: %m\n", |
Pekka Paalanen | 1da1b8f | 2012-06-06 16:59:43 +0300 | [diff] [blame] | 2495 | (unsigned long) xkb_info->keymap_size); |
| 2496 | goto err_keymap_str; |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | xkb_info->keymap_area = mmap(NULL, xkb_info->keymap_size, |
| 2500 | PROT_READ | PROT_WRITE, |
| 2501 | MAP_SHARED, xkb_info->keymap_fd, 0); |
| 2502 | if (xkb_info->keymap_area == MAP_FAILED) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2503 | weston_log("failed to mmap() %lu bytes\n", |
Pekka Paalanen | 1da1b8f | 2012-06-06 16:59:43 +0300 | [diff] [blame] | 2504 | (unsigned long) xkb_info->keymap_size); |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2505 | goto err_dev_zero; |
| 2506 | } |
| 2507 | strcpy(xkb_info->keymap_area, keymap_str); |
| 2508 | free(keymap_str); |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2509 | |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2510 | return 0; |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2511 | |
| 2512 | err_dev_zero: |
| 2513 | close(xkb_info->keymap_fd); |
| 2514 | xkb_info->keymap_fd = -1; |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 2515 | err_keymap_str: |
| 2516 | free(keymap_str); |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2517 | return -1; |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2518 | } |
| 2519 | |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2520 | static int |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2521 | weston_compositor_build_global_keymap(struct weston_compositor *ec) |
| 2522 | { |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2523 | if (ec->xkb_info.keymap != NULL) |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2524 | return 0; |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2525 | |
Daniel Stone | e379da9 | 2012-05-30 16:32:04 +0100 | [diff] [blame] | 2526 | ec->xkb_info.keymap = xkb_map_new_from_names(ec->xkb_context, |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2527 | &ec->xkb_names, |
| 2528 | 0); |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2529 | if (ec->xkb_info.keymap == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2530 | weston_log("failed to compile global XKB keymap\n"); |
| 2531 | weston_log(" tried rules %s, model %s, layout %s, variant %s, " |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2532 | "options %s\n", |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2533 | ec->xkb_names.rules, ec->xkb_names.model, |
| 2534 | ec->xkb_names.layout, ec->xkb_names.variant, |
| 2535 | ec->xkb_names.options); |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2536 | return -1; |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2537 | } |
| 2538 | |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2539 | if (weston_xkb_info_new_keymap(&ec->xkb_info) < 0) |
| 2540 | return -1; |
| 2541 | |
| 2542 | return 0; |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2543 | } |
| 2544 | |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2545 | WL_EXPORT int |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2546 | weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap) |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2547 | { |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2548 | if (seat->has_keyboard) |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2549 | return 0; |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2550 | |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2551 | if (keymap != NULL) { |
| 2552 | seat->xkb_info.keymap = xkb_map_ref(keymap); |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2553 | if (weston_xkb_info_new_keymap(&seat->xkb_info) < 0) |
| 2554 | return -1; |
| 2555 | } else { |
| 2556 | if (weston_compositor_build_global_keymap(seat->compositor) < 0) |
| 2557 | return -1; |
Daniel Stone | bb1df6a | 2012-05-30 16:32:06 +0100 | [diff] [blame] | 2558 | seat->xkb_info = seat->compositor->xkb_info; |
| 2559 | seat->xkb_info.keymap = xkb_map_ref(seat->xkb_info.keymap); |
| 2560 | } |
Daniel Stone | d65b909 | 2012-05-30 16:32:05 +0100 | [diff] [blame] | 2561 | |
| 2562 | seat->xkb_state.state = xkb_state_new(seat->xkb_info.keymap); |
| 2563 | if (seat->xkb_state.state == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2564 | weston_log("failed to initialise XKB state\n"); |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2565 | return -1; |
Daniel Stone | d65b909 | 2012-05-30 16:32:05 +0100 | [diff] [blame] | 2566 | } |
| 2567 | |
Daniel Stone | 71c3877 | 2012-06-22 13:21:30 +0100 | [diff] [blame] | 2568 | seat->xkb_state.leds = 0; |
Daniel Stone | d65b909 | 2012-05-30 16:32:05 +0100 | [diff] [blame] | 2569 | |
Jan Arne Petersen | a75a789 | 2013-01-16 21:26:50 +0100 | [diff] [blame] | 2570 | wl_keyboard_init(&seat->keyboard.keyboard); |
| 2571 | wl_seat_set_keyboard(&seat->seat, &seat->keyboard.keyboard); |
Daniel Stone | 9a9ee2c | 2012-05-30 16:32:03 +0100 | [diff] [blame] | 2572 | |
| 2573 | seat->has_keyboard = 1; |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2574 | |
| 2575 | return 0; |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2576 | } |
| 2577 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2578 | WL_EXPORT void |
Daniel Stone | 74419a2 | 2012-05-30 16:32:02 +0100 | [diff] [blame] | 2579 | weston_seat_init_pointer(struct weston_seat *seat) |
| 2580 | { |
| 2581 | if (seat->has_pointer) |
| 2582 | return; |
| 2583 | |
| 2584 | wl_pointer_init(&seat->pointer); |
| 2585 | wl_seat_set_pointer(&seat->seat, &seat->pointer); |
| 2586 | |
| 2587 | seat->has_pointer = 1; |
| 2588 | } |
| 2589 | |
| 2590 | WL_EXPORT void |
Daniel Stone | 74419a2 | 2012-05-30 16:32:02 +0100 | [diff] [blame] | 2591 | weston_seat_init_touch(struct weston_seat *seat) |
| 2592 | { |
| 2593 | if (seat->has_touch) |
| 2594 | return; |
| 2595 | |
| 2596 | wl_touch_init(&seat->touch); |
| 2597 | wl_seat_set_touch(&seat->seat, &seat->touch); |
| 2598 | |
| 2599 | seat->has_touch = 1; |
| 2600 | } |
| 2601 | |
| 2602 | WL_EXPORT void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2603 | weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec) |
Kristian Høgsberg | cddc0ad | 2008-11-24 00:31:49 -0500 | [diff] [blame] | 2604 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2605 | wl_seat_init(&seat->seat); |
Daniel Stone | 74419a2 | 2012-05-30 16:32:02 +0100 | [diff] [blame] | 2606 | seat->has_pointer = 0; |
| 2607 | seat->has_keyboard = 0; |
| 2608 | seat->has_touch = 0; |
Kristian Høgsberg | 02ef1c1 | 2010-12-06 21:35:19 -0500 | [diff] [blame] | 2609 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2610 | wl_display_add_global(ec->wl_display, &wl_seat_interface, seat, |
| 2611 | bind_seat); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 2612 | |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2613 | seat->sprite = NULL; |
| 2614 | seat->sprite_destroy_listener.notify = pointer_handle_sprite_destroy; |
Kristian Høgsberg | 8244b44 | 2011-06-23 15:44:14 -0400 | [diff] [blame] | 2615 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2616 | seat->compositor = ec; |
| 2617 | seat->hotspot_x = 16; |
| 2618 | seat->hotspot_y = 16; |
| 2619 | seat->modifier_state = 0; |
| 2620 | seat->num_tp = 0; |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 2621 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2622 | seat->drag_surface_destroy_listener.notify = |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2623 | handle_drag_surface_destroy; |
Ander Conselvan de Oliveira | c5fb9a7 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2624 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2625 | wl_list_insert(ec->seat_list.prev, &seat->link); |
Ander Conselvan de Oliveira | d6ea33d | 2012-03-27 17:36:39 +0300 | [diff] [blame] | 2626 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2627 | seat->new_drag_icon_listener.notify = device_handle_new_drag_icon; |
| 2628 | wl_signal_add(&seat->seat.drag_icon_signal, |
| 2629 | &seat->new_drag_icon_listener); |
Kristian Høgsberg | a7ceaff | 2012-06-03 10:20:13 -0400 | [diff] [blame] | 2630 | |
| 2631 | clipboard_create(seat); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 2632 | wl_signal_emit(&ec->seat_created_signal, seat); |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 2633 | } |
| 2634 | |
Pekka Paalanen | 07753fb | 2012-01-02 15:31:01 +0200 | [diff] [blame] | 2635 | WL_EXPORT void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2636 | weston_seat_release(struct weston_seat *seat) |
Pekka Paalanen | 07753fb | 2012-01-02 15:31:01 +0200 | [diff] [blame] | 2637 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2638 | wl_list_remove(&seat->link); |
Pekka Paalanen | 07753fb | 2012-01-02 15:31:01 +0200 | [diff] [blame] | 2639 | /* The global object is destroyed at wl_display_destroy() time. */ |
| 2640 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2641 | if (seat->sprite) |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2642 | pointer_unmap_sprite(seat); |
Pekka Paalanen | 07753fb | 2012-01-02 15:31:01 +0200 | [diff] [blame] | 2643 | |
Daniel Stone | 74419a2 | 2012-05-30 16:32:02 +0100 | [diff] [blame] | 2644 | if (seat->xkb_state.state != NULL) |
| 2645 | xkb_state_unref(seat->xkb_state.state); |
Daniel Stone | d65b909 | 2012-05-30 16:32:05 +0100 | [diff] [blame] | 2646 | xkb_info_destroy(&seat->xkb_info); |
Daniel Stone | 994679a | 2012-05-30 16:31:43 +0100 | [diff] [blame] | 2647 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2648 | wl_seat_release(&seat->seat); |
Pekka Paalanen | 07753fb | 2012-01-02 15:31:01 +0200 | [diff] [blame] | 2649 | } |
| 2650 | |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2651 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2652 | drag_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2653 | { |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2654 | empty_region(&es->pending.input); |
| 2655 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2656 | weston_surface_configure(es, |
| 2657 | es->geometry.x + sx, es->geometry.y + sy, |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2658 | width, height); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | static int |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2662 | device_setup_new_drag_surface(struct weston_seat *ws, |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2663 | struct weston_surface *surface) |
| 2664 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2665 | struct wl_seat *seat = &ws->seat; |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2666 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2667 | if (surface->configure) { |
| 2668 | wl_resource_post_error(&surface->surface.resource, |
| 2669 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2670 | "surface->configure already set"); |
| 2671 | return 0; |
| 2672 | } |
| 2673 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2674 | ws->drag_surface = surface; |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2675 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2676 | weston_surface_set_position(ws->drag_surface, |
| 2677 | wl_fixed_to_double(seat->pointer->x), |
| 2678 | wl_fixed_to_double(seat->pointer->y)); |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2679 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2680 | surface->configure = drag_surface_configure; |
| 2681 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2682 | wl_signal_add(&surface->surface.resource.destroy_signal, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2683 | &ws->drag_surface_destroy_listener); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2684 | |
| 2685 | return 1; |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2689 | device_release_drag_surface(struct weston_seat *seat) |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2690 | { |
Ander Conselvan de Oliveira | 5fd5580 | 2012-10-11 14:06:19 +0300 | [diff] [blame] | 2691 | if (weston_surface_is_mapped(seat->drag_surface)) |
| 2692 | weston_surface_unmap(seat->drag_surface); |
| 2693 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2694 | seat->drag_surface->configure = NULL; |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2695 | empty_region(&seat->drag_surface->pending.input); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2696 | wl_list_remove(&seat->drag_surface_destroy_listener.link); |
| 2697 | seat->drag_surface = NULL; |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2701 | device_map_drag_surface(struct weston_seat *seat) |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2702 | { |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2703 | struct wl_list *list; |
| 2704 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2705 | if (weston_surface_is_mapped(seat->drag_surface) || |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2706 | !seat->drag_surface->buffer_ref.buffer) |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2707 | return; |
| 2708 | |
Ander Conselvan de Oliveira | 37ffc3c | 2012-06-15 17:27:35 +0300 | [diff] [blame] | 2709 | if (seat->sprite && weston_surface_is_mapped(seat->sprite)) |
| 2710 | list = &seat->sprite->layer_link; |
| 2711 | else |
| 2712 | list = &seat->compositor->cursor_layer.surface_list; |
| 2713 | |
| 2714 | wl_list_insert(list, &seat->drag_surface->layer_link); |
Ander Conselvan de Oliveira | 231ba17 | 2012-09-14 16:12:04 +0300 | [diff] [blame] | 2715 | weston_surface_update_transform(seat->drag_surface); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2716 | empty_region(&seat->drag_surface->input); |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2717 | } |
| 2718 | |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 2719 | static void |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2720 | weston_seat_update_drag_surface(struct weston_seat *seat, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2721 | int dx, int dy) |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 2722 | { |
| 2723 | int surface_changed = 0; |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 2724 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2725 | if (!seat->drag_surface && !seat->seat.drag_surface) |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 2726 | return; |
| 2727 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2728 | if (seat->drag_surface && seat->seat.drag_surface && |
| 2729 | (&seat->drag_surface->surface.resource != |
| 2730 | &seat->seat.drag_surface->resource)) |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 2731 | /* between calls to this funcion we got a new drag_surface */ |
| 2732 | surface_changed = 1; |
| 2733 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2734 | if (!seat->seat.drag_surface || surface_changed) { |
| 2735 | device_release_drag_surface(seat); |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 2736 | if (!surface_changed) |
| 2737 | return; |
| 2738 | } |
| 2739 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2740 | if (!seat->drag_surface || surface_changed) { |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2741 | struct weston_surface *surface = (struct weston_surface *) |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2742 | seat->seat.drag_surface; |
| 2743 | if (!device_setup_new_drag_surface(seat, surface)) |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2744 | return; |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 2745 | } |
| 2746 | |
Ander Conselvan de Oliveira | 3e3bb32 | 2012-03-01 14:09:44 +0200 | [diff] [blame] | 2747 | /* the client may not have attached a buffer to the drag surface |
| 2748 | * when we setup it up, so check if map is needed on every update */ |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2749 | device_map_drag_surface(seat); |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 2750 | |
| 2751 | if (!dx && !dy) |
| 2752 | return; |
| 2753 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2754 | weston_surface_set_position(seat->drag_surface, |
| 2755 | seat->drag_surface->geometry.x + wl_fixed_to_double(dx), |
| 2756 | seat->drag_surface->geometry.y + wl_fixed_to_double(dy)); |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | WL_EXPORT void |
| 2760 | weston_compositor_update_drag_surfaces(struct weston_compositor *compositor) |
| 2761 | { |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 2762 | struct weston_seat *seat; |
| 2763 | |
| 2764 | wl_list_for_each(seat, &compositor->seat_list, link) |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 2765 | weston_seat_update_drag_surface(seat, 0, 0); |
Ander Conselvan de Oliveira | 30eebc7 | 2012-02-15 17:02:57 +0200 | [diff] [blame] | 2766 | } |
| 2767 | |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2768 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2769 | bind_output(struct wl_client *client, |
| 2770 | void *data, uint32_t version, uint32_t id) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 2771 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2772 | struct weston_output *output = data; |
| 2773 | struct weston_mode *mode; |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 2774 | struct wl_resource *resource; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2775 | |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 2776 | resource = wl_client_add_object(client, |
| 2777 | &wl_output_interface, NULL, id, data); |
| 2778 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 2779 | wl_list_insert(&output->resource_list, &resource->link); |
| 2780 | resource->destroy = unbind_resource; |
| 2781 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2782 | wl_output_send_geometry(resource, |
| 2783 | output->x, |
| 2784 | output->y, |
| 2785 | output->mm_width, |
| 2786 | output->mm_height, |
| 2787 | output->subpixel, |
Kristian Høgsberg | 0e69647 | 2012-07-22 15:49:57 -0400 | [diff] [blame] | 2788 | output->make, output->model, |
Kristian Høgsberg | 05890dc | 2012-08-10 10:09:20 -0400 | [diff] [blame] | 2789 | output->transform); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 2790 | |
| 2791 | wl_list_for_each (mode, &output->mode_list, link) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2792 | wl_output_send_mode(resource, |
| 2793 | mode->flags, |
| 2794 | mode->width, |
| 2795 | mode->height, |
| 2796 | mode->refresh); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 2797 | } |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2798 | } |
| 2799 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2800 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2801 | weston_output_destroy(struct weston_output *output) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 2802 | { |
Benjamin Franzke | b687940 | 2012-04-10 18:28:54 +0200 | [diff] [blame] | 2803 | struct weston_compositor *c = output->compositor; |
| 2804 | |
Kristian Høgsberg | e75cb7f | 2011-06-21 15:27:41 -0400 | [diff] [blame] | 2805 | pixman_region32_fini(&output->region); |
Ander Conselvan de Oliveira | b8fcca9 | 2012-11-16 17:23:52 +0200 | [diff] [blame] | 2806 | pixman_region32_fini(&output->previous_damage); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 2807 | output->compositor->output_id_pool &= ~(1 << output->id); |
Benjamin Franzke | b687940 | 2012-04-10 18:28:54 +0200 | [diff] [blame] | 2808 | |
| 2809 | wl_display_remove_global(c->wl_display, output->global); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2810 | } |
| 2811 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2812 | static void |
| 2813 | weston_output_compute_transform(struct weston_output *output) |
| 2814 | { |
| 2815 | struct weston_matrix transform; |
| 2816 | int flip; |
| 2817 | |
| 2818 | weston_matrix_init(&transform); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 2819 | transform.type = WESTON_MATRIX_TRANSFORM_ROTATE; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2820 | |
| 2821 | switch(output->transform) { |
| 2822 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 2823 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 2824 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 2825 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 2826 | transform.type |= WESTON_MATRIX_TRANSFORM_OTHER; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2827 | flip = -1; |
| 2828 | break; |
| 2829 | default: |
| 2830 | flip = 1; |
| 2831 | break; |
| 2832 | } |
| 2833 | |
| 2834 | switch(output->transform) { |
| 2835 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 2836 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 2837 | transform.d[0] = flip; |
| 2838 | transform.d[1] = 0; |
| 2839 | transform.d[4] = 0; |
| 2840 | transform.d[5] = 1; |
| 2841 | break; |
| 2842 | case WL_OUTPUT_TRANSFORM_90: |
| 2843 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 2844 | transform.d[0] = 0; |
| 2845 | transform.d[1] = -flip; |
| 2846 | transform.d[4] = 1; |
| 2847 | transform.d[5] = 0; |
| 2848 | break; |
| 2849 | case WL_OUTPUT_TRANSFORM_180: |
| 2850 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 2851 | transform.d[0] = -flip; |
| 2852 | transform.d[1] = 0; |
| 2853 | transform.d[4] = 0; |
| 2854 | transform.d[5] = -1; |
| 2855 | break; |
| 2856 | case WL_OUTPUT_TRANSFORM_270: |
| 2857 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 2858 | transform.d[0] = 0; |
| 2859 | transform.d[1] = flip; |
| 2860 | transform.d[4] = -1; |
| 2861 | transform.d[5] = 0; |
| 2862 | break; |
| 2863 | default: |
| 2864 | break; |
| 2865 | } |
| 2866 | |
| 2867 | weston_matrix_multiply(&output->matrix, &transform); |
| 2868 | } |
| 2869 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2870 | WL_EXPORT void |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2871 | weston_output_update_matrix(struct weston_output *output) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2872 | { |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 2873 | float magnification; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2874 | struct weston_matrix camera; |
| 2875 | struct weston_matrix modelview; |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 2876 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2877 | weston_matrix_init(&output->matrix); |
| 2878 | weston_matrix_translate(&output->matrix, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2879 | -(output->x + (output->border.right + output->width - output->border.left) / 2.0), |
| 2880 | -(output->y + (output->border.bottom + output->height - output->border.top) / 2.0), 0); |
Benjamin Franzke | 1b765ff | 2011-02-18 16:51:37 +0100 | [diff] [blame] | 2881 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2882 | weston_matrix_scale(&output->matrix, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2883 | 2.0 / (output->width + output->border.left + output->border.right), |
| 2884 | -2.0 / (output->height + output->border.top + output->border.bottom), 1); |
| 2885 | |
| 2886 | weston_output_compute_transform(output); |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 2887 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2888 | if (output->zoom.active) { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2889 | magnification = 1 / (1 - output->zoom.spring_z.current); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2890 | weston_matrix_init(&camera); |
| 2891 | weston_matrix_init(&modelview); |
Scott Moreau | 8dacaab | 2012-06-17 18:10:58 -0600 | [diff] [blame] | 2892 | weston_output_update_zoom(output, output->zoom.type); |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2893 | weston_matrix_translate(&camera, output->zoom.trans_x, |
Kristian Høgsberg | 99fd101 | 2012-08-10 09:57:56 -0400 | [diff] [blame] | 2894 | -output->zoom.trans_y, 0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2895 | weston_matrix_invert(&modelview, &camera); |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 2896 | weston_matrix_scale(&modelview, magnification, magnification, 1.0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2897 | weston_matrix_multiply(&output->matrix, &modelview); |
| 2898 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2899 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2900 | output->dirty = 0; |
| 2901 | } |
| 2902 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2903 | static void |
| 2904 | weston_output_transform_init(struct weston_output *output, uint32_t transform) |
| 2905 | { |
| 2906 | output->transform = transform; |
| 2907 | |
| 2908 | switch (transform) { |
| 2909 | case WL_OUTPUT_TRANSFORM_90: |
| 2910 | case WL_OUTPUT_TRANSFORM_270: |
| 2911 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 2912 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 2913 | /* Swap width and height */ |
| 2914 | output->width = output->current->height; |
| 2915 | output->height = output->current->width; |
| 2916 | break; |
| 2917 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 2918 | case WL_OUTPUT_TRANSFORM_180: |
| 2919 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 2920 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 2921 | output->width = output->current->width; |
| 2922 | output->height = output->current->height; |
| 2923 | break; |
| 2924 | default: |
| 2925 | break; |
| 2926 | } |
| 2927 | } |
| 2928 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2929 | WL_EXPORT void |
| 2930 | weston_output_move(struct weston_output *output, int x, int y) |
| 2931 | { |
| 2932 | output->x = x; |
| 2933 | output->y = y; |
| 2934 | |
Ander Conselvan de Oliveira | b8fcca9 | 2012-11-16 17:23:52 +0200 | [diff] [blame] | 2935 | pixman_region32_init(&output->previous_damage); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2936 | pixman_region32_init_rect(&output->region, x, y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2937 | output->width, |
| 2938 | output->height); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2939 | } |
| 2940 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2941 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2942 | weston_output_init(struct weston_output *output, struct weston_compositor *c, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2943 | int x, int y, int width, int height, uint32_t transform) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2944 | { |
| 2945 | output->compositor = c; |
| 2946 | output->x = x; |
| 2947 | output->y = y; |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 2948 | output->border.top = 0; |
| 2949 | output->border.bottom = 0; |
| 2950 | output->border.left = 0; |
| 2951 | output->border.right = 0; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 2952 | output->mm_width = width; |
| 2953 | output->mm_height = height; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2954 | output->dirty = 1; |
| 2955 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2956 | weston_output_transform_init(output, transform); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 2957 | weston_output_init_zoom(output); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2958 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2959 | weston_output_move(output, x, y); |
Benjamin Franzke | 78db848 | 2012-04-10 18:35:33 +0200 | [diff] [blame] | 2960 | weston_output_damage(output); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2961 | |
Kristian Høgsberg | 5fb70bf | 2012-05-24 12:29:46 -0400 | [diff] [blame] | 2962 | wl_signal_init(&output->frame_signal); |
Scott Moreau | 9d1b112 | 2012-06-08 19:40:53 -0600 | [diff] [blame] | 2963 | wl_list_init(&output->animation_list); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 2964 | wl_list_init(&output->resource_list); |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 2965 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 2966 | output->id = ffs(~output->compositor->output_id_pool) - 1; |
| 2967 | output->compositor->output_id_pool |= 1 << output->id; |
| 2968 | |
Benjamin Franzke | b687940 | 2012-04-10 18:28:54 +0200 | [diff] [blame] | 2969 | output->global = |
| 2970 | wl_display_add_global(c->wl_display, &wl_output_interface, |
| 2971 | output, bind_output); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2972 | } |
| 2973 | |
Benjamin Franzke | 315b3dc | 2011-03-08 11:32:57 +0100 | [diff] [blame] | 2974 | static void |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 2975 | compositor_bind(struct wl_client *client, |
| 2976 | void *data, uint32_t version, uint32_t id) |
| 2977 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2978 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 2979 | |
| 2980 | wl_client_add_object(client, &wl_compositor_interface, |
| 2981 | &compositor_interface, id, compositor); |
| 2982 | } |
| 2983 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 2984 | static void |
Martin Minarik | f12c287 | 2012-06-11 00:57:39 +0200 | [diff] [blame] | 2985 | log_uname(void) |
| 2986 | { |
| 2987 | struct utsname usys; |
| 2988 | |
| 2989 | uname(&usys); |
| 2990 | |
| 2991 | weston_log("OS: %s, %s, %s, %s\n", usys.sysname, usys.release, |
| 2992 | usys.version, usys.machine); |
| 2993 | } |
| 2994 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2995 | WL_EXPORT int |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 2996 | weston_environment_get_fd(const char *env) |
| 2997 | { |
| 2998 | char *e, *end; |
| 2999 | int fd, flags; |
| 3000 | |
| 3001 | e = getenv(env); |
| 3002 | if (!e) |
| 3003 | return -1; |
| 3004 | fd = strtol(e, &end, 0); |
| 3005 | if (*end != '\0') |
| 3006 | return -1; |
| 3007 | |
| 3008 | flags = fcntl(fd, F_GETFD); |
| 3009 | if (flags == -1) |
| 3010 | return -1; |
| 3011 | |
| 3012 | fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
| 3013 | unsetenv(env); |
| 3014 | |
| 3015 | return fd; |
| 3016 | } |
| 3017 | |
| 3018 | WL_EXPORT int |
Daniel Stone | baf4359 | 2012-06-01 11:11:10 -0400 | [diff] [blame] | 3019 | weston_compositor_init(struct weston_compositor *ec, |
| 3020 | struct wl_display *display, |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 3021 | int *argc, char *argv[], |
Daniel Stone | c1be8e5 | 2012-06-01 11:14:02 -0400 | [diff] [blame] | 3022 | const char *config_file) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 3023 | { |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 3024 | struct wl_event_loop *loop; |
Daniel Stone | e2ef43a | 2012-06-01 12:14:05 +0100 | [diff] [blame] | 3025 | struct xkb_rule_names xkb_names; |
| 3026 | const struct config_key keyboard_config_keys[] = { |
| 3027 | { "keymap_rules", CONFIG_KEY_STRING, &xkb_names.rules }, |
| 3028 | { "keymap_model", CONFIG_KEY_STRING, &xkb_names.model }, |
| 3029 | { "keymap_layout", CONFIG_KEY_STRING, &xkb_names.layout }, |
| 3030 | { "keymap_variant", CONFIG_KEY_STRING, &xkb_names.variant }, |
| 3031 | { "keymap_options", CONFIG_KEY_STRING, &xkb_names.options }, |
| 3032 | }; |
| 3033 | const struct config_section cs[] = { |
| 3034 | { "keyboard", |
| 3035 | keyboard_config_keys, ARRAY_LENGTH(keyboard_config_keys) }, |
| 3036 | }; |
| 3037 | |
| 3038 | memset(&xkb_names, 0, sizeof(xkb_names)); |
| 3039 | parse_config_file(config_file, cs, ARRAY_LENGTH(cs), ec); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3040 | |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 3041 | ec->wl_display = display; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 3042 | wl_signal_init(&ec->destroy_signal); |
| 3043 | wl_signal_init(&ec->activate_signal); |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 3044 | wl_signal_init(&ec->kill_signal); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3045 | wl_signal_init(&ec->idle_signal); |
| 3046 | wl_signal_init(&ec->wake_signal); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3047 | wl_signal_init(&ec->show_input_panel_signal); |
| 3048 | wl_signal_init(&ec->hide_input_panel_signal); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 3049 | wl_signal_init(&ec->seat_created_signal); |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 3050 | ec->launcher_sock = weston_environment_get_fd("WESTON_LAUNCHER_SOCK"); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3051 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 3052 | ec->output_id_pool = 0; |
| 3053 | |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 3054 | if (!wl_display_add_global(display, &wl_compositor_interface, |
| 3055 | ec, compositor_bind)) |
| 3056 | return -1; |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 3057 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 3058 | wl_list_init(&ec->surface_list); |
| 3059 | wl_list_init(&ec->layer_list); |
| 3060 | wl_list_init(&ec->seat_list); |
| 3061 | wl_list_init(&ec->output_list); |
| 3062 | wl_list_init(&ec->key_binding_list); |
| 3063 | wl_list_init(&ec->button_binding_list); |
| 3064 | wl_list_init(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 3065 | wl_list_init(&ec->debug_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 3066 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3067 | weston_plane_init(&ec->primary_plane, 0, 0); |
| 3068 | |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 3069 | if (weston_compositor_xkb_init(ec, &xkb_names) < 0) |
| 3070 | return -1; |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 3071 | |
| 3072 | ec->ping_handler = NULL; |
| 3073 | |
| 3074 | screenshooter_create(ec); |
| 3075 | text_cursor_position_notifier_create(ec); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 3076 | text_backend_init(ec); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 3077 | |
| 3078 | wl_data_device_manager_init(ec->wl_display); |
| 3079 | |
Kristian Høgsberg | 9629fe3 | 2012-03-26 15:56:39 -0400 | [diff] [blame] | 3080 | wl_display_init_shm(display); |
Kristian Høgsberg | b5819dc | 2011-04-25 15:08:20 -0400 | [diff] [blame] | 3081 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 3082 | loop = wl_display_get_event_loop(ec->wl_display); |
| 3083 | ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec); |
| 3084 | wl_event_source_timer_update(ec->idle_source, ec->idle_time * 1000); |
| 3085 | |
| 3086 | ec->input_loop = wl_event_loop_create(); |
| 3087 | |
Kristian Høgsberg | 861a50c | 2012-09-05 22:02:22 -0400 | [diff] [blame] | 3088 | weston_layer_init(&ec->fade_layer, &ec->layer_list); |
| 3089 | weston_layer_init(&ec->cursor_layer, &ec->fade_layer.link); |
| 3090 | |
| 3091 | weston_compositor_schedule_repaint(ec); |
| 3092 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 3093 | return 0; |
| 3094 | } |
| 3095 | |
Benjamin Franzke | b826302 | 2011-08-30 11:32:47 +0200 | [diff] [blame] | 3096 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3097 | weston_compositor_shutdown(struct weston_compositor *ec) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 3098 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3099 | struct weston_output *output, *next; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 3100 | |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 3101 | wl_event_source_remove(ec->idle_source); |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 3102 | if (ec->input_loop_source) |
| 3103 | wl_event_source_remove(ec->input_loop_source); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 3104 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 3105 | /* Destroy all outputs associated with this compositor */ |
Tiago Vignatti | b303a1d | 2011-12-18 22:27:40 +0200 | [diff] [blame] | 3106 | wl_list_for_each_safe(output, next, &ec->output_list, link) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 3107 | output->destroy(output); |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 3108 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3109 | weston_binding_list_destroy_all(&ec->key_binding_list); |
| 3110 | weston_binding_list_destroy_all(&ec->button_binding_list); |
| 3111 | weston_binding_list_destroy_all(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 3112 | weston_binding_list_destroy_all(&ec->debug_binding_list); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 3113 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3114 | weston_plane_release(&ec->primary_plane); |
| 3115 | |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 3116 | wl_array_release(&ec->vertices); |
| 3117 | wl_array_release(&ec->indices); |
Rob Clark | 0e5a2d0 | 2012-08-30 16:47:18 -0500 | [diff] [blame] | 3118 | wl_array_release(&ec->vtxcnt); |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 3119 | |
| 3120 | wl_event_loop_destroy(ec->input_loop); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 3121 | } |
| 3122 | |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 3123 | WL_EXPORT void |
| 3124 | weston_version(int *major, int *minor, int *micro) |
| 3125 | { |
| 3126 | *major = WESTON_VERSION_MAJOR; |
| 3127 | *minor = WESTON_VERSION_MINOR; |
| 3128 | *micro = WESTON_VERSION_MICRO; |
| 3129 | } |
| 3130 | |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 3131 | static int on_term_signal(int signal_number, void *data) |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 3132 | { |
Kristian Høgsberg | 6bded3f | 2011-08-12 14:55:07 -0400 | [diff] [blame] | 3133 | struct wl_display *display = data; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 3134 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3135 | weston_log("caught signal %d\n", signal_number); |
Kristian Høgsberg | 6bded3f | 2011-08-12 14:55:07 -0400 | [diff] [blame] | 3136 | wl_display_terminate(display); |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 3137 | |
| 3138 | return 1; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 3139 | } |
| 3140 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 3141 | #ifdef HAVE_LIBUNWIND |
| 3142 | |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 3143 | static void |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 3144 | print_backtrace(void) |
| 3145 | { |
| 3146 | unw_cursor_t cursor; |
| 3147 | unw_context_t context; |
| 3148 | unw_word_t off; |
| 3149 | unw_proc_info_t pip; |
| 3150 | int ret, i = 0; |
| 3151 | char procname[256]; |
| 3152 | const char *filename; |
| 3153 | Dl_info dlinfo; |
| 3154 | |
| 3155 | pip.unwind_info = NULL; |
| 3156 | ret = unw_getcontext(&context); |
| 3157 | if (ret) { |
| 3158 | weston_log("unw_getcontext: %d\n", ret); |
| 3159 | return; |
| 3160 | } |
| 3161 | |
| 3162 | ret = unw_init_local(&cursor, &context); |
| 3163 | if (ret) { |
| 3164 | weston_log("unw_init_local: %d\n", ret); |
| 3165 | return; |
| 3166 | } |
| 3167 | |
| 3168 | ret = unw_step(&cursor); |
| 3169 | while (ret > 0) { |
| 3170 | ret = unw_get_proc_info(&cursor, &pip); |
| 3171 | if (ret) { |
| 3172 | weston_log("unw_get_proc_info: %d\n", ret); |
| 3173 | break; |
| 3174 | } |
| 3175 | |
| 3176 | ret = unw_get_proc_name(&cursor, procname, 256, &off); |
| 3177 | if (ret && ret != -UNW_ENOMEM) { |
| 3178 | if (ret != -UNW_EUNSPEC) |
| 3179 | weston_log("unw_get_proc_name: %d\n", ret); |
| 3180 | procname[0] = '?'; |
| 3181 | procname[1] = 0; |
| 3182 | } |
| 3183 | |
| 3184 | if (dladdr((void *)(pip.start_ip + off), &dlinfo) && dlinfo.dli_fname && |
| 3185 | *dlinfo.dli_fname) |
| 3186 | filename = dlinfo.dli_fname; |
| 3187 | else |
| 3188 | filename = "?"; |
| 3189 | |
| 3190 | weston_log("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname, |
| 3191 | ret == -UNW_ENOMEM ? "..." : "", (int)off, (void *)(pip.start_ip + off)); |
| 3192 | |
| 3193 | ret = unw_step(&cursor); |
| 3194 | if (ret < 0) |
| 3195 | weston_log("unw_step: %d\n", ret); |
| 3196 | } |
| 3197 | } |
| 3198 | |
| 3199 | #else |
| 3200 | |
| 3201 | static void |
| 3202 | print_backtrace(void) |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 3203 | { |
| 3204 | void *buffer[32]; |
| 3205 | int i, count; |
| 3206 | Dl_info info; |
| 3207 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 3208 | count = backtrace(buffer, ARRAY_LENGTH(buffer)); |
| 3209 | for (i = 0; i < count; i++) { |
| 3210 | dladdr(buffer[i], &info); |
| 3211 | weston_log(" [%016lx] %s (%s)\n", |
| 3212 | (long) buffer[i], |
| 3213 | info.dli_sname ? info.dli_sname : "--", |
| 3214 | info.dli_fname); |
| 3215 | } |
| 3216 | } |
| 3217 | |
| 3218 | #endif |
| 3219 | |
| 3220 | static void |
| 3221 | on_segv_signal(int s, siginfo_t *siginfo, void *context) |
| 3222 | { |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 3223 | /* This SIGSEGV handler will do a best-effort backtrace, and |
| 3224 | * then call the backend restore function, which will switch |
| 3225 | * back to the vt we launched from or ungrab X etc and then |
| 3226 | * raise SIGTRAP. If we run weston under gdb from X or a |
| 3227 | * different vt, and tell gdb "handle SIGSEGV nostop", this |
| 3228 | * will allow weston to switch back to gdb on crash and then |
| 3229 | * gdb will catch the crash with SIGTRAP. */ |
| 3230 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3231 | weston_log("caught segv\n"); |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 3232 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 3233 | print_backtrace(); |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 3234 | |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 3235 | segv_compositor->restore(segv_compositor); |
| 3236 | |
| 3237 | raise(SIGTRAP); |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 3238 | } |
| 3239 | |
| 3240 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3241 | static void * |
Kristian Høgsberg | a4624f6 | 2012-09-11 14:08:26 -0400 | [diff] [blame] | 3242 | load_module(const char *name, const char *entrypoint) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3243 | { |
| 3244 | char path[PATH_MAX]; |
| 3245 | void *module, *init; |
| 3246 | |
| 3247 | if (name[0] != '/') |
Chad Versace | bf38190 | 2012-05-23 23:42:15 -0700 | [diff] [blame] | 3248 | snprintf(path, sizeof path, "%s/%s", MODULEDIR, name); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3249 | else |
Benjamin Franzke | b7acce6 | 2011-05-06 23:19:22 +0200 | [diff] [blame] | 3250 | snprintf(path, sizeof path, "%s", name); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3251 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3252 | module = dlopen(path, RTLD_NOW | RTLD_NOLOAD); |
| 3253 | if (module) { |
| 3254 | weston_log("Module '%s' already loaded\n", path); |
| 3255 | dlclose(module); |
| 3256 | return NULL; |
| 3257 | } |
| 3258 | |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 3259 | weston_log("Loading module '%s'\n", path); |
Kristian Høgsberg | 1acd9f8 | 2012-07-26 11:39:26 -0400 | [diff] [blame] | 3260 | module = dlopen(path, RTLD_NOW); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3261 | if (!module) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 3262 | weston_log("Failed to load module: %s\n", dlerror()); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3263 | return NULL; |
| 3264 | } |
| 3265 | |
| 3266 | init = dlsym(module, entrypoint); |
| 3267 | if (!init) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 3268 | weston_log("Failed to lookup init function: %s\n", dlerror()); |
Rob Bradford | c9e64ab | 2012-12-05 18:47:10 +0000 | [diff] [blame] | 3269 | dlclose(module); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3270 | return NULL; |
| 3271 | } |
| 3272 | |
| 3273 | return init; |
| 3274 | } |
| 3275 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3276 | static int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 3277 | load_modules(struct weston_compositor *ec, const char *modules, |
| 3278 | int *argc, char *argv[], const char *config_file) |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3279 | { |
| 3280 | const char *p, *end; |
| 3281 | char buffer[256]; |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 3282 | int (*module_init)(struct weston_compositor *ec, |
| 3283 | int *argc, char *argv[], const char *config_file); |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3284 | |
| 3285 | if (modules == NULL) |
| 3286 | return 0; |
| 3287 | |
| 3288 | p = modules; |
| 3289 | while (*p) { |
| 3290 | end = strchrnul(p, ','); |
| 3291 | snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p); |
| 3292 | module_init = load_module(buffer, "module_init"); |
| 3293 | if (module_init) |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 3294 | module_init(ec, argc, argv, config_file); |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3295 | p = end; |
| 3296 | while (*p == ',') |
| 3297 | p++; |
| 3298 | |
| 3299 | } |
| 3300 | |
| 3301 | return 0; |
| 3302 | } |
| 3303 | |
Pekka Paalanen | 78a0b57 | 2012-06-06 16:59:44 +0300 | [diff] [blame] | 3304 | static const char xdg_error_message[] = |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 3305 | "fatal: environment variable XDG_RUNTIME_DIR is not set.\n"; |
| 3306 | |
| 3307 | static const char xdg_wrong_message[] = |
| 3308 | "fatal: environment variable XDG_RUNTIME_DIR\n" |
| 3309 | "is set to \"%s\", which is not a directory.\n"; |
| 3310 | |
| 3311 | static const char xdg_wrong_mode_message[] = |
| 3312 | "warning: XDG_RUNTIME_DIR \"%s\" is not configured\n" |
| 3313 | "correctly. Unix access mode must be 0700 but is %o,\n" |
| 3314 | "and XDG_RUNTIME_DIR must be owned by the user, but is\n" |
Kristian Høgsberg | 3033425 | 2012-06-20 14:24:21 -0400 | [diff] [blame] | 3315 | "owned by UID %d.\n"; |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 3316 | |
| 3317 | static const char xdg_detail_message[] = |
Pekka Paalanen | 78a0b57 | 2012-06-06 16:59:44 +0300 | [diff] [blame] | 3318 | "Refer to your distribution on how to get it, or\n" |
| 3319 | "http://www.freedesktop.org/wiki/Specifications/basedir-spec\n" |
| 3320 | "on how to implement it.\n"; |
| 3321 | |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 3322 | static void |
| 3323 | verify_xdg_runtime_dir(void) |
| 3324 | { |
| 3325 | char *dir = getenv("XDG_RUNTIME_DIR"); |
| 3326 | struct stat s; |
| 3327 | |
| 3328 | if (!dir) { |
| 3329 | weston_log(xdg_error_message); |
| 3330 | weston_log_continue(xdg_detail_message); |
| 3331 | exit(EXIT_FAILURE); |
| 3332 | } |
| 3333 | |
| 3334 | if (stat(dir, &s) || !S_ISDIR(s.st_mode)) { |
| 3335 | weston_log(xdg_wrong_message, dir); |
| 3336 | weston_log_continue(xdg_detail_message); |
| 3337 | exit(EXIT_FAILURE); |
| 3338 | } |
| 3339 | |
| 3340 | if ((s.st_mode & 0777) != 0700 || s.st_uid != getuid()) { |
| 3341 | weston_log(xdg_wrong_mode_message, |
| 3342 | dir, s.st_mode & 0777, s.st_uid); |
| 3343 | weston_log_continue(xdg_detail_message); |
| 3344 | } |
| 3345 | } |
| 3346 | |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3347 | static int |
| 3348 | usage(int error_code) |
| 3349 | { |
| 3350 | fprintf(stderr, |
| 3351 | "Usage: weston [OPTIONS]\n\n" |
| 3352 | "This is weston version " VERSION ", the Wayland reference compositor.\n" |
| 3353 | "Weston supports multiple backends, and depending on which backend is in use\n" |
| 3354 | "different options will be accepted.\n\n" |
| 3355 | |
| 3356 | |
| 3357 | "Core options:\n\n" |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 3358 | " --version\t\tPrint weston version\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3359 | " -B, --backend=MODULE\tBackend module, one of drm-backend.so,\n" |
| 3360 | "\t\t\t\tx11-backend.so or wayland-backend.so\n" |
| 3361 | " -S, --socket=NAME\tName of socket to listen on\n" |
| 3362 | " -i, --idle-time=SECS\tIdle time in seconds\n" |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3363 | " --modules\t\tLoad the comma-separated list of modules\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3364 | " --log==FILE\t\tLog to the given file\n" |
| 3365 | " -h, --help\t\tThis help message\n\n"); |
| 3366 | |
| 3367 | fprintf(stderr, |
| 3368 | "Options for drm-backend.so:\n\n" |
| 3369 | " --connector=ID\tBring up only this connector\n" |
| 3370 | " --seat=SEAT\t\tThe seat that weston should run on\n" |
| 3371 | " --tty=TTY\t\tThe tty to use\n" |
Ander Conselvan de Oliveira | 23e72b8 | 2013-01-25 15:13:06 +0200 | [diff] [blame] | 3372 | " --use-pixman\t\tUse the pixman (CPU) renderer\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3373 | " --current-mode\tPrefer current KMS mode over EDID preferred mode\n\n"); |
| 3374 | |
| 3375 | fprintf(stderr, |
| 3376 | "Options for x11-backend.so:\n\n" |
| 3377 | " --width=WIDTH\t\tWidth of X window\n" |
| 3378 | " --height=HEIGHT\tHeight of X window\n" |
| 3379 | " --fullscreen\t\tRun in fullscreen mode\n" |
Kristian Høgsberg | efaca34 | 2013-01-07 15:52:44 -0500 | [diff] [blame] | 3380 | " --use-pixman\t\tUse the pixman (CPU) renderer\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3381 | " --output-count=COUNT\tCreate multiple outputs\n" |
| 3382 | " --no-input\t\tDont create input devices\n\n"); |
| 3383 | |
| 3384 | fprintf(stderr, |
| 3385 | "Options for wayland-backend.so:\n\n" |
| 3386 | " --width=WIDTH\t\tWidth of Wayland surface\n" |
| 3387 | " --height=HEIGHT\tHeight of Wayland surface\n" |
| 3388 | " --display=DISPLAY\tWayland display to connect to\n\n"); |
| 3389 | |
| 3390 | exit(error_code); |
| 3391 | } |
| 3392 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3393 | int main(int argc, char *argv[]) |
| 3394 | { |
Pekka Paalanen | 3ab7269 | 2012-06-08 17:27:28 +0300 | [diff] [blame] | 3395 | int ret = EXIT_SUCCESS; |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3396 | struct wl_display *display; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3397 | struct weston_compositor *ec; |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 3398 | struct wl_event_source *signals[4]; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 3399 | struct wl_event_loop *loop; |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 3400 | struct sigaction segv_action; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3401 | struct weston_compositor |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3402 | *(*backend_init)(struct wl_display *display, |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 3403 | int *argc, char *argv[], const char *config_file); |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 3404 | int i; |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3405 | char *backend = NULL; |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3406 | const char *modules = "desktop-shell.so", *option_modules = NULL; |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 3407 | char *log = NULL; |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3408 | int32_t idle_time = 300; |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3409 | int32_t help = 0; |
Kristian Høgsberg | eb00e2e | 2012-09-11 14:29:47 -0400 | [diff] [blame] | 3410 | char *socket_name = "wayland-0"; |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 3411 | int32_t version = 0; |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 3412 | char *config_file; |
| 3413 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3414 | const struct config_key core_config_keys[] = { |
| 3415 | { "modules", CONFIG_KEY_STRING, &modules }, |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 3416 | }; |
| 3417 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 3418 | const struct config_section cs[] = { |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3419 | { "core", |
| 3420 | core_config_keys, ARRAY_LENGTH(core_config_keys) }, |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 3421 | }; |
Kristian Høgsberg | d34912c | 2011-05-02 10:36:04 -0400 | [diff] [blame] | 3422 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3423 | const struct weston_option core_options[] = { |
| 3424 | { WESTON_OPTION_STRING, "backend", 'B', &backend }, |
| 3425 | { WESTON_OPTION_STRING, "socket", 'S', &socket_name }, |
| 3426 | { WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time }, |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3427 | { WESTON_OPTION_STRING, "modules", 0, &option_modules }, |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 3428 | { WESTON_OPTION_STRING, "log", 0, &log }, |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3429 | { WESTON_OPTION_BOOLEAN, "help", 'h', &help }, |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 3430 | { WESTON_OPTION_BOOLEAN, "version", 0, &version }, |
Kristian Høgsberg | d34912c | 2011-05-02 10:36:04 -0400 | [diff] [blame] | 3431 | }; |
Kristian Høgsberg | d653126 | 2008-12-12 11:06:18 -0500 | [diff] [blame] | 3432 | |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 3433 | parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv); |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3434 | |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3435 | if (help) |
| 3436 | usage(EXIT_SUCCESS); |
| 3437 | |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 3438 | if (version) { |
| 3439 | printf(PACKAGE_STRING "\n"); |
| 3440 | return EXIT_SUCCESS; |
| 3441 | } |
| 3442 | |
Rafal Mielniczuk | 6e0a7d8 | 2012-06-09 15:10:28 +0200 | [diff] [blame] | 3443 | weston_log_file_open(log); |
| 3444 | |
Pekka Paalanen | bce4c2b | 2012-06-11 14:04:21 +0300 | [diff] [blame] | 3445 | weston_log("%s\n" |
| 3446 | STAMP_SPACE "%s\n" |
| 3447 | STAMP_SPACE "Bug reports to: %s\n" |
| 3448 | STAMP_SPACE "Build: %s\n", |
| 3449 | PACKAGE_STRING, PACKAGE_URL, PACKAGE_BUGREPORT, |
Kristian Høgsberg | 23cf9eb | 2012-06-11 12:06:30 -0400 | [diff] [blame] | 3450 | BUILD_ID); |
Pekka Paalanen | 7f4d1a3 | 2012-06-11 14:06:03 +0300 | [diff] [blame] | 3451 | log_uname(); |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 3452 | |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 3453 | verify_xdg_runtime_dir(); |
| 3454 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3455 | display = wl_display_create(); |
| 3456 | |
Tiago Vignatti | 2116b89 | 2011-08-08 05:52:59 -0700 | [diff] [blame] | 3457 | loop = wl_display_get_event_loop(display); |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 3458 | signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal, |
| 3459 | display); |
| 3460 | signals[1] = wl_event_loop_add_signal(loop, SIGINT, on_term_signal, |
| 3461 | display); |
| 3462 | signals[2] = wl_event_loop_add_signal(loop, SIGQUIT, on_term_signal, |
| 3463 | display); |
Tiago Vignatti | 2116b89 | 2011-08-08 05:52:59 -0700 | [diff] [blame] | 3464 | |
| 3465 | wl_list_init(&child_process_list); |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 3466 | signals[3] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler, |
| 3467 | NULL); |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 3468 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3469 | if (!backend) { |
| 3470 | if (getenv("WAYLAND_DISPLAY")) |
| 3471 | backend = "wayland-backend.so"; |
| 3472 | else if (getenv("DISPLAY")) |
| 3473 | backend = "x11-backend.so"; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3474 | else |
Pekka Paalanen | a51e6fa | 2012-11-07 12:25:12 +0200 | [diff] [blame] | 3475 | backend = WESTON_NATIVE_BACKEND; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3476 | } |
| 3477 | |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 3478 | config_file = config_file_path("weston.ini"); |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3479 | parse_config_file(config_file, cs, ARRAY_LENGTH(cs), NULL); |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 3480 | |
Kristian Høgsberg | a4624f6 | 2012-09-11 14:08:26 -0400 | [diff] [blame] | 3481 | backend_init = load_module(backend, "backend_init"); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3482 | if (!backend_init) |
| 3483 | exit(EXIT_FAILURE); |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 3484 | |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 3485 | ec = backend_init(display, &argc, argv, config_file); |
Kristian Høgsberg | 841883b | 2008-12-05 11:19:56 -0500 | [diff] [blame] | 3486 | if (ec == NULL) { |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 3487 | weston_log("fatal: failed to create compositor\n"); |
Kristian Høgsberg | 841883b | 2008-12-05 11:19:56 -0500 | [diff] [blame] | 3488 | exit(EXIT_FAILURE); |
| 3489 | } |
Kristian Høgsberg | 61a8251 | 2010-10-26 11:26:44 -0400 | [diff] [blame] | 3490 | |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 3491 | segv_action.sa_flags = SA_SIGINFO | SA_RESETHAND; |
| 3492 | segv_action.sa_sigaction = on_segv_signal; |
| 3493 | sigemptyset(&segv_action.sa_mask); |
| 3494 | sigaction(SIGSEGV, &segv_action, NULL); |
| 3495 | segv_compositor = ec; |
| 3496 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3497 | ec->option_idle_time = idle_time; |
| 3498 | ec->idle_time = idle_time; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 3499 | |
Kristian Høgsberg | eb00e2e | 2012-09-11 14:29:47 -0400 | [diff] [blame] | 3500 | setenv("WAYLAND_DISPLAY", socket_name, 1); |
| 3501 | |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 3502 | if (load_modules(ec, modules, &argc, argv, config_file) < 0) |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 3503 | goto out; |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 3504 | if (load_modules(ec, option_modules, &argc, argv, config_file) < 0) |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 3505 | goto out; |
Tiago Vignatti | e4faa2a | 2012-04-16 17:31:44 +0300 | [diff] [blame] | 3506 | |
Kristian Høgsberg | 142d546 | 2013-02-21 21:10:36 -0500 | [diff] [blame] | 3507 | free(config_file); |
| 3508 | |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 3509 | for (i = 1; i < argc; i++) |
| 3510 | weston_log("fatal: unhandled option: %s\n", argv[i]); |
| 3511 | if (argc > 1) { |
| 3512 | ret = EXIT_FAILURE; |
| 3513 | goto out; |
| 3514 | } |
| 3515 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3516 | if (wl_display_add_socket(display, socket_name)) { |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 3517 | weston_log("fatal: failed to add socket: %m\n"); |
| 3518 | ret = EXIT_FAILURE; |
| 3519 | goto out; |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3520 | } |
| 3521 | |
Pekka Paalanen | c0444e3 | 2012-01-05 16:28:21 +0200 | [diff] [blame] | 3522 | weston_compositor_wake(ec); |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3523 | |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 3524 | wl_display_run(display); |
| 3525 | |
| 3526 | out: |
Pekka Paalanen | 0135abe | 2012-01-03 10:01:20 +0200 | [diff] [blame] | 3527 | /* prevent further rendering while shutting down */ |
Kristian Høgsberg | 3466bc8 | 2012-01-03 11:29:15 -0500 | [diff] [blame] | 3528 | ec->state = WESTON_COMPOSITOR_SLEEPING; |
Pekka Paalanen | 0135abe | 2012-01-03 10:01:20 +0200 | [diff] [blame] | 3529 | |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 3530 | wl_signal_emit(&ec->destroy_signal, ec); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 3531 | |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 3532 | for (i = ARRAY_LENGTH(signals); i;) |
| 3533 | wl_event_source_remove(signals[--i]); |
| 3534 | |
Daniel Stone | 855028f | 2012-05-01 20:37:10 +0100 | [diff] [blame] | 3535 | weston_compositor_xkb_destroy(ec); |
| 3536 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 3537 | ec->destroy(ec); |
Tiago Vignatti | 9e2be08 | 2011-12-19 00:04:46 +0200 | [diff] [blame] | 3538 | wl_display_destroy(display); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 3539 | |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 3540 | weston_log_file_close(); |
| 3541 | |
Pekka Paalanen | 3ab7269 | 2012-06-08 17:27:28 +0300 | [diff] [blame] | 3542 | return ret; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3543 | } |