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