的xlib - 打印事件名称 [英] xlib - print event name

查看:131
本文介绍了的xlib - 打印事件名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有Xlib中创建了一个标准窗口,处理事件:

So I have a standard window created with xlib that handles events:

while (keep_running){
    XNextEvent (display, &event);
    printf("event\n");
}

现在它似乎并没有被调用暴露事件,所以我不能在窗口中绘制。我可以通过print语句看到,有被解雇的一些事件,我想知道他们是什么事件。

Now it doesn't seem to be calling the expose event, so I'm not able to draw in the window. I can see by the print statement that there are some events being fired, and I'd like to know what events they are.

所以基本上我的问题是,怎样才能得到事件名称打印呢?

So basically my question is, how can I get the event name to print it?

我还在学习C,因此任何帮助appriciated!

I'm still learning C, so any help is appriciated!

推荐答案

所以我不完全同意他们的设计决定不服的,但它可能是30年前做,所以现在不是星期一早晨四分卫的时间。 ..

so I don't totally agree with their design decision, but it was probably made 30 years ago, so now isn't the time for monday morning quarterbacking...

类型是一个疯狂的联盟:

the type is a crazy union:

typedef union _XEvent {
    int type;   /* must not be changed */
    XAnyEvent xany;
    XKeyEvent xkey;
    XButtonEvent xbutton;
    XMotionEvent xmotion;
    XCrossingEvent xcrossing;
    XFocusChangeEvent xfocus;
    XExposeEvent xexpose;
    XGraphicsExposeEvent xgraphicsexpose;
    XNoExposeEvent xnoexpose;
    XVisibilityEvent xvisibility;
    XCreateWindowEvent xcreatewindow;
    XDestroyWindowEvent xdestroywindow;
    XUnmapEvent xunmap;
    XMapEvent xmap;
    XMapRequestEvent xmaprequest;
    XReparentEvent xreparent;
    XConfigureEvent xconfigure;
    XGravityEvent xgravity;
    XResizeRequestEvent xresizerequest;
    XConfigureRequestEvent xconfigurerequest;
    XCirculateEvent xcirculate;
    XCirculateRequestEvent xcirculaterequest;
    XPropertyEvent xproperty;
    XSelectionClearEvent xselectionclear;
    XSelectionRequestEvent xselectionrequest;
    XSelectionEvent xselection;
    XColormapEvent xcolormap;
    XClientMessageEvent xclient;
    XMappingEvent xmapping;
    XErrorEvent xerror;
    XKeymapEvent xkeymap;
    long pad[24];
} Event;

所以你必须首先使用类型,以确定正在使用哪个事件:

so you must first use the type to determine which event is being used:

if(event.type == KeyPress)
{
    printf("keypress\n");
    // now you know the type you can use the specific fields from `XKeyEvent xkey`...
}

或者你可以只需登录类型

or you could just log the type

printf("event type = (%d)\n",event.type);

工会工作,因为每个其他可能的因素也有类型作为第一要素,所以他们都排队在同一地址...

the union works because each of the other possible elements also has type as the first element, so they all line up on the same address...

这篇关于的xlib - 打印事件名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