Lock: add session lock from power button and chandra-ctl lock
CI / test (push) Failing after 52s

- Lock the session from the power button or `chandra-ctl lock`
- Unlock with a face or the password; the password always works
- Add compositor lock module with tests, and a polkit unlock policy (org.chandra.unlock)
- Document the lock flow in docs/lock.md and link it from the README
- Add generated interface bindings for the compositor and widget components
This commit is contained in:
nandi committed 2026-11-29 03:24:46 -08:00
1 parent 7501fc3ad9
commit c790f96e58
131 files changed
+4693 -274

No files matched your search

+42 -136
View File
@@ -95,9 +95,9 @@ pub fn ChandraCompositor::osk_key_center(self : ChandraCompositor, label : Strin
None
}
///| Room kept below the keyboard for the panel (none in a strict kiosk, which has no panel).
///| Room kept below the keyboard for the panel (none in a strict kiosk or locked session, which have no panel).
fn ChandraCompositor::osk_panel_room(self : ChandraCompositor) -> Int {
if self.kiosk_strict() { 0 } else { self.theme.panel_height }
if self.kiosk_strict() || self.locked { 0 } else { self.theme.panel_height }
}
///| Height of the on-screen keyboard when shown.
@@ -121,26 +121,10 @@ pub fn ChandraCompositor::osk_rect(self : ChandraCompositor) -> @scene.Rect {
@scene.Rect::new(0, self.output_h - self.osk_panel_room() - h, self.output_w, h)
}
///| Compact "KB" pill above the bottom-right corner of the panel when the OSK is enabled but
/// currently hidden, letting users summon the keyboard anywhere manually.
pub fn ChandraCompositor::osk_toggle_rect(self : ChandraCompositor) -> @scene.Rect {
let w = 44
let h = 28
let x = (self.output_w - w - 6).max(4)
let y = (self.output_h - self.theme.panel_height - h - 6).max(4)
@scene.Rect::new(x, y, w, h)
}
///| Compact "Rot" pill beside the "KB" pill: tap rotates 90 deg CW, long-press/right-click flips 180 deg.
pub fn ChandraCompositor::osk_rotate_rect(self : ChandraCompositor) -> @scene.Rect {
let kb = self.osk_toggle_rect()
let w = 44
@scene.Rect::new((kb.x - w - 6).max(4), kb.y, w, kb.h)
}
///| Show or hide the OSK, resizing `work_area` and lifting panel popups so focused content stays
/// above the keyboard.
fn ChandraCompositor::osk_set_visible(self : ChandraCompositor, want : Bool) -> Unit {
self.shell.osk_visible = want
if self.osk_visible == want {
return
}
@@ -160,17 +144,32 @@ fn ChandraCompositor::osk_set_visible(self : ChandraCompositor, want : Bool) ->
}
}
///| Manually show or hide the OSK (called by the Keyboard panel module).
pub fn ChandraCompositor::osk_set_manual_visible(self : ChandraCompositor, want : Bool) -> Unit {
if want {
self.osk_manual_hide = false
self.osk_manual_show = true
self.osk_sync()
} else {
self.osk_manual_hide = true
self.osk_manual_show = false
self.osk_set_visible(false)
}
self.damage.mark_full()
}
///| Synchronize OSK visibility with the active focus target (auth dialog, emoji picker, open
/// shell popup, active text-input-v3 or terminal window).
pub fn ChandraCompositor::osk_sync(self : ChandraCompositor) -> Unit {
if !self.osk_enabled {
if self.osk_visible {
self.osk_set_visible(false)
}
let want = self.osk_manual_show && !self.osk_manual_hide && !(self.locked && self.auth is None)
self.osk_set_visible(want)
return
}
let (target, auto_want) : (String, Bool) = if self.auth is Some(_) {
("auth", true)
} else if self.locked {
("locked", false)
} else if self.emoji_ui is Some(_) {
("emoji", true)
} else if self.shell.popup_open() {
@@ -223,7 +222,10 @@ fn ChandraCompositor::osk_on_shell_click(self : ChandraCompositor, xi : Int, yi
}
let mid = self.shell.open_popup_module_id()
if mid == "launcher" {
self.osk_manual_hide = false
match self.shell.open_popup_rect() {
Some(r) if r.contains(xi, yi) => self.osk_manual_hide = false
_ => ()
}
} else if mid == "network" {
match self.shell.open_popup_rect() {
Some(r) if r.contains(xi, yi) => {
@@ -449,17 +451,9 @@ fn ChandraCompositor::osk_key_at(self : ChandraCompositor, x : Int, y : Int) ->
None
}
///| Whether `(x, y)` hits either the open OSK or its compact corner pills ("Rot" / "KB").
///| Whether `(x, y)` hits the open OSK.
fn ChandraCompositor::osk_hit_any(self : ChandraCompositor, x : Int, y : Int) -> Bool {
if !self.osk_enabled {
return false
}
if self.osk_visible {
self.osk_rect().contains(x, y)
} else {
!self.kiosk_strict() &&
(self.osk_toggle_rect().contains(x, y) || self.osk_rotate_rect().contains(x, y))
}
self.osk_visible && self.osk_rect().contains(x, y)
}
///| Route one virtual key press+release to the active target (auth dialog, emoji picker, open
@@ -569,13 +563,13 @@ fn ChandraCompositor::osk_activate_key(
self.damage.mark_full()
}
///| Handle host input when over the OSK or its toggle pill. True if consumed.
///| Handle host input when over the visible OSK. True if consumed.
fn ChandraCompositor::osk_input(
self : ChandraCompositor,
ev : @nested.InputEvent,
time_ms : UInt,
) -> Bool {
if !self.osk_enabled {
if !self.osk_visible {
return false
}
match ev {
@@ -584,46 +578,17 @@ fn ChandraCompositor::osk_input(
self.ptr_y = y
let xi = x.to_int()
let yi = y.to_int()
if self.osk_visible {
if self.osk_pointer_grab || self.osk_rect().contains(xi, yi) {
let h = self.osk_key_at(xi, yi)
if h != self.osk_hover {
self.osk_hover = h
self.damage.mark_full()
}
return true
}
if self.osk_hover is Some(_) {
self.osk_hover = None
if self.osk_pointer_grab || self.osk_rect().contains(xi, yi) {
let h = self.osk_key_at(xi, yi)
if h != self.osk_hover {
self.osk_hover = h
self.damage.mark_full()
}
return false
return true
}
if !self.kiosk_strict() {
let hover = if self.osk_toggle_rect().contains(xi, yi) {
Some(-1)
} else if self.osk_rotate_rect().contains(xi, yi) {
Some(-2)
} else {
None
}
match hover {
Some(id) => {
if self.osk_hover != Some(id) {
self.osk_hover = Some(id)
self.damage.mark_full()
}
return true
}
None =>
if self.osk_hover == Some(-1) || self.osk_hover == Some(-2) {
self.osk_hover = None
self.damage.mark_full()
}
}
if self.osk_pointer_grab {
return true
}
if self.osk_hover is Some(_) {
self.osk_hover = None
self.damage.mark_full()
}
false
}
@@ -636,18 +601,8 @@ fn ChandraCompositor::osk_input(
self.osk_pressed = None
self.damage.mark_full()
match idx_opt {
Some(-1) =>
if !self.osk_visible && !self.kiosk_strict() && self.osk_toggle_rect().contains(xi, yi) {
self.osk_manual_hide = false
self.osk_manual_show = true
self.osk_sync()
}
Some(-2) =>
if !self.osk_visible && !self.kiosk_strict() && self.osk_rotate_rect().contains(xi, yi) {
self.rotate_cw()
}
Some(idx) =>
if self.osk_visible && self.osk_key_at(xi, yi) == Some(idx) {
if self.osk_key_at(xi, yi) == Some(idx) {
self.osk_activate_key(idx, time_ms)
self.osk_sync()
}
@@ -655,7 +610,7 @@ fn ChandraCompositor::osk_input(
}
return true
}
if self.osk_visible && self.osk_rect().contains(xi, yi) {
if self.osk_rect().contains(xi, yi) {
if button == 272U && pressed {
self.osk_pointer_grab = true
self.osk_pressed = self.osk_key_at(xi, yi)
@@ -663,75 +618,26 @@ fn ChandraCompositor::osk_input(
}
return true
}
if !self.osk_visible && !self.kiosk_strict() {
let pill = if self.osk_toggle_rect().contains(xi, yi) {
Some(-1)
} else if self.osk_rotate_rect().contains(xi, yi) {
Some(-2)
} else {
None
}
match pill {
Some(id) => {
if pressed {
if button == 272U {
self.osk_pointer_grab = true
self.osk_pressed = Some(id)
self.damage.mark_full()
} else if button == 273U && id == -2 {
// Long-press / right-click on Rot flips 180 degrees.
self.rotate_flip()
}
}
return true
}
None => ()
}
}
false
}
Scroll(_, _, _) => {
let xi = self.ptr_x.to_int()
let yi = self.ptr_y.to_int()
if (self.osk_visible && self.osk_rect().contains(xi, yi)) || self.osk_pointer_grab {
return true
}
false
self.osk_rect().contains(xi, yi) || self.osk_pointer_grab
}
_ => false
}
}
///| Draw the OSK or its compact summon pill when enabled.
///| Draw the OSK when visible.
fn ChandraCompositor::osk_ops(self : ChandraCompositor) -> Array[@scene.DrawOp] {
let ops : Array[@scene.DrawOp] = []
if !self.osk_enabled {
if !self.osk_visible {
return ops
}
let pal = self.theme.palette
let fs = self.theme.font_size
let rad = self.theme.radius
if !self.osk_visible {
if self.kiosk_strict() {
return ops
}
let pills = [(self.osk_rotate_rect(), -2, "Rot"), (self.osk_toggle_rect(), -1, "KB")]
for pill in pills {
let (tr, id, label) = pill
let bg = if self.osk_pressed == Some(id) {
pal.accent
} else if self.osk_hover == Some(id) {
pal.surface_hover
} else {
@scene.Rgba::new(pal.surface_popup.r.to_int(), pal.surface_popup.g.to_int(), pal.surface_popup.b.to_int(), 230)
}
let fg = if self.osk_pressed == Some(id) { pal.accent_foreground } else { pal.foreground }
ops.push(@scene.DrawOp::FillRect(tr, bg, rad + 4))
ops.push(@scene.DrawOp::StrokeRect(tr, pal.border, 1, rad + 4))
ops.push(@scene.DrawOp::Text(tr.x + tr.w / 2, tr.y + tr.h / 2, label, (fs - 2).max(10), fg, @scene.TextAlign::Center, true))
}
return ops
}
let r = self.osk_rect()
let panel_bg = @scene.Rgba::new(pal.surface_popup.r.to_int(), pal.surface_popup.g.to_int(), pal.surface_popup.b.to_int(), 248)
ops.push(@scene.DrawOp::FillRect(r, panel_bg, 0))