Follow the desktop accent colour and colour scheme (XDG portal) (#3)
CI / check (push) Successful in 9s
CI / native (push) Successful in 1m14s

This commit was merged in pull request #3.
This commit is contained in:
nandi committed 2026-11-23 01:56:20 +00:00
1 parent 02b08cb471
commit 1746884744
16 files changed
+947 -12

No files matched your search

+62
View File
@@ -286,6 +286,68 @@ pub fn load_css(css : String) -> Unit {
ffi_load_css(cstr(css))
}
///|
extern "C" fn ffi_portal_watch(tag : Int32) -> Int32 = "mm_gtk_portal_watch"
///|
extern "C" fn ffi_portal_accent(i : Int32) -> Double = "mm_gtk_portal_accent"
///|
extern "C" fn ffi_portal_color_scheme() -> Int32 = "mm_gtk_portal_color_scheme"
///|
#borrow(css)
extern "C" fn ffi_set_accent_css(css : Bytes) = "mm_gtk_set_accent_css"
///|
extern "C" fn ffi_prefers_dark() -> Int32 = "mm_gtk_prefers_dark"
///|
extern "C" fn ffi_set_color_scheme(scheme : Int32) = "mm_gtk_set_color_scheme"
///|
/// The desktop's appearance settings, from the XDG Desktop Portal.
pub(all) struct Appearance {
/// accent-color as reported (each channel -1 when unset).
accent : (Double, Double, Double)
/// color-scheme: 0 no preference, 1 dark, 2 light.
color_scheme : Int32
}
///|
/// Follow org.freedesktop.appearance (accent-color, color-scheme) through
/// the portal's Settings interface: `f` runs once with the current values
/// and again on every change. Never runs without a portal. False without a
/// session bus.
pub fn watch_appearance(f : (Appearance) -> Unit) -> Bool {
let tag = register(fn(_) {
f({
accent: (ffi_portal_accent(0), ffi_portal_accent(1), ffi_portal_accent(2)),
color_scheme: ffi_portal_color_scheme(),
})
})
ffi_portal_watch(tag) != 0
}
///|
/// Replace the accent stylesheet (APPLICATION priority); "" removes it.
pub fn set_accent_css(css : String) -> Unit {
ffi_set_accent_css(cstr(css))
}
///|
/// Apply a color-scheme preference (0 none: back to the configured theme
/// variant, 1 dark, 2 light).
pub fn set_color_scheme(scheme : Int32) -> Unit {
ffi_set_color_scheme(scheme)
}
///|
/// Whether the theme is in its dark variant.
pub fn prefers_dark() -> Bool {
ffi_prefers_dark() != 0
}
///|
pub fn window(
title : String,