x11 - Xlib won't draw anyting -
i'm pretty stuck on i'm doing wrong, i've attempted copy example code, i've tried changing colors. here's code:
//headers #include <stdio.h> #include <stdlib.h> #include <x11/xlib.h> #include <x11/xatom.h> int main(int argc, char *argv[]) { //vars create window display *dis; int screen; window win; xevent event; //graphics content xgcvalues values; unsigned long valuemask = 0; gc gc; //to store mouse location int mousex[2], mousey[2]; //stores screen dimensions xwindowattributes xwa; int screenheight, screenwidth; //colors colormap colormap; xcolor backgroundcolor, white; //checks open display dis = xopendisplay(null); //displays error if(dis == null) { fprintf(stderr, "cannot open display\n"); exit(1); } //sets screen screen = defaultscreen(dis); colormap = defaultcolormap(dis, screen); //background color xparsecolor(dis, colormap, "#75677e", &backgroundcolor); xalloccolor(dis, colormap, &backgroundcolor); //white xparsecolor(dis, colormap, "#ffffff", &white); xalloccolor(dis, colormap, &white); //creates window win = xcreatesimplewindow(dis, rootwindow(dis, screen), 100, 100, 500, 300, 1, blackpixel(dis, screen), backgroundcolor.pixel); //changes window full screen //atom atoms[2] = { xinternatom(dis, "_net_wm_state_fullscreen", false), none }; //xchangeproperty(dis, win, xinternatom(dis, "_net_wm_state", false), xa_atom, 32, propmodereplace, (unsigned char *)atoms, 1); //allocates graphics content gc = xcreategc(dis, win, valuemask, &values); xsetlineattributes(dis, gc, 2, linesolid, capbutt, joinbevel); xsetfillstyle(dis, gc, fillsolid); xsync(dis, false); //stores screen dimensions //todo: test xgetwindowattributes(dis, win, &xwa); screenwidth = xwa.width; screenheight = xwa.height; //inner circle //xfillarc(dis, win) xsetforeground(dis, gc, blackpixel(dis, screen)); xfillrectangle(dis, win, gc, 0, 100, 50, 50); //listens input xselectinput(dis, win, exposuremask | keypressmask); //maps window xmapwindow(dis, win); while(1) { xnextevent(dis, &event); } xclosedisplay(dis); return 0; }
i no errors in console when run it, nothing baddrawable or anything. opens window fine, no rectangle appears on screen. i've tried making draw line, point, , arc.
this not authoritative answer, knowledge on subject sketchy @ best, event loop looks empty. window needs redrawn when expose
event received.
for example:
while(1) { xnextevent(dis, &event); switch(event.type) { case expose: if (event.xexpose.count) break; xfillrectangle(dis, win, gc, 0, 100, 50, 50); break; default: break; } }
Comments
Post a Comment