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