linux - Simple C Program that creates 2 X11 windows -
i want create 2 windows in linux i'll later draw in separate thread. have non-deterministic bug second window create doesn't created (no errors though).
here code.
static void create_x_window(display *display, window *win, int width, int height) { int screen_num = defaultscreen(display); unsigned long background = whitepixel(display, screen_num); unsigned long border = blackpixel(display, screen_num); *win = xcreatesimplewindow(display, defaultrootwindow(display), /* display, parent */ 0,0, /* x, y */ width, height, /* width, height */ 2, border, /* border width & colour */ background); /* background colour */ xselectinput(display, *win, buttonpressmask|structurenotifymask); xmapwindow(display, *win); } int main(void) { xinitthreads(); // prevent threaded xio errors local_display = xopendisplay(":0.0"); window self_win, remote_win; xevent self_event, remote_event; create_x_window(local_display, &remote_win, 640,480); // line flushes buffer , blocks window doesn't crash reason dont know yet xnextevent(local_display, &remote_event); create_x_window(local_display, &self_win, 320, 240); // line flushes buffer , blocks window doesn't crash reason dont know yet xnextevent(local_display, &self_event); while (1) { } return 0; }
i don't care capturing input in windows, found tutorial had xselectinput , xnextevent (in event loop) , having trouble making work without either.
it's not bug, it's feature. you left out event loop.
although cleverly called xnextevent twice, x protocol asynchronous server may still setting actual window while call xnextevent, there nothing do.
Comments
Post a Comment