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 |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 4 | * Copyright © 2013 Vasily Khoruzhick <anarsoul@gmail.com> |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 5 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining |
| 7 | * a copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 13 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial |
| 16 | * portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 22 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 23 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 25 | * SOFTWARE. |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 26 | */ |
| 27 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 28 | #include "config.h" |
Chia-I Wu | 1b6c0ed | 2010-10-29 15:20:18 +0800 | [diff] [blame] | 29 | |
John Kåre Alsaker | 143a898 | 2012-10-12 12:25:07 +0200 | [diff] [blame] | 30 | #include <assert.h> |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 31 | #include <stddef.h> |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 32 | #include <stdint.h> |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 33 | #include <stdlib.h> |
| 34 | #include <string.h> |
| 35 | #include <fcntl.h> |
| 36 | #include <unistd.h> |
| 37 | #include <errno.h> |
| 38 | #include <sys/time.h> |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 39 | #include <sys/shm.h> |
Kristian Høgsberg | f9112b2 | 2010-06-14 12:53:43 -0400 | [diff] [blame] | 40 | #include <linux/input.h> |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 41 | |
| 42 | #include <xcb/xcb.h> |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 43 | #include <xcb/shm.h> |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 44 | #ifdef HAVE_XCB_XKB |
| 45 | #include <xcb/xkb.h> |
| 46 | #endif |
| 47 | |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame] | 48 | #include <X11/Xlib.h> |
| 49 | #include <X11/Xlib-xcb.h> |
| 50 | |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 51 | #include <xkbcommon/xkbcommon.h> |
| 52 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 53 | #include "compositor.h" |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 54 | #include "compositor-x11.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 55 | #include "shared/config-parser.h" |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 56 | #include "shared/helpers.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 57 | #include "shared/image-loader.h" |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 58 | #include "gl-renderer.h" |
| 59 | #include "pixman-renderer.h" |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 60 | #include "presentation-time-server-protocol.h" |
Pekka Paalanen | 5ffb440 | 2014-06-12 16:52:53 +0300 | [diff] [blame] | 61 | #include "linux-dmabuf.h" |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 62 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 63 | #define DEFAULT_AXIS_STEP_DISTANCE 10 |
Jonas Ådahl | 62efe20 | 2012-09-27 18:40:41 +0200 | [diff] [blame] | 64 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 65 | struct x11_backend { |
| 66 | struct weston_backend base; |
| 67 | struct weston_compositor *compositor; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 68 | |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame] | 69 | Display *dpy; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 70 | xcb_connection_t *conn; |
| 71 | xcb_screen_t *screen; |
| 72 | xcb_cursor_t null_cursor; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 73 | struct wl_array keys; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 74 | struct wl_event_source *xcb_source; |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 75 | struct xkb_keymap *xkb_keymap; |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 76 | unsigned int has_xkb; |
| 77 | uint8_t xkb_event_base; |
Vasily Khoruzhick | d894351 | 2013-01-07 22:36:02 +0300 | [diff] [blame] | 78 | int use_pixman; |
Kristian Høgsberg | 4f92c53 | 2012-08-10 10:04:36 -0400 | [diff] [blame] | 79 | |
Kristian Høgsberg | 7cc3d84 | 2013-02-19 21:19:04 -0500 | [diff] [blame] | 80 | int has_net_wm_state_fullscreen; |
| 81 | |
Kristian Høgsberg | 4f92c53 | 2012-08-10 10:04:36 -0400 | [diff] [blame] | 82 | /* We could map multi-pointer X to multiple wayland seats, but |
| 83 | * for now we only support core X input. */ |
Kristian Høgsberg | 068b61c | 2013-02-25 17:04:47 -0500 | [diff] [blame] | 84 | struct weston_seat core_seat; |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 85 | double prev_x; |
| 86 | double prev_y; |
Kristian Høgsberg | 4f92c53 | 2012-08-10 10:04:36 -0400 | [diff] [blame] | 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 | 7cc3d84 | 2013-02-19 21:19:04 -0500 | [diff] [blame] | 95 | xcb_atom_t net_supporting_wm_check; |
| 96 | xcb_atom_t net_supported; |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 97 | xcb_atom_t net_wm_icon; |
Kristian Høgsberg | 83eeacb | 2011-06-18 04:20:54 -0400 | [diff] [blame] | 98 | xcb_atom_t net_wm_state; |
| 99 | xcb_atom_t net_wm_state_fullscreen; |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 100 | xcb_atom_t string; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 101 | xcb_atom_t utf8_string; |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 102 | xcb_atom_t cardinal; |
Daniel Stone | 855028f | 2012-05-01 20:37:10 +0100 | [diff] [blame] | 103 | xcb_atom_t xkb_names; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 104 | } atom; |
| 105 | }; |
| 106 | |
| 107 | struct x11_output { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 108 | struct weston_output base; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 109 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 110 | xcb_window_t window; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 111 | struct weston_mode mode; |
Kristian Høgsberg | 06a670f | 2011-10-29 14:39:13 -0400 | [diff] [blame] | 112 | struct wl_event_source *finish_frame_timer; |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 113 | |
| 114 | xcb_gc_t gc; |
| 115 | xcb_shm_seg_t segment; |
| 116 | pixman_image_t *hw_surface; |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 117 | int shm_id; |
| 118 | void *buf; |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 119 | uint8_t depth; |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 120 | int32_t scale; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 121 | }; |
| 122 | |
Derek Foreman | d540f4b | 2015-01-27 16:26:49 -0600 | [diff] [blame] | 123 | struct window_delete_data { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 124 | struct x11_backend *backend; |
Derek Foreman | d540f4b | 2015-01-27 16:26:49 -0600 | [diff] [blame] | 125 | xcb_window_t window; |
| 126 | }; |
| 127 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 128 | struct gl_renderer_interface *gl_renderer; |
| 129 | |
Armin Krezović | 295e9d0 | 2016-08-01 19:17:58 +0200 | [diff] [blame] | 130 | static inline struct x11_output * |
| 131 | to_x11_output(struct weston_output *base) |
| 132 | { |
| 133 | return container_of(base, struct x11_output, base); |
| 134 | } |
| 135 | |
| 136 | static inline struct x11_backend * |
| 137 | to_x11_backend(struct weston_compositor *base) |
| 138 | { |
| 139 | return container_of(base->backend, struct x11_backend, base); |
| 140 | } |
| 141 | |
Marko | 61b4d3e | 2015-10-05 17:27:54 -0500 | [diff] [blame] | 142 | static xcb_screen_t * |
| 143 | x11_compositor_get_default_screen(struct x11_backend *b) |
| 144 | { |
| 145 | xcb_screen_iterator_t iter; |
| 146 | int i, screen_nbr = XDefaultScreen(b->dpy); |
| 147 | |
| 148 | iter = xcb_setup_roots_iterator(xcb_get_setup(b->conn)); |
| 149 | for (i = 0; iter.rem; xcb_screen_next(&iter), i++) |
| 150 | if (i == screen_nbr) |
| 151 | return iter.data; |
| 152 | |
| 153 | return xcb_setup_roots_iterator(xcb_get_setup(b->conn)).data; |
| 154 | } |
| 155 | |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 156 | static struct xkb_keymap * |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 157 | x11_backend_get_keymap(struct x11_backend *b) |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 158 | { |
| 159 | xcb_get_property_cookie_t cookie; |
| 160 | xcb_get_property_reply_t *reply; |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 161 | struct xkb_rule_names names; |
| 162 | struct xkb_keymap *ret; |
| 163 | const char *value_all, *value_part; |
| 164 | int length_all, length_part; |
| 165 | |
| 166 | memset(&names, 0, sizeof(names)); |
| 167 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 168 | cookie = xcb_get_property(b->conn, 0, b->screen->root, |
| 169 | b->atom.xkb_names, b->atom.string, 0, 1024); |
| 170 | reply = xcb_get_property_reply(b->conn, cookie, NULL); |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 171 | if (reply == NULL) |
| 172 | return NULL; |
| 173 | |
| 174 | value_all = xcb_get_property_value(reply); |
| 175 | length_all = xcb_get_property_value_length(reply); |
| 176 | value_part = value_all; |
| 177 | |
| 178 | #define copy_prop_value(to) \ |
| 179 | length_part = strlen(value_part); \ |
| 180 | if (value_part + length_part < (value_all + length_all) && \ |
| 181 | length_part > 0) \ |
| 182 | names.to = value_part; \ |
| 183 | value_part += length_part + 1; |
| 184 | |
| 185 | copy_prop_value(rules); |
| 186 | copy_prop_value(model); |
| 187 | copy_prop_value(layout); |
| 188 | copy_prop_value(variant); |
| 189 | copy_prop_value(options); |
| 190 | #undef copy_prop_value |
| 191 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 192 | ret = xkb_keymap_new_from_names(b->compositor->xkb_context, &names, 0); |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 193 | |
| 194 | free(reply); |
| 195 | return ret; |
| 196 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 197 | |
Kristian Høgsberg | aac8693 | 2012-10-29 14:15:40 -0400 | [diff] [blame] | 198 | static uint32_t |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 199 | get_xkb_mod_mask(struct x11_backend *b, uint32_t in) |
Kristian Høgsberg | aac8693 | 2012-10-29 14:15:40 -0400 | [diff] [blame] | 200 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 201 | struct weston_keyboard *keyboard = |
| 202 | weston_seat_get_keyboard(&b->core_seat); |
| 203 | struct weston_xkb_info *info = keyboard->xkb_info; |
Kristian Høgsberg | aac8693 | 2012-10-29 14:15:40 -0400 | [diff] [blame] | 204 | uint32_t ret = 0; |
| 205 | |
| 206 | if ((in & ShiftMask) && info->shift_mod != XKB_MOD_INVALID) |
| 207 | ret |= (1 << info->shift_mod); |
| 208 | if ((in & LockMask) && info->caps_mod != XKB_MOD_INVALID) |
| 209 | ret |= (1 << info->caps_mod); |
| 210 | if ((in & ControlMask) && info->ctrl_mod != XKB_MOD_INVALID) |
| 211 | ret |= (1 << info->ctrl_mod); |
| 212 | if ((in & Mod1Mask) && info->alt_mod != XKB_MOD_INVALID) |
| 213 | ret |= (1 << info->alt_mod); |
| 214 | if ((in & Mod2Mask) && info->mod2_mod != XKB_MOD_INVALID) |
| 215 | ret |= (1 << info->mod2_mod); |
| 216 | if ((in & Mod3Mask) && info->mod3_mod != XKB_MOD_INVALID) |
| 217 | ret |= (1 << info->mod3_mod); |
| 218 | if ((in & Mod4Mask) && info->super_mod != XKB_MOD_INVALID) |
| 219 | ret |= (1 << info->super_mod); |
| 220 | if ((in & Mod5Mask) && info->mod5_mod != XKB_MOD_INVALID) |
| 221 | ret |= (1 << info->mod5_mod); |
| 222 | |
| 223 | return ret; |
| 224 | } |
| 225 | |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 226 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 227 | x11_backend_setup_xkb(struct x11_backend *b) |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 228 | { |
| 229 | #ifndef HAVE_XCB_XKB |
| 230 | weston_log("XCB-XKB not available during build\n"); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 231 | b->has_xkb = 0; |
| 232 | b->xkb_event_base = 0; |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 233 | return; |
| 234 | #else |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 235 | struct weston_keyboard *keyboard; |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 236 | const xcb_query_extension_reply_t *ext; |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 237 | xcb_generic_error_t *error; |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 238 | xcb_void_cookie_t select; |
Ran Benita | 6a39d87 | 2012-10-31 20:14:57 +0200 | [diff] [blame] | 239 | xcb_xkb_use_extension_cookie_t use_ext; |
| 240 | xcb_xkb_use_extension_reply_t *use_ext_reply; |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 241 | xcb_xkb_per_client_flags_cookie_t pcf; |
| 242 | xcb_xkb_per_client_flags_reply_t *pcf_reply; |
Kristian Høgsberg | aac8693 | 2012-10-29 14:15:40 -0400 | [diff] [blame] | 243 | xcb_xkb_get_state_cookie_t state; |
| 244 | xcb_xkb_get_state_reply_t *state_reply; |
Rui Matos | c6c2f8e | 2013-10-10 19:44:20 +0200 | [diff] [blame] | 245 | uint32_t values[1] = { XCB_EVENT_MASK_PROPERTY_CHANGE }; |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 246 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 247 | b->has_xkb = 0; |
| 248 | b->xkb_event_base = 0; |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 249 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 250 | ext = xcb_get_extension_data(b->conn, &xcb_xkb_id); |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 251 | if (!ext) { |
| 252 | weston_log("XKB extension not available on host X11 server\n"); |
| 253 | return; |
| 254 | } |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 255 | b->xkb_event_base = ext->first_event; |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 256 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 257 | select = xcb_xkb_select_events_checked(b->conn, |
Ran Benita | 424ae01 | 2012-10-31 00:13:08 +0200 | [diff] [blame] | 258 | XCB_XKB_ID_USE_CORE_KBD, |
| 259 | XCB_XKB_EVENT_TYPE_STATE_NOTIFY, |
| 260 | 0, |
| 261 | XCB_XKB_EVENT_TYPE_STATE_NOTIFY, |
| 262 | 0, |
| 263 | 0, |
| 264 | NULL); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 265 | error = xcb_request_check(b->conn, select); |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 266 | if (error) { |
| 267 | weston_log("error: failed to select for XKB state events\n"); |
Ran Benita | 7b5e3cd | 2012-10-31 20:14:56 +0200 | [diff] [blame] | 268 | free(error); |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 269 | return; |
| 270 | } |
| 271 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 272 | use_ext = xcb_xkb_use_extension(b->conn, |
Ran Benita | 6a39d87 | 2012-10-31 20:14:57 +0200 | [diff] [blame] | 273 | XCB_XKB_MAJOR_VERSION, |
| 274 | XCB_XKB_MINOR_VERSION); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 275 | use_ext_reply = xcb_xkb_use_extension_reply(b->conn, use_ext, NULL); |
Ran Benita | 6a39d87 | 2012-10-31 20:14:57 +0200 | [diff] [blame] | 276 | if (!use_ext_reply) { |
| 277 | weston_log("couldn't start using XKB extension\n"); |
| 278 | return; |
| 279 | } |
| 280 | |
| 281 | if (!use_ext_reply->supported) { |
| 282 | weston_log("XKB extension version on the server is too old " |
| 283 | "(want %d.%d, has %d.%d)\n", |
| 284 | XCB_XKB_MAJOR_VERSION, XCB_XKB_MINOR_VERSION, |
| 285 | use_ext_reply->serverMajor, use_ext_reply->serverMinor); |
| 286 | free(use_ext_reply); |
| 287 | return; |
| 288 | } |
| 289 | free(use_ext_reply); |
| 290 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 291 | pcf = xcb_xkb_per_client_flags(b->conn, |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 292 | XCB_XKB_ID_USE_CORE_KBD, |
| 293 | XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT, |
| 294 | XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT, |
| 295 | 0, |
| 296 | 0, |
| 297 | 0); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 298 | pcf_reply = xcb_xkb_per_client_flags_reply(b->conn, pcf, NULL); |
Ran Benita | 7109cc8 | 2012-10-31 20:14:58 +0200 | [diff] [blame] | 299 | if (!pcf_reply || |
| 300 | !(pcf_reply->value & XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT)) { |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 301 | weston_log("failed to set XKB per-client flags, not using " |
| 302 | "detectable repeat\n"); |
Ran Benita | 7109cc8 | 2012-10-31 20:14:58 +0200 | [diff] [blame] | 303 | free(pcf_reply); |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 304 | return; |
| 305 | } |
Ran Benita | 7b5e3cd | 2012-10-31 20:14:56 +0200 | [diff] [blame] | 306 | free(pcf_reply); |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 307 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 308 | state = xcb_xkb_get_state(b->conn, XCB_XKB_ID_USE_CORE_KBD); |
| 309 | state_reply = xcb_xkb_get_state_reply(b->conn, state, NULL); |
Ran Benita | 7b5e3cd | 2012-10-31 20:14:56 +0200 | [diff] [blame] | 310 | if (!state_reply) { |
Kristian Høgsberg | aac8693 | 2012-10-29 14:15:40 -0400 | [diff] [blame] | 311 | weston_log("failed to get initial XKB state\n"); |
Kristian Høgsberg | aac8693 | 2012-10-29 14:15:40 -0400 | [diff] [blame] | 312 | return; |
| 313 | } |
| 314 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 315 | keyboard = weston_seat_get_keyboard(&b->core_seat); |
| 316 | xkb_state_update_mask(keyboard->xkb_state.state, |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 317 | get_xkb_mod_mask(b, state_reply->baseMods), |
| 318 | get_xkb_mod_mask(b, state_reply->latchedMods), |
| 319 | get_xkb_mod_mask(b, state_reply->lockedMods), |
Kristian Høgsberg | aac8693 | 2012-10-29 14:15:40 -0400 | [diff] [blame] | 320 | 0, |
| 321 | 0, |
| 322 | state_reply->group); |
| 323 | |
| 324 | free(state_reply); |
| 325 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 326 | xcb_change_window_attributes(b->conn, b->screen->root, |
Rui Matos | c6c2f8e | 2013-10-10 19:44:20 +0200 | [diff] [blame] | 327 | XCB_CW_EVENT_MASK, values); |
| 328 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 329 | b->has_xkb = 1; |
Daniel Stone | 62b33b6 | 2012-06-22 13:21:35 +0100 | [diff] [blame] | 330 | #endif |
| 331 | } |
| 332 | |
Jonas Ådahl | f88571f | 2013-10-25 23:18:01 +0200 | [diff] [blame] | 333 | #ifdef HAVE_XCB_XKB |
Rui Matos | c6c2f8e | 2013-10-10 19:44:20 +0200 | [diff] [blame] | 334 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 335 | update_xkb_keymap(struct x11_backend *b) |
Rui Matos | c6c2f8e | 2013-10-10 19:44:20 +0200 | [diff] [blame] | 336 | { |
| 337 | struct xkb_keymap *keymap; |
| 338 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 339 | keymap = x11_backend_get_keymap(b); |
Rui Matos | c6c2f8e | 2013-10-10 19:44:20 +0200 | [diff] [blame] | 340 | if (!keymap) { |
| 341 | weston_log("failed to get XKB keymap\n"); |
| 342 | return; |
| 343 | } |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 344 | weston_seat_update_keymap(&b->core_seat, keymap); |
Rui Matos | c6c2f8e | 2013-10-10 19:44:20 +0200 | [diff] [blame] | 345 | xkb_keymap_unref(keymap); |
| 346 | } |
Jonas Ådahl | f88571f | 2013-10-25 23:18:01 +0200 | [diff] [blame] | 347 | #endif |
Rui Matos | c6c2f8e | 2013-10-10 19:44:20 +0200 | [diff] [blame] | 348 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 349 | static int |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 350 | x11_input_create(struct x11_backend *b, int no_input) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 351 | { |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 352 | struct xkb_keymap *keymap; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 353 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 354 | weston_seat_init(&b->core_seat, b->compositor, "default"); |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 355 | |
| 356 | if (no_input) |
| 357 | return 0; |
| 358 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 359 | weston_seat_init_pointer(&b->core_seat); |
Daniel Stone | 576cd15 | 2012-06-01 12:14:02 +0100 | [diff] [blame] | 360 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 361 | keymap = x11_backend_get_keymap(b); |
| 362 | if (weston_seat_init_keyboard(&b->core_seat, keymap) < 0) |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 363 | return -1; |
Ran Benita | c9c7415 | 2014-08-19 23:59:52 +0300 | [diff] [blame] | 364 | xkb_keymap_unref(keymap); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 365 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 366 | x11_backend_setup_xkb(b); |
Kristian Høgsberg | aac8693 | 2012-10-29 14:15:40 -0400 | [diff] [blame] | 367 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 368 | return 0; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 369 | } |
| 370 | |
Pekka Paalanen | 43c61d8 | 2012-01-03 11:58:34 +0200 | [diff] [blame] | 371 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 372 | x11_input_destroy(struct x11_backend *b) |
Pekka Paalanen | 43c61d8 | 2012-01-03 11:58:34 +0200 | [diff] [blame] | 373 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 374 | weston_seat_release(&b->core_seat); |
Pekka Paalanen | 43c61d8 | 2012-01-03 11:58:34 +0200 | [diff] [blame] | 375 | } |
| 376 | |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 377 | static void |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 378 | x11_output_start_repaint_loop(struct weston_output *output) |
| 379 | { |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 380 | struct timespec ts; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 381 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 382 | weston_compositor_read_presentation_clock(output->compositor, &ts); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 383 | weston_output_finish_frame(output, &ts, WP_PRESENTATION_FEEDBACK_INVALID); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 384 | } |
| 385 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 386 | static int |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 387 | x11_output_repaint_gl(struct weston_output *output_base, |
| 388 | pixman_region32_t *damage) |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 389 | { |
Armin Krezović | 295e9d0 | 2016-08-01 19:17:58 +0200 | [diff] [blame] | 390 | struct x11_output *output = to_x11_output(output_base); |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 391 | struct weston_compositor *ec = output->base.compositor; |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 392 | |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 393 | ec->renderer->repaint_output(output_base, damage); |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 394 | |
Ander Conselvan de Oliveira | 0a88772 | 2012-11-22 15:57:00 +0200 | [diff] [blame] | 395 | pixman_region32_subtract(&ec->primary_plane.damage, |
| 396 | &ec->primary_plane.damage, damage); |
| 397 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 398 | wl_event_source_timer_update(output->finish_frame_timer, 10); |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 399 | return 0; |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 400 | } |
| 401 | |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 402 | static void |
Alexander Larsson | 80f9163 | 2013-05-22 14:41:38 +0200 | [diff] [blame] | 403 | set_clip_for_output(struct weston_output *output_base, pixman_region32_t *region) |
| 404 | { |
Armin Krezović | 295e9d0 | 2016-08-01 19:17:58 +0200 | [diff] [blame] | 405 | struct x11_output *output = to_x11_output(output_base); |
Alexander Larsson | 80f9163 | 2013-05-22 14:41:38 +0200 | [diff] [blame] | 406 | struct weston_compositor *ec = output->base.compositor; |
Armin Krezović | 295e9d0 | 2016-08-01 19:17:58 +0200 | [diff] [blame] | 407 | struct x11_backend *b = to_x11_backend(ec); |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 408 | pixman_region32_t transformed_region; |
Alexander Larsson | 80f9163 | 2013-05-22 14:41:38 +0200 | [diff] [blame] | 409 | pixman_box32_t *rects; |
| 410 | xcb_rectangle_t *output_rects; |
Alexander Larsson | 80f9163 | 2013-05-22 14:41:38 +0200 | [diff] [blame] | 411 | xcb_void_cookie_t cookie; |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 412 | int nrects, i; |
Alexander Larsson | 80f9163 | 2013-05-22 14:41:38 +0200 | [diff] [blame] | 413 | xcb_generic_error_t *err; |
| 414 | |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 415 | pixman_region32_init(&transformed_region); |
| 416 | pixman_region32_copy(&transformed_region, region); |
| 417 | pixman_region32_translate(&transformed_region, |
| 418 | -output_base->x, -output_base->y); |
| 419 | weston_transformed_region(output_base->width, output_base->height, |
| 420 | output_base->transform, |
| 421 | output_base->current_scale, |
| 422 | &transformed_region, &transformed_region); |
| 423 | |
| 424 | rects = pixman_region32_rectangles(&transformed_region, &nrects); |
Alexander Larsson | 80f9163 | 2013-05-22 14:41:38 +0200 | [diff] [blame] | 425 | output_rects = calloc(nrects, sizeof(xcb_rectangle_t)); |
| 426 | |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 427 | if (output_rects == NULL) { |
| 428 | pixman_region32_fini(&transformed_region); |
Alexander Larsson | 80f9163 | 2013-05-22 14:41:38 +0200 | [diff] [blame] | 429 | return; |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 430 | } |
Alexander Larsson | 80f9163 | 2013-05-22 14:41:38 +0200 | [diff] [blame] | 431 | |
| 432 | for (i = 0; i < nrects; i++) { |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 433 | output_rects[i].x = rects[i].x1; |
| 434 | output_rects[i].y = rects[i].y1; |
| 435 | output_rects[i].width = rects[i].x2 - rects[i].x1; |
| 436 | output_rects[i].height = rects[i].y2 - rects[i].y1; |
Alexander Larsson | 80f9163 | 2013-05-22 14:41:38 +0200 | [diff] [blame] | 437 | } |
| 438 | |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 439 | pixman_region32_fini(&transformed_region); |
| 440 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 441 | cookie = xcb_set_clip_rectangles_checked(b->conn, XCB_CLIP_ORDERING_UNSORTED, |
Alexander Larsson | 80f9163 | 2013-05-22 14:41:38 +0200 | [diff] [blame] | 442 | output->gc, |
| 443 | 0, 0, nrects, |
| 444 | output_rects); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 445 | err = xcb_request_check(b->conn, cookie); |
Alexander Larsson | 80f9163 | 2013-05-22 14:41:38 +0200 | [diff] [blame] | 446 | if (err != NULL) { |
| 447 | weston_log("Failed to set clip rects, err: %d\n", err->error_code); |
| 448 | free(err); |
| 449 | } |
| 450 | free(output_rects); |
| 451 | } |
| 452 | |
| 453 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 454 | static int |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 455 | x11_output_repaint_shm(struct weston_output *output_base, |
| 456 | pixman_region32_t *damage) |
| 457 | { |
Armin Krezović | 295e9d0 | 2016-08-01 19:17:58 +0200 | [diff] [blame] | 458 | struct x11_output *output = to_x11_output(output_base); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 459 | struct weston_compositor *ec = output->base.compositor; |
Armin Krezović | 295e9d0 | 2016-08-01 19:17:58 +0200 | [diff] [blame] | 460 | struct x11_backend *b = to_x11_backend(ec); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 461 | xcb_void_cookie_t cookie; |
| 462 | xcb_generic_error_t *err; |
| 463 | |
Ander Conselvan de Oliveira | 936effd | 2013-01-25 15:13:01 +0200 | [diff] [blame] | 464 | pixman_renderer_output_set_buffer(output_base, output->hw_surface); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 465 | ec->renderer->repaint_output(output_base, damage); |
| 466 | |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 467 | pixman_region32_subtract(&ec->primary_plane.damage, |
| 468 | &ec->primary_plane.damage, damage); |
Alexander Larsson | 80f9163 | 2013-05-22 14:41:38 +0200 | [diff] [blame] | 469 | set_clip_for_output(output_base, damage); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 470 | cookie = xcb_shm_put_image_checked(b->conn, output->window, output->gc, |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 471 | pixman_image_get_width(output->hw_surface), |
| 472 | pixman_image_get_height(output->hw_surface), |
| 473 | 0, 0, |
| 474 | pixman_image_get_width(output->hw_surface), |
| 475 | pixman_image_get_height(output->hw_surface), |
| 476 | 0, 0, output->depth, XCB_IMAGE_FORMAT_Z_PIXMAP, |
| 477 | 0, output->segment, 0); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 478 | err = xcb_request_check(b->conn, cookie); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 479 | if (err != NULL) { |
| 480 | weston_log("Failed to put shm image, err: %d\n", err->error_code); |
| 481 | free(err); |
| 482 | } |
| 483 | |
| 484 | wl_event_source_timer_update(output->finish_frame_timer, 10); |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 485 | return 0; |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 486 | } |
| 487 | |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 488 | static int |
Kristian Høgsberg | 06a670f | 2011-10-29 14:39:13 -0400 | [diff] [blame] | 489 | finish_frame_handler(void *data) |
| 490 | { |
| 491 | struct x11_output *output = data; |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 492 | struct timespec ts; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 493 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 494 | weston_compositor_read_presentation_clock(output->base.compositor, &ts); |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 495 | weston_output_finish_frame(&output->base, &ts, 0); |
Kristian Høgsberg | 06a670f | 2011-10-29 14:39:13 -0400 | [diff] [blame] | 496 | |
| 497 | return 1; |
| 498 | } |
| 499 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 500 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 501 | x11_output_deinit_shm(struct x11_backend *b, struct x11_output *output) |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 502 | { |
| 503 | xcb_void_cookie_t cookie; |
| 504 | xcb_generic_error_t *err; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 505 | xcb_free_gc(b->conn, output->gc); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 506 | |
| 507 | pixman_image_unref(output->hw_surface); |
| 508 | output->hw_surface = NULL; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 509 | cookie = xcb_shm_detach_checked(b->conn, output->segment); |
| 510 | err = xcb_request_check(b->conn, cookie); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 511 | if (err) { |
| 512 | weston_log("xcb_shm_detach failed, error %d\n", err->error_code); |
| 513 | free(err); |
| 514 | } |
| 515 | shmdt(output->buf); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 519 | x11_output_destroy(struct weston_output *output_base) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 520 | { |
Armin Krezović | 295e9d0 | 2016-08-01 19:17:58 +0200 | [diff] [blame] | 521 | struct x11_output *output = to_x11_output(output_base); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 522 | struct x11_backend *backend = |
Armin Krezović | 295e9d0 | 2016-08-01 19:17:58 +0200 | [diff] [blame] | 523 | to_x11_backend(output->base.compositor); |
Pekka Paalanen | 2de99e2 | 2012-01-03 11:51:03 +0200 | [diff] [blame] | 524 | |
Pekka Paalanen | 2de99e2 | 2012-01-03 11:51:03 +0200 | [diff] [blame] | 525 | wl_event_source_remove(output->finish_frame_timer); |
| 526 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 527 | if (backend->use_pixman) { |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 528 | pixman_renderer_output_destroy(output_base); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 529 | x11_output_deinit_shm(backend, output); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 530 | } else |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 531 | gl_renderer->output_destroy(output_base); |
Pekka Paalanen | 2de99e2 | 2012-01-03 11:51:03 +0200 | [diff] [blame] | 532 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 533 | xcb_destroy_window(backend->conn, output->window); |
Pekka Paalanen | 2de99e2 | 2012-01-03 11:51:03 +0200 | [diff] [blame] | 534 | |
Armin Krezović | ad27693 | 2016-06-30 06:29:00 +0200 | [diff] [blame] | 535 | xcb_flush(backend->conn); |
| 536 | |
Kristian Høgsberg | 3466bc8 | 2012-01-03 11:29:15 -0500 | [diff] [blame] | 537 | weston_output_destroy(&output->base); |
Pekka Paalanen | 2de99e2 | 2012-01-03 11:51:03 +0200 | [diff] [blame] | 538 | |
| 539 | free(output); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 540 | } |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 541 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 542 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 543 | x11_output_set_wm_protocols(struct x11_backend *b, |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 544 | struct x11_output *output) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 545 | { |
| 546 | xcb_atom_t list[1]; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 547 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 548 | list[0] = b->atom.wm_delete_window; |
| 549 | xcb_change_property (b->conn, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 550 | XCB_PROP_MODE_REPLACE, |
| 551 | output->window, |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 552 | b->atom.wm_protocols, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 553 | XCB_ATOM_ATOM, |
| 554 | 32, |
Kristian Høgsberg | 09e2692 | 2011-12-23 13:33:45 -0500 | [diff] [blame] | 555 | ARRAY_LENGTH(list), |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 556 | list); |
| 557 | } |
| 558 | |
| 559 | struct wm_normal_hints { |
| 560 | uint32_t flags; |
| 561 | uint32_t pad[4]; |
| 562 | int32_t min_width, min_height; |
| 563 | int32_t max_width, max_height; |
| 564 | int32_t width_inc, height_inc; |
| 565 | int32_t min_aspect_x, min_aspect_y; |
| 566 | int32_t max_aspect_x, max_aspect_y; |
| 567 | int32_t base_width, base_height; |
| 568 | int32_t win_gravity; |
| 569 | }; |
| 570 | |
| 571 | #define WM_NORMAL_HINTS_MIN_SIZE 16 |
| 572 | #define WM_NORMAL_HINTS_MAX_SIZE 32 |
| 573 | |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 574 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 575 | x11_output_set_icon(struct x11_backend *b, |
Kristian Høgsberg | b41d76c | 2011-04-23 15:03:15 -0400 | [diff] [blame] | 576 | struct x11_output *output, const char *filename) |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 577 | { |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 578 | uint32_t *icon; |
Kristian Høgsberg | b41d76c | 2011-04-23 15:03:15 -0400 | [diff] [blame] | 579 | int32_t width, height; |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 580 | pixman_image_t *image; |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 581 | |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 582 | image = load_image(filename); |
| 583 | if (!image) |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 584 | return; |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 585 | width = pixman_image_get_width(image); |
| 586 | height = pixman_image_get_height(image); |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 587 | icon = malloc(width * height * 4 + 8); |
| 588 | if (!icon) { |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 589 | pixman_image_unref(image); |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 590 | return; |
| 591 | } |
| 592 | |
| 593 | icon[0] = width; |
| 594 | icon[1] = height; |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 595 | memcpy(icon + 2, pixman_image_get_data(image), width * height * 4); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 596 | xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 597 | b->atom.net_wm_icon, b->atom.cardinal, 32, |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 598 | width * height + 2, icon); |
| 599 | free(icon); |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 600 | pixman_image_unref(image); |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 601 | } |
| 602 | |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 603 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 604 | x11_output_wait_for_map(struct x11_backend *b, struct x11_output *output) |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 605 | { |
| 606 | xcb_map_notify_event_t *map_notify; |
| 607 | xcb_configure_notify_event_t *configure_notify; |
| 608 | xcb_generic_event_t *event; |
Kristian Høgsberg | 8e7adbf | 2013-02-14 21:14:11 -0500 | [diff] [blame] | 609 | int mapped = 0, configured = 0; |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 610 | uint8_t response_type; |
| 611 | |
| 612 | /* This isn't the nicest way to do this. Ideally, we could |
Kristian Høgsberg | 8e7adbf | 2013-02-14 21:14:11 -0500 | [diff] [blame] | 613 | * just go back to the main loop and once we get the configure |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 614 | * notify, we add the output to the compositor. While we do |
| 615 | * support output hotplug, we can't start up with no outputs. |
Kristian Høgsberg | 8e7adbf | 2013-02-14 21:14:11 -0500 | [diff] [blame] | 616 | * We could add the output and then resize once we get the |
| 617 | * configure notify, but we don't want to start up and |
| 618 | * immediately resize the output. |
| 619 | * |
| 620 | * Also, some window managers don't give us our final |
| 621 | * fullscreen size before map_notify, so if we don't get a |
| 622 | * configure_notify before map_notify, we just wait for the |
| 623 | * first one and hope that's our size. */ |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 624 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 625 | xcb_flush(b->conn); |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 626 | |
Kristian Høgsberg | 8e7adbf | 2013-02-14 21:14:11 -0500 | [diff] [blame] | 627 | while (!mapped || !configured) { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 628 | event = xcb_wait_for_event(b->conn); |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 629 | response_type = event->response_type & ~0x80; |
| 630 | |
| 631 | switch (response_type) { |
| 632 | case XCB_MAP_NOTIFY: |
| 633 | map_notify = (xcb_map_notify_event_t *) event; |
| 634 | if (map_notify->window == output->window) |
| 635 | mapped = 1; |
| 636 | break; |
| 637 | |
| 638 | case XCB_CONFIGURE_NOTIFY: |
| 639 | configure_notify = |
| 640 | (xcb_configure_notify_event_t *) event; |
| 641 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 642 | |
| 643 | if (configure_notify->width % output->scale != 0 || |
| 644 | configure_notify->height % output->scale != 0) |
| 645 | weston_log("Resolution is not a multiple of screen size, rounding\n"); |
Jason Ekstrand | d89a094 | 2014-03-07 15:29:14 -0600 | [diff] [blame] | 646 | output->mode.width = configure_notify->width; |
| 647 | output->mode.height = configure_notify->height; |
Kristian Høgsberg | 8e7adbf | 2013-02-14 21:14:11 -0500 | [diff] [blame] | 648 | configured = 1; |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 649 | break; |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 654 | static xcb_visualtype_t * |
| 655 | find_visual_by_id(xcb_screen_t *screen, |
| 656 | xcb_visualid_t id) |
| 657 | { |
| 658 | xcb_depth_iterator_t i; |
| 659 | xcb_visualtype_iterator_t j; |
| 660 | for (i = xcb_screen_allowed_depths_iterator(screen); |
| 661 | i.rem; |
| 662 | xcb_depth_next(&i)) { |
| 663 | for (j = xcb_depth_visuals_iterator(i.data); |
| 664 | j.rem; |
| 665 | xcb_visualtype_next(&j)) { |
| 666 | if (j.data->visual_id == id) |
| 667 | return j.data; |
| 668 | } |
| 669 | } |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | static uint8_t |
| 674 | get_depth_of_visual(xcb_screen_t *screen, |
| 675 | xcb_visualid_t id) |
| 676 | { |
| 677 | xcb_depth_iterator_t i; |
| 678 | xcb_visualtype_iterator_t j; |
| 679 | for (i = xcb_screen_allowed_depths_iterator(screen); |
| 680 | i.rem; |
| 681 | xcb_depth_next(&i)) { |
| 682 | for (j = xcb_depth_visuals_iterator(i.data); |
| 683 | j.rem; |
| 684 | xcb_visualtype_next(&j)) { |
| 685 | if (j.data->visual_id == id) |
| 686 | return i.data->depth; |
| 687 | } |
| 688 | } |
| 689 | return 0; |
| 690 | } |
| 691 | |
| 692 | static int |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 693 | x11_output_init_shm(struct x11_backend *b, struct x11_output *output, |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 694 | int width, int height) |
| 695 | { |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 696 | xcb_visualtype_t *visual_type; |
Marko | 61b4d3e | 2015-10-05 17:27:54 -0500 | [diff] [blame] | 697 | xcb_screen_t *screen; |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 698 | xcb_format_iterator_t fmt; |
| 699 | xcb_void_cookie_t cookie; |
| 700 | xcb_generic_error_t *err; |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 701 | const xcb_query_extension_reply_t *ext; |
| 702 | int bitsperpixel = 0; |
| 703 | pixman_format_code_t pixman_format; |
| 704 | |
| 705 | /* Check if SHM is available */ |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 706 | ext = xcb_get_extension_data(b->conn, &xcb_shm_id); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 707 | if (ext == NULL || !ext->present) { |
| 708 | /* SHM is missing */ |
| 709 | weston_log("SHM extension is not available\n"); |
| 710 | errno = ENOENT; |
| 711 | return -1; |
| 712 | } |
| 713 | |
Marko | 61b4d3e | 2015-10-05 17:27:54 -0500 | [diff] [blame] | 714 | screen = x11_compositor_get_default_screen(b); |
| 715 | visual_type = find_visual_by_id(screen, screen->root_visual); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 716 | if (!visual_type) { |
| 717 | weston_log("Failed to lookup visual for root window\n"); |
| 718 | errno = ENOENT; |
| 719 | return -1; |
| 720 | } |
| 721 | weston_log("Found visual, bits per value: %d, red_mask: %.8x, green_mask: %.8x, blue_mask: %.8x\n", |
| 722 | visual_type->bits_per_rgb_value, |
| 723 | visual_type->red_mask, |
| 724 | visual_type->green_mask, |
| 725 | visual_type->blue_mask); |
Marko | 61b4d3e | 2015-10-05 17:27:54 -0500 | [diff] [blame] | 726 | output->depth = get_depth_of_visual(screen, screen->root_visual); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 727 | weston_log("Visual depth is %d\n", output->depth); |
| 728 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 729 | for (fmt = xcb_setup_pixmap_formats_iterator(xcb_get_setup(b->conn)); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 730 | fmt.rem; |
| 731 | xcb_format_next(&fmt)) { |
| 732 | if (fmt.data->depth == output->depth) { |
| 733 | bitsperpixel = fmt.data->bits_per_pixel; |
| 734 | break; |
| 735 | } |
| 736 | } |
| 737 | weston_log("Found format for depth %d, bpp: %d\n", |
| 738 | output->depth, bitsperpixel); |
| 739 | |
| 740 | if (bitsperpixel == 32 && |
| 741 | visual_type->red_mask == 0xff0000 && |
| 742 | visual_type->green_mask == 0x00ff00 && |
| 743 | visual_type->blue_mask == 0x0000ff) { |
| 744 | weston_log("Will use x8r8g8b8 format for SHM surfaces\n"); |
| 745 | pixman_format = PIXMAN_x8r8g8b8; |
MoD | 1b55a59 | 2013-11-28 05:24:21 +0000 | [diff] [blame] | 746 | } else if (bitsperpixel == 16 && |
| 747 | visual_type->red_mask == 0x00f800 && |
| 748 | visual_type->green_mask == 0x0007e0 && |
| 749 | visual_type->blue_mask == 0x00001f) { |
| 750 | weston_log("Will use r5g6b5 format for SHM surfaces\n"); |
| 751 | pixman_format = PIXMAN_r5g6b5; |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 752 | } else { |
| 753 | weston_log("Can't find appropriate format for SHM pixmap\n"); |
| 754 | errno = ENOTSUP; |
| 755 | return -1; |
| 756 | } |
| 757 | |
| 758 | |
| 759 | /* Create SHM segment and attach it */ |
| 760 | output->shm_id = shmget(IPC_PRIVATE, width * height * (bitsperpixel / 8), IPC_CREAT | S_IRWXU); |
| 761 | if (output->shm_id == -1) { |
| 762 | weston_log("x11shm: failed to allocate SHM segment\n"); |
| 763 | return -1; |
| 764 | } |
| 765 | output->buf = shmat(output->shm_id, NULL, 0 /* read/write */); |
| 766 | if (-1 == (long)output->buf) { |
| 767 | weston_log("x11shm: failed to attach SHM segment\n"); |
| 768 | return -1; |
| 769 | } |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 770 | output->segment = xcb_generate_id(b->conn); |
| 771 | cookie = xcb_shm_attach_checked(b->conn, output->segment, output->shm_id, 1); |
| 772 | err = xcb_request_check(b->conn, cookie); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 773 | if (err) { |
Bryce Harrington | 665b025 | 2015-05-26 18:14:21 -0700 | [diff] [blame] | 774 | weston_log("x11shm: xcb_shm_attach error %d, op code %d, resource id %d\n", |
| 775 | err->error_code, err->major_code, err->minor_code); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 776 | free(err); |
| 777 | return -1; |
| 778 | } |
| 779 | |
| 780 | shmctl(output->shm_id, IPC_RMID, NULL); |
| 781 | |
| 782 | /* Now create pixman image */ |
| 783 | output->hw_surface = pixman_image_create_bits(pixman_format, width, height, output->buf, |
| 784 | width * (bitsperpixel / 8)); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 785 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 786 | output->gc = xcb_generate_id(b->conn); |
| 787 | xcb_create_gc(b->conn, output->gc, output->window, 0, NULL); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 792 | static struct x11_output * |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 793 | x11_backend_create_output(struct x11_backend *b, int x, int y, |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 794 | int width, int height, int fullscreen, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 795 | int no_input, char *configured_name, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 796 | uint32_t transform, int32_t scale) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 797 | { |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 798 | static const char name[] = "Weston Compositor"; |
Kristian Høgsberg | 8600040 | 2012-01-03 23:24:14 -0500 | [diff] [blame] | 799 | static const char class[] = "weston-1\0Weston Compositor"; |
Benoit Gschwind | 5c2f20e | 2016-06-05 19:01:11 +0200 | [diff] [blame] | 800 | char *title = NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 801 | struct x11_output *output; |
Marko | 61b4d3e | 2015-10-05 17:27:54 -0500 | [diff] [blame] | 802 | xcb_screen_t *screen; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 803 | struct wm_normal_hints normal_hints; |
Kristian Høgsberg | 06a670f | 2011-10-29 14:39:13 -0400 | [diff] [blame] | 804 | struct wl_event_loop *loop; |
Kristian Høgsberg | 8404acb | 2014-03-18 12:15:42 -0700 | [diff] [blame] | 805 | int output_width, output_height, width_mm, height_mm; |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 806 | int ret; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 807 | uint32_t mask = XCB_CW_EVENT_MASK | XCB_CW_CURSOR; |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 808 | xcb_atom_t atom_list[1]; |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 809 | uint32_t values[2] = { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 810 | XCB_EVENT_MASK_EXPOSURE | |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 811 | XCB_EVENT_MASK_STRUCTURE_NOTIFY, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 812 | 0 |
| 813 | }; |
| 814 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 815 | output_width = width * scale; |
| 816 | output_height = height * scale; |
| 817 | |
Pekka Paalanen | 36f155f | 2012-06-07 15:07:05 +0300 | [diff] [blame] | 818 | if (!no_input) |
| 819 | values[0] |= |
| 820 | XCB_EVENT_MASK_KEY_PRESS | |
| 821 | XCB_EVENT_MASK_KEY_RELEASE | |
| 822 | XCB_EVENT_MASK_BUTTON_PRESS | |
| 823 | XCB_EVENT_MASK_BUTTON_RELEASE | |
| 824 | XCB_EVENT_MASK_POINTER_MOTION | |
| 825 | XCB_EVENT_MASK_ENTER_WINDOW | |
| 826 | XCB_EVENT_MASK_LEAVE_WINDOW | |
| 827 | XCB_EVENT_MASK_KEYMAP_STATE | |
| 828 | XCB_EVENT_MASK_FOCUS_CHANGE; |
| 829 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 830 | output = zalloc(sizeof *output); |
Bryce Harrington | 665b025 | 2015-05-26 18:14:21 -0700 | [diff] [blame] | 831 | if (output == NULL) { |
| 832 | perror("zalloc"); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 833 | return NULL; |
Bryce Harrington | 665b025 | 2015-05-26 18:14:21 -0700 | [diff] [blame] | 834 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 835 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 836 | output->mode.flags = |
| 837 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 838 | |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 839 | output->mode.width = output_width; |
| 840 | output->mode.height = output_height; |
Kristian Høgsberg | c4621b0 | 2012-05-10 12:23:53 -0400 | [diff] [blame] | 841 | output->mode.refresh = 60000; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 842 | output->scale = scale; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 843 | wl_list_init(&output->base.mode_list); |
| 844 | wl_list_insert(&output->base.mode_list, &output->mode.link); |
| 845 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 846 | values[1] = b->null_cursor; |
| 847 | output->window = xcb_generate_id(b->conn); |
Marko | 61b4d3e | 2015-10-05 17:27:54 -0500 | [diff] [blame] | 848 | screen = x11_compositor_get_default_screen(b); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 849 | xcb_create_window(b->conn, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 850 | XCB_COPY_FROM_PARENT, |
| 851 | output->window, |
Marko | 61b4d3e | 2015-10-05 17:27:54 -0500 | [diff] [blame] | 852 | screen->root, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 853 | 0, 0, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 854 | output_width, output_height, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 855 | 0, |
| 856 | XCB_WINDOW_CLASS_INPUT_OUTPUT, |
Marko | 61b4d3e | 2015-10-05 17:27:54 -0500 | [diff] [blame] | 857 | screen->root_visual, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 858 | mask, values); |
| 859 | |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 860 | if (fullscreen) { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 861 | atom_list[0] = b->atom.net_wm_state_fullscreen; |
| 862 | xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE, |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 863 | output->window, |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 864 | b->atom.net_wm_state, |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 865 | XCB_ATOM_ATOM, 32, |
| 866 | ARRAY_LENGTH(atom_list), atom_list); |
| 867 | } else { |
| 868 | /* Don't resize me. */ |
| 869 | memset(&normal_hints, 0, sizeof normal_hints); |
| 870 | normal_hints.flags = |
| 871 | WM_NORMAL_HINTS_MAX_SIZE | WM_NORMAL_HINTS_MIN_SIZE; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 872 | normal_hints.min_width = output_width; |
| 873 | normal_hints.min_height = output_height; |
| 874 | normal_hints.max_width = output_width; |
| 875 | normal_hints.max_height = output_height; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 876 | xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 877 | b->atom.wm_normal_hints, |
| 878 | b->atom.wm_size_hints, 32, |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 879 | sizeof normal_hints / 4, |
| 880 | (uint8_t *) &normal_hints); |
| 881 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 882 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 883 | /* Set window name. Don't bother with non-EWMH WMs. */ |
Benoit Gschwind | 5c2f20e | 2016-06-05 19:01:11 +0200 | [diff] [blame] | 884 | if (configured_name) { |
| 885 | if (asprintf(&title, "%s - %s", name, configured_name) < 0) |
| 886 | title = NULL; |
| 887 | } else { |
| 888 | title = strdup(name); |
| 889 | } |
| 890 | |
| 891 | if (title) { |
| 892 | xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 893 | b->atom.net_wm_name, b->atom.utf8_string, 8, |
| 894 | strlen(title), title); |
| 895 | free(title); |
| 896 | } else { |
| 897 | xcb_destroy_window(b->conn, output->window); |
| 898 | free(output); |
| 899 | return NULL; |
| 900 | } |
| 901 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 902 | xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 903 | b->atom.wm_class, b->atom.string, 8, |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 904 | sizeof class, class); |
| 905 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 906 | x11_output_set_icon(b, output, DATADIR "/weston/wayland.png"); |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 907 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 908 | x11_output_set_wm_protocols(b, output); |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 909 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 910 | xcb_map_window(b->conn, output->window); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 911 | |
Kristian Høgsberg | 7cc3d84 | 2013-02-19 21:19:04 -0500 | [diff] [blame] | 912 | if (fullscreen) |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 913 | x11_output_wait_for_map(b, output); |
Kristian Høgsberg | 83eeacb | 2011-06-18 04:20:54 -0400 | [diff] [blame] | 914 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 915 | output->base.start_repaint_loop = x11_output_start_repaint_loop; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 916 | if (b->use_pixman) |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 917 | output->base.repaint = x11_output_repaint_shm; |
| 918 | else |
| 919 | output->base.repaint = x11_output_repaint_gl; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 920 | output->base.destroy = x11_output_destroy; |
Jesse Barnes | 5308a5e | 2012-02-09 13:12:57 -0800 | [diff] [blame] | 921 | output->base.assign_planes = NULL; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 922 | output->base.set_backlight = NULL; |
| 923 | output->base.set_dpms = NULL; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 924 | output->base.switch_mode = NULL; |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 925 | output->base.current_mode = &output->mode; |
Jason Ekstrand | 22e16b6 | 2014-09-15 12:10:27 -0700 | [diff] [blame] | 926 | output->base.make = "weston-X11"; |
Kristian Høgsberg | d6f09a7 | 2012-11-09 11:12:21 -0500 | [diff] [blame] | 927 | output->base.model = "none"; |
Ander Conselvan de Oliveira | d4ea71e | 2013-12-18 19:51:40 +0200 | [diff] [blame] | 928 | |
| 929 | if (configured_name) |
| 930 | output->base.name = strdup(configured_name); |
| 931 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 932 | width_mm = width * b->screen->width_in_millimeters / |
| 933 | b->screen->width_in_pixels; |
| 934 | height_mm = height * b->screen->height_in_millimeters / |
| 935 | b->screen->height_in_pixels; |
| 936 | weston_output_init(&output->base, b->compositor, |
Kristian Høgsberg | 8404acb | 2014-03-18 12:15:42 -0700 | [diff] [blame] | 937 | x, y, width_mm, height_mm, transform, scale); |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 938 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 939 | if (b->use_pixman) { |
| 940 | if (x11_output_init_shm(b, output, |
Kristian Høgsberg | b5a4f98 | 2013-10-23 23:38:50 -0700 | [diff] [blame] | 941 | output->mode.width, |
Bryce Harrington | 665b025 | 2015-05-26 18:14:21 -0700 | [diff] [blame] | 942 | output->mode.height) < 0) { |
| 943 | weston_log("Failed to initialize SHM for the X11 output\n"); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 944 | return NULL; |
Bryce Harrington | 665b025 | 2015-05-26 18:14:21 -0700 | [diff] [blame] | 945 | } |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 946 | if (pixman_renderer_output_create(&output->base) < 0) { |
Bryce Harrington | 665b025 | 2015-05-26 18:14:21 -0700 | [diff] [blame] | 947 | weston_log("Failed to create pixman renderer for output\n"); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 948 | x11_output_deinit_shm(b, output); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 949 | return NULL; |
| 950 | } |
| 951 | } else { |
Jonny Lamb | 671148f | 2015-03-20 15:26:52 +0100 | [diff] [blame] | 952 | /* eglCreatePlatformWindowSurfaceEXT takes a Window* |
| 953 | * but eglCreateWindowSurface takes a Window. */ |
| 954 | Window xid = (Window) output->window; |
| 955 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 956 | ret = gl_renderer->output_create(&output->base, |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 957 | (EGLNativeWindowType) output->window, |
Jonny Lamb | 671148f | 2015-03-20 15:26:52 +0100 | [diff] [blame] | 958 | &xid, |
Neil Roberts | 77c1a5b | 2014-03-07 18:05:50 +0000 | [diff] [blame] | 959 | gl_renderer->opaque_attribs, |
Derek Foreman | e76f185 | 2015-05-15 12:12:39 -0500 | [diff] [blame] | 960 | NULL, |
| 961 | 0); |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 962 | if (ret < 0) |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 963 | return NULL; |
| 964 | } |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 965 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 966 | loop = wl_display_get_event_loop(b->compositor->wl_display); |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 967 | output->finish_frame_timer = |
| 968 | wl_event_loop_add_timer(loop, finish_frame_handler, output); |
| 969 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 970 | weston_compositor_add_output(b->compositor, &output->base); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 971 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 972 | weston_log("x11 output %dx%d, window id %d\n", |
| 973 | width, height, output->window); |
| 974 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 975 | return output; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 976 | } |
| 977 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 978 | static struct x11_output * |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 979 | x11_backend_find_output(struct x11_backend *b, xcb_window_t window) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 980 | { |
| 981 | struct x11_output *output; |
| 982 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 983 | wl_list_for_each(output, &b->compositor->output_list, base.link) { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 984 | if (output->window == window) |
| 985 | return output; |
| 986 | } |
| 987 | |
Derek Foreman | 99bfa64 | 2014-12-11 15:44:46 -0600 | [diff] [blame] | 988 | return NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 989 | } |
| 990 | |
Ander Conselvan de Oliveira | f54fa4d | 2013-12-13 22:10:49 +0200 | [diff] [blame] | 991 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 992 | x11_backend_delete_window(struct x11_backend *b, xcb_window_t window) |
Ander Conselvan de Oliveira | f54fa4d | 2013-12-13 22:10:49 +0200 | [diff] [blame] | 993 | { |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 994 | struct x11_output *output; |
Ander Conselvan de Oliveira | f54fa4d | 2013-12-13 22:10:49 +0200 | [diff] [blame] | 995 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 996 | output = x11_backend_find_output(b, window); |
Derek Foreman | 99bfa64 | 2014-12-11 15:44:46 -0600 | [diff] [blame] | 997 | if (output) |
| 998 | x11_output_destroy(&output->base); |
Ander Conselvan de Oliveira | f54fa4d | 2013-12-13 22:10:49 +0200 | [diff] [blame] | 999 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1000 | if (wl_list_empty(&b->compositor->output_list)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 1001 | weston_compositor_exit(b->compositor); |
Ander Conselvan de Oliveira | f54fa4d | 2013-12-13 22:10:49 +0200 | [diff] [blame] | 1002 | } |
| 1003 | |
Derek Foreman | d540f4b | 2015-01-27 16:26:49 -0600 | [diff] [blame] | 1004 | static void delete_cb(void *data) |
| 1005 | { |
| 1006 | struct window_delete_data *wd = data; |
| 1007 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1008 | x11_backend_delete_window(wd->backend, wd->window); |
Derek Foreman | d540f4b | 2015-01-27 16:26:49 -0600 | [diff] [blame] | 1009 | free(wd); |
| 1010 | } |
| 1011 | |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 1012 | #ifdef HAVE_XCB_XKB |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 1013 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1014 | update_xkb_state(struct x11_backend *b, xcb_xkb_state_notify_event_t *state) |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 1015 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1016 | struct weston_keyboard *keyboard = |
| 1017 | weston_seat_get_keyboard(&b->core_seat); |
| 1018 | |
| 1019 | xkb_state_update_mask(keyboard->xkb_state.state, |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1020 | get_xkb_mod_mask(b, state->baseMods), |
| 1021 | get_xkb_mod_mask(b, state->latchedMods), |
| 1022 | get_xkb_mod_mask(b, state->lockedMods), |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 1023 | 0, |
| 1024 | 0, |
| 1025 | state->group); |
| 1026 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1027 | notify_modifiers(&b->core_seat, |
| 1028 | wl_display_next_serial(b->compositor->wl_display)); |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 1029 | } |
| 1030 | #endif |
| 1031 | |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 1032 | /** |
| 1033 | * This is monumentally unpleasant. If we don't have XCB-XKB bindings, |
| 1034 | * the best we can do (given that XCB also lacks XI2 support), is to take |
| 1035 | * the state from the core key events. Unfortunately that only gives us |
| 1036 | * the effective (i.e. union of depressed/latched/locked) state, and we |
| 1037 | * need the granularity. |
| 1038 | * |
| 1039 | * So we still update the state with every key event we see, but also use |
| 1040 | * the state field from X11 events as a mask so we don't get any stuck |
| 1041 | * modifiers. |
| 1042 | */ |
| 1043 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1044 | update_xkb_state_from_core(struct x11_backend *b, uint16_t x11_mask) |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 1045 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1046 | uint32_t mask = get_xkb_mod_mask(b, x11_mask); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1047 | struct weston_keyboard *keyboard |
| 1048 | = weston_seat_get_keyboard(&b->core_seat); |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 1049 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1050 | xkb_state_update_mask(keyboard->xkb_state.state, |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 1051 | keyboard->modifiers.mods_depressed & mask, |
| 1052 | keyboard->modifiers.mods_latched & mask, |
| 1053 | keyboard->modifiers.mods_locked & mask, |
| 1054 | 0, |
| 1055 | 0, |
| 1056 | (x11_mask >> 13) & 3); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1057 | notify_modifiers(&b->core_seat, |
| 1058 | wl_display_next_serial(b->compositor->wl_display)); |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 1059 | } |
| 1060 | |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 1061 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1062 | x11_backend_deliver_button_event(struct x11_backend *b, |
| 1063 | xcb_generic_event_t *event, int state) |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 1064 | { |
| 1065 | xcb_button_press_event_t *button_event = |
| 1066 | (xcb_button_press_event_t *) event; |
Daniel Stone | 5d66371 | 2012-05-04 11:21:55 +0100 | [diff] [blame] | 1067 | uint32_t button; |
Kristian Høgsberg | 7330862 | 2012-10-30 11:04:52 -0400 | [diff] [blame] | 1068 | struct x11_output *output; |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1069 | struct weston_pointer_axis_event weston_event; |
Kristian Høgsberg | 7330862 | 2012-10-30 11:04:52 -0400 | [diff] [blame] | 1070 | |
Benoit Gschwind | 4ddc4cc | 2016-05-18 21:32:11 +0200 | [diff] [blame^] | 1071 | assert(event->response_type == XCB_BUTTON_PRESS || |
| 1072 | event->response_type == XCB_BUTTON_RELEASE); |
| 1073 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1074 | output = x11_backend_find_output(b, button_event->event); |
Derek Foreman | 99bfa64 | 2014-12-11 15:44:46 -0600 | [diff] [blame] | 1075 | if (!output) |
| 1076 | return; |
Kristian Høgsberg | 7330862 | 2012-10-30 11:04:52 -0400 | [diff] [blame] | 1077 | |
| 1078 | if (state) |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1079 | xcb_grab_pointer(b->conn, 0, output->window, |
Kristian Høgsberg | 7330862 | 2012-10-30 11:04:52 -0400 | [diff] [blame] | 1080 | XCB_EVENT_MASK_BUTTON_PRESS | |
| 1081 | XCB_EVENT_MASK_BUTTON_RELEASE | |
| 1082 | XCB_EVENT_MASK_POINTER_MOTION | |
| 1083 | XCB_EVENT_MASK_ENTER_WINDOW | |
| 1084 | XCB_EVENT_MASK_LEAVE_WINDOW, |
| 1085 | XCB_GRAB_MODE_ASYNC, |
| 1086 | XCB_GRAB_MODE_ASYNC, |
| 1087 | output->window, XCB_CURSOR_NONE, |
| 1088 | button_event->time); |
| 1089 | else |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1090 | xcb_ungrab_pointer(b->conn, button_event->time); |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 1091 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1092 | if (!b->has_xkb) |
| 1093 | update_xkb_state_from_core(b, button_event->state); |
Daniel Stone | 154c34c | 2012-06-22 13:21:40 +0100 | [diff] [blame] | 1094 | |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 1095 | switch (button_event->detail) { |
Dima Ryazanov | 3e4d4bd | 2015-02-04 01:51:57 -0800 | [diff] [blame] | 1096 | case 1: |
| 1097 | button = BTN_LEFT; |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 1098 | break; |
| 1099 | case 2: |
| 1100 | button = BTN_MIDDLE; |
| 1101 | break; |
| 1102 | case 3: |
| 1103 | button = BTN_RIGHT; |
| 1104 | break; |
| 1105 | case 4: |
Jonas Ådahl | 62efe20 | 2012-09-27 18:40:41 +0200 | [diff] [blame] | 1106 | /* Axis are measured in pixels, but the xcb events are discrete |
| 1107 | * steps. Therefore move the axis by some pixels every step. */ |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1108 | if (state) { |
| 1109 | weston_event.value = -DEFAULT_AXIS_STEP_DISTANCE; |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1110 | weston_event.discrete = -1; |
| 1111 | weston_event.has_discrete = true; |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1112 | weston_event.axis = |
| 1113 | WL_POINTER_AXIS_VERTICAL_SCROLL; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1114 | notify_axis(&b->core_seat, |
Jonas Ådahl | 62efe20 | 2012-09-27 18:40:41 +0200 | [diff] [blame] | 1115 | weston_compositor_get_time(), |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1116 | &weston_event); |
Marek Chalupa | 345b4f5 | 2016-02-03 14:03:00 +0100 | [diff] [blame] | 1117 | notify_pointer_frame(&b->core_seat); |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1118 | } |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 1119 | return; |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 1120 | case 5: |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1121 | if (state) { |
| 1122 | weston_event.value = DEFAULT_AXIS_STEP_DISTANCE; |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1123 | weston_event.discrete = 1; |
| 1124 | weston_event.has_discrete = true; |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1125 | weston_event.axis = |
| 1126 | WL_POINTER_AXIS_VERTICAL_SCROLL; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1127 | notify_axis(&b->core_seat, |
Jonas Ådahl | 62efe20 | 2012-09-27 18:40:41 +0200 | [diff] [blame] | 1128 | weston_compositor_get_time(), |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1129 | &weston_event); |
Marek Chalupa | 345b4f5 | 2016-02-03 14:03:00 +0100 | [diff] [blame] | 1130 | notify_pointer_frame(&b->core_seat); |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1131 | } |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 1132 | return; |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 1133 | case 6: |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1134 | if (state) { |
| 1135 | weston_event.value = -DEFAULT_AXIS_STEP_DISTANCE; |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1136 | weston_event.discrete = -1; |
| 1137 | weston_event.has_discrete = true; |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1138 | weston_event.axis = |
| 1139 | WL_POINTER_AXIS_HORIZONTAL_SCROLL; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1140 | notify_axis(&b->core_seat, |
Jonas Ådahl | 62efe20 | 2012-09-27 18:40:41 +0200 | [diff] [blame] | 1141 | weston_compositor_get_time(), |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1142 | &weston_event); |
Marek Chalupa | 345b4f5 | 2016-02-03 14:03:00 +0100 | [diff] [blame] | 1143 | notify_pointer_frame(&b->core_seat); |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1144 | } |
Scott Moreau | 210d079 | 2012-03-22 10:47:01 -0600 | [diff] [blame] | 1145 | return; |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 1146 | case 7: |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1147 | if (state) { |
| 1148 | weston_event.value = DEFAULT_AXIS_STEP_DISTANCE; |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1149 | weston_event.discrete = 1; |
| 1150 | weston_event.has_discrete = true; |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1151 | weston_event.axis = |
| 1152 | WL_POINTER_AXIS_HORIZONTAL_SCROLL; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1153 | notify_axis(&b->core_seat, |
Jonas Ådahl | 62efe20 | 2012-09-27 18:40:41 +0200 | [diff] [blame] | 1154 | weston_compositor_get_time(), |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1155 | &weston_event); |
Marek Chalupa | 345b4f5 | 2016-02-03 14:03:00 +0100 | [diff] [blame] | 1156 | notify_pointer_frame(&b->core_seat); |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1157 | } |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 1158 | return; |
Dima Ryazanov | 3e4d4bd | 2015-02-04 01:51:57 -0800 | [diff] [blame] | 1159 | default: |
| 1160 | button = button_event->detail + BTN_SIDE - 8; |
| 1161 | break; |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 1162 | } |
| 1163 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1164 | notify_button(&b->core_seat, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1165 | weston_compositor_get_time(), button, |
| 1166 | state ? WL_POINTER_BUTTON_STATE_PRESSED : |
| 1167 | WL_POINTER_BUTTON_STATE_RELEASED); |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1168 | notify_pointer_frame(&b->core_seat); |
Tiago Vignatti | a3a7162 | 2011-12-08 17:03:17 +0200 | [diff] [blame] | 1169 | } |
| 1170 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1171 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1172 | x11_backend_deliver_motion_event(struct x11_backend *b, |
| 1173 | xcb_generic_event_t *event) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1174 | { |
| 1175 | struct x11_output *output; |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1176 | double x, y; |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1177 | struct weston_pointer_motion_event motion_event = { 0 }; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1178 | xcb_motion_notify_event_t *motion_notify = |
| 1179 | (xcb_motion_notify_event_t *) event; |
| 1180 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1181 | if (!b->has_xkb) |
| 1182 | update_xkb_state_from_core(b, motion_notify->state); |
| 1183 | output = x11_backend_find_output(b, motion_notify->event); |
Derek Foreman | 99bfa64 | 2014-12-11 15:44:46 -0600 | [diff] [blame] | 1184 | if (!output) |
| 1185 | return; |
| 1186 | |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 1187 | weston_output_transform_coordinate(&output->base, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1188 | motion_notify->event_x, |
| 1189 | motion_notify->event_y, |
Jason Ekstrand | b6a3cc7 | 2013-10-27 22:25:00 -0500 | [diff] [blame] | 1190 | &x, &y); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1191 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1192 | motion_event = (struct weston_pointer_motion_event) { |
| 1193 | .mask = WESTON_POINTER_MOTION_REL, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1194 | .dx = x - b->prev_x, |
| 1195 | .dy = y - b->prev_y |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1196 | }; |
| 1197 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1198 | notify_motion(&b->core_seat, weston_compositor_get_time(), |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1199 | &motion_event); |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1200 | notify_pointer_frame(&b->core_seat); |
Kristian Høgsberg | 5006596 | 2013-03-27 15:14:07 -0400 | [diff] [blame] | 1201 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1202 | b->prev_x = x; |
| 1203 | b->prev_y = y; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1207 | x11_backend_deliver_enter_event(struct x11_backend *b, |
| 1208 | xcb_generic_event_t *event) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1209 | { |
| 1210 | struct x11_output *output; |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1211 | double x, y; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1212 | |
| 1213 | xcb_enter_notify_event_t *enter_notify = |
| 1214 | (xcb_enter_notify_event_t *) event; |
| 1215 | if (enter_notify->state >= Button1Mask) |
| 1216 | return; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1217 | if (!b->has_xkb) |
| 1218 | update_xkb_state_from_core(b, enter_notify->state); |
| 1219 | output = x11_backend_find_output(b, enter_notify->event); |
Derek Foreman | 99bfa64 | 2014-12-11 15:44:46 -0600 | [diff] [blame] | 1220 | if (!output) |
| 1221 | return; |
| 1222 | |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 1223 | weston_output_transform_coordinate(&output->base, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1224 | enter_notify->event_x, |
| 1225 | enter_notify->event_y, &x, &y); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1226 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1227 | notify_pointer_focus(&b->core_seat, &output->base, x, y); |
Kristian Høgsberg | 5006596 | 2013-03-27 15:14:07 -0400 | [diff] [blame] | 1228 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1229 | b->prev_x = x; |
| 1230 | b->prev_y = y; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1231 | } |
| 1232 | |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 1233 | static int |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1234 | x11_backend_next_event(struct x11_backend *b, |
| 1235 | xcb_generic_event_t **event, uint32_t mask) |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 1236 | { |
Kristian Høgsberg | 127d0f0 | 2011-04-22 12:18:13 -0400 | [diff] [blame] | 1237 | if (mask & WL_EVENT_READABLE) { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1238 | *event = xcb_poll_for_event(b->conn); |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 1239 | } else { |
Kristian Høgsberg | 82ed042 | 2011-04-25 15:41:59 -0400 | [diff] [blame] | 1240 | #ifdef HAVE_XCB_POLL_FOR_QUEUED_EVENT |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1241 | *event = xcb_poll_for_queued_event(b->conn); |
Kristian Høgsberg | 82ed042 | 2011-04-25 15:41:59 -0400 | [diff] [blame] | 1242 | #else |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1243 | *event = xcb_poll_for_event(b->conn); |
Kristian Høgsberg | 82ed042 | 2011-04-25 15:41:59 -0400 | [diff] [blame] | 1244 | #endif |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | return *event != NULL; |
| 1248 | } |
| 1249 | |
Kristian Høgsberg | 127d0f0 | 2011-04-22 12:18:13 -0400 | [diff] [blame] | 1250 | static int |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1251 | x11_backend_handle_event(int fd, uint32_t mask, void *data) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1252 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1253 | struct x11_backend *b = data; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1254 | struct x11_output *output; |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 1255 | xcb_generic_event_t *event, *prev; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1256 | xcb_client_message_event_t *client_message; |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 1257 | xcb_enter_notify_event_t *enter_notify; |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 1258 | xcb_key_press_event_t *key_press, *key_release; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 1259 | xcb_keymap_notify_event_t *keymap_notify; |
| 1260 | xcb_focus_in_event_t *focus_in; |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1261 | xcb_expose_event_t *expose; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1262 | xcb_atom_t atom; |
Ander Conselvan de Oliveira | f54fa4d | 2013-12-13 22:10:49 +0200 | [diff] [blame] | 1263 | xcb_window_t window; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 1264 | uint32_t *k; |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1265 | uint32_t i, set; |
John Kåre Alsaker | 143a898 | 2012-10-12 12:25:07 +0200 | [diff] [blame] | 1266 | uint8_t response_type; |
Bill Spitzak | b715cec | 2012-06-05 17:08:23 -0400 | [diff] [blame] | 1267 | int count; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1268 | |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 1269 | prev = NULL; |
Bill Spitzak | b715cec | 2012-06-05 17:08:23 -0400 | [diff] [blame] | 1270 | count = 0; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1271 | while (x11_backend_next_event(b, &event, mask)) { |
John Kåre Alsaker | 143a898 | 2012-10-12 12:25:07 +0200 | [diff] [blame] | 1272 | response_type = event->response_type & ~0x80; |
| 1273 | |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 1274 | switch (prev ? prev->response_type & ~0x80 : 0x80) { |
| 1275 | case XCB_KEY_RELEASE: |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 1276 | /* Suppress key repeat events; this is only used if we |
| 1277 | * don't have XCB XKB support. */ |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 1278 | key_release = (xcb_key_press_event_t *) prev; |
| 1279 | key_press = (xcb_key_press_event_t *) event; |
John Kåre Alsaker | 143a898 | 2012-10-12 12:25:07 +0200 | [diff] [blame] | 1280 | if (response_type == XCB_KEY_PRESS && |
Dima Ryazanov | c224748 | 2011-08-16 17:25:32 -0700 | [diff] [blame] | 1281 | key_release->time == key_press->time && |
| 1282 | key_release->detail == key_press->detail) { |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 1283 | /* Don't deliver the held key release |
| 1284 | * event or the new key press event. */ |
| 1285 | free(event); |
| 1286 | free(prev); |
| 1287 | prev = NULL; |
| 1288 | continue; |
| 1289 | } else { |
| 1290 | /* Deliver the held key release now |
| 1291 | * and fall through and handle the new |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 1292 | * event below. */ |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1293 | update_xkb_state_from_core(b, key_release->state); |
| 1294 | notify_key(&b->core_seat, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1295 | weston_compositor_get_time(), |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 1296 | key_release->detail - 8, |
Daniel Stone | 1b4e11f | 2012-06-22 13:21:37 +0100 | [diff] [blame] | 1297 | WL_KEYBOARD_KEY_STATE_RELEASED, |
| 1298 | STATE_UPDATE_AUTOMATIC); |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 1299 | free(prev); |
| 1300 | prev = NULL; |
| 1301 | break; |
| 1302 | } |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 1303 | |
| 1304 | case XCB_FOCUS_IN: |
John Kåre Alsaker | 143a898 | 2012-10-12 12:25:07 +0200 | [diff] [blame] | 1305 | assert(response_type == XCB_KEYMAP_NOTIFY); |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 1306 | keymap_notify = (xcb_keymap_notify_event_t *) event; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1307 | b->keys.size = 0; |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 1308 | for (i = 0; i < ARRAY_LENGTH(keymap_notify->keys) * 8; i++) { |
| 1309 | set = keymap_notify->keys[i >> 3] & |
| 1310 | (1 << (i & 7)); |
| 1311 | if (set) { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1312 | k = wl_array_add(&b->keys, sizeof *k); |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 1313 | *k = i; |
| 1314 | } |
| 1315 | } |
| 1316 | |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 1317 | /* Unfortunately the state only comes with the enter |
| 1318 | * event, rather than with the focus event. I'm not |
| 1319 | * sure of the exact semantics around it and whether |
| 1320 | * we can ensure that we get both? */ |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1321 | notify_keyboard_focus_in(&b->core_seat, &b->keys, |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 1322 | STATE_UPDATE_AUTOMATIC); |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 1323 | |
| 1324 | free(prev); |
| 1325 | prev = NULL; |
| 1326 | break; |
| 1327 | |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 1328 | default: |
| 1329 | /* No previous event held */ |
| 1330 | break; |
Kristian Høgsberg | 3ddd148 | 2011-04-15 15:48:07 -0400 | [diff] [blame] | 1331 | } |
| 1332 | |
John Kåre Alsaker | 143a898 | 2012-10-12 12:25:07 +0200 | [diff] [blame] | 1333 | switch (response_type) { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1334 | case XCB_KEY_PRESS: |
| 1335 | key_press = (xcb_key_press_event_t *) event; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1336 | if (!b->has_xkb) |
| 1337 | update_xkb_state_from_core(b, key_press->state); |
| 1338 | notify_key(&b->core_seat, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1339 | weston_compositor_get_time(), |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 1340 | key_press->detail - 8, |
Daniel Stone | 1b4e11f | 2012-06-22 13:21:37 +0100 | [diff] [blame] | 1341 | WL_KEYBOARD_KEY_STATE_PRESSED, |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1342 | b->has_xkb ? STATE_UPDATE_NONE : |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 1343 | STATE_UPDATE_AUTOMATIC); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1344 | break; |
| 1345 | case XCB_KEY_RELEASE: |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 1346 | /* If we don't have XKB, we need to use the lame |
| 1347 | * autorepeat detection above. */ |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1348 | if (!b->has_xkb) { |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 1349 | prev = event; |
| 1350 | break; |
| 1351 | } |
| 1352 | key_release = (xcb_key_press_event_t *) event; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1353 | notify_key(&b->core_seat, |
Daniel Stone | 3ee91e1 | 2012-06-22 13:21:36 +0100 | [diff] [blame] | 1354 | weston_compositor_get_time(), |
| 1355 | key_release->detail - 8, |
Daniel Stone | 1b4e11f | 2012-06-22 13:21:37 +0100 | [diff] [blame] | 1356 | WL_KEYBOARD_KEY_STATE_RELEASED, |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 1357 | STATE_UPDATE_NONE); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1358 | break; |
| 1359 | case XCB_BUTTON_PRESS: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1360 | x11_backend_deliver_button_event(b, event, 1); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1361 | break; |
| 1362 | case XCB_BUTTON_RELEASE: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1363 | x11_backend_deliver_button_event(b, event, 0); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1364 | break; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1365 | case XCB_MOTION_NOTIFY: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1366 | x11_backend_deliver_motion_event(b, event); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1367 | break; |
| 1368 | |
| 1369 | case XCB_EXPOSE: |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1370 | expose = (xcb_expose_event_t *) event; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1371 | output = x11_backend_find_output(b, expose->window); |
Derek Foreman | 99bfa64 | 2014-12-11 15:44:46 -0600 | [diff] [blame] | 1372 | if (!output) |
| 1373 | break; |
| 1374 | |
Kristian Høgsberg | a98c2e1 | 2013-12-05 12:30:37 -0800 | [diff] [blame] | 1375 | weston_output_damage(&output->base); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1376 | weston_output_schedule_repaint(&output->base); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1377 | break; |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 1378 | |
| 1379 | case XCB_ENTER_NOTIFY: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1380 | x11_backend_deliver_enter_event(b, event); |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 1381 | break; |
| 1382 | |
| 1383 | case XCB_LEAVE_NOTIFY: |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 1384 | enter_notify = (xcb_enter_notify_event_t *) event; |
Kristian Høgsberg | 2dfe626 | 2011-02-08 11:59:53 -0500 | [diff] [blame] | 1385 | if (enter_notify->state >= Button1Mask) |
| 1386 | break; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1387 | if (!b->has_xkb) |
| 1388 | update_xkb_state_from_core(b, enter_notify->state); |
| 1389 | notify_pointer_focus(&b->core_seat, NULL, 0, 0); |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 1390 | break; |
| 1391 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1392 | case XCB_CLIENT_MESSAGE: |
| 1393 | client_message = (xcb_client_message_event_t *) event; |
| 1394 | atom = client_message->data.data32[0]; |
Ander Conselvan de Oliveira | f54fa4d | 2013-12-13 22:10:49 +0200 | [diff] [blame] | 1395 | window = client_message->window; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1396 | if (atom == b->atom.wm_delete_window) { |
Derek Foreman | d540f4b | 2015-01-27 16:26:49 -0600 | [diff] [blame] | 1397 | struct wl_event_loop *loop; |
| 1398 | struct window_delete_data *data = malloc(sizeof *data); |
| 1399 | |
| 1400 | /* if malloc failed we should at least try to |
| 1401 | * delete the window, even if it may result in |
| 1402 | * a crash. |
| 1403 | */ |
| 1404 | if (!data) { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1405 | x11_backend_delete_window(b, window); |
Derek Foreman | d540f4b | 2015-01-27 16:26:49 -0600 | [diff] [blame] | 1406 | break; |
| 1407 | } |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1408 | data->backend = b; |
Derek Foreman | d540f4b | 2015-01-27 16:26:49 -0600 | [diff] [blame] | 1409 | data->window = window; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1410 | loop = wl_display_get_event_loop(b->compositor->wl_display); |
Derek Foreman | d540f4b | 2015-01-27 16:26:49 -0600 | [diff] [blame] | 1411 | wl_event_loop_add_idle(loop, delete_cb, data); |
| 1412 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1413 | break; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1414 | |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 1415 | case XCB_FOCUS_IN: |
| 1416 | focus_in = (xcb_focus_in_event_t *) event; |
| 1417 | if (focus_in->mode == XCB_NOTIFY_MODE_WHILE_GRABBED) |
| 1418 | break; |
| 1419 | |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 1420 | prev = event; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 1421 | break; |
| 1422 | |
| 1423 | case XCB_FOCUS_OUT: |
| 1424 | focus_in = (xcb_focus_in_event_t *) event; |
Kristian Høgsberg | 42e40ae | 2011-12-19 14:36:50 -0500 | [diff] [blame] | 1425 | if (focus_in->mode == XCB_NOTIFY_MODE_WHILE_GRABBED || |
| 1426 | focus_in->mode == XCB_NOTIFY_MODE_UNGRAB) |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 1427 | break; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1428 | notify_keyboard_focus_out(&b->core_seat); |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 1429 | break; |
| 1430 | |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 1431 | default: |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1432 | break; |
| 1433 | } |
| 1434 | |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 1435 | #ifdef HAVE_XCB_XKB |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1436 | if (b->has_xkb) { |
| 1437 | if (response_type == b->xkb_event_base) { |
Rui Matos | c6c2f8e | 2013-10-10 19:44:20 +0200 | [diff] [blame] | 1438 | xcb_xkb_state_notify_event_t *state = |
| 1439 | (xcb_xkb_state_notify_event_t *) event; |
| 1440 | if (state->xkbType == XCB_XKB_STATE_NOTIFY) |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1441 | update_xkb_state(b, state); |
Rui Matos | c6c2f8e | 2013-10-10 19:44:20 +0200 | [diff] [blame] | 1442 | } else if (response_type == XCB_PROPERTY_NOTIFY) { |
| 1443 | xcb_property_notify_event_t *prop_notify = |
| 1444 | (xcb_property_notify_event_t *) event; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1445 | if (prop_notify->window == b->screen->root && |
| 1446 | prop_notify->atom == b->atom.xkb_names && |
Rui Matos | c6c2f8e | 2013-10-10 19:44:20 +0200 | [diff] [blame] | 1447 | prop_notify->state == XCB_PROPERTY_NEW_VALUE) |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1448 | update_xkb_keymap(b); |
Rui Matos | c6c2f8e | 2013-10-10 19:44:20 +0200 | [diff] [blame] | 1449 | } |
Daniel Stone | e2faa12 | 2012-06-22 13:21:39 +0100 | [diff] [blame] | 1450 | } |
| 1451 | #endif |
| 1452 | |
Bill Spitzak | b715cec | 2012-06-05 17:08:23 -0400 | [diff] [blame] | 1453 | count++; |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 1454 | if (prev != event) |
Kristian Høgsberg | 3ddd148 | 2011-04-15 15:48:07 -0400 | [diff] [blame] | 1455 | free (event); |
| 1456 | } |
| 1457 | |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 1458 | switch (prev ? prev->response_type & ~0x80 : 0x80) { |
| 1459 | case XCB_KEY_RELEASE: |
| 1460 | key_release = (xcb_key_press_event_t *) prev; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1461 | update_xkb_state_from_core(b, key_release->state); |
| 1462 | notify_key(&b->core_seat, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1463 | weston_compositor_get_time(), |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 1464 | key_release->detail - 8, |
Daniel Stone | 1b4e11f | 2012-06-22 13:21:37 +0100 | [diff] [blame] | 1465 | WL_KEYBOARD_KEY_STATE_RELEASED, |
| 1466 | STATE_UPDATE_AUTOMATIC); |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 1467 | free(prev); |
| 1468 | prev = NULL; |
| 1469 | break; |
| 1470 | default: |
| 1471 | break; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 1472 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1473 | |
Bill Spitzak | b715cec | 2012-06-05 17:08:23 -0400 | [diff] [blame] | 1474 | return count; |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 1475 | } |
| 1476 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1477 | #define F(field) offsetof(struct x11_backend, field) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1478 | |
| 1479 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1480 | x11_backend_get_resources(struct x11_backend *b) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1481 | { |
| 1482 | static const struct { const char *name; int offset; } atoms[] = { |
| 1483 | { "WM_PROTOCOLS", F(atom.wm_protocols) }, |
| 1484 | { "WM_NORMAL_HINTS", F(atom.wm_normal_hints) }, |
| 1485 | { "WM_SIZE_HINTS", F(atom.wm_size_hints) }, |
| 1486 | { "WM_DELETE_WINDOW", F(atom.wm_delete_window) }, |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 1487 | { "WM_CLASS", F(atom.wm_class) }, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1488 | { "_NET_WM_NAME", F(atom.net_wm_name) }, |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 1489 | { "_NET_WM_ICON", F(atom.net_wm_icon) }, |
Kristian Høgsberg | 83eeacb | 2011-06-18 04:20:54 -0400 | [diff] [blame] | 1490 | { "_NET_WM_STATE", F(atom.net_wm_state) }, |
| 1491 | { "_NET_WM_STATE_FULLSCREEN", F(atom.net_wm_state_fullscreen) }, |
Kristian Høgsberg | 7cc3d84 | 2013-02-19 21:19:04 -0500 | [diff] [blame] | 1492 | { "_NET_SUPPORTING_WM_CHECK", |
| 1493 | F(atom.net_supporting_wm_check) }, |
| 1494 | { "_NET_SUPPORTED", F(atom.net_supported) }, |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 1495 | { "STRING", F(atom.string) }, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1496 | { "UTF8_STRING", F(atom.utf8_string) }, |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 1497 | { "CARDINAL", F(atom.cardinal) }, |
Daniel Stone | 855028f | 2012-05-01 20:37:10 +0100 | [diff] [blame] | 1498 | { "_XKB_RULES_NAMES", F(atom.xkb_names) }, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1499 | }; |
| 1500 | |
Kristian Høgsberg | 09e2692 | 2011-12-23 13:33:45 -0500 | [diff] [blame] | 1501 | xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)]; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1502 | xcb_intern_atom_reply_t *reply; |
| 1503 | xcb_pixmap_t pixmap; |
| 1504 | xcb_gc_t gc; |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1505 | unsigned int i; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1506 | uint8_t data[] = { 0, 0, 0, 0 }; |
| 1507 | |
Kristian Høgsberg | 09e2692 | 2011-12-23 13:33:45 -0500 | [diff] [blame] | 1508 | for (i = 0; i < ARRAY_LENGTH(atoms); i++) |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1509 | cookies[i] = xcb_intern_atom (b->conn, 0, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1510 | strlen(atoms[i].name), |
| 1511 | atoms[i].name); |
| 1512 | |
Kristian Høgsberg | 09e2692 | 2011-12-23 13:33:45 -0500 | [diff] [blame] | 1513 | for (i = 0; i < ARRAY_LENGTH(atoms); i++) { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1514 | reply = xcb_intern_atom_reply (b->conn, cookies[i], NULL); |
| 1515 | *(xcb_atom_t *) ((char *) b + atoms[i].offset) = reply->atom; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1516 | free(reply); |
| 1517 | } |
| 1518 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1519 | pixmap = xcb_generate_id(b->conn); |
| 1520 | gc = xcb_generate_id(b->conn); |
| 1521 | xcb_create_pixmap(b->conn, 1, pixmap, b->screen->root, 1, 1); |
| 1522 | xcb_create_gc(b->conn, gc, pixmap, 0, NULL); |
| 1523 | xcb_put_image(b->conn, XCB_IMAGE_FORMAT_XY_PIXMAP, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1524 | pixmap, gc, 1, 1, 0, 0, 0, 32, sizeof data, data); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1525 | b->null_cursor = xcb_generate_id(b->conn); |
| 1526 | xcb_create_cursor (b->conn, b->null_cursor, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1527 | pixmap, pixmap, 0, 0, 0, 0, 0, 0, 1, 1); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1528 | xcb_free_gc(b->conn, gc); |
| 1529 | xcb_free_pixmap(b->conn, pixmap); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1530 | } |
| 1531 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1532 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1533 | x11_backend_get_wm_info(struct x11_backend *c) |
Kristian Høgsberg | 7cc3d84 | 2013-02-19 21:19:04 -0500 | [diff] [blame] | 1534 | { |
| 1535 | xcb_get_property_cookie_t cookie; |
| 1536 | xcb_get_property_reply_t *reply; |
| 1537 | xcb_atom_t *atom; |
| 1538 | unsigned int i; |
| 1539 | |
| 1540 | cookie = xcb_get_property(c->conn, 0, c->screen->root, |
| 1541 | c->atom.net_supported, |
| 1542 | XCB_ATOM_ATOM, 0, 1024); |
| 1543 | reply = xcb_get_property_reply(c->conn, cookie, NULL); |
| 1544 | if (reply == NULL) |
| 1545 | return; |
| 1546 | |
| 1547 | atom = (xcb_atom_t *) xcb_get_property_value(reply); |
| 1548 | |
| 1549 | for (i = 0; i < reply->value_len; i++) { |
| 1550 | if (atom[i] == c->atom.net_wm_state_fullscreen) |
| 1551 | c->has_net_wm_state_fullscreen = 1; |
| 1552 | } |
Ryo Munakata | 76fb7ec | 2015-03-08 19:17:06 +0900 | [diff] [blame] | 1553 | |
| 1554 | free(reply); |
Kristian Høgsberg | 7cc3d84 | 2013-02-19 21:19:04 -0500 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | static void |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 1558 | x11_restore(struct weston_compositor *ec) |
| 1559 | { |
| 1560 | } |
| 1561 | |
| 1562 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1563 | x11_destroy(struct weston_compositor *ec) |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1564 | { |
Armin Krezović | 295e9d0 | 2016-08-01 19:17:58 +0200 | [diff] [blame] | 1565 | struct x11_backend *backend = to_x11_backend(ec); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1566 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1567 | wl_event_source_remove(backend->xcb_source); |
| 1568 | x11_input_destroy(backend); |
Pekka Paalanen | 43c61d8 | 2012-01-03 11:58:34 +0200 | [diff] [blame] | 1569 | |
Ander Conselvan de Oliveira | 6b16214 | 2013-10-25 16:26:32 +0300 | [diff] [blame] | 1570 | weston_compositor_shutdown(ec); /* destroys outputs, too */ |
| 1571 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1572 | XCloseDisplay(backend->dpy); |
| 1573 | free(backend); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1574 | } |
| 1575 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 1576 | static int |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1577 | init_gl_renderer(struct x11_backend *b) |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 1578 | { |
| 1579 | int ret; |
| 1580 | |
| 1581 | gl_renderer = weston_load_module("gl-renderer.so", |
| 1582 | "gl_renderer_interface"); |
| 1583 | if (!gl_renderer) |
| 1584 | return -1; |
| 1585 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1586 | ret = gl_renderer->create(b->compositor, EGL_PLATFORM_X11_KHR, (void *) b->dpy, |
Derek Foreman | e76f185 | 2015-05-15 12:12:39 -0500 | [diff] [blame] | 1587 | gl_renderer->opaque_attribs, NULL, 0); |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 1588 | |
| 1589 | return ret; |
| 1590 | } |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1591 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1592 | static struct x11_backend * |
| 1593 | x11_backend_create(struct weston_compositor *compositor, |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1594 | struct weston_x11_backend_config *config) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1595 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1596 | struct x11_backend *b; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1597 | struct x11_output *output; |
Pekka Paalanen | 157109b | 2016-03-24 15:43:44 +0200 | [diff] [blame] | 1598 | struct wl_event_loop *loop; |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1599 | int x = 0; |
| 1600 | unsigned i; |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 1601 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1602 | b = zalloc(sizeof *b); |
| 1603 | if (b == NULL) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1604 | return NULL; |
| 1605 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1606 | b->compositor = compositor; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1607 | if (weston_compositor_set_presentation_clock_software(compositor) < 0) |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 1608 | goto err_free; |
| 1609 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1610 | b->dpy = XOpenDisplay(NULL); |
| 1611 | if (b->dpy == NULL) |
Martin Olsson | 11434bb | 2012-07-08 03:03:44 +0200 | [diff] [blame] | 1612 | goto err_free; |
Cyril Brulebois | 2079829 | 2011-04-06 18:05:40 +0200 | [diff] [blame] | 1613 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1614 | b->conn = XGetXCBConnection(b->dpy); |
| 1615 | XSetEventQueueOwner(b->dpy, XCBOwnsEventQueue); |
Benjamin Franzke | e997c5f | 2011-03-25 14:06:37 +0100 | [diff] [blame] | 1616 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1617 | if (xcb_connection_has_error(b->conn)) |
Martin Olsson | 11434bb | 2012-07-08 03:03:44 +0200 | [diff] [blame] | 1618 | goto err_xdisplay; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1619 | |
Marko | 61b4d3e | 2015-10-05 17:27:54 -0500 | [diff] [blame] | 1620 | b->screen = x11_compositor_get_default_screen(b); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1621 | wl_array_init(&b->keys); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1622 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1623 | x11_backend_get_resources(b); |
| 1624 | x11_backend_get_wm_info(b); |
Kristian Høgsberg | 7cc3d84 | 2013-02-19 21:19:04 -0500 | [diff] [blame] | 1625 | |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1626 | if (!b->has_net_wm_state_fullscreen && config->fullscreen) { |
Kristian Høgsberg | 7cc3d84 | 2013-02-19 21:19:04 -0500 | [diff] [blame] | 1627 | weston_log("Can not fullscreen without window manager support" |
| 1628 | "(need _NET_WM_STATE_FULLSCREEN)\n"); |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1629 | config->fullscreen = 0; |
Kristian Høgsberg | 7cc3d84 | 2013-02-19 21:19:04 -0500 | [diff] [blame] | 1630 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1631 | |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1632 | b->use_pixman = config->use_pixman; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1633 | if (b->use_pixman) { |
| 1634 | if (pixman_renderer_init(compositor) < 0) { |
Bryce Harrington | 665b025 | 2015-05-26 18:14:21 -0700 | [diff] [blame] | 1635 | weston_log("Failed to initialize pixman renderer for X11 backend\n"); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 1636 | goto err_xdisplay; |
Bryce Harrington | 665b025 | 2015-05-26 18:14:21 -0700 | [diff] [blame] | 1637 | } |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 1638 | } |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1639 | else if (init_gl_renderer(b) < 0) { |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 1640 | goto err_xdisplay; |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 1641 | } |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1642 | weston_log("Using %s renderer\n", config->use_pixman ? "pixman" : "gl"); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1643 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1644 | b->base.destroy = x11_destroy; |
| 1645 | b->base.restore = x11_restore; |
Kristian Høgsberg | 8525a50 | 2011-01-14 16:20:21 -0500 | [diff] [blame] | 1646 | |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1647 | if (x11_input_create(b, config->no_input) < 0) { |
Bryce Harrington | 665b025 | 2015-05-26 18:14:21 -0700 | [diff] [blame] | 1648 | weston_log("Failed to create X11 input\n"); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 1649 | goto err_renderer; |
Bryce Harrington | 665b025 | 2015-05-26 18:14:21 -0700 | [diff] [blame] | 1650 | } |
Daniel Stone | 22815f9 | 2012-06-22 13:21:34 +0100 | [diff] [blame] | 1651 | |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1652 | for (i = 0; i < config->num_outputs; ++i) { |
| 1653 | struct weston_x11_backend_output_config *output_iterator = |
| 1654 | &config->outputs[i]; |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame] | 1655 | |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1656 | if (output_iterator->name == NULL) { |
Kristian Høgsberg | 8f6fcbf | 2013-05-26 21:21:23 -0400 | [diff] [blame] | 1657 | continue; |
Rob Bradford | 5c4245d | 2013-07-26 16:29:44 +0100 | [diff] [blame] | 1658 | } |
Kristian Høgsberg | 8f6fcbf | 2013-05-26 21:21:23 -0400 | [diff] [blame] | 1659 | |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1660 | if (output_iterator->width < 1) { |
| 1661 | weston_log("Invalid width \"%d\" for output %s\n", |
| 1662 | output_iterator->width, output_iterator->name); |
| 1663 | goto err_x11_input; |
Kristian Høgsberg | 8f6fcbf | 2013-05-26 21:21:23 -0400 | [diff] [blame] | 1664 | } |
Kristian Høgsberg | 8f6fcbf | 2013-05-26 21:21:23 -0400 | [diff] [blame] | 1665 | |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1666 | if (output_iterator->height < 1) { |
| 1667 | weston_log("Invalid height \"%d\" for output %s\n", |
| 1668 | output_iterator->height, output_iterator->name); |
| 1669 | goto err_x11_input; |
| 1670 | } |
Kristian Høgsberg | 8f6fcbf | 2013-05-26 21:21:23 -0400 | [diff] [blame] | 1671 | |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1672 | output = x11_backend_create_output(b, |
| 1673 | x, |
| 1674 | 0, |
| 1675 | output_iterator->width, |
| 1676 | output_iterator->height, |
| 1677 | config->fullscreen, |
| 1678 | config->no_input, |
| 1679 | output_iterator->name, |
| 1680 | output_iterator->transform, |
| 1681 | output_iterator->scale); |
Bryce Harrington | 665b025 | 2015-05-26 18:14:21 -0700 | [diff] [blame] | 1682 | if (output == NULL) { |
| 1683 | weston_log("Failed to create configured x11 output\n"); |
Scott Moreau | 248aaec | 2012-08-03 14:19:52 -0600 | [diff] [blame] | 1684 | goto err_x11_input; |
Bryce Harrington | 665b025 | 2015-05-26 18:14:21 -0700 | [diff] [blame] | 1685 | } |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1686 | |
| 1687 | x = pixman_region32_extents(&output->base.region)->x2; |
Kristian Høgsberg | 1ccd9d2 | 2011-07-21 10:22:13 -0700 | [diff] [blame] | 1688 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1689 | |
Pekka Paalanen | 157109b | 2016-03-24 15:43:44 +0200 | [diff] [blame] | 1690 | loop = wl_display_get_event_loop(compositor->wl_display); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1691 | b->xcb_source = |
Pekka Paalanen | 157109b | 2016-03-24 15:43:44 +0200 | [diff] [blame] | 1692 | wl_event_loop_add_fd(loop, |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1693 | xcb_get_file_descriptor(b->conn), |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1694 | WL_EVENT_READABLE, |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1695 | x11_backend_handle_event, b); |
| 1696 | wl_event_source_check(b->xcb_source); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1697 | |
Pekka Paalanen | 5ffb440 | 2014-06-12 16:52:53 +0300 | [diff] [blame] | 1698 | if (compositor->renderer->import_dmabuf) { |
| 1699 | if (linux_dmabuf_setup(compositor) < 0) |
| 1700 | weston_log("Error: initializing dmabuf " |
| 1701 | "support failed.\n"); |
| 1702 | } |
| 1703 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1704 | compositor->backend = &b->base; |
Pekka Paalanen | 5ffb440 | 2014-06-12 16:52:53 +0300 | [diff] [blame] | 1705 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1706 | return b; |
Martin Olsson | 11434bb | 2012-07-08 03:03:44 +0200 | [diff] [blame] | 1707 | |
| 1708 | err_x11_input: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1709 | x11_input_destroy(b); |
Vasily Khoruzhick | b3add19 | 2013-01-07 20:39:50 +0300 | [diff] [blame] | 1710 | err_renderer: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1711 | compositor->renderer->destroy(compositor); |
Martin Olsson | 11434bb | 2012-07-08 03:03:44 +0200 | [diff] [blame] | 1712 | err_xdisplay: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1713 | XCloseDisplay(b->dpy); |
Martin Olsson | 11434bb | 2012-07-08 03:03:44 +0200 | [diff] [blame] | 1714 | err_free: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1715 | free(b); |
Martin Olsson | 11434bb | 2012-07-08 03:03:44 +0200 | [diff] [blame] | 1716 | return NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1717 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1718 | |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1719 | static void |
| 1720 | config_init_to_defaults(struct weston_x11_backend_config *config) |
| 1721 | { |
| 1722 | } |
| 1723 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1724 | WL_EXPORT int |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1725 | backend_init(struct weston_compositor *compositor, |
Giulio Camuffo | 93daabb | 2015-10-17 19:24:14 +0300 | [diff] [blame] | 1726 | struct weston_backend_config *config_base) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1727 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1728 | struct x11_backend *b; |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1729 | struct weston_x11_backend_config config = {{ 0, }}; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1730 | |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1731 | if (config_base == NULL || |
| 1732 | config_base->struct_version != WESTON_X11_BACKEND_CONFIG_VERSION || |
| 1733 | config_base->struct_size > sizeof(struct weston_x11_backend_config)) { |
| 1734 | weston_log("X11 backend config structure is invalid\n"); |
| 1735 | return -1; |
| 1736 | } |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 1737 | |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1738 | config_init_to_defaults(&config); |
| 1739 | memcpy(&config, config_base, config_base->struct_size); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1740 | |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1741 | b = x11_backend_create(compositor, &config); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1742 | if (b == NULL) |
| 1743 | return -1; |
Benoit Gschwind | e16acab | 2016-04-15 20:28:31 -0700 | [diff] [blame] | 1744 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1745 | return 0; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1746 | } |