Irbis
Irbis

Reputation: 13369

A code which is ported from xlib to xcb doesn't work

Here is an example code which sends a mouse click (using xlib). For simplicity events are sent to the fullscreen window (root and window coordinates are the same) and window id is obtained using wmctrl.

Display *display = XOpenDisplay(NULL);
XWarpPointer(display, None, RootWindow(display, DefaultScreen(display)), 0, 0, 0, 0, 300, 200);
XEvent event;
memset(&event, 0x00, sizeof(event));
event.type = ButtonPress;
event.xbutton.button = button;
event.xbutton.same_screen = True;
event.xbutton.root = RootWindow(display, DefaultScreen(display));
event.xbutton.window = 81788929;
event.xbutton.subwindow = 0;
event.xbutton.x_root = 300;
event.xbutton.y_root = 200;
event.xbutton.x = 300;
event.xbutton.y = 200;
event.xbutton.state = 0;

XSendEvent(display, PointerWindow, True, ButtonPressMask, &event);
XFlush(display);
XCloseDisplay(display);

Above code works fine. I ported it to xcb:

Display *display = XOpenDisplay(NULL);
XWarpPointer(display, None, RootWindow(display, DefaultScreen(display)), 0, 0, 0, 0, 300, 200);


xcb_button_press_event_t event;
memset(&event, 0x00, sizeof(event));
event.event = 81788929;
event.same_screen = 1;
event.root = RootWindow(display, DefaultScreen(display));
event.root_x = 300;
event.root_y = 200;
event.event_x = 300;
event.event_y = 200;
event.child = 0;
event.state = 0;

xcb_connection_t *conn = XGetXCBConnection(display);
xcb_send_event(conn, false, 81788929, XCB_EVENT_MASK_BUTTON_PRESS, (char*)(&event));
xcb_flush(conn);
XCloseDisplay(display);

XCB code doesn't work: destination window doesn't get any event. What is wrong ?

Edit1 When I use following code for a connection:

xcb_connection_t *conn;
xcb_screen_t     *screen;
conn = xcb_connect (NULL, NULL);
screen = xcb_setup_roots_iterator (xcb_get_setup (conn)).data;

and later:

event.root = screen->root;

it also doesn't work.

Upvotes: 1

Views: 711

Answers (1)

datenwolf
datenwolf

Reputation: 162164

Nowhere in your code there are error checks. Anyway, I suspect that XGetXCBConnection(display); does not return you a valid Xcb connection. Why you may ask? Because for this to work Xlib must have been built as a wrapper around Xcb and the internal structures properly been set up.

I suggest you create the connection and open the display purely with Xcb and see if this solves the problem.

Upvotes: 1

Related Questions