XFixesSelectSelectionInput()
Xfixesを使用し、XFixesSelectionNotify
イベントを待ちます。
例:
// gcc -o xclipwatch xclipwatch.c -lX11 -lXfixes
...
#include <X11/extensions/Xfixes.h>
...
void WatchSelection(Display *display, Window window, const char *bufname)
{
int event_base, error_base;
XEvent event;
Atom bufid = XInternAtom(display, bufname, False);
assert(XFixesQueryExtension(display, &event_base, &error_base));
XFixesSelectSelectionInput(display, DefaultRootWindow(display), bufid, XFixesSetSelectionOwnerNotifyMask);
while (True)
{
XNextEvent(display, &event);
if (event.type == event_base + XFixesSelectionNotify &&
((XFixesSelectionNotifyEvent*)&event)->selection == bufid)
{
if (!PrintSelection(display, window, bufname, "UTF8_STRING"))
PrintSelection(display, window, bufname, "STRING");
fflush(stdout);
}
}
}
...
これは、両方のbufname == "CLIPBOARD"
とbufname == "PRIMARY"
選択のために動作します。
PrintSelection()
関数in this answerも参照してください。
これは質問に答えません。 –