2010-06-14 19:54:00 +04:00
|
|
|
/*
|
Change remaining GPLv2 headers to MIT
The files in question are copyright Benjamin Franzke (who agrees),
Intel Corporation, Red Hat and myself. On behalf of Red Hat,
Richard Fontana says:
"Therefore, to the extent that Red Hat, Inc. has any copyright
interest in the files you cited as of this date (compositor-drm.c,
compositor.c, compositor.h, screenshooter.c in
http://cgit.freedesktop.org/wayland/wayland-demos/tree/compositor),
Red Hat hereby elects to apply the CC0 1.0 Universal Public Domain
Dedication to such copyrighted material. See:
http://creativecommons.org/publicdomain/zero/1.0/legalcode .
Thanks,
Richard E. Fontana
Open Source Licensing and Patent Counsel
Red Hat, Inc."
2011-09-15 23:43:14 +04:00
|
|
|
* Copyright © 2008-2011 Kristian Høgsberg
|
|
|
|
* Copyright © 2010-2011 Intel Corporation
|
2013-01-07 21:39:50 +04:00
|
|
|
* Copyright © 2013 Vasily Khoruzhick <anarsoul@gmail.com>
|
2010-06-14 19:54:00 +04:00
|
|
|
*
|
2015-06-12 01:35:43 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
2010-06-14 19:54:00 +04:00
|
|
|
*
|
2015-06-12 01:35:43 +03:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-06-14 19:54:00 +04:00
|
|
|
*/
|
|
|
|
|
2013-05-22 19:03:19 +04:00
|
|
|
#include "config.h"
|
2010-10-29 11:20:18 +04:00
|
|
|
|
2012-10-12 14:25:07 +04:00
|
|
|
#include <assert.h>
|
2010-06-14 19:54:00 +04:00
|
|
|
#include <stddef.h>
|
2016-07-19 14:16:27 +03:00
|
|
|
#include <stdint.h>
|
2010-06-14 19:54:00 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/time.h>
|
2013-01-07 21:39:50 +04:00
|
|
|
#include <sys/shm.h>
|
2010-06-14 20:53:43 +04:00
|
|
|
#include <linux/input.h>
|
2010-06-14 19:54:00 +04:00
|
|
|
|
|
|
|
#include <xcb/xcb.h>
|
2013-01-07 21:39:50 +04:00
|
|
|
#include <xcb/shm.h>
|
2012-06-22 16:21:35 +04:00
|
|
|
#ifdef HAVE_XCB_XKB
|
|
|
|
#include <xcb/xkb.h>
|
|
|
|
#endif
|
|
|
|
|
2011-02-20 21:58:42 +03:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xlib-xcb.h>
|
|
|
|
|
2012-06-01 15:14:02 +04:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
|
|
|
|
2019-03-28 17:28:47 +03:00
|
|
|
#include <libweston/libweston.h>
|
2019-03-29 17:39:12 +03:00
|
|
|
#include <libweston/backend-x11.h>
|
2015-06-16 01:37:08 +03:00
|
|
|
#include "shared/helpers.h"
|
2015-06-16 01:37:07 +03:00
|
|
|
#include "shared/image-loader.h"
|
2017-11-24 19:01:46 +03:00
|
|
|
#include "shared/timespec-util.h"
|
2018-02-07 00:18:38 +03:00
|
|
|
#include "shared/file-util.h"
|
2019-04-04 17:29:27 +03:00
|
|
|
#include "renderer-gl/gl-renderer.h"
|
2021-02-04 18:39:45 +03:00
|
|
|
#include "shared/weston-drm-fourcc.h"
|
2019-04-05 16:09:45 +03:00
|
|
|
#include "shared/weston-egl-ext.h"
|
2016-04-16 06:28:31 +03:00
|
|
|
#include "pixman-renderer.h"
|
2016-02-18 17:53:27 +03:00
|
|
|
#include "presentation-time-server-protocol.h"
|
2014-06-12 17:52:53 +04:00
|
|
|
#include "linux-dmabuf.h"
|
libweston: Support zwp_surface_synchronization_v1.set_acquire_fence
Implement the set_acquire_fence request of the
zwp_surface_synchronization_v1 interface.
The implementation uses the acquire fence in two ways:
1. If the associated buffer is used as GL render source, an
EGLSyncKHR is created from the fence and used to synchronize
access.
2. If the associated buffer is used as a plane framebuffer,
the acquire fence is treated as an in-fence for the atomic
commit operation. If in-fences are not supported and the buffer
has an acquire fence, we don't consider it for plane placement.
If the used compositor/renderer doesn't support explicit
synchronization, we don't advertise the protocol at all. Currently only
the DRM and X11 backends when using the GL renderer advertise the
protocol for production use.
Issues for discussion
---------------------
a. Currently, a server-side wait of EGLSyncKHR is performed before
using the EGLImage/texture during rendering. Unfortunately, it's not clear
from the specs whether this is generally safe to do, or we need to
sync before glEGLImageTargetTexture2DOES. The exception is
TEXTURE_EXTERNAL_OES where the spec mentions it's enough to sync
and then glBindTexture for any changes to take effect.
Changes in v5:
- Meson support.
- Make explicit sync server error reporting more generic, supporting
all explicit sync related interfaces not just
wp_linux_surface_synchronization.
- Fix typo in warning for missing EGL_KHR_wait_sync extension.
- Support minor version 2 of the explicit sync protocol (i.e., support
fences for opaque EGL buffers).
Changes in v4:
- Introduce and use fd_clear and and fd_move helpers.
- Don't check for a valid buffer when updating surface acquire fence fd
from state.
- Assert that pending state acquire fence fd is always clear
after a commit.
- Clarify that WESTON_CAP_EXPLICIT_SYNC applies to just the
renderer.
- Check for EGL_KHR_wait_sync before using eglWaitSyncKHR.
- Dup the acquire fence before passing to EGL.
Changes in v3:
- Keep acquire_fence_fd in surface instead of buffer.
- Clarify that WESTON_CAP_EXPLICIT_SYNC applies to both backend and
renderer.
- Move comment about non-ownership of in_fence_fd to struct
drm_plane_state definition.
- Assert that we don't try to use planes with in-fences when using the
legacy KMS API.
- Remove unnecessary info from wayland error messages.
- Handle acquire fence for subsurface commits.
- Guard against self-update in fd_update.
- Disconnect the client if acquire fence EGLSyncKHR creation or wait
fails.
- Use updated protocol interface names.
- User correct format specifier for resource ids.
- Advertise protocol for X11 backend with GL renderer.
Changes in v2:
- Remove sync file wait fallbacks.
- Raise UNSUPPORTED_BUFFER error at commit if we have an acquire
fence, but the committed buffer is not a valid linux_dmabuf.
- Don't put buffers with in-fences on planes that don't support
in-fences.
- Don't advertise explicit sync protocol if backend does not
support explicit sync.
Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
2018-10-19 12:14:11 +03:00
|
|
|
#include "linux-explicit-synchronization.h"
|
2019-03-29 18:14:29 +03:00
|
|
|
#include <libweston/windowed-output-api.h>
|
2010-06-14 19:54:00 +04:00
|
|
|
|
2016-03-22 18:44:54 +03:00
|
|
|
#define DEFAULT_AXIS_STEP_DISTANCE 10
|
2012-09-27 20:40:41 +04:00
|
|
|
|
2016-10-29 01:26:46 +03:00
|
|
|
#define WINDOW_MIN_WIDTH 128
|
|
|
|
#define WINDOW_MIN_HEIGHT 128
|
|
|
|
|
|
|
|
#define WINDOW_MAX_WIDTH 8192
|
|
|
|
#define WINDOW_MAX_HEIGHT 8192
|
|
|
|
|
2019-09-30 15:29:13 +03:00
|
|
|
static const uint32_t x11_formats[] = {
|
|
|
|
DRM_FORMAT_XRGB8888,
|
|
|
|
};
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
struct x11_backend {
|
|
|
|
struct weston_backend base;
|
|
|
|
struct weston_compositor *compositor;
|
2010-06-14 19:54:00 +04:00
|
|
|
|
2011-02-20 21:58:42 +03:00
|
|
|
Display *dpy;
|
2010-06-14 19:54:00 +04:00
|
|
|
xcb_connection_t *conn;
|
|
|
|
xcb_screen_t *screen;
|
|
|
|
xcb_cursor_t null_cursor;
|
2011-01-27 19:57:19 +03:00
|
|
|
struct wl_array keys;
|
2010-06-14 19:54:00 +04:00
|
|
|
struct wl_event_source *xcb_source;
|
2012-06-01 15:14:02 +04:00
|
|
|
struct xkb_keymap *xkb_keymap;
|
2012-06-22 16:21:35 +04:00
|
|
|
unsigned int has_xkb;
|
|
|
|
uint8_t xkb_event_base;
|
2016-09-30 15:11:10 +03:00
|
|
|
int fullscreen;
|
|
|
|
int no_input;
|
2012-08-10 18:04:36 +04:00
|
|
|
|
2013-02-20 06:19:04 +04:00
|
|
|
int has_net_wm_state_fullscreen;
|
|
|
|
|
2012-08-10 18:04:36 +04:00
|
|
|
/* We could map multi-pointer X to multiple wayland seats, but
|
|
|
|
* for now we only support core X input. */
|
2013-02-26 02:04:47 +04:00
|
|
|
struct weston_seat core_seat;
|
2016-03-22 18:44:54 +03:00
|
|
|
double prev_x;
|
|
|
|
double prev_y;
|
2012-08-10 18:04:36 +04:00
|
|
|
|
2010-06-14 19:54:00 +04:00
|
|
|
struct {
|
|
|
|
xcb_atom_t wm_protocols;
|
|
|
|
xcb_atom_t wm_normal_hints;
|
|
|
|
xcb_atom_t wm_size_hints;
|
|
|
|
xcb_atom_t wm_delete_window;
|
2011-01-26 22:02:31 +03:00
|
|
|
xcb_atom_t wm_class;
|
2010-06-14 19:54:00 +04:00
|
|
|
xcb_atom_t net_wm_name;
|
2013-02-20 06:19:04 +04:00
|
|
|
xcb_atom_t net_supporting_wm_check;
|
|
|
|
xcb_atom_t net_supported;
|
2011-01-26 22:37:07 +03:00
|
|
|
xcb_atom_t net_wm_icon;
|
2011-06-18 12:20:54 +04:00
|
|
|
xcb_atom_t net_wm_state;
|
|
|
|
xcb_atom_t net_wm_state_fullscreen;
|
2011-01-26 22:02:31 +03:00
|
|
|
xcb_atom_t string;
|
2010-06-14 19:54:00 +04:00
|
|
|
xcb_atom_t utf8_string;
|
2011-01-26 22:37:07 +03:00
|
|
|
xcb_atom_t cardinal;
|
2012-05-01 23:37:10 +04:00
|
|
|
xcb_atom_t xkb_names;
|
2010-06-14 19:54:00 +04:00
|
|
|
} atom;
|
2022-08-30 20:25:01 +03:00
|
|
|
xcb_generic_event_t *prev_event;
|
2010-06-14 19:54:00 +04:00
|
|
|
};
|
|
|
|
|
2017-10-12 15:58:10 +03:00
|
|
|
struct x11_head {
|
|
|
|
struct weston_head base;
|
|
|
|
};
|
|
|
|
|
2010-06-14 19:54:00 +04:00
|
|
|
struct x11_output {
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 19:29:47 +04:00
|
|
|
struct weston_output base;
|
2010-06-14 19:54:00 +04:00
|
|
|
|
|
|
|
xcb_window_t window;
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 19:29:47 +04:00
|
|
|
struct weston_mode mode;
|
2016-10-29 01:26:46 +03:00
|
|
|
struct weston_mode native;
|
2011-10-29 22:39:13 +04:00
|
|
|
struct wl_event_source *finish_frame_timer;
|
2013-01-07 21:39:50 +04:00
|
|
|
|
|
|
|
xcb_gc_t gc;
|
|
|
|
xcb_shm_seg_t segment;
|
|
|
|
pixman_image_t *hw_surface;
|
|
|
|
int shm_id;
|
|
|
|
void *buf;
|
|
|
|
uint8_t depth;
|
2013-05-24 15:09:43 +04:00
|
|
|
int32_t scale;
|
2016-10-29 01:26:46 +03:00
|
|
|
bool resize_pending;
|
|
|
|
bool window_resized;
|
2010-06-14 19:54:00 +04:00
|
|
|
};
|
|
|
|
|
2015-01-28 01:26:49 +03:00
|
|
|
struct window_delete_data {
|
2014-10-11 19:27:30 +04:00
|
|
|
struct x11_backend *backend;
|
2015-01-28 01:26:49 +03:00
|
|
|
xcb_window_t window;
|
|
|
|
};
|
|
|
|
|
2013-10-14 16:57:11 +04:00
|
|
|
struct gl_renderer_interface *gl_renderer;
|
|
|
|
|
2021-02-16 13:25:47 +03:00
|
|
|
static void
|
2021-03-11 15:26:45 +03:00
|
|
|
x11_destroy(struct weston_compositor *ec);
|
2021-02-16 13:25:47 +03:00
|
|
|
|
2017-10-12 15:58:10 +03:00
|
|
|
static inline struct x11_head *
|
|
|
|
to_x11_head(struct weston_head *base)
|
|
|
|
{
|
2021-03-11 15:26:45 +03:00
|
|
|
if (base->backend->destroy != x11_destroy)
|
2021-02-16 13:25:47 +03:00
|
|
|
return NULL;
|
2017-10-12 15:58:10 +03:00
|
|
|
return container_of(base, struct x11_head, base);
|
|
|
|
}
|
|
|
|
|
2021-02-16 13:25:47 +03:00
|
|
|
static void
|
|
|
|
x11_output_destroy(struct weston_output *base);
|
|
|
|
|
2016-08-01 20:17:58 +03:00
|
|
|
static inline struct x11_output *
|
|
|
|
to_x11_output(struct weston_output *base)
|
|
|
|
{
|
2021-02-16 13:25:47 +03:00
|
|
|
if (base->destroy != x11_output_destroy)
|
|
|
|
return NULL;
|
2016-08-01 20:17:58 +03:00
|
|
|
return container_of(base, struct x11_output, base);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct x11_backend *
|
|
|
|
to_x11_backend(struct weston_compositor *base)
|
|
|
|
{
|
|
|
|
return container_of(base->backend, struct x11_backend, base);
|
|
|
|
}
|
|
|
|
|
2015-10-06 01:27:54 +03:00
|
|
|
static xcb_screen_t *
|
|
|
|
x11_compositor_get_default_screen(struct x11_backend *b)
|
|
|
|
{
|
|
|
|
xcb_screen_iterator_t iter;
|
|
|
|
int i, screen_nbr = XDefaultScreen(b->dpy);
|
|
|
|
|
|
|
|
iter = xcb_setup_roots_iterator(xcb_get_setup(b->conn));
|
|
|
|
for (i = 0; iter.rem; xcb_screen_next(&iter), i++)
|
|
|
|
if (i == screen_nbr)
|
|
|
|
return iter.data;
|
|
|
|
|
|
|
|
return xcb_setup_roots_iterator(xcb_get_setup(b->conn)).data;
|
|
|
|
}
|
|
|
|
|
2012-06-01 15:14:02 +04:00
|
|
|
static struct xkb_keymap *
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_get_keymap(struct x11_backend *b)
|
2012-06-01 15:14:02 +04:00
|
|
|
{
|
|
|
|
xcb_get_property_cookie_t cookie;
|
|
|
|
xcb_get_property_reply_t *reply;
|
|
|
|
struct xkb_rule_names names;
|
|
|
|
struct xkb_keymap *ret;
|
|
|
|
const char *value_all, *value_part;
|
|
|
|
int length_all, length_part;
|
|
|
|
|
|
|
|
memset(&names, 0, sizeof(names));
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
cookie = xcb_get_property(b->conn, 0, b->screen->root,
|
|
|
|
b->atom.xkb_names, b->atom.string, 0, 1024);
|
|
|
|
reply = xcb_get_property_reply(b->conn, cookie, NULL);
|
2012-06-01 15:14:02 +04:00
|
|
|
if (reply == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
value_all = xcb_get_property_value(reply);
|
|
|
|
length_all = xcb_get_property_value_length(reply);
|
|
|
|
value_part = value_all;
|
|
|
|
|
|
|
|
#define copy_prop_value(to) \
|
|
|
|
length_part = strlen(value_part); \
|
|
|
|
if (value_part + length_part < (value_all + length_all) && \
|
|
|
|
length_part > 0) \
|
|
|
|
names.to = value_part; \
|
|
|
|
value_part += length_part + 1;
|
|
|
|
|
|
|
|
copy_prop_value(rules);
|
|
|
|
copy_prop_value(model);
|
|
|
|
copy_prop_value(layout);
|
|
|
|
copy_prop_value(variant);
|
|
|
|
copy_prop_value(options);
|
|
|
|
#undef copy_prop_value
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
ret = xkb_keymap_new_from_names(b->compositor->xkb_context, &names, 0);
|
2012-06-01 15:14:02 +04:00
|
|
|
|
|
|
|
free(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-06-14 19:54:00 +04:00
|
|
|
|
2012-10-29 22:15:40 +04:00
|
|
|
static uint32_t
|
2014-10-11 19:27:30 +04:00
|
|
|
get_xkb_mod_mask(struct x11_backend *b, uint32_t in)
|
2012-10-29 22:15:40 +04:00
|
|
|
{
|
2015-08-01 00:55:32 +03:00
|
|
|
struct weston_keyboard *keyboard =
|
|
|
|
weston_seat_get_keyboard(&b->core_seat);
|
|
|
|
struct weston_xkb_info *info = keyboard->xkb_info;
|
2012-10-29 22:15:40 +04:00
|
|
|
uint32_t ret = 0;
|
|
|
|
|
|
|
|
if ((in & ShiftMask) && info->shift_mod != XKB_MOD_INVALID)
|
|
|
|
ret |= (1 << info->shift_mod);
|
|
|
|
if ((in & LockMask) && info->caps_mod != XKB_MOD_INVALID)
|
|
|
|
ret |= (1 << info->caps_mod);
|
|
|
|
if ((in & ControlMask) && info->ctrl_mod != XKB_MOD_INVALID)
|
|
|
|
ret |= (1 << info->ctrl_mod);
|
|
|
|
if ((in & Mod1Mask) && info->alt_mod != XKB_MOD_INVALID)
|
|
|
|
ret |= (1 << info->alt_mod);
|
|
|
|
if ((in & Mod2Mask) && info->mod2_mod != XKB_MOD_INVALID)
|
|
|
|
ret |= (1 << info->mod2_mod);
|
|
|
|
if ((in & Mod3Mask) && info->mod3_mod != XKB_MOD_INVALID)
|
|
|
|
ret |= (1 << info->mod3_mod);
|
|
|
|
if ((in & Mod4Mask) && info->super_mod != XKB_MOD_INVALID)
|
|
|
|
ret |= (1 << info->super_mod);
|
|
|
|
if ((in & Mod5Mask) && info->mod5_mod != XKB_MOD_INVALID)
|
|
|
|
ret |= (1 << info->mod5_mod);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-22 16:21:35 +04:00
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_setup_xkb(struct x11_backend *b)
|
2012-06-22 16:21:35 +04:00
|
|
|
{
|
|
|
|
#ifndef HAVE_XCB_XKB
|
|
|
|
weston_log("XCB-XKB not available during build\n");
|
2014-10-11 19:27:30 +04:00
|
|
|
b->has_xkb = 0;
|
|
|
|
b->xkb_event_base = 0;
|
2012-06-22 16:21:35 +04:00
|
|
|
return;
|
|
|
|
#else
|
2015-08-01 00:55:32 +03:00
|
|
|
struct weston_keyboard *keyboard;
|
2012-06-22 16:21:35 +04:00
|
|
|
const xcb_query_extension_reply_t *ext;
|
2012-06-22 16:21:36 +04:00
|
|
|
xcb_generic_error_t *error;
|
2012-06-22 16:21:39 +04:00
|
|
|
xcb_void_cookie_t select;
|
2012-10-31 22:14:57 +04:00
|
|
|
xcb_xkb_use_extension_cookie_t use_ext;
|
|
|
|
xcb_xkb_use_extension_reply_t *use_ext_reply;
|
2012-06-22 16:21:36 +04:00
|
|
|
xcb_xkb_per_client_flags_cookie_t pcf;
|
|
|
|
xcb_xkb_per_client_flags_reply_t *pcf_reply;
|
2012-10-29 22:15:40 +04:00
|
|
|
xcb_xkb_get_state_cookie_t state;
|
|
|
|
xcb_xkb_get_state_reply_t *state_reply;
|
2013-10-10 21:44:20 +04:00
|
|
|
uint32_t values[1] = { XCB_EVENT_MASK_PROPERTY_CHANGE };
|
2012-06-22 16:21:35 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->has_xkb = 0;
|
|
|
|
b->xkb_event_base = 0;
|
2012-06-22 16:21:35 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
ext = xcb_get_extension_data(b->conn, &xcb_xkb_id);
|
2012-06-22 16:21:35 +04:00
|
|
|
if (!ext) {
|
|
|
|
weston_log("XKB extension not available on host X11 server\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-10-11 19:27:30 +04:00
|
|
|
b->xkb_event_base = ext->first_event;
|
2012-06-22 16:21:35 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
select = xcb_xkb_select_events_checked(b->conn,
|
2012-10-31 02:13:08 +04:00
|
|
|
XCB_XKB_ID_USE_CORE_KBD,
|
|
|
|
XCB_XKB_EVENT_TYPE_STATE_NOTIFY,
|
|
|
|
0,
|
|
|
|
XCB_XKB_EVENT_TYPE_STATE_NOTIFY,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL);
|
2014-10-11 19:27:30 +04:00
|
|
|
error = xcb_request_check(b->conn, select);
|
2012-06-22 16:21:39 +04:00
|
|
|
if (error) {
|
|
|
|
weston_log("error: failed to select for XKB state events\n");
|
2012-10-31 22:14:56 +04:00
|
|
|
free(error);
|
2012-06-22 16:21:39 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
use_ext = xcb_xkb_use_extension(b->conn,
|
2012-10-31 22:14:57 +04:00
|
|
|
XCB_XKB_MAJOR_VERSION,
|
|
|
|
XCB_XKB_MINOR_VERSION);
|
2014-10-11 19:27:30 +04:00
|
|
|
use_ext_reply = xcb_xkb_use_extension_reply(b->conn, use_ext, NULL);
|
2012-10-31 22:14:57 +04:00
|
|
|
if (!use_ext_reply) {
|
|
|
|
weston_log("couldn't start using XKB extension\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!use_ext_reply->supported) {
|
|
|
|
weston_log("XKB extension version on the server is too old "
|
|
|
|
"(want %d.%d, has %d.%d)\n",
|
|
|
|
XCB_XKB_MAJOR_VERSION, XCB_XKB_MINOR_VERSION,
|
|
|
|
use_ext_reply->serverMajor, use_ext_reply->serverMinor);
|
|
|
|
free(use_ext_reply);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(use_ext_reply);
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
pcf = xcb_xkb_per_client_flags(b->conn,
|
2012-06-22 16:21:36 +04:00
|
|
|
XCB_XKB_ID_USE_CORE_KBD,
|
|
|
|
XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT,
|
|
|
|
XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0);
|
2014-10-11 19:27:30 +04:00
|
|
|
pcf_reply = xcb_xkb_per_client_flags_reply(b->conn, pcf, NULL);
|
2012-10-31 22:14:58 +04:00
|
|
|
if (!pcf_reply ||
|
|
|
|
!(pcf_reply->value & XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT)) {
|
2012-06-22 16:21:36 +04:00
|
|
|
weston_log("failed to set XKB per-client flags, not using "
|
|
|
|
"detectable repeat\n");
|
2012-10-31 22:14:58 +04:00
|
|
|
free(pcf_reply);
|
2012-06-22 16:21:36 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-10-31 22:14:56 +04:00
|
|
|
free(pcf_reply);
|
2012-06-22 16:21:36 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
state = xcb_xkb_get_state(b->conn, XCB_XKB_ID_USE_CORE_KBD);
|
|
|
|
state_reply = xcb_xkb_get_state_reply(b->conn, state, NULL);
|
2012-10-31 22:14:56 +04:00
|
|
|
if (!state_reply) {
|
2012-10-29 22:15:40 +04:00
|
|
|
weston_log("failed to get initial XKB state\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
keyboard = weston_seat_get_keyboard(&b->core_seat);
|
|
|
|
xkb_state_update_mask(keyboard->xkb_state.state,
|
2014-10-11 19:27:30 +04:00
|
|
|
get_xkb_mod_mask(b, state_reply->baseMods),
|
|
|
|
get_xkb_mod_mask(b, state_reply->latchedMods),
|
|
|
|
get_xkb_mod_mask(b, state_reply->lockedMods),
|
2012-10-29 22:15:40 +04:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
state_reply->group);
|
|
|
|
|
|
|
|
free(state_reply);
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
xcb_change_window_attributes(b->conn, b->screen->root,
|
2013-10-10 21:44:20 +04:00
|
|
|
XCB_CW_EVENT_MASK, values);
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->has_xkb = 1;
|
2012-06-22 16:21:35 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-10-26 01:18:01 +04:00
|
|
|
#ifdef HAVE_XCB_XKB
|
2013-10-10 21:44:20 +04:00
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
update_xkb_keymap(struct x11_backend *b)
|
2013-10-10 21:44:20 +04:00
|
|
|
{
|
|
|
|
struct xkb_keymap *keymap;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
keymap = x11_backend_get_keymap(b);
|
2013-10-10 21:44:20 +04:00
|
|
|
if (!keymap) {
|
|
|
|
weston_log("failed to get XKB keymap\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-10-11 19:27:30 +04:00
|
|
|
weston_seat_update_keymap(&b->core_seat, keymap);
|
2013-10-10 21:44:20 +04:00
|
|
|
xkb_keymap_unref(keymap);
|
|
|
|
}
|
2013-10-26 01:18:01 +04:00
|
|
|
#endif
|
2013-10-10 21:44:20 +04:00
|
|
|
|
2010-11-23 05:24:39 +03:00
|
|
|
static int
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_input_create(struct x11_backend *b, int no_input)
|
2010-06-14 19:54:00 +04:00
|
|
|
{
|
2012-06-01 15:14:02 +04:00
|
|
|
struct xkb_keymap *keymap;
|
2010-06-14 19:54:00 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
weston_seat_init(&b->core_seat, b->compositor, "default");
|
2012-06-07 16:07:05 +04:00
|
|
|
|
|
|
|
if (no_input)
|
|
|
|
return 0;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
weston_seat_init_pointer(&b->core_seat);
|
2012-06-01 15:14:02 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
keymap = x11_backend_get_keymap(b);
|
|
|
|
if (weston_seat_init_keyboard(&b->core_seat, keymap) < 0)
|
2013-02-16 23:29:24 +04:00
|
|
|
return -1;
|
2014-08-20 00:59:52 +04:00
|
|
|
xkb_keymap_unref(keymap);
|
2010-06-14 19:54:00 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_setup_xkb(b);
|
2012-10-29 22:15:40 +04:00
|
|
|
|
2010-11-23 05:24:39 +03:00
|
|
|
return 0;
|
2010-06-14 19:54:00 +04:00
|
|
|
}
|
|
|
|
|
2012-01-03 13:58:34 +04:00
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_input_destroy(struct x11_backend *b)
|
2012-01-03 13:58:34 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
weston_seat_release(&b->core_seat);
|
2012-01-03 13:58:34 +04:00
|
|
|
}
|
|
|
|
|
2019-06-30 16:51:10 +03:00
|
|
|
static int
|
2013-04-06 01:07:11 +04:00
|
|
|
x11_output_start_repaint_loop(struct weston_output *output)
|
|
|
|
{
|
2014-09-24 06:08:45 +04:00
|
|
|
struct timespec ts;
|
2013-04-06 01:07:11 +04:00
|
|
|
|
2015-03-18 13:17:26 +03:00
|
|
|
weston_compositor_read_presentation_clock(output->compositor, &ts);
|
2016-02-18 17:53:27 +03:00
|
|
|
weston_output_finish_frame(output, &ts, WP_PRESENTATION_FEEDBACK_INVALID);
|
2019-06-30 16:51:10 +03:00
|
|
|
|
|
|
|
return 0;
|
2013-04-06 01:07:11 +04:00
|
|
|
}
|
|
|
|
|
2013-10-22 19:11:26 +04:00
|
|
|
static int
|
2013-01-07 21:39:50 +04:00
|
|
|
x11_output_repaint_gl(struct weston_output *output_base,
|
compositor: remove repaint_data from compositor
The repaint_data is entirely backend specific. Moreover, it is only used by the
drm backend, while other backends ignore the repaint data.
There will always be only one repaint active, thus, there is no need to pass the
repaint data from the outside.
The repaint_data breaks with the multi-backend series, which calls repaint begin
for all backends to get the repaint_data. The repaint_data of the last backend
will then be passed to all other backend. At the moment, this works, because the
drm backend is the only backend that implements the begin_repaint call.
Another option would be to track the repaint data per backend in the compositor,
but actually, it the backend needs to track state across the calls, it's its own
responsibility.
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2021-11-03 13:14:11 +03:00
|
|
|
pixman_region32_t *damage)
|
2013-01-07 21:39:50 +04:00
|
|
|
{
|
2016-08-01 20:17:58 +03:00
|
|
|
struct x11_output *output = to_x11_output(output_base);
|
2021-02-16 13:25:47 +03:00
|
|
|
struct weston_compositor *ec;
|
|
|
|
|
|
|
|
assert(output);
|
|
|
|
|
|
|
|
ec = output->base.compositor;
|
2013-01-07 21:39:50 +04:00
|
|
|
|
|
|
|
ec->renderer->repaint_output(output_base, damage);
|
|
|
|
|
|
|
|
pixman_region32_subtract(&ec->primary_plane.damage,
|
|
|
|
&ec->primary_plane.damage, damage);
|
|
|
|
|
|
|
|
wl_event_source_timer_update(output->finish_frame_timer, 10);
|
2013-10-22 19:11:26 +04:00
|
|
|
return 0;
|
2013-01-07 21:39:50 +04:00
|
|
|
}
|
|
|
|
|
2013-05-22 16:41:38 +04:00
|
|
|
static void
|
|
|
|
set_clip_for_output(struct weston_output *output_base, pixman_region32_t *region)
|
|
|
|
{
|
2016-08-01 20:17:58 +03:00
|
|
|
struct x11_output *output = to_x11_output(output_base);
|
2021-02-16 13:25:47 +03:00
|
|
|
struct weston_compositor *ec;
|
|
|
|
struct x11_backend *b;
|
2013-10-28 07:25:01 +04:00
|
|
|
pixman_region32_t transformed_region;
|
2013-05-22 16:41:38 +04:00
|
|
|
pixman_box32_t *rects;
|
|
|
|
xcb_rectangle_t *output_rects;
|
|
|
|
xcb_void_cookie_t cookie;
|
2013-10-28 07:25:01 +04:00
|
|
|
int nrects, i;
|
2013-05-22 16:41:38 +04:00
|
|
|
xcb_generic_error_t *err;
|
|
|
|
|
2021-02-16 13:25:47 +03:00
|
|
|
if (!output)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ec = output->base.compositor;
|
|
|
|
b = to_x11_backend(ec);
|
|
|
|
|
2013-10-28 07:25:01 +04:00
|
|
|
pixman_region32_init(&transformed_region);
|
2022-09-20 23:21:17 +03:00
|
|
|
weston_region_global_to_output(&transformed_region,
|
|
|
|
output_base,
|
2022-01-20 02:01:36 +03:00
|
|
|
region);
|
2013-10-28 07:25:01 +04:00
|
|
|
|
|
|
|
rects = pixman_region32_rectangles(&transformed_region, &nrects);
|
2013-05-22 16:41:38 +04:00
|
|
|
output_rects = calloc(nrects, sizeof(xcb_rectangle_t));
|
|
|
|
|
2013-10-28 07:25:01 +04:00
|
|
|
if (output_rects == NULL) {
|
|
|
|
pixman_region32_fini(&transformed_region);
|
2013-05-22 16:41:38 +04:00
|
|
|
return;
|
2013-10-28 07:25:01 +04:00
|
|
|
}
|
2013-05-22 16:41:38 +04:00
|
|
|
|
|
|
|
for (i = 0; i < nrects; i++) {
|
2013-10-28 07:25:01 +04:00
|
|
|
output_rects[i].x = rects[i].x1;
|
|
|
|
output_rects[i].y = rects[i].y1;
|
|
|
|
output_rects[i].width = rects[i].x2 - rects[i].x1;
|
|
|
|
output_rects[i].height = rects[i].y2 - rects[i].y1;
|
2013-05-22 16:41:38 +04:00
|
|
|
}
|
|
|
|
|
2013-10-28 07:25:01 +04:00
|
|
|
pixman_region32_fini(&transformed_region);
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
cookie = xcb_set_clip_rectangles_checked(b->conn, XCB_CLIP_ORDERING_UNSORTED,
|
2013-05-22 16:41:38 +04:00
|
|
|
output->gc,
|
|
|
|
0, 0, nrects,
|
|
|
|
output_rects);
|
2014-10-11 19:27:30 +04:00
|
|
|
err = xcb_request_check(b->conn, cookie);
|
2013-05-22 16:41:38 +04:00
|
|
|
if (err != NULL) {
|
|
|
|
weston_log("Failed to set clip rects, err: %d\n", err->error_code);
|
|
|
|
free(err);
|
|
|
|
}
|
|
|
|
free(output_rects);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-22 19:11:26 +04:00
|
|
|
static int
|
2013-01-07 21:39:50 +04:00
|
|
|
x11_output_repaint_shm(struct weston_output *output_base,
|
compositor: remove repaint_data from compositor
The repaint_data is entirely backend specific. Moreover, it is only used by the
drm backend, while other backends ignore the repaint data.
There will always be only one repaint active, thus, there is no need to pass the
repaint data from the outside.
The repaint_data breaks with the multi-backend series, which calls repaint begin
for all backends to get the repaint_data. The repaint_data of the last backend
will then be passed to all other backend. At the moment, this works, because the
drm backend is the only backend that implements the begin_repaint call.
Another option would be to track the repaint data per backend in the compositor,
but actually, it the backend needs to track state across the calls, it's its own
responsibility.
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2021-11-03 13:14:11 +03:00
|
|
|
pixman_region32_t *damage)
|
2011-03-11 18:39:20 +03:00
|
|
|
{
|
2016-08-01 20:17:58 +03:00
|
|
|
struct x11_output *output = to_x11_output(output_base);
|
2021-02-16 13:25:47 +03:00
|
|
|
struct weston_compositor *ec;
|
|
|
|
struct x11_backend *b;
|
2013-01-07 21:39:50 +04:00
|
|
|
xcb_void_cookie_t cookie;
|
|
|
|
xcb_generic_error_t *err;
|
2012-04-20 23:37:33 +04:00
|
|
|
|
2021-02-16 13:25:47 +03:00
|
|
|
assert(output);
|
|
|
|
|
|
|
|
ec = output->base.compositor;
|
|
|
|
b = to_x11_backend(ec);
|
|
|
|
|
2013-01-25 17:13:01 +04:00
|
|
|
pixman_renderer_output_set_buffer(output_base, output->hw_surface);
|
2012-09-06 06:49:55 +04:00
|
|
|
ec->renderer->repaint_output(output_base, damage);
|
2012-01-26 08:32:28 +04:00
|
|
|
|
2012-11-22 17:57:00 +04:00
|
|
|
pixman_region32_subtract(&ec->primary_plane.damage,
|
|
|
|
&ec->primary_plane.damage, damage);
|
2013-05-22 16:41:38 +04:00
|
|
|
set_clip_for_output(output_base, damage);
|
2014-10-11 19:27:30 +04:00
|
|
|
cookie = xcb_shm_put_image_checked(b->conn, output->window, output->gc,
|
2013-01-07 21:39:50 +04:00
|
|
|
pixman_image_get_width(output->hw_surface),
|
|
|
|
pixman_image_get_height(output->hw_surface),
|
|
|
|
0, 0,
|
|
|
|
pixman_image_get_width(output->hw_surface),
|
|
|
|
pixman_image_get_height(output->hw_surface),
|
|
|
|
0, 0, output->depth, XCB_IMAGE_FORMAT_Z_PIXMAP,
|
|
|
|
0, output->segment, 0);
|
2014-10-11 19:27:30 +04:00
|
|
|
err = xcb_request_check(b->conn, cookie);
|
2013-01-07 21:39:50 +04:00
|
|
|
if (err != NULL) {
|
|
|
|
weston_log("Failed to put shm image, err: %d\n", err->error_code);
|
|
|
|
free(err);
|
|
|
|
}
|
2012-11-22 17:57:00 +04:00
|
|
|
|
2012-01-26 08:47:45 +04:00
|
|
|
wl_event_source_timer_update(output->finish_frame_timer, 10);
|
2013-10-22 19:11:26 +04:00
|
|
|
return 0;
|
2012-01-26 08:32:28 +04:00
|
|
|
}
|
|
|
|
|
2011-10-29 22:39:13 +04:00
|
|
|
static int
|
|
|
|
finish_frame_handler(void *data)
|
|
|
|
{
|
|
|
|
struct x11_output *output = data;
|
compositor: set presentation.presented flags
Change weston_output_finish_frame() signature so that backends are
required to set the flags, that will be reported on the Presentation
'presented' event. This is meant for output-wide feedback flags. Flags
that vary per wl_surface are subject for the following patch.
All start_repaint_loop functions use the special private flag
PRESENTATION_FEEDBACK_INVALID to mark, that this call of
weston_output_finish_frame() cannot trigger the 'presented' event. If it
does, we now hit an assert, and should then investigate why a fake update
triggered Presentation feedback.
DRM:
Page flip is always vsync'd, and always gets the completion timestamp
from the kernel which should correspond well to hardware. Completion is
triggered by the kernel/hardware.
Vblank handler is only used with the broken planes path, therefore do
not report VSYNC, because we cannot guarantee all the planes updated at
the same time. We cannot set the INVALID, because it would abort the
compositor if the broken planes path was ever used. This is a hack that
will get fixed with nuclear pageflip support in the future.
fbdev:
No vsync, update done by copy, no completion event from hardware, and
completion time is totally fake.
headless:
No real output to update.
RDP:
Guessing that maybe no vsync, fake time, and copy make sense (pixels
sent over network). Also no event that the pixels have been shown?
RPI:
Presumably Dispmanx updates are vsync'd. We get a completion event from
the driver, but need to read the clock ourselves, so the completion time
is somewhat unreliable. Zero-copy flag not implemented though it would
be theoretically possible with EGL clients (zero-copy is a per-surface
flag anyway, so in this patch).
Wayland:
No information how the host compositor is doing updates, so make a safe
guess without assuming vsync or hardware completion event. While we do
get some timestamp from the host compositor, it is not the completion
time. Would need to hook to the Presentation extension of the host
compositor to get more accurate flags.
X11:
No idea about vsync, completion event, or copying. Also the timestamp is
a fake.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Tested-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Acked-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2014-12-17 17:20:40 +03:00
|
|
|
struct timespec ts;
|
2013-04-06 01:07:11 +04:00
|
|
|
|
2015-03-18 13:17:26 +03:00
|
|
|
weston_compositor_read_presentation_clock(output->base.compositor, &ts);
|
compositor: set presentation.presented flags
Change weston_output_finish_frame() signature so that backends are
required to set the flags, that will be reported on the Presentation
'presented' event. This is meant for output-wide feedback flags. Flags
that vary per wl_surface are subject for the following patch.
All start_repaint_loop functions use the special private flag
PRESENTATION_FEEDBACK_INVALID to mark, that this call of
weston_output_finish_frame() cannot trigger the 'presented' event. If it
does, we now hit an assert, and should then investigate why a fake update
triggered Presentation feedback.
DRM:
Page flip is always vsync'd, and always gets the completion timestamp
from the kernel which should correspond well to hardware. Completion is
triggered by the kernel/hardware.
Vblank handler is only used with the broken planes path, therefore do
not report VSYNC, because we cannot guarantee all the planes updated at
the same time. We cannot set the INVALID, because it would abort the
compositor if the broken planes path was ever used. This is a hack that
will get fixed with nuclear pageflip support in the future.
fbdev:
No vsync, update done by copy, no completion event from hardware, and
completion time is totally fake.
headless:
No real output to update.
RDP:
Guessing that maybe no vsync, fake time, and copy make sense (pixels
sent over network). Also no event that the pixels have been shown?
RPI:
Presumably Dispmanx updates are vsync'd. We get a completion event from
the driver, but need to read the clock ourselves, so the completion time
is somewhat unreliable. Zero-copy flag not implemented though it would
be theoretically possible with EGL clients (zero-copy is a per-surface
flag anyway, so in this patch).
Wayland:
No information how the host compositor is doing updates, so make a safe
guess without assuming vsync or hardware completion event. While we do
get some timestamp from the host compositor, it is not the completion
time. Would need to hook to the Presentation extension of the host
compositor to get more accurate flags.
X11:
No idea about vsync, completion event, or copying. Also the timestamp is
a fake.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Tested-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Acked-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2014-12-17 17:20:40 +03:00
|
|
|
weston_output_finish_frame(&output->base, &ts, 0);
|
2011-10-29 22:39:13 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-01-07 21:39:50 +04:00
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_output_deinit_shm(struct x11_backend *b, struct x11_output *output)
|
2013-01-07 21:39:50 +04:00
|
|
|
{
|
|
|
|
xcb_void_cookie_t cookie;
|
|
|
|
xcb_generic_error_t *err;
|
2014-10-11 19:27:30 +04:00
|
|
|
xcb_free_gc(b->conn, output->gc);
|
2013-01-07 21:39:50 +04:00
|
|
|
|
|
|
|
pixman_image_unref(output->hw_surface);
|
|
|
|
output->hw_surface = NULL;
|
2014-10-11 19:27:30 +04:00
|
|
|
cookie = xcb_shm_detach_checked(b->conn, output->segment);
|
|
|
|
err = xcb_request_check(b->conn, cookie);
|
2013-01-07 21:39:50 +04:00
|
|
|
if (err) {
|
|
|
|
weston_log("xcb_shm_detach failed, error %d\n", err->error_code);
|
|
|
|
free(err);
|
|
|
|
}
|
|
|
|
shmdt(output->buf);
|
|
|
|
}
|
|
|
|
|
2010-06-14 19:54:00 +04:00
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_output_set_wm_protocols(struct x11_backend *b,
|
2012-11-09 20:12:21 +04:00
|
|
|
struct x11_output *output)
|
2010-06-14 19:54:00 +04:00
|
|
|
{
|
|
|
|
xcb_atom_t list[1];
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
list[0] = b->atom.wm_delete_window;
|
|
|
|
xcb_change_property (b->conn,
|
2010-06-14 19:54:00 +04:00
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
output->window,
|
2014-10-11 19:27:30 +04:00
|
|
|
b->atom.wm_protocols,
|
2010-06-14 19:54:00 +04:00
|
|
|
XCB_ATOM_ATOM,
|
|
|
|
32,
|
2011-12-23 22:33:45 +04:00
|
|
|
ARRAY_LENGTH(list),
|
2010-06-14 19:54:00 +04:00
|
|
|
list);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wm_normal_hints {
|
2021-02-16 13:25:47 +03:00
|
|
|
uint32_t flags;
|
2010-06-14 19:54:00 +04:00
|
|
|
uint32_t pad[4];
|
|
|
|
int32_t min_width, min_height;
|
|
|
|
int32_t max_width, max_height;
|
2021-02-16 13:25:47 +03:00
|
|
|
int32_t width_inc, height_inc;
|
|
|
|
int32_t min_aspect_x, min_aspect_y;
|
|
|
|
int32_t max_aspect_x, max_aspect_y;
|
2010-06-14 19:54:00 +04:00
|
|
|
int32_t base_width, base_height;
|
|
|
|
int32_t win_gravity;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define WM_NORMAL_HINTS_MIN_SIZE 16
|
|
|
|
#define WM_NORMAL_HINTS_MAX_SIZE 32
|
|
|
|
|
2011-01-26 22:37:07 +03:00
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_output_set_icon(struct x11_backend *b,
|
2011-04-23 23:03:15 +04:00
|
|
|
struct x11_output *output, const char *filename)
|
2011-01-26 22:37:07 +03:00
|
|
|
{
|
2012-03-12 09:05:25 +04:00
|
|
|
uint32_t *icon;
|
2011-04-23 23:03:15 +04:00
|
|
|
int32_t width, height;
|
2012-03-12 09:05:25 +04:00
|
|
|
pixman_image_t *image;
|
2011-01-26 22:37:07 +03:00
|
|
|
|
2012-03-12 09:05:25 +04:00
|
|
|
image = load_image(filename);
|
|
|
|
if (!image)
|
2011-01-26 22:37:07 +03:00
|
|
|
return;
|
2012-03-12 09:05:25 +04:00
|
|
|
width = pixman_image_get_width(image);
|
|
|
|
height = pixman_image_get_height(image);
|
2011-01-26 22:37:07 +03:00
|
|
|
icon = malloc(width * height * 4 + 8);
|
|
|
|
if (!icon) {
|
2012-03-12 09:05:25 +04:00
|
|
|
pixman_image_unref(image);
|
2011-01-26 22:37:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
icon[0] = width;
|
|
|
|
icon[1] = height;
|
2012-03-12 09:05:25 +04:00
|
|
|
memcpy(icon + 2, pixman_image_get_data(image), width * height * 4);
|
2014-10-11 19:27:30 +04:00
|
|
|
xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE, output->window,
|
|
|
|
b->atom.net_wm_icon, b->atom.cardinal, 32,
|
2011-01-26 22:37:07 +03:00
|
|
|
width * height + 2, icon);
|
|
|
|
free(icon);
|
2012-03-12 09:05:25 +04:00
|
|
|
pixman_image_unref(image);
|
2011-01-26 22:37:07 +03:00
|
|
|
}
|
|
|
|
|
2012-11-09 20:12:21 +04:00
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_output_wait_for_map(struct x11_backend *b, struct x11_output *output)
|
2012-11-09 20:12:21 +04:00
|
|
|
{
|
|
|
|
xcb_map_notify_event_t *map_notify;
|
|
|
|
xcb_configure_notify_event_t *configure_notify;
|
|
|
|
xcb_generic_event_t *event;
|
2013-02-15 06:14:11 +04:00
|
|
|
int mapped = 0, configured = 0;
|
2012-11-09 20:12:21 +04:00
|
|
|
uint8_t response_type;
|
|
|
|
|
|
|
|
/* This isn't the nicest way to do this. Ideally, we could
|
2013-02-15 06:14:11 +04:00
|
|
|
* just go back to the main loop and once we get the configure
|
2012-11-09 20:12:21 +04:00
|
|
|
* notify, we add the output to the compositor. While we do
|
|
|
|
* support output hotplug, we can't start up with no outputs.
|
2013-02-15 06:14:11 +04:00
|
|
|
* We could add the output and then resize once we get the
|
|
|
|
* configure notify, but we don't want to start up and
|
|
|
|
* immediately resize the output.
|
|
|
|
*
|
|
|
|
* Also, some window managers don't give us our final
|
|
|
|
* fullscreen size before map_notify, so if we don't get a
|
|
|
|
* configure_notify before map_notify, we just wait for the
|
|
|
|
* first one and hope that's our size. */
|
2012-11-09 20:12:21 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
xcb_flush(b->conn);
|
2012-11-09 20:12:21 +04:00
|
|
|
|
2013-02-15 06:14:11 +04:00
|
|
|
while (!mapped || !configured) {
|
2014-10-11 19:27:30 +04:00
|
|
|
event = xcb_wait_for_event(b->conn);
|
2012-11-09 20:12:21 +04:00
|
|
|
response_type = event->response_type & ~0x80;
|
|
|
|
|
|
|
|
switch (response_type) {
|
|
|
|
case XCB_MAP_NOTIFY:
|
|
|
|
map_notify = (xcb_map_notify_event_t *) event;
|
|
|
|
if (map_notify->window == output->window)
|
|
|
|
mapped = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XCB_CONFIGURE_NOTIFY:
|
|
|
|
configure_notify =
|
|
|
|
(xcb_configure_notify_event_t *) event;
|
|
|
|
|
2013-05-22 16:41:37 +04:00
|
|
|
|
|
|
|
if (configure_notify->width % output->scale != 0 ||
|
|
|
|
configure_notify->height % output->scale != 0)
|
|
|
|
weston_log("Resolution is not a multiple of screen size, rounding\n");
|
2014-03-08 01:29:14 +04:00
|
|
|
output->mode.width = configure_notify->width;
|
|
|
|
output->mode.height = configure_notify->height;
|
2013-02-15 06:14:11 +04:00
|
|
|
configured = 1;
|
2012-11-09 20:12:21 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-07 21:39:50 +04:00
|
|
|
static xcb_visualtype_t *
|
|
|
|
find_visual_by_id(xcb_screen_t *screen,
|
|
|
|
xcb_visualid_t id)
|
|
|
|
{
|
|
|
|
xcb_depth_iterator_t i;
|
|
|
|
xcb_visualtype_iterator_t j;
|
|
|
|
for (i = xcb_screen_allowed_depths_iterator(screen);
|
|
|
|
i.rem;
|
|
|
|
xcb_depth_next(&i)) {
|
|
|
|
for (j = xcb_depth_visuals_iterator(i.data);
|
|
|
|
j.rem;
|
|
|
|
xcb_visualtype_next(&j)) {
|
|
|
|
if (j.data->visual_id == id)
|
|
|
|
return j.data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint8_t
|
|
|
|
get_depth_of_visual(xcb_screen_t *screen,
|
|
|
|
xcb_visualid_t id)
|
|
|
|
{
|
|
|
|
xcb_depth_iterator_t i;
|
|
|
|
xcb_visualtype_iterator_t j;
|
|
|
|
for (i = xcb_screen_allowed_depths_iterator(screen);
|
|
|
|
i.rem;
|
|
|
|
xcb_depth_next(&i)) {
|
|
|
|
for (j = xcb_depth_visuals_iterator(i.data);
|
|
|
|
j.rem;
|
|
|
|
xcb_visualtype_next(&j)) {
|
|
|
|
if (j.data->visual_id == id)
|
|
|
|
return i.data->depth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_output_init_shm(struct x11_backend *b, struct x11_output *output,
|
2013-01-07 21:39:50 +04:00
|
|
|
int width, int height)
|
|
|
|
{
|
|
|
|
xcb_visualtype_t *visual_type;
|
2015-10-06 01:27:54 +03:00
|
|
|
xcb_screen_t *screen;
|
2013-01-07 21:39:50 +04:00
|
|
|
xcb_format_iterator_t fmt;
|
|
|
|
xcb_void_cookie_t cookie;
|
|
|
|
xcb_generic_error_t *err;
|
|
|
|
const xcb_query_extension_reply_t *ext;
|
|
|
|
int bitsperpixel = 0;
|
|
|
|
pixman_format_code_t pixman_format;
|
|
|
|
|
|
|
|
/* Check if SHM is available */
|
2014-10-11 19:27:30 +04:00
|
|
|
ext = xcb_get_extension_data(b->conn, &xcb_shm_id);
|
2013-01-07 21:39:50 +04:00
|
|
|
if (ext == NULL || !ext->present) {
|
|
|
|
/* SHM is missing */
|
|
|
|
weston_log("SHM extension is not available\n");
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-10-06 01:27:54 +03:00
|
|
|
screen = x11_compositor_get_default_screen(b);
|
|
|
|
visual_type = find_visual_by_id(screen, screen->root_visual);
|
2013-01-07 21:39:50 +04:00
|
|
|
if (!visual_type) {
|
|
|
|
weston_log("Failed to lookup visual for root window\n");
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
weston_log("Found visual, bits per value: %d, red_mask: %.8x, green_mask: %.8x, blue_mask: %.8x\n",
|
|
|
|
visual_type->bits_per_rgb_value,
|
|
|
|
visual_type->red_mask,
|
|
|
|
visual_type->green_mask,
|
|
|
|
visual_type->blue_mask);
|
2015-10-06 01:27:54 +03:00
|
|
|
output->depth = get_depth_of_visual(screen, screen->root_visual);
|
2013-01-07 21:39:50 +04:00
|
|
|
weston_log("Visual depth is %d\n", output->depth);
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
for (fmt = xcb_setup_pixmap_formats_iterator(xcb_get_setup(b->conn));
|
2013-01-07 21:39:50 +04:00
|
|
|
fmt.rem;
|
|
|
|
xcb_format_next(&fmt)) {
|
|
|
|
if (fmt.data->depth == output->depth) {
|
|
|
|
bitsperpixel = fmt.data->bits_per_pixel;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
weston_log("Found format for depth %d, bpp: %d\n",
|
|
|
|
output->depth, bitsperpixel);
|
|
|
|
|
|
|
|
if (bitsperpixel == 32 &&
|
|
|
|
visual_type->red_mask == 0xff0000 &&
|
|
|
|
visual_type->green_mask == 0x00ff00 &&
|
|
|
|
visual_type->blue_mask == 0x0000ff) {
|
|
|
|
weston_log("Will use x8r8g8b8 format for SHM surfaces\n");
|
|
|
|
pixman_format = PIXMAN_x8r8g8b8;
|
2013-11-28 09:24:21 +04:00
|
|
|
} else if (bitsperpixel == 16 &&
|
|
|
|
visual_type->red_mask == 0x00f800 &&
|
|
|
|
visual_type->green_mask == 0x0007e0 &&
|
|
|
|
visual_type->blue_mask == 0x00001f) {
|
|
|
|
weston_log("Will use r5g6b5 format for SHM surfaces\n");
|
|
|
|
pixman_format = PIXMAN_r5g6b5;
|
2013-01-07 21:39:50 +04:00
|
|
|
} else {
|
|
|
|
weston_log("Can't find appropriate format for SHM pixmap\n");
|
|
|
|
errno = ENOTSUP;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Create SHM segment and attach it */
|
|
|
|
output->shm_id = shmget(IPC_PRIVATE, width * height * (bitsperpixel / 8), IPC_CREAT | S_IRWXU);
|
|
|
|
if (output->shm_id == -1) {
|
|
|
|
weston_log("x11shm: failed to allocate SHM segment\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
output->buf = shmat(output->shm_id, NULL, 0 /* read/write */);
|
|
|
|
if (-1 == (long)output->buf) {
|
|
|
|
weston_log("x11shm: failed to attach SHM segment\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2014-10-11 19:27:30 +04:00
|
|
|
output->segment = xcb_generate_id(b->conn);
|
|
|
|
cookie = xcb_shm_attach_checked(b->conn, output->segment, output->shm_id, 1);
|
|
|
|
err = xcb_request_check(b->conn, cookie);
|
2013-01-07 21:39:50 +04:00
|
|
|
if (err) {
|
2015-05-27 04:14:21 +03:00
|
|
|
weston_log("x11shm: xcb_shm_attach error %d, op code %d, resource id %d\n",
|
|
|
|
err->error_code, err->major_code, err->minor_code);
|
2013-01-07 21:39:50 +04:00
|
|
|
free(err);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
shmctl(output->shm_id, IPC_RMID, NULL);
|
|
|
|
|
|
|
|
/* Now create pixman image */
|
|
|
|
output->hw_surface = pixman_image_create_bits(pixman_format, width, height, output->buf,
|
|
|
|
width * (bitsperpixel / 8));
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
output->gc = xcb_generate_id(b->conn);
|
|
|
|
xcb_create_gc(b->conn, output->gc, output->window, 0, NULL);
|
2013-01-07 21:39:50 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-29 01:26:46 +03:00
|
|
|
static int
|
|
|
|
x11_output_switch_mode(struct weston_output *base, struct weston_mode *mode)
|
|
|
|
{
|
|
|
|
struct x11_backend *b;
|
2021-02-16 13:25:47 +03:00
|
|
|
struct x11_output *output = to_x11_output(base);
|
2022-07-22 15:09:29 +03:00
|
|
|
struct weston_size fb_size;
|
2016-10-29 01:26:46 +03:00
|
|
|
static uint32_t values[2];
|
|
|
|
|
2021-02-16 13:25:47 +03:00
|
|
|
assert(output);
|
|
|
|
|
2021-07-31 18:25:41 +03:00
|
|
|
b = to_x11_backend(base->compositor);
|
2016-10-29 01:26:46 +03:00
|
|
|
|
2021-07-31 18:25:41 +03:00
|
|
|
if (mode->width == output->mode.width &&
|
2016-10-29 01:26:46 +03:00
|
|
|
mode->height == output->mode.height)
|
2021-07-31 18:25:41 +03:00
|
|
|
return 0;
|
2016-10-29 01:26:46 +03:00
|
|
|
|
2021-07-31 18:25:41 +03:00
|
|
|
if (mode->width < WINDOW_MIN_WIDTH || mode->width > WINDOW_MAX_WIDTH)
|
2016-10-29 01:26:46 +03:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (mode->height < WINDOW_MIN_HEIGHT || mode->height > WINDOW_MAX_HEIGHT)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* xcb_configure_window will create an event, and we could end up
|
|
|
|
being called twice */
|
|
|
|
output->resize_pending = true;
|
|
|
|
|
|
|
|
/* window could've been resized by the user, so don't do it twice */
|
|
|
|
if (!output->window_resized) {
|
|
|
|
values[0] = mode->width;
|
|
|
|
values[1] = mode->height;
|
|
|
|
xcb_configure_window(b->conn, output->window, XCB_CONFIG_WINDOW_WIDTH |
|
|
|
|
XCB_CONFIG_WINDOW_HEIGHT, values);
|
|
|
|
}
|
|
|
|
|
2022-07-22 15:09:29 +03:00
|
|
|
fb_size.width = output->mode.width = mode->width;
|
|
|
|
fb_size.height = output->mode.height = mode->height;
|
2016-10-29 01:26:46 +03:00
|
|
|
|
2022-07-22 17:38:47 +03:00
|
|
|
weston_renderer_resize_output(&output->base, &fb_size, NULL);
|
|
|
|
|
2022-11-30 13:02:07 +03:00
|
|
|
if (base->compositor->renderer->type == WESTON_RENDERER_PIXMAN) {
|
2016-10-29 01:26:46 +03:00
|
|
|
x11_output_deinit_shm(b, output);
|
|
|
|
if (x11_output_init_shm(b, output,
|
2022-07-22 15:09:29 +03:00
|
|
|
fb_size.width, fb_size.height) < 0) {
|
2016-10-29 01:26:46 +03:00
|
|
|
weston_log("Failed to initialize SHM for the X11 output\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
output->resize_pending = false;
|
|
|
|
output->window_resized = false;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:11:10 +03:00
|
|
|
static int
|
|
|
|
x11_output_disable(struct weston_output *base)
|
|
|
|
{
|
|
|
|
struct x11_output *output = to_x11_output(base);
|
2021-02-16 13:25:47 +03:00
|
|
|
struct x11_backend *backend;
|
|
|
|
|
|
|
|
assert(output);
|
|
|
|
|
|
|
|
backend = to_x11_backend(base->compositor);
|
2016-09-30 15:11:10 +03:00
|
|
|
|
|
|
|
if (!output->base.enabled)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
wl_event_source_remove(output->finish_frame_timer);
|
|
|
|
|
2022-11-30 13:02:07 +03:00
|
|
|
if (base->compositor->renderer->type == WESTON_RENDERER_PIXMAN) {
|
2016-09-30 15:11:10 +03:00
|
|
|
pixman_renderer_output_destroy(&output->base);
|
|
|
|
x11_output_deinit_shm(backend, output);
|
|
|
|
} else {
|
|
|
|
gl_renderer->output_destroy(&output->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_destroy_window(backend->conn, output->window);
|
|
|
|
xcb_flush(backend->conn);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
x11_output_destroy(struct weston_output *base)
|
|
|
|
{
|
|
|
|
struct x11_output *output = to_x11_output(base);
|
|
|
|
|
2021-02-16 13:25:47 +03:00
|
|
|
assert(output);
|
|
|
|
|
2016-09-30 15:11:10 +03:00
|
|
|
x11_output_disable(&output->base);
|
2017-08-16 12:07:14 +03:00
|
|
|
weston_output_release(&output->base);
|
2016-09-30 15:11:10 +03:00
|
|
|
|
|
|
|
free(output);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
x11_output_enable(struct weston_output *base)
|
2010-06-14 19:54:00 +04:00
|
|
|
{
|
2016-09-30 15:11:10 +03:00
|
|
|
struct x11_output *output = to_x11_output(base);
|
2022-07-26 17:05:05 +03:00
|
|
|
const struct weston_mode *mode = output->base.current_mode;
|
2021-02-16 13:25:47 +03:00
|
|
|
struct x11_backend *b;
|
|
|
|
|
|
|
|
assert(output);
|
|
|
|
|
|
|
|
b = to_x11_backend(base->compositor);
|
2016-09-30 15:11:10 +03:00
|
|
|
|
2012-08-18 11:04:05 +04:00
|
|
|
static const char name[] = "Weston Compositor";
|
2012-01-04 08:24:14 +04:00
|
|
|
static const char class[] = "weston-1\0Weston Compositor";
|
2016-06-05 20:01:11 +03:00
|
|
|
char *title = NULL;
|
2015-10-06 01:27:54 +03:00
|
|
|
xcb_screen_t *screen;
|
2010-06-14 19:54:00 +04:00
|
|
|
struct wm_normal_hints normal_hints;
|
2011-10-29 22:39:13 +04:00
|
|
|
struct wl_event_loop *loop;
|
2018-02-07 00:18:38 +03:00
|
|
|
char *icon_filename;
|
2016-09-30 15:11:10 +03:00
|
|
|
|
2013-10-14 16:57:11 +04:00
|
|
|
int ret;
|
2010-06-14 19:54:00 +04:00
|
|
|
uint32_t mask = XCB_CW_EVENT_MASK | XCB_CW_CURSOR;
|
2012-11-09 20:12:21 +04:00
|
|
|
xcb_atom_t atom_list[1];
|
2012-06-07 16:07:05 +04:00
|
|
|
uint32_t values[2] = {
|
2010-06-14 19:54:00 +04:00
|
|
|
XCB_EVENT_MASK_EXPOSURE |
|
2012-06-07 16:07:05 +04:00
|
|
|
XCB_EVENT_MASK_STRUCTURE_NOTIFY,
|
2010-06-14 19:54:00 +04:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2016-09-30 15:11:10 +03:00
|
|
|
if (!b->no_input)
|
2012-06-07 16:07:05 +04:00
|
|
|
values[0] |=
|
|
|
|
XCB_EVENT_MASK_KEY_PRESS |
|
|
|
|
XCB_EVENT_MASK_KEY_RELEASE |
|
|
|
|
XCB_EVENT_MASK_BUTTON_PRESS |
|
|
|
|
XCB_EVENT_MASK_BUTTON_RELEASE |
|
|
|
|
XCB_EVENT_MASK_POINTER_MOTION |
|
|
|
|
XCB_EVENT_MASK_ENTER_WINDOW |
|
|
|
|
XCB_EVENT_MASK_LEAVE_WINDOW |
|
|
|
|
XCB_EVENT_MASK_KEYMAP_STATE |
|
|
|
|
XCB_EVENT_MASK_FOCUS_CHANGE;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
values[1] = b->null_cursor;
|
|
|
|
output->window = xcb_generate_id(b->conn);
|
2015-10-06 01:27:54 +03:00
|
|
|
screen = x11_compositor_get_default_screen(b);
|
2014-10-11 19:27:30 +04:00
|
|
|
xcb_create_window(b->conn,
|
2010-06-14 19:54:00 +04:00
|
|
|
XCB_COPY_FROM_PARENT,
|
|
|
|
output->window,
|
2015-10-06 01:27:54 +03:00
|
|
|
screen->root,
|
2010-06-14 19:54:00 +04:00
|
|
|
0, 0,
|
2022-07-26 17:05:05 +03:00
|
|
|
mode->width, mode->height,
|
2010-06-14 19:54:00 +04:00
|
|
|
0,
|
|
|
|
XCB_WINDOW_CLASS_INPUT_OUTPUT,
|
2015-10-06 01:27:54 +03:00
|
|
|
screen->root_visual,
|
2010-06-14 19:54:00 +04:00
|
|
|
mask, values);
|
|
|
|
|
2016-09-30 15:11:10 +03:00
|
|
|
if (b->fullscreen) {
|
2014-10-11 19:27:30 +04:00
|
|
|
atom_list[0] = b->atom.net_wm_state_fullscreen;
|
|
|
|
xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE,
|
2012-11-09 20:12:21 +04:00
|
|
|
output->window,
|
2014-10-11 19:27:30 +04:00
|
|
|
b->atom.net_wm_state,
|
2012-11-09 20:12:21 +04:00
|
|
|
XCB_ATOM_ATOM, 32,
|
|
|
|
ARRAY_LENGTH(atom_list), atom_list);
|
|
|
|
} else {
|
|
|
|
memset(&normal_hints, 0, sizeof normal_hints);
|
|
|
|
normal_hints.flags =
|
|
|
|
WM_NORMAL_HINTS_MAX_SIZE | WM_NORMAL_HINTS_MIN_SIZE;
|
2016-10-29 01:26:46 +03:00
|
|
|
normal_hints.min_width = WINDOW_MIN_WIDTH;
|
|
|
|
normal_hints.min_height = WINDOW_MIN_HEIGHT;
|
|
|
|
normal_hints.max_width = WINDOW_MAX_WIDTH;
|
|
|
|
normal_hints.max_height = WINDOW_MAX_HEIGHT;
|
2014-10-11 19:27:30 +04:00
|
|
|
xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE, output->window,
|
|
|
|
b->atom.wm_normal_hints,
|
|
|
|
b->atom.wm_size_hints, 32,
|
2012-11-09 20:12:21 +04:00
|
|
|
sizeof normal_hints / 4,
|
|
|
|
(uint8_t *) &normal_hints);
|
|
|
|
}
|
2010-06-14 19:54:00 +04:00
|
|
|
|
|
|
|
/* Set window name. Don't bother with non-EWMH WMs. */
|
2016-09-30 15:11:10 +03:00
|
|
|
if (output->base.name) {
|
|
|
|
if (asprintf(&title, "%s - %s", name, output->base.name) < 0)
|
2016-06-05 20:01:11 +03:00
|
|
|
title = NULL;
|
|
|
|
} else {
|
|
|
|
title = strdup(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (title) {
|
|
|
|
xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE, output->window,
|
|
|
|
b->atom.net_wm_name, b->atom.utf8_string, 8,
|
|
|
|
strlen(title), title);
|
|
|
|
free(title);
|
|
|
|
} else {
|
2016-09-30 15:11:10 +03:00
|
|
|
goto err;
|
2016-06-05 20:01:11 +03:00
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE, output->window,
|
|
|
|
b->atom.wm_class, b->atom.string, 8,
|
2011-01-26 22:02:31 +03:00
|
|
|
sizeof class, class);
|
|
|
|
|
2018-02-07 00:18:38 +03:00
|
|
|
icon_filename = file_name_with_datadir("wayland.png");
|
|
|
|
x11_output_set_icon(b, output, icon_filename);
|
|
|
|
free(icon_filename);
|
2011-01-26 22:37:07 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_output_set_wm_protocols(b, output);
|
2010-06-14 19:54:00 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
xcb_map_window(b->conn, output->window);
|
2010-06-14 19:54:00 +04:00
|
|
|
|
2016-09-30 15:11:10 +03:00
|
|
|
if (b->fullscreen)
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_output_wait_for_map(b, output);
|
2011-06-18 12:20:54 +04:00
|
|
|
|
2022-11-30 13:02:07 +03:00
|
|
|
if (base->compositor->renderer->type == WESTON_RENDERER_PIXMAN) {
|
2020-03-06 15:46:30 +03:00
|
|
|
const struct pixman_renderer_output_options options = {
|
|
|
|
.use_shadow = true,
|
2022-07-22 14:47:03 +03:00
|
|
|
.fb_size = {
|
|
|
|
.width = mode->width,
|
|
|
|
.height = mode->height
|
|
|
|
},
|
2020-03-06 15:46:30 +03:00
|
|
|
};
|
2014-10-11 19:27:30 +04:00
|
|
|
if (x11_output_init_shm(b, output,
|
2022-07-26 17:05:05 +03:00
|
|
|
mode->width, mode->height) < 0) {
|
2015-05-27 04:14:21 +03:00
|
|
|
weston_log("Failed to initialize SHM for the X11 output\n");
|
2016-09-30 15:11:10 +03:00
|
|
|
goto err;
|
2015-05-27 04:14:21 +03:00
|
|
|
}
|
2020-03-06 15:46:30 +03:00
|
|
|
if (pixman_renderer_output_create(&output->base, &options) < 0) {
|
2015-05-27 04:14:21 +03:00
|
|
|
weston_log("Failed to create pixman renderer for output\n");
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_output_deinit_shm(b, output);
|
2016-09-30 15:11:10 +03:00
|
|
|
goto err;
|
2013-01-07 21:39:50 +04:00
|
|
|
}
|
2016-11-24 13:05:07 +03:00
|
|
|
|
|
|
|
output->base.repaint = x11_output_repaint_shm;
|
2013-01-07 21:39:50 +04:00
|
|
|
} else {
|
2015-03-20 17:26:52 +03:00
|
|
|
/* eglCreatePlatformWindowSurfaceEXT takes a Window*
|
|
|
|
* but eglCreateWindowSurface takes a Window. */
|
|
|
|
Window xid = (Window) output->window;
|
2020-03-06 16:04:18 +03:00
|
|
|
const struct gl_renderer_output_options options = {
|
2021-11-18 17:57:22 +03:00
|
|
|
.window_for_legacy = (EGLNativeWindowType) (uintptr_t) output->window,
|
2020-03-06 16:04:18 +03:00
|
|
|
.window_for_platform = &xid,
|
|
|
|
.drm_formats = x11_formats,
|
|
|
|
.drm_formats_count = ARRAY_LENGTH(x11_formats),
|
2022-07-26 17:22:04 +03:00
|
|
|
.area.x = 0,
|
|
|
|
.area.y = 0,
|
|
|
|
.area.width = mode->width,
|
|
|
|
.area.height = mode->height,
|
|
|
|
.fb_size.width = mode->width,
|
|
|
|
.fb_size.height = mode->height,
|
2020-03-06 16:04:18 +03:00
|
|
|
};
|
2015-03-20 17:26:52 +03:00
|
|
|
|
2020-03-06 16:04:18 +03:00
|
|
|
ret = gl_renderer->output_window_create(&output->base,
|
|
|
|
&options);
|
2013-10-14 16:57:11 +04:00
|
|
|
if (ret < 0)
|
2016-09-30 15:11:10 +03:00
|
|
|
goto err;
|
2016-10-29 01:26:45 +03:00
|
|
|
|
|
|
|
output->base.repaint = x11_output_repaint_gl;
|
2013-01-07 21:39:50 +04:00
|
|
|
}
|
2012-11-13 22:10:18 +04:00
|
|
|
|
2016-10-29 01:26:45 +03:00
|
|
|
output->base.start_repaint_loop = x11_output_start_repaint_loop;
|
|
|
|
output->base.assign_planes = NULL;
|
|
|
|
output->base.set_backlight = NULL;
|
|
|
|
output->base.set_dpms = NULL;
|
2016-10-29 01:26:46 +03:00
|
|
|
output->base.switch_mode = x11_output_switch_mode;
|
2016-10-29 01:26:45 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
loop = wl_display_get_event_loop(b->compositor->wl_display);
|
2012-11-13 22:10:18 +04:00
|
|
|
output->finish_frame_timer =
|
|
|
|
wl_event_loop_add_timer(loop, finish_frame_handler, output);
|
|
|
|
|
2012-06-09 00:45:33 +04:00
|
|
|
weston_log("x11 output %dx%d, window id %d\n",
|
2022-07-26 17:05:05 +03:00
|
|
|
mode->width, mode->height, output->window);
|
2016-09-30 15:11:10 +03:00
|
|
|
|
|
|
|
return 0;
|
2012-06-09 00:45:33 +04:00
|
|
|
|
2016-09-30 15:11:10 +03:00
|
|
|
err:
|
|
|
|
xcb_destroy_window(b->conn, output->window);
|
|
|
|
xcb_flush(b->conn);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
x11_output_set_size(struct weston_output *base, int width, int height)
|
|
|
|
{
|
|
|
|
struct x11_output *output = to_x11_output(base);
|
2021-02-16 13:25:47 +03:00
|
|
|
struct x11_backend *b;
|
2017-10-12 15:58:10 +03:00
|
|
|
struct weston_head *head;
|
2021-02-16 13:25:47 +03:00
|
|
|
xcb_screen_t *scrn;
|
2016-09-30 15:11:10 +03:00
|
|
|
int output_width, output_height;
|
|
|
|
|
2021-02-16 13:25:47 +03:00
|
|
|
if (!output)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
b = to_x11_backend(base->compositor);
|
|
|
|
scrn = b->screen;
|
|
|
|
|
2016-09-30 15:11:10 +03:00
|
|
|
/* We can only be called once. */
|
|
|
|
assert(!output->base.current_mode);
|
|
|
|
|
|
|
|
/* Make sure we have scale set. */
|
|
|
|
assert(output->base.scale);
|
|
|
|
|
2016-10-29 01:26:46 +03:00
|
|
|
if (width < WINDOW_MIN_WIDTH) {
|
2016-09-30 15:11:10 +03:00
|
|
|
weston_log("Invalid width \"%d\" for output %s\n",
|
|
|
|
width, output->base.name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-10-29 01:26:46 +03:00
|
|
|
if (height < WINDOW_MIN_HEIGHT) {
|
2016-09-30 15:11:10 +03:00
|
|
|
weston_log("Invalid height \"%d\" for output %s\n",
|
|
|
|
height, output->base.name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-10-12 15:58:10 +03:00
|
|
|
wl_list_for_each(head, &output->base.head_list, output_link) {
|
|
|
|
weston_head_set_monitor_strings(head, "weston-X11", "none", NULL);
|
|
|
|
weston_head_set_physical_size(head,
|
|
|
|
width * scrn->width_in_millimeters / scrn->width_in_pixels,
|
|
|
|
height * scrn->height_in_millimeters / scrn->height_in_pixels);
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:11:10 +03:00
|
|
|
output_width = width * output->base.scale;
|
|
|
|
output_height = height * output->base.scale;
|
|
|
|
|
|
|
|
output->mode.flags =
|
|
|
|
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
|
|
|
|
|
|
|
|
output->mode.width = output_width;
|
|
|
|
output->mode.height = output_height;
|
|
|
|
output->mode.refresh = 60000;
|
2016-10-29 01:26:46 +03:00
|
|
|
output->native = output->mode;
|
2016-09-30 15:11:10 +03:00
|
|
|
output->scale = output->base.scale;
|
|
|
|
wl_list_insert(&output->base.mode_list, &output->mode.link);
|
|
|
|
|
|
|
|
output->base.current_mode = &output->mode;
|
2016-10-29 01:26:46 +03:00
|
|
|
output->base.native_mode = &output->native;
|
|
|
|
output->base.native_scale = output->base.scale;
|
|
|
|
|
2016-09-30 15:11:10 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-12 15:58:10 +03:00
|
|
|
static struct weston_output *
|
|
|
|
x11_output_create(struct weston_compositor *compositor, const char *name)
|
2016-09-30 15:11:10 +03:00
|
|
|
{
|
|
|
|
struct x11_output *output;
|
|
|
|
|
|
|
|
/* name can't be NULL. */
|
|
|
|
assert(name);
|
|
|
|
|
|
|
|
output = zalloc(sizeof *output);
|
2017-10-12 15:58:10 +03:00
|
|
|
if (!output)
|
|
|
|
return NULL;
|
2016-09-30 15:11:10 +03:00
|
|
|
|
2017-04-03 13:18:13 +03:00
|
|
|
weston_output_init(&output->base, compositor, name);
|
|
|
|
|
2016-09-30 15:11:10 +03:00
|
|
|
output->base.destroy = x11_output_destroy;
|
|
|
|
output->base.disable = x11_output_disable;
|
|
|
|
output->base.enable = x11_output_enable;
|
2017-10-12 15:58:10 +03:00
|
|
|
output->base.attach_head = NULL;
|
2016-09-30 15:11:10 +03:00
|
|
|
|
|
|
|
weston_compositor_add_pending_output(&output->base, compositor);
|
|
|
|
|
2017-10-12 15:58:10 +03:00
|
|
|
return &output->base;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
x11_head_create(struct weston_compositor *compositor, const char *name)
|
|
|
|
{
|
2021-03-11 15:26:45 +03:00
|
|
|
struct x11_backend *backend = to_x11_backend(compositor);
|
2017-10-12 15:58:10 +03:00
|
|
|
struct x11_head *head;
|
|
|
|
|
|
|
|
assert(name);
|
|
|
|
|
|
|
|
head = zalloc(sizeof *head);
|
|
|
|
if (!head)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
weston_head_init(&head->base, name);
|
2021-02-16 13:25:47 +03:00
|
|
|
|
2021-03-11 15:26:45 +03:00
|
|
|
head->base.backend = &backend->base;
|
2021-02-16 13:25:47 +03:00
|
|
|
|
2017-10-12 15:58:10 +03:00
|
|
|
weston_head_set_connection_status(&head->base, true);
|
|
|
|
weston_compositor_add_head(compositor, &head->base);
|
|
|
|
|
2016-09-30 15:11:10 +03:00
|
|
|
return 0;
|
2010-06-14 19:54:00 +04:00
|
|
|
}
|
|
|
|
|
2017-10-12 15:58:10 +03:00
|
|
|
static void
|
2021-02-16 13:25:47 +03:00
|
|
|
x11_head_destroy(struct weston_head *base)
|
2017-10-12 15:58:10 +03:00
|
|
|
{
|
2021-02-16 13:25:47 +03:00
|
|
|
struct x11_head *head = to_x11_head(base);
|
|
|
|
|
|
|
|
assert(head);
|
|
|
|
|
2017-10-12 15:58:10 +03:00
|
|
|
weston_head_release(&head->base);
|
|
|
|
free(head);
|
|
|
|
}
|
|
|
|
|
2010-06-14 19:54:00 +04:00
|
|
|
static struct x11_output *
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_find_output(struct x11_backend *b, xcb_window_t window)
|
2010-06-14 19:54:00 +04:00
|
|
|
{
|
|
|
|
struct x11_output *output;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_list_for_each(output, &b->compositor->output_list, base.link) {
|
2010-06-14 19:54:00 +04:00
|
|
|
if (output->window == window)
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2014-12-12 00:44:46 +03:00
|
|
|
return NULL;
|
2010-06-14 19:54:00 +04:00
|
|
|
}
|
|
|
|
|
2013-12-14 00:10:49 +04:00
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_delete_window(struct x11_backend *b, xcb_window_t window)
|
2013-12-14 00:10:49 +04:00
|
|
|
{
|
2013-12-14 00:10:51 +04:00
|
|
|
struct x11_output *output;
|
2013-12-14 00:10:49 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
output = x11_backend_find_output(b, window);
|
2014-12-12 00:44:46 +03:00
|
|
|
if (output)
|
|
|
|
x11_output_destroy(&output->base);
|
2013-12-14 00:10:49 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (wl_list_empty(&b->compositor->output_list))
|
2014-10-12 00:56:24 +04:00
|
|
|
weston_compositor_exit(b->compositor);
|
2013-12-14 00:10:49 +04:00
|
|
|
}
|
|
|
|
|
2015-01-28 01:26:49 +03:00
|
|
|
static void delete_cb(void *data)
|
|
|
|
{
|
|
|
|
struct window_delete_data *wd = data;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_delete_window(wd->backend, wd->window);
|
2015-01-28 01:26:49 +03:00
|
|
|
free(wd);
|
|
|
|
}
|
|
|
|
|
2012-06-22 16:21:40 +04:00
|
|
|
#ifdef HAVE_XCB_XKB
|
2012-06-22 16:21:39 +04:00
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
update_xkb_state(struct x11_backend *b, xcb_xkb_state_notify_event_t *state)
|
2012-06-22 16:21:39 +04:00
|
|
|
{
|
2015-08-01 00:55:32 +03:00
|
|
|
struct weston_keyboard *keyboard =
|
|
|
|
weston_seat_get_keyboard(&b->core_seat);
|
|
|
|
|
|
|
|
xkb_state_update_mask(keyboard->xkb_state.state,
|
2014-10-11 19:27:30 +04:00
|
|
|
get_xkb_mod_mask(b, state->baseMods),
|
|
|
|
get_xkb_mod_mask(b, state->latchedMods),
|
|
|
|
get_xkb_mod_mask(b, state->lockedMods),
|
2012-06-22 16:21:39 +04:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
state->group);
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
notify_modifiers(&b->core_seat,
|
|
|
|
wl_display_next_serial(b->compositor->wl_display));
|
2012-06-22 16:21:39 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-06-22 16:21:40 +04:00
|
|
|
/**
|
|
|
|
* This is monumentally unpleasant. If we don't have XCB-XKB bindings,
|
|
|
|
* the best we can do (given that XCB also lacks XI2 support), is to take
|
|
|
|
* the state from the core key events. Unfortunately that only gives us
|
|
|
|
* the effective (i.e. union of depressed/latched/locked) state, and we
|
|
|
|
* need the granularity.
|
|
|
|
*
|
|
|
|
* So we still update the state with every key event we see, but also use
|
|
|
|
* the state field from X11 events as a mask so we don't get any stuck
|
|
|
|
* modifiers.
|
|
|
|
*/
|
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
update_xkb_state_from_core(struct x11_backend *b, uint16_t x11_mask)
|
2012-06-22 16:21:40 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
uint32_t mask = get_xkb_mod_mask(b, x11_mask);
|
2015-08-01 00:55:32 +03:00
|
|
|
struct weston_keyboard *keyboard
|
|
|
|
= weston_seat_get_keyboard(&b->core_seat);
|
2012-06-22 16:21:40 +04:00
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
xkb_state_update_mask(keyboard->xkb_state.state,
|
2012-06-22 16:21:40 +04:00
|
|
|
keyboard->modifiers.mods_depressed & mask,
|
|
|
|
keyboard->modifiers.mods_latched & mask,
|
|
|
|
keyboard->modifiers.mods_locked & mask,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
(x11_mask >> 13) & 3);
|
2014-10-11 19:27:30 +04:00
|
|
|
notify_modifiers(&b->core_seat,
|
|
|
|
wl_display_next_serial(b->compositor->wl_display));
|
2012-06-22 16:21:40 +04:00
|
|
|
}
|
|
|
|
|
2011-12-08 19:03:17 +04:00
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_deliver_button_event(struct x11_backend *b,
|
2016-05-18 22:32:12 +03:00
|
|
|
xcb_generic_event_t *event)
|
2011-12-08 19:03:17 +04:00
|
|
|
{
|
|
|
|
xcb_button_press_event_t *button_event =
|
|
|
|
(xcb_button_press_event_t *) event;
|
2012-05-04 14:21:55 +04:00
|
|
|
uint32_t button;
|
2012-10-30 19:04:52 +04:00
|
|
|
struct x11_output *output;
|
2016-01-18 08:58:17 +03:00
|
|
|
struct weston_pointer_axis_event weston_event;
|
2016-05-18 22:32:12 +03:00
|
|
|
bool is_button_pressed = event->response_type == XCB_BUTTON_PRESS;
|
2017-11-16 19:20:55 +03:00
|
|
|
struct timespec time = { 0 };
|
2012-10-30 19:04:52 +04:00
|
|
|
|
2016-05-18 22:32:11 +03:00
|
|
|
assert(event->response_type == XCB_BUTTON_PRESS ||
|
|
|
|
event->response_type == XCB_BUTTON_RELEASE);
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
output = x11_backend_find_output(b, button_event->event);
|
2014-12-12 00:44:46 +03:00
|
|
|
if (!output)
|
|
|
|
return;
|
2012-10-30 19:04:52 +04:00
|
|
|
|
2016-05-18 22:32:12 +03:00
|
|
|
if (is_button_pressed)
|
2014-10-11 19:27:30 +04:00
|
|
|
xcb_grab_pointer(b->conn, 0, output->window,
|
2012-10-30 19:04:52 +04:00
|
|
|
XCB_EVENT_MASK_BUTTON_PRESS |
|
|
|
|
XCB_EVENT_MASK_BUTTON_RELEASE |
|
|
|
|
XCB_EVENT_MASK_POINTER_MOTION |
|
|
|
|
XCB_EVENT_MASK_ENTER_WINDOW |
|
|
|
|
XCB_EVENT_MASK_LEAVE_WINDOW,
|
|
|
|
XCB_GRAB_MODE_ASYNC,
|
|
|
|
XCB_GRAB_MODE_ASYNC,
|
|
|
|
output->window, XCB_CURSOR_NONE,
|
|
|
|
button_event->time);
|
|
|
|
else
|
2014-10-11 19:27:30 +04:00
|
|
|
xcb_ungrab_pointer(b->conn, button_event->time);
|
2011-12-08 19:03:17 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (!b->has_xkb)
|
|
|
|
update_xkb_state_from_core(b, button_event->state);
|
2012-06-22 16:21:40 +04:00
|
|
|
|
2011-12-08 19:03:17 +04:00
|
|
|
switch (button_event->detail) {
|
2015-02-04 12:51:57 +03:00
|
|
|
case 1:
|
|
|
|
button = BTN_LEFT;
|
2011-12-08 19:03:17 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
button = BTN_MIDDLE;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
button = BTN_RIGHT;
|
|
|
|
break;
|
|
|
|
case 4:
|
2012-09-27 20:40:41 +04:00
|
|
|
/* Axis are measured in pixels, but the xcb events are discrete
|
|
|
|
* steps. Therefore move the axis by some pixels every step. */
|
2016-05-18 22:32:12 +03:00
|
|
|
if (is_button_pressed) {
|
2016-01-18 08:58:17 +03:00
|
|
|
weston_event.value = -DEFAULT_AXIS_STEP_DISTANCE;
|
2016-01-18 09:38:22 +03:00
|
|
|
weston_event.discrete = -1;
|
|
|
|
weston_event.has_discrete = true;
|
2016-01-18 08:58:17 +03:00
|
|
|
weston_event.axis =
|
|
|
|
WL_POINTER_AXIS_VERTICAL_SCROLL;
|
2017-11-16 19:21:01 +03:00
|
|
|
weston_compositor_get_time(&time);
|
2017-11-16 19:20:56 +03:00
|
|
|
notify_axis(&b->core_seat, &time, &weston_event);
|
2016-02-03 16:03:00 +03:00
|
|
|
notify_pointer_frame(&b->core_seat);
|
2016-01-18 08:58:17 +03:00
|
|
|
}
|
2012-03-22 20:47:01 +04:00
|
|
|
return;
|
2011-12-08 19:03:17 +04:00
|
|
|
case 5:
|
2016-05-18 22:32:12 +03:00
|
|
|
if (is_button_pressed) {
|
2016-01-18 08:58:17 +03:00
|
|
|
weston_event.value = DEFAULT_AXIS_STEP_DISTANCE;
|
2016-01-18 09:38:22 +03:00
|
|
|
weston_event.discrete = 1;
|
|
|
|
weston_event.has_discrete = true;
|
2016-01-18 08:58:17 +03:00
|
|
|
weston_event.axis =
|
|
|
|
WL_POINTER_AXIS_VERTICAL_SCROLL;
|
2017-11-16 19:21:01 +03:00
|
|
|
weston_compositor_get_time(&time);
|
2017-11-16 19:20:56 +03:00
|
|
|
notify_axis(&b->core_seat, &time, &weston_event);
|
2016-02-03 16:03:00 +03:00
|
|
|
notify_pointer_frame(&b->core_seat);
|
2016-01-18 08:58:17 +03:00
|
|
|
}
|
2012-03-22 20:47:01 +04:00
|
|
|
return;
|
2011-12-08 19:03:17 +04:00
|
|
|
case 6:
|
2016-05-18 22:32:12 +03:00
|
|
|
if (is_button_pressed) {
|
2016-01-18 08:58:17 +03:00
|
|
|
weston_event.value = -DEFAULT_AXIS_STEP_DISTANCE;
|
2016-01-18 09:38:22 +03:00
|
|
|
weston_event.discrete = -1;
|
|
|
|
weston_event.has_discrete = true;
|
2016-01-18 08:58:17 +03:00
|
|
|
weston_event.axis =
|
|
|
|
WL_POINTER_AXIS_HORIZONTAL_SCROLL;
|
2017-11-16 19:21:01 +03:00
|
|
|
weston_compositor_get_time(&time);
|
2017-11-16 19:20:56 +03:00
|
|
|
notify_axis(&b->core_seat, &time, &weston_event);
|
2016-02-03 16:03:00 +03:00
|
|
|
notify_pointer_frame(&b->core_seat);
|
2016-01-18 08:58:17 +03:00
|
|
|
}
|
2012-03-22 20:47:01 +04:00
|
|
|
return;
|
2011-12-08 19:03:17 +04:00
|
|
|
case 7:
|
2016-05-18 22:32:12 +03:00
|
|
|
if (is_button_pressed) {
|
2016-01-18 08:58:17 +03:00
|
|
|
weston_event.value = DEFAULT_AXIS_STEP_DISTANCE;
|
2016-01-18 09:38:22 +03:00
|
|
|
weston_event.discrete = 1;
|
|
|
|
weston_event.has_discrete = true;
|
2016-01-18 08:58:17 +03:00
|
|
|
weston_event.axis =
|
|
|
|
WL_POINTER_AXIS_HORIZONTAL_SCROLL;
|
2017-11-16 19:21:01 +03:00
|
|
|
weston_compositor_get_time(&time);
|
2017-11-16 19:20:56 +03:00
|
|
|
notify_axis(&b->core_seat, &time, &weston_event);
|
2016-02-03 16:03:00 +03:00
|
|
|
notify_pointer_frame(&b->core_seat);
|
2016-01-18 08:58:17 +03:00
|
|
|
}
|
2011-12-08 19:03:17 +04:00
|
|
|
return;
|
2015-02-04 12:51:57 +03:00
|
|
|
default:
|
|
|
|
button = button_event->detail + BTN_SIDE - 8;
|
|
|
|
break;
|
2011-12-08 19:03:17 +04:00
|
|
|
}
|
|
|
|
|
2017-11-16 19:21:01 +03:00
|
|
|
weston_compositor_get_time(&time);
|
2017-11-16 19:20:55 +03:00
|
|
|
|
|
|
|
notify_button(&b->core_seat, &time, button,
|
2016-05-18 22:32:12 +03:00
|
|
|
is_button_pressed ? WL_POINTER_BUTTON_STATE_PRESSED :
|
|
|
|
WL_POINTER_BUTTON_STATE_RELEASED);
|
2016-01-18 09:38:22 +03:00
|
|
|
notify_pointer_frame(&b->core_seat);
|
2011-12-08 19:03:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-18 11:04:05 +04:00
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_deliver_motion_event(struct x11_backend *b,
|
|
|
|
xcb_generic_event_t *event)
|
2012-08-18 11:04:05 +04:00
|
|
|
{
|
|
|
|
struct x11_output *output;
|
2016-03-22 18:44:54 +03:00
|
|
|
double x, y;
|
2014-10-05 23:39:14 +04:00
|
|
|
struct weston_pointer_motion_event motion_event = { 0 };
|
2012-08-18 11:04:05 +04:00
|
|
|
xcb_motion_notify_event_t *motion_notify =
|
|
|
|
(xcb_motion_notify_event_t *) event;
|
2017-11-24 19:01:46 +03:00
|
|
|
struct timespec time;
|
2012-08-18 11:04:05 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (!b->has_xkb)
|
|
|
|
update_xkb_state_from_core(b, motion_notify->state);
|
|
|
|
output = x11_backend_find_output(b, motion_notify->event);
|
2014-12-12 00:44:46 +03:00
|
|
|
if (!output)
|
|
|
|
return;
|
|
|
|
|
2013-07-23 01:33:42 +04:00
|
|
|
weston_output_transform_coordinate(&output->base,
|
2016-03-22 18:44:54 +03:00
|
|
|
motion_notify->event_x,
|
|
|
|
motion_notify->event_y,
|
2013-10-28 07:25:00 +04:00
|
|
|
&x, &y);
|
2012-08-18 11:04:05 +04:00
|
|
|
|
2014-10-05 23:39:14 +04:00
|
|
|
motion_event = (struct weston_pointer_motion_event) {
|
|
|
|
.mask = WESTON_POINTER_MOTION_REL,
|
2016-03-22 18:44:54 +03:00
|
|
|
.dx = x - b->prev_x,
|
|
|
|
.dy = y - b->prev_y
|
2014-10-05 23:39:14 +04:00
|
|
|
};
|
|
|
|
|
2017-11-16 19:21:01 +03:00
|
|
|
weston_compositor_get_time(&time);
|
2017-11-24 19:01:46 +03:00
|
|
|
notify_motion(&b->core_seat, &time, &motion_event);
|
2016-01-18 09:38:22 +03:00
|
|
|
notify_pointer_frame(&b->core_seat);
|
2013-03-27 23:14:07 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->prev_x = x;
|
|
|
|
b->prev_y = y;
|
2012-08-18 11:04:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_deliver_enter_event(struct x11_backend *b,
|
|
|
|
xcb_generic_event_t *event)
|
2012-08-18 11:04:05 +04:00
|
|
|
{
|
|
|
|
struct x11_output *output;
|
2016-03-22 18:44:54 +03:00
|
|
|
double x, y;
|
2012-08-18 11:04:05 +04:00
|
|
|
|
|
|
|
xcb_enter_notify_event_t *enter_notify =
|
|
|
|
(xcb_enter_notify_event_t *) event;
|
|
|
|
if (enter_notify->state >= Button1Mask)
|
|
|
|
return;
|
2014-10-11 19:27:30 +04:00
|
|
|
if (!b->has_xkb)
|
|
|
|
update_xkb_state_from_core(b, enter_notify->state);
|
|
|
|
output = x11_backend_find_output(b, enter_notify->event);
|
2014-12-12 00:44:46 +03:00
|
|
|
if (!output)
|
|
|
|
return;
|
|
|
|
|
2013-07-23 01:33:42 +04:00
|
|
|
weston_output_transform_coordinate(&output->base,
|
2016-03-22 18:44:54 +03:00
|
|
|
enter_notify->event_x,
|
|
|
|
enter_notify->event_y, &x, &y);
|
2012-08-18 11:04:05 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
notify_pointer_focus(&b->core_seat, &output->base, x, y);
|
2013-03-27 23:14:07 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->prev_x = x;
|
|
|
|
b->prev_y = y;
|
2012-08-18 11:04:05 +04:00
|
|
|
}
|
|
|
|
|
2011-04-21 22:51:44 +04:00
|
|
|
static int
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_next_event(struct x11_backend *b,
|
|
|
|
xcb_generic_event_t **event, uint32_t mask)
|
2011-04-21 22:51:44 +04:00
|
|
|
{
|
2016-11-29 15:03:35 +03:00
|
|
|
if (mask & WL_EVENT_READABLE)
|
2014-10-11 19:27:30 +04:00
|
|
|
*event = xcb_poll_for_event(b->conn);
|
2016-11-29 15:03:35 +03:00
|
|
|
else
|
2014-10-11 19:27:30 +04:00
|
|
|
*event = xcb_poll_for_queued_event(b->conn);
|
2011-04-21 22:51:44 +04:00
|
|
|
|
|
|
|
return *event != NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-22 20:18:13 +04:00
|
|
|
static int
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_handle_event(int fd, uint32_t mask, void *data)
|
2010-06-14 19:54:00 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct x11_backend *b = data;
|
2010-06-14 19:54:00 +04:00
|
|
|
struct x11_output *output;
|
2022-08-30 20:25:01 +03:00
|
|
|
xcb_generic_event_t *event;
|
2010-06-14 19:54:00 +04:00
|
|
|
xcb_client_message_event_t *client_message;
|
2011-01-27 04:35:07 +03:00
|
|
|
xcb_enter_notify_event_t *enter_notify;
|
2011-04-19 17:23:29 +04:00
|
|
|
xcb_key_press_event_t *key_press, *key_release;
|
2011-01-27 19:57:19 +03:00
|
|
|
xcb_keymap_notify_event_t *keymap_notify;
|
|
|
|
xcb_focus_in_event_t *focus_in;
|
2012-06-20 08:35:59 +04:00
|
|
|
xcb_expose_event_t *expose;
|
2016-10-29 01:26:46 +03:00
|
|
|
xcb_configure_notify_event_t *configure;
|
2010-06-14 19:54:00 +04:00
|
|
|
xcb_atom_t atom;
|
2013-12-14 00:10:49 +04:00
|
|
|
xcb_window_t window;
|
2011-01-27 19:57:19 +03:00
|
|
|
uint32_t *k;
|
2012-03-30 19:52:39 +04:00
|
|
|
uint32_t i, set;
|
2012-10-12 14:25:07 +04:00
|
|
|
uint8_t response_type;
|
2012-06-06 01:08:23 +04:00
|
|
|
int count;
|
2017-11-16 19:20:57 +03:00
|
|
|
struct timespec time;
|
2010-06-14 19:54:00 +04:00
|
|
|
|
2012-06-06 01:08:23 +04:00
|
|
|
count = 0;
|
2014-10-11 19:27:30 +04:00
|
|
|
while (x11_backend_next_event(b, &event, mask)) {
|
2012-10-12 14:25:07 +04:00
|
|
|
response_type = event->response_type & ~0x80;
|
|
|
|
|
2022-08-30 20:25:01 +03:00
|
|
|
switch (b->prev_event ? b->prev_event->response_type & ~0x80 : 0x80) {
|
2011-04-19 17:23:29 +04:00
|
|
|
case XCB_KEY_RELEASE:
|
2012-06-22 16:21:36 +04:00
|
|
|
/* Suppress key repeat events; this is only used if we
|
|
|
|
* don't have XCB XKB support. */
|
2022-08-30 20:25:01 +03:00
|
|
|
key_release = (xcb_key_press_event_t *) b->prev_event;
|
2011-04-19 17:23:29 +04:00
|
|
|
key_press = (xcb_key_press_event_t *) event;
|
2012-10-12 14:25:07 +04:00
|
|
|
if (response_type == XCB_KEY_PRESS &&
|
2011-08-17 04:25:32 +04:00
|
|
|
key_release->time == key_press->time &&
|
|
|
|
key_release->detail == key_press->detail) {
|
2011-04-19 17:23:29 +04:00
|
|
|
/* Don't deliver the held key release
|
|
|
|
* event or the new key press event. */
|
|
|
|
free(event);
|
2022-08-30 20:25:01 +03:00
|
|
|
free(b->prev_event);
|
|
|
|
b->prev_event = NULL;
|
2011-04-19 17:23:29 +04:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
/* Deliver the held key release now
|
|
|
|
* and fall through and handle the new
|
2011-04-19 20:38:22 +04:00
|
|
|
* event below. */
|
2014-10-11 19:27:30 +04:00
|
|
|
update_xkb_state_from_core(b, key_release->state);
|
2017-11-16 19:21:01 +03:00
|
|
|
weston_compositor_get_time(&time);
|
2014-10-11 19:27:30 +04:00
|
|
|
notify_key(&b->core_seat,
|
2017-11-16 19:20:57 +03:00
|
|
|
&time,
|
2012-05-30 19:31:52 +04:00
|
|
|
key_release->detail - 8,
|
2012-06-22 16:21:37 +04:00
|
|
|
WL_KEYBOARD_KEY_STATE_RELEASED,
|
|
|
|
STATE_UPDATE_AUTOMATIC);
|
2022-08-30 20:25:01 +03:00
|
|
|
free(b->prev_event);
|
|
|
|
b->prev_event = NULL;
|
2011-04-19 17:23:29 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-04-19 20:38:22 +04:00
|
|
|
|
|
|
|
case XCB_FOCUS_IN:
|
2012-10-12 14:25:07 +04:00
|
|
|
assert(response_type == XCB_KEYMAP_NOTIFY);
|
2011-04-19 20:38:22 +04:00
|
|
|
keymap_notify = (xcb_keymap_notify_event_t *) event;
|
2014-10-11 19:27:30 +04:00
|
|
|
b->keys.size = 0;
|
2011-04-19 20:38:22 +04:00
|
|
|
for (i = 0; i < ARRAY_LENGTH(keymap_notify->keys) * 8; i++) {
|
|
|
|
set = keymap_notify->keys[i >> 3] &
|
|
|
|
(1 << (i & 7));
|
|
|
|
if (set) {
|
2014-10-11 19:27:30 +04:00
|
|
|
k = wl_array_add(&b->keys, sizeof *k);
|
2011-04-19 20:38:22 +04:00
|
|
|
*k = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-22 16:21:29 +04:00
|
|
|
/* Unfortunately the state only comes with the enter
|
|
|
|
* event, rather than with the focus event. I'm not
|
|
|
|
* sure of the exact semantics around it and whether
|
|
|
|
* we can ensure that we get both? */
|
2014-10-11 19:27:30 +04:00
|
|
|
notify_keyboard_focus_in(&b->core_seat, &b->keys,
|
2012-06-22 16:21:29 +04:00
|
|
|
STATE_UPDATE_AUTOMATIC);
|
2011-04-19 20:38:22 +04:00
|
|
|
|
2022-08-30 20:25:01 +03:00
|
|
|
free(b->prev_event);
|
|
|
|
b->prev_event = NULL;
|
2011-04-19 20:38:22 +04:00
|
|
|
break;
|
|
|
|
|
2011-04-19 17:23:29 +04:00
|
|
|
default:
|
|
|
|
/* No previous event held */
|
|
|
|
break;
|
2011-04-15 23:48:07 +04:00
|
|
|
}
|
|
|
|
|
2012-10-12 14:25:07 +04:00
|
|
|
switch (response_type) {
|
2010-06-14 19:54:00 +04:00
|
|
|
case XCB_KEY_PRESS:
|
|
|
|
key_press = (xcb_key_press_event_t *) event;
|
2014-10-11 19:27:30 +04:00
|
|
|
if (!b->has_xkb)
|
|
|
|
update_xkb_state_from_core(b, key_press->state);
|
2017-11-16 19:21:01 +03:00
|
|
|
weston_compositor_get_time(&time);
|
2014-10-11 19:27:30 +04:00
|
|
|
notify_key(&b->core_seat,
|
2017-11-16 19:20:57 +03:00
|
|
|
&time,
|
2012-05-30 19:31:52 +04:00
|
|
|
key_press->detail - 8,
|
2012-06-22 16:21:37 +04:00
|
|
|
WL_KEYBOARD_KEY_STATE_PRESSED,
|
2014-10-11 19:27:30 +04:00
|
|
|
b->has_xkb ? STATE_UPDATE_NONE :
|
2012-06-22 16:21:39 +04:00
|
|
|
STATE_UPDATE_AUTOMATIC);
|
2010-06-14 19:54:00 +04:00
|
|
|
break;
|
|
|
|
case XCB_KEY_RELEASE:
|
2012-06-22 16:21:36 +04:00
|
|
|
/* If we don't have XKB, we need to use the lame
|
|
|
|
* autorepeat detection above. */
|
2014-10-11 19:27:30 +04:00
|
|
|
if (!b->has_xkb) {
|
2022-08-30 20:25:01 +03:00
|
|
|
b->prev_event = event;
|
2012-06-22 16:21:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
key_release = (xcb_key_press_event_t *) event;
|
2017-11-16 19:21:01 +03:00
|
|
|
weston_compositor_get_time(&time);
|
2014-10-11 19:27:30 +04:00
|
|
|
notify_key(&b->core_seat,
|
2017-11-16 19:20:57 +03:00
|
|
|
&time,
|
2012-06-22 16:21:36 +04:00
|
|
|
key_release->detail - 8,
|
2012-06-22 16:21:37 +04:00
|
|
|
WL_KEYBOARD_KEY_STATE_RELEASED,
|
2012-06-22 16:21:39 +04:00
|
|
|
STATE_UPDATE_NONE);
|
2010-06-14 19:54:00 +04:00
|
|
|
break;
|
|
|
|
case XCB_BUTTON_PRESS:
|
|
|
|
case XCB_BUTTON_RELEASE:
|
2016-05-18 22:32:12 +03:00
|
|
|
x11_backend_deliver_button_event(b, event);
|
2010-06-14 19:54:00 +04:00
|
|
|
break;
|
|
|
|
case XCB_MOTION_NOTIFY:
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_deliver_motion_event(b, event);
|
2010-06-14 19:54:00 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case XCB_EXPOSE:
|
2012-06-20 08:35:59 +04:00
|
|
|
expose = (xcb_expose_event_t *) event;
|
2014-10-11 19:27:30 +04:00
|
|
|
output = x11_backend_find_output(b, expose->window);
|
2014-12-12 00:44:46 +03:00
|
|
|
if (!output)
|
|
|
|
break;
|
|
|
|
|
2013-12-06 00:30:37 +04:00
|
|
|
weston_output_damage(&output->base);
|
2012-06-20 08:35:59 +04:00
|
|
|
weston_output_schedule_repaint(&output->base);
|
2010-06-14 19:54:00 +04:00
|
|
|
break;
|
2010-07-07 17:51:11 +04:00
|
|
|
|
|
|
|
case XCB_ENTER_NOTIFY:
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_deliver_enter_event(b, event);
|
2010-07-07 17:51:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case XCB_LEAVE_NOTIFY:
|
2011-01-27 04:35:07 +03:00
|
|
|
enter_notify = (xcb_enter_notify_event_t *) event;
|
2011-02-08 19:59:53 +03:00
|
|
|
if (enter_notify->state >= Button1Mask)
|
|
|
|
break;
|
2014-10-11 19:27:30 +04:00
|
|
|
if (!b->has_xkb)
|
|
|
|
update_xkb_state_from_core(b, enter_notify->state);
|
2022-10-25 23:58:24 +03:00
|
|
|
clear_pointer_focus(&b->core_seat);
|
2010-07-07 17:51:11 +04:00
|
|
|
break;
|
|
|
|
|
2010-06-14 19:54:00 +04:00
|
|
|
case XCB_CLIENT_MESSAGE:
|
|
|
|
client_message = (xcb_client_message_event_t *) event;
|
|
|
|
atom = client_message->data.data32[0];
|
2013-12-14 00:10:49 +04:00
|
|
|
window = client_message->window;
|
2014-10-11 19:27:30 +04:00
|
|
|
if (atom == b->atom.wm_delete_window) {
|
2015-01-28 01:26:49 +03:00
|
|
|
struct wl_event_loop *loop;
|
|
|
|
struct window_delete_data *data = malloc(sizeof *data);
|
|
|
|
|
|
|
|
/* if malloc failed we should at least try to
|
|
|
|
* delete the window, even if it may result in
|
|
|
|
* a crash.
|
|
|
|
*/
|
|
|
|
if (!data) {
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_delete_window(b, window);
|
2015-01-28 01:26:49 +03:00
|
|
|
break;
|
|
|
|
}
|
2014-10-11 19:27:30 +04:00
|
|
|
data->backend = b;
|
2015-01-28 01:26:49 +03:00
|
|
|
data->window = window;
|
2014-10-11 19:27:30 +04:00
|
|
|
loop = wl_display_get_event_loop(b->compositor->wl_display);
|
2015-01-28 01:26:49 +03:00
|
|
|
wl_event_loop_add_idle(loop, delete_cb, data);
|
|
|
|
}
|
2010-06-14 19:54:00 +04:00
|
|
|
break;
|
|
|
|
|
2016-10-29 01:26:46 +03:00
|
|
|
case XCB_CONFIGURE_NOTIFY:
|
|
|
|
configure = (struct xcb_configure_notify_event_t *) event;
|
|
|
|
struct x11_output *output =
|
|
|
|
x11_backend_find_output(b, configure->window);
|
|
|
|
|
|
|
|
if (!output || output->resize_pending)
|
|
|
|
break;
|
|
|
|
|
|
|
|
struct weston_mode mode = output->mode;
|
|
|
|
|
|
|
|
if (mode.width == configure->width &&
|
|
|
|
mode.height == configure->height)
|
|
|
|
break;
|
|
|
|
|
|
|
|
output->window_resized = true;
|
|
|
|
|
|
|
|
mode.width = configure->width;
|
|
|
|
mode.height = configure->height;
|
|
|
|
|
|
|
|
if (weston_output_mode_set_native(&output->base,
|
|
|
|
&mode, output->scale) < 0)
|
|
|
|
weston_log("Mode switch failed\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2011-01-27 19:57:19 +03:00
|
|
|
case XCB_FOCUS_IN:
|
|
|
|
focus_in = (xcb_focus_in_event_t *) event;
|
|
|
|
if (focus_in->mode == XCB_NOTIFY_MODE_WHILE_GRABBED)
|
|
|
|
break;
|
|
|
|
|
2022-08-30 20:25:01 +03:00
|
|
|
b->prev_event = event;
|
2011-01-27 19:57:19 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case XCB_FOCUS_OUT:
|
|
|
|
focus_in = (xcb_focus_in_event_t *) event;
|
2011-12-19 23:36:50 +04:00
|
|
|
if (focus_in->mode == XCB_NOTIFY_MODE_WHILE_GRABBED ||
|
|
|
|
focus_in->mode == XCB_NOTIFY_MODE_UNGRAB)
|
2011-01-27 19:57:19 +03:00
|
|
|
break;
|
2014-10-11 19:27:30 +04:00
|
|
|
notify_keyboard_focus_out(&b->core_seat);
|
2011-01-27 19:57:19 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-06-14 19:54:00 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-22 16:21:39 +04:00
|
|
|
#ifdef HAVE_XCB_XKB
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b->has_xkb) {
|
|
|
|
if (response_type == b->xkb_event_base) {
|
2013-10-10 21:44:20 +04:00
|
|
|
xcb_xkb_state_notify_event_t *state =
|
|
|
|
(xcb_xkb_state_notify_event_t *) event;
|
|
|
|
if (state->xkbType == XCB_XKB_STATE_NOTIFY)
|
2014-10-11 19:27:30 +04:00
|
|
|
update_xkb_state(b, state);
|
2013-10-10 21:44:20 +04:00
|
|
|
} else if (response_type == XCB_PROPERTY_NOTIFY) {
|
|
|
|
xcb_property_notify_event_t *prop_notify =
|
|
|
|
(xcb_property_notify_event_t *) event;
|
2014-10-11 19:27:30 +04:00
|
|
|
if (prop_notify->window == b->screen->root &&
|
|
|
|
prop_notify->atom == b->atom.xkb_names &&
|
2013-10-10 21:44:20 +04:00
|
|
|
prop_notify->state == XCB_PROPERTY_NEW_VALUE)
|
2014-10-11 19:27:30 +04:00
|
|
|
update_xkb_keymap(b);
|
2013-10-10 21:44:20 +04:00
|
|
|
}
|
2012-06-22 16:21:39 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-06-06 01:08:23 +04:00
|
|
|
count++;
|
2022-08-30 20:25:01 +03:00
|
|
|
if (b->prev_event != event)
|
|
|
|
free(event);
|
2011-04-15 23:48:07 +04:00
|
|
|
}
|
|
|
|
|
2022-08-30 20:25:01 +03:00
|
|
|
switch (b->prev_event ? b->prev_event->response_type & ~0x80 : 0x80) {
|
2011-04-19 17:23:29 +04:00
|
|
|
case XCB_KEY_RELEASE:
|
2022-08-30 20:25:01 +03:00
|
|
|
key_release = (xcb_key_press_event_t *) b->prev_event;
|
2014-10-11 19:27:30 +04:00
|
|
|
update_xkb_state_from_core(b, key_release->state);
|
2017-11-16 19:21:01 +03:00
|
|
|
weston_compositor_get_time(&time);
|
2014-10-11 19:27:30 +04:00
|
|
|
notify_key(&b->core_seat,
|
2017-11-16 19:20:57 +03:00
|
|
|
&time,
|
2012-05-30 19:31:52 +04:00
|
|
|
key_release->detail - 8,
|
2012-06-22 16:21:37 +04:00
|
|
|
WL_KEYBOARD_KEY_STATE_RELEASED,
|
|
|
|
STATE_UPDATE_AUTOMATIC);
|
2022-08-30 20:25:01 +03:00
|
|
|
free(b->prev_event);
|
|
|
|
b->prev_event = NULL;
|
2011-04-19 17:23:29 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2011-01-27 19:57:19 +03:00
|
|
|
}
|
2011-04-21 22:51:44 +04:00
|
|
|
|
2012-06-06 01:08:23 +04:00
|
|
|
return count;
|
2011-04-21 22:51:44 +04:00
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
#define F(field) offsetof(struct x11_backend, field)
|
2010-06-14 19:54:00 +04:00
|
|
|
|
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_get_resources(struct x11_backend *b)
|
2010-06-14 19:54:00 +04:00
|
|
|
{
|
|
|
|
static const struct { const char *name; int offset; } atoms[] = {
|
|
|
|
{ "WM_PROTOCOLS", F(atom.wm_protocols) },
|
|
|
|
{ "WM_NORMAL_HINTS", F(atom.wm_normal_hints) },
|
|
|
|
{ "WM_SIZE_HINTS", F(atom.wm_size_hints) },
|
|
|
|
{ "WM_DELETE_WINDOW", F(atom.wm_delete_window) },
|
2011-01-26 22:02:31 +03:00
|
|
|
{ "WM_CLASS", F(atom.wm_class) },
|
2010-06-14 19:54:00 +04:00
|
|
|
{ "_NET_WM_NAME", F(atom.net_wm_name) },
|
2011-01-26 22:37:07 +03:00
|
|
|
{ "_NET_WM_ICON", F(atom.net_wm_icon) },
|
2011-06-18 12:20:54 +04:00
|
|
|
{ "_NET_WM_STATE", F(atom.net_wm_state) },
|
|
|
|
{ "_NET_WM_STATE_FULLSCREEN", F(atom.net_wm_state_fullscreen) },
|
2013-02-20 06:19:04 +04:00
|
|
|
{ "_NET_SUPPORTING_WM_CHECK",
|
|
|
|
F(atom.net_supporting_wm_check) },
|
|
|
|
{ "_NET_SUPPORTED", F(atom.net_supported) },
|
2011-01-26 22:02:31 +03:00
|
|
|
{ "STRING", F(atom.string) },
|
2010-06-14 19:54:00 +04:00
|
|
|
{ "UTF8_STRING", F(atom.utf8_string) },
|
2011-01-26 22:37:07 +03:00
|
|
|
{ "CARDINAL", F(atom.cardinal) },
|
2012-05-01 23:37:10 +04:00
|
|
|
{ "_XKB_RULES_NAMES", F(atom.xkb_names) },
|
2010-06-14 19:54:00 +04:00
|
|
|
};
|
|
|
|
|
2011-12-23 22:33:45 +04:00
|
|
|
xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)];
|
2010-06-14 19:54:00 +04:00
|
|
|
xcb_intern_atom_reply_t *reply;
|
|
|
|
xcb_pixmap_t pixmap;
|
|
|
|
xcb_gc_t gc;
|
2012-03-30 19:52:39 +04:00
|
|
|
unsigned int i;
|
2010-06-14 19:54:00 +04:00
|
|
|
uint8_t data[] = { 0, 0, 0, 0 };
|
|
|
|
|
2011-12-23 22:33:45 +04:00
|
|
|
for (i = 0; i < ARRAY_LENGTH(atoms); i++)
|
2014-10-11 19:27:30 +04:00
|
|
|
cookies[i] = xcb_intern_atom (b->conn, 0,
|
2010-06-14 19:54:00 +04:00
|
|
|
strlen(atoms[i].name),
|
|
|
|
atoms[i].name);
|
|
|
|
|
2011-12-23 22:33:45 +04:00
|
|
|
for (i = 0; i < ARRAY_LENGTH(atoms); i++) {
|
2014-10-11 19:27:30 +04:00
|
|
|
reply = xcb_intern_atom_reply (b->conn, cookies[i], NULL);
|
|
|
|
*(xcb_atom_t *) ((char *) b + atoms[i].offset) = reply->atom;
|
2010-06-14 19:54:00 +04:00
|
|
|
free(reply);
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
pixmap = xcb_generate_id(b->conn);
|
|
|
|
gc = xcb_generate_id(b->conn);
|
|
|
|
xcb_create_pixmap(b->conn, 1, pixmap, b->screen->root, 1, 1);
|
|
|
|
xcb_create_gc(b->conn, gc, pixmap, 0, NULL);
|
|
|
|
xcb_put_image(b->conn, XCB_IMAGE_FORMAT_XY_PIXMAP,
|
2010-06-14 19:54:00 +04:00
|
|
|
pixmap, gc, 1, 1, 0, 0, 0, 32, sizeof data, data);
|
2014-10-11 19:27:30 +04:00
|
|
|
b->null_cursor = xcb_generate_id(b->conn);
|
|
|
|
xcb_create_cursor (b->conn, b->null_cursor,
|
2010-06-14 19:54:00 +04:00
|
|
|
pixmap, pixmap, 0, 0, 0, 0, 0, 0, 1, 1);
|
2014-10-11 19:27:30 +04:00
|
|
|
xcb_free_gc(b->conn, gc);
|
|
|
|
xcb_free_pixmap(b->conn, pixmap);
|
2010-06-14 19:54:00 +04:00
|
|
|
}
|
|
|
|
|
2013-02-20 06:19:04 +04:00
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_get_wm_info(struct x11_backend *c)
|
2013-02-20 06:19:04 +04:00
|
|
|
{
|
|
|
|
xcb_get_property_cookie_t cookie;
|
|
|
|
xcb_get_property_reply_t *reply;
|
|
|
|
xcb_atom_t *atom;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
cookie = xcb_get_property(c->conn, 0, c->screen->root,
|
|
|
|
c->atom.net_supported,
|
|
|
|
XCB_ATOM_ATOM, 0, 1024);
|
|
|
|
reply = xcb_get_property_reply(c->conn, cookie, NULL);
|
|
|
|
if (reply == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
atom = (xcb_atom_t *) xcb_get_property_value(reply);
|
|
|
|
|
|
|
|
for (i = 0; i < reply->value_len; i++) {
|
|
|
|
if (atom[i] == c->atom.net_wm_state_fullscreen)
|
|
|
|
c->has_net_wm_state_fullscreen = 1;
|
|
|
|
}
|
2015-03-08 13:17:06 +03:00
|
|
|
|
|
|
|
free(reply);
|
2013-02-20 06:19:04 +04:00
|
|
|
}
|
|
|
|
|
2010-12-02 00:52:15 +03:00
|
|
|
static void
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 19:29:47 +04:00
|
|
|
x11_destroy(struct weston_compositor *ec)
|
2010-12-02 00:52:15 +03:00
|
|
|
{
|
2016-08-01 20:17:58 +03:00
|
|
|
struct x11_backend *backend = to_x11_backend(ec);
|
2017-10-12 15:58:10 +03:00
|
|
|
struct weston_head *base, *next;
|
2012-01-03 13:58:34 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_event_source_remove(backend->xcb_source);
|
|
|
|
x11_input_destroy(backend);
|
2012-01-03 13:58:34 +04:00
|
|
|
|
2013-10-25 17:26:32 +04:00
|
|
|
weston_compositor_shutdown(ec); /* destroys outputs, too */
|
|
|
|
|
2021-02-16 13:25:47 +03:00
|
|
|
wl_list_for_each_safe(base, next, &ec->head_list, compositor_link) {
|
|
|
|
if (to_x11_head(base))
|
|
|
|
x11_head_destroy(base);
|
|
|
|
}
|
2017-10-12 15:58:10 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
XCloseDisplay(backend->dpy);
|
|
|
|
free(backend);
|
2010-12-02 00:52:15 +03:00
|
|
|
}
|
|
|
|
|
2013-10-14 16:57:11 +04:00
|
|
|
static int
|
2014-10-11 19:27:30 +04:00
|
|
|
init_gl_renderer(struct x11_backend *b)
|
2013-10-14 16:57:11 +04:00
|
|
|
{
|
2020-03-06 16:04:18 +03:00
|
|
|
const struct gl_renderer_display_options options = {
|
|
|
|
.egl_platform = EGL_PLATFORM_X11_KHR,
|
|
|
|
.egl_native_display = b->dpy,
|
|
|
|
.egl_surface_type = EGL_WINDOW_BIT,
|
|
|
|
.drm_formats = x11_formats,
|
|
|
|
.drm_formats_count = ARRAY_LENGTH(x11_formats),
|
|
|
|
};
|
2013-10-14 16:57:11 +04:00
|
|
|
|
|
|
|
gl_renderer = weston_load_module("gl-renderer.so",
|
2022-09-19 14:20:02 +03:00
|
|
|
"gl_renderer_interface",
|
|
|
|
LIBWESTON_MODULEDIR);
|
2013-10-14 16:57:11 +04:00
|
|
|
if (!gl_renderer)
|
|
|
|
return -1;
|
|
|
|
|
2020-03-06 16:04:18 +03:00
|
|
|
return gl_renderer->display_create(b->compositor, &options);
|
2013-10-14 16:57:11 +04:00
|
|
|
}
|
2016-04-16 06:28:31 +03:00
|
|
|
|
2016-09-30 15:11:10 +03:00
|
|
|
static const struct weston_windowed_output_api api = {
|
|
|
|
x11_output_set_size,
|
2017-10-12 15:58:10 +03:00
|
|
|
x11_head_create,
|
2016-09-30 15:11:10 +03:00
|
|
|
};
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
static struct x11_backend *
|
|
|
|
x11_backend_create(struct weston_compositor *compositor,
|
2016-04-16 06:28:31 +03:00
|
|
|
struct weston_x11_backend_config *config)
|
2010-06-14 19:54:00 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct x11_backend *b;
|
2016-03-24 16:43:44 +03:00
|
|
|
struct wl_event_loop *loop;
|
2016-09-30 15:11:10 +03:00
|
|
|
int ret;
|
2012-06-09 00:45:33 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b = zalloc(sizeof *b);
|
|
|
|
if (b == NULL)
|
2010-06-14 19:54:00 +04:00
|
|
|
return NULL;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->compositor = compositor;
|
2016-09-30 15:11:10 +03:00
|
|
|
b->fullscreen = config->fullscreen;
|
|
|
|
b->no_input = config->no_input;
|
|
|
|
|
2017-08-30 11:29:49 +03:00
|
|
|
compositor->backend = &b->base;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (weston_compositor_set_presentation_clock_software(compositor) < 0)
|
2014-09-24 06:08:45 +04:00
|
|
|
goto err_free;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->dpy = XOpenDisplay(NULL);
|
|
|
|
if (b->dpy == NULL)
|
2012-07-08 05:03:44 +04:00
|
|
|
goto err_free;
|
2011-04-06 20:05:40 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->conn = XGetXCBConnection(b->dpy);
|
|
|
|
XSetEventQueueOwner(b->dpy, XCBOwnsEventQueue);
|
2011-03-25 16:06:37 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (xcb_connection_has_error(b->conn))
|
2012-07-08 05:03:44 +04:00
|
|
|
goto err_xdisplay;
|
2010-06-14 19:54:00 +04:00
|
|
|
|
2015-10-06 01:27:54 +03:00
|
|
|
b->screen = x11_compositor_get_default_screen(b);
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_array_init(&b->keys);
|
2010-06-14 19:54:00 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_get_resources(b);
|
|
|
|
x11_backend_get_wm_info(b);
|
2013-02-20 06:19:04 +04:00
|
|
|
|
2016-04-16 06:28:31 +03:00
|
|
|
if (!b->has_net_wm_state_fullscreen && config->fullscreen) {
|
2013-02-20 06:19:04 +04:00
|
|
|
weston_log("Can not fullscreen without window manager support"
|
|
|
|
"(need _NET_WM_STATE_FULLSCREEN)\n");
|
2016-04-16 06:28:31 +03:00
|
|
|
config->fullscreen = 0;
|
2013-02-20 06:19:04 +04:00
|
|
|
}
|
2010-06-14 19:54:00 +04:00
|
|
|
|
2022-11-30 13:02:07 +03:00
|
|
|
if (config->use_pixman) {
|
2014-10-11 19:27:30 +04:00
|
|
|
if (pixman_renderer_init(compositor) < 0) {
|
2015-05-27 04:14:21 +03:00
|
|
|
weston_log("Failed to initialize pixman renderer for X11 backend\n");
|
2013-01-07 21:39:50 +04:00
|
|
|
goto err_xdisplay;
|
2015-05-27 04:14:21 +03:00
|
|
|
}
|
2013-01-07 21:39:50 +04:00
|
|
|
}
|
2014-10-11 19:27:30 +04:00
|
|
|
else if (init_gl_renderer(b) < 0) {
|
2013-10-14 16:57:11 +04:00
|
|
|
goto err_xdisplay;
|
2013-01-07 21:39:50 +04:00
|
|
|
}
|
2016-04-16 06:28:31 +03:00
|
|
|
weston_log("Using %s renderer\n", config->use_pixman ? "pixman" : "gl");
|
2010-06-14 19:54:00 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->base.destroy = x11_destroy;
|
2017-10-12 15:58:10 +03:00
|
|
|
b->base.create_output = x11_output_create;
|
2011-01-15 00:20:21 +03:00
|
|
|
|
2016-04-16 06:28:31 +03:00
|
|
|
if (x11_input_create(b, config->no_input) < 0) {
|
2015-05-27 04:14:21 +03:00
|
|
|
weston_log("Failed to create X11 input\n");
|
2013-01-07 21:39:50 +04:00
|
|
|
goto err_renderer;
|
2015-05-27 04:14:21 +03:00
|
|
|
}
|
2012-06-22 16:21:34 +04:00
|
|
|
|
2016-03-24 16:43:44 +03:00
|
|
|
loop = wl_display_get_event_loop(compositor->wl_display);
|
2014-10-11 19:27:30 +04:00
|
|
|
b->xcb_source =
|
2016-03-24 16:43:44 +03:00
|
|
|
wl_event_loop_add_fd(loop,
|
2014-10-11 19:27:30 +04:00
|
|
|
xcb_get_file_descriptor(b->conn),
|
2010-06-14 19:54:00 +04:00
|
|
|
WL_EVENT_READABLE,
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_backend_handle_event, b);
|
|
|
|
wl_event_source_check(b->xcb_source);
|
2010-06-14 19:54:00 +04:00
|
|
|
|
2014-06-12 17:52:53 +04:00
|
|
|
if (compositor->renderer->import_dmabuf) {
|
|
|
|
if (linux_dmabuf_setup(compositor) < 0)
|
|
|
|
weston_log("Error: initializing dmabuf "
|
|
|
|
"support failed.\n");
|
|
|
|
}
|
|
|
|
|
libweston: Support zwp_surface_synchronization_v1.set_acquire_fence
Implement the set_acquire_fence request of the
zwp_surface_synchronization_v1 interface.
The implementation uses the acquire fence in two ways:
1. If the associated buffer is used as GL render source, an
EGLSyncKHR is created from the fence and used to synchronize
access.
2. If the associated buffer is used as a plane framebuffer,
the acquire fence is treated as an in-fence for the atomic
commit operation. If in-fences are not supported and the buffer
has an acquire fence, we don't consider it for plane placement.
If the used compositor/renderer doesn't support explicit
synchronization, we don't advertise the protocol at all. Currently only
the DRM and X11 backends when using the GL renderer advertise the
protocol for production use.
Issues for discussion
---------------------
a. Currently, a server-side wait of EGLSyncKHR is performed before
using the EGLImage/texture during rendering. Unfortunately, it's not clear
from the specs whether this is generally safe to do, or we need to
sync before glEGLImageTargetTexture2DOES. The exception is
TEXTURE_EXTERNAL_OES where the spec mentions it's enough to sync
and then glBindTexture for any changes to take effect.
Changes in v5:
- Meson support.
- Make explicit sync server error reporting more generic, supporting
all explicit sync related interfaces not just
wp_linux_surface_synchronization.
- Fix typo in warning for missing EGL_KHR_wait_sync extension.
- Support minor version 2 of the explicit sync protocol (i.e., support
fences for opaque EGL buffers).
Changes in v4:
- Introduce and use fd_clear and and fd_move helpers.
- Don't check for a valid buffer when updating surface acquire fence fd
from state.
- Assert that pending state acquire fence fd is always clear
after a commit.
- Clarify that WESTON_CAP_EXPLICIT_SYNC applies to just the
renderer.
- Check for EGL_KHR_wait_sync before using eglWaitSyncKHR.
- Dup the acquire fence before passing to EGL.
Changes in v3:
- Keep acquire_fence_fd in surface instead of buffer.
- Clarify that WESTON_CAP_EXPLICIT_SYNC applies to both backend and
renderer.
- Move comment about non-ownership of in_fence_fd to struct
drm_plane_state definition.
- Assert that we don't try to use planes with in-fences when using the
legacy KMS API.
- Remove unnecessary info from wayland error messages.
- Handle acquire fence for subsurface commits.
- Guard against self-update in fd_update.
- Disconnect the client if acquire fence EGLSyncKHR creation or wait
fails.
- Use updated protocol interface names.
- User correct format specifier for resource ids.
- Advertise protocol for X11 backend with GL renderer.
Changes in v2:
- Remove sync file wait fallbacks.
- Raise UNSUPPORTED_BUFFER error at commit if we have an acquire
fence, but the committed buffer is not a valid linux_dmabuf.
- Don't put buffers with in-fences on planes that don't support
in-fences.
- Don't advertise explicit sync protocol if backend does not
support explicit sync.
Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
2018-10-19 12:14:11 +03:00
|
|
|
if (compositor->capabilities & WESTON_CAP_EXPLICIT_SYNC) {
|
|
|
|
if (linux_explicit_synchronization_setup(compositor) < 0)
|
|
|
|
weston_log("Error: initializing explicit "
|
|
|
|
" synchronization support failed.\n");
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:11:10 +03:00
|
|
|
ret = weston_plugin_api_register(compositor, WESTON_WINDOWED_OUTPUT_API_NAME,
|
|
|
|
&api, sizeof(api));
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
weston_log("Failed to register output API.\n");
|
|
|
|
goto err_x11_input;
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
return b;
|
2012-07-08 05:03:44 +04:00
|
|
|
|
|
|
|
err_x11_input:
|
2014-10-11 19:27:30 +04:00
|
|
|
x11_input_destroy(b);
|
2013-01-07 21:39:50 +04:00
|
|
|
err_renderer:
|
2014-10-11 19:27:30 +04:00
|
|
|
compositor->renderer->destroy(compositor);
|
2012-07-08 05:03:44 +04:00
|
|
|
err_xdisplay:
|
2014-10-11 19:27:30 +04:00
|
|
|
XCloseDisplay(b->dpy);
|
2012-07-08 05:03:44 +04:00
|
|
|
err_free:
|
2014-10-11 19:27:30 +04:00
|
|
|
free(b);
|
2012-07-08 05:03:44 +04:00
|
|
|
return NULL;
|
2010-06-14 19:54:00 +04:00
|
|
|
}
|
2011-05-03 06:09:20 +04:00
|
|
|
|
2016-04-16 06:28:31 +03:00
|
|
|
static void
|
|
|
|
config_init_to_defaults(struct weston_x11_backend_config *config)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
WL_EXPORT int
|
2016-12-02 16:08:44 +03:00
|
|
|
weston_backend_init(struct weston_compositor *compositor,
|
|
|
|
struct weston_backend_config *config_base)
|
2011-05-03 06:09:20 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct x11_backend *b;
|
2016-04-16 06:28:31 +03:00
|
|
|
struct weston_x11_backend_config config = {{ 0, }};
|
2012-03-12 05:05:57 +04:00
|
|
|
|
2016-04-16 06:28:31 +03:00
|
|
|
if (config_base == NULL ||
|
|
|
|
config_base->struct_version != WESTON_X11_BACKEND_CONFIG_VERSION ||
|
|
|
|
config_base->struct_size > sizeof(struct weston_x11_backend_config)) {
|
|
|
|
weston_log("X11 backend config structure is invalid\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
config_init_to_defaults(&config);
|
|
|
|
memcpy(&config, config_base, config_base->struct_size);
|
2011-05-03 06:09:20 +04:00
|
|
|
|
2016-04-16 06:28:31 +03:00
|
|
|
b = x11_backend_create(compositor, &config);
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b == NULL)
|
|
|
|
return -1;
|
2016-04-16 06:28:31 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
return 0;
|
2011-05-03 06:09:20 +04:00
|
|
|
}
|