创建窗口 CreateWindow(1)

sin 2021-10-11 PM 535℃ 0条

介绍

Xlib手册 is based on X11 release 6。

创建窗口 XCreateWindow

#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>


int main() {
    Display *X;
    Window win;
    GC gc;
    XSetWindowAttributes attributes;
    XKeyEvent event;


    X = XOpenDisplay(NULL);

    attributes.background_pixel = XWhitePixel(X, 0);
    attributes.border_pixel = 0x3344ff;

    win = XCreateWindow(X,
        XRootWindow(X, 0),
        100, 100, 200, 200,
        15,
        DefaultDepth(X, 0),
        InputOutput,
        DefaultVisual(X, 0),
        CWBackPixel | CWBorderPixel,
        &attributes);

    XSelectInput(X, win, KeyPressMask);

    gc = XCreateGC(X, win, 0, NULL);
    XMapWindow(X, win);
    while(1){
        XNextEvent(X, (XEvent*)&event);
        switch(event.type) {
            case KeyPress:
                {
                    XFreeGC(X, gc);
                    XCloseDisplay(X);
                    exit(0);
                }break;
            default:
                {
                    printf("%p", &event);
                }break;
        }
    }
    return 0;
}

创建XCreateWindow,显示窗口 XMapWindow

wmgo: main.c
    gcc main.c -o wmgo -lX11 -O3

png

添加cursor

上述代码还没有鼠标指针。给窗口添加个向右的XDefineCursor

XDefineCursor(X, win, XCreateFontCursor(X, XC_right_ptr));

cursor.gif

标签: none

非特殊说明,本博所有文章均为博主原创。

评论啦~