]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
defined event type for x11
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 31 Aug 2017 00:55:29 +0000 (20:55 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 31 Aug 2017 00:55:29 +0000 (20:55 -0400)
Makefile
lib/x11.ml
lib/x11_prims.c

index 3b13f0f98ca2d5352ffc4720de9a77eecb1f2d28..dabf4c11dcb7f35e1d70c43cc4e9c78d9219e089 100644 (file)
--- 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)
index 04e879883a62ebad4fc12f2cc903774aece0773d..05aab11097619c642b4aa0fa79743e6e40cd63fc 100644 (file)
@@ -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
index 2f7f350ffb8e6bd0131872f19a0836ea9ee39897..1338e5430e55bfb6b37f7e5355bd94d282f6d421 100644 (file)
@@ -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;
 }