xcb_wrapper
Here's an example of how to wrap a dynamic link library. This library attempts to wrap xcb.
Under construction
-- XCB API Wrapper Library -- See: -- http://xcb.freedesktop.org/manual/ -- http://xcb.freedesktop.org/PublicApi/ -- http://xcb.freedesktop.org/tutorial/ include std/dll.e include std/console.e include std/error.e atom xcb_connect_, xcb_get_setup_, xcb_setup_roots_iterator_, xcb_generate_id_, xcb_create_window_, xcb_map_window_, xcb_flush_, xcb_disconnect_ constant XCB_COPY_FROM_PARENT = 0, XCB_WINDOW_CLASS_INPUT_OUTPUT = 1 -- dynamically link a C routine as a Euphoria function function link_c_func(atom dll, sequence name, sequence args, atom result) atom handle = define_c_func(dll, name, args, result) if handle = -1 then crash("Couldn't find " & name) end if return handle end function -- dynamically link a C routine as a Euphoria procedure function link_c_proc(atom dll, sequence name, sequence args) atom handle = define_c_proc(dll, name, args) if handle = -1 then crash("Couldn't find " & name) end if return handle end function -- get handles to all dll routines that we need procedure link_dll_routines() atom libxcb = open_dll({"libxcb.so.1.1.0", "libxcb.so"}) -- Must have a 32bit .so installed if on a 64bit machine. if libxcb = NULL then crash("Couldn't find libxcb.so") end if xcb_connect_ = link_c_func(libxcb, "xcb_connect", {C_POINTER, C_POINTER}, C_POINTER) xcb_get_setup_ = link_c_func(libxcb, "xcb_get_setup", {C_POINTER}, C_POINTER) xcb_setup_roots_iterator_ = link_c_func(libxcb, "xcb_setup_roots_iterator", {C_POINTER}, C_POINTER) xcb_generate_id_ = link_c_func(libxcb, "xcb_generate_id", {C_POINTER}, C_UINT) xcb_create_window_ = link_c_proc(libxcb, "xcb_create_window", {C_POINTER, C_INT, C_UINT, C_UINT, C_INT, C_INT, C_INT, C_INT, C_INT, C_INT, C_UINT, C_INT, C_POINTER}) xcb_map_window_ = link_c_proc(libxcb, "xcb_map_window", {C_POINTER,C_UINT}) xcb_flush_ = link_c_proc(libxcb, "xcb_flush", {C_POINTER}) xcb_disconnect_ = link_c_proc(libxcb, "xcb_disconnect", {C_POINTER}) end procedure public function xcb_connect(atom a1, atom a2) return c_func(xcb_connect_, {a1, a2}) end function public function xcb_get_setup(atom connection) return c_func(xcb_get_setup_, {connection}) end function public function xcb_setup_roots_iterator(atom connection) return c_func(xcb_setup_roots_iterator_,{connection}) end function public function xcb_generate_id(atom connection) return c_func(xcb_generate_id_, {connection}) end function public procedure xcb_create_window(atom connection, integer copy, atom window, atom parentwindow, integer x, integer y, integer w, integer h, integer border, integer class, atom visual, integer flags, atom notused) c_proc(xcb_create_window_, {connection, copy, window, parentwindow, x, y, w, h, border, class, visual, flags, notused}) end procedure public procedure xcb_map_window(atom connection, atom window) c_proc(xcb_map_window_, {connection, window}) end procedure public procedure xcb_flush(atom connection) c_proc(xcb_flush_, {connection}) end procedure public procedure xcb_disconnect(atom connection) c_proc(xcb_disconnect_, {connection}) end procedure procedure main() link_dll_routines() -- Open the connection to the X server atom connection = xcb_connect (0, 0) -- Get the first screen atom setup = xcb_get_setup (connection) atom screen = xcb_setup_roots_iterator (setup) -- Create the window atom window = xcb_generate_id (connection) xcb_create_window (connection, -- Connection XCB_COPY_FROM_PARENT, -- depth(same as root) window, -- window Id peek4u(screen+0), -- root -- parent window 0, 0, -- x, y 150, 150, -- width, height 10, -- border_width XCB_WINDOW_CLASS_INPUT_OUTPUT, -- class peek4u(screen+8), --root_visual-- visual 0, 0 ) -- masks, not used yet -- Map the window on the screen xcb_map_window (connection, window) -- Make sure commands are sent before we pause so that the window gets shown xcb_flush (connection) wait_key() -- pause () -- hold client until Ctrl-C xcb_disconnect (connection) end procedure main()
Not Categorized, Please Help
|