Setup proper WM lifecycle and xcb bindings
This commit is contained in:
+36
-7
@@ -8,22 +8,51 @@ let spawn cmd =
|
||||
Unix.execvp cmd.(0) cmd
|
||||
| _pid -> ()
|
||||
|
||||
type wm_state = {
|
||||
mutable running : bool;
|
||||
conn : Xcb.Types.Connection.conn_ptr;
|
||||
root : Xcb.Types.Window.t;
|
||||
mutable focus : Xcb.Types.Window.t;
|
||||
}
|
||||
|
||||
let () =
|
||||
let conn = Xcb.Connection.connect () in
|
||||
|
||||
print_endline "Connected to X";
|
||||
|
||||
Xcb.Utils.setup conn;
|
||||
let root = Xcb.Utils.get_root conn in
|
||||
|
||||
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;
|
||||
|
||||
spawn [| "kitty" |];
|
||||
|
||||
while true do
|
||||
if Xcb.Connection.flush conn <= 0 then exit 1;
|
||||
while state.running do
|
||||
(match Xcb.Event.next conn with
|
||||
| None -> ()
|
||||
| Some ev ->
|
||||
(match Xcb.Event.rtype ev with
|
||||
| KeyPress -> (
|
||||
let key = Xcb.Event.Key.detail (Xcb.Event.Key.from ev) in
|
||||
match key with
|
||||
| 26 -> state.running <- false
|
||||
| 25 -> spawn [| "kitty" |]
|
||||
| 24 -> Xcb.Window.kill state.conn state.focus
|
||||
| _ -> ())
|
||||
| MapRequest ->
|
||||
let req = Xcb.Types.Events.Map_request.from ev in
|
||||
let window = Xcb.Types.Events.Map_request.window req in
|
||||
state.focus <- window;
|
||||
Xcb.Window.map state.conn window
|
||||
| _ -> ());
|
||||
Xcb.Utils.free ev);
|
||||
if Xcb.Connection.flush state.conn <= 0 then exit 1;
|
||||
Unix.sleepf 0.01
|
||||
done;
|
||||
|
||||
Xcb.Connection.disconnect conn;
|
||||
|
||||
Xcb.Connection.disconnect state.conn;
|
||||
print_endline "done"
|
||||
|
||||
Reference in New Issue
Block a user