I've recently started to learn the Xlib API (mostly for fun).
I'm seeing some strange behavior with my simple tutorial programs,
so I'm trying different window managers (to see if the problems are
me or the window manager). However, in FVWM, the attached program
only draws a "transparent" window. The background of the window is
the same as the root window, and none of the text shows up.
Under enlightenment 0.16.7.2 and fluxbox 0.9.14 the text shows up.
Any thoughts?
Thanks!
Matt
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <unistd.h>
int main(int argc, char* argv[])
{
Display *dpy = NULL;
Window window;
char* display_name = NULL;
XFontStruct* font_info;
char* font_name = "10x20";
GC gc;
XGCValues values;
unsigned long valuemask = 0;
int screen_num = 0;
/* create display */
display_name = getenv("DISPLAY");
dpy = XOpenDisplay(display_name);
if (!dpy) {
fprintf(stderr, "Can't open display '%s'!\n",
display_name);
}
screen_num = DefaultScreen(dpy);
/* create window */
window = XCreateWindow( dpy, DefaultRootWindow(dpy), 0, 0, 400, 400, 0,
CopyFromParent, CopyFromParent, CopyFromParent, 0, 0);
XMapWindow(dpy, window);
XFlush(dpy);
/* create graphics context (gc) */
gc = XCreateGC(dpy, window, valuemask, &values);
if (gc < 0) {
fprintf(stderr, "XCreateGC() failure!\n");
}
XSetForeground(dpy, gc, WhitePixel(dpy, screen_num));
XSetBackground(dpy, gc, BlackPixel(dpy, screen_num));
XSetLineAttributes(dpy, gc, 10, LineSolid, CapButt, JoinBevel);
XSetFillStyle(dpy, gc, FillSolid);
/* set font */
font_info = XLoadQueryFont(dpy, font_name);
if (!font_info) {
fprintf(stderr, "XLoadQueryFont() failed for '%s'\n", font_name);
}
XSetFont(dpy, gc, font_info->fid);
XSync(dpy, False);
/* draw! draw! draw! */
XDrawString(dpy, window, gc, 0, 0, "Hello World", strlen("Hello World"));
XFillRectangle(dpy, window, gc, 60, 150, 50, 60);
XFlush(dpy);
sleep(10);
XCloseDisplay(dpy);
return 0;
}
--
Matt Garman
email at: http://raw-sewage.net/index.php?file=email