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