--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,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user