linux的桌面图形架构图,使用client与server模式,server使用x11(X Window System protocol)协议,client通过x11协议告诉server怎么显示,显示什么,就像http协议,xlib是封装协议的c库,使用xlib可以方便与xserver建立连接,显示图像,不用关注协议具体的字节格式等等
// Written by Ch. Tronche (http://tronche.lri.fr:8000/) // Copyright by the author. This is unmaintained, no-warranty free software. // Please use freely. It is appreciated (but by no means mandatory) to // acknowledge the author's contribution. Thank you. // Started on Thu Jun 26 23:29:03 1997
// // Xlib tutorial: 2nd program // Make a window appear on the screen and draw a line inside. // If you don't understand this program, go to // http://tronche.lri.fr:8000/gui/x/xlib-tutorial/2nd-program-anatomy.html //
#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));