1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! Dynamic CSS management for Libadwaita applications.
//!
//! This module allows you to load custom CSS at runtime and
//! ensures that styles are correctly reapplied even when switching between light and
//! dark mode.
/**
* load_adw_provider.rs
*
* (C) Copyright 2026 AtlantisOS Project
* by @NachtsternBuild
*
* License: GNU GENERAL PUBLIC LICENSE Version 3
*/
use StyleManager;
use ;
use RefCell;
thread_local!
/// Loads CSS data from a string into the active provider.
///
/// This function is used internally to initially load the CSS content
/// or to update it when the theme changes.
/// Initializes and activates a global CSS provider for Libadwaita/GTK4.
///
/// This function registers a `CssProvider` for the default display and
/// ensures that custom styles take precedence over the
/// default system styles (`STYLE_PROVIDER_PRIORITY_USER`).
///
/// # Special Features
/// - **Reactivity:** Registers a listener on `adw::StyleManager` to reload the CSS when
/// the `dark-notify` property changes. This is important
/// because some CSS variables only respond correctly to theme changes after a reload.
/// - **Thread Safety:** Uses `thread_local!` to safely manage the provider within the context
/// of the GTK main loop.
///
/// # Arguments
/// * `css_content` - A string slice containing the CSS rules.
///
/// # Usage:
///
/// ```rust
/// pub const ADW_CUSTOM_CSS: &str = r#"
/// window {
/// background-color: @theme_bg_color;
/// color: @theme_fg_color;
/// padding: 12px;
/// font-size: 14px;
/// border: 2px solid @theme_bg_color;
/// border-radius: 35px;
/// }"#;
/// use_adw_provider(ADW_CUSTOM_CSS);
/// ```