Face unlock window: live camera preview, Snap, thumbnails, one password on Apply
CI / test (push) Failing after 12m30s
CI / test (push) Failing after 12m30s
Settings > Session "Add or remove faces…" (and "Remove…" on a face) opens a compositor-drawn Face unlock window instead of running root steps one by one: - chandra-face camera runs as the user (no password): it streams a small live picture with the face box and a cropped thumbnail per snap; the snaps' embeddings stay in that process, nothing is written to disk. - Click a snap to drop it; mark saved faces Remove/Keep. - Apply saves the snaps as one face and removes the marked ones in one root `chandra-face apply` (JSON on stdin, validated) through run0/pkexec: one password prompt. - New raster host function image-pixels (host-wasm, wasmhost, native) for the window's pictures. Tests: camera session and apply in face/test_face.py; the window end to end against a fake tool in compositor/host/face_test.mbt. Docs explain why the change itself still needs root. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hhiJfJNAYqWzQiuKMf
This commit is contained in:
74 files changed
+2617
-89
No files matched your search
@@ -7,6 +7,9 @@ pub fn run(Array[String]) -> Int32
|
||||
// Errors
|
||||
|
||||
// Types and methods
|
||||
type IdleClock
|
||||
|
||||
type Pacer
|
||||
|
||||
// Type aliases
|
||||
|
||||
|
||||
@@ -193,6 +193,10 @@ pub(all) struct ChandraCompositor {
|
||||
mut polkit_bus : String
|
||||
mut auth : AuthUi?
|
||||
auth_swallow : Array[UInt]
|
||||
/// The Face unlock window (face_window.mbt): where its controls were drawn, and the change of
|
||||
/// it last drawn.
|
||||
face_hits : Array[(@scene.Rect, FaceHit)]
|
||||
mut face_rev : Int
|
||||
mut auth_routes : Array[@polkit.HelperRoute]
|
||||
mut keymap : (Bytes, @polkit.Keymap)?
|
||||
/// How requests are put into words (tests pass their own process lookups); None: the usual.
|
||||
@@ -236,6 +240,8 @@ pub fn ChandraCompositor::new(
|
||||
polkit_bus: "",
|
||||
auth: None,
|
||||
auth_swallow: [],
|
||||
face_hits: [],
|
||||
face_rev: -1,
|
||||
auth_routes: [],
|
||||
keymap: None,
|
||||
auth_describe: None,
|
||||
@@ -478,6 +484,7 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
|
||||
self.kiosk_tick()
|
||||
self.portal_tick()
|
||||
self.auth_tick()
|
||||
self.face_window_tick()
|
||||
self.control_tick()
|
||||
let events = self.server.poll_events()
|
||||
for ev in events {
|
||||
@@ -906,6 +913,7 @@ fn ChandraCompositor::build_scene(
|
||||
panel_ops.append(self.switcher_ops())
|
||||
}
|
||||
panel_ops.append(self.screenshot_ops())
|
||||
panel_ops.append(self.face_window_ops())
|
||||
panel_ops.append(self.auth_ops())
|
||||
self.frames_built = self.frames_built + 1
|
||||
self.run_shell_actions()
|
||||
@@ -1506,6 +1514,10 @@ pub fn ChandraCompositor::handle_input(
|
||||
if self.auth_input(ev) {
|
||||
return
|
||||
}
|
||||
// So does the Face unlock window (below the password dialog it opens on Apply).
|
||||
if self.face_window_input(ev) {
|
||||
return
|
||||
}
|
||||
match ev {
|
||||
Key(code, pressed) => {
|
||||
self.track_modifier_key(code, pressed)
|
||||
@@ -1868,6 +1880,9 @@ pub fn ChandraCompositor::desired_cursor(self : ChandraCompositor) -> UInt {
|
||||
Some(ui) => return self.auth_cursor(ui)
|
||||
None => ()
|
||||
}
|
||||
if self.shell.face.window is Some(_) {
|
||||
return if self.face_window_hit() is Some(_) { 4U } else { 1U }
|
||||
}
|
||||
match self.shot {
|
||||
Some(o) => return self.overlay_cursor(o)
|
||||
None => ()
|
||||
|
||||
@@ -20,6 +20,27 @@ fn fake_face_tool(dir : String) -> String {
|
||||
#|remove)
|
||||
#| grep -v "^face $2 " "$S/faces" > "$S/faces.new"; mv "$S/faces.new" "$S/faces"
|
||||
#| echo "done Removed face $2" ;;
|
||||
#|camera)
|
||||
#| # The Face unlock window's camera: a grey 4x3 picture with a face box, a white 2x2
|
||||
#| # thumbnail per snap, and an apply that changes the faces file.
|
||||
#| pic() { printf 'frame 4 3 1 0 2 2 36\n'; head -c 36 /dev/zero | tr '\000' '\200'; }
|
||||
#| echo "info Look at the camera and press Snap"; pic
|
||||
#| n=0; kept=0
|
||||
#| while read -r cmd arg; do
|
||||
#| case "$cmd" in
|
||||
#| snap) n=$((n+1)); kept=$((kept+1)); printf 'snap %d 2 2 12\n' $n; head -c 12 /dev/zero | tr '\000' '\377'; pic ;;
|
||||
#| drop) kept=$((kept-1)); pic ;;
|
||||
#| apply)
|
||||
#| echo "info Waiting for the password…"
|
||||
#| for id in $(echo "$arg" | tr ',' ' '); do
|
||||
#| grep -v "^face $id " "$S/faces" > "$S/faces.new"; mv "$S/faces.new" "$S/faces"
|
||||
#| done
|
||||
#| [ $kept -gt 0 ] && printf 'face 2\tFace 2\t2026-11-26\n' >> "$S/faces"
|
||||
#| echo "$kept $arg" > "$S/applied"
|
||||
#| echo "done Added Face 2 and removed 1 face"; echo "applied 0"; exit 0 ;;
|
||||
#| quit) exit 0 ;;
|
||||
#| esac
|
||||
#| done ;;
|
||||
#|pam)
|
||||
#| if [ "$2" = enable ]; then echo "polkit-1,sudo" > "$S/pam"; else : > "$S/pam"; fi
|
||||
#| echo "done ok" ;;
|
||||
@@ -65,7 +86,7 @@ fn face_click(comp : @host.ChandraCompositor, label : String, t : UInt) -> Unit
|
||||
}
|
||||
|
||||
///|
|
||||
test "Settings > Session: face unlock lists faces, adds one, turns it on, removes one" {
|
||||
test "Settings > Session: face unlock lists faces and turns it on" {
|
||||
let dir = "/tmp/chandra-face-test-" + @sys.getpid().to_string()
|
||||
let tool = fake_face_tool(dir)
|
||||
let comp = new_comp("face")
|
||||
@@ -77,12 +98,8 @@ test "Settings > Session: face unlock lists faces, adds one, turns it on, remove
|
||||
assert_true(texts.contains("Face unlock"))
|
||||
assert_true(texts.contains("Use my face for passwords"))
|
||||
assert_true(texts.contains("added 2026-11-20"))
|
||||
assert_true(texts.contains("Add a face…"))
|
||||
assert_true(texts.contains("Add or remove faces…"))
|
||||
assert_false(comp.shell.face.in_use())
|
||||
// Add a face: the tool's progress shows, then the new face.
|
||||
face_click(comp, "Add a face…", 10U)
|
||||
assert_true(face_settle(comp, fn() { face_texts(comp).contains("Face 2") }))
|
||||
assert_true(face_texts(comp).contains("Added Face 2"))
|
||||
// The switch: polkit-1 and sudo try the face first.
|
||||
face_click(comp, "Use my face for passwords", 20U)
|
||||
assert_true(face_settle(comp, fn() { comp.shell.face.in_use() }))
|
||||
@@ -90,13 +107,57 @@ test "Settings > Session: face unlock lists faces, adds one, turns it on, remove
|
||||
if shots != "" {
|
||||
ignore(@sys.write_file_bytes(shots + "/16-settings-face.png", @renderer.encode_png_compressed(comp.compose_frame())))
|
||||
}
|
||||
// Remove takes a second click.
|
||||
face_click(comp, "Remove", 30U)
|
||||
assert_true(face_texts(comp).contains("Click again to remove"))
|
||||
assert_eq(comp.shell.face.faces.length(), 2)
|
||||
face_click(comp, "Click again to remove", 40U)
|
||||
assert_true(face_settle(comp, fn() { comp.shell.face.faces.length() == 1 }))
|
||||
assert_eq(comp.shell.face.faces[0].1, "Face 2")
|
||||
comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
fn face_key(comp : @host.ChandraCompositor, code : UInt, t : UInt) -> Unit {
|
||||
comp.handle_input(@nested.InputEvent::Key(code, true), t)
|
||||
comp.handle_input(@nested.InputEvent::Key(code, false), t + 1U)
|
||||
ignore(comp.compose_frame())
|
||||
}
|
||||
|
||||
///|
|
||||
test "the Face unlock window: live picture, snaps, a face marked for removal, one Apply" {
|
||||
let dir = "/tmp/chandra-face-win-" + @sys.getpid().to_string()
|
||||
let tool = fake_face_tool(dir)
|
||||
let comp = new_comp("facewin")
|
||||
comp.shell.set_face_tool(["/bin/sh", tool])
|
||||
assert_true(comp.shell.open_settings(Session))
|
||||
assert_true(face_settle(comp, fn() { face_texts(comp).contains("Desk") }))
|
||||
// "Remove…" on a face opens the window with that face marked; nothing is removed yet.
|
||||
face_click(comp, "Remove…", 10U)
|
||||
assert_true(face_settle(comp, fn() { comp.shell.face.window.map(w => w.picture != 0U).unwrap_or(false) }))
|
||||
let w = comp.shell.face.window.unwrap()
|
||||
assert_eq(w.remove, ["1"])
|
||||
assert_eq((w.pic_w, w.pic_h, w.face_box), (4, 3, Some((1, 0, 2, 2))))
|
||||
assert_eq(w.message, "Look at the camera and press Snap")
|
||||
// Space snaps (the window has the keyboard), twice; one snap is dropped again.
|
||||
face_key(comp, 57U, 20U)
|
||||
assert_true(face_settle(comp, fn() { w.snaps.length() == 1 }))
|
||||
face_key(comp, 57U, 30U)
|
||||
assert_true(face_settle(comp, fn() { w.snaps.length() == 2 }))
|
||||
assert_eq(w.message, "2 pictures: snap more, or press Apply")
|
||||
comp.shell.face.drop_snap(0)
|
||||
assert_eq(w.snaps.map(s => s.id), ["2"])
|
||||
assert_eq(w.message, "1 picture: turn a little and snap again, or press Apply")
|
||||
let shots = @sys.getenv("CHANDRA_AUTH_SHOTS")
|
||||
if shots != "" {
|
||||
ignore(@sys.write_file_bytes(shots + "/17-face-window.png", @renderer.encode_png_compressed(comp.compose_frame())))
|
||||
}
|
||||
assert_eq(comp.shell.face.faces.length(), 1)
|
||||
// Enter applies: one run for the snap and the removal; the window closes, Settings shows it.
|
||||
face_key(comp, 28U, 40U)
|
||||
assert_true(face_settle(comp, fn() { comp.shell.face.window is None }))
|
||||
assert_true(face_settle(comp, fn() { face_texts(comp).contains("Face 2") }))
|
||||
assert_eq(comp.shell.face.faces.map(f => f.1), ["Face 2"])
|
||||
assert_eq(comp.shell.face.message, "Added Face 2 and removed 1 face")
|
||||
assert_eq(@sys.read_file_bytes(dir + "/applied") |> @utf8.decode_lossy, "1 1\n")
|
||||
// Esc cancels without changing anything.
|
||||
face_click(comp, "Add or remove faces…", 50U)
|
||||
assert_true(face_settle(comp, fn() { comp.shell.face.window is Some(_) }))
|
||||
face_key(comp, 1U, 60U)
|
||||
assert_true(comp.shell.face.window is None)
|
||||
comp.close()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,290 @@
|
||||
///| The Face unlock window (docs/face-unlock.md): Settings > Session > "Add or remove faces…"
|
||||
/// opens it. A live camera picture with the face box, Snap to keep the picture in view (its
|
||||
/// thumbnail shows below; click one to drop it), the saved faces with Remove / Keep, and Apply,
|
||||
/// which saves the snaps and removes the marked faces in one root step: polkit asks for the
|
||||
/// password once, in the password dialog drawn above this window.
|
||||
///
|
||||
/// The camera runs as the user (`chandra-face camera`, compositor/shell/face.mbt); the pictures
|
||||
/// only live in memory, and only the face data (embeddings) is saved.
|
||||
///
|
||||
/// Like the password dialog it is drawn by the compositor above the windows, on a dimmed
|
||||
/// screen, and takes the keyboard and the pointer while it is up: Space snaps, Enter applies,
|
||||
/// Esc cancels.
|
||||
|
||||
///| A control of the window.
|
||||
pub(all) enum FaceHit {
|
||||
Snap
|
||||
DropSnap(Int)
|
||||
ToggleFace(String)
|
||||
Apply
|
||||
Cancel
|
||||
} derive(Eq)
|
||||
|
||||
///| Follow the camera process and redraw when the window changed.
|
||||
fn ChandraCompositor::face_window_tick(self : ChandraCompositor) -> Unit {
|
||||
let f = self.shell.face
|
||||
f.poll_window()
|
||||
if f.window_rev != self.face_rev {
|
||||
self.face_rev = f.window_rev
|
||||
self.damage.mark_full()
|
||||
}
|
||||
}
|
||||
|
||||
///| The control under the pointer.
|
||||
fn ChandraCompositor::face_window_hit(self : ChandraCompositor) -> FaceHit? {
|
||||
let x = self.ptr_x.to_int()
|
||||
let y = self.ptr_y.to_int()
|
||||
for h in self.face_hits {
|
||||
let r = h.0
|
||||
if x >= r.x && x < r.x + r.w && y >= r.y && y < r.y + r.h {
|
||||
return Some(h.1)
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
///| Do what control `h` does.
|
||||
fn ChandraCompositor::face_window_activate(self : ChandraCompositor, h : FaceHit) -> Unit {
|
||||
let f = self.shell.face
|
||||
match h {
|
||||
Snap => f.snap()
|
||||
DropSnap(i) => f.drop_snap(i)
|
||||
ToggleFace(id) => f.toggle_remove(id)
|
||||
Apply => f.apply()
|
||||
Cancel => f.cancel_window()
|
||||
}
|
||||
self.damage.mark_full()
|
||||
}
|
||||
|
||||
///| Input while the window is up: all of it goes to the window.
|
||||
fn ChandraCompositor::face_window_input(self : ChandraCompositor, ev : @nested.InputEvent) -> Bool {
|
||||
if self.shell.face.window is None {
|
||||
return false
|
||||
}
|
||||
match ev {
|
||||
Key(code, pressed) => {
|
||||
if code == key_lsuper || code == key_rsuper {
|
||||
self.super_solo = false
|
||||
}
|
||||
if pressed {
|
||||
self.auth_swallow.push(code)
|
||||
if code == key_esc {
|
||||
self.face_window_activate(Cancel)
|
||||
} else if code == key_enter || code == key_kp_enter {
|
||||
self.face_window_activate(Apply)
|
||||
} else if code == key_space {
|
||||
self.face_window_activate(Snap)
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
Modifiers(_, _, _, _) => true
|
||||
PointerMove(x, y) => {
|
||||
self.ptr_x = x
|
||||
self.ptr_y = y
|
||||
self.damage.mark_full()
|
||||
true
|
||||
}
|
||||
PointerButton(button, pressed) => {
|
||||
if pressed && button == 272U {
|
||||
match self.face_window_hit() {
|
||||
Some(h) => self.face_window_activate(h)
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
Scroll(_, _, _) => true
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
let key_space : UInt = 57
|
||||
|
||||
///| The window, when it is open.
|
||||
fn ChandraCompositor::face_window_ops(self : ChandraCompositor) -> Array[@scene.DrawOp] {
|
||||
let ops : Array[@scene.DrawOp] = []
|
||||
let f = self.shell.face
|
||||
let win = match f.window {
|
||||
Some(w) => w
|
||||
None => {
|
||||
self.face_hits.clear()
|
||||
return ops
|
||||
}
|
||||
}
|
||||
let p = self.theme.palette
|
||||
let (err_c, _) = auth_colors(p)
|
||||
let fs = self.theme.font_size
|
||||
let rad = self.theme.radius + 2
|
||||
let sw = self.output_w
|
||||
let sh = self.output_h
|
||||
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(0, 0, sw, sh), @scene.Rgba::new(0, 0, 0, 150), 0))
|
||||
let w = (sw - 32).min(560)
|
||||
let pad = 24
|
||||
let inner = w - pad * 2
|
||||
let hover = self.face_window_hit()
|
||||
let body : Array[@scene.DrawOp] = []
|
||||
let hits : Array[(@scene.Rect, FaceHit)] = []
|
||||
let mut y = pad
|
||||
body.push(@scene.DrawOp::Text(pad, y + 7, "FACE UNLOCK", fs - 3, p.accent, @scene.TextAlign::Left, true))
|
||||
y = y + 18
|
||||
body.push(@scene.DrawOp::Text(pad, y + (fs + 8) / 2, "Add or remove faces", fs + 3, p.foreground, @scene.TextAlign::Left, true))
|
||||
y = y + fs + 10
|
||||
let intro = "Snap a few pictures: straight on, turned a little, with and without glasses. " +
|
||||
"Pictures stay in memory; Apply saves only the face data, after one password."
|
||||
for l in wrap_text(intro, fs - 1, false, false, inner) {
|
||||
body.push(@scene.DrawOp::Text(pad, y + (fs + 4) / 2, l, fs - 1, p.foreground_muted, @scene.TextAlign::Left, false))
|
||||
y = y + fs + 4
|
||||
}
|
||||
y = y + 12
|
||||
// The live picture, as big as fits (4:3 until the first one says otherwise).
|
||||
let (aw, ah) = if win.pic_w > 0 && win.pic_h > 0 { (win.pic_w, win.pic_h) } else { (4, 3) }
|
||||
let max_h = (sh * 2 / 5).max(120)
|
||||
let mut pw = inner
|
||||
let mut ph = pw * ah / aw
|
||||
if ph > max_h {
|
||||
ph = max_h
|
||||
pw = ph * aw / ah
|
||||
}
|
||||
let pr = @scene.Rect::new(pad + (inner - pw) / 2, y, pw, ph)
|
||||
body.push(@scene.DrawOp::FillRect(pr, @scene.Rgba::new(16, 16, 18, 255), rad))
|
||||
if win.picture != 0U && !win.ended {
|
||||
body.push(@scene.DrawOp::Image(pr, win.picture))
|
||||
match win.face_box {
|
||||
Some((bx, by, bw, bh)) => {
|
||||
let r = @scene.Rect::new(pr.x + bx * pw / win.pic_w, pr.y + by * ph / win.pic_h, bw * pw / win.pic_w, bh * ph / win.pic_h)
|
||||
body.push(@scene.DrawOp::StrokeRect(r, p.accent, 2, 6))
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
} else {
|
||||
face_glyph(pr.x + pw / 2, pr.y + ph / 2 - 12, 22, @scene.Rgba::new(120, 120, 128, 255), body)
|
||||
let t = if win.ended { "No camera picture" } else { "Starting the camera…" }
|
||||
body.push(@scene.DrawOp::Text(pr.x + pw / 2, pr.y + ph / 2 + 30, t, fs - 1, @scene.Rgba::new(200, 200, 205, 255), @scene.TextAlign::Center, false))
|
||||
}
|
||||
y = y + ph + 12
|
||||
// What the camera said, and Snap.
|
||||
let bh = 34
|
||||
let snap_w = @renderer.text_width("Snap", fs, true, false) + 40
|
||||
let sr = @scene.Rect::new(pad + inner - snap_w, y, snap_w, bh)
|
||||
let can_snap = !win.applying && !win.ended && win.picture != 0U
|
||||
auth_button(sr, "Snap", true, false, hover == Some(Snap), can_snap, p, fs, rad, body)
|
||||
if can_snap {
|
||||
hits.push((sr, Snap))
|
||||
}
|
||||
let msg_lines = wrap_text(win.message, fs - 1, false, false, inner - snap_w - 12)
|
||||
let mut my = y + bh / 2 - (msg_lines.length() - 1) * (fs + 3) / 2
|
||||
for l in msg_lines {
|
||||
body.push(@scene.DrawOp::Text(pad, my, l, fs - 1, if win.error { err_c } else { p.foreground }, @scene.TextAlign::Left, false))
|
||||
my = my + fs + 3
|
||||
}
|
||||
y = y + bh.max(msg_lines.length() * (fs + 3)) + 14
|
||||
// The snaps: click one to drop it.
|
||||
if win.snaps.length() > 0 {
|
||||
body.push(@scene.DrawOp::Text(pad, y + 8, "New pictures (click one to drop it)", fs - 2, p.foreground_muted, @scene.TextAlign::Left, true))
|
||||
y = y + 20
|
||||
let ts = 64
|
||||
let gap = 8
|
||||
let per_row = ((inner + gap) / (ts + gap)).max(1)
|
||||
for i, s in win.snaps {
|
||||
let r = @scene.Rect::new(pad + i % per_row * (ts + gap), y + i / per_row * (ts + gap), ts, ts)
|
||||
body.push(@scene.DrawOp::Image(r, s.image))
|
||||
let hov = hover == Some(DropSnap(i))
|
||||
body.push(@scene.DrawOp::StrokeRect(r, if hov { err_c } else { p.border }, if hov { 2 } else { 1 }, 4))
|
||||
if hov {
|
||||
// A cross over it: this one goes.
|
||||
body.push(@scene.DrawOp::Circle(r.x + ts - 10, r.y + 10, 8, err_c, true))
|
||||
body.push(@scene.DrawOp::Line(r.x + ts - 13, r.y + 7, r.x + ts - 7, r.y + 13, p.surface_popup, 2))
|
||||
body.push(@scene.DrawOp::Line(r.x + ts - 7, r.y + 7, r.x + ts - 13, r.y + 13, p.surface_popup, 2))
|
||||
}
|
||||
if !win.applying {
|
||||
hits.push((r, DropSnap(i)))
|
||||
}
|
||||
}
|
||||
y = y + (win.snaps.length() + per_row - 1) / per_row * (ts + gap) + 8
|
||||
}
|
||||
// The saved faces, each with Remove / Keep.
|
||||
if f.faces.length() > 0 {
|
||||
body.push(@scene.DrawOp::Text(pad, y + 8, "Saved faces", fs - 2, p.foreground_muted, @scene.TextAlign::Left, true))
|
||||
y = y + 20
|
||||
let rh = 34
|
||||
for face in f.faces {
|
||||
let (id, label, added) = face
|
||||
let marked = win.remove.contains(id)
|
||||
let btn = if marked { "Keep" } else { "Remove" }
|
||||
let bw = @renderer.text_width("Remove", fs - 1, false, false) + 28
|
||||
let br = @scene.Rect::new(pad + inner - bw, y + 3, bw, rh - 6)
|
||||
face_glyph(pad + 12, y + rh / 2, 9, if marked { p.foreground_muted } else { p.foreground }, body)
|
||||
body.push(@scene.DrawOp::Text(pad + 32, y + rh / 2, label, fs, if marked { p.foreground_muted } else { p.foreground }, @scene.TextAlign::Left, !marked))
|
||||
let lw = @renderer.text_width(label, fs, !marked, false)
|
||||
let note = if marked { "will be removed" } else { "added " + added }
|
||||
body.push(@scene.DrawOp::Text(pad + 32 + lw + 10, y + rh / 2, note, fs - 2, if marked { err_c } else { p.foreground_muted }, @scene.TextAlign::Left, false))
|
||||
if marked {
|
||||
body.push(@scene.DrawOp::Line(pad + 30, y + rh / 2, pad + 34 + lw, y + rh / 2, p.foreground_muted, 1))
|
||||
}
|
||||
auth_button(br, btn, false, false, hover == Some(ToggleFace(id)), !win.applying, p, fs - 1, rad, body)
|
||||
if !win.applying {
|
||||
hits.push((br, ToggleFace(id)))
|
||||
}
|
||||
y = y + rh
|
||||
}
|
||||
y = y + 8
|
||||
}
|
||||
// Footer: what Apply will do, Cancel, Apply.
|
||||
y = y + 6
|
||||
body.push(@scene.DrawOp::Line(pad, y, pad + inner, y, p.border, 1))
|
||||
y = y + 14
|
||||
let adds = win.snaps.length()
|
||||
let rems = win.remove.length()
|
||||
let summary = if win.applying {
|
||||
"Saving…"
|
||||
} else if adds == 0 && rems == 0 {
|
||||
"Nothing to save yet"
|
||||
} else {
|
||||
let parts : Array[String] = []
|
||||
if adds > 0 {
|
||||
parts.push("adds a face from " + adds.to_string() + (if adds == 1 { " picture" } else { " pictures" }))
|
||||
}
|
||||
if rems > 0 {
|
||||
parts.push("removes " + rems.to_string() + (if rems == 1 { " face" } else { " faces" }))
|
||||
}
|
||||
let s = parts.join(", ")
|
||||
"Apply " + s
|
||||
}
|
||||
let apply_w = @renderer.text_width("Apply", fs, true, false) + 40
|
||||
let cancel_w = @renderer.text_width("Cancel", fs, false, false) + 32
|
||||
let ar = @scene.Rect::new(pad + inner - apply_w, y, apply_w, bh)
|
||||
let cr = @scene.Rect::new(ar.x - 10 - cancel_w, y, cancel_w, bh)
|
||||
let sl = wrap_text(summary, fs - 2, false, false, cr.x - pad - 12)
|
||||
let sl = if sl.length() > 2 { sl[:2].to_array() } else { sl }
|
||||
let lh = fs + 2
|
||||
for i, l in sl {
|
||||
body.push(@scene.DrawOp::Text(pad, y + bh / 2 - (sl.length() - 1) * lh / 2 + i * lh, l, fs - 2, p.foreground_muted, @scene.TextAlign::Left, false))
|
||||
}
|
||||
auth_button(cr, "Cancel", false, false, hover == Some(Cancel), !win.applying, p, fs, rad, body)
|
||||
auth_button(ar, "Apply", true, false, hover == Some(Apply), win.can_apply(), p, fs, rad, body)
|
||||
if !win.applying {
|
||||
hits.push((cr, Cancel))
|
||||
}
|
||||
if win.can_apply() {
|
||||
hits.push((ar, Apply))
|
||||
}
|
||||
y = y + bh + pad
|
||||
// Centre the card, with the password dialog's shadow.
|
||||
let h = y
|
||||
let cx = (sw - w) / 2
|
||||
let cyy = ((sh - h) / 2).max(8)
|
||||
for k = 1; k <= 4; k = k + 1 {
|
||||
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(cx - k * 2, cyy - k * 2 + 6, w + k * 4, h + k * 4), @scene.Rgba::new(0, 0, 0, 22), rad + 6 + k * 2))
|
||||
}
|
||||
let opaque = @scene.Rgba::new(p.surface_popup.r.to_int(), p.surface_popup.g.to_int(), p.surface_popup.b.to_int(), 255)
|
||||
ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(cx, cyy, w, h), opaque, rad + 6))
|
||||
ops.push(@scene.DrawOp::StrokeRect(@scene.Rect::new(cx, cyy, w, h), p.border, 1, rad + 6))
|
||||
ops.append(offset_ops_all(body, cx, cyy))
|
||||
self.face_hits.clear()
|
||||
for hit in hits {
|
||||
let r = hit.0
|
||||
self.face_hits.push((@scene.Rect::new(r.x + cx, r.y + cyy, r.w, r.h), hit.1))
|
||||
}
|
||||
ops
|
||||
}
|
||||
@@ -41,6 +41,19 @@ pub fn snapshot_pixels(_r : @scene.Rect, _w : Int, _h : Int) -> @renderer.Pixmap
|
||||
abort("the host rasteriser is only available to the wasm compositor")
|
||||
}
|
||||
|
||||
///| `w` x `h` RGBA pixels as an image (`reuse`: an earlier handle of this kind to overwrite, or 0).
|
||||
pub fn image_pixels(w : Int, h : Int, rgba : Bytes, reuse : UInt) -> UInt {
|
||||
if w <= 0 || h <= 0 || w > 1024 || h > 1024 || rgba.length() < w * h * 4 {
|
||||
return 0U
|
||||
}
|
||||
let p : @renderer.Pixmap = { width: w, height: h, data: rgba.to_fixedarray() }
|
||||
if reuse == 0U {
|
||||
@renderer.add_image(p)
|
||||
} else {
|
||||
@renderer.set_image(reuse, p)
|
||||
}
|
||||
}
|
||||
|
||||
///| Images already loaded, by path (0: it failed, don't try again).
|
||||
let loaded_images : Map[String, UInt] = {}
|
||||
|
||||
|
||||
@@ -128,6 +128,11 @@ pub fn snapshot_pixels(r : @scene.Rect, w : Int, h : Int) -> @renderer.Pixmap {
|
||||
{ width: w, height: h, data: @hostraster.snapshot_pixels(r.x, r.y, r.w, r.h, w, h) }
|
||||
}
|
||||
|
||||
///| `w` x `h` RGBA pixels as an image (`reuse`: an earlier handle of this kind to overwrite, or 0).
|
||||
pub fn image_pixels(w : Int, h : Int, rgba : Bytes, reuse : UInt) -> UInt {
|
||||
@hostraster.image_pixels(w, h, rgba.to_fixedarray(), reuse)
|
||||
}
|
||||
|
||||
///| Images already loaded, by path (0: it failed, don't ask the host again).
|
||||
let loaded_images : Map[String, UInt] = {}
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@ pub fn render_scene(@scene.SceneGraph) -> Pixmap
|
||||
|
||||
pub fn scale_pixmap(Pixmap, Int32, Int32) -> Pixmap
|
||||
|
||||
pub fn set_image(UInt32, Pixmap) -> UInt32
|
||||
|
||||
pub fn set_glyph_source((Int32, Int32, Bool, Bool) -> Glyph) -> Unit
|
||||
|
||||
pub fn set_image(UInt32, Pixmap) -> UInt32
|
||||
|
||||
pub fn shm_thumbnail(@scene.ShmBufferSnapshot, Int32, Int32) -> Pixmap?
|
||||
|
||||
pub fn text_width(String, Int32, Bool, Bool) -> Int32
|
||||
|
||||
@@ -92,6 +92,7 @@ pub(all) enum TextAlign {
|
||||
Right
|
||||
}
|
||||
|
||||
#derive(Eq)
|
||||
pub(all) struct ThemePalette {
|
||||
desktop_top : Rgba
|
||||
desktop_bottom : Rgba
|
||||
@@ -105,6 +106,7 @@ pub(all) struct ThemePalette {
|
||||
border : Rgba
|
||||
}
|
||||
|
||||
#derive(Eq)
|
||||
pub(all) struct ThemeTokens {
|
||||
name : String
|
||||
palette : ThemePalette
|
||||
|
||||
+384
-11
@@ -3,8 +3,14 @@
|
||||
/// gets all of it from `chandra-face` (face/chandra-face), run on a socket so the compositor
|
||||
/// never waits on it: `status` as the user (labels only, no face data), and enroll / remove /
|
||||
/// `pam enable|disable` the same way, which re-run themselves through run0 or pkexec, so polkit
|
||||
/// asks for an administrator's password (in Chandra's own dialog) before anything changes. The
|
||||
/// camera pictures stay inside that root process.
|
||||
/// asks for an administrator's password (in Chandra's own dialog) before anything changes.
|
||||
///
|
||||
/// Adding and removing faces happens in the Face unlock window (FaceWindow, drawn by the host in
|
||||
/// compositor/host/face_window.mbt): `chandra-face camera` runs as the user, with no password,
|
||||
/// and streams a small live picture with the face box; Snap keeps a picture (its embedding stays
|
||||
/// in that process, its thumbnail comes here); saved faces can be marked for removal; Apply hands
|
||||
/// all of it to one root `chandra-face apply`, so the password is asked once. The pictures only
|
||||
/// live in memory: that process's and the images here, which are dropped when the window closes.
|
||||
|
||||
///| What the shell knows about face unlock, and the chandra-face run in progress.
|
||||
pub(all) struct FaceUnlock {
|
||||
@@ -32,6 +38,43 @@ pub(all) struct FaceUnlock {
|
||||
/// The status was read at least once.
|
||||
mut loaded : Bool
|
||||
mut dirty : Bool
|
||||
/// The Face unlock window, while it is open, and a count of its changes (the host redraws).
|
||||
mut window : FaceWindow?
|
||||
mut window_rev : Int
|
||||
/// Image handles to reuse for the live picture (two, in turn, so a new picture is a changed
|
||||
/// draw op) and for snap thumbnails.
|
||||
pics : Array[UInt]
|
||||
spare_thumbs : Array[UInt]
|
||||
}
|
||||
|
||||
///| A snap kept in the Face unlock window: its id in the camera process, and its thumbnail.
|
||||
pub(all) struct FaceSnap {
|
||||
id : String
|
||||
image : UInt
|
||||
}
|
||||
|
||||
///| The Face unlock window: the camera process (`chandra-face camera`) and what it showed.
|
||||
pub(all) struct FaceWindow {
|
||||
mut fd : Int
|
||||
inbuf : Array[Byte]
|
||||
/// A binary message's header words while its bytes are still coming, and how many.
|
||||
mut header : Array[String]
|
||||
mut need : Int
|
||||
/// The live picture (0 until the first one), its size, and the face box in it.
|
||||
mut picture : UInt
|
||||
mut pic_w : Int
|
||||
mut pic_h : Int
|
||||
mut face_box : (Int, Int, Int, Int)?
|
||||
mut pictures : Int
|
||||
snaps : Array[FaceSnap]
|
||||
/// Ids of saved faces marked for removal.
|
||||
remove : Array[String]
|
||||
mut message : String
|
||||
mut error : Bool
|
||||
/// Apply was pressed: the root step runs (or polkit is asking).
|
||||
mut applying : Bool
|
||||
/// When the camera process ended without a picture: the window shows why.
|
||||
mut ended : Bool
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -60,6 +103,10 @@ pub fn FaceUnlock::new() -> FaceUnlock {
|
||||
queue: [],
|
||||
loaded: false,
|
||||
dirty: true,
|
||||
window: None,
|
||||
window_rev: 0,
|
||||
pics: [],
|
||||
spare_thumbs: [],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,10 +302,7 @@ pub fn FaceUnlock::request(self : FaceUnlock, code : Int) -> Unit {
|
||||
return // one change at a time
|
||||
}
|
||||
match code {
|
||||
-2 => {
|
||||
self.message = "Waiting for the password…"
|
||||
self.run(["enroll"], true)
|
||||
}
|
||||
-2 => self.open_window(None)
|
||||
-3 => {
|
||||
self.message = "Waiting for the password…"
|
||||
self.run(["pam", "disable"], true)
|
||||
@@ -267,10 +311,7 @@ pub fn FaceUnlock::request(self : FaceUnlock, code : Int) -> Unit {
|
||||
self.message = "Waiting for the password…"
|
||||
self.run(["pam", "enable"], true)
|
||||
}
|
||||
i if i >= 0 && i < self.faces.length() => {
|
||||
self.message = "Waiting for the password…"
|
||||
self.run(["remove", self.faces[i].0], true)
|
||||
}
|
||||
i if i >= 0 && i < self.faces.length() => self.open_window(Some(self.faces[i].0))
|
||||
_ => return
|
||||
}
|
||||
self.dirty = true
|
||||
@@ -283,6 +324,337 @@ pub fn FaceUnlock::close(self : FaceUnlock) -> Unit {
|
||||
self.fd = -1
|
||||
}
|
||||
self.queue.clear()
|
||||
self.close_window()
|
||||
}
|
||||
|
||||
// ---- the Face unlock window ----
|
||||
|
||||
///| Open the Face unlock window (with saved face `mark` already marked for removal), starting
|
||||
/// the camera as the user. When it is open already, only the mark is added.
|
||||
pub fn FaceUnlock::open_window(self : FaceUnlock, mark : String?) -> Unit {
|
||||
match self.window {
|
||||
Some(w) => {
|
||||
match mark {
|
||||
Some(id) => if !w.remove.contains(id) { w.remove.push(id) }
|
||||
None => ()
|
||||
}
|
||||
self.touch()
|
||||
return
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
let argv = self.tool.copy()
|
||||
argv.append(["camera", "--machine"])
|
||||
let fd = @sys.spawn_socket(argv)
|
||||
let w : FaceWindow = {
|
||||
fd,
|
||||
inbuf: [],
|
||||
header: [],
|
||||
need: 0,
|
||||
picture: 0U,
|
||||
pic_w: 0,
|
||||
pic_h: 0,
|
||||
face_box: None,
|
||||
pictures: 0,
|
||||
snaps: [],
|
||||
remove: match mark {
|
||||
Some(id) => [id]
|
||||
None => []
|
||||
},
|
||||
message: "Starting the camera…",
|
||||
error: false,
|
||||
applying: false,
|
||||
ended: fd < 0,
|
||||
}
|
||||
if fd < 0 {
|
||||
w.message = "Couldn't run chandra-face"
|
||||
w.error = true
|
||||
}
|
||||
self.window = Some(w)
|
||||
self.touch()
|
||||
}
|
||||
|
||||
///| Something in the window changed: Settings and the host redraw.
|
||||
fn FaceUnlock::touch(self : FaceUnlock) -> Unit {
|
||||
self.dirty = true
|
||||
self.window_rev = self.window_rev + 1
|
||||
}
|
||||
|
||||
///| Send a command line to the camera process.
|
||||
fn FaceWindow::send(self : FaceWindow, line : String) -> Unit {
|
||||
if self.fd >= 0 {
|
||||
@sys.write_nonblock(self.fd, @utf8.encode(line + "\n")) |> ignore
|
||||
}
|
||||
}
|
||||
|
||||
///| Keep the picture in view now.
|
||||
pub fn FaceUnlock::snap(self : FaceUnlock) -> Unit {
|
||||
match self.window {
|
||||
Some(w) if !w.applying && !w.ended => w.send("snap")
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| Forget snap `i`.
|
||||
pub fn FaceUnlock::drop_snap(self : FaceUnlock, i : Int) -> Unit {
|
||||
match self.window {
|
||||
Some(w) if !w.applying && i >= 0 && i < w.snaps.length() => {
|
||||
let s = w.snaps.remove(i)
|
||||
self.spare_thumbs.push(s.image)
|
||||
w.send("drop " + s.id)
|
||||
w.message = snapped_text(w.snaps.length())
|
||||
w.error = false
|
||||
self.touch()
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| Mark saved face `id` for removal, or unmark it.
|
||||
pub fn FaceUnlock::toggle_remove(self : FaceUnlock, id : String) -> Unit {
|
||||
match self.window {
|
||||
Some(w) if !w.applying => {
|
||||
if w.remove.contains(id) {
|
||||
w.remove.retain(r => r != id)
|
||||
} else {
|
||||
w.remove.push(id)
|
||||
}
|
||||
self.touch()
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| Whether Apply has anything to do.
|
||||
pub fn FaceWindow::can_apply(self : FaceWindow) -> Bool {
|
||||
!self.applying && self.fd >= 0 && (self.snaps.length() > 0 || self.remove.length() > 0)
|
||||
}
|
||||
|
||||
///| Save the snaps and remove the marked faces, in one root step (one password).
|
||||
pub fn FaceUnlock::apply(self : FaceUnlock) -> Unit {
|
||||
match self.window {
|
||||
Some(w) if w.can_apply() => {
|
||||
w.applying = true
|
||||
w.message = "Waiting for the password…"
|
||||
w.error = false
|
||||
w.send("apply " + w.remove.join(","))
|
||||
self.touch()
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| Close the window without changing anything (the camera stops). Not while Apply runs: the
|
||||
/// root step can't be taken back half way.
|
||||
pub fn FaceUnlock::cancel_window(self : FaceUnlock) -> Unit {
|
||||
match self.window {
|
||||
Some(w) if !w.applying || w.fd < 0 => self.close_window()
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| Close the window and drop its pictures.
|
||||
fn FaceUnlock::close_window(self : FaceUnlock) -> Unit {
|
||||
match self.window {
|
||||
Some(w) => {
|
||||
if w.fd >= 0 {
|
||||
w.send("quit")
|
||||
@sys.close_fd(w.fd)
|
||||
w.fd = -1
|
||||
}
|
||||
for s in w.snaps {
|
||||
self.spare_thumbs.push(s.image)
|
||||
}
|
||||
self.window = None
|
||||
self.touch()
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| Read what the camera process sent (non-blocking).
|
||||
pub fn FaceUnlock::poll_window(self : FaceUnlock) -> Unit {
|
||||
let w = match self.window {
|
||||
Some(w) if w.fd >= 0 => w
|
||||
_ => return
|
||||
}
|
||||
let buf : FixedArray[Byte] = FixedArray::make(65536, b'\x00')
|
||||
let mut eof = false
|
||||
let mut rounds = 0
|
||||
// At most ~1 MB a call: a live picture is ~300 KB.
|
||||
while rounds < 16 && @sys.poll_read(w.fd, 0) > 0 {
|
||||
rounds = rounds + 1
|
||||
let (n, extra) = @sys.recvmsg_fd(w.fd, buf, buf.length())
|
||||
if extra >= 0 {
|
||||
@sys.close_fd(extra)
|
||||
}
|
||||
if n == -1 {
|
||||
break
|
||||
}
|
||||
if n <= 0 {
|
||||
eof = true
|
||||
break
|
||||
}
|
||||
for i = 0; i < n; i = i + 1 {
|
||||
w.inbuf.push(buf[i])
|
||||
}
|
||||
}
|
||||
let mut at = 0
|
||||
while true {
|
||||
if w.need > 0 {
|
||||
if w.inbuf.length() - at < w.need {
|
||||
break
|
||||
}
|
||||
let data = Bytes::from_array(w.inbuf[at:at + w.need].to_array())
|
||||
at = at + w.need
|
||||
w.need = 0
|
||||
self.window_blob(w, w.header, data)
|
||||
continue
|
||||
}
|
||||
let mut nl = -1
|
||||
for i = at; i < w.inbuf.length(); i = i + 1 {
|
||||
if w.inbuf[i] == b'\n' {
|
||||
nl = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if nl < 0 {
|
||||
break
|
||||
}
|
||||
let line = @utf8.decode_lossy(Bytes::from_array(w.inbuf[at:nl].to_array()))
|
||||
at = nl + 1
|
||||
let words = line.split(" ").map(s => s.to_string()).to_array()
|
||||
if (words[0] == "frame" || words[0] == "snap") && words.length() >= 2 {
|
||||
let n = parse_int(words[words.length() - 1])
|
||||
if n > 0 && n <= 4 * 1024 * 1024 {
|
||||
w.header = words
|
||||
w.need = n
|
||||
}
|
||||
continue
|
||||
}
|
||||
self.window_line(w, words[0], if line.length() > words[0].length() { line[words[0].length() + 1:].to_string() } else { "" })
|
||||
}
|
||||
if at > 0 {
|
||||
let rest = w.inbuf[at:].to_array()
|
||||
w.inbuf.clear()
|
||||
w.inbuf.append(rest)
|
||||
}
|
||||
if eof && self.window is Some(_) {
|
||||
@sys.close_fd(w.fd)
|
||||
w.fd = -1
|
||||
if w.applying {
|
||||
// Apply ended (chandra-face said "applied" or went away): close and show the outcome.
|
||||
self.message = if w.error || w.message == "Waiting for the password…" {
|
||||
if w.message == "Waiting for the password…" { "Nothing changed" } else { w.message }
|
||||
} else {
|
||||
w.message
|
||||
}
|
||||
self.close_window()
|
||||
self.refresh()
|
||||
} else {
|
||||
w.ended = true
|
||||
if !w.error {
|
||||
w.message = "The camera stopped"
|
||||
w.error = true
|
||||
}
|
||||
self.touch()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| A text line from the camera process.
|
||||
fn FaceUnlock::window_line(self : FaceUnlock, w : FaceWindow, kind : String, text : String) -> Unit {
|
||||
match kind {
|
||||
"info" | "done" => {
|
||||
w.message = text
|
||||
w.error = false
|
||||
}
|
||||
"error" => {
|
||||
w.message = text
|
||||
w.error = true
|
||||
}
|
||||
"applied" => if text != "0" && !w.error { w.message = "Nothing changed" }
|
||||
_ => ()
|
||||
}
|
||||
self.touch()
|
||||
}
|
||||
|
||||
///| A picture from the camera process: the live one, or a snap's thumbnail.
|
||||
fn FaceUnlock::window_blob(self : FaceUnlock, w : FaceWindow, header : Array[String], rgb : Bytes) -> Unit {
|
||||
let num = (i : Int) => if i < header.length() { parse_int(header[i]) } else { -1 }
|
||||
if header[0] == "frame" && header.length() >= 8 {
|
||||
let pw = num(1)
|
||||
let ph = num(2)
|
||||
let rgba = rgb_to_rgba(rgb, pw, ph)
|
||||
if rgba.length() == 0 {
|
||||
return
|
||||
}
|
||||
// Two handles in turn: a new picture is a different image op, so the host redraws it.
|
||||
while self.pics.length() < 2 {
|
||||
self.pics.push(0U)
|
||||
}
|
||||
let k = w.pictures % 2
|
||||
let h = @raster.image_pixels(pw, ph, rgba, self.pics[k])
|
||||
self.pics[k] = h
|
||||
w.picture = h
|
||||
w.pic_w = pw
|
||||
w.pic_h = ph
|
||||
w.pictures = w.pictures + 1
|
||||
w.face_box = if num(5) > 0 { Some((num(3), num(4), num(5), num(6))) } else { None }
|
||||
if w.pictures == 1 && w.message == "Starting the camera…" {
|
||||
w.message = "Look at the camera and press Snap"
|
||||
}
|
||||
} else if header[0] == "snap" && header.length() >= 5 {
|
||||
let rgba = rgb_to_rgba(rgb, num(2), num(3))
|
||||
if rgba.length() == 0 {
|
||||
return
|
||||
}
|
||||
let reuse = self.spare_thumbs.pop().unwrap_or(0U)
|
||||
let h = @raster.image_pixels(num(2), num(3), rgba, reuse)
|
||||
w.snaps.push({ id: header[1], image: h })
|
||||
w.message = snapped_text(w.snaps.length())
|
||||
w.error = false
|
||||
}
|
||||
self.touch()
|
||||
}
|
||||
|
||||
///| What the window says after a snap or a drop.
|
||||
fn snapped_text(n : Int) -> String {
|
||||
match n {
|
||||
0 => "Look at the camera and press Snap"
|
||||
1 => "1 picture: turn a little and snap again, or press Apply"
|
||||
_ => n.to_string() + " pictures: snap more, or press Apply"
|
||||
}
|
||||
}
|
||||
|
||||
///| RGB bytes of a `w` x `h` picture as RGBA (empty when the sizes don't add up).
|
||||
fn rgb_to_rgba(rgb : Bytes, w : Int, h : Int) -> Bytes {
|
||||
if w <= 0 || h <= 0 || w > 1024 || h > 1024 || rgb.length() < w * h * 3 {
|
||||
return b""
|
||||
}
|
||||
let out = FixedArray::make(w * h * 4, b'\xff')
|
||||
for i = 0; i < w * h; i = i + 1 {
|
||||
out[i * 4] = rgb[i * 3]
|
||||
out[i * 4 + 1] = rgb[i * 3 + 1]
|
||||
out[i * 4 + 2] = rgb[i * 3 + 2]
|
||||
}
|
||||
Bytes::from_fixedarray(out)
|
||||
}
|
||||
|
||||
///| A non-negative decimal number, or -1.
|
||||
fn parse_int(s : String) -> Int {
|
||||
if s.length() == 0 || s.length() > 9 {
|
||||
return -1
|
||||
}
|
||||
let mut n = 0
|
||||
for ch in s {
|
||||
let d = ch.to_int() - 48
|
||||
if d < 0 || d > 9 {
|
||||
return -1
|
||||
}
|
||||
n = n * 10 + d
|
||||
}
|
||||
n
|
||||
}
|
||||
|
||||
///| Publish the face unlock tables (24: status, 25: faces) while a module imports `face-unlock`.
|
||||
@@ -293,6 +665,7 @@ fn DesktopShell::publish_face_unlock(self : DesktopShell) -> Unit {
|
||||
}
|
||||
let f = self.face
|
||||
f.poll()
|
||||
f.poll_window()
|
||||
if !f.dirty {
|
||||
return
|
||||
}
|
||||
@@ -318,5 +691,5 @@ fn DesktopShell::publish_face_unlock(self : DesktopShell) -> Unit {
|
||||
///| Whether a chandra-face run is in progress: the main loop keeps its frame pace meanwhile, so
|
||||
/// what it says shows up (it runs seconds, while the camera looks).
|
||||
pub fn DesktopShell::face_busy(self : DesktopShell) -> Bool {
|
||||
self.face.fd >= 0
|
||||
self.face.fd >= 0 || self.face.window is Some(_)
|
||||
}
|
||||
Reference in new issue
Block a user