我正在 Golang 中创建一个简单的窗口管理器(基于 tinywm 中的 c 代码的代码)。要使用 Xlib,我使用的是 cgo,所以我的标题是:
// #cgo LDFLAGS: -lX11
// #include <X11/Xlib.h>
我有一个变量声明,例如:
event := C.XEvent{}
然后,我稍后在事件循环中使用它来分配给它:
C.XNextEvent(display, &event) // Yes, display is defined
但是,当我尝试访问事件的属性(例如 xbutton 或 xkey)时,出现错误:
event.xbutton undefined (type C.XEvent has no field or method xbutton)
当我查看 XEvent 的 cgo 输出时,它在_cgo_gotypes.go文件中如下所示:
type _Ctype_XEvent [192] byte
而且我无法弄清楚发生了什么,尽管我有一种预感,即[192] byteC 结构类型的类型非常错误。如果这有帮助,XEvent 结构在 C 库中看起来像这样:
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;
猛跑小猪
相关分类