Add workspace management functions.

This commit is contained in:
2026-09-10 14:51:21 +01:00
parent ac72396a0f
commit 6544ae5f23
8 changed files with 227 additions and 69 deletions
+47 -19
View File
@@ -5,18 +5,24 @@ let () =
Bindings.Core.register_callbacks state;
Mruby.Core.mrb_load_string state.mrb
{|
{|#ruby
MOD_MAP = {
none: 0,
alt: 8,
super: 64
}
KEY_MAP = {
"tab" => 23,
"q" => 24,
"w" => 25,
"e" => 26,
"r" => 27,
"f" => 41
"f" => 41,
"n" => 57,
"b" => 56,
"m" => 58,
"v" => 55,
}
def bind(key, mod = :alt, &block)
key = KEY_MAP[key]
@@ -33,21 +39,37 @@ let () =
_unbind key, mod
end
bind "tab" do
system "firefox >/dev/null 2>&1 &"
end
bind ?q do |x|
kill x
end
bind ?w do |x|
bind ?w do
system "kitty >/dev/null 2>&1 &"
end
bind ?e do |x|
bind ?e do
exit
end
bind ?r do |x|
puts "hello there!"
bind ?r do
unbind ?w
end
bind ?f do |x|
toggle_float x
end
bind ?v do |_, x|
remove_ws x
end
bind ?b do |_, x|
jump_ws ((x - 1 + ws_count) % ws_count)
end
bind ?n do |_, x|
jump_ws ((x + 1) % ws_count)
end
bind ?m do
new_ws
end
|};
Mruby.Core.error_check state.mrb;
@@ -64,22 +86,29 @@ let () =
let modifier = Xcb.Types.Events.Key.state req in
Bindings.Keybinds.dispatch_keybind state.mrb state.blocks key
modifier state.focus
(Unsigned.UInt32.of_int state.current)
| MapRequest ->
let req = Xcb.Types.Events.Map_request.from ev in
let window = Xcb.Types.Events.Map_request.window req in
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;
let ws = List.nth state.workspaces state.current in
ws.ws_root <-
Kutu.Layout.insert Kutu.Layout.Horizontal window ws.ws_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)
(Kutu.Layout.calculate state.screen ws.ws_root)
| Create ->
let req = Xcb.Types.Events.Create.from ev in
let window = Xcb.Types.Events.Create.window req in
let override_ridirect =
Xcb.Types.Events.Create.override_redirect req
in
if override_ridirect == Unsigned.UInt8.of_int 0 then
Xcb.Window.setup_window state.conn window
| Enter ->
let req = Xcb.Types.Events.Enter.from ev in
let window = Xcb.Types.Events.Enter.window req in
@@ -88,18 +117,17 @@ let () =
| 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;
let ws = List.nth state.workspaces state.current in
let new_root, removed = Kutu.Layout.remove window ws.ws_root in
if removed then ws.ws_root <- new_root
else
ws.ws_fwindows <- Kutu.Layout.remove_fwindow window ws.ws_fwindows;
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)
(Kutu.Layout.calculate state.screen ws.ws_root)
| _ -> ());
Xcb.Utils.free ev);
Mruby.Core.error_check state.mrb;