Fix and make mruby work better
This commit is contained in:
+22
-24
@@ -1,38 +1,30 @@
|
||||
let spawn cmd =
|
||||
match Unix.fork () with
|
||||
| 0 ->
|
||||
let devnull = Unix.openfile "/dev/null" [ Unix.O_WRONLY ] 0o666 in
|
||||
Unix.dup2 devnull Unix.stdout;
|
||||
Unix.dup2 devnull Unix.stderr;
|
||||
Unix.close devnull;
|
||||
Unix.execvp cmd.(0) cmd
|
||||
| _pid -> ()
|
||||
|
||||
type wm_state = {
|
||||
mutable running : bool;
|
||||
conn : Xcb.Types.Connection.conn_ptr;
|
||||
mrb : Mruby.Types.Mrb_state.mrb_ptr;
|
||||
root : Xcb.Types.Window.t;
|
||||
mutable focus : Xcb.Types.Window.t;
|
||||
}
|
||||
|
||||
let () =
|
||||
let conn = Xcb.Connection.connect () in
|
||||
let state =
|
||||
let conn = Xcb.Connection.connect () in
|
||||
let mrb = Mruby.Core.mrb_open in
|
||||
let root = Xcb.Utils.get_root conn in
|
||||
{ running = true; conn; mrb; root; focus = root }
|
||||
in
|
||||
|
||||
print_endline "Connected to X";
|
||||
print_endline "Started Kutu WM";
|
||||
|
||||
let root = Xcb.Utils.get_root conn in
|
||||
Xcb.Window.setup state.conn state.root;
|
||||
Xcb.Window.keybind state.conn state.root 0 24;
|
||||
Xcb.Window.keybind state.conn state.root 0 25;
|
||||
Xcb.Window.keybind state.conn state.root 0 26;
|
||||
|
||||
let state = { running = true; conn; root; focus = root } in
|
||||
|
||||
Xcb.Window.setup conn root;
|
||||
Xcb.Window.keybind conn root 0 24;
|
||||
Xcb.Window.keybind conn root 0 25;
|
||||
Xcb.Window.keybind conn root 0 26;
|
||||
|
||||
if Xcb.Connection.flush conn <= 0 then exit 1;
|
||||
if Xcb.Connection.flush state.conn <= 0 then exit 1;
|
||||
|
||||
while state.running do
|
||||
(match Xcb.Event.next conn with
|
||||
(match Xcb.Event.next state.conn with
|
||||
| None -> ()
|
||||
| Some ev ->
|
||||
(match Xcb.Event.rtype ev with
|
||||
@@ -40,7 +32,11 @@ let () =
|
||||
let key = Xcb.Event.Key.detail (Xcb.Event.Key.from ev) in
|
||||
match key with
|
||||
| 26 -> state.running <- false
|
||||
| 25 -> spawn [| "kitty" |]
|
||||
| 25 ->
|
||||
Mruby.Core.mrb_load_string state.mrb
|
||||
{|
|
||||
system "kitty &"
|
||||
|}
|
||||
| 24 -> Xcb.Window.kill state.conn state.focus
|
||||
| _ -> ())
|
||||
| MapRequest ->
|
||||
@@ -50,9 +46,11 @@ let () =
|
||||
Xcb.Window.map state.conn window
|
||||
| _ -> ());
|
||||
Xcb.Utils.free ev);
|
||||
Mruby.Core.error_check state.mrb;
|
||||
if Xcb.Connection.flush state.conn <= 0 then exit 1;
|
||||
Unix.sleepf 0.01
|
||||
done;
|
||||
|
||||
Mruby.Core.mrb_close state.mrb;
|
||||
Xcb.Connection.disconnect state.conn;
|
||||
print_endline "done"
|
||||
print_endline "Closing up Kutu WM"
|
||||
|
||||
Reference in New Issue
Block a user