Events后续 MotionNotify(5)

sin 2021-10-22 PM 655℃ 0条

这是上一篇文章Events(3)的补充说明

Event MaskEvent TypeStructureGeneric Structure
PointerMotionMaskMotionNotifyXPointerMovedEventXMotionEvent
ButtonMotionMaskMotionNotifyXPointerMovedEventXMotionEvent
XMotionEvent代码结构
typedef struct {
    int type;        /* of event */
    unsigned long serial;    /* # of last request processed by server */
    Bool send_event;    /* true if this came from a SendEvent request */
    Display *display;    /* Display the event was read from */
    Window window;            /* "event" window reported relative to */
    Window root;            /* root window that the event occurred on */
    Window subwindow;    /* child window */
    Time time;        /* milliseconds */
    int x, y;        /* pointer x, y coordinates in event window */
    int x_root, y_root;    /* coordinates relative to root */
    unsigned int state;    /* key or button mask */
    char is_hint;        /* detail */
    Bool same_screen;    /* same screen flag */
} XMotionEvent;
typedef XMotionEvent XPointerMovedEvent;
样例代码
// ======代码1=============
void motionnotify(XEvent *e)
{
    XMotionEvent *ev = &e->xmotion;
    if (ev->state & Button2Mask)
    {
        printf("button 2 motion\n");
    }
    printf("motion notify event: state=%d , x y = %d %d\n", ev->state, ev->x, ev->y);
    return;
}
// =======================

// ======代码2=============
wa.event_mask = PointerMotionMask | ButtonMotionMask;
// =======================

// ======代码3=============
handlers[MotionNotify] = motionnotify;
// =======================

运行后,我按动滚轮移动来验证代码

gif

标签: none

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

评论啦~