From 93d71d820a1cfbb84f105164c752a0d1e2446f12 Mon Sep 17 00:00:00 2001 From: Daanish Syed Date: Wed, 9 Sep 2026 16:14:38 +0100 Subject: [PATCH] Minor updates, breaking. --- src/decl/types.ml | 1 + src/kutu/layout.ml | 37 ++++++++++++++++++------------------- src/main.ml | 24 ++++++++++++------------ src/xcb/screen_iterator.ml | 9 ++++++++- src/xcb/types.ml | 2 ++ 5 files changed, 41 insertions(+), 32 deletions(-) create mode 100644 src/decl/types.ml diff --git a/src/decl/types.ml b/src/decl/types.ml new file mode 100644 index 0000000..7142a5e --- /dev/null +++ b/src/decl/types.ml @@ -0,0 +1 @@ +type rect = { rect_x : int; rect_y : int; rect_width : int; rect_height : int } diff --git a/src/kutu/layout.ml b/src/kutu/layout.ml index d408df7..58ea4b0 100644 --- a/src/kutu/layout.ml +++ b/src/kutu/layout.ml @@ -1,5 +1,4 @@ type direction = Horizontal | Vertical -type rect = { rect_x : int; rect_y : int; rect_width : int; rect_height : int } type layout = | Nothing @@ -11,7 +10,7 @@ type layout = layout_r : layout; } -type fwindow = { fw_rect : rect; fw_window : Xcb.Types.Window.t } +type fwindow = { fw_rect : Decl.Types.rect; fw_window : Xcb.Types.Window.t } type workspace = { mutable ws_root : layout; ws_fwindows : fwindow array } let flip_direction = function Horizontal -> Vertical | Vertical -> Horizontal @@ -35,25 +34,25 @@ let rec insert direction window = function layout_r = insert (flip_direction layout_direction) window layout_r; } -let split_rect rect direction ratio = +let split_rect (rect : Decl.Types.rect) direction ratio = match direction with | Horizontal -> let left_width = int_of_float (float rect.rect_width *. ratio) in let right_width = rect.rect_width - left_width in let left = { - rect_x = rect.rect_x; - rect_y = rect.rect_y; - rect_width = left_width; - rect_height = rect.rect_height; + Decl.Types.rect_x = rect.rect_x; + Decl.Types.rect_y = rect.rect_y; + Decl.Types.rect_width = left_width; + Decl.Types.rect_height = rect.rect_height; } in let right = { - rect_x = rect.rect_x + left_width; - rect_y = rect.rect_y; - rect_width = right_width; - rect_height = rect.rect_height; + Decl.Types.rect_x = rect.rect_x + left_width; + Decl.Types.rect_y = rect.rect_y; + Decl.Types.rect_width = right_width; + Decl.Types.rect_height = rect.rect_height; } in (left, right) @@ -62,18 +61,18 @@ let split_rect rect direction ratio = let bottom_height = rect.rect_height - top_height in let top = { - rect_x = rect.rect_x; - rect_y = rect.rect_y; - rect_width = rect.rect_width; - rect_height = top_height; + Decl.Types.rect_x = rect.rect_x; + Decl.Types.rect_y = rect.rect_y; + Decl.Types.rect_width = rect.rect_width; + Decl.Types.rect_height = top_height; } in let bottom = { - rect_x = rect.rect_x; - rect_y = rect.rect_y + top_height; - rect_width = rect.rect_width; - rect_height = bottom_height; + Decl.Types.rect_x = rect.rect_x; + Decl.Types.rect_y = rect.rect_y + top_height; + Decl.Types.rect_width = rect.rect_width; + Decl.Types.rect_height = bottom_height; } in (top, bottom) diff --git a/src/main.ml b/src/main.ml index 7ddde89..657bc5a 100644 --- a/src/main.ml +++ b/src/main.ml @@ -6,7 +6,7 @@ type wm_state = { mutable focus : Xcb.Types.Window.t; workspaces : Kutu.Layout.workspace array; mutable current : int; - screen : Kutu.Layout.rect; + screen : Decl.Types.rect; } let () = @@ -14,22 +14,22 @@ let () = let conn = Xcb.Connection.connect () in let mrb = Mruby.Core.mrb_open in let root = Xcb.Utils.get_root conn in - let _ = Xcb.Window.setup conn root in + let screen = Xcb.Window.setup conn root in { running = true; conn; mrb; root; focus = root; - workspaces = [| { ws_root = Kutu.Layout.Nothing; ws_fwindows = [||] } |]; + workspaces = + [| + { + Kutu.Layout.ws_root = Kutu.Layout.Nothing; + Kutu.Layout.ws_fwindows = [||]; + }; + |]; current = 0; - screen = - { - Kutu.Layout.rect_x = 100; - Kutu.Layout.rect_y = 100; - Kutu.Layout.rect_width = 100; - Kutu.Layout.rect_height = 100; - }; + screen; } in @@ -61,9 +61,9 @@ let () = let req = Xcb.Types.Events.Map_request.from ev in let window = Xcb.Types.Events.Map_request.window req in state.focus <- window; - state.workspaces.(state.current).ws_root <- + (*Kutu.Layout.ws_root state.workspaces.(state.current)) <- Kutu.Layout.insert Kutu.Layout.Horizontal window - state.workspaces.(state.current).ws_root; + (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; diff --git a/src/xcb/screen_iterator.ml b/src/xcb/screen_iterator.ml index 7767abf..f673118 100644 --- a/src/xcb/screen_iterator.ml +++ b/src/xcb/screen_iterator.ml @@ -9,4 +9,11 @@ let _xcb_get = foreign "xcb_setup_roots_iterator" (ptr Types.Setup.typ @-> returning Types.Screen_iterator.typ) -let screen conn = get conn |> _xcb_get |> Types.Screen_iterator.screen +let screen conn = + let screen = get conn |> _xcb_get |> Types.Screen_iterator.screen in + { + Decl.Types.rect_x = 0; + Decl.Types.rect_y = 0; + Decl.Types.rect_height = Types.Screen.height screen; + Decl.Types.rect_width = Types.Screen.width screen; + } diff --git a/src/xcb/types.ml b/src/xcb/types.ml index 2331ff0..233b0a2 100644 --- a/src/xcb/types.ml +++ b/src/xcb/types.ml @@ -150,6 +150,8 @@ module Screen = struct let allowed_depths_len = field typ "allowed_depths_len" uint8_t let () = seal typ let root ptr = getf ptr root + let width ptr = Unsigned.UInt16.to_int (getf ptr width_in_pixels) + let height ptr = Unsigned.UInt16.to_int (getf ptr height_in_pixels) end module Setup = struct