shared/xcb-xwayland: Split into common helpers

Avoid duplication of atom retrieval. This is particuarly useful
if one would one to reuse atom retrival in other parts, like tests.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Suggested-by: Daniel Stone <daniel.stone@collabora.com>
dev
Marius Vlad 3 years ago committed by Pekka Paalanen
parent 107d69f10c
commit 49d6532254
  1. 20
      shared/meson.build
  2. 145
      shared/xcb-xwayland.c
  3. 104
      shared/xcb-xwayland.h
  4. 2
      xwayland/meson.build
  5. 115
      xwayland/window-manager.c
  6. 73
      xwayland/xwayland.h

@ -22,6 +22,26 @@ dep_libshared = declare_dependency(
dependencies: deps_libshared
)
xcb_dep = dependency('xcb', required: false)
xcb_xwayland_srcs = [
'xcb-xwayland.c',
]
lib_xcb_xwayland = static_library(
'xcb-xwayland',
xcb_xwayland_srcs,
include_directories: common_inc,
dependencies: [ xcb_dep ],
install: false,
build_by_default: false,
)
dep_xcb_xwayland = declare_dependency(
link_with: lib_xcb_xwayland,
include_directories: public_inc,
)
srcs_cairo_shared = [
'image-loader.c',
'cairo-util.c',

@ -0,0 +1,145 @@
/*
* Copyright © 2011 Intel Corporation
* Copyright © 2021 Collabora, Ltd.
*
* 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:
*
* 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.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stddef.h>
#include <assert.h>
#include "shared/helpers.h"
#include "xcb-xwayland.h"
const char *
get_atom_name(xcb_connection_t *c, xcb_atom_t atom)
{
xcb_get_atom_name_cookie_t cookie;
xcb_get_atom_name_reply_t *reply;
xcb_generic_error_t *e;
static char buffer[64];
if (atom == XCB_ATOM_NONE)
return "None";
cookie = xcb_get_atom_name(c, atom);
reply = xcb_get_atom_name_reply(c, cookie, &e);
if (reply) {
snprintf(buffer, sizeof buffer, "%.*s",
xcb_get_atom_name_name_length(reply),
xcb_get_atom_name_name(reply));
} else {
snprintf(buffer, sizeof buffer, "(atom %u)", atom);
}
free(reply);
return buffer;
}
void
x11_get_atoms(xcb_connection_t *connection, struct atom_x11 *atom)
{
unsigned int i;
#define F(field) offsetof(struct atom_x11, field)
static const struct { const char *name; int offset; } atoms[] = {
{ "WM_PROTOCOLS", F(wm_protocols) },
{ "WM_NORMAL_HINTS", F(wm_normal_hints) },
{ "WM_TAKE_FOCUS", F(wm_take_focus) },
{ "WM_DELETE_WINDOW", F(wm_delete_window) },
{ "WM_STATE", F(wm_state) },
{ "WM_S0", F(wm_s0) },
{ "WM_CLIENT_MACHINE", F(wm_client_machine) },
{ "_NET_WM_CM_S0", F(net_wm_cm_s0) },
{ "_NET_WM_NAME", F(net_wm_name) },
{ "_NET_WM_PID", F(net_wm_pid) },
{ "_NET_WM_ICON", F(net_wm_icon) },
{ "_NET_WM_STATE", F(net_wm_state) },
{ "_NET_WM_STATE_MAXIMIZED_VERT", F(net_wm_state_maximized_vert) },
{ "_NET_WM_STATE_MAXIMIZED_HORZ", F(net_wm_state_maximized_horz) },
{ "_NET_WM_STATE_FULLSCREEN", F(net_wm_state_fullscreen) },
{ "_NET_WM_USER_TIME", F(net_wm_user_time) },
{ "_NET_WM_ICON_NAME", F(net_wm_icon_name) },
{ "_NET_WM_DESKTOP", F(net_wm_desktop) },
{ "_NET_WM_WINDOW_TYPE", F(net_wm_window_type) },
{ "_NET_WM_WINDOW_TYPE_DESKTOP", F(net_wm_window_type_desktop) },
{ "_NET_WM_WINDOW_TYPE_DOCK", F(net_wm_window_type_dock) },
{ "_NET_WM_WINDOW_TYPE_TOOLBAR", F(net_wm_window_type_toolbar) },
{ "_NET_WM_WINDOW_TYPE_MENU", F(net_wm_window_type_menu) },
{ "_NET_WM_WINDOW_TYPE_UTILITY", F(net_wm_window_type_utility) },
{ "_NET_WM_WINDOW_TYPE_SPLASH", F(net_wm_window_type_splash) },
{ "_NET_WM_WINDOW_TYPE_DIALOG", F(net_wm_window_type_dialog) },
{ "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", F(net_wm_window_type_dropdown) },
{ "_NET_WM_WINDOW_TYPE_POPUP_MENU", F(net_wm_window_type_popup) },
{ "_NET_WM_WINDOW_TYPE_TOOLTIP", F(net_wm_window_type_tooltip) },
{ "_NET_WM_WINDOW_TYPE_NOTIFICATION", F(net_wm_window_type_notification) },
{ "_NET_WM_WINDOW_TYPE_COMBO", F(net_wm_window_type_combo) },
{ "_NET_WM_WINDOW_TYPE_DND", F(net_wm_window_type_dnd) },
{ "_NET_WM_WINDOW_TYPE_NORMAL", F(net_wm_window_type_normal) },
{ "_NET_WM_MOVERESIZE", F(net_wm_moveresize) },
{ "_NET_SUPPORTING_WM_CHECK", F(net_supporting_wm_check) },
{ "_NET_SUPPORTED", F(net_supported) },
{ "_NET_ACTIVE_WINDOW", F(net_active_window) },
{ "_MOTIF_WM_HINTS", F(motif_wm_hints) },
{ "CLIPBOARD", F(clipboard) },
{ "CLIPBOARD_MANAGER", F(clipboard_manager) },
{ "TARGETS", F(targets) },
{ "UTF8_STRING", F(utf8_string) },
{ "_WL_SELECTION", F(wl_selection) },
{ "INCR", F(incr) },
{ "TIMESTAMP", F(timestamp) },
{ "MULTIPLE", F(multiple) },
{ "UTF8_STRING" , F(utf8_string) },
{ "COMPOUND_TEXT", F(compound_text) },
{ "TEXT", F(text) },
{ "STRING", F(string) },
{ "WINDOW", F(window) },
{ "WL_SURFACE_ID", F(wl_surface_id) },
};
xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)];
for (i = 0; i < ARRAY_LENGTH(atoms); i++)
cookies[i] =
xcb_intern_atom(connection, 0, strlen(atoms[i].name), atoms[i].name);
for (i = 0; i < ARRAY_LENGTH(atoms); i++) {
xcb_intern_atom_reply_t *reply_atom;
reply_atom = xcb_intern_atom_reply(connection, cookies[i], NULL);
assert(reply_atom);
xcb_atom_t rr_atom = reply_atom->atom;
*(xcb_atom_t *) ((char *) atom + atoms[i].offset) = rr_atom;
free(reply_atom);
}
}

@ -0,0 +1,104 @@
/*
* Copyright © 2011 Intel Corporation
* Copyright © 2021 Collabora, Ltd.
*
* 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:
*
* 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.
*/
#pragma once
#include <xcb/xcb.h>
#define SEND_EVENT_MASK (0x80)
#define EVENT_TYPE(event) ((event)->response_type & ~SEND_EVENT_MASK)
struct atom_x11 {
xcb_atom_t wm_protocols;
xcb_atom_t wm_normal_hints;
xcb_atom_t wm_take_focus;
xcb_atom_t wm_delete_window;
xcb_atom_t wm_state;
xcb_atom_t wm_s0;
xcb_atom_t wm_client_machine;
xcb_atom_t net_wm_cm_s0;
xcb_atom_t net_wm_name;
xcb_atom_t net_wm_pid;
xcb_atom_t net_wm_icon;
xcb_atom_t net_wm_state;
xcb_atom_t net_wm_state_maximized_vert;
xcb_atom_t net_wm_state_maximized_horz;
xcb_atom_t net_wm_state_fullscreen;
xcb_atom_t net_wm_user_time;
xcb_atom_t net_wm_icon_name;
xcb_atom_t net_wm_desktop;
xcb_atom_t net_wm_window_type;
xcb_atom_t net_wm_window_type_desktop;
xcb_atom_t net_wm_window_type_dock;
xcb_atom_t net_wm_window_type_toolbar;
xcb_atom_t net_wm_window_type_menu;
xcb_atom_t net_wm_window_type_utility;
xcb_atom_t net_wm_window_type_splash;
xcb_atom_t net_wm_window_type_dialog;
xcb_atom_t net_wm_window_type_dropdown;
xcb_atom_t net_wm_window_type_popup;
xcb_atom_t net_wm_window_type_tooltip;
xcb_atom_t net_wm_window_type_notification;
xcb_atom_t net_wm_window_type_combo;
xcb_atom_t net_wm_window_type_dnd;
xcb_atom_t net_wm_window_type_normal;
xcb_atom_t net_wm_moveresize;
xcb_atom_t net_supporting_wm_check;
xcb_atom_t net_supported;
xcb_atom_t net_active_window;
xcb_atom_t motif_wm_hints;
xcb_atom_t clipboard;
xcb_atom_t clipboard_manager;
xcb_atom_t targets;
xcb_atom_t utf8_string;
xcb_atom_t wl_selection;
xcb_atom_t incr;
xcb_atom_t timestamp;
xcb_atom_t multiple;
xcb_atom_t compound_text;
xcb_atom_t text;
xcb_atom_t string;
xcb_atom_t window;
xcb_atom_t text_plain_utf8;
xcb_atom_t text_plain;
xcb_atom_t xdnd_selection;
xcb_atom_t xdnd_aware;
xcb_atom_t xdnd_enter;
xcb_atom_t xdnd_leave;
xcb_atom_t xdnd_drop;
xcb_atom_t xdnd_status;
xcb_atom_t xdnd_finished;
xcb_atom_t xdnd_type_list;
xcb_atom_t xdnd_action_copy;
xcb_atom_t wl_surface_id;
xcb_atom_t allow_commits;
};
const char *
get_atom_name(xcb_connection_t *c, xcb_atom_t atom);
void
x11_get_atoms(xcb_connection_t *connection, struct atom_x11 *atom);

@ -26,7 +26,7 @@ dep_names_xwayland = [
'cairo-xcb',
]
deps_xwayland = [ dep_libweston_public ]
deps_xwayland = [ dep_libweston_public, dep_xcb_xwayland ]
foreach name : dep_names_xwayland
d = dependency(name, required: false)

@ -48,6 +48,7 @@
#include "shared/cairo-util.h"
#include "hash.h"
#include "shared/helpers.h"
#include "shared/xcb-xwayland.h"
struct wm_size_hints {
uint32_t flags;
@ -268,32 +269,6 @@ wm_lookup_window(struct weston_wm *wm, xcb_window_t hash,
return false;
}
const char *
get_atom_name(xcb_connection_t *c, xcb_atom_t atom)
{
xcb_get_atom_name_cookie_t cookie;
xcb_get_atom_name_reply_t *reply;
xcb_generic_error_t *e;
static char buffer[64];
if (atom == XCB_ATOM_NONE)
return "None";
cookie = xcb_get_atom_name (c, atom);
reply = xcb_get_atom_name_reply (c, cookie, &e);
if (reply) {
snprintf(buffer, sizeof buffer, "%.*s",
xcb_get_atom_name_name_length (reply),
xcb_get_atom_name_name (reply));
} else {
snprintf(buffer, sizeof buffer, "(atom %u)", atom);
}
free(reply);
return buffer;
}
static xcb_cursor_t
xcb_cursor_image_load_cursor(struct weston_wm *wm, const XcursorImage *img)
@ -2387,84 +2362,8 @@ weston_wm_get_visual_and_colormap(struct weston_wm *wm)
static void
weston_wm_get_resources(struct weston_wm *wm)
{
#define F(field) offsetof(struct weston_wm, field)
static const struct { const char *name; int offset; } atoms[] = {
{ "WM_PROTOCOLS", F(atom.wm_protocols) },
{ "WM_NORMAL_HINTS", F(atom.wm_normal_hints) },
{ "WM_TAKE_FOCUS", F(atom.wm_take_focus) },
{ "WM_DELETE_WINDOW", F(atom.wm_delete_window) },
{ "WM_STATE", F(atom.wm_state) },
{ "WM_S0", F(atom.wm_s0) },
{ "WM_CLIENT_MACHINE", F(atom.wm_client_machine) },
{ "_NET_WM_CM_S0", F(atom.net_wm_cm_s0) },
{ "_NET_WM_NAME", F(atom.net_wm_name) },
{ "_NET_WM_PID", F(atom.net_wm_pid) },
{ "_NET_WM_ICON", F(atom.net_wm_icon) },
{ "_NET_WM_STATE", F(atom.net_wm_state) },
{ "_NET_WM_STATE_MAXIMIZED_VERT", F(atom.net_wm_state_maximized_vert) },
{ "_NET_WM_STATE_MAXIMIZED_HORZ", F(atom.net_wm_state_maximized_horz) },
{ "_NET_WM_STATE_FULLSCREEN", F(atom.net_wm_state_fullscreen) },
{ "_NET_WM_USER_TIME", F(atom.net_wm_user_time) },
{ "_NET_WM_ICON_NAME", F(atom.net_wm_icon_name) },
{ "_NET_WM_DESKTOP", F(atom.net_wm_desktop) },
{ "_NET_WM_WINDOW_TYPE", F(atom.net_wm_window_type) },
{ "_NET_WM_WINDOW_TYPE_DESKTOP", F(atom.net_wm_window_type_desktop) },
{ "_NET_WM_WINDOW_TYPE_DOCK", F(atom.net_wm_window_type_dock) },
{ "_NET_WM_WINDOW_TYPE_TOOLBAR", F(atom.net_wm_window_type_toolbar) },
{ "_NET_WM_WINDOW_TYPE_MENU", F(atom.net_wm_window_type_menu) },
{ "_NET_WM_WINDOW_TYPE_UTILITY", F(atom.net_wm_window_type_utility) },
{ "_NET_WM_WINDOW_TYPE_SPLASH", F(atom.net_wm_window_type_splash) },
{ "_NET_WM_WINDOW_TYPE_DIALOG", F(atom.net_wm_window_type_dialog) },
{ "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", F(atom.net_wm_window_type_dropdown) },
{ "_NET_WM_WINDOW_TYPE_POPUP_MENU", F(atom.net_wm_window_type_popup) },
{ "_NET_WM_WINDOW_TYPE_TOOLTIP", F(atom.net_wm_window_type_tooltip) },
{ "_NET_WM_WINDOW_TYPE_NOTIFICATION", F(atom.net_wm_window_type_notification) },
{ "_NET_WM_WINDOW_TYPE_COMBO", F(atom.net_wm_window_type_combo) },
{ "_NET_WM_WINDOW_TYPE_DND", F(atom.net_wm_window_type_dnd) },
{ "_NET_WM_WINDOW_TYPE_NORMAL", F(atom.net_wm_window_type_normal) },
{ "_NET_WM_MOVERESIZE", F(atom.net_wm_moveresize) },
{ "_NET_SUPPORTING_WM_CHECK",
F(atom.net_supporting_wm_check) },
{ "_NET_SUPPORTED", F(atom.net_supported) },
{ "_NET_ACTIVE_WINDOW", F(atom.net_active_window) },
{ "_MOTIF_WM_HINTS", F(atom.motif_wm_hints) },
{ "CLIPBOARD", F(atom.clipboard) },
{ "CLIPBOARD_MANAGER", F(atom.clipboard_manager) },
{ "TARGETS", F(atom.targets) },
{ "UTF8_STRING", F(atom.utf8_string) },
{ "_WL_SELECTION", F(atom.wl_selection) },
{ "INCR", F(atom.incr) },
{ "TIMESTAMP", F(atom.timestamp) },
{ "MULTIPLE", F(atom.multiple) },
{ "UTF8_STRING" , F(atom.utf8_string) },
{ "COMPOUND_TEXT", F(atom.compound_text) },
{ "TEXT", F(atom.text) },
{ "STRING", F(atom.string) },
{ "WINDOW", F(atom.window) },
{ "text/plain;charset=utf-8", F(atom.text_plain_utf8) },
{ "text/plain", F(atom.text_plain) },
{ "XdndSelection", F(atom.xdnd_selection) },
{ "XdndAware", F(atom.xdnd_aware) },
{ "XdndEnter", F(atom.xdnd_enter) },
{ "XdndLeave", F(atom.xdnd_leave) },
{ "XdndDrop", F(atom.xdnd_drop) },
{ "XdndStatus", F(atom.xdnd_status) },
{ "XdndFinished", F(atom.xdnd_finished) },
{ "XdndTypeList", F(atom.xdnd_type_list) },
{ "XdndActionCopy", F(atom.xdnd_action_copy) },
{ "_XWAYLAND_ALLOW_COMMITS", F(atom.allow_commits) },
{ "WL_SURFACE_ID", F(atom.wl_surface_id) }
};
#undef F
xcb_xfixes_query_version_cookie_t xfixes_cookie;
xcb_xfixes_query_version_reply_t *xfixes_reply;
xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)];
xcb_intern_atom_reply_t *reply;
xcb_render_query_pict_formats_reply_t *formats_reply;
xcb_render_query_pict_formats_cookie_t formats_cookie;
xcb_render_pictforminfo_t *formats;
@ -2475,17 +2374,7 @@ weston_wm_get_resources(struct weston_wm *wm)
formats_cookie = xcb_render_query_pict_formats(wm->conn);
for (i = 0; i < ARRAY_LENGTH(atoms); i++)
cookies[i] = xcb_intern_atom (wm->conn, 0,
strlen(atoms[i].name),
atoms[i].name);
for (i = 0; i < ARRAY_LENGTH(atoms); i++) {
reply = xcb_intern_atom_reply (wm->conn, cookies[i], NULL);
*(xcb_atom_t *) ((char *) wm + atoms[i].offset) = reply->atom;
free(reply);
}
x11_get_atoms(wm->conn, &wm->atom);
wm->xfixes = xcb_get_extension_data(wm->conn, &xcb_xfixes_id);
if (!wm->xfixes || !wm->xfixes->present)
weston_log("xfixes not available\n");

@ -33,9 +33,7 @@
#include <libweston/libweston.h>
#include <libweston/xwayland-api.h>
#include <libweston/weston-log.h>
#define SEND_EVENT_MASK (0x80)
#define EVENT_TYPE(event) ((event)->response_type & ~SEND_EVENT_MASK)
#include "shared/xcb-xwayland.h"
struct weston_xserver {
struct wl_display *wl_display;
@ -94,80 +92,13 @@ struct weston_wm {
xcb_window_t dnd_window;
xcb_window_t dnd_owner;
struct {
xcb_atom_t wm_protocols;
xcb_atom_t wm_normal_hints;
xcb_atom_t wm_take_focus;
xcb_atom_t wm_delete_window;
xcb_atom_t wm_state;
xcb_atom_t wm_s0;
xcb_atom_t wm_client_machine;
xcb_atom_t net_wm_cm_s0;
xcb_atom_t net_wm_name;
xcb_atom_t net_wm_pid;
xcb_atom_t net_wm_icon;
xcb_atom_t net_wm_state;
xcb_atom_t net_wm_state_maximized_vert;
xcb_atom_t net_wm_state_maximized_horz;
xcb_atom_t net_wm_state_fullscreen;
xcb_atom_t net_wm_user_time;
xcb_atom_t net_wm_icon_name;
xcb_atom_t net_wm_desktop;
xcb_atom_t net_wm_window_type;
xcb_atom_t net_wm_window_type_desktop;
xcb_atom_t net_wm_window_type_dock;
xcb_atom_t net_wm_window_type_toolbar;
xcb_atom_t net_wm_window_type_menu;
xcb_atom_t net_wm_window_type_utility;
xcb_atom_t net_wm_window_type_splash;
xcb_atom_t net_wm_window_type_dialog;
xcb_atom_t net_wm_window_type_dropdown;
xcb_atom_t net_wm_window_type_popup;
xcb_atom_t net_wm_window_type_tooltip;
xcb_atom_t net_wm_window_type_notification;
xcb_atom_t net_wm_window_type_combo;
xcb_atom_t net_wm_window_type_dnd;
xcb_atom_t net_wm_window_type_normal;
xcb_atom_t net_wm_moveresize;
xcb_atom_t net_supporting_wm_check;
xcb_atom_t net_supported;
xcb_atom_t net_active_window;
xcb_atom_t motif_wm_hints;
xcb_atom_t clipboard;
xcb_atom_t clipboard_manager;
xcb_atom_t targets;
xcb_atom_t utf8_string;
xcb_atom_t wl_selection;
xcb_atom_t incr;
xcb_atom_t timestamp;
xcb_atom_t multiple;
xcb_atom_t compound_text;
xcb_atom_t text;
xcb_atom_t string;
xcb_atom_t window;
xcb_atom_t text_plain_utf8;
xcb_atom_t text_plain;
xcb_atom_t xdnd_selection;
xcb_atom_t xdnd_aware;
xcb_atom_t xdnd_enter;
xcb_atom_t xdnd_leave;
xcb_atom_t xdnd_drop;
xcb_atom_t xdnd_status;
xcb_atom_t xdnd_finished;
xcb_atom_t xdnd_type_list;
xcb_atom_t xdnd_action_copy;
xcb_atom_t wl_surface_id;
xcb_atom_t allow_commits;
} atom;
struct atom_x11 atom;
};
void
dump_property(FILE *fp, struct weston_wm *wm, xcb_atom_t property,
xcb_get_property_reply_t *reply);
const char *
get_atom_name(xcb_connection_t *c, xcb_atom_t atom);
void
weston_wm_selection_init(struct weston_wm *wm);
int

Loading…
Cancel
Save