Skip to content

Commit 3c0447b

Browse files
committed
Engine: make mouse disappear after some inactivity
1 parent e2c23fb commit 3c0447b

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

src/engine/dune

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(executable
22
(modes js)
33
(name main)
4-
(libraries communication brr normalization browser rescale table_of_content undoable step universe drawing))
4+
(libraries communication brr normalization browser rescale table_of_content undoable step universe drawing mouse_disappearing))
55

66
(rule
77
(action

src/engine/main.ml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ let start id step =
1010
(* TODO: move out of here (Later: Why?) *)
1111
let () = Rescale.setup_rescalers () in
1212
let () = Drawing.setup body in
13+
let () = Mouse_disappearing.setup () in
1314
let initial_step =
1415
match step with
1516
| Some _ as step -> step

src/engine/mouse_disappearing/dune

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(library
2+
(name mouse_disappearing)
3+
(libraries brr))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
(*
2+
document.body.style.cursor = "auto";
3+
let timeOutIds = [];
4+
document.body.addEventListener("mousemove", (ev) => {
5+
timeOutIds.forEach((id) => { clearTimeout(id); });
6+
document.body.style.cursor = "auto";
7+
timeOutIds.push(setTimeout(() => { document.body.style.cursor = "none";}, 5000));
8+
});
9+
*)
10+
let body = Brr.Document.body Brr.G.document
11+
12+
let show_cursor () =
13+
Brr.El.set_inline_style Brr.El.Style.cursor (Jstr.v "auto") body
14+
15+
let hide_cursor () =
16+
Brr.El.set_inline_style Brr.El.Style.cursor (Jstr.v "none") body
17+
18+
let setup () =
19+
show_cursor ();
20+
let timeout_id = ref None in
21+
let _unlisten =
22+
Brr.Ev.listen Brr.Ev.mousemove
23+
(fun _ ->
24+
(match !timeout_id with None -> () | Some id -> Brr.G.stop_timer id);
25+
show_cursor ();
26+
let id = Brr.G.set_timeout ~ms:5000 (fun _ -> hide_cursor ()) in
27+
timeout_id := Some id)
28+
(Brr.El.as_target body)
29+
in
30+
()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val setup : unit -> unit

0 commit comments

Comments
 (0)