Chrome follows the Dark mode switch: Chandra serves the portal's color-scheme
CI / test (push) Failing after 17s
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:
14 files changed
+739
-5
No files matched your search
+130
-4
@@ -223,6 +223,8 @@ pub(all) struct DMessage {
|
||||
meth : String
|
||||
error_name : String
|
||||
dest : String
|
||||
/// The unique name of who sent it (set by the bus on what we receive).
|
||||
sender : String
|
||||
sig : String
|
||||
body : Array[DValue]
|
||||
} derive(Debug)
|
||||
@@ -248,6 +250,7 @@ pub fn DMessage::call(
|
||||
meth,
|
||||
error_name: "",
|
||||
dest,
|
||||
sender: "",
|
||||
sig: sb.to_string(),
|
||||
body: args,
|
||||
}
|
||||
@@ -538,6 +541,7 @@ pub fn decode(data : Array[Byte]) -> DMessage? {
|
||||
let mut error_name = ""
|
||||
let mut reply_serial = 0
|
||||
let mut dest = ""
|
||||
let mut sender = ""
|
||||
let mut sig = ""
|
||||
if fields is Arr(_, items) {
|
||||
for f in items {
|
||||
@@ -550,6 +554,7 @@ pub fn decode(data : Array[Byte]) -> DMessage? {
|
||||
(4, Str(s)) => error_name = s
|
||||
(5, U32(n)) => reply_serial = n.reinterpret_as_int()
|
||||
(6, Str(s)) => dest = s
|
||||
(7, Str(s)) => sender = s
|
||||
(8, Sig(s)) => sig = s
|
||||
_ => ()
|
||||
}
|
||||
@@ -562,7 +567,19 @@ pub fn decode(data : Array[Byte]) -> DMessage? {
|
||||
if r.bad {
|
||||
return None
|
||||
}
|
||||
Some({ mtype, serial, reply_serial, path, iface, meth, error_name, dest, sig, body })
|
||||
Some({
|
||||
mtype,
|
||||
serial,
|
||||
reply_serial,
|
||||
path,
|
||||
iface,
|
||||
meth,
|
||||
error_name,
|
||||
dest,
|
||||
sender,
|
||||
sig,
|
||||
body,
|
||||
})
|
||||
}
|
||||
|
||||
// ---- the connection ----
|
||||
@@ -574,6 +591,41 @@ pub struct DBus {
|
||||
mut serial : Int
|
||||
pending : Map[Int, (DMessage) -> Unit]
|
||||
mut alive : Bool
|
||||
/// Runs (from `pump`) for each method call made to us; it should answer with `reply` or
|
||||
/// `reply_error`. Unset, calls to us are dropped.
|
||||
mut on_call : ((DMessage) -> Unit)?
|
||||
/// Runs (from `pump`) for each signal that reaches us (see AddMatch). Unset, they are dropped.
|
||||
mut on_signal : ((DMessage) -> Unit)?
|
||||
}
|
||||
|
||||
///| The socket path of a unix:path= bus address ("" for anything else, such as unix:abstract=).
|
||||
/// An address may list several, separated by ';': the first unix:path= one is used.
|
||||
pub fn bus_address_path(addr : String) -> String {
|
||||
let pre = "unix:path="
|
||||
for a in addr.split(";") {
|
||||
let a = a.to_string()
|
||||
if a.has_prefix(pre) {
|
||||
let rest = a[pre.length():].to_string()
|
||||
return match rest.find(",") {
|
||||
Some(i) => rest[:i].to_string()
|
||||
None => rest
|
||||
}
|
||||
}
|
||||
}
|
||||
""
|
||||
}
|
||||
|
||||
///| The session bus socket: $DBUS_SESSION_BUS_ADDRESS when it is a unix:path= address, else
|
||||
/// $XDG_RUNTIME_DIR/bus (systemd's per-user bus), else "".
|
||||
pub fn session_bus_path() -> String {
|
||||
let p = bus_address_path(@sys.getenv("DBUS_SESSION_BUS_ADDRESS"))
|
||||
if p != "" {
|
||||
return p
|
||||
}
|
||||
match @sys.getenv("XDG_RUNTIME_DIR") {
|
||||
"" => ""
|
||||
rt => rt + "/bus"
|
||||
}
|
||||
}
|
||||
|
||||
///| The system bus socket: $DBUS_SYSTEM_BUS_ADDRESS when it is a unix:path= address, else the
|
||||
@@ -693,7 +745,7 @@ pub fn DBus::open(path : String) -> DBus? {
|
||||
if !ok || !send_text(fd, "BEGIN\r\n") {
|
||||
return fail()
|
||||
}
|
||||
let bus = { fd, inbuf, serial: 0, pending: {}, alive: true }
|
||||
let bus = { fd, inbuf, serial: 0, pending: {}, alive: true, on_call: None, on_signal: None }
|
||||
let hello = bus.call_sync(
|
||||
DMessage::call(
|
||||
"org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "Hello", [],
|
||||
@@ -737,8 +789,8 @@ pub fn DBus::call(self : DBus, m : DMessage, on_reply? : (DMessage) -> Unit) ->
|
||||
s
|
||||
}
|
||||
|
||||
///| Read whatever has arrived (waiting up to `timeout_ms`) and run reply handlers. Signals and
|
||||
/// calls to us are dropped.
|
||||
///| Read whatever has arrived (waiting up to `timeout_ms`) and run reply handlers, `on_call` for
|
||||
/// calls to us and `on_signal` for signals.
|
||||
pub fn DBus::pump(self : DBus, timeout_ms? : Int = 0) -> Unit {
|
||||
if !self.alive {
|
||||
return
|
||||
@@ -785,6 +837,16 @@ fn DBus::dispatch(self : DBus) -> Unit {
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
Some(m) if m.mtype == method_call =>
|
||||
match self.on_call {
|
||||
Some(f) => f(m)
|
||||
None => ()
|
||||
}
|
||||
Some(m) if m.mtype == signal_msg =>
|
||||
match self.on_signal {
|
||||
Some(f) => f(m)
|
||||
None => ()
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
@@ -816,3 +878,67 @@ pub fn DMessage::error_text(self : DMessage) -> String {
|
||||
_ => self.error_name
|
||||
}
|
||||
}
|
||||
|
||||
///| The socket, for waiting until something arrives (-1 once closed).
|
||||
pub fn DBus::fd(self : DBus) -> Int {
|
||||
if self.alive {
|
||||
self.fd
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
}
|
||||
|
||||
///| Send `m` without waiting for anything back (replies, signals).
|
||||
fn DBus::send(self : DBus, m : DMessage) -> Bool {
|
||||
if !self.alive {
|
||||
return false
|
||||
}
|
||||
self.serial = self.serial + 1
|
||||
let b = m.encode(self.serial)
|
||||
if @sys.sendmsg_fd(self.fd, b, -1) != b.length() {
|
||||
self.close()
|
||||
return false
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
///| Answer the method call `call` with `args`.
|
||||
pub fn DBus::reply(self : DBus, call : DMessage, args : Array[DValue]) -> Unit {
|
||||
let m = DMessage::call(call.sender, "", "", "", args)
|
||||
ignore(self.send({ ..m, mtype: method_return, reply_serial: call.serial }))
|
||||
}
|
||||
|
||||
///| Answer the method call `call` with the error `name` (say
|
||||
/// "org.freedesktop.DBus.Error.UnknownMethod") and message `text`.
|
||||
pub fn DBus::reply_error(
|
||||
self : DBus,
|
||||
call : DMessage,
|
||||
name : String,
|
||||
text : String,
|
||||
) -> Unit {
|
||||
let m = DMessage::call(call.sender, "", "", "", [Str(text)])
|
||||
ignore(
|
||||
self.send({ ..m, mtype: error_reply, reply_serial: call.serial, error_name: name }),
|
||||
)
|
||||
}
|
||||
|
||||
///| Broadcast the signal `iface`.`member` from object `path`.
|
||||
pub fn DBus::emit(
|
||||
self : DBus,
|
||||
path : String,
|
||||
iface : String,
|
||||
member : String,
|
||||
args : Array[DValue],
|
||||
) -> Unit {
|
||||
ignore(self.send({ ..DMessage::call("", path, iface, member, args), mtype: signal_msg }))
|
||||
}
|
||||
|
||||
///| Answer method calls to us with `f` (see `on_call`).
|
||||
pub fn DBus::set_on_call(self : DBus, f : (DMessage) -> Unit) -> Unit {
|
||||
self.on_call = Some(f)
|
||||
}
|
||||
|
||||
///| Run `f` for each signal that reaches us (subscribe with the bus's AddMatch).
|
||||
pub fn DBus::set_on_signal(self : DBus, f : (DMessage) -> Unit) -> Unit {
|
||||
self.on_signal = Some(f)
|
||||
}
|
||||
Reference in new issue
Block a user