Chrome follows the Dark mode switch: Chandra serves the portal's color-scheme
CI / test (push) Failing after 17s

Chrome (and Firefox, Electron, GTK 4, Qt 6) read dark/light from xdg-desktop-portal's Settings
interface. With XDG_CURRENT_DESKTOP=chandra and no chandra-portals.conf, xdg-desktop-portal found
no Settings backend (gtk/gnome are UseIn=gnome, kde is UseIn=KDE) and exported no Settings
interface at all, so the gsettings color-scheme a790901 sets never reached Chrome.

- compositor/portal: the compositor is an org.freedesktop.impl.portal.Settings backend
  (org.freedesktop.impl.portal.desktop.chandra on the session bus): Read/ReadAll of
  org.freedesktop.appearance color-scheme (1 dark, 2 light), SettingChanged when the switch flips,
  version property, introspection. Login session only; the main loop wakes on its socket.
- compositor/network/dbus.mbt: serve calls (on_call, reply, reply_error), emit and receive
  signals, sender field, session bus address.
- session/chandra.portal + chandra-portals.conf, installed to /usr/share/xdg-desktop-portal by
  install.py: Settings from chandra first, then gtk/kde/gnome; other portals from gtk/kde/gnome.
- chandra-session restarts a running xdg-desktop-portal so it reads the config for this desktop.
- scripts/test-portal-dbus.sh: end to end behind the real xdg-desktop-portal on a private bus
  (ReadOne gives 1, flipping gives SettingChanged 2). docs/dark-mode.md: how to check it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hhkztRQM7vcSuHX4bB
This commit is contained in:
Claude committed 2026-11-25 20:30:30 +00:00
1 parent c7a6c8376e
commit 005e11e7bf
14 files changed
+739 -5

No files matched your search

+9
View File
@@ -44,6 +44,9 @@ pub(all) struct ChandraCompositor {
/// Also set the system-wide dark/light preference for apps (system_theme.mbt). The login
/// session turns it on; nested windows and tests leave it off.
mut sync_system_theme : Bool
/// The xdg-desktop-portal Settings backend apps read the dark/light preference from
/// (compositor/portal), started with the first `sync_system_theme_pref`.
mut settings_portal : @portal.SettingsPortal?
/// Running as the login session (--drm): power actions act on the machine (power.mbt).
mut login_session : Bool
/// Power (power.mbt): when input last came (monotonic ms), whether the screen is off for being
@@ -162,6 +165,7 @@ pub fn ChandraCompositor::new(
theme,
dark_theme: theme,
sync_system_theme: false,
settings_portal: None,
login_session: false,
last_input_ms: @sys.monotonic_ms(),
screen_off: false,
@@ -267,6 +271,10 @@ pub fn ChandraCompositor::close(self : ChandraCompositor) -> Unit {
release_snapshot(win.surface)
}
self.shell.shutdown()
match self.settings_portal {
Some(p) => p.close()
None => ()
}
self.server.close()
}
@@ -367,6 +375,7 @@ fn ChandraCompositor::flush_configures(self : ChandraCompositor) -> Unit {
///|
pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
self.flush_configures()
self.portal_tick()
let events = self.server.poll_events()
for ev in events {
match ev {
+1
View File
@@ -12,6 +12,7 @@ import {
"chandra/desktop/compositor/wayland" @wayland,
"chandra/desktop/compositor/gfx" @gfx,
"chandra/desktop/compositor/network" @network,
"chandra/desktop/compositor/portal" @portal,
}
supported_targets = "+native+wasm"
+26 -1
View File
@@ -73,11 +73,36 @@ pub fn system_theme_command(dark : Bool) -> String {
s
}
///| Tell the system the desktop is dark or light (see above). A no-op unless
///| Tell the system the desktop is dark or light (see above), and apps through our own portal
/// backend (compositor/portal), which xdg-desktop-portal relays to them live. A no-op unless
/// `sync_system_theme` is on.
fn ChandraCompositor::sync_system_theme_pref(self : ChandraCompositor, dark : Bool) -> Unit {
if self.sync_system_theme {
ignore(@sys.spawn(system_theme_command(dark), self.shell.display))
match self.settings_portal {
Some(p) => p.set_dark(dark)
None => {
let p = @portal.SettingsPortal::new(dark)
self.settings_portal = Some(p)
p.tick(@sys.monotonic_ms())
}
}
}
}
///| Serve calls to the portal backend (each main-loop pass).
fn ChandraCompositor::portal_tick(self : ChandraCompositor) -> Unit {
match self.settings_portal {
Some(p) => p.tick(@sys.monotonic_ms())
None => ()
}
}
///| The portal backend's bus socket, for the main loop to wake on (-1 when there is none).
pub fn ChandraCompositor::portal_fd(self : ChandraCompositor) -> Int {
match self.settings_portal {
Some(p) => p.fd()
None => -1
}
}