Search code examples
c++clinuxclipboardx11

Xlib how to answer to wrong target in XSelectionRequestEvent?


I'm working on program for sending clipboard contents between different computers.

Now I'm stuck on processing request for sending data from clipboard to requestor on Linux with Xorg.

For example my program is own image/bmp data, but other program send me request for image/png that I'm just ignore. After approximately 30 seconds other program send me other request for image/jpeg and so on.

How to properly send answer to this wrong targets so other program wouldn't wait this 30 seconds timeout?


Solution

  • I just send XSelectionEvent with property field set to None.

    // event is event that i responde
    
    XEvent ev;
    auto& sel_resp = ev.xselection;
    sel_resp.type = SelectionNotify;
    sel_resp.display = event.display;
    sel_resp.requestor = event.requestor;
    sel_resp.selection = event.selection;
    sel_resp.target = event.target;
    // Set property to None
    sel_resp.property = None;
    sel_resp.time = event.time;
    XSendEvent( mDisplay, event.requestor, False, 0, &ev );