moon-plasma / moonplasma / MoonPlasma / Moon Plasma become chandra / Chandra everywhere: the WIT package (chandra:desktop, chandra:host, chandra:wm), the MoonBit module (chandra/desktop) and generated bindings, the Rust host, identifiers (ChandraCompositor), the session script (chandra-session) and desktop entry (chandra.desktop), config and data paths ($XDG_CONFIG_HOME/chandra, share/chandra/modules), env vars (CHANDRA_*), UI strings, docs and tests. The test fixture components are rebuilt against the renamed WIT. Saved panel.edn and state.edn are still read from the old $XDG_CONFIG_HOME/moon-plasma until the first save writes the new copy. The remote repository keeps its experiments/moon-plasma name for now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hi3L9oVBoRd373Qr4n
This commit is contained in:
323 files changed
+1055
-1013
No files matched your search
@@ -0,0 +1,154 @@
|
||||
///| Implementation of `chandra:desktop/plasmoid` for the logout button. A click on the panel
|
||||
/// button opens a small popup, "Log out | Cancel", so a stray click can't end the session; Enter
|
||||
/// confirms and Escape (or a click elsewhere) cancels. Confirming calls `session.logout`, which
|
||||
/// makes the host stop the compositor and hand the screen back to the display manager.
|
||||
|
||||
///| Popup geometry: a column of two rows with a margin around them.
|
||||
let popup_w : Int = 150
|
||||
|
||||
///|
|
||||
let row_h : Int = 30
|
||||
|
||||
///|
|
||||
let margin : Int = 6
|
||||
|
||||
///|
|
||||
let rows : Array[String] = ["Log out", "Cancel"]
|
||||
|
||||
///| Whether the popup is open, and which row the pointer is over (-1: none).
|
||||
let open_ : Ref[Bool] = { val: false }
|
||||
|
||||
///|
|
||||
let hover : Ref[Int] = { val: -1 }
|
||||
|
||||
///|
|
||||
fn popup_h() -> Int {
|
||||
margin * 2 + rows.length() * row_h
|
||||
}
|
||||
|
||||
///| Row under a popup-local y, or -1.
|
||||
fn row_at(x : Int, y : Int) -> Int {
|
||||
if x < margin || x >= popup_w - margin || y < margin {
|
||||
return -1
|
||||
}
|
||||
let i = (y - margin) / row_h
|
||||
if i < rows.length() { i } else { -1 }
|
||||
}
|
||||
|
||||
///|
|
||||
fn close() -> Unit {
|
||||
open_.val = false
|
||||
hover.val = -1
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn info() -> PlasmoidInfo {
|
||||
{
|
||||
id: "org.chandra.logout",
|
||||
name: "Log out",
|
||||
preferred: { w: 84, h: 34 },
|
||||
min_width: 70,
|
||||
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 bg = if open_.val { t.palette.accent } else { t.palette.surface_hover }
|
||||
let fg = if open_.val { t.palette.accent_foreground } else { t.palette.foreground }
|
||||
[
|
||||
@ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=r),
|
||||
@ui.text(w / 2, h / 2, "Log out", fs - 2, fg, align=CENTER),
|
||||
]
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn popup() -> PopupSurface? {
|
||||
if !open_.val {
|
||||
return None
|
||||
}
|
||||
let t = @theme.get_tokens()
|
||||
let w = popup_w
|
||||
let h = popup_h()
|
||||
let r = t.radius.reinterpret_as_int()
|
||||
let fs = t.font_size.reinterpret_as_int()
|
||||
let ops : Array[@types.DrawOp] = [
|
||||
@ui.fill_rect(@ui.rect(0, 0, w, h), t.palette.surface_popup, radius=r),
|
||||
@ui.stroke_rect(@ui.rect(0, 0, w, h), t.palette.border, width=1, radius=r),
|
||||
]
|
||||
for i = 0; i < rows.length(); i = i + 1 {
|
||||
let y = margin + i * row_h
|
||||
let hot = i == hover.val
|
||||
if hot {
|
||||
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, row_h - 2), t.palette.accent, radius=r))
|
||||
}
|
||||
let fg = if hot { t.palette.accent_foreground } else { t.palette.foreground }
|
||||
ops.push(@ui.text(margin + 12, y + (row_h - 2) / 2, rows[i], fs - 1, fg, bold=i == 0))
|
||||
}
|
||||
Some({ size: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }, ops })
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||
match (target, event) {
|
||||
(WIDGET, PointerDown(_)) => {
|
||||
if open_.val {
|
||||
close()
|
||||
} else {
|
||||
open_.val = true
|
||||
hover.val = -1
|
||||
}
|
||||
true
|
||||
}
|
||||
(POPUP, PointerMove(p)) => {
|
||||
let i = row_at(p.x, p.y)
|
||||
if i != hover.val {
|
||||
hover.val = i
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
(POPUP, PointerLeave) =>
|
||||
if hover.val != -1 {
|
||||
hover.val = -1
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
(POPUP, PointerDown(p)) => {
|
||||
let i = row_at(p.x, p.y)
|
||||
close()
|
||||
if i == 0 {
|
||||
@session.logout()
|
||||
}
|
||||
true
|
||||
}
|
||||
(_, FocusLost) =>
|
||||
if open_.val {
|
||||
close()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
(_, KeyDown(k)) =>
|
||||
if !open_.val {
|
||||
false
|
||||
} else if k == "Escape" {
|
||||
close()
|
||||
true
|
||||
} else if k == "Enter" {
|
||||
close()
|
||||
@session.logout()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user