1999-11-30 06:59:39 -08:00
|
|
|
open Widget
|
|
|
|
|
|
|
|
(* Events and bindings *)
|
|
|
|
(* Builtin types *)
|
|
|
|
(* type *)
|
1999-12-16 00:37:38 -08:00
|
|
|
type event = [
|
2000-02-16 03:51:37 -08:00
|
|
|
| `ButtonPress (* also Button, but we omit it *)
|
2000-04-02 18:57:52 -07:00
|
|
|
| `ButtonPressDetail of int
|
1999-11-30 06:59:39 -08:00
|
|
|
| `ButtonRelease
|
2000-04-02 18:57:52 -07:00
|
|
|
| `ButtonReleaseDetail of int
|
1999-11-30 06:59:39 -08:00
|
|
|
| `Circulate
|
2000-10-16 00:14:26 -07:00
|
|
|
| `Colormap
|
1999-11-30 06:59:39 -08:00
|
|
|
| `Configure
|
|
|
|
| `Destroy
|
|
|
|
| `Enter
|
|
|
|
| `Expose
|
|
|
|
| `FocusIn
|
|
|
|
| `FocusOut
|
|
|
|
| `Gravity
|
|
|
|
| `KeyPress (* also Key, but we omit it *)
|
2000-04-02 18:57:52 -07:00
|
|
|
| `KeyPressDetail of string (* /usr/include/X11/keysymdef.h *)
|
1999-11-30 06:59:39 -08:00
|
|
|
| `KeyRelease
|
2000-04-02 18:57:52 -07:00
|
|
|
| `KeyReleaseDetail of string
|
1999-11-30 06:59:39 -08:00
|
|
|
| `Leave
|
|
|
|
| `Map
|
|
|
|
| `Motion
|
|
|
|
| `Property
|
|
|
|
| `Reparent
|
|
|
|
| `Unmap
|
1999-12-16 00:37:38 -08:00
|
|
|
| `Visibility
|
2000-04-02 18:57:52 -07:00
|
|
|
| `Modified of modifier list * event
|
1999-11-30 06:59:39 -08:00
|
|
|
]
|
|
|
|
|
1999-12-16 00:37:38 -08:00
|
|
|
and modifier = [
|
2000-02-16 03:51:37 -08:00
|
|
|
| `Control
|
1999-11-30 06:59:39 -08:00
|
|
|
| `Shift
|
|
|
|
| `Lock
|
|
|
|
| `Button1
|
|
|
|
| `Button2
|
|
|
|
| `Button3
|
|
|
|
| `Button4
|
|
|
|
| `Button5
|
|
|
|
| `Double
|
|
|
|
| `Triple
|
|
|
|
| `Mod1
|
|
|
|
| `Mod2
|
|
|
|
| `Mod3
|
|
|
|
| `Mod4
|
|
|
|
| `Mod5
|
|
|
|
| `Meta
|
|
|
|
| `Alt
|
|
|
|
]
|
|
|
|
(* /type *)
|
|
|
|
|
|
|
|
(* Event structure, passed to bounded functions *)
|
|
|
|
|
|
|
|
(* type *)
|
|
|
|
type eventInfo =
|
|
|
|
{
|
|
|
|
mutable ev_Above : int; (* tk: %a *)
|
|
|
|
mutable ev_ButtonNumber : int; (* tk: %b *)
|
|
|
|
mutable ev_Count : int; (* tk: %c *)
|
|
|
|
mutable ev_Detail : string; (* tk: %d *)
|
|
|
|
mutable ev_Focus : bool; (* tk: %f *)
|
|
|
|
mutable ev_Height : int; (* tk: %h *)
|
|
|
|
mutable ev_KeyCode : int; (* tk: %k *)
|
|
|
|
mutable ev_Mode : string; (* tk: %m *)
|
|
|
|
mutable ev_OverrideRedirect : bool; (* tk: %o *)
|
|
|
|
mutable ev_Place : string; (* tk: %p *)
|
|
|
|
mutable ev_State : string; (* tk: %s *)
|
|
|
|
mutable ev_Time : int; (* tk: %t *)
|
|
|
|
mutable ev_Width : int; (* tk: %w *)
|
|
|
|
mutable ev_MouseX : int; (* tk: %x *)
|
|
|
|
mutable ev_MouseY : int; (* tk: %y *)
|
|
|
|
mutable ev_Char : string; (* tk: %A *)
|
|
|
|
mutable ev_BorderWidth : int; (* tk: %B *)
|
|
|
|
mutable ev_SendEvent : bool; (* tk: %E *)
|
|
|
|
mutable ev_KeySymString : string; (* tk: %K *)
|
|
|
|
mutable ev_KeySymInt : int; (* tk: %N *)
|
|
|
|
mutable ev_RootWindow : int; (* tk: %R *)
|
|
|
|
mutable ev_SubWindow : int; (* tk: %S *)
|
|
|
|
mutable ev_Type : int; (* tk: %T *)
|
|
|
|
mutable ev_Widget : any widget; (* tk: %W *)
|
|
|
|
mutable ev_RootX : int; (* tk: %X *)
|
|
|
|
mutable ev_RootY : int (* tk: %Y *)
|
|
|
|
}
|
|
|
|
(* /type *)
|
|
|
|
|
|
|
|
|
|
|
|
(* To avoid collision with other constructors (Width, State),
|
|
|
|
use Ev_ prefix *)
|
|
|
|
(* type *)
|
|
|
|
type eventField = [
|
2000-02-16 03:51:37 -08:00
|
|
|
| `Above
|
1999-11-30 06:59:39 -08:00
|
|
|
| `ButtonNumber
|
|
|
|
| `Count
|
|
|
|
| `Detail
|
|
|
|
| `Focus
|
|
|
|
| `Height
|
|
|
|
| `KeyCode
|
|
|
|
| `Mode
|
|
|
|
| `OverrideRedirect
|
|
|
|
| `Place
|
|
|
|
| `State
|
|
|
|
| `Time
|
|
|
|
| `Width
|
|
|
|
| `MouseX
|
|
|
|
| `MouseY
|
|
|
|
| `Char
|
|
|
|
| `BorderWidth
|
|
|
|
| `SendEvent
|
|
|
|
| `KeySymString
|
|
|
|
| `KeySymInt
|
|
|
|
| `RootWindow
|
|
|
|
| `SubWindow
|
|
|
|
| `Type
|
|
|
|
| `Widget
|
|
|
|
| `RootX
|
|
|
|
| `RootY
|
|
|
|
]
|
|
|
|
(* /type *)
|
|
|
|
|
1999-12-16 00:37:38 -08:00
|
|
|
let filleventInfo ev v : eventField -> unit = function
|
2000-02-16 03:51:37 -08:00
|
|
|
| `Above -> ev.ev_Above <- int_of_string v
|
1999-11-30 06:59:39 -08:00
|
|
|
| `ButtonNumber -> ev.ev_ButtonNumber <- int_of_string v
|
|
|
|
| `Count -> ev.ev_Count <- int_of_string v
|
|
|
|
| `Detail -> ev.ev_Detail <- v
|
|
|
|
| `Focus -> ev.ev_Focus <- v = "1"
|
|
|
|
| `Height -> ev.ev_Height <- int_of_string v
|
|
|
|
| `KeyCode -> ev.ev_KeyCode <- int_of_string v
|
|
|
|
| `Mode -> ev.ev_Mode <- v
|
|
|
|
| `OverrideRedirect -> ev.ev_OverrideRedirect <- v = "1"
|
|
|
|
| `Place -> ev.ev_Place <- v
|
|
|
|
| `State -> ev.ev_State <- v
|
|
|
|
| `Time -> ev.ev_Time <- int_of_string v
|
|
|
|
| `Width -> ev.ev_Width <- int_of_string v
|
|
|
|
| `MouseX -> ev.ev_MouseX <- int_of_string v
|
|
|
|
| `MouseY -> ev.ev_MouseY <- int_of_string v
|
|
|
|
| `Char -> ev.ev_Char <- v
|
|
|
|
| `BorderWidth -> ev.ev_BorderWidth <- int_of_string v
|
|
|
|
| `SendEvent -> ev.ev_SendEvent <- v = "1"
|
|
|
|
| `KeySymString -> ev.ev_KeySymString <- v
|
|
|
|
| `KeySymInt -> ev.ev_KeySymInt <- int_of_string v
|
|
|
|
| `RootWindow -> ev.ev_RootWindow <- int_of_string v
|
|
|
|
| `SubWindow -> ev.ev_SubWindow <- int_of_string v
|
|
|
|
| `Type -> ev.ev_Type <- int_of_string v
|
|
|
|
| `Widget -> ev.ev_Widget <- cTKtoCAMLwidget v
|
|
|
|
| `RootX -> ev.ev_RootX <- int_of_string v
|
|
|
|
| `RootY -> ev.ev_RootY <- int_of_string v
|
|
|
|
|
1999-12-16 00:37:38 -08:00
|
|
|
let wrapeventInfo f (what : eventField list) =
|
1999-11-30 06:59:39 -08:00
|
|
|
let ev = {
|
|
|
|
ev_Above = 0;
|
|
|
|
ev_ButtonNumber = 0;
|
|
|
|
ev_Count = 0;
|
|
|
|
ev_Detail = "";
|
|
|
|
ev_Focus = false;
|
|
|
|
ev_Height = 0;
|
|
|
|
ev_KeyCode = 0;
|
|
|
|
ev_Mode = "";
|
|
|
|
ev_OverrideRedirect = false;
|
|
|
|
ev_Place = "";
|
|
|
|
ev_State = "";
|
|
|
|
ev_Time = 0;
|
|
|
|
ev_Width = 0;
|
|
|
|
ev_MouseX = 0;
|
|
|
|
ev_MouseY = 0;
|
|
|
|
ev_Char = "";
|
|
|
|
ev_BorderWidth = 0;
|
|
|
|
ev_SendEvent = false;
|
|
|
|
ev_KeySymString = "";
|
|
|
|
ev_KeySymInt = 0;
|
|
|
|
ev_RootWindow = 0;
|
|
|
|
ev_SubWindow = 0;
|
|
|
|
ev_Type = 0;
|
|
|
|
ev_Widget = forget_type default_toplevel;
|
|
|
|
ev_RootX = 0;
|
|
|
|
ev_RootY = 0 } in
|
|
|
|
function args ->
|
|
|
|
let l = ref args in
|
2000-04-11 20:43:25 -07:00
|
|
|
List.iter what ~f:
|
|
|
|
begin fun field ->
|
|
|
|
match !l with
|
|
|
|
| [] -> ()
|
|
|
|
| v :: rest -> filleventInfo ev v field; l := rest
|
|
|
|
end;
|
1999-11-30 06:59:39 -08:00
|
|
|
f ev
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-12-16 00:37:38 -08:00
|
|
|
let rec writeeventField : eventField list -> string = function
|
2000-02-16 03:51:37 -08:00
|
|
|
| [] -> ""
|
|
|
|
| field :: rest ->
|
1999-11-30 06:59:39 -08:00
|
|
|
begin
|
|
|
|
match field with
|
2000-02-16 03:51:37 -08:00
|
|
|
| `Above -> " %a"
|
|
|
|
| `ButtonNumber ->" %b"
|
|
|
|
| `Count -> " %c"
|
|
|
|
| `Detail -> " %d"
|
|
|
|
| `Focus -> " %f"
|
|
|
|
| `Height -> " %h"
|
|
|
|
| `KeyCode -> " %k"
|
|
|
|
| `Mode -> " %m"
|
|
|
|
| `OverrideRedirect -> " %o"
|
|
|
|
| `Place -> " %p"
|
|
|
|
| `State -> " %s"
|
|
|
|
| `Time -> " %t"
|
|
|
|
| `Width -> " %w"
|
|
|
|
| `MouseX -> " %x"
|
|
|
|
| `MouseY -> " %y"
|
|
|
|
(* Quoting is done by Tk *)
|
|
|
|
| `Char -> " %A"
|
|
|
|
| `BorderWidth -> " %B"
|
|
|
|
| `SendEvent -> " %E"
|
|
|
|
| `KeySymString -> " %K"
|
|
|
|
| `KeySymInt -> " %N"
|
|
|
|
| `RootWindow ->" %R"
|
|
|
|
| `SubWindow -> " %S"
|
|
|
|
| `Type -> " %T"
|
|
|
|
| `Widget -> " %W"
|
|
|
|
| `RootX -> " %X"
|
|
|
|
| `RootY -> " %Y"
|
1999-11-30 06:59:39 -08:00
|
|
|
end
|
|
|
|
^ writeeventField rest
|