mirror of https://github.com/buggins/dlangui.git
fix sample XCB code formatting
This commit is contained in:
parent
77ee20c6a9
commit
f3584dd6fc
|
@ -4,70 +4,73 @@ import std.stdio;
|
||||||
import std.c.linux.X11.xcb.xcb;
|
import std.c.linux.X11.xcb.xcb;
|
||||||
import std.c.linux.X11.xcb.xproto;
|
import std.c.linux.X11.xcb.xproto;
|
||||||
import std.c.stdlib;
|
import std.c.stdlib;
|
||||||
int main()
|
|
||||||
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
xcb_connection_t *c;
|
xcb_connection_t *c;
|
||||||
xcb_screen_t *s;
|
xcb_screen_t *s;
|
||||||
xcb_window_t w;
|
xcb_window_t w;
|
||||||
xcb_gcontext_t g;
|
xcb_gcontext_t g;
|
||||||
xcb_generic_event_t *e;
|
xcb_generic_event_t *e;
|
||||||
uint mask;
|
uint mask;
|
||||||
uint values[2];
|
uint values[2];
|
||||||
int done = 0;
|
int done = 0;
|
||||||
static xcb_rectangle_t r = { 20, 20, 60, 60 };
|
static xcb_rectangle_t r = { 20, 20, 60, 60 };
|
||||||
|
|
||||||
/* open connection with the server */
|
/* open connection with the server */
|
||||||
c = xcb_connect(null,null);
|
c = xcb_connect(null,null);
|
||||||
if (xcb_connection_has_error(c)) {
|
if (xcb_connection_has_error(c)) {
|
||||||
writefln("Cannot open display");
|
writefln("Cannot open display");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* get the first screen */
|
|
||||||
s = xcb_setup_roots_iterator( xcb_get_setup(c) ).data;
|
|
||||||
|
|
||||||
/* create black graphics context */
|
/* get the first screen */
|
||||||
g = xcb_generate_id(c);
|
s = xcb_setup_roots_iterator( xcb_get_setup(c) ).data;
|
||||||
w = s.root;
|
|
||||||
mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
|
||||||
values[0] = s.black_pixel;
|
|
||||||
values[1] = 0;
|
|
||||||
xcb_create_gc(c, g, w, mask, &values[0]);
|
|
||||||
|
|
||||||
/* create window */
|
/* create black graphics context */
|
||||||
w = xcb_generate_id(c);
|
g = xcb_generate_id(c);
|
||||||
mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
|
w = s.root;
|
||||||
values[0] = s.white_pixel;
|
mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
||||||
values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS;
|
values[0] = s.black_pixel;
|
||||||
xcb_create_window(c, s.root_depth, w, s.root,
|
values[1] = 0;
|
||||||
10, 10, 100, 100, 1,
|
xcb_create_gc(c, g, w, mask, &values[0]);
|
||||||
XCB_WINDOW_CLASS_INPUT_OUTPUT, s.root_visual,
|
|
||||||
mask, &values[0]);
|
|
||||||
|
|
||||||
/* map (show) the window */
|
/* create window */
|
||||||
xcb_map_window(c, w);
|
w = xcb_generate_id(c);
|
||||||
|
mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
|
||||||
|
values[0] = s.white_pixel;
|
||||||
|
values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS;
|
||||||
|
xcb_create_window(c, s.root_depth, w, s.root,
|
||||||
|
10, 10, 100, 100, 1,
|
||||||
|
XCB_WINDOW_CLASS_INPUT_OUTPUT, s.root_visual,
|
||||||
|
mask, &values[0]);
|
||||||
|
|
||||||
xcb_flush(c);
|
/* map (show) the window */
|
||||||
|
xcb_map_window(c, w);
|
||||||
|
|
||||||
/* event loop */
|
xcb_flush(c);
|
||||||
|
|
||||||
do{
|
/* event loop */
|
||||||
e = xcb_wait_for_event(c);
|
do {
|
||||||
if(!e)break;
|
|
||||||
switch (e.response_type & ~0x80) {
|
e = xcb_wait_for_event(c);
|
||||||
case XCB_EXPOSE: /* draw or redraw the window */
|
if (!e)
|
||||||
xcb_poly_fill_rectangle(c, w, g, 1, &r);
|
break;
|
||||||
xcb_flush(c);
|
switch (e.response_type & ~0x80) {
|
||||||
break;
|
case XCB_EXPOSE: /* draw or redraw the window */
|
||||||
case XCB_KEY_PRESS: /* exit on key press */
|
xcb_poly_fill_rectangle(c, w, g, 1, &r);
|
||||||
done = 1;
|
xcb_flush(c);
|
||||||
break;
|
break;
|
||||||
|
case XCB_KEY_PRESS: /* exit on key press */
|
||||||
|
done = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(e);
|
free(e);
|
||||||
}while(!done);
|
} while(!done);
|
||||||
/* close connection to server */
|
/* close connection to server */
|
||||||
xcb_disconnect(c);
|
xcb_disconnect(c);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue