///| Implementation of `moonplasma:desktop/plasmoid` for the layout toggle: /// a two-segment panel switch, "Tile | Float", that flips the window manager between /// tiling and floating. Monocle (set elsewhere) shows neither segment lit; a click /// then returns to tiling. ///| Mode indices follow the host's layout list: 0 Tiling, 1 Monocle, 2 Floating. let tiling : UInt = 0 ///| let floating : UInt = 2 ///| pub fn info() -> PlasmoidInfo { { id: "org.moonplasma.layout-toggle", name: "Tile / Float", preferred: { w: 120, h: 34 }, min_width: 90, stretch: false, } } ///| pub fn render(size : @types.Size) -> Array[@types.DrawOp] { let t = @theme.get_tokens() let w = size.w.reinterpret_as_int() let h = size.h.reinterpret_as_int() let r = t.radius.reinterpret_as_int() let fs = t.font_size.reinterpret_as_int() let cur = @layout.current_layout() let half = w / 2 let ops : Array[@types.DrawOp] = [ @ui.fill_rect(@ui.rect(0, 0, w, h), t.palette.surface_hover, radius=r), ] if cur == tiling { ops.push(@ui.fill_rect(@ui.rect(0, 0, half, h), t.palette.accent, radius=r)) } else if cur == floating { ops.push(@ui.fill_rect(@ui.rect(half, 0, w - half, h), t.palette.accent, radius=r)) } let on_l = if cur == tiling { t.palette.accent_foreground } else { t.palette.foreground } let on_r = if cur == floating { t.palette.accent_foreground } else { t.palette.foreground } ops.push(@ui.text(half / 2, h / 2, "Tile", fs, on_l, align=CENTER, bold=cur == tiling)) ops.push(@ui.text(half + (w - half) / 2, h / 2, "Float", fs, on_r, align=CENTER, bold=cur == floating)) ops } ///| pub fn popup() -> PopupSurface? { None } ///| pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool { match (target, event) { (WIDGET, PointerDown(_)) => { // Float -> tile; anything else (tiling, monocle) -> float. @layout.set_layout(if @layout.current_layout() == floating { tiling } else { floating }) true } _ => false } }