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