- remote/: shared-memory framebuffer mirror served as RFB 3.8 (VNC, port 5900) and an HTTP/WebSocket PWA (port 6080), bound to the Tailscale interface and loopback by default - Compositor: remote pointer, button, scroll, modifier, key, key-tap, text and clipboard input, routed past OLED blanking - chandra-ctl: add status, refresh and osk commands; add input-* and clipboard-set for remote control - Camera: debayer 10-bit CSI-2 Quad-Bayer frames for imx371 and high-quality still capture - Camera: rotate frames by the libcamera mounting angle (CCW for 90), fix the expected test values, and restyle the UI for a dark theme
This commit is contained in:
1 parent
de39b74282
commit
bfc60ee0e5
24 files changed
+5310
-79
No files matched your search
@@ -188,6 +188,92 @@ fn ChandraCompositor::control_tick(self : ChandraCompositor) -> Unit {
|
||||
}
|
||||
}
|
||||
|
||||
///| Parse a signed base-10 integer string.
|
||||
fn parse_int_opt(s : String) -> Int? {
|
||||
if s.length() == 0 {
|
||||
return None
|
||||
}
|
||||
let mut neg = false
|
||||
let mut start = 0
|
||||
if s[0] == '-' {
|
||||
neg = true
|
||||
start = 1
|
||||
} else if s[0] == '+' {
|
||||
start = 1
|
||||
}
|
||||
if start >= s.length() {
|
||||
return None
|
||||
}
|
||||
let mut acc : Int64 = 0L
|
||||
for i = start; i < s.length(); i = i + 1 {
|
||||
let c = s[i].to_int()
|
||||
if c < 48 || c > 57 {
|
||||
return None
|
||||
}
|
||||
acc = acc * 10L + (c - 48).to_int64()
|
||||
if acc > 2147483648L {
|
||||
return None
|
||||
}
|
||||
}
|
||||
let v = if neg { -acc } else { acc }
|
||||
if v < -2147483648L || v > 2147483647L {
|
||||
None
|
||||
} else {
|
||||
Some(v.to_int())
|
||||
}
|
||||
}
|
||||
|
||||
///| Parse an unsigned base-10 integer string.
|
||||
fn parse_uint_opt(s : String) -> UInt? {
|
||||
if s.length() == 0 {
|
||||
return None
|
||||
}
|
||||
let mut acc : UInt64 = 0UL
|
||||
for i = 0; i < s.length(); i = i + 1 {
|
||||
let c = s[i].to_int()
|
||||
if c < 48 || c > 57 {
|
||||
return None
|
||||
}
|
||||
acc = acc * 10UL + (c - 48).to_uint64()
|
||||
if acc > 4294967295UL {
|
||||
return None
|
||||
}
|
||||
}
|
||||
Some(acc.to_uint())
|
||||
}
|
||||
|
||||
///| Convert one ASCII hex digit into 0..15, or -1 if invalid.
|
||||
fn hex_nibble(c : Int) -> Int {
|
||||
if c >= 48 && c <= 57 {
|
||||
c - 48
|
||||
} else if c >= 65 && c <= 70 {
|
||||
c - 55
|
||||
} else if c >= 97 && c <= 102 {
|
||||
c - 87
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
}
|
||||
|
||||
///| Decode a lowercase/uppercase hex string into UTF-8 `String`.
|
||||
fn decode_hex_utf8(s : String) -> String? {
|
||||
if s.length() % 2 != 0 {
|
||||
return None
|
||||
}
|
||||
let out : Array[Byte] = []
|
||||
let mut i = 0
|
||||
while i < s.length() {
|
||||
let hi = hex_nibble(s[i].to_int())
|
||||
let lo = hex_nibble(s[i + 1].to_int())
|
||||
if hi < 0 || lo < 0 {
|
||||
return None
|
||||
}
|
||||
out.push(((hi << 4) | lo).to_byte())
|
||||
i = i + 2
|
||||
}
|
||||
Some(@utf8.decode_lossy(Bytes::from_array(out)))
|
||||
}
|
||||
|
||||
///| Run one control command; the reply lines (the last starts with "ok" or "error") and whether
|
||||
/// it succeeded.
|
||||
pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : String) -> (Array[String], Bool) {
|
||||
@@ -216,6 +302,9 @@ pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : Strin
|
||||
"rotate [cw|ccw|flip|0|90|180|270|status] rotate or flip the display",
|
||||
"screen [on|off|toggle|status] blank or wake the display",
|
||||
"brightness [PCT|status] read or set display backlight percent (5..100)",
|
||||
"osk [on|off|toggle|status] enable, disable, or query the on-screen keyboard",
|
||||
"refresh schedule a full frame redraw",
|
||||
"status report geometry, rotation, screen power, brightness, pointer, OSK",
|
||||
"settings [TAB] open Settings popup (session, desktop, panel, power, shortcuts, apps)",
|
||||
"auth-demo [MODE] show the password dialog with a pretend check (password \"demo\"); MODE: " +
|
||||
@polkit.demo_modes.join(", "),
|
||||
@@ -485,6 +574,194 @@ pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : Strin
|
||||
}
|
||||
}
|
||||
}
|
||||
"status" => {
|
||||
let deg = (self.rotation * 90).to_string()
|
||||
let scr = if self.screen_off || self.manual_screen_off { "off" } else { "on" }
|
||||
let bri = @shell.read_backlight_percent().to_string()
|
||||
let ptr = self.ptr_x.to_int().to_string() + "," + self.ptr_y.to_int().to_string()
|
||||
let osk = if self.osk_enabled { "1" } else { "0" }
|
||||
(
|
||||
[
|
||||
"ok " +
|
||||
self.output_w.to_string() +
|
||||
"x" +
|
||||
self.output_h.to_string() +
|
||||
" rot=" +
|
||||
deg +
|
||||
" screen=" +
|
||||
scr +
|
||||
" brightness=" +
|
||||
bri +
|
||||
" ptr=" +
|
||||
ptr +
|
||||
" osk=" +
|
||||
osk,
|
||||
],
|
||||
true,
|
||||
)
|
||||
}
|
||||
"refresh" => {
|
||||
self.damage.mark_full()
|
||||
self.frame_changed = true
|
||||
(["ok"], true)
|
||||
}
|
||||
"osk" => {
|
||||
let arg = if words.length() >= 2 { words[1] } else { "status" }
|
||||
if words.length() > 2 {
|
||||
return (["error usage: osk [on|off|toggle|status]"], false)
|
||||
}
|
||||
match arg {
|
||||
"status" => (["ok " + (if self.osk_enabled { "on" } else { "off" })], true)
|
||||
"on" => {
|
||||
self.set_osk_enabled(true)
|
||||
(["ok on"], true)
|
||||
}
|
||||
"off" => {
|
||||
self.set_osk_enabled(false)
|
||||
(["ok off"], true)
|
||||
}
|
||||
"toggle" => {
|
||||
let next = !self.osk_enabled
|
||||
self.set_osk_enabled(next)
|
||||
(["ok " + (if next { "on" } else { "off" })], true)
|
||||
}
|
||||
_ => (["error usage: osk [on|off|toggle|status]"], false)
|
||||
}
|
||||
}
|
||||
"input-ptr" => {
|
||||
if words.length() != 3 {
|
||||
return (["error usage: input-ptr X Y"], false)
|
||||
}
|
||||
match (parse_int_opt(words[1]), parse_int_opt(words[2])) {
|
||||
(Some(x), Some(y)) => {
|
||||
let now_ms = @sys.monotonic_ms().to_uint()
|
||||
self.handle_remote_input(
|
||||
@nested.InputEvent::PointerMove(x.to_double(), y.to_double()),
|
||||
now_ms,
|
||||
)
|
||||
(["ok"], true)
|
||||
}
|
||||
_ => (["error invalid coordinates"], false)
|
||||
}
|
||||
}
|
||||
"input-btn" => {
|
||||
if words.length() != 3 {
|
||||
return (["error usage: input-btn CODE STATE"], false)
|
||||
}
|
||||
match (parse_uint_opt(words[1]), parse_int_opt(words[2])) {
|
||||
(Some(code), Some(state)) => {
|
||||
let now_ms = @sys.monotonic_ms().to_uint()
|
||||
self.handle_remote_input(
|
||||
@nested.InputEvent::PointerButton(code, state != 0),
|
||||
now_ms,
|
||||
)
|
||||
(["ok"], true)
|
||||
}
|
||||
_ => (["error invalid button args"], false)
|
||||
}
|
||||
}
|
||||
"input-scroll" => {
|
||||
if words.length() != 4 {
|
||||
return (["error usage: input-scroll AXIS VAL DISCRETE"], false)
|
||||
}
|
||||
match
|
||||
(parse_uint_opt(words[1]), parse_int_opt(words[2]), parse_int_opt(words[3])) {
|
||||
(Some(axis), Some(val), Some(disc)) => {
|
||||
let now_ms = @sys.monotonic_ms().to_uint()
|
||||
self.handle_remote_input(
|
||||
@nested.InputEvent::Scroll(axis, val.to_double(), disc),
|
||||
now_ms,
|
||||
)
|
||||
(["ok"], true)
|
||||
}
|
||||
_ => (["error invalid scroll args"], false)
|
||||
}
|
||||
}
|
||||
"input-mods" => {
|
||||
if words.length() != 5 {
|
||||
return (["error usage: input-mods DEP LAT LOCK GROUP"], false)
|
||||
}
|
||||
match
|
||||
(
|
||||
parse_uint_opt(words[1]),
|
||||
parse_uint_opt(words[2]),
|
||||
parse_uint_opt(words[3]),
|
||||
parse_uint_opt(words[4]),
|
||||
) {
|
||||
(Some(dep), Some(lat), Some(lock), Some(grp)) => {
|
||||
let now_ms = @sys.monotonic_ms().to_uint()
|
||||
self.handle_remote_input(
|
||||
@nested.InputEvent::Modifiers(dep, lat, lock, grp),
|
||||
now_ms,
|
||||
)
|
||||
(["ok"], true)
|
||||
}
|
||||
_ => (["error invalid modifier args"], false)
|
||||
}
|
||||
}
|
||||
"input-key" => {
|
||||
if words.length() != 3 {
|
||||
return (["error usage: input-key CODE STATE"], false)
|
||||
}
|
||||
match (parse_uint_opt(words[1]), parse_int_opt(words[2])) {
|
||||
(Some(code), Some(state)) => {
|
||||
let now_ms = @sys.monotonic_ms().to_uint()
|
||||
self.handle_remote_input(
|
||||
@nested.InputEvent::Key(code, state != 0),
|
||||
now_ms,
|
||||
)
|
||||
(["ok"], true)
|
||||
}
|
||||
_ => (["error invalid key args"], false)
|
||||
}
|
||||
}
|
||||
"input-key-tap" => {
|
||||
if words.length() < 2 || words.length() > 3 {
|
||||
return (["error usage: input-key-tap CODE [MODS]"], false)
|
||||
}
|
||||
let mods = if words.length() == 3 {
|
||||
match parse_uint_opt(words[2]) {
|
||||
Some(m) => m
|
||||
None => return (["error invalid mods"], false)
|
||||
}
|
||||
} else {
|
||||
0U
|
||||
}
|
||||
match parse_uint_opt(words[1]) {
|
||||
Some(code) => {
|
||||
let now_ms = @sys.monotonic_ms().to_uint()
|
||||
self.remote_key_tap(code, mods, now_ms)
|
||||
(["ok"], true)
|
||||
}
|
||||
None => (["error invalid key code"], false)
|
||||
}
|
||||
}
|
||||
"input-text" => {
|
||||
if words.length() != 2 {
|
||||
return (["error usage: input-text HEX"], false)
|
||||
}
|
||||
match decode_hex_utf8(words[1]) {
|
||||
Some(text) =>
|
||||
if self.remote_commit_text(text) {
|
||||
(["ok typed"], true)
|
||||
} else {
|
||||
(["ok clipboard"], true)
|
||||
}
|
||||
None => (["error invalid hex"], false)
|
||||
}
|
||||
}
|
||||
"clipboard-set" => {
|
||||
if words.length() != 2 {
|
||||
return (["error usage: clipboard-set HEX"], false)
|
||||
}
|
||||
match decode_hex_utf8(words[1]) {
|
||||
Some(text) => {
|
||||
self.remote_set_clipboard(text)
|
||||
(["ok"], true)
|
||||
}
|
||||
None => (["error invalid hex"], false)
|
||||
}
|
||||
}
|
||||
other => (["error unknown command '" + other + "' (try: help)"], false)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user