xlib笔记

基本概念

x窗口是树状结构,每个物理屏幕都有一个根窗口root window,除了根窗口每个窗口都有父窗口,根窗口的大小是屏幕大小,且不可见。  

根窗口的第一代窗口叫做顶层窗口。  

子窗口可以大于父窗口,超出部分会被截断不显示。  

窗口的边框宽度默认为0。  

父窗口之外的内容会被裁减掉,而且不会响应事件。 

窗口的样式有两种:平铺式和重叠式,平铺式现在已经见不到了。  

在X中,display指的是x-server,display的全称应该是display server,screen指的是屏幕。  

全局坐标系: 原点是屏幕左上角,向右增长,向下增长,单位是像素; 
窗口坐标系: 原点是窗口左上角,向右增长,向下增长,单位是像素; 

display_name参数用于指定X服务器的显示名称,其格式可以是以下几种形式之一:
- 本地连接:`NULL`、`""`、`:0`。表示连接默认的X服务器。函数将尝试连接默认的X服务器。
- 网络连接:`hostname:display_number`。示例:"localhost:0", "192.168.1.10:0"。

在多用户情况下,操作系统中的每个用户会有一个x服务,所以需要使用`:0`,`:1`来表示x服务器;  

调色板用于映射颜色字符串和颜色值。

数据结构

/* 像素格式 */
typedef struct {
 int depth;
 int bits_per_pixel;
 int scanline_pad;
} XPixmapFormatValues;

/* 窗口属性结构体成员 */
typedef struct {
     int x, y;                     /* location of window */
     int width, height;            /* width and height of window */
     int border_width;             /* border width of window */
     int depth;                    /* depth of window */
     Visual *visual;               /* the associated visual structure */
     Window root;                  /* root of screen containing window */
     int class;                    /* InputOutput, InputOnly*/
     int bit_gravity;              /* one of the bit gravity values */
     int win_gravity;              /* one of the window gravity values */
     int backing_store;            /* NotUseful, WhenMapped, Always */
     unsigned long backing_planes; /* planes to be preserved if possible */
     unsigned long backing_pixel;  /* value to be used when restoring planes */
     Bool save_under;              /* boolean, should bits under be saved? */
     Colormap colormap;            /* color map to be associated with window */
     Bool map_installed;           /* boolean, is color map currently installed*/
     int map_state;                /* IsUnmapped, IsUnviewable, IsViewable */
     long all_event_masks;         /* set of events all people have interest in*/
     long your_event_mask;         /* my event mask */
     long do_not_propagate_mask;   /* set of events that should not propagate */
     Bool override_redirect;       /* boolean value for override-redirect */
     Screen *screen;               /* back pointer to correct screen */
} XWindowAttributes;


/* 设置窗口属性结构体成员 */
typedef struct {
     Pixmap background_pixmap;     /* background, None, or ParentRelative */
     unsigned long background_pixel;     /* background pixel */
     Pixmap border_pixmap;          /* border of the window or CopyFromParent */
     unsigned long border_pixel;     /* border pixel value */
     int bit_gravity;     /* one of bit gravity values */
     int win_gravity;     /* one of the window gravity values */
     int backing_store;     /* NotUseful, WhenMapped, Always */
     unsigned long backing_planes;     /* planes to be preserved if possible */
     unsigned long backing_pixel;     /* value to use in restoring planes */
     Bool save_under;     /* should bits under be saved? (popups) */
     long event_mask;     /* set of events that should be saved */
     long do_not_propagate_mask;     /* set of events that should not propagate */
     Bool override_redirect;     /* boolean value for override_redirect */
     Colormap colormap;     /* color map to be associated with window */
     Cursor cursor;          /* cursor to be displayed (or None) */
} XSetWindowAttributes;


/* 改变窗口属性结构体成员 */
typedef struct {
     int x, y;
     int width, height;
     int border_width;
     Window sibling;
     int stack_mode;
} XWindowChanges;

/* stack_mode */
Above		The window is placed just above the sibling.
Below		The window is placed just below the sibling.
TopIf		If the sibling occludes the window, the window is placed at the top of the stack.
BottomIf	If the window occludes the sibling, the window is placed at the bottom of the stack.
Opposite	If the sibling occludes the window, the window is placed at the top of the stack. If the window occludes the sibling, the window is placed at the bottom of the stack.

