问题描述
刚开始使用C进行XCB编程。我编写了这段代码,该代码将创建一个窗口并绘制一些点和一个矩形:
#include <stdlib.h>
#include <stdio.h>
#include <xcb/xcb.h>
int main() {
xcb_connection_t *connection = xcb_connect(NULL,NULL);
if (xcb_connection_has_error(connection)) {
printf("Error setting up connection to X\n");
exit(1);
}
const xcb_setup_t *setup = xcb_get_setup(connection);
xcb_screen_t *screen = xcb_setup_roots_iterator(setup).data;
// Create wndow
xcb_window_t window_id = xcb_generate_id(connection);
uint32_t prop_name = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
uint32_t prop_value[2];
prop_value[0] = screen->white_pixel;
prop_value[1] = XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_EXPOSURE;
xcb_create_window(connection,screen->root_depth,window_id,screen->root,100,500,400,1,XCB_WINDOW_CLASS_INPUT_OUTPUT,screen->root_visual,prop_name,&prop_value);
xcb_map_window(connection,window_id);
xcb_flush(connection);
uint32_t gc_value_mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
uint32_t gc_value_list[2];
gc_value_list[0] = screen->black_pixel;
gc_value_list[1] = 0;
xcb_drawable_t drawable_window = screen->root;
xcb_gcontext_t context_id = xcb_generate_id(connection);
xcb_void_cookie_t cookie = xcb_create_gc(connection,context_id,drawable_window,gc_value_mask,gc_value_list);
// Create polygons
xcb_point_t points[5] = {{10,10},{10,50},{40,70},{70,40},{50,10}};
xcb_rectangle_t rect = {50,50,50};
// Main loop
xcb_generic_event_t *event;
while ((event = xcb_wait_for_event(connection))) {
switch (event->response_type) {
case XCB_KEY_PRESS:
break;
case XCB_BUTTON_PRESS:
break;
case XCB_EXPOSE:
printf("Expose event called\n");
// Draw polygons
xcb_poly_point(connection,XCB_COORD_MODE_ORIGIN,4,points);
xcb_poly_fill_rectangle(connection,&rect);
xcb_flush(connection);
default:
break;
}
free(event);
}
return 0;
}
它已正确编译,并且在运行时没有警告或错误。但是,我只是得到一个没有图形的窗口。我在做什么错了?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)