Add display rotation: Rot pill, chandra-ctl rotate, sensor auto-rotate
CI / test (push) Failing after 51s

- Rotate the display 0/90/180/270 degrees in the KMS host, with scanout and libinput touch/pointer coordinates transformed to match
- Add a touch "Rot" pill beside "KB": tap turns 90 CW, long-press or right-click flips 180
- Add `chandra-ctl rotate [cw|ccw|flip|0|90|180|270|status]`; CHANDRA_ROTATE sets the initial orientation
- Add session/chandra-auto-rotate, which follows iio-sensor-proxy orientation (disable with CHANDRA_AUTO_ROTATE=0)
- Advertise window_menu, maximize, fullscreen and minimize via xdg_toplevel.wm_capabilities (xdg_wm_base v5+)
- Add docs/handset.md covering handset touch, scaling, OSK and rotation
This commit is contained in:
nandi committed 2026-11-28 00:39:24 -08:00
1 parent 905dab8725
commit 2e00009c79
21 files changed
+669 -63

No files matched your search

+72
View File
@@ -326,6 +326,9 @@ pub(all) struct ChandraCompositor {
mut osk_pressed : Int?
mut osk_hover : Int?
mut osk_pointer_grab : Bool
/// Output rotation (`0=0`, `1=90 CW`, `2=180 flip`, `3=270 CW`) and pending backend switch.
mut rotation : Int
mut pending_rotation : Int?
}
///|
@@ -475,6 +478,8 @@ pub fn ChandraCompositor::new(
osk_pressed: None,
osk_hover: None,
osk_pointer_grab: false,
rotation: initial_rotation_from_env(),
pending_rotation: None,
}
// Client popups (menus) are placed to stay on screen: the server asks for the output's
// rectangle relative to the parent's content origin when it applies constraint adjustment.
@@ -524,6 +529,72 @@ fn ChandraCompositor::recompute_work_area(self : ChandraCompositor) -> Unit {
self.damage.mark_full()
}
///| Initial display rotation parsed from `CHANDRA_ROTATE` (`0|90|180|270` or `0..3`).
fn initial_rotation_from_env() -> Int {
match @sys.getenv("CHANDRA_ROTATE") {
"90" | "1" => 1
"180" | "2" => 2
"270" | "3" => 3
_ => 0
}
}
///| Queue a display rotation (`0=0`, `1=90 CW`, `2=180 flip`, `3=270 CW`). Applied by the
/// DRM/KMS host loop on the next iteration.
pub fn ChandraCompositor::request_rotation(self : ChandraCompositor, rot : Int) -> Unit {
let r = (rot % 4 + 4) % 4
self.pending_rotation = Some(r)
self.damage.mark_full()
}
///| Rotate the display 90 degrees clockwise.
pub fn ChandraCompositor::rotate_cw(self : ChandraCompositor) -> Unit {
self.request_rotation(self.rotation + 1)
}
///| Rotate the display 90 degrees counter-clockwise.
pub fn ChandraCompositor::rotate_ccw(self : ChandraCompositor) -> Unit {
self.request_rotation(self.rotation + 3)
}
///| Flip the display 180 degrees.
pub fn ChandraCompositor::rotate_flip(self : ChandraCompositor) -> Unit {
self.request_rotation(self.rotation + 2)
}
///| Current output rotation (`0=0`, `1=90`, `2=180`, `3=270`).
pub fn ChandraCompositor::current_rotation(self : ChandraCompositor) -> Int {
self.rotation
}
///| Consume any pending rotation request for the DRM backend.
pub fn ChandraCompositor::take_pending_rotation(self : ChandraCompositor) -> Int? {
match self.pending_rotation {
Some(r) => {
self.pending_rotation = None
self.rotation = r
Some(r)
}
None => None
}
}
///| Apply the new logical `(w, h)` reported by KMS after a rotation; forces a full redraw even
/// when dimensions match (such as a 180-degree flip).
pub fn ChandraCompositor::apply_rotated_size(self : ChandraCompositor, w : Int, h : Int) -> Unit {
if w > 0 && h > 0 && (w != self.output_w || h != self.output_h) {
self.resize(w, h)
}
self.last_frame = None
self.last_sig = None
self.frame_changed = true
self.damage.mark_full()
match self.emoji_ui {
Some(ui) => self.emoji_place(ui)
None => ()
}
}
///| The output changed size (the nested window was resized, maximized or made fullscreen):
/// lay the desktop out for the new size, so nothing is drawn past the edge and cropped away.
pub fn ChandraCompositor::resize(self : ChandraCompositor, w : Int, h : Int) -> Unit {
@@ -963,6 +1034,7 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
/// a pending screenshot, a toast counting down): the main loop keeps its frame pace then instead
/// of sleeping until an fd wakes it.
pub fn ChandraCompositor::has_timed_work(self : ChandraCompositor) -> Bool {
self.pending_rotation is Some(_) ||
self.rec is Some(_) ||
self.shot_request is Some(_) ||
self.rec_request is Some(_) ||
+39
View File
@@ -213,6 +213,7 @@ pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : Strin
"launch ID start desktop app ID (e.g. org.kde.kwi) as the dock does; a failed start shows its notice",
"windows each window: frame, layout, box, shadow, size limits; and what is under the pointer",
"screenshot [PATH] save a full-screen PNG directly (without opening the editor)",
"rotate [cw|ccw|flip|0|90|180|270|status] rotate or flip the display",
"auth-demo [MODE] show the password dialog with a pretend check (password \"demo\"); MODE: " +
@polkit.demo_modes.join(", "),
"auth-status the password dialog's agent: running, registered, or why not",
@@ -359,6 +360,44 @@ pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : Strin
}
}
}
"rotate" => {
let arg = if words.length() >= 2 { words[1] } else { "cw" }
if words.length() > 2 {
return (["error usage: rotate [cw|ccw|flip|0|90|180|270|status]"], false)
}
match arg {
"status" => (["ok " + (self.rotation * 90).to_string() + " " + self.output_w.to_string() + "x" + self.output_h.to_string()], true)
"cw" | "right" => {
self.rotate_cw()
(["ok rotate cw"], true)
}
"ccw" | "left" => {
self.rotate_ccw()
(["ok rotate ccw"], true)
}
"flip" => {
self.rotate_flip()
(["ok rotate flip"], true)
}
"0" | "normal" => {
self.request_rotation(0)
(["ok rotate 0"], true)
}
"90" | "1" => {
self.request_rotation(1)
(["ok rotate 90"], true)
}
"180" | "2" => {
self.request_rotation(2)
(["ok rotate 180"], true)
}
"270" | "3" => {
self.request_rotation(3)
(["ok rotate 270"], true)
}
_ => (["error usage: rotate [cw|ccw|flip|0|90|180|270|status]"], false)
}
}
other => (["error unknown command '" + other + "' (try: help)"], false)
}
}
+75 -28
View File
@@ -118,6 +118,13 @@ pub fn ChandraCompositor::osk_toggle_rect(self : ChandraCompositor) -> @scene.Re
@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 {
@@ -429,7 +436,7 @@ fn ChandraCompositor::osk_key_at(self : ChandraCompositor, x : Int, y : Int) ->
None
}
///| Whether `(x, y)` hits either the open OSK or its compact reopen pill.
///| Whether `(x, y)` hits either the open OSK or its compact corner pills ("Rot" / "KB").
fn ChandraCompositor::osk_hit_any(self : ChandraCompositor, x : Int, y : Int) -> Bool {
if !self.osk_enabled {
return false
@@ -437,7 +444,8 @@ fn ChandraCompositor::osk_hit_any(self : ChandraCompositor, x : Int, y : Int) ->
if self.osk_visible {
self.osk_rect().contains(x, y)
} else {
!self.kiosk_strict() && self.osk_toggle_rect().contains(x, y)
!self.kiosk_strict() &&
(self.osk_toggle_rect().contains(x, y) || self.osk_rotate_rect().contains(x, y))
}
}
@@ -578,16 +586,31 @@ fn ChandraCompositor::osk_input(
}
return false
}
if !self.kiosk_strict() && self.osk_toggle_rect().contains(xi, yi) {
if self.osk_hover != Some(-1) {
self.osk_hover = Some(-1)
self.damage.mark_full()
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
}
return true
}
if self.osk_hover == Some(-1) {
self.osk_hover = None
self.damage.mark_full()
}
false
}
@@ -606,6 +629,10 @@ fn ChandraCompositor::osk_input(
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) {
self.osk_activate_key(idx, time_ms)
@@ -623,13 +650,30 @@ fn ChandraCompositor::osk_input(
}
return true
}
if !self.osk_visible && !self.kiosk_strict() && self.osk_toggle_rect().contains(xi, yi) {
if button == 272U && pressed {
self.osk_pointer_grab = true
self.osk_pressed = Some(-1)
self.damage.mark_full()
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 => ()
}
return true
}
false
}
@@ -658,18 +702,21 @@ fn ChandraCompositor::osk_ops(self : ChandraCompositor) -> Array[@scene.DrawOp]
if self.kiosk_strict() {
return ops
}
let tr = self.osk_toggle_rect()
let bg = if self.osk_pressed == Some(-1) {
pal.accent
} else if self.osk_hover == Some(-1) {
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 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))
}
let fg = if self.osk_pressed == Some(-1) { 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, "KB", (fs - 2).max(10), fg, @scene.TextAlign::Center, true))
return ops
}
let r = self.osk_rect()
+40
View File
@@ -137,3 +137,43 @@ test "OSK auto-opens on launcher popup, lifts popup above OSK, and types into se
assert_eq(comp.shell.launcher_state.query, "t")
comp.close()
}
///|
test "Rot pill tap rotates CW, right-click flips 180 deg, and rotate control commands update size" {
let comp = osk_comp("rotate")
let rr = comp.osk_rotate_rect()
let rx = rr.x + rr.w / 2
let ry = rr.y + rr.h / 2
// Tap Rot pill -> queues 90 deg CW rotation.
click_at(comp, rx, ry, 10U)
assert_eq(comp.take_pending_rotation(), Some(1))
assert_eq(comp.current_rotation(), 1)
comp.apply_rotated_size(1170, 540)
assert_eq((comp.output_w, comp.output_h), (1170, 540))
// Right-click / long-press Rot pill -> queues 180 deg flip (1 -> 3 = 270 deg).
let rr2 = comp.osk_rotate_rect()
click_at(comp, rr2.x + rr2.w / 2, rr2.y + rr2.h / 2, 20U, btn=273U)
assert_eq(comp.take_pending_rotation(), Some(3))
assert_eq(comp.current_rotation(), 3)
// chandra-ctl rotate 0 / flip / status.
let (out0, ok0) = comp.control_command("rotate 0")
assert_true(ok0)
assert_eq(out0, ["ok rotate 0"])
assert_eq(comp.take_pending_rotation(), Some(0))
comp.apply_rotated_size(540, 1170)
let (out_flip, ok_flip) = comp.control_command("rotate flip")
assert_true(ok_flip)
assert_eq(out_flip, ["ok rotate flip"])
assert_eq(comp.take_pending_rotation(), Some(2))
comp.apply_rotated_size(540, 1170)
assert_true(comp.frame_changed)
let (out_st, ok_st) = comp.control_command("rotate status")
assert_true(ok_st)
assert_eq(out_st, ["ok 180 540x1170"])
comp.close()
}