/* 颜色 */
typedef struct {
	unsigned long pixel;	/* pixel value */
	unsigned short red, green, blue;	/* rgb values */
	char flags;	/* DoRed, DoGreen, DoBlue */	
	char pad;
} XColor;

typedef unsigned long XcmsColorFormat;			/* Color Specification Format */

typedef struct {
	union {
		XcmsRGB RGB;
		XcmsRGBi RGBi;
		XcmsCIEXYZ CIEXYZ;
		XcmsCIEuvY CIEuvY;
		XcmsCIExyY CIExyY;
		XcmsCIELab CIELab;
		XcmsCIELuv CIELuv;
		XcmsTekHVC TekHVC;
		XcmsPad Pad;
	} spec;
	unsigned long pixel;
	XcmsColorFormat format;
} XcmsColor;			/* Xcms Color Structure */

/* GC 结构体 */
typedef struct {
     int function;                 /* logical operation */
     unsigned long plane_mask;     /* plane mask */
     unsigned long foreground;     /* foreground pixel */
     unsigned long background;     /* background pixel */
     int line_width;               /* line width (in pixels) */
     int line_style;               /* LineSolid, LineOnOffDash, LineDoubleDash */
     int cap_style;                /* CapNotLast, CapButt, CapRound, CapProjecting */
     int join_style;               /* JoinMiter, JoinRound, JoinBevel */
     int fill_style;               /* FillSolid, FillTiled, FillStippled FillOpaqueStippled*/
     int fill_rule;                /* EvenOddRule, WindingRule */
     int arc_mode;                 /* ArcChord, ArcPieSlice */
     Pixmap tile;                  /* tile pixmap for tiling operations */
     Pixmap stipple;               /* stipple 1 plane pixmap for stippling */
     int ts_x_origin;              /* offset for tile or stipple operations */
     int ts_y_origin
     Font font;                    /* default text font for text operations */
     int subwindow_mode;           /* ClipByChildren, IncludeInferiors */
     Bool graphics_exposures;      /* boolean, should exposures be generated */
     int clip_x_origin;            /* origin for clipping */
     int clip_y_origin;
     Pixmap clip_mask;             /* bitmap clipping; other calls for rects */
     int dash_offset;              /* patterned/dashed line information */
     char dashes;
} XGCValues;

标志位

/* 窗口属性掩码值 */
#define    CWBackPixmap                    (1L<<0)
#define    CWBackPixel                     (1L<<1)
#define    CWBorderPixmap                  (1L<<2)
#define    CWBorderPixel                   (1L<<3)
#define    CWBitGravity                    (1L<<4)
#define    CWWinGravity                    (1L<<5)
#define    CWBackingStore                  (1L<<6)
#define    CWBackingPlanes                 (1L<<7)
#define    CWBackingPixel                  (1L<<8)
#define    CWOverrideRedirect              (1L<<9)
#define    CWSaveUnder                     (1L<<10)
#define    CWEventMask                     (1L<<11)
#define    CWDontPropagate                 (1L<<12)
#define    CWColormap                      (1L<<13)
#define    CWCursor                        (1L<<14)

/* 配置窗口掩码值 */
#define      CWX              (1<<0)
#define      CWY              (1<<1)
#define      CWWidth          (1<<2)
#define      CWHeight         (1<<3)
#define      CWBorderWidth    (1<<4)
#define      CWSibling        (1<<5)
#define      CWStackMode      (1<<6)

/* GC 标志位 */
#define     GCFunction              (1L<<0)
#define     GCPlaneMask             (1L<<1)
#define     GCForeground            (1L<<2)
#define     GCBackground            (1L<<3)
#define     GCLineWidth             (1L<<4)
#define     GCLineStyle             (1L<<5)
#define     GCCapStyle              (1L<<6)
#define     GCJoinStyle             (1L<<7)
#define     GCFillStyle             (1L<<8)
#define     GCFillRule              (1L<<9)
#define     GCTile                  (1L<<10)
#define     GCStipple               (1L<<11)
#define     GCTileStipXOrigin       (1L<<12)
#define     GCTileStipYOrigin       (1L<<13)
#define     GCFont                  (1L<<14)
#define     GCSubwindowMode         (1L<<15)
#define     GCGraphicsExposures     (1L<<16)
#define     GCClipXOrigin           (1L<<17)
#define     GCClipYOrigin           (1L<<18)
#define     GCClipMask              (1L<<19)
#define     GCDashOffset            (1L<<20)
#define     GCDashList              (1L<<21)
#define     GCArcMode               (1L<<22)

