处理XCB中的多个窗口的好方法

huangapple go评论95阅读模式
英文:

A good way to handle multiple windows in xcb

问题

我正在使用xcb开发一个X11应用程序。问题是,我想创建多个窗口,但我找不到任何方法来从事件循环中确定事件来自哪个窗口。我应该打开多个连接吗?在使用一个连接时,是否有一种方法可以在某种程度上分离这些事件?另外,我看到X11lib有上下文管理器,但我找不到有关xcb是否有类似功能的信息。

我已经在xcb文档和谷歌上尝试查找有关这个主题的信息,但没有找到关于处理多个窗口和它们的事件的太多内容。

英文:

I'm working on an X11 app using xcb. The problem is, I want to make multiple windows, but I cannot find any way to tell from the event loop, from which window the event comes from. Should I open multiple connections? Is there a way to separate somehow those events when using one connection?
Also i've seen that X11lib has Context Manager, and I've couldn't find any information on does the xcb has an analogue for that.

I've tried to find something on the topic in the xcb documentation and in google. Didn't find so much about handling multiple windows and events from them.

答案1

得分: 1

这取决于实际的事件类型,但对于大多数类型,都有一个独立的窗口ID字段。一些示例:

英文:

It depends on the actual event type, but for most types there is a separate field for window ID. Some examples:

xcb_generic_event_t *e;
while ((e = xcb_wait_for_event(connection))) {
    uint8_t type = XCB_EVENT_RESPONSE_TYPE(e);
    switch (type) {
        case XCB_CREATE_NOTIFY: {
            xcb_create_notify_event_t *create_event =
                (xcb_create_notify_event_t *)e;
            xcb_window_t wid = create_event->window;
            break;
        }
        case XCB_ENTER_NOTIFY: {
            xcb_enter_notify_event_t *enter_event =
                (xcb_enter_notify_event_t *)e;
            xcb_window_t wid = enter_event->event;
            break;
        }
        case XCB_BUTTON_PRESS: {
            xcb_button_press_event_t *press_event =
                (xcb_button_press_event_t *)e;
            xcb_window_t wid = press_event->event;
            break;
        }
        case XCB_PROPERTY_NOTIFY: {
            xcb_property_notify_event_t *notify_event =
                (xcb_property_notify_event_t *)e;
            xcb_window_t wid = notify_event->window;
            break;
        }
        case XCB_EXPOSE: {
            xcb_expose_event_t *expose_event = (xcb_expose_event_t *)e;
            xcb_window_t wid = expose_event->window;
            break;
        }
        ...
    }
}

huangapple
  • 本文由 发表于 2023年6月15日 01:43:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76476254.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定