x window学习笔记

常用函数

1.Display XOpenDisplay(char display_name);
用途:connect to X server
参数display_name指明将X window窗口显示到哪个硬件(Specifies the hardware display name)。为空(NULL)时,默认值为当前系统的DISPLAY环境变量。

详见:http://www.x.org/releases/X11R7.5/doc/man/man3/XOpenDisplay.3.html

2.Window XCreateWindow(Display display, Window parent, int x, int y, unsigned int width, unsigned int height, unsigned int border_width, int depth, unsigned int class, Visual visual, unsigned long valuemask, XSetWindowAttributes *attributes);
The XCreateWindow function creates an unmapped subwindow for a specified parent window, returns the window ID of the created window, and causes the X server to generate a CreateNotify event. The created window is placed on top in the stacking order with respect to siblings.
The created window is not yet displayed (mapped) on the user’s display. To display the window, call XMapWindow. The new window initially uses the same cursor as its parent. A new cursor can be defined for the new window by calling XDefineCursor. The window will not be visible on the screen unless it and all of its ancestors are mapped and it is not obscured by any of its ancestors.

详见:http://www.x.org/releases/X11R7.5/doc/man/man3/XCreateSimpleWindow.3.html

3.int XMapWindow(Display *display, Window w);
The XMapWindow function maps the window and all of its subwindows that have had map requests. Mapping a window that has an unmapped ancestor does not display the window but marks it as eligible for display when the ancestor becomes mapped.

详见:http://www.x.org/releases/X11R7.5/doc/man/man3/XMapWindow.3.html

简单用法

Display* display = XOpenDisplay(NULL);
Window win = XCreateSimpleWindow(display, RootWindow(display, screen), 0, 0, width, height, 3, BlackPixel(display, screen), WhitePixel(display, screen));
XMapWindow(display, win);//完成这一步才会最终在显示器上显示窗口

基本流程

建立一个 displayX Server  
取得 display的相关资料  
建立视窗  
和视窗管理程式(Window Manager)沟通  
显示视窗  
关闭(destroy)视窗  
关闭 display

常用名词

XIC: input context
GC: graphic context

参考资料

X Window 程式设计入门—第二章 X Programming 的第一步