X服务器

// 元信息
int XProtocolVersion(Display *display);
int XProtocolRevision(Display *display);
char *XServerVendor(Display *display);
int XVendorRelease(Display *display);

// 服务器
Display *XDisplayOfScreen(Screen *screen);
int XDisplayHeight(Display *display, int screen_number);
int XDisplayHeightMM(Display *display, int screen_number);
int XDisplayWidth(Display *display, int screen_number);
int XDisplayWidthMM(Display *display, int screen_number);
char *XDisplayString(Display *display);
XCloseDisplay(Display *display);
Display *XOpenDisplay(char *display_name);

// 颜色
unsigned long XAllPlanes(void);
unsigned long XBlackPixel(Display *display, int screen_number);
unsigned long XBlackPixelOfScreen(Screen *screen);
unsigned long XWhitePixel(Display *display, int screen_number);
unsigned long XWhitePixelOfScreen(Screen *screen);
int XConnectionNumber(Display *display);
Colormap XDefaultColormap(Display *display, int screen_number);
Colormap XDefaultColormapOfScreen(Screen *screen);
int XDefaultDepth(Display *display, int screen_number);
int XDefaultDepthOfScreen(Screen *screen);
int *XListDepths(Display *display, int screen_number, int *count_return);
int XDisplayCells(Display *display, int screen_number);
int XCellsOfScreen(Screen *screen);
int XDisplayPlanes(Display *display, int screen_number);
int XMaxCmapsOfScreen(Screen *screen);
int XMinCmapsOfScreen(Screen *screen);
int XPlanesOfScreen(Screen *screen);

// 图形
GC XDefaultGC(Display *display, int screen_number);
GC XDefaultGCOfScreen(Screen *screen);

// 根窗口
Window XDefaultRootWindow(Display *display);
Window XRootWindow(Display *display, int screen_number);
Window XRootWindowOfScreen(Screen *screen);

// 屏幕
Screen *XDefaultScreenOfDisplay(Display *display);
Screen *XScreenOfDisplay(Display *display, int screen_number);
int XDefaultScreen(Display *display);
Visual *XDefaultVisual(Display *display, int screen_number);
Visual *XDefaultVisualOfScreen(Screen *screen);
int XScreenCount(Display *display);
long XScreenNumberOfScreen(Screen *screen);
int XWidthOfScreen(Screen *screen);
int XHeightOfScreen(Screen *screen);
int XWidthMMOfScreen(Screen *screen);
int XHeightMMOfScreen(Screen *screen);

// 事件
long XExtendedMaxRequestSize(Display *display);
long XMaxRequestSize(Display *display);
unsigned long XLastKnownRequestProcessed(Display *display);
unsigned long XNextRequest(Display *display);
int XQLength(Display *display);
long XEventMaskOfScreen(Screen *screen);
XNoOp(Display *display);

// 存储
int XDoesBackingStore(Screen *screen);
Bool XDoesSaveUnders(Screen *screen);

// 内存
XFree(void *data);

窗口

// 创建通用窗口
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);

// 创建继承父窗口的新窗口
Window XCreateSimpleWindow(Display *display, Window parent, int x, int y, unsigned int width, unsigned int height, unsigned int border_width, unsigned long border, unsigned long background);

// 映射窗口
XMapWindow(Display *display, Window w);

// 映射并置顶窗口
XMapRaised(Display *display, Window w);

// 映射所有子窗口
XMapSubwindows(Display *display, Window w);

// 销毁窗口
XDestroyWindow(Display *display, Window w);

// 销毁子窗口
XDestroySubwindows(Display *display, Window w);

// 取消映射窗口
XUnmapWindow(Display *display, Window w);

