/*
* Simple Xlib application drawing a box in a window.
*/
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
//licl2012-05-30
//#include "config.h"
//#include "fcitx/fcitx.h"
#include <limits.h>
#include <unistd.h>
#include <X11/extensions/Xrender.h>
#include <X11/Xatom.h>
//#include "fcitx/module.h"
//#include "x11stuff.h"
//#include "fcitx-utils/utils.h"
//#include "fcitx/instance.h"
//#include "xerrorhandler.h"
//#include <fcitx-utils/log.h>
//#include "composite-engine.h"
//#include<GL/glx.h>
int main()
{
struct _XDisplay *d;
int s;
Window w;
XEvent e;
XVisualInfo *xvi;//licl2012-05-30
XVisualInfo temp;
int nvi;//licl2012-05-30
int i;//licl2012-05-30
XRenderPictFormat *format;//licl2012-05-30
Visual *visual = NULL;//licl2012-05-30
/* To open a connection to the X server that controls a display*/
d = XOpenDisplay(NULL);
if(d == NULL)
{
printf("Cannot open display\n");
exit(1);
}
else {
printf(" open display ok\n");
}
/* Both return the default screen number referenced by the XOpenDisplay() function */
s = DefaultScreen(d);
printf(" got the screen\n");
/* create window */
//licl2012-05-30
temp.screen = s;
temp.depth = 32;
temp.class = TrueColor;
if ((xvi = XGetVisualInfo (d,
VisualScreenMask |
VisualDepthMask |
VisualClassMask,
&temp,
&nvi)) == NULL)
//return NULL;
for (i = 0; i < nvi; i++)
{
format = XRenderFindVisualFormat (d, xvi[i].visual);
if (format->type == PictTypeDirect && format->direct.alphaMask)
{
visual = xvi[i].visual;
break;
}
}
w = XCreateSimpleWindow(d,
RootWindow(d, s),
10,
10,
100,
100,
1,
BlackPixel(d, s),
WhitePixel(d, s));
/* select kind of events we are interested in */
XSelectInput(d, w, ExposureMask | KeyPressMask);
/* map (show) the window */
XMapWindow(d, w);
/* event loop */
while(1)
{
XNextEvent(d, &e);
/* draw or redraw the window */
if(e.type == Expose)
{
XFillRectangle(d, w, DefaultGC(d, s), 10, 10, 100, 100);
}
/* exit on key press */
//licl2012-05-30if(e.type == KeyPress)
//licl2012-05-30 break;
}
/* close connection to server */
XCloseDisplay(d);
return 0;
}
代码中有关键词c++的class,所以原来作为testwindow.cpp文件时编译不过,后改成testwindow.c就ok了