--x11 shows the desktop on the X server in $DISPLAY: a resizable window under a window manager (--fullscreen asks it for fullscreen), or the whole screen when no window manager runs, following xrandr resizes. compositor/x11 is a pure X11 wire-protocol client (no libX11/xcb), so it runs in the wasm compositor on both hosts and in the native build. Frames go through MIT-SHM 1.2 (ShmAttachFd of the host frame memfd, paced by ShmCompletion), with a core PutImage fallback. The keymap given to clients is the X server's own (xkbcomp -xkb $DISPLAY -); X auto-repeat is dropped, modifier/lock state comes from X's modifier map; MIT-MAGIC-COOKIE-1 auth. chandra-session --x11 (and the new "Chandra (X11)" xsessions entry) runs it as the login session; --login-session gives an X11 session what --drm implied (power actions, polkit agent, system theme). just run-x11. Docs: docs/x11.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hhLFs4VtHV26G1iyeo
This commit is contained in:
14 files changed
+1777
-19
No files matched your search
+92
-6
@@ -2,7 +2,11 @@
|
||||
/// operating system reached only through `@sys`. The wasm component (components/compositor)
|
||||
/// calls `run`; on the native side it is the same code with `@sys` backed by a C shim.
|
||||
///
|
||||
/// Arguments: --socket PATH --theme PATH --window --drm --gfx-out PNG --serve --size WxH
|
||||
/// Arguments: --socket PATH --theme PATH --window --drm --x11 --fullscreen --gfx-out PNG --serve
|
||||
/// --size WxH. --x11 shows the desktop on the X server in $DISPLAY (a window, or the whole screen
|
||||
/// when no window manager runs there); --fullscreen asks a window manager for a fullscreen window;
|
||||
/// --login-session makes it the user's desktop session as --drm does (power actions, the polkit
|
||||
/// agent, apps' dark/light preference), for chandra-session --x11.
|
||||
/// --drm runs as a login session: the host takes the display (DRM/KMS) and input (libinput).
|
||||
/// With --gfx-out alone one frame is written and the program exits; add --serve to keep running
|
||||
/// and rewrite the PNG about twice a second (for looking at a live compositor without a display).
|
||||
@@ -49,6 +53,9 @@ pub fn run(args : Array[String]) -> Int {
|
||||
let mut serve = false
|
||||
let mut profile = false
|
||||
let mut drm = false
|
||||
let mut x11 = false
|
||||
let mut fullscreen = false
|
||||
let mut login = false
|
||||
let mut restore = true
|
||||
let mut width = 1280
|
||||
let mut height = 720
|
||||
@@ -68,6 +75,15 @@ pub fn run(args : Array[String]) -> Int {
|
||||
} else if a == "--drm" {
|
||||
drm = true
|
||||
i = i + 1
|
||||
} else if a == "--x11" {
|
||||
x11 = true // a window (or, with no window manager, the whole screen) on $DISPLAY
|
||||
i = i + 1
|
||||
} else if a == "--login-session" {
|
||||
login = true // this is the user's desktop session (as --drm is): power, polkit, system theme
|
||||
i = i + 1
|
||||
} else if a == "--fullscreen" {
|
||||
fullscreen = true // --x11 under a window manager: ask it for a fullscreen window
|
||||
i = i + 1
|
||||
} else if a == "--no-restore" {
|
||||
restore = false // don't reopen the apps of the last session
|
||||
i = i + 1
|
||||
@@ -125,6 +141,28 @@ pub fn run(args : Array[String]) -> Int {
|
||||
None
|
||||
}
|
||||
|
||||
// X11 mode: a window on an X server (NVIDIA's Xorg driver has no usable KMS path for us), or
|
||||
// the whole screen when no window manager runs there. Opened first so the desktop gets its size.
|
||||
let xwin = if x11 && !drm {
|
||||
let display = match @sys.getenv("DISPLAY") {
|
||||
"" => ":0"
|
||||
d => d
|
||||
}
|
||||
match @x11.X11Window::open(display, "Chandra", "chandra", width, height, fullscreen) {
|
||||
Some(x) => {
|
||||
width = x.width
|
||||
height = x.height
|
||||
Some(x)
|
||||
}
|
||||
None => {
|
||||
@sys.log("failed to open a window on the X display " + display)
|
||||
return 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
let gfx_surface = @gfx.Surface::new({ width: Some(width), height: Some(height) })
|
||||
|
||||
match @host.ChandraCompositor::new(socket_path, theme, width, height) {
|
||||
@@ -138,8 +176,9 @@ pub fn run(args : Array[String]) -> Int {
|
||||
}
|
||||
Some(comp) => {
|
||||
comp.shell.persist = true // remember which modules are loaded in the panel
|
||||
comp.sync_system_theme = drm // the login session sets apps' dark/light preference
|
||||
comp.login_session = drm // and power actions (suspend, power off) act on the machine
|
||||
let login = drm || login
|
||||
comp.sync_system_theme = login // the login session sets apps' dark/light preference
|
||||
comp.login_session = login // and power actions (suspend, power off) act on the machine
|
||||
comp.restore_state() // and the layout mode and recent apps from the last session
|
||||
comp.shell.screen_w = width
|
||||
// Screenshots and recordings read the host's framebuffer (it draws the desktop).
|
||||
@@ -192,7 +231,7 @@ pub fn run(args : Array[String]) -> Int {
|
||||
@sys.log("chandra compositor listening on " + socket_path)
|
||||
// chandra-ctl's socket (reload panel modules from a script); SIGUSR1 reloads too.
|
||||
ignore(comp.start_control(@host.control_socket_path(@sys.getenv("XDG_RUNTIME_DIR"), socket_path)))
|
||||
if drm {
|
||||
if login {
|
||||
comp.start_auth_agent() // polkit's password prompts (run0, pkexec): Chandra's dialog
|
||||
}
|
||||
if restore {
|
||||
@@ -339,7 +378,53 @@ pub fn run(args : Array[String]) -> Int {
|
||||
busy = busy || input.length() > 0 || need_present
|
||||
wait_fds.push(n.fd)
|
||||
}
|
||||
None => {
|
||||
None =>
|
||||
match xwin {
|
||||
Some(x) => {
|
||||
if !x.poll() {
|
||||
break
|
||||
}
|
||||
if x.keymap.length() > 0 {
|
||||
comp.server.set_keymap(x.keymap)
|
||||
}
|
||||
// The window or the screen (xrandr) changed size: draw the desktop at the new size.
|
||||
match x.take_resize() {
|
||||
Some((nw, nh)) => {
|
||||
width = nw
|
||||
height = nh
|
||||
comp.resize(nw, nh)
|
||||
need_present = true
|
||||
busy = true
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
if x.take_redraw() {
|
||||
need_present = true // exposed: the X server has no copy of what was there
|
||||
}
|
||||
let now_ms = @sys.monotonic_ms().to_uint()
|
||||
let input = x.take_input()
|
||||
for ev in input {
|
||||
comp.handle_input(ev, now_ms)
|
||||
}
|
||||
x.set_cursor_shape(comp.desired_cursor())
|
||||
match comp.compose_scene() {
|
||||
Some(sg) => {
|
||||
let r0 = @sys.monotonic_ms()
|
||||
@raster.submit(sg)
|
||||
comp.prof_raster_ms = comp.prof_raster_ms + (@sys.monotonic_ms() - r0)
|
||||
need_present = true
|
||||
busy = true
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
if need_present && x.frame_ready() {
|
||||
x.present_frame(width, height)
|
||||
need_present = false
|
||||
}
|
||||
busy = busy || input.length() > 0 || need_present
|
||||
wait_fds.append(x.wait_fds())
|
||||
}
|
||||
None => {
|
||||
comp.handle_gfx_events(gfx_surface)
|
||||
match comp.compose_scene() {
|
||||
Some(sg) => {
|
||||
@@ -357,7 +442,8 @@ pub fn run(args : Array[String]) -> Int {
|
||||
need_present = false
|
||||
}
|
||||
busy = busy || need_present
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if profile {
|
||||
p_n = p_n + 1
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
"chandra/desktop/compositor/gfx" @gfx,
|
||||
"chandra/desktop/compositor/host" @host,
|
||||
"chandra/desktop/compositor/nested" @nested,
|
||||
"chandra/desktop/compositor/x11" @x11,
|
||||
"chandra/desktop/compositor/kms" @kms,
|
||||
"chandra/desktop/compositor/raster" @raster,
|
||||
}
|
||||
|
||||
+57
-4
@@ -9,6 +9,8 @@ fn main {
|
||||
let widgets : Array[String] = []
|
||||
let mut windowed = false
|
||||
let mut drm = false
|
||||
let mut x11 = false
|
||||
let mut fullscreen = false
|
||||
let mut restore = true
|
||||
let mut width = 1280
|
||||
let mut height = 720
|
||||
@@ -28,6 +30,12 @@ fn main {
|
||||
} else if a == "--drm" {
|
||||
drm = true
|
||||
i = i + 1
|
||||
} else if a == "--x11" {
|
||||
x11 = true
|
||||
i = i + 1
|
||||
} else if a == "--fullscreen" {
|
||||
fullscreen = true
|
||||
i = i + 1
|
||||
} else if a == "--no-restore" {
|
||||
restore = false // don't reopen the apps of the last session
|
||||
i = i + 1
|
||||
@@ -71,6 +79,27 @@ fn main {
|
||||
None
|
||||
}
|
||||
|
||||
// X11 mode: a window (or the whole screen, without a window manager) on $DISPLAY.
|
||||
let xwin = if x11 && !drm {
|
||||
let display = match @env.get_env_var("DISPLAY") {
|
||||
Some(d) => d
|
||||
None => ":0"
|
||||
}
|
||||
match @x11.X11Window::open(display, "Chandra", "chandra", width, height, fullscreen) {
|
||||
Some(x) => {
|
||||
width = x.width
|
||||
height = x.height
|
||||
Some(x)
|
||||
}
|
||||
None => {
|
||||
println("failed to open a window on the X display " + display)
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
let gfx_surface = @gfx.Surface::new({
|
||||
width: Some(width),
|
||||
height: Some(height),
|
||||
@@ -175,10 +204,34 @@ fn main {
|
||||
n.present(comp.present_to_gfx(gfx_ctx))
|
||||
}
|
||||
}
|
||||
None => {
|
||||
comp.handle_gfx_events(gfx_surface)
|
||||
ignore(comp.present_to_gfx(gfx_ctx))
|
||||
}
|
||||
None =>
|
||||
match xwin {
|
||||
Some(x) => {
|
||||
if !x.poll() {
|
||||
break
|
||||
}
|
||||
if x.keymap.length() > 0 {
|
||||
comp.server.set_keymap(x.keymap)
|
||||
}
|
||||
match x.take_resize() {
|
||||
Some((nw, nh)) => comp.resize(nw, nh)
|
||||
None => ()
|
||||
}
|
||||
ignore(x.take_redraw()) // every frame is presented here anyway
|
||||
let now_ms = @env.now().to_uint()
|
||||
for ev in x.take_input() {
|
||||
comp.handle_input(ev, now_ms)
|
||||
}
|
||||
x.set_cursor_shape(comp.desired_cursor())
|
||||
if x.frame_ready() {
|
||||
x.present(comp.present_to_gfx(gfx_ctx))
|
||||
}
|
||||
}
|
||||
None => {
|
||||
comp.handle_gfx_events(gfx_surface)
|
||||
ignore(comp.present_to_gfx(gfx_ctx))
|
||||
}
|
||||
}
|
||||
}
|
||||
@sys.sleep_ms(16)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
"chandra/desktop/compositor/gfx" @gfx,
|
||||
"chandra/desktop/compositor/host" @host,
|
||||
"chandra/desktop/compositor/nested" @nested,
|
||||
"chandra/desktop/compositor/x11" @x11,
|
||||
"chandra/desktop/compositor/kms" @kms,
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import {
|
||||
"moonbitlang/core/builtin",
|
||||
"chandra/desktop/compositor/sys" @sys,
|
||||
"chandra/desktop/compositor/renderer" @renderer,
|
||||
"chandra/desktop/compositor/nested" @nested,
|
||||
}
|
||||
|
||||
supported_targets = "+native+wasm"
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,54 @@
|
||||
///|
|
||||
test "parse_display: local displays only" {
|
||||
assert_eq(@x11.parse_display(":0"), Some((0, 0)))
|
||||
assert_eq(@x11.parse_display(":1.2"), Some((1, 2)))
|
||||
assert_eq(@x11.parse_display("unix:10"), Some((10, 0)))
|
||||
assert_eq(@x11.parse_display("localhost:10.0"), None)
|
||||
assert_eq(@x11.parse_display(""), None)
|
||||
assert_eq(@x11.parse_display(":"), None)
|
||||
}
|
||||
|
||||
///| One Xauthority entry: family, address, display number, auth name, data (big-endian lengths).
|
||||
fn xauth_entry(family : Int, addr : String, num : String, data : Array[Byte]) -> Array[Byte] {
|
||||
let out : Array[Byte] = []
|
||||
fn field(b : Array[Byte]) -> Unit {
|
||||
out.push(((b.length() >> 8) & 0xFF).to_byte())
|
||||
out.push((b.length() & 0xFF).to_byte())
|
||||
for c in b {
|
||||
out.push(c)
|
||||
}
|
||||
}
|
||||
|
||||
fn text(s : String) -> Array[Byte] {
|
||||
let b : Array[Byte] = []
|
||||
for c in s {
|
||||
b.push(c.to_int().to_byte())
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
out.push(((family >> 8) & 0xFF).to_byte())
|
||||
out.push((family & 0xFF).to_byte())
|
||||
field(text(addr))
|
||||
field(text(num))
|
||||
field(text("MIT-MAGIC-COOKIE-1"))
|
||||
field(data)
|
||||
out
|
||||
}
|
||||
|
||||
///|
|
||||
test "xauth_cookie: picks this host's entry for the display" {
|
||||
let file : Array[Byte] = []
|
||||
file.append(xauth_entry(256, "otherhost", "0", [b'\x01']))
|
||||
file.append(xauth_entry(256, "rig", "1", [b'\x02']))
|
||||
file.append(xauth_entry(256, "rig", "0", [b'\x03', b'\x04']))
|
||||
let f = Bytes::from_array(file)
|
||||
assert_eq(@x11.xauth_cookie(f, 0, "rig").to_array(), [b'\x03', b'\x04'])
|
||||
assert_eq(@x11.xauth_cookie(f, 1, "rig").to_array(), [b'\x02'])
|
||||
// No entry for this host: any local one for the display.
|
||||
assert_eq(@x11.xauth_cookie(f, 0, "elsewhere").to_array(), [b'\x01'])
|
||||
assert_eq(@x11.xauth_cookie(f, 7, "rig").length(), 0)
|
||||
// FamilyWild (xauth's "ffff" entries, as Docker setups write) matches any host.
|
||||
let wild = Bytes::from_array(xauth_entry(0xFFFF, "", "0", [b'\x09']))
|
||||
assert_eq(@x11.xauth_cookie(wild, 0, "rig").to_array(), [b'\x09'])
|
||||
}
|
||||
Reference in new issue
Block a user