Arch Linux를 설치하면 위와 같은 초기 X-Window System의 모습을 볼 수 있다. X에서만 제공하는 기본 API만으로 작성되었다. 참고로, 다음은 실제 Xlib 프로그래밍 소스 코드로서 실행을 하면, “Hello, World!"라는 텍스트를 출력하는 작은 윈도우를 화면에 보여준다.
#include
#include
#include
#include
int main(void) {
Display *d;
Window w;
XEvent e;
char *msg = "Hello, World!";
int s;
d = XOpenDisplay(NULL);
if (d == NULL) {
fprintf(stderr, "Cannot open display\n");
exit(1);
}
s = DefaultScreen(d);
w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1,
BlackPixel(d, s), WhitePixel(d, s));
printf("w=%lu\n", w);
XSelectInput(d, w, ExposureMask | KeyPressMask);
XMapWindow(d, w);
while (1) {
XNextEvent(d, &e);
if (e.type == Expose) {
XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10);
XDrawString(d, w, DefaultGC(d, s), 10, 50, msg, strlen(msg));
}
if (e.type == KeyPress)
break;
}
XCloseDisplay(d);
return 0;
}
소스코드와 컴파일 방법은 여기를 확인.