// 取消映射子窗口
XUnmapSubwindows(Display *display, Window w);
// 设置窗口单个属性
XSetWindowBackground(Display *display, Window w, unsigned long background_pixel);
XMoveWindow(Display *display, Window w, int x, int y);
XResizeWindow(Display *display, Window w, unsigned int width, unsigned int height);
XMoveResizeWindow(Display *display, Window w, int x, int y, unsigned int width, unsigned int height);
XSetWindowBackgroundPixmap(Display *display, Window w, Pixmap background_pixmap);
XSetWindowBorder(Display *display, Window w, unsigned long border_pixel);
XSetWindowBorderPixmap(Display *display, Window w, Pixmap border_pixmap);
XSetWindowColormap(Display *display, Window w, Colormap colormap);
XDefineCursor(Display *display, Window w, Cursor cursor);
XUndefineCursor(Display *display, Window w);

// 设置窗口属性
XConfigureWindow(Display *display, Window w, unsigned int value_mask, XWindowChanges *values);
XChangeWindowAttributes(Display *display, Window w, unsigned long valuemask, XSetWindowAttributes *attributes);

// 改变窗口属性
int XGetWindowProperty(Display *display, Window w, Atom property, long long_offset, long long_length, Bool delete, Atom req_type, Atom *actual_type_return, int *actual_format_return, unsigned long *nitems_return, unsigned long *bytes_after_return, unsigned char **prop_return);

// 查看窗口属性
Atom *XListProperties(Display *display, Window w, int *num_prop_return);
XChangeProperty(Display *display, Window w, Atom property, Atom type, int format, int mode, unsignedchar *data, int nelements);
XRotateWindowProperties(Display *display, Window w, Atom properties[], int num_prop, int npositions);

// 删除窗口属性
XDeleteProperty(Display *display, Window w, Atom property);
// 改变层叠顺序
XSetWindowBorderWidth(Display *display, Window w, unsigned int width);
XRaiseWindow(Display *display, Window w);
XLowerWindow(Display *display, Window w);
XCirculateSubwindows(Display *display, Window w, int direction);
XCirculateSubwindowsUp(Display *display, Window w);
XCirculateSubwindowsDown(Display *display, Window w);
XRestackWindows(Display *display, Window windows[], int nwindows);


// 查询窗口信息
Status XQueryTree(Display *display, Window w, Window *root_return, Window *parent_return, Window **children_return, unsigned int *nchildren_return);
Status XGetWindowAttributes(Display *display, Window w, XWindowAttributes *window_attributes_return);
Status XGetGeometry(Display *display, Drawable d, Window *root_return, int *x_return, int *y_return, unsigned int *width_return, unsigned int *height_return, unsigned int *border_width_return, unsigned int *depth_return);

// 坐标
Bool XTranslateCoordinates(Display *display, Window src_w, Window dest_w, int src_x, int src_y, int *dest_x_return, int *dest_y_return, Window *child_return);
Bool XQueryPointer(Display *display, Window w, Window *root_return, Window *child_return, int *root_x_return, int *root_y_return, int *win_x_return, int *win_y_return, unsigned int *mask_return);
XReparentWindow(Display *display, Window w, Window parent, int x, int y);
XGrabServer(Display *display);
XUngrabServer(Display *display);
XKillClient(Display *display, XID resource);

XChangeSaveSet(Display *display, Window w, int change_mode);
XAddToSaveSet(Display *display, Window w);
XInstallColormap(Display *display, Colormap colormap);
XUninstallColormap(Display *display, Colormap colormap);
Colormap *XListInstalledColormaps(Display *display, Window w, int *num_return);
XSetFontPath(Display *display, char **directories, int ndirs);
char **XGetFontPath(Display *display, int *npaths_return);
XFreeFontPath(char **list);

像素

// 像素格式
XPixmapFormatValues *XListPixmapFormats(Display *display, int *count_return);
int XImageByteOrder(Display *display);
int XBitmapUnit(Display *display);
int XBitmapBitOrder(Display *display);
int XBitmapPad(Display *display);
Pixmap XCreatePixmap(Display *display, Drawable d, unsigned int width, unsigned int height, unsigned int depth);
XFreePixmap(Display *display, Pixmap pixmap);

光标

