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