xcb_connection_t *c =xcb_connect(NULL,NULL);/* Get the first screen */
xcb_screen_t *screen =xcb_setup_roots_iterator(xcb_get_setup(c)).data;/* Ask for our window's Id */
xcb_window_t winId =xcb_generate_id(c);uint32_t baseMask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;uint32_t values[2];// 可以捕获自己关注的事件
values[0]= screen->white_pixel;
values[1]= XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS |
XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION |
XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW |
XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE;/* Create the window */xcb_create_window(c,/* Connection */
XCB_COPY_FROM_PARENT,/* depth (same as root)*/
winId,/* window Id */
screen->root,/* parent window */0,0,/* x, y */480,480,/* width, height */10,/* border_width */
XCB_WINDOW_CLASS_INPUT_OUTPUT,/* class */
screen->root_visual,/* visual */
baseMask, values);/* masks, not used yet *//* Map the window on the screen */xcb_map_window(c, winId);/* Make sure commands are sent before we pause, so window is shown */xcb_flush(c);
二、注册tablet或者touch事件
structqt_xcb_input_event_mask_t{
xcb_input_event_mask_t header;uint32_t mask;};voidxi2SelectDeviceEvents(xcb_connection_t *c, xcb_window_t window){uint32_t bitMask = XCB_INPUT_XI_EVENT_MASK_BUTTON_PRESS;
bitMask |= XCB_INPUT_XI_EVENT_MASK_BUTTON_RELEASE;
bitMask |= XCB_INPUT_XI_EVENT_MASK_MOTION;// There is a check for enter/leave events in plain xcb enter/leave event handler,// core enter/leave events will be ignored in this case.
bitMask |= XCB_INPUT_XI_EVENT_MASK_ENTER;
bitMask |= XCB_INPUT_XI_EVENT_MASK_LEAVE;
qt_xcb_input_event_mask_t mask;
mask.header.deviceid = XCB_INPUT_DEVICE_ALL_MASTER;
mask.header.mask_len =1;
mask.mask = bitMask;xcb_input_xi_select_events_checked(c, window,1,&mask.header);}// 参数:已经创建好的连接、窗口IDxi2SelectDeviceEvents(c, winId);