Setup proper bindings for mruby.
- and a lot more stuff.
This commit is contained in:
+77
-61
@@ -1,43 +1,55 @@
|
||||
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;
|
||||
workspaces : Kutu.Layout.workspace array;
|
||||
mutable current : int;
|
||||
screen : Decl.Types.rect;
|
||||
}
|
||||
|
||||
let () =
|
||||
let state =
|
||||
let conn = Xcb.Connection.connect () in
|
||||
let mrb = Mruby.Core.mrb_open in
|
||||
let root = Xcb.Utils.get_root conn in
|
||||
let screen = Xcb.Window.setup conn root in
|
||||
{
|
||||
running = true;
|
||||
conn;
|
||||
mrb;
|
||||
root;
|
||||
focus = root;
|
||||
workspaces =
|
||||
[|
|
||||
{
|
||||
Kutu.Layout.ws_root = Kutu.Layout.Nothing;
|
||||
Kutu.Layout.ws_fwindows = [||];
|
||||
};
|
||||
|];
|
||||
current = 0;
|
||||
screen;
|
||||
}
|
||||
in
|
||||
let state = Kutu.State.new_state in
|
||||
|
||||
print_endline "Started Kutu WM";
|
||||
|
||||
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;
|
||||
Bindings.Core.register_callbacks state;
|
||||
Mruby.Core.mrb_load_string state.mrb
|
||||
{|
|
||||
MOD_MAP = {
|
||||
none: 0,
|
||||
alt: 8,
|
||||
super: 64
|
||||
}
|
||||
KEY_MAP = {
|
||||
"q" => 24,
|
||||
"w" => 25,
|
||||
"e" => 26,
|
||||
"r" => 27,
|
||||
"f" => 41
|
||||
}
|
||||
def bind(key, mod = :alt, &block)
|
||||
key = KEY_MAP[key]
|
||||
mod = MOD_MAP[mod]
|
||||
raise "unknown key" unless key
|
||||
raise "unknown modifier" unless mod
|
||||
_bind key, mod, &block
|
||||
end
|
||||
def unbind(key, mod = :alt)
|
||||
key = KEY_MAP[key]
|
||||
mod = MOD_MAP[mod]
|
||||
raise "unknown key" unless key
|
||||
raise "unknown modifier" unless mod
|
||||
_unbind key, mod
|
||||
end
|
||||
|
||||
bind ?q do |x|
|
||||
kill x
|
||||
end
|
||||
bind ?w do |x|
|
||||
system "kitty >/dev/null 2>&1 &"
|
||||
end
|
||||
bind ?e do |x|
|
||||
exit
|
||||
end
|
||||
bind ?r do |x|
|
||||
puts "hello there!"
|
||||
end
|
||||
bind ?f do |x|
|
||||
toggle_float x
|
||||
end
|
||||
|};
|
||||
Mruby.Core.error_check state.mrb;
|
||||
|
||||
if Xcb.Connection.flush state.conn <= 0 then exit 1;
|
||||
|
||||
@@ -46,38 +58,26 @@ let () =
|
||||
| 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 ->
|
||||
Mruby.Core.mrb_load_string state.mrb
|
||||
{|
|
||||
system "kitty &"
|
||||
|}
|
||||
| 24 -> Xcb.Window.kill state.conn state.focus
|
||||
| _ -> ())
|
||||
| KeyPress ->
|
||||
let req = Xcb.Types.Events.Key.from ev in
|
||||
let key = Xcb.Types.Events.Key.detail req in
|
||||
let modifier = Xcb.Types.Events.Key.state req in
|
||||
Bindings.Keybinds.dispatch_keybind state.mrb state.blocks key
|
||||
modifier 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;
|
||||
(*Kutu.Layout.ws_root state.workspaces.(state.current)) <-
|
||||
Kutu.Layout.insert Kutu.Layout.Horizontal window
|
||||
(Kutu.Layout.ws_root state.workspaces.(state.current)*)
|
||||
Xcb.Window.map state.conn window;
|
||||
Xcb.Window.setup_window state.conn window;
|
||||
Xcb.Window.focus state.conn window;
|
||||
Xcb.Window.move_to_bottom state.conn window;
|
||||
state.focus <- window;
|
||||
state.workspaces.(state.current).ws_root <-
|
||||
Kutu.Layout.insert Kutu.Layout.Horizontal window
|
||||
state.workspaces.(state.current).ws_root;
|
||||
List.iter
|
||||
(fun {
|
||||
Kutu.Layout.fw_window = window;
|
||||
fw_rect =
|
||||
{
|
||||
rect_x = x;
|
||||
rect_y = y;
|
||||
rect_width = width;
|
||||
rect_height = height;
|
||||
};
|
||||
} -> Xcb.Window.reshape state.conn window x y width height)
|
||||
(fun { Kutu.Layout.fw_window = window; fw_rect = rect } ->
|
||||
Xcb.Window.reshape state.conn window rect)
|
||||
(Kutu.Layout.calculate state.screen
|
||||
state.workspaces.(state.current).ws_root)
|
||||
| Enter ->
|
||||
@@ -85,6 +85,21 @@ let () =
|
||||
let window = Xcb.Types.Events.Enter.window req in
|
||||
state.focus <- window;
|
||||
Xcb.Window.focus state.conn window
|
||||
| Destroy ->
|
||||
let req = Xcb.Types.Events.Destroy.from ev in
|
||||
let window = Xcb.Types.Events.Destroy.window req in
|
||||
let new_root, removed =
|
||||
Kutu.Layout.remove window state.workspaces.(state.current).ws_root
|
||||
(* TODO: Handle floating windows too. *)
|
||||
in
|
||||
state.workspaces.(state.current).ws_root <- new_root;
|
||||
Xcb.Window.focus state.conn state.root;
|
||||
state.focus <- state.root;
|
||||
List.iter
|
||||
(fun { Kutu.Layout.fw_window = window; fw_rect = rect } ->
|
||||
Xcb.Window.reshape state.conn window rect)
|
||||
(Kutu.Layout.calculate state.screen
|
||||
state.workspaces.(state.current).ws_root)
|
||||
| _ -> ());
|
||||
Xcb.Utils.free ev);
|
||||
Mruby.Core.error_check state.mrb;
|
||||
@@ -92,6 +107,7 @@ let () =
|
||||
Unix.sleepf 0.01
|
||||
done;
|
||||
|
||||
Bindings.Keybinds.cleanup state.mrb state.blocks;
|
||||
Mruby.Core.mrb_close state.mrb;
|
||||
Xcb.Connection.disconnect state.conn;
|
||||
print_endline "Closing up Kutu WM"
|
||||
|
||||
Reference in New Issue
Block a user