title: CGO converting Xlib XEvent struct to byte array?
body: <p>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:</p>
  
  <pre><code>// #cgo LDFLAGS: -lX11
  // #include &lt;X11/Xlib.h&gt;
  </code></pre>
  
  <p>And I have a variable declaration, like:</p>
  
  <pre><code>event := C.XEvent{}
  </code></pre>
  
  <p>And then, I use this to assign to it, later, in the event loop:</p>
  
  <pre><code>C.XNextEvent(display, &amp;event) // Yes, display is defined
  </code></pre>
  
  <p>But when I try to access properties on the event, such as xbutton or xkey, I get an error:</p>
  
  <pre><code>event.xbutton undefined (type C.XEvent has no field or method xbutton)
  </code></pre>
  
  <p>And when I look at the cgo output for XEvent, it looks like this, in the <code>_cgo_gotypes.go</code> file:</p>
  
  <pre><code>type _Ctype_XEvent [192] byte
  </code></pre>
  
  <p>And I cant figure out what is going on, although I have a hunch that the type <code>[192] byte</code> is very wrong for a C struct type. In case this helps, the XEvent struct looks like this in the C library:</p>
  
  <pre><code>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;
  </code></pre>