我正在编写一个组件,它必须监视 CLIPBOARD 中 X11 窗口的变化。
auto display = XOpenDisplay(NULL);
auto screen = DefaultScreen(mdisplay);
auto root_window = RootWindow(display, screen);
clipboard = XInternAtom(display, "CLIPBOARD", 0);
window = XCreateSimpleWindow(mdisplay, root_window, 0, 0, 1, 1, 0, 0, 0);
while(true) {
XEvent event = {0};
XNextEvent(display, &event);
switch(event.type) {
case SelectionNotify: {
// do something
}
break;
case SelectionRequest: { // triggered after performing copy
auto target_name = XGetAtomName(display, event.xselectionrequest.target);
auto selection_name = XGetAtomName(display, event.xselectionrequest.selection);
auto property_name = XGetAtomName(display, event.xselectionrequest.property);
Log("Event SelectionRequest: owner: %ld, requestor: %ld, selection: %s, target: %s(%d), property: %s",
event.xselectionrequest.owner,
event.xselectionrequest.requestor,
selection_name,
target_name,
event.xselectionrequest.target,
property_name);
if(x_event.xselectionrequest.selection != clipboard) {
Log("%s: Warning: event selection not matching\n", __func__);
break;
}
}
break;
}
}
问题是当我尝试检查事件时,SelectionRequest
我看到的只是
Event SelectionRequest: owner: 33554433, requestor: 18874649, selection: CLIPBOARD, target: TARGETS(344), property: GDK_SELECTION
我正在执行的操作是从 Chrome 浏览器中复制一些文本。谁能告诉我为什么我没有看到这个文本,unicode,字符串类型,而是GDK_SELECTION
?
PS:碰巧我只看到过一次这些格式(文本、Unicode、字符串类型),但再也没有看到过。