[Xcb] xcb-xfixes, problem with selection change event.

xiangxw5689 xiangxw5689 at 126.com
Thu Dec 26 02:47:35 PST 2013


I'm looking for help with selection change event in xcb-xfixes.
I want capture selection change event and I write a simple program with xcb-xfixes. But it does not work.
Please help, thanks.

code: https://gist.github.com/xiangxw/8132154
#include <stdio.h>
#include <xcb/xcb.h>
#include <xcb/xfixes.h>

int main(void)
{
    xcb_connection_t    *c;
    xcb_screen_t        *screen;
    xcb_window_t         win;
    xcb_generic_event_t *e;
    uint32_t             mask = 0;
    uint32_t             values[2];

    /* Create the window */
    c = xcb_connect (NULL, NULL);
    screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;
    win = xcb_generate_id (c);
    mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
    values[0] = screen->white_pixel;
    values[1] = XCB_EVENT_MASK_PROPERTY_CHANGE;
    xcb_create_window (c,                             /* Connection          */
                       XCB_COPY_FROM_PARENT,          /* depth               */
                       win,                           /* window Id           */
                       screen->root,                  /* parent window       */
                       0, 0,                          /* x, y                */
                       150, 150,                      /* width, height       */
                       10,                            /* border_width        */
                       XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class               */
                       screen->root_visual,           /* visual              */
                       mask, values);                 /* masks */
    xcb_map_window (c, win);
    xcb_flush (c);

    // init xfixes
    xcb_generic_error_t *error = 0;
    const xcb_query_extension_reply_t *reply = xcb_get_extension_data(c, &xcb_xfixes_id);
    if (!reply || !reply->present) {
        return -1;
    }
    xcb_xfixes_query_version_cookie_t xfixes_query_cookie = xcb_xfixes_query_version(c,
                                                                                     XCB_XFIXES_MAJOR_VERSION,
                                                                                     XCB_XFIXES_MINOR_VERSION);
    xcb_xfixes_query_version_reply_t *xfixes_query = xcb_xfixes_query_version_reply (c,
                                                                                     xfixes_query_cookie, &error);
    if (!xfixes_query || error || xfixes_query->major_version < 2) {
        free(error);
    }
    free(xfixes_query);

    // delivers request
    mask =  XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_CLIENT_CLOSE
            | XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_WINDOW_DESTROY
            | XCB_XFIXES_SELECTION_EVENT_MASK_SET_SELECTION_OWNER;
    xcb_xfixes_select_selection_input_checked(c, win, XCB_ATOM_PRIMARY, mask);
    xcb_xfixes_select_selection_input_checked(c, win, XCB_ATOM_SECONDARY, mask);

    // recevie events
    uint response_type;
    while (e = xcb_wait_for_event(c)) {
        response_type = e->response_type & ~0x80;
        if (response_type == reply->first_event + XCB_XFIXES_SELECTION_NOTIFY) {
            printf("notify\n");
        } else {
            printf("code:%d\n", response_type);
        }
    }

    return 0;
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20131226/7af40396/attachment.html>


More information about the Xcb mailing list