From 0f948d0dd946024bcb390c2b201ab84a11f5c4c2 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 10 Feb 2019 17:42:34 +0100 Subject: [PATCH] Begin implementing selection transfers This commit adds an implementation that always answers "Test\n" when asked for the selection contents. Signed-off-by: Uli Schlachter --- event.c | 1 + objects/selection_acquire.c | 56 +++++++++++++++++++++++++++++++++++++ objects/selection_acquire.h | 1 + 3 files changed, 58 insertions(+) diff --git a/event.c b/event.c index 2c5ef7460..5e4ef9129 100644 --- a/event.c +++ b/event.c @@ -1111,6 +1111,7 @@ void event_handle(xcb_generic_event_t *event) EVENT(XCB_UNMAP_NOTIFY, event_handle_unmapnotify); EVENT(XCB_SELECTION_CLEAR, event_handle_selectionclear); EVENT(XCB_SELECTION_NOTIFY, event_handle_selectionnotify); + EVENT(XCB_SELECTION_REQUEST, selection_handle_selectionrequest); #undef EVENT } diff --git a/objects/selection_acquire.c b/objects/selection_acquire.c index 3d619cc50..4bd182480 100644 --- a/objects/selection_acquire.c +++ b/objects/selection_acquire.c @@ -107,6 +107,62 @@ selection_handle_selectionclear(xcb_selection_clear_event_t *ev) lua_pop(L, 1); } +static void +selection_transfer_notify(xcb_window_t requestor, xcb_atom_t selection, xcb_atom_t target, xcb_atom_t property, xcb_timestamp_t time) +{ + xcb_selection_notify_event_t ev; + + p_clear(&ev, 1); + ev.response_type = XCB_SELECTION_NOTIFY; + ev.requestor = requestor; + ev.selection = selection; + ev.target = target; + ev.property = property; + ev.time = time; + + xcb_send_event(globalconf.connection, false, requestor, XCB_EVENT_MASK_NO_EVENT, (char *) &ev); +} + +static void +selection_transfer_reject(xcb_window_t requestor, xcb_atom_t selection, + xcb_atom_t target, xcb_timestamp_t time) +{ + selection_transfer_notify(requestor, selection, target, XCB_NONE, time); +} + +#include "common/atoms.h" /* TODO remove */ +static void +selection_transfer_begin(lua_State *L, int ud, xcb_window_t requestor, + xcb_atom_t selection, xcb_atom_t target, xcb_atom_t property, + xcb_timestamp_t time) +{ + /* TODO implement this */ + xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, + requestor, property, UTF8_STRING, 8, 5, "Test\n"); + selection_transfer_notify(requestor, selection, target, property, time); +} + +void +selection_handle_selectionrequest(xcb_selection_request_event_t *ev) +{ + lua_State *L = globalconf_get_lua_State(); + + if (ev->property == XCB_NONE) + /* Obsolete client */ + ev->property = ev->target; + + if (selection_acquire_find_by_window(L, ev->owner) == 0) + { + selection_transfer_reject(ev->requestor, ev->selection, ev->target, ev->time); + return; + } + + selection_transfer_begin(L, -1, ev->requestor, ev->selection, ev->target, + ev->property, ev->time); + + lua_pop(L, 1); +} + static int luaA_selection_acquire_new(lua_State *L) { diff --git a/objects/selection_acquire.h b/objects/selection_acquire.h index 1f13bd3b2..8036a9f45 100644 --- a/objects/selection_acquire.h +++ b/objects/selection_acquire.h @@ -27,6 +27,7 @@ void selection_acquire_class_setup(lua_State*); void selection_handle_selectionclear(xcb_selection_clear_event_t*); +void selection_handle_selectionrequest(xcb_selection_request_event_t*); #endif