|
|
[php]
// #!/usr/bin/tcc -run -L/usr/X11R6/lib -lX11
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
Display *display;
XEvent event;
display=XOpenDisplay(":0");
if (display==NULL) {
printf("Cannot connect to X server %s\n :0");
exit(-1);
}
int screen_num;
int screen_width;
int screen_height;
Window root_win;
unsigned long white_pixel;
unsigned long black_pixel;
screen_num = DefaultScreen(display);
screen_width=DisplayWidth(display,screen_num);
screen_height=DisplayHeight(display,screen_num);
printf("%d,%d\n",screen_width,screen_height);
root_win=RootWindow(display,screen_num);
white_pixel=WhitePixel(display,screen_num);
black_pixel=BlackPixel(display,screen_num);
Window win;
int win_width,win_height,win_x,win_y;
win_width=690;
win_height=458;
win_x=win_y=0;
win=XCreateSimpleWindow(display,
root_win,
win_x,win_y,
win_width,win_height,
9,
black_pixel,white_pixel);
XMapWindow(display,win);
//XSync(display, False);
XSelectInput(display, win, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask);
XFlush(display);
sleep(1);
XMoveWindow(display,win,75,125);
XRaiseWindow(display,win);
XFlush(display);
while (1)
{
static i;
i++;
XNextEvent(display,&event);
printf("new coming event!\n");
switch (event.type) {
case Expose:
printf("%d times\tExpose iD -> %d\n",i,event.type);
break;
case ConfigureNotify:
printf("%d times\tConfigureNotify iD -> %d\n",i,event.type);
break;
case ButtonPress:
printf("%d times\t x,y -> %d,%d\n",i,event.xbutton.x,event.xbutton.y);
break;
case KeyPress:
printf("%d times\tKeyPress iD -> %d\n",i,event.type);
XCloseDisplay(display);
exit(1);
}
}
}
[/php]
编译:gcc hello.c -o helloX -lX11
如果有tcc的话把行首解注释,可以直接运行。 |
|