Cursor XCreateFontCursor(Display *display, unsigned int shape);
Cursor XCreateGlyphCursor(Display *display, Font source_font, Font mask_font, unsigned int source_char, unsigned int mask_char, XColor *foreground_color, XColor *background_color);
Cursor XCreatePixmapCursor(Display *display, Pixmap source, Pixmap mask, XColor *foreground_color, XColor *background_color, unsigned int x, unsigned int y);
Status XQueryBestCursor(Display *display, Drawable d, unsigned int width, unsigned int height, unsigned int *width_return, unsigned int *height_return);
XRecolorCursor(Display *display, Cursor cursor, XColor *foreground_color, XColor *background_color);
XFreeCursor(Display *display, Cursor cursor);

颜色

Colormap XCreateColormap(Display *display, Window w, Visual *visual, int alloc);
Status XAllocColor(Display *display, Colormap colormap, XColor *screen_in_out);
XFreeColormap(Display *display, Colormap colormap);

图形上下文

默认GC值:

成员默认值
functionGXcopy
plane_maskAll ones
foreground0
background1
line_width0
line_styleLineSolid
cap_styleCapButt
join_styleJoinMiter
fill_styleFillSolid
fill_ruleEvenOddRule
arc_modeArcPieSlice
tilePixmap of unspecified size filled with foreground pixel
stipplePixmap of unspecified size filled with ones
ts_x_origin0
ts_y_origin0
font<implementation dependent>
subwindow_modeClipByChildren
graphics_exposuresTrue
clip_x_origin0
clip_y_origin0
clip_maskNone
dash_offset0
dashes4
// 管理GC
GC XCreateGC(Display *display, Drawable d, unsigned long valuemask, XGCValues *values);
XCopyGC(Display *display, GC src, GC dest, unsigned long valuemask);
XChangeGC(Display *display, GC gc, unsigned long valuemask, XGCValues *values);
Status XGetGCValues(Display *display, GC gc, unsigned long valuemask, XGCValues *values_return);
XFreeGC(Display *display, GC gc);
GContext XGContextFromGC(GC gc);
void XFlushGC(Display *display, GC gc);

// 设置背景、前景等
XSetState(Display *display, GC gc, unsigned long foreground, unsigned long background, int function, unsigned long plane_mask);
XSetForeground(Display *display, GC gc, unsigned long foreground);
XSetBackground(Display *display, GC gc, unsigned long background);
XSetFunction(Display *display, GC gc, int function);
XSetPlaneMask(Display *display, GC gc, unsigned long plane_mask);

// 设置线性
XSetLineAttributes(Display *display, GC gc, unsigned int line_width, int line_style, int cap_style, int join_style);
XSetDashes(Display *display, GC gc, int dash_offset, char dash_list[], int n);
XSetFillStyle(Display *display, GC gc, int fill_style);
XSetFillRule(Display *display, GC gc, int fill_rule);
Status XQueryBestSize(Display *display, int class, Drawable which_screen, unsigned int width, unsigned int height, unsigned int *width_return, unsigned int *height_return);
Status XQueryBestTile(Display *display, Drawable which_screen, unsigned int width, unsigned int height, unsigned int *width_return, unsigned int *height_return);
Status XQueryBestStipple(Display *display, Drawable which_screen, unsigned int width, unsigned int height, unsigned int *width_return, unsigned int *height_return);
XSetTile(Display *display, GC gc, Pixmap tile);
XSetStipple(Display *display, GC gc, Pixmap stipple);
XSetTSOrigin(Display *display, GC gc, int ts_x_origin, int ts_y_origin);

// 设置字体
XSetFont(Display *display, GC gc, Font font);

图形函数

// 清除区域
XClearArea(Display *display, Window w, int x, int y, unsigned int width, unsigned int height, Bool exposures);
XClearWindow(Display *display, Window w);

// 拷贝区域
XCopyArea(Display *display, Drawable src, Drawable dest, GC gc, int src_x, int src_y, unsigned int width, unsigned int height, int dest_x, int dest_y);
XCopyPlane(Display *display, Drawable src, Drawable dest, GC gc, int src_x, int src_y, unsigned int width, unsigned int height, int dest_x, int dest_y, unsigned long plane);

// 图形元素
XDrawPoint(Display *display, Drawable d, GC gc, int x, int y);
XDrawPoints(Display *display, Drawable d, GC gc, XPoint *points, int npoints, int mode);
XDrawLine(Display *display, Drawable d, GC gc, int x1, int y1, int x2, int y2);
XDrawLines(Display *display, Drawable d, GC gc, XPoint *points, int npoints, int mode);
XDrawSegments(Display *display, Drawable d, GC gc, XSegment *segments, int nsegments);

