From 9b176bad26711359e9980911dbd9e5bcbac2e822 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 30 Aug 2017 20:55:29 -0400 Subject: [PATCH] defined event type for x11 --- Makefile | 2 +- lib/x11.ml | 35 ++++++++++++++++++++++++++++++----- lib/x11_prims.c | 15 ++++++++++----- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 3b13f0f..dabf4c1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Toolchain Configuration #------------------------------------------------------------------------------- -INCS = -I . -I lib -I /usr/X11R6/include -I /usr/include/freetype2 +INCS = -I . -I lib -I /usr/X11R6/include -I /usr/include/freetype2 -I /usr/X11R6/include/freetype2 LIBS = -L/usr/X11R6/lib -lX11 -lXft ifeq ($(NATIVE), 1) diff --git a/lib/x11.ml b/lib/x11.ml index 04e8798..05aab11 100644 --- a/lib/x11.ml +++ b/lib/x11.ml @@ -1,5 +1,21 @@ -type atom -type winid +type xatom +type xwin +type xevent = + Focus of { focused: bool } + | KeyPress of { mods: int; rune: int } + | MouseBtn of { + mods: int; + btn: int; + x: int; + y: int; + pressed: bool; + dragged: bool + } + | Paste of { text: string } + | Command of { commands: string array } + | Resize of { height: int; width: int } + | Shutdown + | QueueEmpty external connect : unit -> unit = "x11_connect" @@ -7,6 +23,9 @@ external connect : unit -> unit external disconnect : unit -> unit = "x11_disconnect" +external connfd : unit -> int + = "x11_connfd" + external make_window : int -> int -> unit = "x11_make_window" @@ -16,16 +35,22 @@ external make_dialog : int -> int -> unit external show_window : bool -> unit = "x11_show_window" +external has_event : unit -> bool + = "x11_has_event" + +external next_event : unit -> xevent + = "x11_next_event" + external errno : unit -> int = "x11_errno" -external intern : string -> atom +external intern : string -> xatom = "x11_intern" -external prop_set : winid -> atom -> string -> unit +external prop_set : xwin -> xatom -> string -> unit = "x11_prop_set" -external prop_get : winid -> atom -> string +external prop_get : xwin -> xatom -> string = "x11_prop_get" (* to be implemented diff --git a/lib/x11_prims.c b/lib/x11_prims.c index 2f7f350..1338e54 100644 --- a/lib/x11_prims.c +++ b/lib/x11_prims.c @@ -20,7 +20,7 @@ static struct { unsigned depth; int screen; Window root; - int errno; + int errnum; /* assume one window per process for now */ Window self; XftDraw* xft; @@ -53,10 +53,15 @@ CAMLprim value x11_disconnect(void) { CAMLreturn(Val_unit); } +CAMLprim value x11_connfd(void) { + CAMLparam0(); + CAMLreturn(Val_int( ConnectionNumber(X.display) )); +} + CAMLprim value x11_make_window(value height, value width) { CAMLparam2(height, width); create_window(Int_val(height), Int_val(width)); - CAMLreturn(Val_unit); + CAMLreturn(Val_int(X.self)); } CAMLprim value x11_make_dialog(value height, value width) { @@ -65,7 +70,7 @@ CAMLprim value x11_make_dialog(value height, value width) { Atom WindowType = XInternAtom(X.display, "_NET_WM_WINDOW_TYPE", False); Atom DialogType = XInternAtom(X.display, "_NET_WM_WINDOW_TYPE_DIALOG", False); XChangeProperty(X.display, X.self, WindowType, XA_ATOM, 32, PropModeReplace, (unsigned char*)&DialogType, 1); - CAMLreturn(Val_unit); + CAMLreturn(Val_int(X.self)); } CAMLprim value x11_show_window(value state) { @@ -86,7 +91,7 @@ CAMLprim value x11_show_window(value state) { CAMLprim value x11_errno(void) { CAMLparam0(); - CAMLreturn(Val_int(X.errno)); + CAMLreturn(Val_int(X.errnum)); } CAMLprim value x11_intern(value name) { @@ -120,7 +125,7 @@ static char* readprop(Window win, Atom prop) { } static int error_handler(Display* disp, XErrorEvent* ev) { - X.errno = ev->error_code; + X.errnum = ev->error_code; return 0; } -- 2.49.0