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