为什么我不收到我订阅的活动?

发布于 2025-01-22 16:25:37 字数 1586 浏览 1 评论 0原文

我正在尝试在已经创建的窗口上收听指针运动事件(不是由我),所以首先,我使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文