Events(3)

sin 2021-10-14 PM 697℃ 0条

Event Types

Event CategoryEvent Type
Keyboard events 键盘事件KeyPress KeyRelease
Pointer events 鼠标事件ButtonPress ButtonRelease MotionNotify(运动事件)
Window crossing events 窗体进入离开事件EnterNotify LeaveNotify
Input focus eventsFocusIn FocusOut
Keymap state notification eventKeymapNotify
Exposure eventsExpose GraphicsExpose NoExpose
Structure control eventsCirculateRequest ConfigureRequest MapRequest ResizeRequest
Window state notification eventsCirculateNotify ConfigureNotify CreateNotify DestroyNotify GravityNotify MapNotify MappingNotify ReparentNotify UnmapNotify VisibilityNotify
Colormap State Change EventsColormapNotify
Client Communication EventsClientMessage PropertyNotify SelectionClear SelectionNotify SelectionRequest

下面我们详细测试解释

主体结构
#include <stdio.h>
#include <X11/Xlib.h>

static Display *dpy;
static int screen;
static int sw, sh;
static Window root;
static int running = 1;

typedef void (*handler)(XEvent *);

static void *handlers[LASTEvent];

void default_handler(XEvent *ev)
{
    printf("default event handler: ev.type = %d\n", ev->type);
    return;
}

// ======代码1=============
void xxxx(XEvent *ev)
{
}
// =======================

void init()
{
    dpy = XOpenDisplay(NULL);

    XSetWindowAttributes wa;

    screen = DefaultScreen(dpy);
    sw = DisplayWidth(dpy, screen);
    sh = DisplayHeight(dpy, screen);
    root = RootWindow(dpy, screen);
    
    // ======代码2=============
    wa.event_mask = Mask;
    // =======================
    
    XChangeWindowAttributes(dpy, root, CWEventMask, &wa);
    XSelectInput(dpy, root, wa.event_mask);

    for (int i = 0; i < LASTEvent; i++)
    {
        handlers[i] = default_handler;
    }

    // ======代码3=============
    handlers[XXXX] = xxxx;
    // =======================
}

void run()
{
    XEvent ev;
    XSync(dpy, False);
    while (running && !XNextEvent(dpy, &ev))
    {
        handler caller = handlers[ev.type];
        if (caller != NULL)
        {
            caller(&ev);
        }
    }
}

int main()
{
    init();
    run();
}
event_test: event_test.c
    gcc event_test.c -o event_test -lX11

启动Xephyr,同时启动event_test测试。

测试文章

标签: none

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

评论啦~