mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-26 00:52:21 +00:00
xwayland/selection: extract out property requests
Apart from reducing duplication, this has the positive side-effect of allowing all deallocs to use `xwm_selection_transfer_destroy_property_reply`, as opposed to the latter and a mix of ad-hoc `free`s.
This commit is contained in:
parent
dea94f2bad
commit
23148d283f
@ -47,6 +47,8 @@ void xwm_selection_transfer_close_wl_client_fd(
|
|||||||
struct wlr_xwm_selection_transfer *transfer);
|
struct wlr_xwm_selection_transfer *transfer);
|
||||||
void xwm_selection_transfer_destroy_property_reply(
|
void xwm_selection_transfer_destroy_property_reply(
|
||||||
struct wlr_xwm_selection_transfer *transfer);
|
struct wlr_xwm_selection_transfer *transfer);
|
||||||
|
bool xwm_selection_transfer_get_selection_property(
|
||||||
|
struct wlr_xwm_selection_transfer *transfer, bool delete);
|
||||||
|
|
||||||
xcb_atom_t xwm_mime_type_to_atom(struct wlr_xwm *xwm, char *mime_type);
|
xcb_atom_t xwm_mime_type_to_atom(struct wlr_xwm *xwm, char *mime_type);
|
||||||
char *xwm_mime_type_from_atom(struct wlr_xwm *xwm, xcb_atom_t atom);
|
char *xwm_mime_type_from_atom(struct wlr_xwm *xwm, xcb_atom_t atom);
|
||||||
|
@ -61,13 +61,9 @@ static int xwm_data_source_write(int fd, uint32_t mask, void *data) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xwm_write_property(struct wlr_xwm_selection_transfer *transfer,
|
static void xwm_write_property(struct wlr_xwm_selection_transfer *transfer) {
|
||||||
xcb_get_property_reply_t *reply) {
|
|
||||||
struct wlr_xwm *xwm = transfer->selection->xwm;
|
struct wlr_xwm *xwm = transfer->selection->xwm;
|
||||||
|
|
||||||
transfer->property_start = 0;
|
|
||||||
transfer->property_reply = reply;
|
|
||||||
|
|
||||||
bool wl_client_finished_consuming =
|
bool wl_client_finished_consuming =
|
||||||
!xwm_data_source_write(transfer->wl_client_fd, WL_EVENT_WRITABLE, transfer);
|
!xwm_data_source_write(transfer->wl_client_fd, WL_EVENT_WRITABLE, transfer);
|
||||||
if (!wl_client_finished_consuming) {
|
if (!wl_client_finished_consuming) {
|
||||||
@ -83,74 +79,48 @@ static void xwm_write_property(struct wlr_xwm_selection_transfer *transfer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void xwm_get_incr_chunk(struct wlr_xwm_selection_transfer *transfer) {
|
void xwm_get_incr_chunk(struct wlr_xwm_selection_transfer *transfer) {
|
||||||
struct wlr_xwm *xwm = transfer->selection->xwm;
|
|
||||||
wlr_log(WLR_DEBUG, "xwm_get_incr_chunk");
|
wlr_log(WLR_DEBUG, "xwm_get_incr_chunk");
|
||||||
|
|
||||||
xcb_get_property_cookie_t cookie = xcb_get_property(xwm->xcb_conn,
|
if (!xwm_selection_transfer_get_selection_property(transfer, false)) {
|
||||||
0, // delete
|
|
||||||
transfer->selection->window,
|
|
||||||
xwm->atoms[WL_SELECTION],
|
|
||||||
XCB_GET_PROPERTY_TYPE_ANY,
|
|
||||||
0, // offset
|
|
||||||
0x1fffffff // length
|
|
||||||
);
|
|
||||||
|
|
||||||
xcb_get_property_reply_t *reply =
|
|
||||||
xcb_get_property_reply(xwm->xcb_conn, cookie, NULL);
|
|
||||||
if (reply == NULL) {
|
|
||||||
wlr_log(WLR_ERROR, "cannot get selection property");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//dump_property(xwm, xwm->atoms[WL_SELECTION], reply);
|
|
||||||
|
|
||||||
if (xcb_get_property_value_length(reply) > 0) {
|
if (xcb_get_property_value_length(transfer->property_reply) > 0) {
|
||||||
// Reply's ownership is transferred to xwm, which is responsible
|
// Reply's ownership is transferred to xwm, which is responsible
|
||||||
// for freeing it.
|
// for freeing it.
|
||||||
if (transfer->wl_client_fd >= 0) {
|
if (transfer->wl_client_fd >= 0) {
|
||||||
// Wayland client is alive, property will be freed once it has finished
|
// Wayland client is alive, property will be freed once it has finished
|
||||||
// reading it.
|
// reading it.
|
||||||
xwm_write_property(transfer, reply);
|
xwm_write_property(transfer);
|
||||||
} else {
|
} else {
|
||||||
// Wayland client closed its pipe prematurely (or died). Continue draining
|
// Wayland client closed its pipe prematurely (or died). Continue draining
|
||||||
// the X11 client.
|
// the X11 client.
|
||||||
xwm_notify_ready_for_next_incr_chunk(transfer);
|
xwm_notify_ready_for_next_incr_chunk(transfer);
|
||||||
free(reply);
|
xwm_selection_transfer_destroy_property_reply(transfer);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
wlr_log(WLR_DEBUG, "incremental transfer complete");
|
wlr_log(WLR_DEBUG, "incremental transfer complete");
|
||||||
xwm_selection_transfer_close_wl_client_fd(transfer);
|
xwm_selection_transfer_close_wl_client_fd(transfer);
|
||||||
free(reply);
|
xwm_selection_transfer_destroy_property_reply(transfer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xwm_selection_get_data(struct wlr_xwm_selection *selection) {
|
static void xwm_selection_get_data(struct wlr_xwm_selection *selection) {
|
||||||
struct wlr_xwm *xwm = selection->xwm;
|
struct wlr_xwm *xwm = selection->xwm;
|
||||||
|
struct wlr_xwm_selection_transfer *transfer = &selection->incoming;
|
||||||
|
|
||||||
xcb_get_property_cookie_t cookie = xcb_get_property(xwm->xcb_conn,
|
if (!xwm_selection_transfer_get_selection_property(transfer, true)) {
|
||||||
1, // delete
|
|
||||||
selection->window,
|
|
||||||
xwm->atoms[WL_SELECTION],
|
|
||||||
XCB_GET_PROPERTY_TYPE_ANY,
|
|
||||||
0, // offset
|
|
||||||
0x1fffffff // length
|
|
||||||
);
|
|
||||||
|
|
||||||
xcb_get_property_reply_t *reply =
|
|
||||||
xcb_get_property_reply(xwm->xcb_conn, cookie, NULL);
|
|
||||||
if (reply == NULL) {
|
|
||||||
wlr_log(WLR_ERROR, "Cannot get selection property");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_xwm_selection_transfer *transfer = &selection->incoming;
|
if (transfer->property_reply->type == xwm->atoms[INCR]) {
|
||||||
if (reply->type == xwm->atoms[INCR]) {
|
|
||||||
transfer->incr = true;
|
transfer->incr = true;
|
||||||
free(reply);
|
xwm_selection_transfer_destroy_property_reply(transfer);
|
||||||
} else {
|
} else {
|
||||||
transfer->incr = false;
|
transfer->incr = false;
|
||||||
// reply's ownership is transferred to wm, which is responsible
|
// reply's ownership is transferred to wm, which is responsible
|
||||||
// for freeing it
|
// for freeing it
|
||||||
xwm_write_property(transfer, reply);
|
xwm_write_property(transfer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,32 @@ void xwm_selection_transfer_destroy_property_reply(
|
|||||||
transfer->property_reply = NULL;
|
transfer->property_reply = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool xwm_selection_transfer_get_selection_property(
|
||||||
|
struct wlr_xwm_selection_transfer *transfer, bool delete) {
|
||||||
|
struct wlr_xwm *xwm = transfer->selection->xwm;
|
||||||
|
|
||||||
|
xcb_get_property_cookie_t cookie = xcb_get_property(
|
||||||
|
xwm->xcb_conn,
|
||||||
|
delete,
|
||||||
|
transfer->selection->window,
|
||||||
|
xwm->atoms[WL_SELECTION],
|
||||||
|
XCB_GET_PROPERTY_TYPE_ANY,
|
||||||
|
0, // offset
|
||||||
|
0x1fffffff // length
|
||||||
|
);
|
||||||
|
|
||||||
|
transfer->property_start = 0;
|
||||||
|
transfer->property_reply =
|
||||||
|
xcb_get_property_reply(xwm->xcb_conn, cookie, NULL);
|
||||||
|
|
||||||
|
if (!transfer->property_reply) {
|
||||||
|
wlr_log(WLR_ERROR, "cannot get selection property");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
xcb_atom_t xwm_mime_type_to_atom(struct wlr_xwm *xwm, char *mime_type) {
|
xcb_atom_t xwm_mime_type_to_atom(struct wlr_xwm *xwm, char *mime_type) {
|
||||||
if (strcmp(mime_type, "text/plain;charset=utf-8") == 0) {
|
if (strcmp(mime_type, "text/plain;charset=utf-8") == 0) {
|
||||||
return xwm->atoms[UTF8_STRING];
|
return xwm->atoms[UTF8_STRING];
|
||||||
|
Loading…
Reference in New Issue
Block a user