JNA 联合结构映射
在 JNA 中,如何映射来自 Xlib 的联合结构,如以下 XEvent
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];
} XEvent;
我希望稍后能够根据事件的类型将 JNA 中的 XEvent 转换为其他事件(如 XKeyEvent、XButtonEvent、XMotionEvent ...等)收到事件。
我并不是要求对上述所有结构进行完整映射。一个清晰的解释和一个关于如何做的小例子就足够了。
谢谢
In JNA, how do you map a union structure like the following XEvent from Xlib
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];
} XEvent;
I want to be able later on to cast the XEvent in JNA to other events (like XKeyEvent, XButtonEvent, XMotionEvent ...etc) based on the type of the event received.
I am not asking for a full mapping for all the structures above. A clear explanation with a small example on how to do it will be enough.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 JNA contrib (com.sun.jna.platform.X11) 中定义的映射,然后执行以下操作:
例子:
Use the mappings defined in the JNA contrib (com.sun.jna.platform.X11) then do the following:
Example:
JNA 的源代码已经提供了 xlib 的示例。
此处对此进行了描述。 此处
可以在 contrib 文件夹下的 jna 源代码中找到实现。
具体来说,对于 XEvent,它被定义为:
我自己仍在学习 JNA,但我相信这个想法是检查类型值,然后仅引用相应的事件字段。其他应该为空。我认为通过演员阵容不可能做到这一点。
The sources for JNA already provide examples for xlib.
This is described here. here
The implementation can be found in the jna sources under the contrib folder.
Specifically for XEvent it is defined as:
I'm still learning JNA myself but I believe the idea is check the type value and then only refer to the corresponding event field. The others should be null. I don't think it is possible to do this through a cast.