为什么我不收到我订阅的活动?
我正在尝试在已经创建的窗口上收听指针运动事件(不是由我),所以首先,我使用xwininfo
进行了窗口ID并进行了硬编码以进行测试,我用不同的Windows ID进行了测试对于某些窗口,它可以使用,而对于另一些窗口而言。
Alacritty窗口ID:不工作 MPV窗口ID:使用
:gcc pointermotion.c -o pointermotion -lxcb
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <xcb/xcb.h>
#include <xcb/xproto.h>
int
main(int argc, char **argv) {
xcb_connection_t *connection;
xcb_generic_event_t *ev;
xcb_motion_notify_event_t *mnev;
xcb_get_window_attributes_cookie_t cookie;
xcb_get_window_attributes_reply_t *reply;
xcb_window_t window;
connection = xcb_connect(NULL, NULL);
window = 0x3000002;
xcb_change_window_attributes(connection, window, XCB_CW_EVENT_MASK, (const uint32_t [1]) { XCB_EVENT_MASK_POINTER_MOTION });
xcb_flush(connection);
cookie = xcb_get_window_attributes_unchecked(connection, window);
reply = xcb_get_window_attributes_reply(connection, cookie, NULL);
assert(reply->your_event_mask == XCB_EVENT_MASK_POINTER_MOTION);
free(reply);
while (1) {
while ((ev = xcb_poll_for_event(connection))) {
switch (ev->response_type & ~0x80) {
case XCB_MOTION_NOTIFY:
mnev = (xcb_motion_notify_event_t *)(ev);
printf("%d, %d\n", mnev->event_x, mnev->event_y);
break;
default:
break;
}
free(ev);
}
}
return 0;
}
I'm trying to listen to pointer motion events on an already created window (not by me), so first I got the window id using xwininfo
and hardcoded it for testing, I tested it with different windows ids and for some windows it worked and for others it didn't.
alacritty window id: not working
mpv window id: working
Compile with: gcc pointermotion.c -o pointermotion -lxcb
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <xcb/xcb.h>
#include <xcb/xproto.h>
int
main(int argc, char **argv) {
xcb_connection_t *connection;
xcb_generic_event_t *ev;
xcb_motion_notify_event_t *mnev;
xcb_get_window_attributes_cookie_t cookie;
xcb_get_window_attributes_reply_t *reply;
xcb_window_t window;
connection = xcb_connect(NULL, NULL);
window = 0x3000002;
xcb_change_window_attributes(connection, window, XCB_CW_EVENT_MASK, (const uint32_t [1]) { XCB_EVENT_MASK_POINTER_MOTION });
xcb_flush(connection);
cookie = xcb_get_window_attributes_unchecked(connection, window);
reply = xcb_get_window_attributes_reply(connection, cookie, NULL);
assert(reply->your_event_mask == XCB_EVENT_MASK_POINTER_MOTION);
free(reply);
while (1) {
while ((ev = xcb_poll_for_event(connection))) {
switch (ev->response_type & ~0x80) {
case XCB_MOTION_NOTIFY:
mnev = (xcb_motion_notify_event_t *)(ev);
printf("%d, %d\n", mnev->event_x, mnev->event_y);
break;
default:
break;
}
free(ev);
}
}
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论