// 画图形
XDrawRectangle(Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height);
XDrawRectangles(Display *display, Drawable d, GC gc, XRectangle rectangles[], int nrectangles);
XDrawArc(Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height, int angle1, int angle2);
XDrawArcs(Display *display, Drawable d, GC gc, XArc *arcs, int narcs);

// 填充
XFillRectangle(Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height);
XFillRectangles(Display *display, Drawable d, GC gc, XRectangle *rectangles, int nrectangles);
XFillPolygon(Display *display, Drawable d, GC gc, XPoint *points, int npoints, int shape, int mode);
XFillArc(Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height, int angle1, int angle2);
XFillArcs(Display *display, Drawable d, GC gc, XArc *arcs, int narcs);

字体

// 配置字体
Font XLoadFont(Display *display, char *name);
XFontStruct *XQueryFont(Display *display, XID font_ID);
XFontStruct *XLoadQueryFont(Display *display, char *name);
XFreeFont(Display *display, XFontStruct *font_struct);
Bool XGetFontProperty(XFontStruct *font_struct, Atom atom, unsigned long *value_return);
XUnloadFont(Display *display, Font font);
char **XListFonts(Display *display, char *pattern, int maxnames, int *actual_count_return);
XFreeFontNames(char *list[]);
char **XListFontsWithInfo(Display *display, char *pattern, int maxnames, int *count_return, XFontStruct **info_return);
XFreeFontInfo(char **names, XFontStruct *free_info, int actual_count);


// 输出文字
XDrawText(Display *display, Drawable d, GC gc, int x, int y, XTextItem *items, int nitems);
XDrawText16(Display *display, Drawable d, GC gc, int x, int y, XTextItem16 *items, int nitems);
XDrawString(Display *display, Drawable d, GC gc, int x, int y, char *string, int length);
XDrawString16(Display *display, Drawable d, GC gc, int x, int y, XChar2b *string, int length);

图片

XImage *XCreateImage(Display *display, Visual *visual, unsigned int depth, int format, int offset, char *data, unsigned int width, unsigned int height, int bitmap_pad, int bytes_per_line);
XPutImage(Display *display, Drawable d, GC gc, XImage *image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height);

Status XInitImage(XImage *image);
XImage *XGetImage(Display *display, Drawable d, int x, int y, unsigned int width, unsigned int height, unsigned long plane_mask, int format);
XImage *XGetSubImage(Display *display, Drawable d, int x, int y, unsigned int width, unsigned int height, unsigned long plane_mask, int format, XImage *dest_image, int dest_x, int dest_y);

焦点

无论是xlib还是qt,焦点都是窗口的属性之一,切换焦点意味着设置当前窗口焦点为false,设置新窗口焦点为true。

XSetInputFocus(Display *display, Window focus, int revert_to, Time time);
XGetInputFocus(Display *display, Window *focus_return, int *revert_to_return);

事件

事件是用于处理客户端和服务器之间的通信的。

键盘事件、鼠标事件、窗口状态变更事件、

客户端间通信

窗口属性、剪切板,selection

Demo

#include <X11/Xlib.h>

int main() {
    Display *display;
    Window window;
    XEvent event;
    int screen;

    // 打开与X服务器的连接
    display = XOpenDisplay(NULL);
    if (display == NULL) {
        fprintf(stderr, "无法打开X服务器\n");
        return -1;
    }

    screen = DefaultScreen(display);

    // 创建窗口
    window = XCreateSimpleWindow(display, RootWindow(display, screen), 10, 10, 200, 200, 1, BlackPixel(display, screen), WhitePixel(display, screen));

    // 选择捕获事件
    XSelectInput(display, window, ExposureMask | KeyPressMask);

    // 显示窗口
    XMapWindow(display, window);

    // 处理窗口事件
    while (1) {
        XNextEvent(display, &event);

        if (event.type == Expose) {
            // 窗口需要重绘
            // 在这里可以添加自定义的绘制代码
        }

        if (event.type == KeyPress)
            break;
    }

    // 关闭连接
    XCloseDisplay(display);

    return 0;
}

参考连接

libx11源码
x11 协议
xlib API接口

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多弗朗强哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值