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