Hi all,
I'm currently learning xlib and I've encountered a bizarre mistake: function calls such as XDrawPoint, XDrawLine, etc., don't seem to work; a blank window with nothing in is appears. I believe this has something to do with the window manager I use, fluxbox.
After checking the code and not finding any mistakes, I decided to copy the code here - http://tronche.com/gui/x/xlib-tutorial/prog-2.cc - to see if it would work. Here it is:
#include <X11/Xlib.h> // Every Xlib program must include this
#include <assert.h> // I include this to test return values the lazy way
#include <unistd.h> // So we got the profile for 10 seconds
#define NIL (0) // A name for the void pointer
main()
{
// Open the display
Display *dpy = XOpenDisplay(NIL);
assert(dpy);
// Get some colors
int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
// Create the window
Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,
200, 100, 0, blackColor, blackColor);
// We want to get MapNotify events
XSelectInput(dpy, w, StructureNotifyMask);
// "Map" the window (that is, make it appear on the screen)
XMapWindow(dpy, w);
// Create a "Graphics Context"
GC gc = XCreateGC(dpy, w, 0, NIL);
// Tell the GC we draw using the white color
XSetForeground(dpy, gc, whiteColor);
// Wait for the MapNotify event
for(;;) {
XEvent e;
XNextEvent(dpy, &e);
if (e.type == MapNotify)
break;
}
// Draw the line
XDrawLine(dpy, w, gc, 10, 60, 180, 20);
// Send the "DrawLine" request to the server
XFlush(dpy);
// Wait for 10 seconds
sleep(10);
}
this is indeed completely plagiarized. Funnily though, it works (displays the white line) by starting x without fluxbox, i.e. an .xinitrc file like this:
"program-name" #first do the program
startfluxbox #then start fluxbox
this seems very bizarre and to be honest, I'm a bit lost...are there any settings I've not set?
Any help would be greatly appreciated.
Thanks in advance.