Add display rotation: Rot pill, chandra-ctl rotate, sensor auto-rotate
CI / test (push) Failing after 51s
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:
1 parent
905dab8725
commit
2e00009c79
21 files changed
+669
-63
No files matched your search
Executable
+163
@@ -0,0 +1,163 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Auto-rotate the Chandra KMS display from iio-sensor-proxy accelerometer events."""
|
||||
|
||||
import argparse
|
||||
import ctypes
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
CHANDRA_CTL = "/usr/local/bin/chandra-ctl"
|
||||
ORIENTATION_TO_DEG = {
|
||||
"normal": 0,
|
||||
"right-up": 90,
|
||||
"bottom-up": 180,
|
||||
"left-up": 270,
|
||||
}
|
||||
PR_SET_PDEATHSIG = 1
|
||||
|
||||
|
||||
def parse_orientation(line: str) -> int | None:
|
||||
"""Return display rotation degrees (0/90/180/270) from a monitor-sensor line."""
|
||||
text = line.strip()
|
||||
if "Accelerometer orientation changed:" in text:
|
||||
tail = text.split("Accelerometer orientation changed:", 1)[1].strip()
|
||||
val = tail.split()[0] if tail else ""
|
||||
return ORIENTATION_TO_DEG.get(val)
|
||||
if "orientation:" in text:
|
||||
part = text.split("orientation:", 1)[1].strip()
|
||||
val = part.split(",", 1)[0].rstrip(")").strip()
|
||||
return ORIENTATION_TO_DEG.get(val)
|
||||
return None
|
||||
|
||||
|
||||
def set_parent_death_signal() -> None:
|
||||
"""Request SIGTERM from the kernel when the parent compositor process exits."""
|
||||
try:
|
||||
libc = ctypes.CDLL("libc.so.6")
|
||||
libc.prctl(PR_SET_PDEATHSIG, signal.SIGTERM, 0, 0, 0)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def parent_alive(pid: int) -> bool:
|
||||
"""Return True while the tracked parent PID still exists."""
|
||||
try:
|
||||
os.kill(pid, 0)
|
||||
return True
|
||||
except ProcessLookupError:
|
||||
return False
|
||||
except PermissionError:
|
||||
return True
|
||||
|
||||
|
||||
def wait_for_compositor(parent_pid: int, timeout_s: float = 15.0) -> bool:
|
||||
"""Poll chandra-ctl ping until the compositor control socket responds or parent exits."""
|
||||
deadline = time.monotonic() + timeout_s
|
||||
while time.monotonic() < deadline:
|
||||
if os.getppid() != parent_pid or not parent_alive(parent_pid):
|
||||
return False
|
||||
res = subprocess.run(
|
||||
[CHANDRA_CTL, "ping"],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
check=False,
|
||||
)
|
||||
if res.returncode == 0:
|
||||
return True
|
||||
time.sleep(0.25)
|
||||
return False
|
||||
|
||||
|
||||
def current_rotation() -> int | None:
|
||||
"""Query current display rotation degrees via chandra-ctl rotate status."""
|
||||
res = subprocess.run(
|
||||
[CHANDRA_CTL, "rotate", "status"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.DEVNULL,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
if res.returncode != 0:
|
||||
return None
|
||||
parts = res.stdout.strip().split()
|
||||
if len(parts) >= 2 and parts[0] == "ok":
|
||||
try:
|
||||
return int(parts[1])
|
||||
except ValueError:
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
def apply_rotation(deg: int) -> bool:
|
||||
"""Apply display rotation in degrees via chandra-ctl rotate."""
|
||||
res = subprocess.run(
|
||||
[CHANDRA_CTL, "rotate", str(deg)],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
check=False,
|
||||
)
|
||||
return res.returncode == 0
|
||||
|
||||
|
||||
def main() -> int:
|
||||
"""Watch monitor-sensor --accel and mirror orientation changes to Chandra."""
|
||||
parser = argparse.ArgumentParser(description="Chandra auto-rotate daemon")
|
||||
parser.add_argument("--parent-pid", type=int, default=os.getppid())
|
||||
args = parser.parse_args()
|
||||
parent_pid = args.parent_pid
|
||||
|
||||
set_parent_death_signal()
|
||||
if os.getppid() != parent_pid:
|
||||
return 0
|
||||
|
||||
if not wait_for_compositor(parent_pid):
|
||||
return 0
|
||||
|
||||
proc = subprocess.Popen(
|
||||
["monitor-sensor", "--accel"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
bufsize=1,
|
||||
)
|
||||
|
||||
def stop_child(_signum: int, _frame: object) -> None:
|
||||
if proc.poll() is None:
|
||||
proc.terminate()
|
||||
raise SystemExit(0)
|
||||
|
||||
signal.signal(signal.SIGTERM, stop_child)
|
||||
signal.signal(signal.SIGINT, stop_child)
|
||||
|
||||
last_rot: int | None = None
|
||||
try:
|
||||
assert proc.stdout is not None
|
||||
for line in proc.stdout:
|
||||
if not parent_alive(parent_pid):
|
||||
break
|
||||
if "No accelerometer" in line or "Failed to claim accelerometer" in line:
|
||||
print(f"chandra-auto-rotate: {line.strip()}", file=sys.stderr, flush=True)
|
||||
break
|
||||
deg = parse_orientation(line)
|
||||
if deg is None or deg == last_rot:
|
||||
continue
|
||||
if last_rot is None and current_rotation() == deg:
|
||||
last_rot = deg
|
||||
continue
|
||||
apply_rotation(deg)
|
||||
last_rot = deg
|
||||
finally:
|
||||
if proc.poll() is None:
|
||||
proc.terminate()
|
||||
try:
|
||||
proc.wait(timeout=2)
|
||||
except subprocess.TimeoutExpired:
|
||||
proc.kill()
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
+2
-1
@@ -10,6 +10,7 @@
|
||||
chandra-ctl launch ID start desktop app ID (org.kde.kwi) as the dock does
|
||||
chandra-ctl windows how Chandra sees each window, and what is under the pointer
|
||||
chandra-ctl screenshot [PATH] save a full-screen PNG directly without opening the editor
|
||||
chandra-ctl rotate [ARG] rotate/flip display (cw, ccw, flip, 0, 90, 180, 270, status)
|
||||
chandra-ctl auth-demo [MODE] show the password dialog with a pretend check (password "demo");
|
||||
MODE: password, face, face-ok, die, slow, users (docs/auth-dialog.md)
|
||||
chandra-ctl auth-status the password dialog's agent: registered with polkit, or why not
|
||||
@@ -25,7 +26,7 @@ import os
|
||||
import socket
|
||||
import sys
|
||||
|
||||
USAGE = "usage: chandra-ctl [--socket PATH] [--quiet] {reload [NAME] | list | ping | shortcut ID | kiosk [lock|unlock|status] | launch ID | windows | screenshot [PATH] | auth-demo [MODE] | auth-status | help}"
|
||||
USAGE = "usage: chandra-ctl [--socket PATH] [--quiet] {reload [NAME] | list | ping | shortcut ID | kiosk [lock|unlock|status] | launch ID | windows | screenshot [PATH] | rotate [ARG] | auth-demo [MODE] | auth-status | help}"
|
||||
|
||||
|
||||
def runtime_dir():
|
||||
|
||||
@@ -241,5 +241,11 @@ for a in \
|
||||
done
|
||||
export CHANDRA_POLKIT_FALLBACK="$fallback"
|
||||
|
||||
if [ "$backend" = --drm ] && [ "${CHANDRA_AUTO_ROTATE:-1}" != "0" ] &&
|
||||
[ -x /usr/local/bin/chandra-auto-rotate ] && command -v monitor-sensor >/dev/null 2>&1; then
|
||||
WAYLAND_DISPLAY="$(basename "$sock")" \
|
||||
/usr/local/bin/chandra-auto-rotate --parent-pid "$$" >>"$log" 2>&1 &
|
||||
fi
|
||||
|
||||
exec "$@" $backend --socket "$sock" \
|
||||
--theme "$share/config/themes/moon-night.json" >>"$log" 2>&1
|
||||
@@ -28,6 +28,7 @@ Installs:
|
||||
starts it (docs/auth-dialog.md)
|
||||
/usr/local/bin/chandra-ctl talk to the running session: `chandra-ctl reload` loads
|
||||
the panel modules again (docs/reloading.md)
|
||||
/usr/local/bin/chandra-auto-rotate DRM session accelerometer watcher (iio-sensor-proxy)
|
||||
/usr/local/bin/chandra-kde-colors Dark mode for KDE/Qt apps: copies a color scheme into
|
||||
kdeglobals (docs/dark-mode.md)
|
||||
/usr/local/share/color-schemes/Chandra{Dark,Light}.colors KDE color schemes, used when Breeze's
|
||||
@@ -64,6 +65,7 @@ targets = [
|
||||
"/usr/local/bin/chandra-root",
|
||||
"/usr/local/lib/chandra/chandra-polkit-agent",
|
||||
"/usr/local/bin/chandra-ctl",
|
||||
"/usr/local/bin/chandra-auto-rotate",
|
||||
"/usr/local/bin/chandra-kde-colors",
|
||||
"/usr/local/share/color-schemes/ChandraDark.colors",
|
||||
"/usr/local/share/color-schemes/ChandraLight.colors",
|
||||
@@ -173,6 +175,7 @@ if linked:
|
||||
else:
|
||||
put(auth_agent, auth_agent_dst, 0o755)
|
||||
install(os.path.join(root, "session/chandra-ctl"), "/usr/local/bin/chandra-ctl")
|
||||
install(os.path.join(root, "session/chandra-auto-rotate"), "/usr/local/bin/chandra-auto-rotate")
|
||||
install(os.path.join(root, "session/chandra-kde-colors"), "/usr/local/bin/chandra-kde-colors")
|
||||
for f in ("ChandraDark.colors", "ChandraLight.colors"):
|
||||
put(os.path.join(root, "session/color-schemes", f), "/usr/local/share/color-schemes/" + f, 0o644)
|
||||
|
||||
Reference in new issue
Block a user