summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorMarius Vlad <marius.vlad@collabora.com>2021-07-27 12:55:58 +0300
committerPekka Paalanen <pq@iki.fi>2022-06-22 08:08:41 +0000
commit49d6532254fa27e3a28a3fb26d0b9d253d002125 (patch)
tree7c4f03cb38e96b6861a8ff580d48571867177e2b /shared
parent107d69f10cf7d74964f289c86e17389d29595439 (diff)
downloadweston-49d6532254fa27e3a28a3fb26d0b9d253d002125.tar.gz
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>
Diffstat (limited to 'shared')
-rw-r--r--shared/meson.build20
-rw-r--r--shared/xcb-xwayland.c145
-rw-r--r--shared/xcb-xwayland.h104
3 files changed, 269 insertions, 0 deletions
diff --git a/shared/meson.build b/shared/meson.build
index 9a4af530..d05e2d46 100644
--- a/shared/meson.build
+++ b/shared/meson.build
@@ -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',
diff --git a/shared/xcb-xwayland.c b/shared/xcb-xwayland.c
new file mode 100644
index 00000000..fe801198
--- /dev/null
+++ b/shared/xcb-xwayland.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);
+ }
+}
diff --git a/shared/xcb-xwayland.h b/shared/xcb-xwayland.h
new file mode 100644
index 00000000..f4f03954
--- /dev/null
+++ b/shared/xcb-xwayland.h
@@ -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);