From The Compiler, 5 Years ago, written in Python.
Embed
  1. #### cherbstclient.pxd
  2.  
  3. cdef extern from "glib.h":
  4.     ctypedef struct GString:
  5.         pass
  6.  
  7. cdef extern from "X11/Xlib.h":
  8.     ctypedef struct Display:
  9.         pass
  10.  
  11. cdef extern from "stdbool.h":
  12.     ctypedef struct bool:
  13.         pass
  14.  
  15. cdef extern from "herbstclient.h":
  16.     ctypedef struct HCConnection:
  17.         pass
  18.  
  19.     HCConnection* hc_connect()
  20.     HCConnection* hc_connect_to_display(Display* display)
  21.     void hc_disconnect(HCConnection* con)
  22.     bool hc_create_client_window(HCConnection* con)
  23.  
  24.     bool hc_send_command(HCConnection* con, int argc, char* argv[],
  25.                          GString** ret_out, int* ret_status)
  26.     bool hc_send_command_once(int argc, char* argv[],
  27.                               GString** ret_out, int* ret_status)
  28.  
  29.     bool hc_hook_window_connect(HCConnection* con)
  30.     bool hc_next_hook(HCConnection* con, int* argc, char** argv[])
  31.    
  32. #### herbstclient.pyx
  33.  
  34. cimport cherbstclient as chc
  35.  
  36. cdef class Herbstclient:
  37.     cdef chc.HCConnection* _c_con
  38.     def __cinit__(self, display=None):
  39.         # TODO handle display correctly
  40.         if display is None:
  41.             self._c_con = chc.hc_connect()
  42.         else:
  43.             #self._c_con = chc.hc_connect_to_display(display)
  44.             raise NotImplementedError
  45.         if self._c_con is NULL:
  46.             raise EnvironmentError("Could not open connection")
  47.  
  48.     def __dealloc__(self):
  49.         if self._c_con is not NULL:
  50.             chc.hc_disconnect(self._c_con)