Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 2 | * Copyright © 2008-2011 Kristian Høgsberg |
| 3 | * Copyright © 2010-2011 Intel Corporation |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 4 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 5 | * Permission to use, copy, modify, distribute, and sell this software and |
| 6 | * its documentation for any purpose is hereby granted without fee, provided |
| 7 | * that the above copyright notice appear in all copies and that both that |
| 8 | * copyright notice and this permission notice appear in supporting |
| 9 | * documentation, and that the name of the copyright holders not be used in |
| 10 | * advertising or publicity pertaining to distribution of the software |
| 11 | * without specific, written prior permission. The copyright holders make |
| 12 | * no representations about the suitability of this software for any |
| 13 | * purpose. It is provided "as is" without express or implied warranty. |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 14 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 15 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 16 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 18 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 19 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 20 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 21 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 22 | */ |
| 23 | |
Chia-I Wu | 1b6c0ed | 2010-10-29 15:20:18 +0800 | [diff] [blame] | 24 | #ifdef HAVE_CONFIG_H |
| 25 | #include <config.h> |
| 26 | #endif |
| 27 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 28 | #include <stddef.h> |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 29 | #include <stdlib.h> |
| 30 | #include <string.h> |
| 31 | #include <fcntl.h> |
| 32 | #include <unistd.h> |
| 33 | #include <errno.h> |
| 34 | #include <sys/time.h> |
Kristian Høgsberg | f9112b2 | 2010-06-14 12:53:43 -0400 | [diff] [blame] | 35 | #include <linux/input.h> |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 36 | |
| 37 | #include <xcb/xcb.h> |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 38 | #ifdef HAVE_XCB_XKB |
| 39 | #include <xcb/xkb.h> |
| 40 | #endif |
| 41 | |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame] | 42 | #include <X11/Xlib.h> |
| 43 | #include <X11/Xlib-xcb.h> |
| 44 | |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 45 | #include <xkbcommon/xkbcommon.h> |
| 46 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 47 | #include <GLES2/gl2.h> |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 48 | #include <EGL/egl.h> |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 49 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 50 | #include "compositor.h" |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 51 | #include "../shared/config-parser.h" |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 52 | |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 53 | static char *output_name; |
| 54 | static char *output_mode; |
| 55 | static int option_width; |
| 56 | static int option_height; |
| 57 | static int option_count; |
| 58 | static struct wl_list configured_output_list; |
| 59 | |
| 60 | struct x11_configured_output { |
| 61 | char *name; |
| 62 | int width, height; |
| 63 | struct wl_list link; |
| 64 | }; |
| 65 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 66 | struct x11_compositor { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 67 | struct weston_compositor base; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 68 | |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 69 | EGLSurface dummy_pbuffer; |
| 70 | |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame] | 71 | Display *dpy; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 72 | xcb_connection_t *conn; |
| 73 | xcb_screen_t *screen; |
| 74 | xcb_cursor_t null_cursor; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 75 | struct wl_array keys; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 76 | struct wl_event_source *xcb_source; |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 77 | struct xkb_keymap *xkb_keymap; |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 78 | unsigned int has_xkb; |
| 79 | uint8_t xkb_event_base; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 80 | struct { |
| 81 | xcb_atom_t wm_protocols; |
| 82 | xcb_atom_t wm_normal_hints; |
| 83 | xcb_atom_t wm_size_hints; |
| 84 | xcb_atom_t wm_delete_window; |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 85 | xcb_atom_t wm_class; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 86 | xcb_atom_t net_wm_name; |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 87 | xcb_atom_t net_wm_icon; |
Kristian Høgsberg | 83eeacb | 2011-06-18 04:20:54 -0400 | [diff] [blame] | 88 | xcb_atom_t net_wm_state; |
| 89 | xcb_atom_t net_wm_state_fullscreen; |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 90 | xcb_atom_t string; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 91 | xcb_atom_t utf8_string; |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 92 | xcb_atom_t cardinal; |
Daniel Stone | 855028f | 2012-05-01 20:37:10 +0100 | [diff] [blame] | 93 | xcb_atom_t xkb_names; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 94 | } atom; |
| 95 | }; |
| 96 | |
| 97 | struct x11_output { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 98 | struct weston_output base; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 99 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 100 | xcb_window_t window; |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 101 | EGLSurface egl_surface; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 102 | struct weston_mode mode; |
Kristian Høgsberg | 06a670f | 2011-10-29 14:39:13 -0400 | [diff] [blame] | 103 | struct wl_event_source *finish_frame_timer; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | struct x11_input { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 107 | struct weston_seat base; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 108 | }; |
| 109 | |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 110 | static struct xkb_keymap * |
| 111 | x11_compositor_get_keymap(struct x11_compositor *c) |
| 112 | { |
| 113 | xcb_get_property_cookie_t cookie; |
| 114 | xcb_get_property_reply_t *reply; |
| 115 | xcb_generic_error_t *error; |
| 116 | struct xkb_rule_names names; |
| 117 | struct xkb_keymap *ret; |
| 118 | const char *value_all, *value_part; |
| 119 | int length_all, length_part; |
| 120 | |
| 121 | memset(&names, 0, sizeof(names)); |
| 122 | |
| 123 | cookie = xcb_get_property(c->conn, 0, c->screen->root, |
| 124 | c->atom.xkb_names, c->atom.string, 0, 1024); |
| 125 | reply = xcb_get_property_reply(c->conn, cookie, &error); |
| 126 | if (reply == NULL) |
| 127 | return NULL; |
| 128 | |
| 129 | value_all = xcb_get_property_value(reply); |
| 130 | length_all = xcb_get_property_value_length(reply); |
| 131 | value_part = value_all; |
| 132 | |
| 133 | #define copy_prop_value(to) \ |
| 134 | length_part = strlen(value_part); \ |
| 135 | if (value_part + length_part < (value_all + length_all) && \ |
| 136 | length_part > 0) \ |
| 137 | names.to = value_part; \ |
| 138 | value_part += length_part + 1; |
| 139 | |
| 140 | copy_prop_value(rules); |
| 141 | copy_prop_value(model); |
| 142 | copy_prop_value(layout); |
| 143 | copy_prop_value(variant); |
| 144 | copy_prop_value(options); |
| 145 | #undef copy_prop_value |
| 146 | |
| 147 | ret = xkb_map_new_from_names(c->base.xkb_context, &names, 0); |
| 148 | |
| 149 | free(reply); |
| 150 | return ret; |
| 151 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 152 | |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 153 | static void |
| 154 | x11_compositor_setup_xkb(struct x11_compositor *c) |
| 155 | { |
| 156 | #ifndef HAVE_XCB_XKB |
| 157 | weston_log("XCB-XKB not available during build\n"); |
| 158 | c->has_xkb = 0; |
| 159 | c->xkb_event_base = 0; |
| 160 | return; |
| 161 | #else |
| 162 | const xcb_query_extension_reply_t *ext; |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 163 | xcb_generic_error_t *error; |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 164 | xcb_void_cookie_t select; |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 165 | xcb_xkb_per_client_flags_cookie_t pcf; |
| 166 | xcb_xkb_per_client_flags_reply_t *pcf_reply; |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 167 | |
| 168 | c->has_xkb = 0; |
| 169 | c->xkb_event_base = 0; |
| 170 | |
| 171 | ext = xcb_get_extension_data(c->conn, &xcb_xkb_id); |
| 172 | if (!ext) { |
| 173 | weston_log("XKB extension not available on host X11 server\n"); |
| 174 | return; |
| 175 | } |
| 176 | c->xkb_event_base = ext->first_event; |
| 177 | |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 178 | select = xcb_xkb_select_events(c->conn, |
| 179 | XCB_XKB_ID_USE_CORE_KBD, |
| 180 | XCB_XKB_EVENT_TYPE_STATE_NOTIFY, |
| 181 | 0, |
| 182 | XCB_XKB_EVENT_TYPE_STATE_NOTIFY, |
| 183 | 0, |
| 184 | 0, |
| 185 | NULL); |
| 186 | error = xcb_request_check(c->conn, select); |
| 187 | if (error) { |
| 188 | weston_log("error: failed to select for XKB state events\n"); |
| 189 | return; |
| 190 | } |
| 191 | |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 192 | pcf = xcb_xkb_per_client_flags(c->conn, |
| 193 | XCB_XKB_ID_USE_CORE_KBD, |
| 194 | XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT, |
| 195 | XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT, |
| 196 | 0, |
| 197 | 0, |
| 198 | 0); |
| 199 | pcf_reply = xcb_xkb_per_client_flags_reply(c->conn, pcf, &error); |
| 200 | free(pcf_reply); |
| 201 | if (error) { |
| 202 | weston_log("failed to set XKB per-client flags, not using " |
| 203 | "detectable repeat\n"); |
| 204 | return; |
| 205 | } |
| 206 | |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 207 | c->has_xkb = 1; |
| 208 | #endif |
| 209 | } |
| 210 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 211 | static int |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 212 | x11_input_create(struct x11_compositor *c, int no_input) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 213 | { |
| 214 | struct x11_input *input; |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 215 | struct xkb_keymap *keymap; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 216 | |
| 217 | input = malloc(sizeof *input); |
| 218 | if (input == NULL) |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 219 | return -1; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 220 | |
| 221 | memset(input, 0, sizeof *input); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 222 | weston_seat_init(&input->base, &c->base); |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 223 | c->base.seat = &input->base; |
| 224 | |
| 225 | if (no_input) |
| 226 | return 0; |
| 227 | |
Daniel Stone | 74419a2 | 2012-05-30 16:32:02 +0100 | [diff] [blame] | 228 | weston_seat_init_pointer(&input->base); |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 229 | |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 230 | x11_compositor_setup_xkb(c); |
| 231 | |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 232 | keymap = x11_compositor_get_keymap(c); |
| 233 | weston_seat_init_keyboard(&input->base, keymap); |
| 234 | if (keymap) |
| 235 | xkb_map_unref(keymap); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 236 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 237 | return 0; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 238 | } |
| 239 | |
Pekka Paalanen | 43c61d8 | 2012-01-03 11:58:34 +0200 | [diff] [blame] | 240 | static void |
| 241 | x11_input_destroy(struct x11_compositor *compositor) |
| 242 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 243 | struct x11_input *input = container_of(compositor->base.seat, |
Pekka Paalanen | 43c61d8 | 2012-01-03 11:58:34 +0200 | [diff] [blame] | 244 | struct x11_input, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 245 | base); |
Pekka Paalanen | 43c61d8 | 2012-01-03 11:58:34 +0200 | [diff] [blame] | 246 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 247 | weston_seat_release(&input->base); |
Pekka Paalanen | 43c61d8 | 2012-01-03 11:58:34 +0200 | [diff] [blame] | 248 | free(input); |
| 249 | } |
| 250 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 251 | static int |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 252 | x11_compositor_init_egl(struct x11_compositor *c) |
| 253 | { |
Kristian Høgsberg | 379b678 | 2010-07-28 22:52:28 -0400 | [diff] [blame] | 254 | EGLint major, minor; |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 255 | EGLint n; |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 256 | EGLint config_attribs[] = { |
| 257 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 258 | EGL_RED_SIZE, 1, |
| 259 | EGL_GREEN_SIZE, 1, |
| 260 | EGL_BLUE_SIZE, 1, |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 261 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 262 | EGL_NONE |
| 263 | }; |
Kristian Høgsberg | 2c28aa5 | 2010-07-28 23:47:54 -0400 | [diff] [blame] | 264 | static const EGLint context_attribs[] = { |
| 265 | EGL_CONTEXT_CLIENT_VERSION, 2, |
| 266 | EGL_NONE |
| 267 | }; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 268 | |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 269 | static const EGLint pbuffer_attribs[] = { |
| 270 | EGL_WIDTH, 10, |
| 271 | EGL_HEIGHT, 10, |
| 272 | EGL_NONE |
| 273 | }; |
| 274 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 275 | c->base.egl_display = eglGetDisplay(c->dpy); |
| 276 | if (c->base.egl_display == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 277 | weston_log("failed to create display\n"); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 278 | return -1; |
| 279 | } |
| 280 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 281 | if (!eglInitialize(c->base.egl_display, &major, &minor)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 282 | weston_log("failed to initialize display\n"); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 283 | return -1; |
| 284 | } |
| 285 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 286 | if (!eglBindAPI(EGL_OPENGL_ES_API)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 287 | weston_log("failed to bind EGL_OPENGL_ES_API\n"); |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 288 | return -1; |
| 289 | } |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 290 | if (!eglChooseConfig(c->base.egl_display, config_attribs, |
| 291 | &c->base.egl_config, 1, &n) || n == 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 292 | weston_log("failed to choose config: %d\n", n); |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 293 | return -1; |
| 294 | } |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 295 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 296 | c->base.egl_context = |
| 297 | eglCreateContext(c->base.egl_display, c->base.egl_config, |
| 298 | EGL_NO_CONTEXT, context_attribs); |
| 299 | if (c->base.egl_context == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 300 | weston_log("failed to create context\n"); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 301 | return -1; |
| 302 | } |
| 303 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 304 | c->dummy_pbuffer = eglCreatePbufferSurface(c->base.egl_display, |
| 305 | c->base.egl_config, |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 306 | pbuffer_attribs); |
Kristian Høgsberg | c0bc844 | 2012-05-17 09:40:23 -0400 | [diff] [blame] | 307 | if (c->dummy_pbuffer == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 308 | weston_log("failed to create dummy pbuffer\n"); |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 309 | return -1; |
| 310 | } |
| 311 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 312 | if (!eglMakeCurrent(c->base.egl_display, c->dummy_pbuffer, |
| 313 | c->dummy_pbuffer, c->base.egl_context)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 314 | weston_log("failed to make context current\n"); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 315 | return -1; |
| 316 | } |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
Pekka Paalanen | 43c61d8 | 2012-01-03 11:58:34 +0200 | [diff] [blame] | 321 | static void |
| 322 | x11_compositor_fini_egl(struct x11_compositor *compositor) |
| 323 | { |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 324 | eglMakeCurrent(compositor->base.egl_display, |
Pekka Paalanen | 43c61d8 | 2012-01-03 11:58:34 +0200 | [diff] [blame] | 325 | EGL_NO_SURFACE, EGL_NO_SURFACE, |
| 326 | EGL_NO_CONTEXT); |
| 327 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 328 | eglTerminate(compositor->base.egl_display); |
Pekka Paalanen | 43c61d8 | 2012-01-03 11:58:34 +0200 | [diff] [blame] | 329 | eglReleaseThread(); |
| 330 | } |
| 331 | |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 332 | static void |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 333 | x11_output_repaint(struct weston_output *output_base, |
| 334 | pixman_region32_t *damage) |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 335 | { |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 336 | struct x11_output *output = (struct x11_output *)output_base; |
| 337 | struct x11_compositor *compositor = |
| 338 | (struct x11_compositor *)output->base.compositor; |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 339 | struct weston_surface *surface; |
| 340 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 341 | if (!eglMakeCurrent(compositor->base.egl_display, output->egl_surface, |
| 342 | output->egl_surface, |
| 343 | compositor->base.egl_context)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 344 | weston_log("failed to make current\n"); |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 345 | return; |
| 346 | } |
| 347 | |
| 348 | wl_list_for_each_reverse(surface, &compositor->base.surface_list, link) |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 349 | weston_surface_draw(surface, &output->base, damage); |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 350 | |
Kristian Høgsberg | e0f832b | 2012-06-20 00:13:18 -0400 | [diff] [blame] | 351 | wl_signal_emit(&output->base.frame_signal, output); |
Scott Moreau | 062be7e | 2012-04-20 13:37:33 -0600 | [diff] [blame] | 352 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 353 | eglSwapBuffers(compositor->base.egl_display, output->egl_surface); |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 354 | |
| 355 | wl_event_source_timer_update(output->finish_frame_timer, 10); |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 356 | } |
| 357 | |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 358 | static int |
Kristian Høgsberg | 06a670f | 2011-10-29 14:39:13 -0400 | [diff] [blame] | 359 | finish_frame_handler(void *data) |
| 360 | { |
| 361 | struct x11_output *output = data; |
| 362 | uint32_t msec; |
| 363 | struct timeval tv; |
| 364 | |
| 365 | gettimeofday(&tv, NULL); |
| 366 | msec = tv.tv_sec * 1000 + tv.tv_usec / 1000; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 367 | weston_output_finish_frame(&output->base, msec); |
Kristian Høgsberg | 06a670f | 2011-10-29 14:39:13 -0400 | [diff] [blame] | 368 | |
| 369 | return 1; |
| 370 | } |
| 371 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 372 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 373 | x11_output_destroy(struct weston_output *output_base) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 374 | { |
Pekka Paalanen | 2de99e2 | 2012-01-03 11:51:03 +0200 | [diff] [blame] | 375 | struct x11_output *output = (struct x11_output *)output_base; |
| 376 | struct x11_compositor *compositor = |
| 377 | (struct x11_compositor *)output->base.compositor; |
| 378 | |
| 379 | wl_list_remove(&output->base.link); |
| 380 | wl_event_source_remove(output->finish_frame_timer); |
| 381 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 382 | eglDestroySurface(compositor->base.egl_display, output->egl_surface); |
Pekka Paalanen | 2de99e2 | 2012-01-03 11:51:03 +0200 | [diff] [blame] | 383 | |
| 384 | xcb_destroy_window(compositor->conn, output->window); |
| 385 | |
Kristian Høgsberg | 3466bc8 | 2012-01-03 11:29:15 -0500 | [diff] [blame] | 386 | weston_output_destroy(&output->base); |
Pekka Paalanen | 2de99e2 | 2012-01-03 11:51:03 +0200 | [diff] [blame] | 387 | |
| 388 | free(output); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 389 | } |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 390 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 391 | static void |
| 392 | x11_output_set_wm_protocols(struct x11_output *output) |
| 393 | { |
| 394 | xcb_atom_t list[1]; |
| 395 | struct x11_compositor *c = |
| 396 | (struct x11_compositor *) output->base.compositor; |
| 397 | |
| 398 | list[0] = c->atom.wm_delete_window; |
| 399 | xcb_change_property (c->conn, |
| 400 | XCB_PROP_MODE_REPLACE, |
| 401 | output->window, |
| 402 | c->atom.wm_protocols, |
| 403 | XCB_ATOM_ATOM, |
| 404 | 32, |
Kristian Høgsberg | 09e2692 | 2011-12-23 13:33:45 -0500 | [diff] [blame] | 405 | ARRAY_LENGTH(list), |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 406 | list); |
| 407 | } |
| 408 | |
Kristian Høgsberg | 83eeacb | 2011-06-18 04:20:54 -0400 | [diff] [blame] | 409 | static void |
| 410 | x11_output_change_state(struct x11_output *output, int add, xcb_atom_t state) |
| 411 | { |
| 412 | xcb_client_message_event_t event; |
| 413 | struct x11_compositor *c = |
| 414 | (struct x11_compositor *) output->base.compositor; |
| 415 | xcb_screen_iterator_t iter; |
| 416 | |
| 417 | #define _NET_WM_STATE_REMOVE 0 /* remove/unset property */ |
| 418 | #define _NET_WM_STATE_ADD 1 /* add/set property */ |
| 419 | #define _NET_WM_STATE_TOGGLE 2 /* toggle property */ |
| 420 | |
| 421 | memset(&event, 0, sizeof event); |
| 422 | event.response_type = XCB_CLIENT_MESSAGE; |
| 423 | event.format = 32; |
| 424 | event.window = output->window; |
| 425 | event.type = c->atom.net_wm_state; |
| 426 | |
| 427 | event.data.data32[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE; |
| 428 | event.data.data32[1] = state; |
| 429 | event.data.data32[2] = 0; |
| 430 | event.data.data32[3] = 0; |
| 431 | event.data.data32[4] = 0; |
| 432 | |
| 433 | iter = xcb_setup_roots_iterator(xcb_get_setup(c->conn)); |
| 434 | xcb_send_event(c->conn, 0, iter.data->root, |
| 435 | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | |
| 436 | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, |
| 437 | (void *) &event); |
| 438 | } |
| 439 | |
| 440 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 441 | struct wm_normal_hints { |
| 442 | uint32_t flags; |
| 443 | uint32_t pad[4]; |
| 444 | int32_t min_width, min_height; |
| 445 | int32_t max_width, max_height; |
| 446 | int32_t width_inc, height_inc; |
| 447 | int32_t min_aspect_x, min_aspect_y; |
| 448 | int32_t max_aspect_x, max_aspect_y; |
| 449 | int32_t base_width, base_height; |
| 450 | int32_t win_gravity; |
| 451 | }; |
| 452 | |
| 453 | #define WM_NORMAL_HINTS_MIN_SIZE 16 |
| 454 | #define WM_NORMAL_HINTS_MAX_SIZE 32 |
| 455 | |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 456 | static void |
Kristian Høgsberg | b41d76c | 2011-04-23 15:03:15 -0400 | [diff] [blame] | 457 | x11_output_set_icon(struct x11_compositor *c, |
| 458 | struct x11_output *output, const char *filename) |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 459 | { |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 460 | uint32_t *icon; |
Kristian Høgsberg | b41d76c | 2011-04-23 15:03:15 -0400 | [diff] [blame] | 461 | int32_t width, height; |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 462 | pixman_image_t *image; |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 463 | |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 464 | image = load_image(filename); |
| 465 | if (!image) |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 466 | return; |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 467 | width = pixman_image_get_width(image); |
| 468 | height = pixman_image_get_height(image); |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 469 | icon = malloc(width * height * 4 + 8); |
| 470 | if (!icon) { |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 471 | pixman_image_unref(image); |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 472 | return; |
| 473 | } |
| 474 | |
| 475 | icon[0] = width; |
| 476 | icon[1] = height; |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 477 | memcpy(icon + 2, pixman_image_get_data(image), width * height * 4); |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 478 | xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 479 | c->atom.net_wm_icon, c->atom.cardinal, 32, |
| 480 | width * height + 2, icon); |
| 481 | free(icon); |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 482 | pixman_image_unref(image); |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 483 | } |
| 484 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 485 | static int |
Kristian Høgsberg | 1ccd9d2 | 2011-07-21 10:22:13 -0700 | [diff] [blame] | 486 | x11_compositor_create_output(struct x11_compositor *c, int x, int y, |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 487 | int width, int height, int fullscreen, |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 488 | int no_input, const char *name) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 489 | { |
Kristian Høgsberg | 8600040 | 2012-01-03 23:24:14 -0500 | [diff] [blame] | 490 | static const char class[] = "weston-1\0Weston Compositor"; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 491 | struct x11_output *output; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 492 | xcb_screen_iterator_t iter; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 493 | struct wm_normal_hints normal_hints; |
Kristian Høgsberg | 06a670f | 2011-10-29 14:39:13 -0400 | [diff] [blame] | 494 | struct wl_event_loop *loop; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 495 | uint32_t mask = XCB_CW_EVENT_MASK | XCB_CW_CURSOR; |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 496 | uint32_t values[2] = { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 497 | XCB_EVENT_MASK_EXPOSURE | |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 498 | XCB_EVENT_MASK_STRUCTURE_NOTIFY, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 499 | 0 |
| 500 | }; |
| 501 | |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 502 | if (!no_input) |
| 503 | values[0] |= |
| 504 | XCB_EVENT_MASK_KEY_PRESS | |
| 505 | XCB_EVENT_MASK_KEY_RELEASE | |
| 506 | XCB_EVENT_MASK_BUTTON_PRESS | |
| 507 | XCB_EVENT_MASK_BUTTON_RELEASE | |
| 508 | XCB_EVENT_MASK_POINTER_MOTION | |
| 509 | XCB_EVENT_MASK_ENTER_WINDOW | |
| 510 | XCB_EVENT_MASK_LEAVE_WINDOW | |
| 511 | XCB_EVENT_MASK_KEYMAP_STATE | |
| 512 | XCB_EVENT_MASK_FOCUS_CHANGE; |
| 513 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 514 | output = malloc(sizeof *output); |
| 515 | if (output == NULL) |
| 516 | return -1; |
| 517 | |
| 518 | memset(output, 0, sizeof *output); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 519 | |
| 520 | output->mode.flags = |
| 521 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 522 | output->mode.width = width; |
| 523 | output->mode.height = height; |
Kristian Høgsberg | c4621b0 | 2012-05-10 12:23:53 -0400 | [diff] [blame] | 524 | output->mode.refresh = 60000; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 525 | wl_list_init(&output->base.mode_list); |
| 526 | wl_list_insert(&output->base.mode_list, &output->mode.link); |
| 527 | |
| 528 | output->base.current = &output->mode; |
Kristian Høgsberg | 1248158 | 2012-07-02 21:24:57 -0400 | [diff] [blame] | 529 | output->base.make = "xwayland"; |
| 530 | output->base.model = "none"; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 531 | weston_output_init(&output->base, &c->base, x, y, width, height, |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 532 | WL_OUTPUT_FLIPPED); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 533 | |
| 534 | values[1] = c->null_cursor; |
| 535 | output->window = xcb_generate_id(c->conn); |
| 536 | iter = xcb_setup_roots_iterator(xcb_get_setup(c->conn)); |
| 537 | xcb_create_window(c->conn, |
| 538 | XCB_COPY_FROM_PARENT, |
| 539 | output->window, |
| 540 | iter.data->root, |
| 541 | 0, 0, |
| 542 | width, height, |
| 543 | 0, |
| 544 | XCB_WINDOW_CLASS_INPUT_OUTPUT, |
| 545 | iter.data->root_visual, |
| 546 | mask, values); |
| 547 | |
| 548 | /* Don't resize me. */ |
| 549 | memset(&normal_hints, 0, sizeof normal_hints); |
| 550 | normal_hints.flags = |
| 551 | WM_NORMAL_HINTS_MAX_SIZE | WM_NORMAL_HINTS_MIN_SIZE; |
| 552 | normal_hints.min_width = width; |
| 553 | normal_hints.min_height = height; |
| 554 | normal_hints.max_width = width; |
| 555 | normal_hints.max_height = height; |
| 556 | xcb_change_property (c->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 557 | c->atom.wm_normal_hints, |
| 558 | c->atom.wm_size_hints, 32, |
| 559 | sizeof normal_hints / 4, |
| 560 | (uint8_t *) &normal_hints); |
| 561 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 562 | /* Set window name. Don't bother with non-EWMH WMs. */ |
| 563 | xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 564 | c->atom.net_wm_name, c->atom.utf8_string, 8, |
| 565 | strlen(name), name); |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 566 | xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 567 | c->atom.wm_class, c->atom.string, 8, |
| 568 | sizeof class, class); |
| 569 | |
Kristian Høgsberg | 8600040 | 2012-01-03 23:24:14 -0500 | [diff] [blame] | 570 | x11_output_set_icon(c, output, DATADIR "/weston/wayland.png"); |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 571 | |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 572 | xcb_map_window(c->conn, output->window); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 573 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 574 | x11_output_set_wm_protocols(output); |
| 575 | |
Kristian Høgsberg | 83eeacb | 2011-06-18 04:20:54 -0400 | [diff] [blame] | 576 | if (fullscreen) |
| 577 | x11_output_change_state(output, 1, |
| 578 | c->atom.net_wm_state_fullscreen); |
| 579 | |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 580 | output->egl_surface = |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 581 | eglCreateWindowSurface(c->base.egl_display, c->base.egl_config, |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 582 | output->window, NULL); |
| 583 | if (!output->egl_surface) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 584 | weston_log("failed to create window surface\n"); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 585 | return -1; |
| 586 | } |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 587 | if (!eglMakeCurrent(c->base.egl_display, output->egl_surface, |
| 588 | output->egl_surface, c->base.egl_context)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 589 | weston_log("failed to make surface current\n"); |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 590 | return -1; |
| 591 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 592 | |
Kristian Høgsberg | 06a670f | 2011-10-29 14:39:13 -0400 | [diff] [blame] | 593 | loop = wl_display_get_event_loop(c->base.wl_display); |
| 594 | output->finish_frame_timer = |
| 595 | wl_event_loop_add_timer(loop, finish_frame_handler, output); |
| 596 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 597 | output->base.origin = output->base.current; |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 598 | output->base.repaint = x11_output_repaint; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 599 | output->base.destroy = x11_output_destroy; |
Jesse Barnes | 5308a5e | 2012-02-09 13:12:57 -0800 | [diff] [blame] | 600 | output->base.assign_planes = NULL; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 601 | output->base.set_backlight = NULL; |
| 602 | output->base.set_dpms = NULL; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 603 | output->base.switch_mode = NULL; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 604 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 605 | wl_list_insert(c->base.output_list.prev, &output->base.link); |
| 606 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 607 | weston_log("x11 output %dx%d, window id %d\n", |
| 608 | width, height, output->window); |
| 609 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 610 | return 0; |
| 611 | } |
| 612 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 613 | static struct x11_output * |
| 614 | x11_compositor_find_output(struct x11_compositor *c, xcb_window_t window) |
| 615 | { |
| 616 | struct x11_output *output; |
| 617 | |
| 618 | wl_list_for_each(output, &c->base.output_list, base.link) { |
| 619 | if (output->window == window) |
| 620 | return output; |
| 621 | } |
| 622 | |
| 623 | return NULL; |
| 624 | } |
| 625 | |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 626 | static uint32_t |
| 627 | get_xkb_mod_mask(struct x11_compositor *c, uint32_t in) |
| 628 | { |
| 629 | struct weston_xkb_info *info = &c->base.seat->xkb_info; |
| 630 | uint32_t ret = 0; |
| 631 | |
| 632 | if ((in & ShiftMask) && info->shift_mod != XKB_MOD_INVALID) |
| 633 | ret |= (1 << info->shift_mod); |
| 634 | if ((in & LockMask) && info->caps_mod != XKB_MOD_INVALID) |
| 635 | ret |= (1 << info->caps_mod); |
| 636 | if ((in & ControlMask) && info->ctrl_mod != XKB_MOD_INVALID) |
| 637 | ret |= (1 << info->ctrl_mod); |
| 638 | if ((in & Mod1Mask) && info->alt_mod != XKB_MOD_INVALID) |
| 639 | ret |= (1 << info->alt_mod); |
| 640 | if ((in & Mod2Mask) && info->mod2_mod != XKB_MOD_INVALID) |
| 641 | ret |= (1 << info->mod2_mod); |
| 642 | if ((in & Mod3Mask) && info->mod3_mod != XKB_MOD_INVALID) |
| 643 | ret |= (1 << info->mod3_mod); |
| 644 | if ((in & Mod4Mask) && info->super_mod != XKB_MOD_INVALID) |
| 645 | ret |= (1 << info->super_mod); |
| 646 | if ((in & Mod5Mask) && info->mod5_mod != XKB_MOD_INVALID) |
| 647 | ret |= (1 << info->mod5_mod); |
| 648 | |
| 649 | return ret; |
| 650 | } |
| 651 | |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 652 | #ifdef HAVE_XCB_XKB |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 653 | static void |
| 654 | update_xkb_state(struct x11_compositor *c, xcb_xkb_state_notify_event_t *state) |
| 655 | { |
| 656 | struct weston_compositor *ec = &c->base; |
| 657 | struct wl_seat *seat = &ec->seat->seat; |
| 658 | |
| 659 | xkb_state_update_mask(c->base.seat->xkb_state.state, |
| 660 | get_xkb_mod_mask(c, state->baseMods), |
| 661 | get_xkb_mod_mask(c, state->latchedMods), |
| 662 | get_xkb_mod_mask(c, state->lockedMods), |
| 663 | 0, |
| 664 | 0, |
| 665 | state->group); |
| 666 | |
| 667 | notify_modifiers(seat, wl_display_next_serial(c->base.wl_display)); |
| 668 | } |
| 669 | #endif |
| 670 | |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 671 | /** |
| 672 | * This is monumentally unpleasant. If we don't have XCB-XKB bindings, |
| 673 | * the best we can do (given that XCB also lacks XI2 support), is to take |
| 674 | * the state from the core key events. Unfortunately that only gives us |
| 675 | * the effective (i.e. union of depressed/latched/locked) state, and we |
| 676 | * need the granularity. |
| 677 | * |
| 678 | * So we still update the state with every key event we see, but also use |
| 679 | * the state field from X11 events as a mask so we don't get any stuck |
| 680 | * modifiers. |
| 681 | */ |
| 682 | static void |
| 683 | update_xkb_state_from_core(struct x11_compositor *c, uint16_t x11_mask) |
| 684 | { |
| 685 | uint32_t mask = get_xkb_mod_mask(c, x11_mask); |
| 686 | struct wl_keyboard *keyboard = &c->base.seat->keyboard; |
| 687 | |
| 688 | xkb_state_update_mask(c->base.seat->xkb_state.state, |
| 689 | keyboard->modifiers.mods_depressed & mask, |
| 690 | keyboard->modifiers.mods_latched & mask, |
| 691 | keyboard->modifiers.mods_locked & mask, |
| 692 | 0, |
| 693 | 0, |
| 694 | (x11_mask >> 13) & 3); |
| 695 | notify_modifiers(&c->base.seat->seat, |
| 696 | wl_display_next_serial(c->base.wl_display)); |
| 697 | } |
| 698 | |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 699 | static void |
| 700 | x11_compositor_deliver_button_event(struct x11_compositor *c, |
| 701 | xcb_generic_event_t *event, int state) |
| 702 | { |
| 703 | xcb_button_press_event_t *button_event = |
| 704 | (xcb_button_press_event_t *) event; |
Daniel Stone | 5d66371 | 2012-05-04 11:21:55 +0100 | [diff] [blame] | 705 | uint32_t button; |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 706 | |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 707 | if (!c->has_xkb) |
| 708 | update_xkb_state_from_core(c, button_event->state); |
| 709 | |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 710 | switch (button_event->detail) { |
| 711 | default: |
| 712 | button = button_event->detail + BTN_LEFT - 1; |
| 713 | break; |
| 714 | case 2: |
| 715 | button = BTN_MIDDLE; |
| 716 | break; |
| 717 | case 3: |
| 718 | button = BTN_RIGHT; |
| 719 | break; |
| 720 | case 4: |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 721 | if (state) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 722 | notify_axis(&c->base.seat->seat, |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 723 | weston_compositor_get_time(), |
Daniel Stone | 878f0b7 | 2012-05-30 16:31:57 +0100 | [diff] [blame] | 724 | WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 725 | wl_fixed_from_int(1)); |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 726 | return; |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 727 | case 5: |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 728 | if (state) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 729 | notify_axis(&c->base.seat->seat, |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 730 | weston_compositor_get_time(), |
Daniel Stone | 878f0b7 | 2012-05-30 16:31:57 +0100 | [diff] [blame] | 731 | WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 732 | wl_fixed_from_int(-1)); |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 733 | return; |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 734 | case 6: |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 735 | if (state) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 736 | notify_axis(&c->base.seat->seat, |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 737 | weston_compositor_get_time(), |
Daniel Stone | 878f0b7 | 2012-05-30 16:31:57 +0100 | [diff] [blame] | 738 | WL_POINTER_AXIS_HORIZONTAL_SCROLL, |
| 739 | wl_fixed_from_int(1)); |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 740 | return; |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 741 | case 7: |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 742 | if (state) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 743 | notify_axis(&c->base.seat->seat, |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 744 | weston_compositor_get_time(), |
Daniel Stone | 878f0b7 | 2012-05-30 16:31:57 +0100 | [diff] [blame] | 745 | WL_POINTER_AXIS_HORIZONTAL_SCROLL, |
| 746 | wl_fixed_from_int(-1)); |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 747 | return; |
| 748 | } |
| 749 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 750 | notify_button(&c->base.seat->seat, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 751 | weston_compositor_get_time(), button, |
| 752 | state ? WL_POINTER_BUTTON_STATE_PRESSED : |
| 753 | WL_POINTER_BUTTON_STATE_RELEASED); |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 754 | } |
| 755 | |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 756 | static int |
| 757 | x11_compositor_next_event(struct x11_compositor *c, |
Kristian Høgsberg | 127d0f0 | 2011-04-22 12:18:13 -0400 | [diff] [blame] | 758 | xcb_generic_event_t **event, uint32_t mask) |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 759 | { |
Kristian Høgsberg | 127d0f0 | 2011-04-22 12:18:13 -0400 | [diff] [blame] | 760 | if (mask & WL_EVENT_READABLE) { |
| 761 | *event = xcb_poll_for_event(c->conn); |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 762 | } else { |
Kristian Høgsberg | 82ed042 | 2011-04-25 15:41:59 -0400 | [diff] [blame] | 763 | #ifdef HAVE_XCB_POLL_FOR_QUEUED_EVENT |
Kristian Høgsberg | 127d0f0 | 2011-04-22 12:18:13 -0400 | [diff] [blame] | 764 | *event = xcb_poll_for_queued_event(c->conn); |
Kristian Høgsberg | 82ed042 | 2011-04-25 15:41:59 -0400 | [diff] [blame] | 765 | #else |
| 766 | *event = xcb_poll_for_event(c->conn); |
| 767 | #endif |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | return *event != NULL; |
| 771 | } |
| 772 | |
Kristian Høgsberg | 127d0f0 | 2011-04-22 12:18:13 -0400 | [diff] [blame] | 773 | static int |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 774 | x11_compositor_handle_event(int fd, uint32_t mask, void *data) |
| 775 | { |
| 776 | struct x11_compositor *c = data; |
| 777 | struct x11_output *output; |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 778 | xcb_generic_event_t *event, *prev; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 779 | xcb_client_message_event_t *client_message; |
| 780 | xcb_motion_notify_event_t *motion_notify; |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 781 | xcb_enter_notify_event_t *enter_notify; |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 782 | xcb_key_press_event_t *key_press, *key_release; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 783 | xcb_keymap_notify_event_t *keymap_notify; |
| 784 | xcb_focus_in_event_t *focus_in; |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 785 | xcb_expose_event_t *expose; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 786 | xcb_atom_t atom; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 787 | uint32_t *k; |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 788 | uint32_t i, set; |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 789 | wl_fixed_t x, y; |
Bill Spitzak | b715cec | 2012-06-05 17:08:23 -0400 | [diff] [blame] | 790 | int count; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 791 | |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 792 | prev = NULL; |
Bill Spitzak | b715cec | 2012-06-05 17:08:23 -0400 | [diff] [blame] | 793 | count = 0; |
Kristian Høgsberg | 127d0f0 | 2011-04-22 12:18:13 -0400 | [diff] [blame] | 794 | while (x11_compositor_next_event(c, &event, mask)) { |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 795 | switch (prev ? prev->response_type & ~0x80 : 0x80) { |
| 796 | case XCB_KEY_RELEASE: |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 797 | /* Suppress key repeat events; this is only used if we |
| 798 | * don't have XCB XKB support. */ |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 799 | key_release = (xcb_key_press_event_t *) prev; |
| 800 | key_press = (xcb_key_press_event_t *) event; |
| 801 | if ((event->response_type & ~0x80) == XCB_KEY_PRESS && |
Dima Ryazanov | c224748 | 2011-08-16 17:25:32 -0700 | [diff] [blame] | 802 | key_release->time == key_press->time && |
| 803 | key_release->detail == key_press->detail) { |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 804 | /* Don't deliver the held key release |
| 805 | * event or the new key press event. */ |
| 806 | free(event); |
| 807 | free(prev); |
| 808 | prev = NULL; |
| 809 | continue; |
| 810 | } else { |
| 811 | /* Deliver the held key release now |
| 812 | * and fall through and handle the new |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 813 | * event below. */ |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 814 | update_xkb_state_from_core(c, key_release->state); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 815 | notify_key(&c->base.seat->seat, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 816 | weston_compositor_get_time(), |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 817 | key_release->detail - 8, |
Daniel Stone | 1b4e11f | 2012-06-22 13:21:37 +0100 | [diff] [blame] | 818 | WL_KEYBOARD_KEY_STATE_RELEASED, |
| 819 | STATE_UPDATE_AUTOMATIC); |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 820 | free(prev); |
| 821 | prev = NULL; |
| 822 | break; |
| 823 | } |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 824 | |
| 825 | case XCB_FOCUS_IN: |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 826 | /* assert event is keymap_notify */ |
| 827 | focus_in = (xcb_focus_in_event_t *) prev; |
| 828 | keymap_notify = (xcb_keymap_notify_event_t *) event; |
| 829 | c->keys.size = 0; |
| 830 | for (i = 0; i < ARRAY_LENGTH(keymap_notify->keys) * 8; i++) { |
| 831 | set = keymap_notify->keys[i >> 3] & |
| 832 | (1 << (i & 7)); |
| 833 | if (set) { |
| 834 | k = wl_array_add(&c->keys, sizeof *k); |
| 835 | *k = i; |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | output = x11_compositor_find_output(c, focus_in->event); |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 840 | /* Unfortunately the state only comes with the enter |
| 841 | * event, rather than with the focus event. I'm not |
| 842 | * sure of the exact semantics around it and whether |
| 843 | * we can ensure that we get both? */ |
| 844 | notify_keyboard_focus_in(&c->base.seat->seat, &c->keys, |
| 845 | STATE_UPDATE_AUTOMATIC); |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 846 | |
| 847 | free(prev); |
| 848 | prev = NULL; |
| 849 | break; |
| 850 | |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 851 | default: |
| 852 | /* No previous event held */ |
| 853 | break; |
Kristian Høgsberg | 3ddd148 | 2011-04-15 15:48:07 -0400 | [diff] [blame] | 854 | } |
| 855 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 856 | switch (event->response_type & ~0x80) { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 857 | case XCB_KEY_PRESS: |
| 858 | key_press = (xcb_key_press_event_t *) event; |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 859 | if (!c->has_xkb) |
| 860 | update_xkb_state_from_core(c, key_press->state); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 861 | notify_key(&c->base.seat->seat, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 862 | weston_compositor_get_time(), |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 863 | key_press->detail - 8, |
Daniel Stone | 1b4e11f | 2012-06-22 13:21:37 +0100 | [diff] [blame] | 864 | WL_KEYBOARD_KEY_STATE_PRESSED, |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 865 | c->has_xkb ? STATE_UPDATE_NONE : |
| 866 | STATE_UPDATE_AUTOMATIC); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 867 | break; |
| 868 | case XCB_KEY_RELEASE: |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 869 | /* If we don't have XKB, we need to use the lame |
| 870 | * autorepeat detection above. */ |
| 871 | if (!c->has_xkb) { |
| 872 | prev = event; |
| 873 | break; |
| 874 | } |
| 875 | key_release = (xcb_key_press_event_t *) event; |
| 876 | notify_key(&c->base.seat->seat, |
| 877 | weston_compositor_get_time(), |
| 878 | key_release->detail - 8, |
Daniel Stone | 1b4e11f | 2012-06-22 13:21:37 +0100 | [diff] [blame] | 879 | WL_KEYBOARD_KEY_STATE_RELEASED, |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 880 | STATE_UPDATE_NONE); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 881 | break; |
| 882 | case XCB_BUTTON_PRESS: |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 883 | x11_compositor_deliver_button_event(c, event, 1); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 884 | break; |
| 885 | case XCB_BUTTON_RELEASE: |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 886 | x11_compositor_deliver_button_event(c, event, 0); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 887 | break; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 888 | case XCB_MOTION_NOTIFY: |
| 889 | motion_notify = (xcb_motion_notify_event_t *) event; |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 890 | if (!c->has_xkb) |
| 891 | update_xkb_state_from_core(c, motion_notify->state); |
Kristian Høgsberg | 1ccd9d2 | 2011-07-21 10:22:13 -0700 | [diff] [blame] | 892 | output = x11_compositor_find_output(c, motion_notify->event); |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 893 | x = wl_fixed_from_int(output->base.x + motion_notify->event_x); |
| 894 | y = wl_fixed_from_int(output->base.y + motion_notify->event_y); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 895 | notify_motion(&c->base.seat->seat, |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 896 | weston_compositor_get_time(), x, y); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 897 | break; |
| 898 | |
| 899 | case XCB_EXPOSE: |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 900 | expose = (xcb_expose_event_t *) event; |
| 901 | output = x11_compositor_find_output(c, expose->window); |
| 902 | weston_output_schedule_repaint(&output->base); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 903 | break; |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 904 | |
| 905 | case XCB_ENTER_NOTIFY: |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 906 | enter_notify = (xcb_enter_notify_event_t *) event; |
Kristian Høgsberg | 2dfe626 | 2011-02-08 11:59:53 -0500 | [diff] [blame] | 907 | if (enter_notify->state >= Button1Mask) |
| 908 | break; |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 909 | if (!c->has_xkb) |
| 910 | update_xkb_state_from_core(c, enter_notify->state); |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 911 | output = x11_compositor_find_output(c, enter_notify->event); |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 912 | x = wl_fixed_from_int(output->base.x + enter_notify->event_x); |
| 913 | y = wl_fixed_from_int(output->base.y + enter_notify->event_y); |
| 914 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 915 | notify_pointer_focus(&c->base.seat->seat, |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 916 | &output->base, x, y); |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 917 | break; |
| 918 | |
| 919 | case XCB_LEAVE_NOTIFY: |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 920 | enter_notify = (xcb_enter_notify_event_t *) event; |
Kristian Høgsberg | 2dfe626 | 2011-02-08 11:59:53 -0500 | [diff] [blame] | 921 | if (enter_notify->state >= Button1Mask) |
| 922 | break; |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 923 | if (!c->has_xkb) |
| 924 | update_xkb_state_from_core(c, enter_notify->state); |
Kristian Høgsberg | 1ccd9d2 | 2011-07-21 10:22:13 -0700 | [diff] [blame] | 925 | output = x11_compositor_find_output(c, enter_notify->event); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 926 | notify_pointer_focus(&c->base.seat->seat, NULL, 0, 0); |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 927 | break; |
| 928 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 929 | case XCB_CLIENT_MESSAGE: |
| 930 | client_message = (xcb_client_message_event_t *) event; |
| 931 | atom = client_message->data.data32[0]; |
| 932 | if (atom == c->atom.wm_delete_window) |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 933 | wl_display_terminate(c->base.wl_display); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 934 | break; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 935 | |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 936 | case XCB_FOCUS_IN: |
| 937 | focus_in = (xcb_focus_in_event_t *) event; |
| 938 | if (focus_in->mode == XCB_NOTIFY_MODE_WHILE_GRABBED) |
| 939 | break; |
| 940 | |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 941 | prev = event; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 942 | break; |
| 943 | |
| 944 | case XCB_FOCUS_OUT: |
| 945 | focus_in = (xcb_focus_in_event_t *) event; |
Kristian Høgsberg | 42e40ae | 2011-12-19 14:36:50 -0500 | [diff] [blame] | 946 | if (focus_in->mode == XCB_NOTIFY_MODE_WHILE_GRABBED || |
| 947 | focus_in->mode == XCB_NOTIFY_MODE_UNGRAB) |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 948 | break; |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 949 | notify_keyboard_focus_out(&c->base.seat->seat); |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 950 | break; |
| 951 | |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 952 | default: |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 953 | break; |
| 954 | } |
| 955 | |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 956 | #ifdef HAVE_XCB_XKB |
| 957 | if (c->has_xkb && |
| 958 | (event->response_type & ~0x80) == c->xkb_event_base) { |
| 959 | xcb_xkb_state_notify_event_t *state = |
| 960 | (xcb_xkb_state_notify_event_t *) event; |
| 961 | if (state->xkbType == XCB_XKB_STATE_NOTIFY) |
| 962 | update_xkb_state(c, state); |
| 963 | } |
| 964 | #endif |
| 965 | |
Bill Spitzak | b715cec | 2012-06-05 17:08:23 -0400 | [diff] [blame] | 966 | count++; |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 967 | if (prev != event) |
Kristian Høgsberg | 3ddd148 | 2011-04-15 15:48:07 -0400 | [diff] [blame] | 968 | free (event); |
| 969 | } |
| 970 | |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 971 | switch (prev ? prev->response_type & ~0x80 : 0x80) { |
| 972 | case XCB_KEY_RELEASE: |
| 973 | key_release = (xcb_key_press_event_t *) prev; |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 974 | update_xkb_state_from_core(c, key_release->state); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 975 | notify_key(&c->base.seat->seat, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 976 | weston_compositor_get_time(), |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 977 | key_release->detail - 8, |
Daniel Stone | 1b4e11f | 2012-06-22 13:21:37 +0100 | [diff] [blame] | 978 | WL_KEYBOARD_KEY_STATE_RELEASED, |
| 979 | STATE_UPDATE_AUTOMATIC); |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 980 | free(prev); |
| 981 | prev = NULL; |
| 982 | break; |
| 983 | default: |
| 984 | break; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 985 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 986 | |
Bill Spitzak | b715cec | 2012-06-05 17:08:23 -0400 | [diff] [blame] | 987 | return count; |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 988 | } |
| 989 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 990 | #define F(field) offsetof(struct x11_compositor, field) |
| 991 | |
| 992 | static void |
| 993 | x11_compositor_get_resources(struct x11_compositor *c) |
| 994 | { |
| 995 | static const struct { const char *name; int offset; } atoms[] = { |
| 996 | { "WM_PROTOCOLS", F(atom.wm_protocols) }, |
| 997 | { "WM_NORMAL_HINTS", F(atom.wm_normal_hints) }, |
| 998 | { "WM_SIZE_HINTS", F(atom.wm_size_hints) }, |
| 999 | { "WM_DELETE_WINDOW", F(atom.wm_delete_window) }, |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 1000 | { "WM_CLASS", F(atom.wm_class) }, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1001 | { "_NET_WM_NAME", F(atom.net_wm_name) }, |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 1002 | { "_NET_WM_ICON", F(atom.net_wm_icon) }, |
Kristian Høgsberg | 83eeacb | 2011-06-18 04:20:54 -0400 | [diff] [blame] | 1003 | { "_NET_WM_STATE", F(atom.net_wm_state) }, |
| 1004 | { "_NET_WM_STATE_FULLSCREEN", F(atom.net_wm_state_fullscreen) }, |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 1005 | { "STRING", F(atom.string) }, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1006 | { "UTF8_STRING", F(atom.utf8_string) }, |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 1007 | { "CARDINAL", F(atom.cardinal) }, |
Daniel Stone | 855028f | 2012-05-01 20:37:10 +0100 | [diff] [blame] | 1008 | { "_XKB_RULES_NAMES", F(atom.xkb_names) }, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1009 | }; |
| 1010 | |
Kristian Høgsberg | 09e2692 | 2011-12-23 13:33:45 -0500 | [diff] [blame] | 1011 | xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)]; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1012 | xcb_intern_atom_reply_t *reply; |
| 1013 | xcb_pixmap_t pixmap; |
| 1014 | xcb_gc_t gc; |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1015 | unsigned int i; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1016 | uint8_t data[] = { 0, 0, 0, 0 }; |
| 1017 | |
Kristian Høgsberg | 09e2692 | 2011-12-23 13:33:45 -0500 | [diff] [blame] | 1018 | for (i = 0; i < ARRAY_LENGTH(atoms); i++) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1019 | cookies[i] = xcb_intern_atom (c->conn, 0, |
| 1020 | strlen(atoms[i].name), |
| 1021 | atoms[i].name); |
| 1022 | |
Kristian Høgsberg | 09e2692 | 2011-12-23 13:33:45 -0500 | [diff] [blame] | 1023 | for (i = 0; i < ARRAY_LENGTH(atoms); i++) { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1024 | reply = xcb_intern_atom_reply (c->conn, cookies[i], NULL); |
| 1025 | *(xcb_atom_t *) ((char *) c + atoms[i].offset) = reply->atom; |
| 1026 | free(reply); |
| 1027 | } |
| 1028 | |
| 1029 | pixmap = xcb_generate_id(c->conn); |
| 1030 | gc = xcb_generate_id(c->conn); |
| 1031 | xcb_create_pixmap(c->conn, 1, pixmap, c->screen->root, 1, 1); |
| 1032 | xcb_create_gc(c->conn, gc, pixmap, 0, NULL); |
| 1033 | xcb_put_image(c->conn, XCB_IMAGE_FORMAT_XY_PIXMAP, |
| 1034 | pixmap, gc, 1, 1, 0, 0, 0, 32, sizeof data, data); |
| 1035 | c->null_cursor = xcb_generate_id(c->conn); |
| 1036 | xcb_create_cursor (c->conn, c->null_cursor, |
| 1037 | pixmap, pixmap, 0, 0, 0, 0, 0, 0, 1, 1); |
| 1038 | xcb_free_gc(c->conn, gc); |
| 1039 | xcb_free_pixmap(c->conn, pixmap); |
| 1040 | } |
| 1041 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1042 | static void |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 1043 | x11_restore(struct weston_compositor *ec) |
| 1044 | { |
| 1045 | } |
| 1046 | |
| 1047 | static void |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 1048 | x11_free_configured_output(struct x11_configured_output *output) |
| 1049 | { |
| 1050 | free(output->name); |
| 1051 | free(output); |
| 1052 | } |
| 1053 | |
| 1054 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1055 | x11_destroy(struct weston_compositor *ec) |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1056 | { |
Pekka Paalanen | 43c61d8 | 2012-01-03 11:58:34 +0200 | [diff] [blame] | 1057 | struct x11_compositor *compositor = (struct x11_compositor *)ec; |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 1058 | struct x11_configured_output *o, *n; |
| 1059 | |
| 1060 | wl_list_for_each_safe(o, n, &configured_output_list, link) |
| 1061 | x11_free_configured_output(o); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1062 | |
Pekka Paalanen | 43c61d8 | 2012-01-03 11:58:34 +0200 | [diff] [blame] | 1063 | wl_event_source_remove(compositor->xcb_source); |
| 1064 | x11_input_destroy(compositor); |
| 1065 | |
Kristian Høgsberg | 3466bc8 | 2012-01-03 11:29:15 -0500 | [diff] [blame] | 1066 | weston_compositor_shutdown(ec); /* destroys outputs, too */ |
Pekka Paalanen | 43c61d8 | 2012-01-03 11:58:34 +0200 | [diff] [blame] | 1067 | |
| 1068 | x11_compositor_fini_egl(compositor); |
| 1069 | |
| 1070 | XCloseDisplay(compositor->dpy); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1071 | free(ec); |
| 1072 | } |
| 1073 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1074 | static struct weston_compositor * |
Kristian Høgsberg | 83eeacb | 2011-06-18 04:20:54 -0400 | [diff] [blame] | 1075 | x11_compositor_create(struct wl_display *display, |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 1076 | int fullscreen, |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 1077 | int no_input, |
Daniel Stone | c1be8e5 | 2012-06-01 11:14:02 -0400 | [diff] [blame] | 1078 | int argc, char *argv[], const char *config_file) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1079 | { |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 1080 | static const char name[] = "Weston Compositor"; |
| 1081 | char configured_name[32]; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1082 | struct x11_compositor *c; |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 1083 | struct x11_configured_output *o; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1084 | xcb_screen_iterator_t s; |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 1085 | int i, x = 0, output_count = 0; |
| 1086 | int width, height, count; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1087 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 1088 | weston_log("initializing x11 backend\n"); |
| 1089 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1090 | c = malloc(sizeof *c); |
| 1091 | if (c == NULL) |
| 1092 | return NULL; |
| 1093 | |
| 1094 | memset(c, 0, sizeof *c); |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame] | 1095 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 1096 | if (weston_compositor_init(&c->base, display, argc, argv, |
| 1097 | config_file) < 0) |
Martin Olsson | 11434bb | 2012-07-08 03:03:44 +0200 | [diff] [blame] | 1098 | goto err_free; |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 1099 | |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame] | 1100 | c->dpy = XOpenDisplay(NULL); |
Cyril Brulebois | 2079829 | 2011-04-06 18:05:40 +0200 | [diff] [blame] | 1101 | if (c->dpy == NULL) |
Martin Olsson | 11434bb | 2012-07-08 03:03:44 +0200 | [diff] [blame] | 1102 | goto err_free; |
Cyril Brulebois | 2079829 | 2011-04-06 18:05:40 +0200 | [diff] [blame] | 1103 | |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame] | 1104 | c->conn = XGetXCBConnection(c->dpy); |
Benjamin Franzke | e997c5f | 2011-03-25 14:06:37 +0100 | [diff] [blame] | 1105 | XSetEventQueueOwner(c->dpy, XCBOwnsEventQueue); |
| 1106 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1107 | if (xcb_connection_has_error(c->conn)) |
Martin Olsson | 11434bb | 2012-07-08 03:03:44 +0200 | [diff] [blame] | 1108 | goto err_xdisplay; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1109 | |
| 1110 | s = xcb_setup_roots_iterator(xcb_get_setup(c->conn)); |
| 1111 | c->screen = s.data; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 1112 | wl_array_init(&c->keys); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1113 | |
| 1114 | x11_compositor_get_resources(c); |
| 1115 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 1116 | c->base.wl_display = display; |
Tiago Vignatti | 997ce64 | 2010-11-10 02:42:35 +0200 | [diff] [blame] | 1117 | if (x11_compositor_init_egl(c) < 0) |
Martin Olsson | 11434bb | 2012-07-08 03:03:44 +0200 | [diff] [blame] | 1118 | goto err_xdisplay; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1119 | |
Kristian Høgsberg | 8525a50 | 2011-01-14 16:20:21 -0500 | [diff] [blame] | 1120 | c->base.destroy = x11_destroy; |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 1121 | c->base.restore = x11_restore; |
Kristian Høgsberg | 8525a50 | 2011-01-14 16:20:21 -0500 | [diff] [blame] | 1122 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 1123 | if (weston_compositor_init_gl(&c->base) < 0) |
Martin Olsson | 11434bb | 2012-07-08 03:03:44 +0200 | [diff] [blame] | 1124 | goto err_egl; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1125 | |
Daniel Stone | 22815f9 | 2012-06-22 13:21:34 +0100 | [diff] [blame] | 1126 | if (x11_input_create(c, no_input) < 0) |
Martin Olsson | 11434bb | 2012-07-08 03:03:44 +0200 | [diff] [blame] | 1127 | goto err_egl; |
Daniel Stone | 22815f9 | 2012-06-22 13:21:34 +0100 | [diff] [blame] | 1128 | |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 1129 | width = option_width ? option_width : 1024; |
| 1130 | height = option_height ? option_height : 640; |
| 1131 | count = option_count ? option_count : 1; |
| 1132 | |
| 1133 | wl_list_for_each(o, &configured_output_list, link) { |
| 1134 | sprintf(configured_name, "%s - %s", name, o->name); |
| 1135 | if (x11_compositor_create_output(c, x, 0, |
| 1136 | option_width ? option_width : |
| 1137 | o->width, |
| 1138 | option_height ? option_height : |
| 1139 | o->height, |
| 1140 | fullscreen, no_input, |
| 1141 | configured_name) < 0) |
| 1142 | goto err_x11_input; |
| 1143 | x += option_width ? option_width : o->width; |
| 1144 | output_count++; |
| 1145 | if (option_count && output_count >= option_count) |
| 1146 | break; |
| 1147 | } |
| 1148 | |
| 1149 | for (i = output_count; i < count; i++) { |
Kristian Høgsberg | 1ccd9d2 | 2011-07-21 10:22:13 -0700 | [diff] [blame] | 1150 | if (x11_compositor_create_output(c, x, 0, width, height, |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 1151 | fullscreen, no_input, name) < 0) |
Martin Olsson | 11434bb | 2012-07-08 03:03:44 +0200 | [diff] [blame] | 1152 | goto err_x11_input; |
Kristian Høgsberg | 1ccd9d2 | 2011-07-21 10:22:13 -0700 | [diff] [blame] | 1153 | x += width; |
| 1154 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1155 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1156 | c->xcb_source = |
Kristian Høgsberg | 22ba60e | 2012-03-12 01:18:24 -0400 | [diff] [blame] | 1157 | wl_event_loop_add_fd(c->base.input_loop, |
| 1158 | xcb_get_file_descriptor(c->conn), |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1159 | WL_EVENT_READABLE, |
| 1160 | x11_compositor_handle_event, c); |
Kristian Høgsberg | 127d0f0 | 2011-04-22 12:18:13 -0400 | [diff] [blame] | 1161 | wl_event_source_check(c->xcb_source); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1162 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1163 | return &c->base; |
Martin Olsson | 11434bb | 2012-07-08 03:03:44 +0200 | [diff] [blame] | 1164 | |
| 1165 | err_x11_input: |
| 1166 | x11_input_destroy(c); |
| 1167 | err_egl: |
| 1168 | x11_compositor_fini_egl(c); |
| 1169 | err_xdisplay: |
| 1170 | XCloseDisplay(c->dpy); |
| 1171 | err_free: |
| 1172 | free(c); |
| 1173 | return NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1174 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1175 | |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 1176 | static void |
| 1177 | output_section_done(void *data) |
| 1178 | { |
| 1179 | struct x11_configured_output *output; |
| 1180 | |
| 1181 | output = malloc(sizeof *output); |
| 1182 | |
| 1183 | if (!output || !output_name || !output_mode) { |
| 1184 | free(output_name); |
| 1185 | output_name = NULL; |
| 1186 | free(output_mode); |
| 1187 | output_mode = NULL; |
| 1188 | return; |
| 1189 | } |
| 1190 | |
| 1191 | output->name = output_name; |
| 1192 | |
| 1193 | if (output_name[0] != 'X') { |
| 1194 | x11_free_configured_output(output); |
| 1195 | return; |
| 1196 | } |
| 1197 | |
| 1198 | if (sscanf(output_mode, "%dx%d", &output->width, &output->height) != 2) { |
| 1199 | weston_log("Invalid mode \"%s\" for output %s\n", |
| 1200 | output_mode, output_name); |
| 1201 | x11_free_configured_output(output); |
| 1202 | return; |
| 1203 | } |
| 1204 | |
| 1205 | free(output_mode); |
| 1206 | output_mode = NULL; |
| 1207 | |
| 1208 | wl_list_insert(configured_output_list.prev, &output->link); |
| 1209 | } |
| 1210 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1211 | WL_EXPORT struct weston_compositor * |
Daniel Stone | c1be8e5 | 2012-06-01 11:14:02 -0400 | [diff] [blame] | 1212 | backend_init(struct wl_display *display, int argc, char *argv[], |
| 1213 | const char *config_file) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1214 | { |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 1215 | int fullscreen = 0; |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 1216 | int no_input = 0; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1217 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 1218 | const struct weston_option x11_options[] = { |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 1219 | { WESTON_OPTION_INTEGER, "width", 0, &option_width }, |
| 1220 | { WESTON_OPTION_INTEGER, "height", 0, &option_height }, |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 1221 | { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &fullscreen }, |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 1222 | { WESTON_OPTION_INTEGER, "output-count", 0, &option_count }, |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 1223 | { WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input }, |
Kristian Høgsberg | 83eeacb | 2011-06-18 04:20:54 -0400 | [diff] [blame] | 1224 | }; |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 1225 | |
| 1226 | parse_options(x11_options, ARRAY_LENGTH(x11_options), argc, argv); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1227 | |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 1228 | wl_list_init(&configured_output_list); |
| 1229 | |
| 1230 | const struct config_key x11_config_keys[] = { |
| 1231 | { "name", CONFIG_KEY_STRING, &output_name }, |
| 1232 | { "mode", CONFIG_KEY_STRING, &output_mode }, |
| 1233 | }; |
| 1234 | |
| 1235 | const struct config_section config_section[] = { |
| 1236 | { "output", x11_config_keys, |
| 1237 | ARRAY_LENGTH(x11_config_keys), output_section_done }, |
| 1238 | }; |
| 1239 | |
| 1240 | parse_config_file(config_file, config_section, |
| 1241 | ARRAY_LENGTH(config_section), NULL); |
| 1242 | |
Kristian Høgsberg | 1ccd9d2 | 2011-07-21 10:22:13 -0700 | [diff] [blame] | 1243 | return x11_compositor_create(display, |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame^] | 1244 | fullscreen, |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 1245 | no_input, |
Daniel Stone | c1be8e5 | 2012-06-01 11:14:02 -0400 | [diff] [blame] | 1246 | argc, argv, config_file); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1247 | } |