I am creating a simple window manager (code based of the c code in tinywm) in Golang. To use Xlib, I am using cgo, so my header is:
// #cgo LDFLAGS: -lX11
// #include <X11/Xlib.h>
And I have a variable declaration, like:
event := C.XEvent{}
And then, I use this to assign to it, later, in the event loop:
C.XNextEvent(display, &event) // Yes, display is defined
But when I try to access properties on the event, such as xbutton or xkey, I get an error:
event.xbutton undefined (type C.XEvent has no field or method xbutton)
And when I look at the cgo output for XEvent, it looks like this, in the _cgo_gotypes.go
file:
type _Ctype_XEvent [192] byte
And I cant figure out what is going on, although I have a hunch that the type [192] byte
is very wrong for a C struct type. In case this helps, the XEvent struct looks like this in the C library:
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;