2018-04-03 02:57:09 +02:00
|
|
|
#include <assert.h>
|
2017-08-19 21:25:26 +02:00
|
|
|
#include <stdlib.h>
|
2017-10-26 16:39:36 +02:00
|
|
|
#include <unistd.h>
|
2018-07-21 15:44:20 +02:00
|
|
|
#include <wlr/config.h>
|
2022-01-13 09:55:09 +01:00
|
|
|
#include <wlr/types/wlr_compositor.h>
|
2021-01-30 05:47:03 +01:00
|
|
|
#include <wlr/types/wlr_data_device.h>
|
|
|
|
#include <wlr/types/wlr_primary_selection.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <wlr/util/edges.h>
|
|
|
|
#include <wlr/util/log.h>
|
2018-02-12 09:12:31 +01:00
|
|
|
#include <wlr/xcursor.h>
|
2022-10-18 13:09:17 +02:00
|
|
|
#include <wlr/xwayland/shell.h>
|
|
|
|
#include <wlr/xwayland/xwayland.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <xcb/composite.h>
|
|
|
|
#include <xcb/render.h>
|
2021-04-17 04:27:12 +02:00
|
|
|
#include <xcb/res.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <xcb/xfixes.h>
|
2018-03-03 17:03:19 +01:00
|
|
|
#include "xwayland/xwm.h"
|
2017-10-05 12:32:12 +02:00
|
|
|
|
2023-03-09 08:53:09 +01:00
|
|
|
static const char *const atom_map[ATOM_LAST] = {
|
2020-03-06 12:29:20 +01:00
|
|
|
[WL_SURFACE_ID] = "WL_SURFACE_ID",
|
2022-10-18 13:09:17 +02:00
|
|
|
[WL_SURFACE_SERIAL] = "WL_SURFACE_SERIAL",
|
2020-03-06 12:29:20 +01:00
|
|
|
[WM_DELETE_WINDOW] = "WM_DELETE_WINDOW",
|
|
|
|
[WM_PROTOCOLS] = "WM_PROTOCOLS",
|
|
|
|
[WM_HINTS] = "WM_HINTS",
|
|
|
|
[WM_NORMAL_HINTS] = "WM_NORMAL_HINTS",
|
|
|
|
[WM_SIZE_HINTS] = "WM_SIZE_HINTS",
|
|
|
|
[WM_WINDOW_ROLE] = "WM_WINDOW_ROLE",
|
|
|
|
[MOTIF_WM_HINTS] = "_MOTIF_WM_HINTS",
|
|
|
|
[UTF8_STRING] = "UTF8_STRING",
|
|
|
|
[WM_S0] = "WM_S0",
|
|
|
|
[NET_SUPPORTED] = "_NET_SUPPORTED",
|
|
|
|
[NET_WM_CM_S0] = "_NET_WM_CM_S0",
|
|
|
|
[NET_WM_PID] = "_NET_WM_PID",
|
|
|
|
[NET_WM_NAME] = "_NET_WM_NAME",
|
|
|
|
[NET_WM_STATE] = "_NET_WM_STATE",
|
2022-11-09 22:09:43 +01:00
|
|
|
[NET_WM_STRUT_PARTIAL] = "_NET_WM_STRUT_PARTIAL",
|
2020-03-06 12:29:20 +01:00
|
|
|
[NET_WM_WINDOW_TYPE] = "_NET_WM_WINDOW_TYPE",
|
|
|
|
[WM_TAKE_FOCUS] = "WM_TAKE_FOCUS",
|
|
|
|
[WINDOW] = "WINDOW",
|
2020-03-06 12:37:43 +01:00
|
|
|
[NET_ACTIVE_WINDOW] = "_NET_ACTIVE_WINDOW",
|
|
|
|
[NET_WM_MOVERESIZE] = "_NET_WM_MOVERESIZE",
|
|
|
|
[NET_SUPPORTING_WM_CHECK] = "_NET_SUPPORTING_WM_CHECK",
|
2020-07-27 13:41:54 +02:00
|
|
|
[NET_WM_STATE_FOCUSED] = "_NET_WM_STATE_FOCUSED",
|
2020-03-06 12:37:43 +01:00
|
|
|
[NET_WM_STATE_MODAL] = "_NET_WM_STATE_MODAL",
|
|
|
|
[NET_WM_STATE_FULLSCREEN] = "_NET_WM_STATE_FULLSCREEN",
|
|
|
|
[NET_WM_STATE_MAXIMIZED_VERT] = "_NET_WM_STATE_MAXIMIZED_VERT",
|
|
|
|
[NET_WM_STATE_MAXIMIZED_HORZ] = "_NET_WM_STATE_MAXIMIZED_HORZ",
|
2020-07-18 21:37:02 +02:00
|
|
|
[NET_WM_STATE_HIDDEN] = "_NET_WM_STATE_HIDDEN",
|
2020-03-06 12:37:43 +01:00
|
|
|
[NET_WM_PING] = "_NET_WM_PING",
|
2020-07-18 21:37:02 +02:00
|
|
|
[WM_CHANGE_STATE] = "WM_CHANGE_STATE",
|
2020-03-06 12:29:20 +01:00
|
|
|
[WM_STATE] = "WM_STATE",
|
|
|
|
[CLIPBOARD] = "CLIPBOARD",
|
|
|
|
[PRIMARY] = "PRIMARY",
|
|
|
|
[WL_SELECTION] = "_WL_SELECTION",
|
|
|
|
[TARGETS] = "TARGETS",
|
|
|
|
[CLIPBOARD_MANAGER] = "CLIPBOARD_MANAGER",
|
|
|
|
[INCR] = "INCR",
|
|
|
|
[TEXT] = "TEXT",
|
|
|
|
[TIMESTAMP] = "TIMESTAMP",
|
|
|
|
[DELETE] = "DELETE",
|
2021-01-29 16:45:44 +01:00
|
|
|
[NET_STARTUP_ID] = "_NET_STARTUP_ID",
|
2021-01-29 16:45:44 +01:00
|
|
|
[NET_STARTUP_INFO] = "_NET_STARTUP_INFO",
|
|
|
|
[NET_STARTUP_INFO_BEGIN] = "_NET_STARTUP_INFO_BEGIN",
|
2020-03-06 12:29:20 +01:00
|
|
|
[NET_WM_WINDOW_TYPE_NORMAL] = "_NET_WM_WINDOW_TYPE_NORMAL",
|
|
|
|
[NET_WM_WINDOW_TYPE_UTILITY] = "_NET_WM_WINDOW_TYPE_UTILITY",
|
|
|
|
[NET_WM_WINDOW_TYPE_TOOLTIP] = "_NET_WM_WINDOW_TYPE_TOOLTIP",
|
|
|
|
[NET_WM_WINDOW_TYPE_DND] = "_NET_WM_WINDOW_TYPE_DND",
|
|
|
|
[NET_WM_WINDOW_TYPE_DROPDOWN_MENU] = "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU",
|
|
|
|
[NET_WM_WINDOW_TYPE_POPUP_MENU] = "_NET_WM_WINDOW_TYPE_POPUP_MENU",
|
|
|
|
[NET_WM_WINDOW_TYPE_COMBO] = "_NET_WM_WINDOW_TYPE_COMBO",
|
|
|
|
[NET_WM_WINDOW_TYPE_MENU] = "_NET_WM_WINDOW_TYPE_MENU",
|
|
|
|
[NET_WM_WINDOW_TYPE_NOTIFICATION] = "_NET_WM_WINDOW_TYPE_NOTIFICATION",
|
|
|
|
[NET_WM_WINDOW_TYPE_SPLASH] = "_NET_WM_WINDOW_TYPE_SPLASH",
|
2024-01-25 17:27:37 +01:00
|
|
|
[NET_WM_WINDOW_TYPE_DESKTOP] = "_NET_WM_WINDOW_TYPE_DESKTOP",
|
2020-03-06 12:29:20 +01:00
|
|
|
[DND_SELECTION] = "XdndSelection",
|
|
|
|
[DND_AWARE] = "XdndAware",
|
|
|
|
[DND_STATUS] = "XdndStatus",
|
|
|
|
[DND_POSITION] = "XdndPosition",
|
|
|
|
[DND_ENTER] = "XdndEnter",
|
|
|
|
[DND_LEAVE] = "XdndLeave",
|
|
|
|
[DND_DROP] = "XdndDrop",
|
|
|
|
[DND_FINISHED] = "XdndFinished",
|
|
|
|
[DND_PROXY] = "XdndProxy",
|
|
|
|
[DND_TYPE_LIST] = "XdndTypeList",
|
|
|
|
[DND_ACTION_MOVE] = "XdndActionMove",
|
|
|
|
[DND_ACTION_COPY] = "XdndActionCopy",
|
|
|
|
[DND_ACTION_ASK] = "XdndActionAsk",
|
|
|
|
[DND_ACTION_PRIVATE] = "XdndActionPrivate",
|
2020-03-06 12:37:43 +01:00
|
|
|
[NET_CLIENT_LIST] = "_NET_CLIENT_LIST",
|
2021-05-02 18:50:36 +02:00
|
|
|
[NET_CLIENT_LIST_STACKING] = "_NET_CLIENT_LIST_STACKING",
|
2023-10-24 16:33:50 +02:00
|
|
|
[NET_WORKAREA] = "_NET_WORKAREA",
|
2017-09-29 00:47:20 +02:00
|
|
|
};
|
|
|
|
|
2021-01-29 16:45:44 +01:00
|
|
|
#define STARTUP_INFO_REMOVE_PREFIX "remove: ID="
|
|
|
|
struct pending_startup_id {
|
|
|
|
char *msg;
|
|
|
|
size_t len;
|
|
|
|
xcb_window_t window;
|
|
|
|
struct wl_list link;
|
|
|
|
};
|
|
|
|
|
2022-11-29 17:19:30 +01:00
|
|
|
static const struct wlr_addon_interface surface_addon_impl;
|
2018-04-03 02:57:09 +02:00
|
|
|
|
2022-12-05 19:13:19 +01:00
|
|
|
struct wlr_xwayland_surface *wlr_xwayland_surface_try_from_wlr_surface(
|
2018-04-03 02:57:09 +02:00
|
|
|
struct wlr_surface *surface) {
|
2022-11-29 17:19:30 +01:00
|
|
|
struct wlr_addon *addon = wlr_addon_find(&surface->addons, NULL, &surface_addon_impl);
|
2022-12-05 19:13:19 +01:00
|
|
|
if (addon == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2022-11-29 17:19:30 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface = wl_container_of(addon, xsurface, surface_addon);
|
|
|
|
return xsurface;
|
2018-04-03 02:57:09 +02:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:43:04 +02:00
|
|
|
// TODO: replace this with hash table?
|
2017-10-24 20:37:18 +02:00
|
|
|
static struct wlr_xwayland_surface *lookup_surface(struct wlr_xwm *xwm,
|
2017-09-28 23:26:31 +02:00
|
|
|
xcb_window_t window_id) {
|
|
|
|
struct wlr_xwayland_surface *surface;
|
2017-10-25 00:57:20 +02:00
|
|
|
wl_list_for_each(surface, &xwm->surfaces, link) {
|
2017-10-24 20:37:18 +02:00
|
|
|
if (surface->window_id == window_id) {
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-04-08 22:28:01 +02:00
|
|
|
static int xwayland_surface_handle_ping_timeout(void *data) {
|
|
|
|
struct wlr_xwayland_surface *surface = data;
|
|
|
|
|
2023-07-09 11:51:31 +02:00
|
|
|
wl_signal_emit_mutable(&surface->events.ping_timeout, NULL);
|
2018-04-08 22:28:01 +02:00
|
|
|
surface->pinging = false;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-01-13 23:28:44 +01:00
|
|
|
static void read_surface_client_id(struct wlr_xwm *xwm,
|
|
|
|
struct wlr_xwayland_surface *xsurface,
|
|
|
|
xcb_res_query_client_ids_cookie_t cookie) {
|
|
|
|
xcb_res_query_client_ids_reply_t *reply = xcb_res_query_client_ids_reply(
|
|
|
|
xwm->xcb_conn, cookie, NULL);
|
|
|
|
if (reply == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t *pid = NULL;
|
|
|
|
xcb_res_client_id_value_iterator_t iter =
|
|
|
|
xcb_res_query_client_ids_ids_iterator(reply);
|
|
|
|
while (iter.rem > 0) {
|
|
|
|
if (iter.data->spec.mask & XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID &&
|
|
|
|
xcb_res_client_id_value_value_length(iter.data) > 0) {
|
|
|
|
pid = xcb_res_client_id_value_value(iter.data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
xcb_res_client_id_value_next(&iter);
|
|
|
|
}
|
|
|
|
if (pid == NULL) {
|
|
|
|
free(reply);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
xsurface->pid = *pid;
|
|
|
|
free(reply);
|
|
|
|
}
|
|
|
|
|
2018-04-13 05:30:06 +02:00
|
|
|
static struct wlr_xwayland_surface *xwayland_surface_create(
|
2017-09-28 23:26:31 +02:00
|
|
|
struct wlr_xwm *xwm, xcb_window_t window_id, int16_t x, int16_t y,
|
2017-08-20 13:43:04 +02:00
|
|
|
uint16_t width, uint16_t height, bool override_redirect) {
|
2023-10-03 07:51:07 +02:00
|
|
|
struct wlr_xwayland_surface *surface = calloc(1, sizeof(*surface));
|
2017-09-28 23:26:31 +02:00
|
|
|
if (!surface) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "Could not allocate wlr xwayland surface");
|
2017-08-20 13:43:04 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-10-24 19:24:26 +02:00
|
|
|
|
2017-10-27 21:20:50 +02:00
|
|
|
xcb_get_geometry_cookie_t geometry_cookie =
|
|
|
|
xcb_get_geometry(xwm->xcb_conn, window_id);
|
|
|
|
|
2024-02-22 23:13:36 +01:00
|
|
|
xcb_res_query_client_ids_cookie_t client_id_cookie = { 0 };
|
2024-01-13 23:28:44 +01:00
|
|
|
if (xwm->xres) {
|
|
|
|
xcb_res_client_id_spec_t spec = {
|
|
|
|
.client = window_id,
|
|
|
|
.mask = XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID
|
|
|
|
};
|
|
|
|
client_id_cookie = xcb_res_query_client_ids(xwm->xcb_conn, 1, &spec);
|
|
|
|
}
|
|
|
|
|
2017-10-24 19:24:26 +02:00
|
|
|
uint32_t values[1];
|
|
|
|
values[0] =
|
|
|
|
XCB_EVENT_MASK_FOCUS_CHANGE |
|
|
|
|
XCB_EVENT_MASK_PROPERTY_CHANGE;
|
|
|
|
xcb_change_window_attributes(xwm->xcb_conn, window_id,
|
2018-03-01 21:11:41 +01:00
|
|
|
XCB_CW_EVENT_MASK, values);
|
2017-10-24 19:24:26 +02:00
|
|
|
|
2017-10-24 18:00:43 +02:00
|
|
|
surface->xwm = xwm;
|
2017-09-28 23:26:31 +02:00
|
|
|
surface->window_id = window_id;
|
|
|
|
surface->x = x;
|
|
|
|
surface->y = y;
|
|
|
|
surface->width = width;
|
|
|
|
surface->height = height;
|
|
|
|
surface->override_redirect = override_redirect;
|
2018-01-14 18:19:37 +01:00
|
|
|
wl_list_init(&surface->children);
|
2021-05-02 18:50:36 +02:00
|
|
|
wl_list_init(&surface->stack_link);
|
2018-01-14 18:19:37 +01:00
|
|
|
wl_list_init(&surface->parent_link);
|
2022-10-18 14:31:05 +02:00
|
|
|
wl_list_init(&surface->unpaired_link);
|
2017-09-28 23:26:31 +02:00
|
|
|
wl_signal_init(&surface->events.destroy);
|
2017-09-29 18:28:38 +02:00
|
|
|
wl_signal_init(&surface->events.request_configure);
|
2017-10-27 16:48:09 +02:00
|
|
|
wl_signal_init(&surface->events.request_move);
|
|
|
|
wl_signal_init(&surface->events.request_resize);
|
2020-07-18 21:37:02 +02:00
|
|
|
wl_signal_init(&surface->events.request_minimize);
|
2017-10-27 19:05:14 +02:00
|
|
|
wl_signal_init(&surface->events.request_maximize);
|
|
|
|
wl_signal_init(&surface->events.request_fullscreen);
|
2018-09-02 06:59:09 +02:00
|
|
|
wl_signal_init(&surface->events.request_activate);
|
2023-03-11 12:01:02 +01:00
|
|
|
wl_signal_init(&surface->events.associate);
|
|
|
|
wl_signal_init(&surface->events.dissociate);
|
2017-09-29 18:28:38 +02:00
|
|
|
wl_signal_init(&surface->events.set_class);
|
2018-09-03 09:07:07 +02:00
|
|
|
wl_signal_init(&surface->events.set_role);
|
2017-09-29 18:28:38 +02:00
|
|
|
wl_signal_init(&surface->events.set_title);
|
2017-09-29 20:22:35 +02:00
|
|
|
wl_signal_init(&surface->events.set_parent);
|
2021-01-29 16:45:44 +01:00
|
|
|
wl_signal_init(&surface->events.set_startup_id);
|
2017-09-29 23:03:01 +02:00
|
|
|
wl_signal_init(&surface->events.set_window_type);
|
2018-07-19 13:07:11 +02:00
|
|
|
wl_signal_init(&surface->events.set_hints);
|
2018-09-24 12:14:02 +02:00
|
|
|
wl_signal_init(&surface->events.set_decorations);
|
2022-11-09 22:09:43 +01:00
|
|
|
wl_signal_init(&surface->events.set_strut_partial);
|
2018-07-18 19:51:03 +02:00
|
|
|
wl_signal_init(&surface->events.set_override_redirect);
|
2020-10-14 11:47:23 +02:00
|
|
|
wl_signal_init(&surface->events.set_geometry);
|
2024-02-13 00:37:55 +01:00
|
|
|
wl_signal_init(&surface->events.map_request);
|
|
|
|
wl_signal_init(&surface->events.ping_timeout);
|
2017-10-27 21:20:50 +02:00
|
|
|
|
|
|
|
xcb_get_geometry_reply_t *geometry_reply =
|
|
|
|
xcb_get_geometry_reply(xwm->xcb_conn, geometry_cookie, NULL);
|
|
|
|
if (geometry_reply != NULL) {
|
|
|
|
surface->has_alpha = geometry_reply->depth == 32;
|
|
|
|
}
|
|
|
|
free(geometry_reply);
|
|
|
|
|
2018-04-08 22:28:01 +02:00
|
|
|
struct wl_display *display = xwm->xwayland->wl_display;
|
|
|
|
struct wl_event_loop *loop = wl_display_get_event_loop(display);
|
|
|
|
surface->ping_timer = wl_event_loop_add_timer(loop,
|
|
|
|
xwayland_surface_handle_ping_timeout, surface);
|
|
|
|
if (surface->ping_timer == NULL) {
|
|
|
|
free(surface);
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "Could not add timer to event loop");
|
2018-04-08 22:28:01 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-21 12:05:04 +02:00
|
|
|
wl_list_insert(&xwm->surfaces, &surface->link);
|
|
|
|
|
2024-01-13 23:28:44 +01:00
|
|
|
if (xwm->xres) {
|
|
|
|
read_surface_client_id(xwm, surface, client_id_cookie);
|
|
|
|
}
|
|
|
|
|
2023-03-11 11:59:13 +01:00
|
|
|
wl_signal_emit_mutable(&xwm->xwayland->events.new_surface, surface);
|
|
|
|
|
2017-09-28 23:26:31 +02:00
|
|
|
return surface;
|
2017-08-20 13:43:04 +02:00
|
|
|
}
|
|
|
|
|
2017-10-25 14:39:28 +02:00
|
|
|
static void xwm_set_net_active_window(struct wlr_xwm *xwm,
|
|
|
|
xcb_window_t window) {
|
|
|
|
xcb_change_property(xwm->xcb_conn, XCB_PROP_MODE_REPLACE,
|
2020-03-06 12:37:43 +01:00
|
|
|
xwm->screen->root, xwm->atoms[NET_ACTIVE_WINDOW],
|
2017-10-25 14:39:28 +02:00
|
|
|
xwm->atoms[WINDOW], 32, 1, &window);
|
|
|
|
}
|
|
|
|
|
2018-04-08 22:28:01 +02:00
|
|
|
static void xwm_send_wm_message(struct wlr_xwayland_surface *surface,
|
2018-05-26 09:08:20 +02:00
|
|
|
xcb_client_message_data_t *data, uint32_t event_mask) {
|
2018-04-08 22:28:01 +02:00
|
|
|
struct wlr_xwm *xwm = surface->xwm;
|
|
|
|
|
|
|
|
xcb_client_message_event_t event = {
|
|
|
|
.response_type = XCB_CLIENT_MESSAGE,
|
|
|
|
.format = 32,
|
|
|
|
.sequence = 0,
|
|
|
|
.window = surface->window_id,
|
|
|
|
.type = xwm->atoms[WM_PROTOCOLS],
|
|
|
|
.data = *data,
|
|
|
|
};
|
|
|
|
|
|
|
|
xcb_send_event(xwm->xcb_conn,
|
|
|
|
0, // propagate
|
|
|
|
surface->window_id,
|
2018-05-26 09:08:20 +02:00
|
|
|
event_mask,
|
2018-04-08 22:28:01 +02:00
|
|
|
(const char *)&event);
|
|
|
|
xcb_flush(xwm->xcb_conn);
|
|
|
|
}
|
|
|
|
|
2019-02-13 11:18:46 +01:00
|
|
|
static void xwm_set_net_client_list(struct wlr_xwm *xwm) {
|
2021-05-02 18:50:36 +02:00
|
|
|
// FIXME: _NET_CLIENT_LIST is expected to be ordered by map time, but the
|
|
|
|
// order of surfaces in `xwm->surfaces` is by creation time. The order of
|
|
|
|
// windows _NET_CLIENT_LIST exposed by wlroots is wrong.
|
|
|
|
|
2019-02-13 11:18:46 +01:00
|
|
|
size_t mapped_surfaces = 0;
|
|
|
|
struct wlr_xwayland_surface *surface;
|
|
|
|
wl_list_for_each(surface, &xwm->surfaces, link) {
|
2023-03-08 21:41:49 +01:00
|
|
|
if (surface->surface != NULL && surface->surface->mapped) {
|
2019-02-13 11:18:46 +01:00
|
|
|
mapped_surfaces++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-22 13:44:46 +01:00
|
|
|
xcb_window_t *windows = NULL;
|
|
|
|
if (mapped_surfaces > 0) {
|
2024-02-22 17:41:39 +01:00
|
|
|
windows = malloc(sizeof(*windows) * mapped_surfaces);
|
2024-02-22 13:44:46 +01:00
|
|
|
if (!windows) {
|
|
|
|
return;
|
|
|
|
}
|
2021-05-20 02:48:18 +02:00
|
|
|
|
2024-02-22 13:44:46 +01:00
|
|
|
size_t index = 0;
|
|
|
|
wl_list_for_each(surface, &xwm->surfaces, link) {
|
|
|
|
if (surface->surface != NULL && surface->surface->mapped) {
|
|
|
|
windows[index++] = surface->window_id;
|
|
|
|
}
|
2019-02-13 11:18:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_change_property(xwm->xcb_conn, XCB_PROP_MODE_REPLACE,
|
2020-03-06 12:37:43 +01:00
|
|
|
xwm->screen->root, xwm->atoms[NET_CLIENT_LIST],
|
2019-02-13 11:18:46 +01:00
|
|
|
XCB_ATOM_WINDOW, 32, mapped_surfaces, windows);
|
2021-05-20 02:48:18 +02:00
|
|
|
free(windows);
|
2019-02-13 11:18:46 +01:00
|
|
|
}
|
|
|
|
|
2021-05-02 18:50:36 +02:00
|
|
|
static void xwm_set_net_client_list_stacking(struct wlr_xwm *xwm) {
|
|
|
|
size_t num_surfaces = wl_list_length(&xwm->surfaces_in_stack_order);
|
2021-05-20 02:48:18 +02:00
|
|
|
xcb_window_t *windows = malloc(sizeof(xcb_window_t) * num_surfaces);
|
|
|
|
if (!windows) {
|
|
|
|
return;
|
|
|
|
}
|
2021-05-02 18:50:36 +02:00
|
|
|
|
|
|
|
size_t i = 0;
|
|
|
|
struct wlr_xwayland_surface *xsurface;
|
|
|
|
wl_list_for_each(xsurface, &xwm->surfaces_in_stack_order, stack_link) {
|
|
|
|
windows[i++] = xsurface->window_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_change_property(xwm->xcb_conn, XCB_PROP_MODE_REPLACE, xwm->screen->root,
|
|
|
|
xwm->atoms[NET_CLIENT_LIST_STACKING], XCB_ATOM_WINDOW, 32, num_surfaces,
|
|
|
|
windows);
|
2021-05-20 02:48:18 +02:00
|
|
|
free(windows);
|
2021-05-02 18:50:36 +02:00
|
|
|
}
|
|
|
|
|
2020-07-27 13:41:54 +02:00
|
|
|
static void xsurface_set_net_wm_state(struct wlr_xwayland_surface *xsurface);
|
|
|
|
|
|
|
|
static void xwm_set_focus_window(struct wlr_xwm *xwm,
|
2017-10-29 15:31:01 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface) {
|
2020-07-27 13:41:54 +02:00
|
|
|
struct wlr_xwayland_surface *unfocus_surface = xwm->focus_surface;
|
|
|
|
|
|
|
|
// We handle cases where focus_surface == xsurface because we
|
|
|
|
// want to be able to deny FocusIn events.
|
|
|
|
xwm->focus_surface = xsurface;
|
|
|
|
|
|
|
|
if (unfocus_surface) {
|
|
|
|
xsurface_set_net_wm_state(unfocus_surface);
|
|
|
|
}
|
|
|
|
|
2017-10-29 15:40:16 +01:00
|
|
|
if (!xsurface) {
|
|
|
|
xcb_set_input_focus_checked(xwm->xcb_conn,
|
2017-10-25 14:39:28 +02:00
|
|
|
XCB_INPUT_FOCUS_POINTER_ROOT,
|
|
|
|
XCB_NONE, XCB_CURRENT_TIME);
|
2017-10-29 15:40:16 +01:00
|
|
|
return;
|
2018-06-29 16:22:19 +02:00
|
|
|
}
|
|
|
|
|
2018-06-29 19:25:20 +02:00
|
|
|
if (xsurface->override_redirect) {
|
2017-10-29 15:40:16 +01:00
|
|
|
return;
|
2017-10-25 14:39:28 +02:00
|
|
|
}
|
2017-10-29 15:40:16 +01:00
|
|
|
|
2018-04-08 22:28:01 +02:00
|
|
|
xcb_client_message_data_t message_data = { 0 };
|
|
|
|
message_data.data32[0] = xwm->atoms[WM_TAKE_FOCUS];
|
|
|
|
message_data.data32[1] = XCB_TIME_CURRENT_TIME;
|
2018-06-29 16:22:19 +02:00
|
|
|
|
2018-06-29 19:25:20 +02:00
|
|
|
if (xsurface->hints && !xsurface->hints->input) {
|
|
|
|
// if the surface doesn't allow the focus request, we will send him
|
|
|
|
// only the take focus event. It will get the focus by itself.
|
|
|
|
xwm_send_wm_message(xsurface, &message_data, XCB_EVENT_MASK_NO_EVENT);
|
2018-07-03 15:11:02 +02:00
|
|
|
} else {
|
2018-07-03 15:03:00 +02:00
|
|
|
xwm_send_wm_message(xsurface, &message_data, XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT);
|
2018-06-29 16:22:19 +02:00
|
|
|
|
2020-07-19 14:57:10 +02:00
|
|
|
xcb_void_cookie_t cookie = xcb_set_input_focus(xwm->xcb_conn,
|
|
|
|
XCB_INPUT_FOCUS_POINTER_ROOT, xsurface->window_id, XCB_CURRENT_TIME);
|
|
|
|
xwm->last_focus_seq = cookie.sequence;
|
2018-07-03 15:03:00 +02:00
|
|
|
}
|
2017-10-29 15:40:16 +01:00
|
|
|
|
2020-07-27 13:41:54 +02:00
|
|
|
xsurface_set_net_wm_state(xsurface);
|
2017-10-25 14:39:28 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 20:59:46 +02:00
|
|
|
static void xwm_surface_activate(struct wlr_xwm *xwm,
|
2017-10-25 14:39:28 +02:00
|
|
|
struct wlr_xwayland_surface *xsurface) {
|
2017-10-26 02:40:55 +02:00
|
|
|
if (xwm->focus_surface == xsurface ||
|
|
|
|
(xsurface && xsurface->override_redirect)) {
|
2017-10-25 14:39:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xsurface) {
|
|
|
|
xwm_set_net_active_window(xwm, xsurface->window_id);
|
|
|
|
} else {
|
|
|
|
xwm_set_net_active_window(xwm, XCB_WINDOW_NONE);
|
|
|
|
}
|
|
|
|
|
2020-07-27 13:41:54 +02:00
|
|
|
xwm_set_focus_window(xwm, xsurface);
|
2017-10-25 14:39:28 +02:00
|
|
|
|
|
|
|
xcb_flush(xwm->xcb_conn);
|
|
|
|
}
|
|
|
|
|
2017-10-26 21:58:18 +02:00
|
|
|
static void xsurface_set_net_wm_state(struct wlr_xwayland_surface *xsurface) {
|
|
|
|
struct wlr_xwm *xwm = xsurface->xwm;
|
|
|
|
|
2023-03-11 13:51:52 +01:00
|
|
|
// EWMH says _NET_WM_STATE should be unset if the window is withdrawn
|
|
|
|
if (xsurface->withdrawn) {
|
|
|
|
xcb_delete_property(xwm->xcb_conn,
|
|
|
|
xsurface->window_id,
|
|
|
|
xwm->atoms[NET_WM_STATE]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-27 13:41:54 +02:00
|
|
|
uint32_t property[6];
|
2020-07-21 13:15:00 +02:00
|
|
|
size_t i = 0;
|
2018-09-02 06:23:22 +02:00
|
|
|
if (xsurface->modal) {
|
2020-03-06 12:37:43 +01:00
|
|
|
property[i++] = xwm->atoms[NET_WM_STATE_MODAL];
|
2018-09-02 06:23:22 +02:00
|
|
|
}
|
2017-10-26 21:58:18 +02:00
|
|
|
if (xsurface->fullscreen) {
|
2020-03-06 12:37:43 +01:00
|
|
|
property[i++] = xwm->atoms[NET_WM_STATE_FULLSCREEN];
|
2017-10-26 21:58:18 +02:00
|
|
|
}
|
|
|
|
if (xsurface->maximized_vert) {
|
2020-03-06 12:37:43 +01:00
|
|
|
property[i++] = xwm->atoms[NET_WM_STATE_MAXIMIZED_VERT];
|
2017-10-26 21:58:18 +02:00
|
|
|
}
|
|
|
|
if (xsurface->maximized_horz) {
|
2020-03-06 12:37:43 +01:00
|
|
|
property[i++] = xwm->atoms[NET_WM_STATE_MAXIMIZED_HORZ];
|
2017-10-26 21:58:18 +02:00
|
|
|
}
|
2020-07-18 21:37:02 +02:00
|
|
|
if (xsurface->minimized) {
|
|
|
|
property[i++] = xwm->atoms[NET_WM_STATE_HIDDEN];
|
|
|
|
}
|
2020-07-27 13:41:54 +02:00
|
|
|
if (xsurface == xwm->focus_surface) {
|
|
|
|
property[i++] = xwm->atoms[NET_WM_STATE_FOCUSED];
|
|
|
|
}
|
2020-07-21 13:15:00 +02:00
|
|
|
assert(i <= sizeof(property) / sizeof(property[0]));
|
2017-10-26 21:58:18 +02:00
|
|
|
|
|
|
|
xcb_change_property(xwm->xcb_conn,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
xsurface->window_id,
|
|
|
|
xwm->atoms[NET_WM_STATE],
|
|
|
|
XCB_ATOM_ATOM,
|
|
|
|
32, // format
|
|
|
|
i, property);
|
|
|
|
}
|
2017-10-25 14:39:28 +02:00
|
|
|
|
2022-11-29 17:19:30 +01:00
|
|
|
static void xwayland_surface_dissociate(struct wlr_xwayland_surface *xsurface) {
|
2022-12-22 11:18:47 +01:00
|
|
|
if (xsurface->surface != NULL) {
|
2023-03-08 21:41:49 +01:00
|
|
|
wlr_surface_unmap(xsurface->surface);
|
2023-03-11 12:01:02 +01:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.dissociate, NULL);
|
|
|
|
|
2022-12-22 11:18:47 +01:00
|
|
|
wl_list_remove(&xsurface->surface_commit.link);
|
2023-03-08 21:41:49 +01:00
|
|
|
wl_list_remove(&xsurface->surface_map.link);
|
|
|
|
wl_list_remove(&xsurface->surface_unmap.link);
|
2022-12-22 11:18:47 +01:00
|
|
|
wlr_addon_finish(&xsurface->surface_addon);
|
|
|
|
xsurface->surface = NULL;
|
|
|
|
}
|
|
|
|
|
2022-11-29 17:19:30 +01:00
|
|
|
// Make sure we're not on the unpaired surface list or we
|
|
|
|
// could be assigned a surface during surface creation that
|
|
|
|
// was mapped before this unmap request.
|
|
|
|
wl_list_remove(&xsurface->unpaired_link);
|
|
|
|
wl_list_init(&xsurface->unpaired_link);
|
|
|
|
xsurface->surface_id = 0;
|
2023-02-01 16:04:21 +01:00
|
|
|
xsurface->serial = 0;
|
2023-03-10 14:05:41 +01:00
|
|
|
|
|
|
|
wl_list_remove(&xsurface->stack_link);
|
|
|
|
wl_list_init(&xsurface->stack_link);
|
|
|
|
xwm_set_net_client_list_stacking(xsurface->xwm);
|
2022-11-29 17:19:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void xwayland_surface_destroy(struct wlr_xwayland_surface *xsurface) {
|
2022-12-22 11:18:47 +01:00
|
|
|
xwayland_surface_dissociate(xsurface);
|
2018-04-12 05:09:13 +02:00
|
|
|
|
2023-07-09 11:51:31 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.destroy, NULL);
|
2023-03-11 11:59:13 +01:00
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
if (xsurface == xsurface->xwm->focus_surface) {
|
|
|
|
xwm_surface_activate(xsurface->xwm, NULL);
|
2017-10-25 14:39:28 +02:00
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
wl_list_remove(&xsurface->link);
|
2018-01-14 18:19:37 +01:00
|
|
|
wl_list_remove(&xsurface->parent_link);
|
2017-10-24 20:37:18 +02:00
|
|
|
|
2018-06-25 03:30:51 +02:00
|
|
|
struct wlr_xwayland_surface *child, *next;
|
|
|
|
wl_list_for_each_safe(child, next, &xsurface->children, parent_link) {
|
|
|
|
wl_list_remove(&child->parent_link);
|
|
|
|
wl_list_init(&child->parent_link);
|
2018-10-19 15:03:58 +02:00
|
|
|
child->parent = NULL;
|
2018-06-25 03:30:51 +02:00
|
|
|
}
|
|
|
|
|
2022-10-18 14:31:05 +02:00
|
|
|
wl_list_remove(&xsurface->unpaired_link);
|
2017-10-24 20:37:18 +02:00
|
|
|
|
2018-04-13 05:30:06 +02:00
|
|
|
wl_event_source_remove(xsurface->ping_timer);
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
free(xsurface->title);
|
|
|
|
free(xsurface->class);
|
|
|
|
free(xsurface->instance);
|
2018-09-03 09:07:07 +02:00
|
|
|
free(xsurface->role);
|
2017-10-29 15:31:01 +01:00
|
|
|
free(xsurface->window_type);
|
|
|
|
free(xsurface->protocols);
|
2021-01-29 16:45:44 +01:00
|
|
|
free(xsurface->startup_id);
|
2017-10-29 15:31:01 +01:00
|
|
|
free(xsurface->hints);
|
|
|
|
free(xsurface->size_hints);
|
2022-11-09 22:09:43 +01:00
|
|
|
free(xsurface->strut_partial);
|
2017-10-29 15:31:01 +01:00
|
|
|
free(xsurface);
|
2017-08-20 13:43:04 +02:00
|
|
|
}
|
|
|
|
|
2017-09-29 16:44:22 +02:00
|
|
|
static void read_surface_class(struct wlr_xwm *xwm,
|
|
|
|
struct wlr_xwayland_surface *surface, xcb_get_property_reply_t *reply) {
|
|
|
|
if (reply->type != XCB_ATOM_STRING &&
|
|
|
|
reply->type != xwm->atoms[UTF8_STRING]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t len = xcb_get_property_value_length(reply);
|
|
|
|
char *class = xcb_get_property_value(reply);
|
|
|
|
|
|
|
|
// Unpack two sequentially stored strings: instance, class
|
|
|
|
size_t instance_len = strnlen(class, len);
|
|
|
|
free(surface->instance);
|
|
|
|
if (len > 0 && instance_len < len) {
|
|
|
|
surface->instance = strndup(class, instance_len);
|
|
|
|
class += instance_len + 1;
|
|
|
|
} else {
|
|
|
|
surface->instance = NULL;
|
|
|
|
}
|
|
|
|
free(surface->class);
|
|
|
|
if (len > 0) {
|
|
|
|
surface->class = strndup(class, len);
|
|
|
|
} else {
|
|
|
|
surface->class = NULL;
|
|
|
|
}
|
|
|
|
|
2023-07-09 11:51:31 +02:00
|
|
|
wl_signal_emit_mutable(&surface->events.set_class, NULL);
|
2017-09-29 16:44:22 +02:00
|
|
|
}
|
|
|
|
|
2021-01-29 16:45:44 +01:00
|
|
|
static void read_surface_startup_id(struct wlr_xwm *xwm,
|
|
|
|
struct wlr_xwayland_surface *xsurface,
|
|
|
|
xcb_get_property_reply_t *reply) {
|
|
|
|
if (reply->type != XCB_ATOM_STRING &&
|
|
|
|
reply->type != xwm->atoms[UTF8_STRING]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t len = xcb_get_property_value_length(reply);
|
|
|
|
char *startup_id = xcb_get_property_value(reply);
|
|
|
|
|
|
|
|
free(xsurface->startup_id);
|
|
|
|
if (len > 0) {
|
|
|
|
xsurface->startup_id = strndup(startup_id, len);
|
|
|
|
} else {
|
|
|
|
xsurface->startup_id = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_log(WLR_DEBUG, "XCB_ATOM_NET_STARTUP_ID: %s",
|
|
|
|
xsurface->startup_id ? xsurface->startup_id: "(null)");
|
2023-07-09 11:51:31 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.set_startup_id, NULL);
|
2021-01-29 16:45:44 +01:00
|
|
|
}
|
|
|
|
|
2018-09-03 09:07:07 +02:00
|
|
|
static void read_surface_role(struct wlr_xwm *xwm,
|
|
|
|
struct wlr_xwayland_surface *xsurface,
|
|
|
|
xcb_get_property_reply_t *reply) {
|
|
|
|
if (reply->type != XCB_ATOM_STRING &&
|
|
|
|
reply->type != xwm->atoms[UTF8_STRING]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t len = xcb_get_property_value_length(reply);
|
|
|
|
char *role = xcb_get_property_value(reply);
|
|
|
|
|
|
|
|
free(xsurface->role);
|
|
|
|
if (len > 0) {
|
|
|
|
xsurface->role = strndup(role, len);
|
|
|
|
} else {
|
|
|
|
xsurface->role = NULL;
|
|
|
|
}
|
|
|
|
|
2023-07-09 11:51:31 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.set_role, NULL);
|
2018-09-03 09:07:07 +02:00
|
|
|
}
|
|
|
|
|
2017-09-29 16:44:22 +02:00
|
|
|
static void read_surface_title(struct wlr_xwm *xwm,
|
2017-10-29 15:31:01 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface,
|
|
|
|
xcb_get_property_reply_t *reply) {
|
2017-09-29 16:44:22 +02:00
|
|
|
if (reply->type != XCB_ATOM_STRING &&
|
|
|
|
reply->type != xwm->atoms[UTF8_STRING]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-04 21:44:00 +02:00
|
|
|
bool is_utf8 = reply->type == xwm->atoms[UTF8_STRING];
|
|
|
|
if (!is_utf8 && xsurface->has_utf8_title) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-29 16:44:22 +02:00
|
|
|
|
|
|
|
size_t len = xcb_get_property_value_length(reply);
|
|
|
|
char *title = xcb_get_property_value(reply);
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
free(xsurface->title);
|
2017-09-29 16:44:22 +02:00
|
|
|
if (len > 0) {
|
2017-10-29 15:31:01 +01:00
|
|
|
xsurface->title = strndup(title, len);
|
2017-09-29 16:44:22 +02:00
|
|
|
} else {
|
2017-10-29 15:31:01 +01:00
|
|
|
xsurface->title = NULL;
|
2017-09-29 16:44:22 +02:00
|
|
|
}
|
2018-05-04 21:44:00 +02:00
|
|
|
xsurface->has_utf8_title = is_utf8;
|
2017-09-29 16:44:22 +02:00
|
|
|
|
2023-07-09 11:51:31 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.set_title, NULL);
|
2017-09-29 16:44:22 +02:00
|
|
|
}
|
|
|
|
|
2020-09-19 11:36:33 +02:00
|
|
|
static bool has_parent(struct wlr_xwayland_surface *parent,
|
|
|
|
struct wlr_xwayland_surface *child) {
|
|
|
|
while (parent) {
|
|
|
|
if (child == parent) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = parent->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-29 16:44:22 +02:00
|
|
|
static void read_surface_parent(struct wlr_xwm *xwm,
|
2017-10-29 15:31:01 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface,
|
|
|
|
xcb_get_property_reply_t *reply) {
|
2020-09-19 11:36:33 +02:00
|
|
|
struct wlr_xwayland_surface *found_parent = NULL;
|
2017-09-29 16:44:22 +02:00
|
|
|
if (reply->type != XCB_ATOM_WINDOW) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_window_t *xid = xcb_get_property_value(reply);
|
|
|
|
if (xid != NULL) {
|
2020-09-19 11:36:33 +02:00
|
|
|
found_parent = lookup_surface(xwm, *xid);
|
|
|
|
if (!has_parent(found_parent, xsurface)) {
|
|
|
|
xsurface->parent = found_parent;
|
|
|
|
} else {
|
|
|
|
wlr_log(WLR_INFO, "%p with %p would create a loop", xsurface,
|
|
|
|
found_parent);
|
|
|
|
}
|
2017-09-29 16:44:22 +02:00
|
|
|
} else {
|
2017-10-29 15:31:01 +01:00
|
|
|
xsurface->parent = NULL;
|
2017-09-29 16:44:22 +02:00
|
|
|
}
|
|
|
|
|
2020-09-19 11:36:33 +02:00
|
|
|
|
2018-01-14 18:19:37 +01:00
|
|
|
wl_list_remove(&xsurface->parent_link);
|
|
|
|
if (xsurface->parent != NULL) {
|
|
|
|
wl_list_insert(&xsurface->parent->children, &xsurface->parent_link);
|
|
|
|
} else {
|
|
|
|
wl_list_init(&xsurface->parent_link);
|
|
|
|
}
|
|
|
|
|
2023-07-09 11:51:31 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.set_parent, NULL);
|
2017-09-29 16:44:22 +02:00
|
|
|
}
|
|
|
|
|
2017-09-29 23:03:01 +02:00
|
|
|
static void read_surface_window_type(struct wlr_xwm *xwm,
|
2017-10-29 15:31:01 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface,
|
|
|
|
xcb_get_property_reply_t *reply) {
|
2017-09-29 23:03:01 +02:00
|
|
|
if (reply->type != XCB_ATOM_ATOM) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_atom_t *atoms = xcb_get_property_value(reply);
|
|
|
|
size_t atoms_len = reply->value_len;
|
|
|
|
size_t atoms_size = sizeof(xcb_atom_t) * atoms_len;
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
free(xsurface->window_type);
|
|
|
|
xsurface->window_type = malloc(atoms_size);
|
|
|
|
if (xsurface->window_type == NULL) {
|
2017-09-29 23:03:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-10-29 15:31:01 +01:00
|
|
|
memcpy(xsurface->window_type, atoms, atoms_size);
|
|
|
|
xsurface->window_type_len = atoms_len;
|
2017-09-29 23:03:01 +02:00
|
|
|
|
2023-07-09 11:51:31 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.set_window_type, NULL);
|
2017-09-29 22:43:14 +02:00
|
|
|
}
|
|
|
|
|
2017-09-29 23:18:12 +02:00
|
|
|
static void read_surface_protocols(struct wlr_xwm *xwm,
|
2017-10-29 15:31:01 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface,
|
|
|
|
xcb_get_property_reply_t *reply) {
|
2017-09-29 23:18:12 +02:00
|
|
|
if (reply->type != XCB_ATOM_ATOM) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_atom_t *atoms = xcb_get_property_value(reply);
|
|
|
|
size_t atoms_len = reply->value_len;
|
|
|
|
size_t atoms_size = sizeof(xcb_atom_t) * atoms_len;
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
free(xsurface->protocols);
|
|
|
|
xsurface->protocols = malloc(atoms_size);
|
|
|
|
if (xsurface->protocols == NULL) {
|
2017-09-29 23:18:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-10-29 15:31:01 +01:00
|
|
|
memcpy(xsurface->protocols, atoms, atoms_size);
|
|
|
|
xsurface->protocols_len = atoms_len;
|
2017-09-29 23:18:12 +02:00
|
|
|
}
|
|
|
|
|
2017-10-05 16:24:45 +02:00
|
|
|
static void read_surface_hints(struct wlr_xwm *xwm,
|
2017-10-29 15:31:01 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface,
|
|
|
|
xcb_get_property_reply_t *reply) {
|
2017-10-05 16:24:45 +02:00
|
|
|
// According to the docs, reply->type == xwm->atoms[WM_HINTS]
|
|
|
|
// In practice, reply->type == XCB_ATOM_ATOM
|
|
|
|
if (reply->value_len == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
free(xsurface->hints);
|
2023-10-03 07:51:07 +02:00
|
|
|
xsurface->hints = calloc(1, sizeof(*xsurface->hints));
|
2017-10-29 15:31:01 +01:00
|
|
|
if (xsurface->hints == NULL) {
|
2017-10-05 16:32:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-04-16 19:24:11 +02:00
|
|
|
xcb_icccm_get_wm_hints_from_reply(xsurface->hints, reply);
|
2017-10-05 16:24:45 +02:00
|
|
|
|
2018-10-12 23:53:21 +02:00
|
|
|
if (!(xsurface->hints->flags & XCB_ICCCM_WM_HINT_INPUT)) {
|
|
|
|
// The client didn't specify whether it wants input.
|
|
|
|
// Assume it does.
|
|
|
|
xsurface->hints->input = true;
|
|
|
|
}
|
|
|
|
|
2023-07-09 11:51:31 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.set_hints, NULL);
|
2017-10-05 16:24:45 +02:00
|
|
|
}
|
|
|
|
|
2017-10-02 17:34:55 +02:00
|
|
|
static void read_surface_normal_hints(struct wlr_xwm *xwm,
|
2017-10-29 15:31:01 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface,
|
|
|
|
xcb_get_property_reply_t *reply) {
|
2017-10-05 16:24:45 +02:00
|
|
|
if (reply->type != xwm->atoms[WM_SIZE_HINTS] || reply->value_len == 0) {
|
2017-10-02 17:34:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
free(xsurface->size_hints);
|
2023-10-03 07:51:07 +02:00
|
|
|
xsurface->size_hints = calloc(1, sizeof(*xsurface->size_hints));
|
2017-10-29 15:31:01 +01:00
|
|
|
if (xsurface->size_hints == NULL) {
|
2017-10-05 16:32:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-04-16 19:24:11 +02:00
|
|
|
xcb_icccm_get_wm_size_hints_from_reply(xsurface->size_hints, reply);
|
2017-10-02 17:34:55 +02:00
|
|
|
|
2022-04-16 19:24:11 +02:00
|
|
|
int32_t flags = xsurface->size_hints->flags;
|
|
|
|
bool has_min_size_hints = (flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE) != 0;
|
|
|
|
bool has_base_size_hints = (flags & XCB_ICCCM_SIZE_HINT_BASE_SIZE) != 0;
|
2019-03-03 21:29:35 +01:00
|
|
|
/* ICCCM says that if absent, min size is equal to base size and vice versa */
|
|
|
|
if (!has_min_size_hints && !has_base_size_hints) {
|
2018-10-22 13:49:17 +02:00
|
|
|
xsurface->size_hints->min_width = -1;
|
|
|
|
xsurface->size_hints->min_height = -1;
|
2019-03-03 21:29:35 +01:00
|
|
|
xsurface->size_hints->base_width = -1;
|
|
|
|
xsurface->size_hints->base_height = -1;
|
|
|
|
} else if (!has_base_size_hints) {
|
|
|
|
xsurface->size_hints->base_width = xsurface->size_hints->min_width;
|
|
|
|
xsurface->size_hints->base_height = xsurface->size_hints->min_height;
|
|
|
|
} else if (!has_min_size_hints) {
|
2019-03-04 18:41:45 +01:00
|
|
|
xsurface->size_hints->min_width = xsurface->size_hints->base_width;
|
|
|
|
xsurface->size_hints->min_height = xsurface->size_hints->base_height;
|
2018-10-22 13:49:17 +02:00
|
|
|
}
|
2019-03-03 21:29:35 +01:00
|
|
|
|
2022-04-16 19:24:11 +02:00
|
|
|
if ((flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE) == 0) {
|
2018-10-22 13:49:17 +02:00
|
|
|
xsurface->size_hints->max_width = -1;
|
|
|
|
xsurface->size_hints->max_height = -1;
|
|
|
|
}
|
2017-10-02 17:34:55 +02:00
|
|
|
}
|
2017-10-05 16:49:47 +02:00
|
|
|
|
|
|
|
#define MWM_HINTS_FLAGS_FIELD 0
|
|
|
|
#define MWM_HINTS_DECORATIONS_FIELD 2
|
|
|
|
|
|
|
|
#define MWM_HINTS_DECORATIONS (1 << 1)
|
|
|
|
|
|
|
|
#define MWM_DECOR_ALL (1 << 0)
|
|
|
|
#define MWM_DECOR_BORDER (1 << 1)
|
|
|
|
#define MWM_DECOR_TITLE (1 << 3)
|
|
|
|
|
2017-10-02 17:34:55 +02:00
|
|
|
static void read_surface_motif_hints(struct wlr_xwm *xwm,
|
2017-10-29 15:31:01 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface,
|
|
|
|
xcb_get_property_reply_t *reply) {
|
2017-10-05 11:47:58 +02:00
|
|
|
if (reply->value_len < 5) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t *motif_hints = xcb_get_property_value(reply);
|
2017-10-05 16:49:47 +02:00
|
|
|
if (motif_hints[MWM_HINTS_FLAGS_FIELD] & MWM_HINTS_DECORATIONS) {
|
2017-10-29 15:31:01 +01:00
|
|
|
xsurface->decorations = WLR_XWAYLAND_SURFACE_DECORATIONS_ALL;
|
2017-10-05 16:49:47 +02:00
|
|
|
uint32_t decorations = motif_hints[MWM_HINTS_DECORATIONS_FIELD];
|
|
|
|
if ((decorations & MWM_DECOR_ALL) == 0) {
|
|
|
|
if ((decorations & MWM_DECOR_BORDER) == 0) {
|
2017-10-29 15:31:01 +01:00
|
|
|
xsurface->decorations |=
|
2017-10-05 16:49:47 +02:00
|
|
|
WLR_XWAYLAND_SURFACE_DECORATIONS_NO_BORDER;
|
|
|
|
}
|
|
|
|
if ((decorations & MWM_DECOR_TITLE) == 0) {
|
2017-10-29 15:31:01 +01:00
|
|
|
xsurface->decorations |=
|
2017-10-05 16:49:47 +02:00
|
|
|
WLR_XWAYLAND_SURFACE_DECORATIONS_NO_TITLE;
|
|
|
|
}
|
|
|
|
}
|
2023-07-09 11:51:31 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.set_decorations, NULL);
|
2017-10-05 16:49:47 +02:00
|
|
|
}
|
2017-10-02 17:34:55 +02:00
|
|
|
}
|
|
|
|
|
2022-11-09 22:09:43 +01:00
|
|
|
static void read_surface_strut_partial(struct wlr_xwm *xwm,
|
|
|
|
struct wlr_xwayland_surface *xsurface,
|
|
|
|
xcb_get_property_reply_t *reply) {
|
|
|
|
if (reply->type != XCB_ATOM_CARDINAL || reply->format != 32 ||
|
|
|
|
xcb_get_property_value_length(reply) !=
|
|
|
|
sizeof(xcb_ewmh_wm_strut_partial_t)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(xsurface->strut_partial);
|
2023-10-03 07:51:07 +02:00
|
|
|
xsurface->strut_partial = calloc(1, sizeof(*xsurface->strut_partial));
|
2022-11-09 22:09:43 +01:00
|
|
|
if (xsurface->strut_partial == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
xcb_ewmh_get_wm_strut_partial_from_reply(xsurface->strut_partial, reply);
|
2023-07-09 11:51:31 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.set_strut_partial, NULL);
|
2022-11-09 22:09:43 +01:00
|
|
|
}
|
|
|
|
|
2017-10-27 19:05:14 +02:00
|
|
|
static void read_surface_net_wm_state(struct wlr_xwm *xwm,
|
2017-10-29 15:31:01 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface,
|
|
|
|
xcb_get_property_reply_t *reply) {
|
2017-10-27 19:05:14 +02:00
|
|
|
xsurface->fullscreen = 0;
|
|
|
|
xcb_atom_t *atom = xcb_get_property_value(reply);
|
|
|
|
for (uint32_t i = 0; i < reply->value_len; i++) {
|
2020-03-06 12:37:43 +01:00
|
|
|
if (atom[i] == xwm->atoms[NET_WM_STATE_MODAL]) {
|
2018-09-02 06:23:22 +02:00
|
|
|
xsurface->modal = true;
|
2020-03-06 12:37:43 +01:00
|
|
|
} else if (atom[i] == xwm->atoms[NET_WM_STATE_FULLSCREEN]) {
|
2017-10-27 19:05:14 +02:00
|
|
|
xsurface->fullscreen = true;
|
2020-03-06 12:37:43 +01:00
|
|
|
} else if (atom[i] == xwm->atoms[NET_WM_STATE_MAXIMIZED_VERT]) {
|
2017-10-27 19:05:14 +02:00
|
|
|
xsurface->maximized_vert = true;
|
2020-03-06 12:37:43 +01:00
|
|
|
} else if (atom[i] == xwm->atoms[NET_WM_STATE_MAXIMIZED_HORZ]) {
|
2017-10-27 19:05:14 +02:00
|
|
|
xsurface->maximized_horz = true;
|
2020-07-18 21:37:02 +02:00
|
|
|
} else if (atom[i] == xwm->atoms[NET_WM_STATE_HIDDEN]) {
|
|
|
|
xsurface->minimized = true;
|
2018-01-21 16:28:21 +01:00
|
|
|
}
|
2017-10-27 19:05:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-29 03:36:53 +02:00
|
|
|
char *xwm_get_atom_name(struct wlr_xwm *xwm, xcb_atom_t atom) {
|
2018-03-28 21:45:15 +02:00
|
|
|
xcb_get_atom_name_cookie_t name_cookie =
|
|
|
|
xcb_get_atom_name(xwm->xcb_conn, atom);
|
|
|
|
xcb_get_atom_name_reply_t *name_reply =
|
|
|
|
xcb_get_atom_name_reply(xwm->xcb_conn, name_cookie, NULL);
|
|
|
|
if (name_reply == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
size_t len = xcb_get_atom_name_name_length(name_reply);
|
|
|
|
char *buf = xcb_get_atom_name_name(name_reply); // not a C string
|
2018-04-03 16:36:22 +02:00
|
|
|
char *name = strndup(buf, len);
|
2018-03-28 21:45:15 +02:00
|
|
|
free(name_reply);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2017-09-29 15:57:21 +02:00
|
|
|
static void read_surface_property(struct wlr_xwm *xwm,
|
2023-07-28 12:19:06 +02:00
|
|
|
struct wlr_xwayland_surface *xsurface, xcb_atom_t property,
|
|
|
|
xcb_get_property_reply_t *reply) {
|
2017-09-29 15:57:21 +02:00
|
|
|
if (property == XCB_ATOM_WM_CLASS) {
|
2017-10-29 15:31:01 +01:00
|
|
|
read_surface_class(xwm, xsurface, reply);
|
2017-09-29 15:57:21 +02:00
|
|
|
} else if (property == XCB_ATOM_WM_NAME ||
|
|
|
|
property == xwm->atoms[NET_WM_NAME]) {
|
2017-10-29 15:31:01 +01:00
|
|
|
read_surface_title(xwm, xsurface, reply);
|
2017-09-29 16:44:22 +02:00
|
|
|
} else if (property == XCB_ATOM_WM_TRANSIENT_FOR) {
|
2017-10-29 15:31:01 +01:00
|
|
|
read_surface_parent(xwm, xsurface, reply);
|
2017-09-29 22:43:14 +02:00
|
|
|
} else if (property == xwm->atoms[NET_WM_PID]) {
|
2021-04-17 21:23:27 +02:00
|
|
|
// intentionally ignored
|
2017-09-29 23:03:01 +02:00
|
|
|
} else if (property == xwm->atoms[NET_WM_WINDOW_TYPE]) {
|
2017-10-29 15:31:01 +01:00
|
|
|
read_surface_window_type(xwm, xsurface, reply);
|
2017-09-29 23:18:12 +02:00
|
|
|
} else if (property == xwm->atoms[WM_PROTOCOLS]) {
|
2017-10-29 15:31:01 +01:00
|
|
|
read_surface_protocols(xwm, xsurface, reply);
|
2017-09-29 22:26:03 +02:00
|
|
|
} else if (property == xwm->atoms[NET_WM_STATE]) {
|
2017-10-29 15:31:01 +01:00
|
|
|
read_surface_net_wm_state(xwm, xsurface, reply);
|
2017-10-05 16:24:45 +02:00
|
|
|
} else if (property == xwm->atoms[WM_HINTS]) {
|
2017-10-29 15:31:01 +01:00
|
|
|
read_surface_hints(xwm, xsurface, reply);
|
2017-10-02 17:34:55 +02:00
|
|
|
} else if (property == xwm->atoms[WM_NORMAL_HINTS]) {
|
2017-10-29 15:31:01 +01:00
|
|
|
read_surface_normal_hints(xwm, xsurface, reply);
|
2017-10-02 17:34:55 +02:00
|
|
|
} else if (property == xwm->atoms[MOTIF_WM_HINTS]) {
|
2017-10-29 15:31:01 +01:00
|
|
|
read_surface_motif_hints(xwm, xsurface, reply);
|
2022-11-09 22:09:43 +01:00
|
|
|
} else if (property == xwm->atoms[NET_WM_STRUT_PARTIAL]) {
|
|
|
|
read_surface_strut_partial(xwm, xsurface, reply);
|
2018-09-03 09:07:07 +02:00
|
|
|
} else if (property == xwm->atoms[WM_WINDOW_ROLE]) {
|
|
|
|
read_surface_role(xwm, xsurface, reply);
|
2021-01-29 16:45:44 +01:00
|
|
|
} else if (property == xwm->atoms[NET_STARTUP_ID]) {
|
|
|
|
read_surface_startup_id(xwm, xsurface, reply);
|
2023-07-28 14:21:37 +02:00
|
|
|
} else if (wlr_log_get_verbosity() >= WLR_DEBUG) {
|
2018-03-29 03:36:53 +02:00
|
|
|
char *prop_name = xwm_get_atom_name(xwm, property);
|
2020-06-04 14:33:32 +02:00
|
|
|
wlr_log(WLR_DEBUG, "unhandled X11 property %" PRIu32 " (%s) for window %" PRIu32,
|
|
|
|
property, prop_name ? prop_name : "(null)", xsurface->window_id);
|
2018-03-28 21:45:15 +02:00
|
|
|
free(prop_name);
|
2017-09-29 15:57:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-29 17:19:30 +01:00
|
|
|
static void xwayland_surface_handle_commit(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_xwayland_surface *xsurface = wl_container_of(listener, xsurface, surface_commit);
|
2023-06-02 21:44:21 +02:00
|
|
|
if (wlr_surface_has_buffer(xsurface->surface)) {
|
|
|
|
wlr_surface_map(xsurface->surface);
|
|
|
|
}
|
2022-11-29 17:19:30 +01:00
|
|
|
}
|
2018-07-10 00:02:03 +02:00
|
|
|
|
2023-03-08 21:41:49 +01:00
|
|
|
static void xwayland_surface_handle_map(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_xwayland_surface *xsurface = wl_container_of(listener, xsurface, surface_map);
|
|
|
|
xwm_set_net_client_list(xsurface->xwm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xwayland_surface_handle_unmap(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_xwayland_surface *xsurface = wl_container_of(listener, xsurface, surface_unmap);
|
|
|
|
xwm_set_net_client_list(xsurface->xwm);
|
2018-07-10 00:02:03 +02:00
|
|
|
}
|
|
|
|
|
2022-11-29 17:19:30 +01:00
|
|
|
static void xwayland_surface_handle_addon_destroy(struct wlr_addon *addon) {
|
|
|
|
struct wlr_xwayland_surface *xsurface = wl_container_of(addon, xsurface, surface_addon);
|
|
|
|
xwayland_surface_dissociate(xsurface);
|
2022-11-06 11:39:34 +01:00
|
|
|
}
|
|
|
|
|
2022-11-29 17:19:30 +01:00
|
|
|
static const struct wlr_addon_interface surface_addon_impl = {
|
2018-07-07 23:45:16 +02:00
|
|
|
.name = "wlr_xwayland_surface",
|
2022-11-29 17:19:30 +01:00
|
|
|
.destroy = xwayland_surface_handle_addon_destroy,
|
2018-07-07 23:45:16 +02:00
|
|
|
};
|
|
|
|
|
2022-11-29 17:03:19 +01:00
|
|
|
static void xwayland_surface_associate(struct wlr_xwm *xwm,
|
2018-04-13 05:30:06 +02:00
|
|
|
struct wlr_xwayland_surface *xsurface, struct wlr_surface *surface) {
|
2022-12-22 15:44:15 +01:00
|
|
|
assert(xsurface->surface == NULL);
|
|
|
|
|
2022-10-18 14:31:05 +02:00
|
|
|
wl_list_remove(&xsurface->unpaired_link);
|
|
|
|
wl_list_init(&xsurface->unpaired_link);
|
|
|
|
xsurface->surface_id = 0;
|
|
|
|
|
2017-10-24 18:00:43 +02:00
|
|
|
xsurface->surface = surface;
|
2022-11-29 17:19:30 +01:00
|
|
|
wlr_addon_init(&xsurface->surface_addon, &surface->addons, NULL, &surface_addon_impl);
|
|
|
|
|
|
|
|
xsurface->surface_commit.notify = xwayland_surface_handle_commit;
|
|
|
|
wl_signal_add(&surface->events.commit, &xsurface->surface_commit);
|
|
|
|
|
2023-03-08 21:41:49 +01:00
|
|
|
xsurface->surface_map.notify = xwayland_surface_handle_map;
|
|
|
|
wl_signal_add(&surface->events.map, &xsurface->surface_map);
|
|
|
|
|
|
|
|
xsurface->surface_unmap.notify = xwayland_surface_handle_unmap;
|
|
|
|
wl_signal_add(&surface->events.unmap, &xsurface->surface_unmap);
|
2017-08-20 13:43:04 +02:00
|
|
|
|
2017-09-29 15:57:21 +02:00
|
|
|
// read all surface properties
|
|
|
|
const xcb_atom_t props[] = {
|
|
|
|
XCB_ATOM_WM_CLASS,
|
|
|
|
XCB_ATOM_WM_NAME,
|
|
|
|
XCB_ATOM_WM_TRANSIENT_FOR,
|
2017-09-29 23:18:12 +02:00
|
|
|
xwm->atoms[WM_PROTOCOLS],
|
2017-10-05 16:24:45 +02:00
|
|
|
xwm->atoms[WM_HINTS],
|
2017-10-02 17:34:55 +02:00
|
|
|
xwm->atoms[WM_NORMAL_HINTS],
|
|
|
|
xwm->atoms[MOTIF_WM_HINTS],
|
2021-01-29 16:45:44 +01:00
|
|
|
xwm->atoms[NET_STARTUP_ID],
|
2017-09-29 22:26:03 +02:00
|
|
|
xwm->atoms[NET_WM_STATE],
|
2022-11-09 22:09:43 +01:00
|
|
|
xwm->atoms[NET_WM_STRUT_PARTIAL],
|
2017-09-29 23:03:01 +02:00
|
|
|
xwm->atoms[NET_WM_WINDOW_TYPE],
|
2017-09-29 22:26:03 +02:00
|
|
|
xwm->atoms[NET_WM_NAME],
|
2017-09-29 15:57:21 +02:00
|
|
|
};
|
2023-07-28 12:19:06 +02:00
|
|
|
|
|
|
|
xcb_get_property_cookie_t cookies[sizeof(props) / sizeof(props[0])] = {0};
|
|
|
|
for (size_t i = 0; i < sizeof(props) / sizeof(props[0]); i++) {
|
|
|
|
cookies[i] = xcb_get_property(xwm->xcb_conn, 0, xsurface->window_id,
|
|
|
|
props[i], XCB_ATOM_ANY, 0, 2048);
|
2017-09-29 15:57:21 +02:00
|
|
|
}
|
2023-07-28 12:19:06 +02:00
|
|
|
|
|
|
|
for (size_t i = 0; i < sizeof(props) / sizeof(props[0]); i++) {
|
|
|
|
xcb_get_property_reply_t *reply =
|
|
|
|
xcb_get_property_reply(xwm->xcb_conn, cookies[i], NULL);
|
|
|
|
if (reply == NULL) {
|
|
|
|
wlr_log(WLR_ERROR, "Failed to get window property");
|
2024-01-24 10:42:18 +01:00
|
|
|
continue;
|
2023-07-28 12:19:06 +02:00
|
|
|
}
|
|
|
|
read_surface_property(xwm, xsurface, props[i], reply);
|
|
|
|
free(reply);
|
|
|
|
}
|
|
|
|
|
2023-03-11 12:01:02 +01:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.associate, NULL);
|
2018-04-12 05:09:13 +02:00
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
static void xwm_handle_create_notify(struct wlr_xwm *xwm,
|
2017-09-28 23:26:31 +02:00
|
|
|
xcb_create_notify_event_t *ev) {
|
2018-04-13 05:30:06 +02:00
|
|
|
if (ev->window == xwm->window ||
|
xwayland/selection: use one target window per selection
Previously, the clipboard and primary selections shared the same window.
This was racey, and could have led to pasting failures.
On xfixes selection owner change notification, the logic for requesting
the supported mimetypes of the new owner's selection looks like:
xcb_convert_selection(
xwm->xcb_conn,
selection->window,
selection->atom,
xwm->atoms[TARGETS],
xwm->atoms[WL_SELECTION],
selection->timestamp
);
This means ask the selection owner to write its TARGETS for the
`selection->atom` selection (one of PRIMARY, CLIPBOARD, DND_SELECTION)
to `selection->window`'s WL_SELECTION atom.
However, `selection->window` is shared for both PRIMARY and CLIPBOARD
selections, and WL_SELECTION is used as the target atom in both cases.
So, there's a race when both selections change at the same time.
The CLIPBOARD selection might support mimetypes {A, B, C}, and the
PRIMARY only {A, B}. If the ConvertSelection requests/responses "cross
on the wire", so to speak, wlroots can end up believing that the PRIMARY
selection also supports C.
A Wayland client may then ask for the PRIMARY selection in C format,
which will fail with "convert selection failed".
This commit fixes this by using a separate window for PRIMARY and
CLIPBOARD target requests, so that WL_SELECTION can be used as the
target atom in both cases.
2021-02-03 06:16:15 +01:00
|
|
|
ev->window == xwm->primary_selection.window ||
|
|
|
|
ev->window == xwm->clipboard_selection.window ||
|
|
|
|
ev->window == xwm->dnd_selection.window) {
|
2018-04-13 05:30:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xwayland_surface_create(xwm, ev->window, ev->x, ev->y,
|
2017-08-23 23:19:15 +02:00
|
|
|
ev->width, ev->height, ev->override_redirect);
|
2017-08-20 13:43:04 +02:00
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
static void xwm_handle_destroy_notify(struct wlr_xwm *xwm,
|
2017-09-28 23:26:31 +02:00
|
|
|
xcb_destroy_notify_event_t *ev) {
|
2017-10-29 15:31:01 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window);
|
|
|
|
if (xsurface == NULL) {
|
2017-08-20 13:43:04 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-04-26 00:51:00 +02:00
|
|
|
xwayland_surface_destroy(xsurface);
|
2020-07-03 04:25:25 +02:00
|
|
|
xwm_handle_selection_destroy_notify(xwm, ev);
|
2017-08-20 13:43:04 +02:00
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
static void xwm_handle_configure_request(struct wlr_xwm *xwm,
|
2017-09-28 23:26:31 +02:00
|
|
|
xcb_configure_request_event_t *ev) {
|
2018-04-26 23:18:31 +02:00
|
|
|
struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window);
|
|
|
|
if (surface == NULL) {
|
2017-08-20 13:43:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-29 18:28:38 +02:00
|
|
|
// TODO: handle ev->{parent,sibling}?
|
2017-08-20 14:18:43 +02:00
|
|
|
|
2018-10-18 14:31:08 +02:00
|
|
|
uint16_t mask = ev->value_mask;
|
|
|
|
uint16_t geo_mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
|
|
|
|
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
|
|
|
|
if ((mask & geo_mask) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-26 23:18:31 +02:00
|
|
|
struct wlr_xwayland_surface_configure_event wlr_event = {
|
|
|
|
.surface = surface,
|
2018-10-18 14:31:08 +02:00
|
|
|
.x = mask & XCB_CONFIG_WINDOW_X ? ev->x : surface->x,
|
|
|
|
.y = mask & XCB_CONFIG_WINDOW_Y ? ev->y : surface->y,
|
|
|
|
.width = mask & XCB_CONFIG_WINDOW_WIDTH ? ev->width : surface->width,
|
|
|
|
.height = mask & XCB_CONFIG_WINDOW_HEIGHT ? ev->height : surface->height,
|
2019-10-08 18:23:10 +02:00
|
|
|
.mask = mask,
|
2018-04-26 23:18:31 +02:00
|
|
|
};
|
2017-09-29 18:28:38 +02:00
|
|
|
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&surface->events.request_configure, &wlr_event);
|
2017-08-20 13:43:04 +02:00
|
|
|
}
|
|
|
|
|
2023-03-10 14:05:41 +01:00
|
|
|
static void xwm_update_override_redirect(struct wlr_xwayland_surface *xsurface,
|
|
|
|
bool override_redirect) {
|
|
|
|
if (xsurface->override_redirect == override_redirect) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
xsurface->override_redirect = override_redirect;
|
|
|
|
|
|
|
|
if (override_redirect) {
|
|
|
|
wl_list_remove(&xsurface->stack_link);
|
|
|
|
wl_list_init(&xsurface->stack_link);
|
|
|
|
xwm_set_net_client_list_stacking(xsurface->xwm);
|
|
|
|
} else if (xsurface->surface != NULL && xsurface->surface->mapped) {
|
|
|
|
wlr_xwayland_surface_restack(xsurface, NULL, XCB_STACK_MODE_BELOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_signal_emit_mutable(&xsurface->events.set_override_redirect, NULL);
|
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
static void xwm_handle_configure_notify(struct wlr_xwm *xwm,
|
2017-10-24 19:57:10 +02:00
|
|
|
xcb_configure_notify_event_t *ev) {
|
2018-07-18 19:51:03 +02:00
|
|
|
struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window);
|
2017-10-24 19:57:10 +02:00
|
|
|
if (!xsurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-14 11:47:23 +02:00
|
|
|
bool geometry_changed =
|
|
|
|
(xsurface->x != ev->x || xsurface->y != ev->y ||
|
|
|
|
xsurface->width != ev->width || xsurface->height != ev->height);
|
|
|
|
|
|
|
|
if (geometry_changed) {
|
|
|
|
xsurface->x = ev->x;
|
|
|
|
xsurface->y = ev->y;
|
|
|
|
xsurface->width = ev->width;
|
|
|
|
xsurface->height = ev->height;
|
|
|
|
}
|
2018-07-18 19:51:03 +02:00
|
|
|
|
2023-03-10 14:05:41 +01:00
|
|
|
xwm_update_override_redirect(xsurface, ev->override_redirect);
|
2020-10-14 11:47:23 +02:00
|
|
|
|
|
|
|
if (geometry_changed) {
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.set_geometry, NULL);
|
2020-10-14 11:47:23 +02:00
|
|
|
}
|
2017-10-24 19:57:10 +02:00
|
|
|
}
|
|
|
|
|
2023-03-11 13:51:52 +01:00
|
|
|
static void xsurface_set_wm_state(struct wlr_xwayland_surface *xsurface) {
|
2017-10-26 17:39:08 +02:00
|
|
|
struct wlr_xwm *xwm = xsurface->xwm;
|
2023-03-11 13:51:52 +01:00
|
|
|
uint32_t property[] = { XCB_ICCCM_WM_STATE_NORMAL, XCB_WINDOW_NONE };
|
|
|
|
|
|
|
|
if (xsurface->withdrawn) {
|
|
|
|
property[0] = XCB_ICCCM_WM_STATE_WITHDRAWN;
|
|
|
|
} else if (xsurface->minimized) {
|
|
|
|
property[0] = XCB_ICCCM_WM_STATE_ICONIC;
|
|
|
|
} else {
|
|
|
|
property[0] = XCB_ICCCM_WM_STATE_NORMAL;
|
|
|
|
}
|
2017-10-26 17:39:08 +02:00
|
|
|
|
|
|
|
xcb_change_property(xwm->xcb_conn,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
xsurface->window_id,
|
2017-11-19 23:55:02 +01:00
|
|
|
xwm->atoms[WM_STATE],
|
|
|
|
xwm->atoms[WM_STATE],
|
2017-10-26 17:39:08 +02:00
|
|
|
32, // format
|
2020-07-21 13:16:28 +02:00
|
|
|
sizeof(property) / sizeof(property[0]), property);
|
2017-10-26 17:39:08 +02:00
|
|
|
}
|
|
|
|
|
2021-05-02 18:50:36 +02:00
|
|
|
void wlr_xwayland_surface_restack(struct wlr_xwayland_surface *xsurface,
|
|
|
|
struct wlr_xwayland_surface *sibling, enum xcb_stack_mode_t mode) {
|
|
|
|
struct wlr_xwm *xwm = xsurface->xwm;
|
|
|
|
uint32_t values[2];
|
|
|
|
size_t idx = 0;
|
|
|
|
uint32_t flags = XCB_CONFIG_WINDOW_STACK_MODE;
|
|
|
|
|
2023-03-10 13:49:47 +01:00
|
|
|
assert(!xsurface->override_redirect);
|
|
|
|
|
|
|
|
// X11 clients expect their override_redirect windows to stay on top.
|
|
|
|
// Avoid interfering by restacking above the topmost managed surface.
|
|
|
|
if (mode == XCB_STACK_MODE_ABOVE && !sibling) {
|
|
|
|
sibling = wl_container_of(xwm->surfaces_in_stack_order.prev, sibling, stack_link);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sibling == xsurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-02 18:50:36 +02:00
|
|
|
if (sibling != NULL) {
|
|
|
|
values[idx++] = sibling->window_id;
|
|
|
|
flags |= XCB_CONFIG_WINDOW_SIBLING;
|
|
|
|
}
|
|
|
|
values[idx++] = mode;
|
|
|
|
|
|
|
|
xcb_configure_window(xwm->xcb_conn, xsurface->window_id, flags, values);
|
|
|
|
|
|
|
|
wl_list_remove(&xsurface->stack_link);
|
|
|
|
|
|
|
|
struct wl_list *node;
|
|
|
|
if (mode == XCB_STACK_MODE_ABOVE) {
|
2023-03-10 13:49:47 +01:00
|
|
|
node = &sibling->stack_link;
|
2021-05-02 18:50:36 +02:00
|
|
|
} else if (mode == XCB_STACK_MODE_BELOW) {
|
|
|
|
if (sibling) {
|
|
|
|
node = sibling->stack_link.prev;
|
|
|
|
} else {
|
|
|
|
node = &xwm->surfaces_in_stack_order;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Not implementing XCB_STACK_MODE_TOP_IF | XCB_STACK_MODE_BOTTOM_IF |
|
|
|
|
// XCB_STACK_MODE_OPPOSITE.
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_insert(node, &xsurface->stack_link);
|
|
|
|
xwm_set_net_client_list_stacking(xwm);
|
|
|
|
xcb_flush(xwm->xcb_conn);
|
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
static void xwm_handle_map_request(struct wlr_xwm *xwm,
|
2017-09-28 23:26:31 +02:00
|
|
|
xcb_map_request_event_t *ev) {
|
2017-10-26 17:39:08 +02:00
|
|
|
struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window);
|
|
|
|
if (!xsurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-13 00:37:55 +01:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.map_request, NULL);
|
2017-10-24 19:24:26 +02:00
|
|
|
xcb_map_window(xwm->xcb_conn, ev->window);
|
2017-08-20 13:43:04 +02:00
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
static void xwm_handle_map_notify(struct wlr_xwm *xwm,
|
|
|
|
xcb_map_notify_event_t *ev) {
|
2018-07-18 19:51:03 +02:00
|
|
|
struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window);
|
|
|
|
if (!xsurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-10 14:05:41 +01:00
|
|
|
xwm_update_override_redirect(xsurface, ev->override_redirect);
|
2023-11-26 00:49:56 +01:00
|
|
|
|
|
|
|
if (!xsurface->override_redirect) {
|
|
|
|
wlr_xwayland_surface_set_withdrawn(xsurface, false);
|
|
|
|
wlr_xwayland_surface_restack(xsurface, NULL, XCB_STACK_MODE_BELOW);
|
|
|
|
}
|
2017-08-20 13:43:04 +02:00
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
static void xwm_handle_unmap_notify(struct wlr_xwm *xwm,
|
2017-09-28 23:26:31 +02:00
|
|
|
xcb_unmap_notify_event_t *ev) {
|
2017-10-25 00:57:20 +02:00
|
|
|
struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window);
|
|
|
|
if (xsurface == NULL) {
|
2017-08-20 13:43:04 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-10-25 00:57:20 +02:00
|
|
|
|
2022-12-22 11:18:47 +01:00
|
|
|
xwayland_surface_dissociate(xsurface);
|
2022-11-06 11:39:34 +01:00
|
|
|
|
2023-03-11 13:51:52 +01:00
|
|
|
if (!xsurface->override_redirect) {
|
|
|
|
wlr_xwayland_surface_set_withdrawn(xsurface, true);
|
|
|
|
}
|
2017-08-20 13:43:04 +02:00
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
static void xwm_handle_property_notify(struct wlr_xwm *xwm,
|
2017-09-28 23:26:31 +02:00
|
|
|
xcb_property_notify_event_t *ev) {
|
2017-10-29 15:31:01 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window);
|
|
|
|
if (xsurface == NULL) {
|
2017-09-29 15:57:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-28 12:19:06 +02:00
|
|
|
xcb_get_property_cookie_t cookie =
|
|
|
|
xcb_get_property(xwm->xcb_conn, 0, xsurface->window_id, ev->atom, XCB_ATOM_ANY, 0, 2048);
|
|
|
|
xcb_get_property_reply_t *reply =
|
|
|
|
xcb_get_property_reply(xwm->xcb_conn, cookie, NULL);
|
|
|
|
if (reply == NULL) {
|
|
|
|
wlr_log(WLR_ERROR, "Failed to get window property");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
read_surface_property(xwm, xsurface, ev->atom, reply);
|
2023-10-10 05:47:58 +02:00
|
|
|
free(reply);
|
2017-08-20 13:43:04 +02:00
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
static void xwm_handle_surface_id_message(struct wlr_xwm *xwm,
|
2017-10-26 15:01:53 +02:00
|
|
|
xcb_client_message_event_t *ev) {
|
|
|
|
struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window);
|
|
|
|
if (xsurface == NULL) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG,
|
2017-10-26 15:01:53 +02:00
|
|
|
"client message WL_SURFACE_ID but no new window %u ?",
|
|
|
|
ev->window);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Check if we got notified after wayland surface create event */
|
|
|
|
uint32_t id = ev->data.data32[0];
|
|
|
|
struct wl_resource *resource =
|
2020-05-05 10:24:08 +02:00
|
|
|
wl_client_get_object(xwm->xwayland->server->client, id);
|
2017-10-26 15:01:53 +02:00
|
|
|
if (resource) {
|
2018-02-13 23:48:46 +01:00
|
|
|
struct wlr_surface *surface = wlr_surface_from_resource(resource);
|
2022-11-29 17:03:19 +01:00
|
|
|
xwayland_surface_associate(xwm, xsurface, surface);
|
2017-10-26 15:01:53 +02:00
|
|
|
} else {
|
|
|
|
xsurface->surface_id = id;
|
2022-10-18 14:31:05 +02:00
|
|
|
wl_list_remove(&xsurface->unpaired_link);
|
2017-10-26 15:01:53 +02:00
|
|
|
wl_list_insert(&xwm->unpaired_surfaces, &xsurface->unpaired_link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-18 13:09:17 +02:00
|
|
|
static void xwm_handle_surface_serial_message(struct wlr_xwm *xwm,
|
|
|
|
xcb_client_message_event_t *ev) {
|
|
|
|
struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window);
|
|
|
|
if (xsurface == NULL) {
|
|
|
|
wlr_log(WLR_DEBUG,
|
|
|
|
"Received client message WL_SURFACE_SERIAL but no X11 window %u",
|
|
|
|
ev->window);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (xsurface->serial != 0) {
|
|
|
|
wlr_log(WLR_DEBUG, "Received multiple client messages WL_SURFACE_SERIAL "
|
|
|
|
"for the same X11 window %u", ev->window);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t serial_lo = ev->data.data32[0];
|
|
|
|
uint32_t serial_hi = ev->data.data32[1];
|
|
|
|
xsurface->serial = ((uint64_t)serial_hi << 32) | serial_lo;
|
|
|
|
|
|
|
|
struct wlr_surface *surface = wlr_xwayland_shell_v1_surface_from_serial(
|
|
|
|
xwm->xwayland->shell_v1, xsurface->serial);
|
|
|
|
if (surface != NULL) {
|
2022-11-29 17:03:19 +01:00
|
|
|
xwayland_surface_associate(xwm, xsurface, surface);
|
2022-10-18 13:09:17 +02:00
|
|
|
} else {
|
|
|
|
wl_list_remove(&xsurface->unpaired_link);
|
|
|
|
wl_list_insert(&xwm->unpaired_surfaces, &xsurface->unpaired_link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:31:23 +01:00
|
|
|
#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
|
|
|
|
#define _NET_WM_MOVERESIZE_SIZE_TOP 1
|
|
|
|
#define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
|
|
|
|
#define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
|
|
|
|
#define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
|
|
|
|
#define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
|
|
|
|
#define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
|
|
|
|
#define _NET_WM_MOVERESIZE_SIZE_LEFT 7
|
|
|
|
#define _NET_WM_MOVERESIZE_MOVE 8 // movement only
|
|
|
|
#define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 // size via keyboard
|
|
|
|
#define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 // move via keyboard
|
|
|
|
#define _NET_WM_MOVERESIZE_CANCEL 11 // cancel operation
|
2017-10-27 16:48:09 +02:00
|
|
|
|
2017-12-07 18:04:02 +01:00
|
|
|
static enum wlr_edges net_wm_edges_to_wlr(uint32_t net_wm_edges) {
|
|
|
|
switch(net_wm_edges) {
|
2020-11-03 15:31:23 +01:00
|
|
|
case _NET_WM_MOVERESIZE_SIZE_TOPLEFT:
|
2022-10-18 22:57:15 +02:00
|
|
|
return WLR_EDGE_TOP | WLR_EDGE_LEFT;
|
2020-11-03 15:31:23 +01:00
|
|
|
case _NET_WM_MOVERESIZE_SIZE_TOP:
|
2022-10-18 22:57:15 +02:00
|
|
|
return WLR_EDGE_TOP;
|
2020-11-03 15:31:23 +01:00
|
|
|
case _NET_WM_MOVERESIZE_SIZE_TOPRIGHT:
|
2022-10-18 22:57:15 +02:00
|
|
|
return WLR_EDGE_TOP | WLR_EDGE_RIGHT;
|
2020-11-03 15:31:23 +01:00
|
|
|
case _NET_WM_MOVERESIZE_SIZE_RIGHT:
|
2022-10-18 22:57:15 +02:00
|
|
|
return WLR_EDGE_RIGHT;
|
2020-11-03 15:31:23 +01:00
|
|
|
case _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT:
|
2022-10-18 22:57:15 +02:00
|
|
|
return WLR_EDGE_BOTTOM | WLR_EDGE_RIGHT;
|
2020-11-03 15:31:23 +01:00
|
|
|
case _NET_WM_MOVERESIZE_SIZE_BOTTOM:
|
2022-10-18 22:57:15 +02:00
|
|
|
return WLR_EDGE_BOTTOM;
|
2020-11-03 15:31:23 +01:00
|
|
|
case _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT:
|
2022-10-18 22:57:15 +02:00
|
|
|
return WLR_EDGE_BOTTOM | WLR_EDGE_LEFT;
|
2020-11-03 15:31:23 +01:00
|
|
|
case _NET_WM_MOVERESIZE_SIZE_LEFT:
|
2022-10-18 22:57:15 +02:00
|
|
|
return WLR_EDGE_LEFT;
|
2020-11-03 15:31:23 +01:00
|
|
|
default:
|
2022-10-18 22:57:15 +02:00
|
|
|
return WLR_EDGE_NONE;
|
2017-12-07 18:04:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
static void xwm_handle_net_wm_moveresize_message(struct wlr_xwm *xwm,
|
2017-10-26 15:01:53 +02:00
|
|
|
xcb_client_message_event_t *ev) {
|
2017-10-27 16:48:09 +02:00
|
|
|
struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window);
|
|
|
|
if (!xsurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int detail = ev->data.data32[2];
|
|
|
|
switch (detail) {
|
|
|
|
case _NET_WM_MOVERESIZE_MOVE:
|
2023-07-09 11:47:50 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.request_move, NULL);
|
2017-10-27 16:48:09 +02:00
|
|
|
break;
|
|
|
|
case _NET_WM_MOVERESIZE_SIZE_TOPLEFT:
|
|
|
|
case _NET_WM_MOVERESIZE_SIZE_TOP:
|
|
|
|
case _NET_WM_MOVERESIZE_SIZE_TOPRIGHT:
|
|
|
|
case _NET_WM_MOVERESIZE_SIZE_RIGHT:
|
|
|
|
case _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT:
|
|
|
|
case _NET_WM_MOVERESIZE_SIZE_BOTTOM:
|
|
|
|
case _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT:
|
2023-07-09 11:49:45 +02:00
|
|
|
case _NET_WM_MOVERESIZE_SIZE_LEFT:;
|
|
|
|
struct wlr_xwayland_resize_event resize_event = {
|
|
|
|
.surface = xsurface,
|
|
|
|
.edges = net_wm_edges_to_wlr(detail),
|
|
|
|
};
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.request_resize, &resize_event);
|
2017-10-27 16:48:09 +02:00
|
|
|
break;
|
|
|
|
case _NET_WM_MOVERESIZE_CANCEL:
|
2017-10-29 15:31:01 +01:00
|
|
|
// handled by the compositor
|
2017-10-27 16:48:09 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-10-26 15:01:53 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 15:31:23 +01:00
|
|
|
#define _NET_WM_STATE_REMOVE 0
|
|
|
|
#define _NET_WM_STATE_ADD 1
|
|
|
|
#define _NET_WM_STATE_TOGGLE 2
|
2017-10-27 19:05:14 +02:00
|
|
|
|
|
|
|
static bool update_state(int action, bool *state) {
|
|
|
|
int new_state, changed;
|
|
|
|
|
|
|
|
switch (action) {
|
2020-11-03 15:31:23 +01:00
|
|
|
case _NET_WM_STATE_REMOVE:
|
|
|
|
new_state = false;
|
|
|
|
break;
|
|
|
|
case _NET_WM_STATE_ADD:
|
|
|
|
new_state = true;
|
|
|
|
break;
|
|
|
|
case _NET_WM_STATE_TOGGLE:
|
|
|
|
new_state = !*state;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
2017-10-27 19:05:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
changed = (*state != new_state);
|
|
|
|
*state = new_state;
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2020-12-15 13:49:42 +01:00
|
|
|
static bool xsurface_is_maximized(
|
2017-10-29 15:31:01 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface) {
|
2017-10-27 19:05:14 +02:00
|
|
|
return xsurface->maximized_horz && xsurface->maximized_vert;
|
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
static void xwm_handle_net_wm_state_message(struct wlr_xwm *xwm,
|
2017-10-27 19:05:14 +02:00
|
|
|
xcb_client_message_event_t *client_message) {
|
2017-10-29 15:31:01 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface =
|
|
|
|
lookup_surface(xwm, client_message->window);
|
2017-10-27 19:05:14 +02:00
|
|
|
if (!xsurface) {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-09 11:21:55 +01:00
|
|
|
if (client_message->format != 32) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-27 19:05:14 +02:00
|
|
|
|
2017-11-09 11:21:55 +01:00
|
|
|
bool fullscreen = xsurface->fullscreen;
|
|
|
|
bool maximized = xsurface_is_maximized(xsurface);
|
2020-07-18 21:37:02 +02:00
|
|
|
bool minimized = xsurface->minimized;
|
2017-10-27 19:05:14 +02:00
|
|
|
|
|
|
|
uint32_t action = client_message->data.data32[0];
|
2017-11-09 11:21:55 +01:00
|
|
|
for (size_t i = 0; i < 2; ++i) {
|
2020-11-03 16:48:01 +01:00
|
|
|
xcb_atom_t property = client_message->data.data32[1 + i];
|
2017-10-27 19:05:14 +02:00
|
|
|
|
2021-01-26 23:11:29 +01:00
|
|
|
bool changed = false;
|
|
|
|
if (property == xwm->atoms[NET_WM_STATE_MODAL]) {
|
|
|
|
changed = update_state(action, &xsurface->modal);
|
|
|
|
} else if (property == xwm->atoms[NET_WM_STATE_FULLSCREEN]) {
|
|
|
|
changed = update_state(action, &xsurface->fullscreen);
|
|
|
|
} else if (property == xwm->atoms[NET_WM_STATE_MAXIMIZED_VERT]) {
|
|
|
|
changed = update_state(action, &xsurface->maximized_vert);
|
|
|
|
} else if (property == xwm->atoms[NET_WM_STATE_MAXIMIZED_HORZ]) {
|
|
|
|
changed = update_state(action, &xsurface->maximized_horz);
|
|
|
|
} else if (property == xwm->atoms[NET_WM_STATE_HIDDEN]) {
|
|
|
|
changed = update_state(action, &xsurface->minimized);
|
2023-07-28 14:21:37 +02:00
|
|
|
} else if (property != XCB_ATOM_NONE && wlr_log_get_verbosity() >= WLR_DEBUG) {
|
2020-11-03 16:48:01 +01:00
|
|
|
char *prop_name = xwm_get_atom_name(xwm, property);
|
|
|
|
wlr_log(WLR_DEBUG, "Unhandled NET_WM_STATE property change "
|
|
|
|
"%"PRIu32" (%s)", property, prop_name ? prop_name : "(null)");
|
|
|
|
free(prop_name);
|
2017-11-09 11:21:55 +01:00
|
|
|
}
|
2021-01-26 23:11:29 +01:00
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
xsurface_set_net_wm_state(xsurface);
|
|
|
|
}
|
2017-11-09 11:21:55 +01:00
|
|
|
}
|
|
|
|
// client_message->data.data32[3] is the source indication
|
|
|
|
// all other values are set to 0
|
2017-10-27 19:05:14 +02:00
|
|
|
|
2017-11-09 11:21:55 +01:00
|
|
|
if (fullscreen != xsurface->fullscreen) {
|
2017-10-27 19:05:14 +02:00
|
|
|
if (xsurface->fullscreen) {
|
|
|
|
xsurface->saved_width = xsurface->width;
|
|
|
|
xsurface->saved_height = xsurface->height;
|
|
|
|
}
|
|
|
|
|
2023-07-09 11:51:31 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.request_fullscreen, NULL);
|
2017-11-09 11:21:55 +01:00
|
|
|
}
|
2017-10-27 19:05:14 +02:00
|
|
|
|
2017-11-09 11:21:55 +01:00
|
|
|
if (maximized != xsurface_is_maximized(xsurface)) {
|
|
|
|
if (xsurface_is_maximized(xsurface)) {
|
|
|
|
xsurface->saved_width = xsurface->width;
|
|
|
|
xsurface->saved_height = xsurface->height;
|
2017-10-27 19:05:14 +02:00
|
|
|
}
|
|
|
|
|
2023-07-09 11:51:31 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.request_maximize, NULL);
|
2017-10-27 19:05:14 +02:00
|
|
|
}
|
2020-07-18 21:37:02 +02:00
|
|
|
|
|
|
|
if (minimized != xsurface->minimized) {
|
|
|
|
if (xsurface->minimized) {
|
|
|
|
xsurface->saved_width = xsurface->width;
|
|
|
|
xsurface->saved_height = xsurface->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_xwayland_minimize_event minimize_event = {
|
|
|
|
.surface = xsurface,
|
|
|
|
.minimize = xsurface->minimized,
|
|
|
|
};
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.request_minimize, &minimize_event);
|
2020-07-18 21:37:02 +02:00
|
|
|
}
|
2017-10-27 19:05:14 +02:00
|
|
|
}
|
|
|
|
|
2018-04-08 22:28:01 +02:00
|
|
|
static void xwm_handle_wm_protocols_message(struct wlr_xwm *xwm,
|
|
|
|
xcb_client_message_event_t *ev) {
|
|
|
|
xcb_atom_t type = ev->data.data32[0];
|
|
|
|
|
2020-03-06 12:37:43 +01:00
|
|
|
if (type == xwm->atoms[NET_WM_PING]) {
|
2018-04-08 22:28:01 +02:00
|
|
|
xcb_window_t window_id = ev->data.data32[2];
|
|
|
|
|
|
|
|
struct wlr_xwayland_surface *surface = lookup_surface(xwm, window_id);
|
|
|
|
if (surface == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!surface->pinging) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_event_source_timer_update(surface->ping_timer, 0);
|
|
|
|
surface->pinging = false;
|
2023-07-28 14:21:37 +02:00
|
|
|
} else if (wlr_log_get_verbosity() >= WLR_DEBUG) {
|
2018-04-08 22:28:01 +02:00
|
|
|
char *type_name = xwm_get_atom_name(xwm, type);
|
2020-06-04 14:33:32 +02:00
|
|
|
wlr_log(WLR_DEBUG, "unhandled WM_PROTOCOLS client message %" PRIu32 " (%s)",
|
|
|
|
type, type_name ? type_name : "(null)");
|
2018-04-08 22:28:01 +02:00
|
|
|
free(type_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-02 06:59:09 +02:00
|
|
|
static void xwm_handle_net_active_window_message(struct wlr_xwm *xwm,
|
|
|
|
xcb_client_message_event_t *ev) {
|
|
|
|
struct wlr_xwayland_surface *surface = lookup_surface(xwm, ev->window);
|
|
|
|
if (surface == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2023-07-09 11:51:31 +02:00
|
|
|
wl_signal_emit_mutable(&surface->events.request_activate, NULL);
|
2018-09-02 06:59:09 +02:00
|
|
|
}
|
|
|
|
|
2021-01-29 16:45:44 +01:00
|
|
|
static void pending_startup_id_destroy(struct pending_startup_id *pending) {
|
|
|
|
wl_list_remove(&pending->link);
|
|
|
|
free(pending->msg);
|
|
|
|
free(pending);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xwm_handle_net_startup_info_message(struct wlr_xwm *xwm,
|
|
|
|
xcb_client_message_event_t *ev) {
|
|
|
|
struct pending_startup_id *pending, *curr = NULL;
|
|
|
|
wl_list_for_each(pending, &xwm->pending_startup_ids, link) {
|
|
|
|
if (pending->window == ev->window) {
|
|
|
|
curr = pending;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *start;
|
|
|
|
size_t buf_len = sizeof(ev->data);
|
|
|
|
if (curr) {
|
|
|
|
curr->msg = realloc(curr->msg, curr->len + buf_len);
|
|
|
|
if (!curr->msg) {
|
|
|
|
pending_startup_id_destroy(curr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
start = curr->msg + curr->len;
|
|
|
|
curr->len += buf_len;
|
|
|
|
} else {
|
2023-10-03 07:51:07 +02:00
|
|
|
curr = calloc(1, sizeof(*curr));
|
2021-01-29 16:45:44 +01:00
|
|
|
if (!curr)
|
|
|
|
return;
|
|
|
|
curr->window = ev->window;
|
|
|
|
curr->msg = malloc(buf_len);
|
|
|
|
if (!curr->msg) {
|
|
|
|
free(curr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
start = curr->msg;
|
|
|
|
curr->len = buf_len;
|
|
|
|
wl_list_insert(&xwm->pending_startup_ids, &curr->link);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *id = NULL;
|
|
|
|
const char *data = (const char *)ev->data.data8;
|
|
|
|
for (size_t i = 0; i < buf_len; i++) {
|
|
|
|
start[i] = data[i];
|
|
|
|
if (start[i] == '\0') {
|
|
|
|
if (strncmp(curr->msg, STARTUP_INFO_REMOVE_PREFIX,
|
|
|
|
strlen(STARTUP_INFO_REMOVE_PREFIX)) == 0 &&
|
|
|
|
strlen(curr->msg) > strlen(STARTUP_INFO_REMOVE_PREFIX)) {
|
|
|
|
id = curr->msg + strlen(STARTUP_INFO_REMOVE_PREFIX);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
wlr_log(WLR_ERROR, "Unhandled message '%s'\n", curr->msg);
|
|
|
|
pending_startup_id_destroy(curr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id) {
|
|
|
|
struct wlr_xwayland_remove_startup_info_event data = { id, ev->window };
|
|
|
|
wlr_log(WLR_DEBUG, "Got startup id: %s", id);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&xwm->xwayland->events.remove_startup_info, &data);
|
2021-01-29 16:45:44 +01:00
|
|
|
pending_startup_id_destroy(curr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-18 21:37:02 +02:00
|
|
|
static void xwm_handle_wm_change_state_message(struct wlr_xwm *xwm,
|
|
|
|
xcb_client_message_event_t *ev) {
|
|
|
|
struct wlr_xwayland_surface *xsurface = lookup_surface(xwm, ev->window);
|
|
|
|
uint32_t detail = ev->data.data32[0];
|
|
|
|
|
|
|
|
if (xsurface == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool minimize;
|
2021-03-29 12:11:53 +02:00
|
|
|
if (detail == XCB_ICCCM_WM_STATE_ICONIC) {
|
2020-07-18 21:37:02 +02:00
|
|
|
minimize = true;
|
2021-03-29 12:11:53 +02:00
|
|
|
} else if (detail == XCB_ICCCM_WM_STATE_NORMAL) {
|
2020-07-18 21:37:02 +02:00
|
|
|
minimize = false;
|
|
|
|
} else {
|
|
|
|
wlr_log(WLR_DEBUG, "unhandled wm_change_state event %u", detail);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_xwayland_minimize_event minimize_event = {
|
|
|
|
.surface = xsurface,
|
|
|
|
.minimize = minimize,
|
|
|
|
};
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&xsurface->events.request_minimize, &minimize_event);
|
2020-07-18 21:37:02 +02:00
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
static void xwm_handle_client_message(struct wlr_xwm *xwm,
|
2017-09-28 23:26:31 +02:00
|
|
|
xcb_client_message_event_t *ev) {
|
2017-08-20 13:43:04 +02:00
|
|
|
if (ev->type == xwm->atoms[WL_SURFACE_ID]) {
|
2017-10-29 15:31:01 +01:00
|
|
|
xwm_handle_surface_id_message(xwm, ev);
|
2022-10-18 13:09:17 +02:00
|
|
|
} else if (ev->type == xwm->atoms[WL_SURFACE_SERIAL]) {
|
|
|
|
xwm_handle_surface_serial_message(xwm, ev);
|
2017-09-29 22:26:03 +02:00
|
|
|
} else if (ev->type == xwm->atoms[NET_WM_STATE]) {
|
2017-10-29 15:31:01 +01:00
|
|
|
xwm_handle_net_wm_state_message(xwm, ev);
|
2020-03-06 12:37:43 +01:00
|
|
|
} else if (ev->type == xwm->atoms[NET_WM_MOVERESIZE]) {
|
2017-10-29 15:31:01 +01:00
|
|
|
xwm_handle_net_wm_moveresize_message(xwm, ev);
|
2018-04-08 22:28:01 +02:00
|
|
|
} else if (ev->type == xwm->atoms[WM_PROTOCOLS]) {
|
|
|
|
xwm_handle_wm_protocols_message(xwm, ev);
|
2020-03-06 12:37:43 +01:00
|
|
|
} else if (ev->type == xwm->atoms[NET_ACTIVE_WINDOW]) {
|
2018-09-02 06:59:09 +02:00
|
|
|
xwm_handle_net_active_window_message(xwm, ev);
|
2021-01-29 16:45:44 +01:00
|
|
|
} else if (ev->type == xwm->atoms[NET_STARTUP_INFO] ||
|
|
|
|
ev->type == xwm->atoms[NET_STARTUP_INFO_BEGIN]) {
|
|
|
|
xwm_handle_net_startup_info_message(xwm, ev);
|
2020-07-18 21:37:02 +02:00
|
|
|
} else if (ev->type == xwm->atoms[WM_CHANGE_STATE]) {
|
|
|
|
xwm_handle_wm_change_state_message(xwm, ev);
|
2023-07-28 14:21:37 +02:00
|
|
|
} else if (!xwm_handle_selection_client_message(xwm, ev) &&
|
|
|
|
wlr_log_get_verbosity() >= WLR_DEBUG) {
|
2018-03-29 03:36:53 +02:00
|
|
|
char *type_name = xwm_get_atom_name(xwm, ev->type);
|
2020-06-04 14:33:32 +02:00
|
|
|
wlr_log(WLR_DEBUG, "unhandled x11 client message %" PRIu32 " (%s)", ev->type,
|
|
|
|
type_name ? type_name : "(null)");
|
2018-03-28 21:45:15 +02:00
|
|
|
free(type_name);
|
2017-08-20 13:43:04 +02:00
|
|
|
}
|
|
|
|
}
|
2017-08-20 07:47:38 +02:00
|
|
|
|
2020-07-19 14:57:10 +02:00
|
|
|
static bool validate_focus_serial(uint16_t last_focus_seq, uint16_t event_seq) {
|
|
|
|
uint16_t rev_dist = event_seq - last_focus_seq;
|
|
|
|
if (rev_dist >= UINT16_MAX / 2) {
|
|
|
|
// Probably overflow or too old
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
static void xwm_handle_focus_in(struct wlr_xwm *xwm,
|
2017-10-26 17:54:39 +02:00
|
|
|
xcb_focus_in_event_t *ev) {
|
|
|
|
// Do not interfere with grabs
|
|
|
|
if (ev->mode == XCB_NOTIFY_MODE_GRAB ||
|
|
|
|
ev->mode == XCB_NOTIFY_MODE_UNGRAB) {
|
|
|
|
return;
|
|
|
|
}
|
2020-02-19 10:55:26 +01:00
|
|
|
// Ignore pointer focus change events
|
|
|
|
if (ev->detail == XCB_NOTIFY_DETAIL_POINTER) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-26 17:54:39 +02:00
|
|
|
|
|
|
|
// Do not let X clients change the focus behind the compositor's
|
|
|
|
// back. Reset the focus to the old one if it changed.
|
2020-01-05 17:36:32 +01:00
|
|
|
//
|
|
|
|
// Note: Some applications rely on being able to change focus, for ex. Steam:
|
|
|
|
// https://github.com/swaywm/sway/issues/1865
|
|
|
|
// Because of that, we allow changing focus between surfaces belonging to the
|
2020-07-19 14:57:10 +02:00
|
|
|
// same application. We must be careful to ignore requests that are too old
|
|
|
|
// though, because otherwise it may lead to race conditions:
|
|
|
|
// https://github.com/swaywm/wlroots/issues/2324
|
2020-01-05 17:36:32 +01:00
|
|
|
struct wlr_xwayland_surface *requested_focus = lookup_surface(xwm, ev->event);
|
2020-05-23 16:41:20 +02:00
|
|
|
if (xwm->focus_surface && requested_focus &&
|
2020-07-19 14:57:10 +02:00
|
|
|
requested_focus->pid == xwm->focus_surface->pid &&
|
|
|
|
validate_focus_serial(xwm->last_focus_seq, ev->sequence)) {
|
2020-07-27 13:41:54 +02:00
|
|
|
xwm_set_focus_window(xwm, requested_focus);
|
|
|
|
} else {
|
|
|
|
xwm_set_focus_window(xwm, xwm->focus_surface);
|
2017-10-26 17:54:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 10:40:52 +01:00
|
|
|
static void xwm_handle_xcb_error(struct wlr_xwm *xwm, xcb_value_error_t *ev) {
|
2022-11-25 18:15:31 +01:00
|
|
|
#if HAVE_XCB_ERRORS
|
2018-03-03 12:00:32 +01:00
|
|
|
const char *major_name =
|
2018-03-03 17:06:27 +01:00
|
|
|
xcb_errors_get_name_for_major_code(xwm->errors_context,
|
|
|
|
ev->major_opcode);
|
2018-03-03 11:37:02 +01:00
|
|
|
if (!major_name) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "xcb error happened, but could not get major name");
|
2018-03-03 11:37:02 +01:00
|
|
|
goto log_raw;
|
|
|
|
}
|
|
|
|
|
2018-03-03 12:00:32 +01:00
|
|
|
const char *minor_name =
|
2018-03-03 17:06:27 +01:00
|
|
|
xcb_errors_get_name_for_minor_code(xwm->errors_context,
|
2018-03-03 12:00:32 +01:00
|
|
|
ev->major_opcode, ev->minor_opcode);
|
2018-03-03 11:37:02 +01:00
|
|
|
|
2018-03-03 12:00:32 +01:00
|
|
|
const char *extension;
|
|
|
|
const char *error_name =
|
2018-03-03 17:06:27 +01:00
|
|
|
xcb_errors_get_name_for_error(xwm->errors_context,
|
|
|
|
ev->error_code, &extension);
|
2018-03-03 11:37:02 +01:00
|
|
|
if (!error_name) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "xcb error happened, but could not get error name");
|
2018-03-03 11:37:02 +01:00
|
|
|
goto log_raw;
|
|
|
|
}
|
|
|
|
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "xcb error: op %s (%s), code %s (%s), sequence %"PRIu16", value %"PRIu32,
|
2018-03-03 11:37:02 +01:00
|
|
|
major_name, minor_name ? minor_name : "no minor",
|
|
|
|
error_name, extension ? extension : "no extension",
|
2018-03-03 16:13:45 +01:00
|
|
|
ev->sequence, ev->bad_value);
|
2018-03-03 11:37:02 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
log_raw:
|
|
|
|
#endif
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR,
|
2018-03-03 11:37:02 +01:00
|
|
|
"xcb error: op %"PRIu8":%"PRIu16", code %"PRIu8", sequence %"PRIu16", value %"PRIu32,
|
|
|
|
ev->major_opcode, ev->minor_opcode, ev->error_code,
|
|
|
|
ev->sequence, ev->bad_value);
|
|
|
|
|
2018-03-03 10:40:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-03 16:27:26 +01:00
|
|
|
static void xwm_handle_unhandled_event(struct wlr_xwm *xwm, xcb_generic_event_t *ev) {
|
2022-11-25 18:15:31 +01:00
|
|
|
#if HAVE_XCB_ERRORS
|
2018-03-03 16:27:26 +01:00
|
|
|
const char *extension;
|
|
|
|
const char *event_name =
|
2018-03-03 17:06:27 +01:00
|
|
|
xcb_errors_get_name_for_xcb_event(xwm->errors_context,
|
|
|
|
ev, &extension);
|
2018-03-03 16:27:26 +01:00
|
|
|
if (!event_name) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "no name for unhandled event: %u",
|
2018-03-03 16:27:26 +01:00
|
|
|
ev->response_type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "unhandled X11 event: %s (%u)", event_name, ev->response_type);
|
2018-03-03 16:27:26 +01:00
|
|
|
#else
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "unhandled X11 event: %u", ev->response_type);
|
2018-03-03 16:27:26 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-08-19 21:25:26 +02:00
|
|
|
static int x11_event_handler(int fd, uint32_t mask, void *data) {
|
|
|
|
int count = 0;
|
|
|
|
xcb_generic_event_t *event;
|
2017-08-20 13:43:04 +02:00
|
|
|
struct wlr_xwm *xwm = data;
|
2017-08-19 21:25:26 +02:00
|
|
|
|
2020-06-30 18:10:23 +02:00
|
|
|
if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) {
|
|
|
|
xwm_destroy(xwm);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-20 07:47:38 +02:00
|
|
|
while ((event = xcb_poll_for_event(xwm->xcb_conn))) {
|
2017-08-19 21:25:26 +02:00
|
|
|
count++;
|
2017-11-20 13:23:17 +01:00
|
|
|
|
2017-12-13 23:54:19 +01:00
|
|
|
if (xwm->xwayland->user_event_handler &&
|
|
|
|
xwm->xwayland->user_event_handler(xwm, event)) {
|
2023-11-17 03:33:18 +01:00
|
|
|
free(event);
|
|
|
|
continue;
|
2017-12-13 23:54:19 +01:00
|
|
|
}
|
|
|
|
|
2017-11-20 13:23:17 +01:00
|
|
|
if (xwm_handle_selection_event(xwm, event)) {
|
|
|
|
free(event);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-08-20 07:47:38 +02:00
|
|
|
switch (event->response_type & XCB_EVENT_RESPONSE_TYPE_MASK) {
|
|
|
|
case XCB_CREATE_NOTIFY:
|
2017-10-29 15:31:01 +01:00
|
|
|
xwm_handle_create_notify(xwm, (xcb_create_notify_event_t *)event);
|
2017-08-20 13:43:04 +02:00
|
|
|
break;
|
|
|
|
case XCB_DESTROY_NOTIFY:
|
2017-10-29 15:31:01 +01:00
|
|
|
xwm_handle_destroy_notify(xwm, (xcb_destroy_notify_event_t *)event);
|
2017-08-20 07:47:38 +02:00
|
|
|
break;
|
|
|
|
case XCB_CONFIGURE_REQUEST:
|
2017-10-29 15:31:01 +01:00
|
|
|
xwm_handle_configure_request(xwm,
|
2017-10-25 01:18:31 +02:00
|
|
|
(xcb_configure_request_event_t *)event);
|
2017-08-20 07:47:38 +02:00
|
|
|
break;
|
2017-10-24 19:57:10 +02:00
|
|
|
case XCB_CONFIGURE_NOTIFY:
|
2017-10-29 15:31:01 +01:00
|
|
|
xwm_handle_configure_notify(xwm,
|
|
|
|
(xcb_configure_notify_event_t *)event);
|
2017-10-24 19:57:10 +02:00
|
|
|
break;
|
2017-08-20 07:47:38 +02:00
|
|
|
case XCB_MAP_REQUEST:
|
2017-10-29 15:31:01 +01:00
|
|
|
xwm_handle_map_request(xwm, (xcb_map_request_event_t *)event);
|
2017-08-20 07:47:38 +02:00
|
|
|
break;
|
2017-08-20 13:43:04 +02:00
|
|
|
case XCB_MAP_NOTIFY:
|
2017-10-29 15:31:01 +01:00
|
|
|
xwm_handle_map_notify(xwm, (xcb_map_notify_event_t *)event);
|
2017-08-20 13:43:04 +02:00
|
|
|
break;
|
|
|
|
case XCB_UNMAP_NOTIFY:
|
2017-10-29 15:31:01 +01:00
|
|
|
xwm_handle_unmap_notify(xwm, (xcb_unmap_notify_event_t *)event);
|
2017-08-20 13:43:04 +02:00
|
|
|
break;
|
|
|
|
case XCB_PROPERTY_NOTIFY:
|
2017-10-29 15:31:01 +01:00
|
|
|
xwm_handle_property_notify(xwm,
|
|
|
|
(xcb_property_notify_event_t *)event);
|
2017-08-20 13:43:04 +02:00
|
|
|
break;
|
|
|
|
case XCB_CLIENT_MESSAGE:
|
2017-10-29 15:31:01 +01:00
|
|
|
xwm_handle_client_message(xwm, (xcb_client_message_event_t *)event);
|
2017-08-20 07:47:38 +02:00
|
|
|
break;
|
2017-10-26 17:54:39 +02:00
|
|
|
case XCB_FOCUS_IN:
|
2017-10-29 15:31:01 +01:00
|
|
|
xwm_handle_focus_in(xwm, (xcb_focus_in_event_t *)event);
|
2017-10-26 17:54:39 +02:00
|
|
|
break;
|
2018-03-03 10:40:52 +01:00
|
|
|
case 0:
|
|
|
|
xwm_handle_xcb_error(xwm, (xcb_value_error_t *)event);
|
|
|
|
break;
|
2017-08-20 07:47:38 +02:00
|
|
|
default:
|
2018-03-03 16:27:26 +01:00
|
|
|
xwm_handle_unhandled_event(xwm, event);
|
2017-08-20 19:50:28 +02:00
|
|
|
break;
|
2017-08-20 07:47:38 +02:00
|
|
|
}
|
2017-08-27 22:30:37 +02:00
|
|
|
free(event);
|
2017-08-19 21:25:26 +02:00
|
|
|
}
|
2017-08-20 13:43:04 +02:00
|
|
|
|
2017-10-26 00:51:15 +02:00
|
|
|
if (count) {
|
|
|
|
xcb_flush(xwm->xcb_conn);
|
|
|
|
}
|
|
|
|
|
2017-08-19 21:25:26 +02:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2018-02-23 10:20:53 +01:00
|
|
|
static void handle_compositor_new_surface(struct wl_listener *listener,
|
2017-10-25 01:18:31 +02:00
|
|
|
void *data) {
|
2017-10-24 16:04:33 +02:00
|
|
|
struct wlr_xwm *xwm =
|
2018-02-23 10:20:53 +01:00
|
|
|
wl_container_of(listener, xwm, compositor_new_surface);
|
|
|
|
struct wlr_surface *surface = data;
|
2020-05-05 10:24:08 +02:00
|
|
|
|
|
|
|
struct wl_client *client = wl_resource_get_client(surface->resource);
|
|
|
|
if (client != xwm->xwayland->server->client) {
|
2017-08-19 21:25:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "New xwayland surface: %p", surface);
|
2017-08-19 21:25:26 +02:00
|
|
|
|
2017-09-28 23:26:31 +02:00
|
|
|
uint32_t surface_id = wl_resource_get_id(surface->resource);
|
2017-10-25 03:07:46 +02:00
|
|
|
struct wlr_xwayland_surface *xsurface;
|
|
|
|
wl_list_for_each(xsurface, &xwm->unpaired_surfaces, unpaired_link) {
|
|
|
|
if (xsurface->surface_id == surface_id) {
|
2022-11-29 17:03:19 +01:00
|
|
|
xwayland_surface_associate(xwm, xsurface, surface);
|
2017-08-20 13:43:04 +02:00
|
|
|
xcb_flush(xwm->xcb_conn);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-08-19 21:25:26 +02:00
|
|
|
}
|
|
|
|
|
2018-02-23 10:20:53 +01:00
|
|
|
static void handle_compositor_destroy(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_xwm *xwm =
|
|
|
|
wl_container_of(listener, xwm, compositor_destroy);
|
|
|
|
wl_list_remove(&xwm->compositor_new_surface.link);
|
|
|
|
wl_list_remove(&xwm->compositor_destroy.link);
|
|
|
|
wl_list_init(&xwm->compositor_new_surface.link);
|
|
|
|
wl_list_init(&xwm->compositor_destroy.link);
|
|
|
|
}
|
|
|
|
|
2022-10-18 13:09:17 +02:00
|
|
|
static void handle_shell_v1_new_surface(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_xwm *xwm = wl_container_of(listener, xwm, shell_v1_new_surface);
|
|
|
|
struct wlr_xwayland_surface_v1 *shell_surface = data;
|
|
|
|
|
|
|
|
struct wlr_xwayland_surface *xsurface;
|
|
|
|
wl_list_for_each(xsurface, &xwm->unpaired_surfaces, unpaired_link) {
|
|
|
|
if (xsurface->serial == shell_surface->serial) {
|
2022-11-29 17:03:19 +01:00
|
|
|
xwayland_surface_associate(xwm, xsurface, shell_surface->surface);
|
2022-10-18 13:09:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-03 23:30:57 +01:00
|
|
|
void wlr_xwayland_surface_activate(struct wlr_xwayland_surface *xsurface,
|
|
|
|
bool activated) {
|
|
|
|
struct wlr_xwayland_surface *focused = xsurface->xwm->focus_surface;
|
2017-10-25 14:39:28 +02:00
|
|
|
if (activated) {
|
2017-12-03 23:30:57 +01:00
|
|
|
xwm_surface_activate(xsurface->xwm, xsurface);
|
2017-10-29 15:31:01 +01:00
|
|
|
} else if (focused == xsurface) {
|
2017-12-03 23:30:57 +01:00
|
|
|
xwm_surface_activate(xsurface->xwm, NULL);
|
2017-10-24 16:04:33 +02:00
|
|
|
}
|
2017-09-28 15:11:16 +02:00
|
|
|
}
|
|
|
|
|
2017-12-03 23:30:57 +01:00
|
|
|
void wlr_xwayland_surface_configure(struct wlr_xwayland_surface *xsurface,
|
|
|
|
int16_t x, int16_t y, uint16_t width, uint16_t height) {
|
2023-02-17 14:25:39 +01:00
|
|
|
int old_w = xsurface->width;
|
|
|
|
int old_h = xsurface->height;
|
|
|
|
|
2017-10-29 15:31:01 +01:00
|
|
|
xsurface->x = x;
|
|
|
|
xsurface->y = y;
|
|
|
|
xsurface->width = width;
|
|
|
|
xsurface->height = height;
|
2017-09-30 16:33:04 +02:00
|
|
|
|
2017-12-03 23:30:57 +01:00
|
|
|
struct wlr_xwm *xwm = xsurface->xwm;
|
2017-09-29 16:19:06 +02:00
|
|
|
uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
|
|
|
|
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
|
|
|
|
XCB_CONFIG_WINDOW_BORDER_WIDTH;
|
2017-09-30 16:33:04 +02:00
|
|
|
uint32_t values[] = {x, y, width, height, 0};
|
2017-10-29 15:31:01 +01:00
|
|
|
xcb_configure_window(xwm->xcb_conn, xsurface->window_id, mask, values);
|
2023-02-17 14:25:39 +01:00
|
|
|
|
|
|
|
// If the window size did not change, then we cannot rely on
|
|
|
|
// the X server to generate a ConfigureNotify event. Instead,
|
|
|
|
// we are supposed to send a synthetic event. See ICCCM part
|
|
|
|
// 4.1.5. But we ignore override-redirect windows as ICCCM does
|
|
|
|
// not apply to them.
|
|
|
|
if (width == old_w && height == old_h && !xsurface->override_redirect) {
|
|
|
|
xcb_configure_notify_event_t configure_notify = {
|
|
|
|
.response_type = XCB_CONFIGURE_NOTIFY,
|
|
|
|
.event = xsurface->window_id,
|
|
|
|
.window = xsurface->window_id,
|
|
|
|
.x = x,
|
|
|
|
.y = y,
|
|
|
|
.width = width,
|
|
|
|
.height = height,
|
|
|
|
};
|
|
|
|
|
|
|
|
xcb_send_event(xwm->xcb_conn, 0, xsurface->window_id,
|
|
|
|
XCB_EVENT_MASK_STRUCTURE_NOTIFY,
|
|
|
|
(const char *)&configure_notify);
|
|
|
|
}
|
|
|
|
|
2017-10-06 11:55:36 +02:00
|
|
|
xcb_flush(xwm->xcb_conn);
|
2017-09-29 16:19:06 +02:00
|
|
|
}
|
|
|
|
|
2017-12-03 23:30:57 +01:00
|
|
|
void wlr_xwayland_surface_close(struct wlr_xwayland_surface *xsurface) {
|
|
|
|
struct wlr_xwm *xwm = xsurface->xwm;
|
2017-09-29 23:18:12 +02:00
|
|
|
|
|
|
|
bool supports_delete = false;
|
2017-10-29 15:31:01 +01:00
|
|
|
for (size_t i = 0; i < xsurface->protocols_len; i++) {
|
|
|
|
if (xsurface->protocols[i] == xwm->atoms[WM_DELETE_WINDOW]) {
|
2017-09-29 23:18:12 +02:00
|
|
|
supports_delete = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (supports_delete) {
|
2018-04-08 22:28:01 +02:00
|
|
|
xcb_client_message_data_t message_data = {0};
|
|
|
|
message_data.data32[0] = xwm->atoms[WM_DELETE_WINDOW];
|
|
|
|
message_data.data32[1] = XCB_CURRENT_TIME;
|
2018-05-26 09:08:20 +02:00
|
|
|
xwm_send_wm_message(xsurface, &message_data, XCB_EVENT_MASK_NO_EVENT);
|
2017-09-29 23:18:12 +02:00
|
|
|
} else {
|
2017-10-29 15:36:16 +01:00
|
|
|
xcb_kill_client(xwm->xcb_conn, xsurface->window_id);
|
2018-04-08 22:28:01 +02:00
|
|
|
xcb_flush(xwm->xcb_conn);
|
2017-09-29 23:18:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-19 21:25:26 +02:00
|
|
|
void xwm_destroy(struct wlr_xwm *xwm) {
|
2017-08-23 23:19:15 +02:00
|
|
|
if (!xwm) {
|
|
|
|
return;
|
|
|
|
}
|
2021-01-30 05:47:03 +01:00
|
|
|
|
|
|
|
xwm_selection_finish(&xwm->clipboard_selection);
|
|
|
|
xwm_selection_finish(&xwm->primary_selection);
|
|
|
|
xwm_selection_finish(&xwm->dnd_selection);
|
|
|
|
|
|
|
|
if (xwm->seat) {
|
|
|
|
if (xwm->seat->selection_source &&
|
|
|
|
data_source_is_xwayland(xwm->seat->selection_source)) {
|
|
|
|
wlr_seat_set_selection(xwm->seat, NULL,
|
|
|
|
wl_display_next_serial(xwm->xwayland->wl_display));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xwm->seat->primary_selection_source &&
|
|
|
|
primary_selection_source_is_xwayland(
|
|
|
|
xwm->seat->primary_selection_source)) {
|
|
|
|
wlr_seat_set_primary_selection(xwm->seat, NULL,
|
|
|
|
wl_display_next_serial(xwm->xwayland->wl_display));
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_xwayland_set_seat(xwm->xwayland, NULL);
|
|
|
|
}
|
|
|
|
|
2017-11-02 11:09:14 +01:00
|
|
|
if (xwm->cursor) {
|
|
|
|
xcb_free_cursor(xwm->xcb_conn, xwm->cursor);
|
|
|
|
}
|
2017-12-08 01:38:45 +01:00
|
|
|
if (xwm->colormap) {
|
|
|
|
xcb_free_colormap(xwm->xcb_conn, xwm->colormap);
|
|
|
|
}
|
|
|
|
if (xwm->window) {
|
|
|
|
xcb_destroy_window(xwm->xcb_conn, xwm->window);
|
|
|
|
}
|
2017-08-19 21:25:26 +02:00
|
|
|
if (xwm->event_source) {
|
|
|
|
wl_event_source_remove(xwm->event_source);
|
|
|
|
}
|
2022-11-25 18:15:31 +01:00
|
|
|
#if HAVE_XCB_ERRORS
|
2018-03-03 17:06:27 +01:00
|
|
|
if (xwm->errors_context) {
|
|
|
|
xcb_errors_context_free(xwm->errors_context);
|
|
|
|
}
|
|
|
|
#endif
|
2017-10-29 15:31:01 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface, *tmp;
|
|
|
|
wl_list_for_each_safe(xsurface, tmp, &xwm->surfaces, link) {
|
2018-04-26 00:51:00 +02:00
|
|
|
xwayland_surface_destroy(xsurface);
|
2017-08-23 23:39:16 +02:00
|
|
|
}
|
2021-05-20 02:33:45 +02:00
|
|
|
wl_list_for_each_safe(xsurface, tmp, &xwm->unpaired_surfaces, unpaired_link) {
|
2018-04-26 00:51:00 +02:00
|
|
|
xwayland_surface_destroy(xsurface);
|
2017-12-08 01:38:45 +01:00
|
|
|
}
|
2018-02-23 10:20:53 +01:00
|
|
|
wl_list_remove(&xwm->compositor_new_surface.link);
|
|
|
|
wl_list_remove(&xwm->compositor_destroy.link);
|
2022-10-18 13:09:17 +02:00
|
|
|
wl_list_remove(&xwm->shell_v1_new_surface.link);
|
2017-08-20 07:47:38 +02:00
|
|
|
xcb_disconnect(xwm->xcb_conn);
|
|
|
|
|
2021-01-29 16:45:44 +01:00
|
|
|
struct pending_startup_id *pending, *next;
|
|
|
|
wl_list_for_each_safe(pending, next, &xwm->pending_startup_ids, link) {
|
|
|
|
pending_startup_id_destroy(pending);
|
|
|
|
}
|
|
|
|
|
2020-06-30 18:10:23 +02:00
|
|
|
xwm->xwayland->xwm = NULL;
|
2017-08-19 21:25:26 +02:00
|
|
|
free(xwm);
|
|
|
|
}
|
|
|
|
|
2017-10-24 14:49:10 +02:00
|
|
|
static void xwm_get_resources(struct wlr_xwm *xwm) {
|
2017-10-26 16:39:36 +02:00
|
|
|
xcb_prefetch_extension_data(xwm->xcb_conn, &xcb_xfixes_id);
|
|
|
|
xcb_prefetch_extension_data(xwm->xcb_conn, &xcb_composite_id);
|
2021-04-17 04:27:12 +02:00
|
|
|
xcb_prefetch_extension_data(xwm->xcb_conn, &xcb_res_id);
|
2017-10-26 16:39:36 +02:00
|
|
|
|
2017-10-24 14:49:10 +02:00
|
|
|
size_t i;
|
|
|
|
xcb_intern_atom_cookie_t cookies[ATOM_LAST];
|
|
|
|
|
|
|
|
for (i = 0; i < ATOM_LAST; i++) {
|
2017-10-25 01:18:31 +02:00
|
|
|
cookies[i] =
|
|
|
|
xcb_intern_atom(xwm->xcb_conn, 0, strlen(atom_map[i]), atom_map[i]);
|
2017-10-24 14:49:10 +02:00
|
|
|
}
|
|
|
|
for (i = 0; i < ATOM_LAST; i++) {
|
|
|
|
xcb_generic_error_t *error;
|
2017-12-14 16:24:12 +01:00
|
|
|
xcb_intern_atom_reply_t *reply =
|
|
|
|
xcb_intern_atom_reply(xwm->xcb_conn, cookies[i], &error);
|
2017-10-24 14:49:10 +02:00
|
|
|
if (reply && !error) {
|
|
|
|
xwm->atoms[i] = reply->atom;
|
|
|
|
}
|
2017-10-24 15:21:11 +02:00
|
|
|
free(reply);
|
|
|
|
|
2017-10-24 14:49:10 +02:00
|
|
|
if (error) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "could not resolve atom %s, x11 error code %d",
|
2017-10-24 14:49:10 +02:00
|
|
|
atom_map[i], error->error_code);
|
|
|
|
free(error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-10-26 16:39:36 +02:00
|
|
|
|
|
|
|
xwm->xfixes = xcb_get_extension_data(xwm->xcb_conn, &xcb_xfixes_id);
|
|
|
|
|
|
|
|
if (!xwm->xfixes || !xwm->xfixes->present) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "xfixes not available");
|
2017-10-26 16:39:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
xcb_xfixes_query_version_cookie_t xfixes_cookie;
|
|
|
|
xcb_xfixes_query_version_reply_t *xfixes_reply;
|
|
|
|
xfixes_cookie =
|
|
|
|
xcb_xfixes_query_version(xwm->xcb_conn, XCB_XFIXES_MAJOR_VERSION,
|
|
|
|
XCB_XFIXES_MINOR_VERSION);
|
|
|
|
xfixes_reply =
|
|
|
|
xcb_xfixes_query_version_reply(xwm->xcb_conn, xfixes_cookie, NULL);
|
|
|
|
|
2020-06-04 14:33:32 +02:00
|
|
|
wlr_log(WLR_DEBUG, "xfixes version: %" PRIu32 ".%" PRIu32,
|
2017-10-26 16:39:36 +02:00
|
|
|
xfixes_reply->major_version, xfixes_reply->minor_version);
|
2021-06-25 13:49:47 +02:00
|
|
|
xwm->xfixes_major_version = xfixes_reply->major_version;
|
2017-10-26 16:39:36 +02:00
|
|
|
|
|
|
|
free(xfixes_reply);
|
2021-04-17 04:27:12 +02:00
|
|
|
|
|
|
|
const xcb_query_extension_reply_t *xres =
|
|
|
|
xcb_get_extension_data(xwm->xcb_conn, &xcb_res_id);
|
|
|
|
if (!xres || !xres->present) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_res_query_version_cookie_t xres_cookie =
|
|
|
|
xcb_res_query_version(xwm->xcb_conn, XCB_RES_MAJOR_VERSION,
|
|
|
|
XCB_RES_MINOR_VERSION);
|
|
|
|
xcb_res_query_version_reply_t *xres_reply =
|
|
|
|
xcb_res_query_version_reply(xwm->xcb_conn, xres_cookie, NULL);
|
|
|
|
if (xres_reply == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_log(WLR_DEBUG, "xres version: %" PRIu32 ".%" PRIu32,
|
|
|
|
xres_reply->server_major, xres_reply->server_minor);
|
|
|
|
if (xres_reply->server_major > 1 ||
|
|
|
|
(xres_reply->server_major == 1 && xres_reply->server_minor >= 2)) {
|
|
|
|
xwm->xres = xres;
|
|
|
|
}
|
|
|
|
free(xres_reply);
|
2017-10-24 14:49:10 +02:00
|
|
|
}
|
|
|
|
|
2017-10-26 16:39:36 +02:00
|
|
|
static void xwm_create_wm_window(struct wlr_xwm *xwm) {
|
|
|
|
static const char name[] = "wlroots wm";
|
|
|
|
|
|
|
|
xwm->window = xcb_generate_id(xwm->xcb_conn);
|
|
|
|
|
|
|
|
xcb_create_window(xwm->xcb_conn,
|
|
|
|
XCB_COPY_FROM_PARENT,
|
|
|
|
xwm->window,
|
|
|
|
xwm->screen->root,
|
|
|
|
0, 0,
|
|
|
|
10, 10,
|
|
|
|
0,
|
|
|
|
XCB_WINDOW_CLASS_INPUT_OUTPUT,
|
|
|
|
xwm->screen->root_visual,
|
|
|
|
0, NULL);
|
|
|
|
|
|
|
|
xcb_change_property(xwm->xcb_conn,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
xwm->window,
|
2020-03-06 12:33:05 +01:00
|
|
|
xwm->atoms[NET_WM_NAME],
|
2017-10-26 16:39:36 +02:00
|
|
|
xwm->atoms[UTF8_STRING],
|
|
|
|
8, // format
|
|
|
|
strlen(name), name);
|
|
|
|
|
|
|
|
xcb_change_property(xwm->xcb_conn,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
xwm->screen->root,
|
2020-03-06 12:37:43 +01:00
|
|
|
xwm->atoms[NET_SUPPORTING_WM_CHECK],
|
2017-10-26 16:39:36 +02:00
|
|
|
XCB_ATOM_WINDOW,
|
|
|
|
32, // format
|
|
|
|
1, &xwm->window);
|
|
|
|
|
2017-10-27 16:48:09 +02:00
|
|
|
xcb_change_property(xwm->xcb_conn,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
xwm->window,
|
2020-03-06 12:37:43 +01:00
|
|
|
xwm->atoms[NET_SUPPORTING_WM_CHECK],
|
2017-10-27 16:48:09 +02:00
|
|
|
XCB_ATOM_WINDOW,
|
|
|
|
32, // format
|
|
|
|
1, &xwm->window);
|
|
|
|
|
2017-10-26 16:39:36 +02:00
|
|
|
xcb_set_selection_owner(xwm->xcb_conn,
|
|
|
|
xwm->window,
|
|
|
|
xwm->atoms[WM_S0],
|
|
|
|
XCB_CURRENT_TIME);
|
|
|
|
|
|
|
|
xcb_set_selection_owner(xwm->xcb_conn,
|
|
|
|
xwm->window,
|
2018-10-27 11:59:27 +02:00
|
|
|
xwm->atoms[NET_WM_CM_S0],
|
2017-10-26 16:39:36 +02:00
|
|
|
XCB_CURRENT_TIME);
|
|
|
|
}
|
2017-10-24 14:49:10 +02:00
|
|
|
|
2017-10-27 21:20:50 +02:00
|
|
|
// TODO use me to support 32 bit color somehow
|
|
|
|
static void xwm_get_visual_and_colormap(struct wlr_xwm *xwm) {
|
|
|
|
xcb_depth_iterator_t d_iter;
|
|
|
|
xcb_visualtype_iterator_t vt_iter;
|
|
|
|
xcb_visualtype_t *visualtype;
|
|
|
|
|
|
|
|
d_iter = xcb_screen_allowed_depths_iterator(xwm->screen);
|
|
|
|
visualtype = NULL;
|
|
|
|
while (d_iter.rem > 0) {
|
|
|
|
if (d_iter.data->depth == 32) {
|
|
|
|
vt_iter = xcb_depth_visuals_iterator(d_iter.data);
|
|
|
|
visualtype = vt_iter.data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_depth_next(&d_iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visualtype == NULL) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "No 32 bit visualtype\n");
|
2017-10-27 21:20:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xwm->visual_id = visualtype->visual_id;
|
|
|
|
xwm->colormap = xcb_generate_id(xwm->xcb_conn);
|
2017-10-29 15:36:16 +01:00
|
|
|
xcb_create_colormap(xwm->xcb_conn,
|
|
|
|
XCB_COLORMAP_ALLOC_NONE,
|
|
|
|
xwm->colormap,
|
|
|
|
xwm->screen->root,
|
|
|
|
xwm->visual_id);
|
2017-10-27 21:20:50 +02:00
|
|
|
}
|
|
|
|
|
2017-11-02 16:59:57 +01:00
|
|
|
static void xwm_get_render_format(struct wlr_xwm *xwm) {
|
2017-11-02 15:52:02 +01:00
|
|
|
xcb_render_query_pict_formats_cookie_t cookie =
|
|
|
|
xcb_render_query_pict_formats(xwm->xcb_conn);
|
|
|
|
xcb_render_query_pict_formats_reply_t *reply =
|
2017-11-02 16:59:57 +01:00
|
|
|
xcb_render_query_pict_formats_reply(xwm->xcb_conn, cookie, NULL);
|
2017-12-29 20:31:04 +01:00
|
|
|
if (!reply) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "Did not get any reply from xcb_render_query_pict_formats");
|
2017-12-29 20:31:04 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-11-02 17:21:00 +01:00
|
|
|
xcb_render_pictforminfo_iterator_t iter =
|
|
|
|
xcb_render_query_pict_formats_formats_iterator(reply);
|
2017-11-02 15:52:02 +01:00
|
|
|
xcb_render_pictforminfo_t *format = NULL;
|
2017-11-02 17:21:00 +01:00
|
|
|
while (iter.rem > 0) {
|
|
|
|
if (iter.data->depth == 32) {
|
|
|
|
format = iter.data;
|
2017-11-02 15:52:02 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-11-02 17:21:00 +01:00
|
|
|
|
|
|
|
xcb_render_pictforminfo_next(&iter);
|
2017-11-02 15:52:02 +01:00
|
|
|
}
|
2017-11-02 17:21:00 +01:00
|
|
|
|
2017-11-02 15:52:02 +01:00
|
|
|
if (format == NULL) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "No 32 bit render format");
|
2017-12-29 15:56:39 +01:00
|
|
|
free(reply);
|
2017-11-02 16:59:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xwm->render_format_id = format->id;
|
2017-12-29 15:56:39 +01:00
|
|
|
free(reply);
|
2017-11-02 16:59:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride,
|
|
|
|
uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y) {
|
|
|
|
if (!xwm->render_format_id) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "Cannot set xwm cursor: no render format available");
|
2017-11-02 15:52:02 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-11-02 16:59:57 +01:00
|
|
|
if (xwm->cursor) {
|
|
|
|
xcb_free_cursor(xwm->xcb_conn, xwm->cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
int depth = 32;
|
|
|
|
|
|
|
|
xcb_pixmap_t pix = xcb_generate_id(xwm->xcb_conn);
|
|
|
|
xcb_create_pixmap(xwm->xcb_conn, depth, pix, xwm->screen->root, width,
|
|
|
|
height);
|
2017-11-02 15:52:02 +01:00
|
|
|
|
|
|
|
xcb_render_picture_t pic = xcb_generate_id(xwm->xcb_conn);
|
2017-11-02 16:59:57 +01:00
|
|
|
xcb_render_create_picture(xwm->xcb_conn, pic, pix, xwm->render_format_id,
|
|
|
|
0, 0);
|
2017-11-02 15:52:02 +01:00
|
|
|
|
|
|
|
xcb_gcontext_t gc = xcb_generate_id(xwm->xcb_conn);
|
|
|
|
xcb_create_gc(xwm->xcb_conn, gc, pix, 0, NULL);
|
|
|
|
|
|
|
|
xcb_put_image(xwm->xcb_conn, XCB_IMAGE_FORMAT_Z_PIXMAP, pix, gc,
|
|
|
|
width, height, 0, 0, 0, depth, stride * height * sizeof(uint8_t),
|
|
|
|
pixels);
|
|
|
|
xcb_free_gc(xwm->xcb_conn, gc);
|
|
|
|
|
|
|
|
xwm->cursor = xcb_generate_id(xwm->xcb_conn);
|
|
|
|
xcb_render_create_cursor(xwm->xcb_conn, xwm->cursor, pic, hotspot_x,
|
|
|
|
hotspot_y);
|
|
|
|
xcb_free_pixmap(xwm->xcb_conn, pix);
|
2021-01-21 00:53:12 +01:00
|
|
|
xcb_render_free_picture(xwm->xcb_conn, pic);
|
2017-11-02 15:52:02 +01:00
|
|
|
|
|
|
|
uint32_t values[] = {xwm->cursor};
|
|
|
|
xcb_change_window_attributes(xwm->xcb_conn, xwm->screen->root,
|
|
|
|
XCB_CW_CURSOR, values);
|
2017-11-02 16:49:22 +01:00
|
|
|
xcb_flush(xwm->xcb_conn);
|
2017-11-02 15:52:02 +01:00
|
|
|
}
|
|
|
|
|
2020-05-05 10:24:08 +02:00
|
|
|
struct wlr_xwm *xwm_create(struct wlr_xwayland *xwayland, int wm_fd) {
|
2023-10-03 07:51:07 +02:00
|
|
|
struct wlr_xwm *xwm = calloc(1, sizeof(*xwm));
|
2017-09-28 23:26:31 +02:00
|
|
|
if (xwm == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-08-19 21:25:26 +02:00
|
|
|
|
2020-05-05 10:24:08 +02:00
|
|
|
xwm->xwayland = xwayland;
|
2017-10-25 00:57:20 +02:00
|
|
|
wl_list_init(&xwm->surfaces);
|
2021-05-02 18:50:36 +02:00
|
|
|
wl_list_init(&xwm->surfaces_in_stack_order);
|
2017-09-28 23:26:31 +02:00
|
|
|
wl_list_init(&xwm->unpaired_surfaces);
|
2021-01-29 16:45:44 +01:00
|
|
|
wl_list_init(&xwm->pending_startup_ids);
|
2018-04-08 22:28:01 +02:00
|
|
|
xwm->ping_timeout = 10000;
|
2017-08-19 21:25:26 +02:00
|
|
|
|
2020-05-05 10:24:08 +02:00
|
|
|
xwm->xcb_conn = xcb_connect_to_fd(wm_fd, NULL);
|
2017-09-28 23:26:31 +02:00
|
|
|
|
|
|
|
int rc = xcb_connection_has_error(xwm->xcb_conn);
|
|
|
|
if (rc) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "xcb connect failed: %d", rc);
|
2017-08-20 07:47:38 +02:00
|
|
|
free(xwm);
|
2017-08-19 21:25:26 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-11-25 18:15:31 +01:00
|
|
|
#if HAVE_XCB_ERRORS
|
2018-03-03 17:06:27 +01:00
|
|
|
if (xcb_errors_context_new(xwm->xcb_conn, &xwm->errors_context)) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "Could not allocate error context");
|
2018-03-03 17:06:27 +01:00
|
|
|
xwm_destroy(xwm);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2020-05-05 10:24:08 +02:00
|
|
|
|
2017-10-26 16:39:36 +02:00
|
|
|
xcb_screen_iterator_t screen_iterator =
|
|
|
|
xcb_setup_roots_iterator(xcb_get_setup(xwm->xcb_conn));
|
|
|
|
xwm->screen = screen_iterator.data;
|
|
|
|
|
2020-05-05 10:24:08 +02:00
|
|
|
struct wl_event_loop *event_loop =
|
|
|
|
wl_display_get_event_loop(xwayland->wl_display);
|
|
|
|
xwm->event_source = wl_event_loop_add_fd(event_loop, wm_fd,
|
|
|
|
WL_EVENT_READABLE, x11_event_handler, xwm);
|
2017-10-24 14:49:10 +02:00
|
|
|
wl_event_source_check(xwm->event_source);
|
|
|
|
|
|
|
|
xwm_get_resources(xwm);
|
2017-10-27 21:20:50 +02:00
|
|
|
xwm_get_visual_and_colormap(xwm);
|
2017-11-02 16:59:57 +01:00
|
|
|
xwm_get_render_format(xwm);
|
2017-10-24 14:49:10 +02:00
|
|
|
|
2017-11-02 00:03:55 +01:00
|
|
|
uint32_t values[] = {
|
2017-10-26 16:39:36 +02:00
|
|
|
XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY |
|
2017-11-02 00:03:55 +01:00
|
|
|
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
|
|
|
|
XCB_EVENT_MASK_PROPERTY_CHANGE,
|
|
|
|
};
|
2017-10-26 16:39:36 +02:00
|
|
|
xcb_change_window_attributes(xwm->xcb_conn,
|
|
|
|
xwm->screen->root,
|
2017-11-02 15:52:02 +01:00
|
|
|
XCB_CW_EVENT_MASK,
|
2017-10-26 16:39:36 +02:00
|
|
|
values);
|
|
|
|
|
2017-10-29 15:36:16 +01:00
|
|
|
xcb_composite_redirect_subwindows(xwm->xcb_conn,
|
|
|
|
xwm->screen->root,
|
2017-10-26 16:39:36 +02:00
|
|
|
XCB_COMPOSITE_REDIRECT_MANUAL);
|
2017-10-24 14:49:10 +02:00
|
|
|
|
|
|
|
xcb_atom_t supported[] = {
|
|
|
|
xwm->atoms[NET_WM_STATE],
|
2020-03-06 12:37:43 +01:00
|
|
|
xwm->atoms[NET_ACTIVE_WINDOW],
|
|
|
|
xwm->atoms[NET_WM_MOVERESIZE],
|
2020-07-27 13:41:54 +02:00
|
|
|
xwm->atoms[NET_WM_STATE_FOCUSED],
|
2020-03-06 12:37:43 +01:00
|
|
|
xwm->atoms[NET_WM_STATE_MODAL],
|
|
|
|
xwm->atoms[NET_WM_STATE_FULLSCREEN],
|
|
|
|
xwm->atoms[NET_WM_STATE_MAXIMIZED_VERT],
|
|
|
|
xwm->atoms[NET_WM_STATE_MAXIMIZED_HORZ],
|
2020-07-18 21:37:02 +02:00
|
|
|
xwm->atoms[NET_WM_STATE_HIDDEN],
|
2020-03-06 12:37:43 +01:00
|
|
|
xwm->atoms[NET_CLIENT_LIST],
|
2021-05-02 18:50:36 +02:00
|
|
|
xwm->atoms[NET_CLIENT_LIST_STACKING],
|
2017-10-24 14:49:10 +02:00
|
|
|
};
|
2017-10-26 16:39:36 +02:00
|
|
|
xcb_change_property(xwm->xcb_conn,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
xwm->screen->root,
|
|
|
|
xwm->atoms[NET_SUPPORTED],
|
|
|
|
XCB_ATOM_ATOM,
|
|
|
|
32,
|
|
|
|
sizeof(supported)/sizeof(*supported),
|
|
|
|
supported);
|
2017-10-24 14:49:10 +02:00
|
|
|
|
2022-12-08 02:04:58 +01:00
|
|
|
#if HAVE_XCB_XFIXES_SET_CLIENT_DISCONNECT_MODE
|
2021-06-25 13:49:47 +02:00
|
|
|
if (xwm->xwayland->server->options.terminate_delay > 0 &&
|
|
|
|
xwm->xfixes_major_version >= 6) {
|
|
|
|
xcb_xfixes_set_client_disconnect_mode(xwm->xcb_conn,
|
|
|
|
XCB_XFIXES_CLIENT_DISCONNECT_FLAGS_TERMINATE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-10-26 21:58:18 +02:00
|
|
|
xcb_flush(xwm->xcb_conn);
|
|
|
|
|
2017-10-26 16:39:36 +02:00
|
|
|
xwm_set_net_active_window(xwm, XCB_WINDOW_NONE);
|
2017-10-15 20:50:21 +02:00
|
|
|
|
2021-01-31 18:27:54 +01:00
|
|
|
xwm_selection_init(&xwm->clipboard_selection, xwm, xwm->atoms[CLIPBOARD]);
|
|
|
|
xwm_selection_init(&xwm->primary_selection, xwm, xwm->atoms[PRIMARY]);
|
|
|
|
xwm_selection_init(&xwm->dnd_selection, xwm, xwm->atoms[DND_SELECTION]);
|
2017-11-20 14:51:40 +01:00
|
|
|
|
2018-02-23 10:20:53 +01:00
|
|
|
xwm->compositor_new_surface.notify = handle_compositor_new_surface;
|
2020-05-05 10:24:08 +02:00
|
|
|
wl_signal_add(&xwayland->compositor->events.new_surface,
|
2018-02-23 10:20:53 +01:00
|
|
|
&xwm->compositor_new_surface);
|
|
|
|
xwm->compositor_destroy.notify = handle_compositor_destroy;
|
2020-05-05 10:24:08 +02:00
|
|
|
wl_signal_add(&xwayland->compositor->events.destroy,
|
2018-02-23 10:20:53 +01:00
|
|
|
&xwm->compositor_destroy);
|
2017-08-19 21:25:26 +02:00
|
|
|
|
2022-10-18 13:09:17 +02:00
|
|
|
xwm->shell_v1_new_surface.notify = handle_shell_v1_new_surface;
|
|
|
|
wl_signal_add(&xwayland->shell_v1->events.new_surface,
|
|
|
|
&xwm->shell_v1_new_surface);
|
|
|
|
|
2017-10-26 16:39:36 +02:00
|
|
|
xwm_create_wm_window(xwm);
|
|
|
|
|
|
|
|
xcb_flush(xwm->xcb_conn);
|
2017-10-25 14:42:42 +02:00
|
|
|
|
2017-08-19 21:25:26 +02:00
|
|
|
return xwm;
|
|
|
|
}
|
2017-10-27 19:05:14 +02:00
|
|
|
|
2023-03-11 13:51:52 +01:00
|
|
|
void wlr_xwayland_surface_set_withdrawn(struct wlr_xwayland_surface *surface,
|
|
|
|
bool withdrawn) {
|
|
|
|
surface->withdrawn = withdrawn;
|
|
|
|
xsurface_set_wm_state(surface);
|
|
|
|
xsurface_set_net_wm_state(surface);
|
|
|
|
xcb_flush(surface->xwm->xcb_conn);
|
|
|
|
}
|
|
|
|
|
2020-07-18 21:37:02 +02:00
|
|
|
void wlr_xwayland_surface_set_minimized(struct wlr_xwayland_surface *surface,
|
|
|
|
bool minimized) {
|
|
|
|
surface->minimized = minimized;
|
2023-03-11 13:51:52 +01:00
|
|
|
xsurface_set_wm_state(surface);
|
2020-07-18 21:37:02 +02:00
|
|
|
xsurface_set_net_wm_state(surface);
|
|
|
|
xcb_flush(surface->xwm->xcb_conn);
|
|
|
|
}
|
|
|
|
|
2017-12-03 23:30:57 +01:00
|
|
|
void wlr_xwayland_surface_set_maximized(struct wlr_xwayland_surface *surface,
|
|
|
|
bool maximized) {
|
2017-11-20 19:52:47 +01:00
|
|
|
surface->maximized_horz = maximized;
|
|
|
|
surface->maximized_vert = maximized;
|
|
|
|
xsurface_set_net_wm_state(surface);
|
|
|
|
xcb_flush(surface->xwm->xcb_conn);
|
2017-10-27 19:05:14 +02:00
|
|
|
}
|
|
|
|
|
2017-12-03 23:30:57 +01:00
|
|
|
void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland_surface *surface,
|
|
|
|
bool fullscreen) {
|
2017-11-20 19:52:47 +01:00
|
|
|
surface->fullscreen = fullscreen;
|
|
|
|
xsurface_set_net_wm_state(surface);
|
|
|
|
xcb_flush(surface->xwm->xcb_conn);
|
2017-10-27 19:05:14 +02:00
|
|
|
}
|
2018-02-25 09:57:30 +01:00
|
|
|
|
2018-03-04 11:16:14 +01:00
|
|
|
bool xwm_atoms_contains(struct wlr_xwm *xwm, xcb_atom_t *atoms,
|
2018-02-25 09:57:30 +01:00
|
|
|
size_t num_atoms, enum atom_name needle) {
|
|
|
|
xcb_atom_t atom = xwm->atoms[needle];
|
|
|
|
|
|
|
|
for (size_t i = 0; i < num_atoms; ++i) {
|
|
|
|
if (atom == atoms[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-08 18:02:52 +02:00
|
|
|
|
2018-04-08 22:28:01 +02:00
|
|
|
void wlr_xwayland_surface_ping(struct wlr_xwayland_surface *surface) {
|
|
|
|
xcb_client_message_data_t data = { 0 };
|
2020-03-06 12:37:43 +01:00
|
|
|
data.data32[0] = surface->xwm->atoms[NET_WM_PING];
|
2018-04-08 22:28:01 +02:00
|
|
|
data.data32[1] = XCB_CURRENT_TIME;
|
|
|
|
data.data32[2] = surface->window_id;
|
|
|
|
|
2018-05-26 09:08:20 +02:00
|
|
|
xwm_send_wm_message(surface, &data, XCB_EVENT_MASK_NO_EVENT);
|
2018-04-08 22:28:01 +02:00
|
|
|
|
|
|
|
wl_event_source_timer_update(surface->ping_timer,
|
|
|
|
surface->xwm->ping_timeout);
|
|
|
|
surface->pinging = true;
|
|
|
|
}
|
2018-07-29 11:20:16 +02:00
|
|
|
|
|
|
|
bool wlr_xwayland_or_surface_wants_focus(
|
2021-01-12 15:10:38 +01:00
|
|
|
const struct wlr_xwayland_surface *xsurface) {
|
2022-12-18 11:55:39 +01:00
|
|
|
static const enum atom_name needles[] = {
|
2018-07-29 11:20:16 +02:00
|
|
|
NET_WM_WINDOW_TYPE_COMBO,
|
|
|
|
NET_WM_WINDOW_TYPE_DND,
|
|
|
|
NET_WM_WINDOW_TYPE_DROPDOWN_MENU,
|
|
|
|
NET_WM_WINDOW_TYPE_MENU,
|
|
|
|
NET_WM_WINDOW_TYPE_NOTIFICATION,
|
|
|
|
NET_WM_WINDOW_TYPE_POPUP_MENU,
|
|
|
|
NET_WM_WINDOW_TYPE_SPLASH,
|
2024-01-25 17:27:37 +01:00
|
|
|
NET_WM_WINDOW_TYPE_DESKTOP,
|
2018-07-29 11:20:16 +02:00
|
|
|
NET_WM_WINDOW_TYPE_TOOLTIP,
|
|
|
|
NET_WM_WINDOW_TYPE_UTILITY,
|
|
|
|
};
|
2021-01-12 15:10:38 +01:00
|
|
|
|
2018-07-29 11:20:16 +02:00
|
|
|
for (size_t i = 0; i < sizeof(needles) / sizeof(needles[0]); ++i) {
|
2021-01-12 15:10:38 +01:00
|
|
|
if (xwm_atoms_contains(xsurface->xwm, xsurface->window_type,
|
|
|
|
xsurface->window_type_len, needles[i])) {
|
|
|
|
return false;
|
2018-07-29 11:20:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-12 15:10:38 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum wlr_xwayland_icccm_input_model wlr_xwayland_icccm_input_model(
|
|
|
|
const struct wlr_xwayland_surface *xsurface) {
|
|
|
|
bool take_focus = xwm_atoms_contains(xsurface->xwm,
|
|
|
|
xsurface->protocols, xsurface->protocols_len,
|
|
|
|
WM_TAKE_FOCUS);
|
|
|
|
|
2021-03-29 11:57:31 +02:00
|
|
|
if (!xsurface->hints || xsurface->hints->input) {
|
2021-01-12 15:10:38 +01:00
|
|
|
if (take_focus) {
|
|
|
|
return WLR_ICCCM_INPUT_MODEL_LOCAL;
|
|
|
|
}
|
|
|
|
return WLR_ICCCM_INPUT_MODEL_PASSIVE;
|
|
|
|
} else {
|
|
|
|
if (take_focus) {
|
|
|
|
return WLR_ICCCM_INPUT_MODEL_GLOBAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return WLR_ICCCM_INPUT_MODEL_NONE;
|
2018-07-29 11:20:16 +02:00
|
|
|
}
|
2023-10-24 16:33:50 +02:00
|
|
|
|
|
|
|
void wlr_xwayland_set_workareas(struct wlr_xwayland *wlr_xwayland,
|
|
|
|
const struct wlr_box *workareas, size_t num_workareas) {
|
|
|
|
uint32_t *data = malloc(4 * sizeof(uint32_t) * num_workareas);
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < num_workareas; i++) {
|
|
|
|
data[4 * i] = workareas[i].x;
|
|
|
|
data[4 * i + 1] = workareas[i].y;
|
|
|
|
data[4 * i + 2] = workareas[i].width;
|
|
|
|
data[4 * i + 3] = workareas[i].height;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_xwm *xwm = wlr_xwayland->xwm;
|
|
|
|
xcb_change_property(xwm->xcb_conn, XCB_PROP_MODE_REPLACE,
|
|
|
|
xwm->screen->root, xwm->atoms[NET_WORKAREA],
|
|
|
|
XCB_ATOM_CARDINAL, 32, 4 * num_workareas, data);
|
|
|
|
free(data);
|
|
|
|
}
|