Settings module: the wallpaper chooser moves in, and a Dark mode switch
CI / test (push) Failing after 16s
CI / test (push) Failing after 16s
- The session settings module becomes the panel's "Settings" button. Its popup lists the session switches, then a "Wallpaper" heading and the wallpapers (current one ticked); a click on a wallpaper shows it at once, as the old chooser did. Up/Down skip the heading. - The standalone wallpaper module and its world are removed. A saved panel.edn that lists "wallpaper" gets the settings module in its place (or just drops it when Settings is there). - New "Dark mode" setting (on by default). Off swaps the compositor to the Moon Day palette (ThemeTokens::moon_day, the values of config/themes/moon-day.json) for the shell, panel modules, window decorations and the switcher; on goes back to the configured theme. Saved in state.edn as :theme :light (absent or :dark: dark) and applied at startup by restore_state. - Tests: the native wallpaper test drives the settings module, the settings test flips Dark mode and checks the theme, the state.edn round trip covers :theme, panel migration unit test, and the host-wasm test covers the switches and the wallpaper rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hgxf6exeYrDGcy4WW3
This commit is contained in:
26 files changed
+295
-878
No files matched your search
@@ -32,7 +32,9 @@ pub(all) struct ChandraCompositor {
|
||||
popups : Array[HostPopup]
|
||||
server : @wayland.WaylandServer
|
||||
wm : @wm.WmState
|
||||
theme : @scene.ThemeTokens
|
||||
/// The theme in use: `dark_theme` (the configured one) or Moon Day, per the Dark mode setting.
|
||||
mut theme : @scene.ThemeTokens
|
||||
dark_theme : @scene.ThemeTokens
|
||||
mut output_w : Int
|
||||
mut output_h : Int
|
||||
mut work_area : @wm.Rect
|
||||
@@ -108,6 +110,7 @@ pub fn ChandraCompositor::new(
|
||||
server,
|
||||
wm,
|
||||
theme,
|
||||
dark_theme: theme,
|
||||
output_w,
|
||||
output_h,
|
||||
work_area,
|
||||
@@ -440,6 +443,7 @@ pub fn ChandraCompositor::set_layout_mode(
|
||||
pub fn ChandraCompositor::restore_state(self : ChandraCompositor) -> Unit {
|
||||
let st = self.shell.load_state()
|
||||
self.shell.apply_state(st)
|
||||
self.apply_theme()
|
||||
match st.layout {
|
||||
Some(0) => self.set_layout_mode(@wm.LayoutMode::Tiling)
|
||||
Some(1) => self.set_layout_mode(@wm.LayoutMode::Monocle)
|
||||
@@ -963,12 +967,22 @@ fn ChandraCompositor::activate_task(self : ChandraCompositor, wid : UInt64) -> U
|
||||
)
|
||||
}
|
||||
|
||||
///| Use the dark (configured) or the light theme, as the shell's Dark mode setting says, for the
|
||||
/// shell, the panel modules, the window decorations and the switcher; redraws everything.
|
||||
pub fn ChandraCompositor::apply_theme(self : ChandraCompositor) -> Unit {
|
||||
let t = if self.shell.dark_mode { self.dark_theme } else { @scene.ThemeTokens::moon_day() }
|
||||
self.theme = t
|
||||
self.shell.set_output(t, self.output_w, self.output_h)
|
||||
self.damage.mark_full()
|
||||
}
|
||||
|
||||
///| Carry out what panel modules asked for: focus a window, switch layout.
|
||||
fn ChandraCompositor::run_shell_actions(self : ChandraCompositor) -> Unit {
|
||||
for a in self.shell.take_actions() {
|
||||
match a {
|
||||
@shell.ShellAction::FocusWindow(wid) => self.activate_task(wid)
|
||||
@shell.ShellAction::Logout => self.quit_requested = true
|
||||
@shell.ShellAction::ThemeChanged => self.apply_theme()
|
||||
@shell.ShellAction::SetLayout(m) =>
|
||||
match m {
|
||||
0 => self.set_layout_mode(@wm.LayoutMode::Tiling)
|
||||
|
||||
@@ -1134,23 +1134,28 @@ fn click_wallpaper_ops(comp : @host.ChandraCompositor, x : Int, y : Int, t : UIn
|
||||
}
|
||||
|
||||
///|
|
||||
test "the wallpaper module lists the wallpapers and switches the desktop to the one clicked" {
|
||||
test "the settings module lists the wallpapers and switches the desktop to the one clicked" {
|
||||
let comp = new_comp("wallpaper")
|
||||
let slot = comp.shell.slot_of("wallpaper")
|
||||
let slot = comp.shell.slot_of("session-settings")
|
||||
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
|
||||
assert_eq(comp.shell.slot_of("wallpaper"), "") // the standalone chooser is gone
|
||||
assert_eq(comp.shell.wallpaper_sel, 0)
|
||||
// A click opens the list; nothing changes yet.
|
||||
click_module(comp, "wallpaper", 1U)
|
||||
// A click opens the list; nothing changes yet. The wallpapers follow the three settings and a
|
||||
// "Wallpaper" heading, so the first is row 4.
|
||||
click_module(comp, "session-settings", 1U)
|
||||
let pr = comp.shell.slot_popup_rect(slot)
|
||||
assert_true(pr.h >= 6 * 2 + 5 * 30) // one row per wallpaper
|
||||
assert_true(pr.h >= 6 * 2 + (4 + 5) * 30) // one row per setting and wallpaper, and the heading
|
||||
assert_eq(comp.shell.wallpaper_sel, 0)
|
||||
// Third row: Starfield. The list stays open and the backdrop is drawn anew.
|
||||
let star = click_wallpaper_ops(comp, pr.x + 40, pr.y + 6 + 2 * 30 + 5, 5U)
|
||||
// The heading does nothing.
|
||||
click_at(comp, pr.x + 40, pr.y + 6 + 3 * 30 + 5, 3U)
|
||||
assert_eq(comp.shell.wallpaper_sel, 0)
|
||||
// Third wallpaper: Starfield. The list stays open and the backdrop is drawn anew.
|
||||
let star = click_wallpaper_ops(comp, pr.x + 40, pr.y + 6 + (4 + 2) * 30 + 5, 5U)
|
||||
assert_eq(comp.shell.wallpaper_sel, 2)
|
||||
assert_true(star > 0)
|
||||
assert_true(comp.shell.slot_popup_rect(slot).w > 0)
|
||||
// Last row: Solid, a single fill. Escape then closes the list.
|
||||
assert_eq(click_wallpaper_ops(comp, pr.x + 40, pr.y + 6 + 4 * 30 + 5, 10U), 1)
|
||||
assert_eq(click_wallpaper_ops(comp, pr.x + 40, pr.y + 6 + (4 + 4) * 30 + 5, 10U), 1)
|
||||
assert_eq(comp.shell.wallpaper_sel, 4)
|
||||
comp.shell.key_down("Escape")
|
||||
ignore(comp.compose_frame())
|
||||
@@ -1255,7 +1260,7 @@ test "the open windows are saved as the session and a restored app's window gets
|
||||
}
|
||||
|
||||
///|
|
||||
test "the session settings module flips the session settings from its popup" {
|
||||
test "the settings module flips the session settings from its popup" {
|
||||
let comp = new_comp("sessset")
|
||||
let slot = comp.shell.slot_of("session-settings")
|
||||
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
|
||||
@@ -1264,7 +1269,7 @@ test "the session settings module flips the session settings from its popup" {
|
||||
// A click opens the list of switches; nothing changes yet.
|
||||
click_module(comp, "session-settings", 1U)
|
||||
let pr = comp.shell.slot_popup_rect(slot)
|
||||
assert_true(pr.h >= 6 * 2 + 2 * 32) // one row per setting
|
||||
assert_true(pr.h >= 6 * 2 + 3 * 30) // one row per setting
|
||||
assert_true(comp.shell.restore_session)
|
||||
// First row: "Reopen windows at login" goes off, and on again with a second click.
|
||||
click_at(comp, pr.x + 40, pr.y + 6 + 5, 5U)
|
||||
@@ -1274,12 +1279,22 @@ test "the session settings module flips the session settings from its popup" {
|
||||
click_at(comp, pr.x + 40, pr.y + 6 + 5, 10U)
|
||||
assert_true(comp.shell.restore_session)
|
||||
// Second row: "Remember window positions"; then Down and Enter flip it back from the keyboard.
|
||||
click_at(comp, pr.x + 40, pr.y + 6 + 32 + 5, 15U)
|
||||
click_at(comp, pr.x + 40, pr.y + 6 + 30 + 5, 15U)
|
||||
assert_false(comp.shell.remember_windows)
|
||||
comp.shell.key_down("Enter")
|
||||
ignore(comp.compose_frame())
|
||||
assert_true(comp.shell.remember_windows)
|
||||
assert_true(comp.shell.restore_session)
|
||||
// Third row: Dark mode. Off switches the shell, panel and decorations to the light theme.
|
||||
assert_eq(comp.theme.name, "Moon Night")
|
||||
click_at(comp, pr.x + 40, pr.y + 6 + 2 * 30 + 5, 20U)
|
||||
assert_false(comp.shell.dark_mode)
|
||||
assert_eq(comp.theme.name, "Moon Day")
|
||||
assert_eq(comp.shell.tokens.name, "Moon Day")
|
||||
comp.shell.key_down("Enter") // the highlight stayed on Dark mode
|
||||
ignore(comp.compose_frame())
|
||||
assert_true(comp.shell.dark_mode)
|
||||
assert_eq(comp.theme.name, "Moon Night")
|
||||
comp.shell.key_down("Escape")
|
||||
ignore(comp.compose_frame())
|
||||
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
|
||||
@@ -1323,5 +1338,16 @@ test "session settings are saved to state.edn and restored, and take effect" {
|
||||
assert_false(text2.contains(":remember-windows"))
|
||||
assert_eq(b.shell.load_session().length(), 1)
|
||||
assert_eq(b.shell.saved_window("foot"), Some((10, 20, 300, 200)))
|
||||
// Dark mode off is saved as :theme :light and the next start comes up light.
|
||||
b.shell.set_session_setting(2, false)
|
||||
assert_true(read_state_edn().contains(":theme :light"))
|
||||
let c = new_comp("sess-c")
|
||||
c.shell.persist = true
|
||||
assert_eq(c.theme.name, "Moon Night")
|
||||
c.restore_state()
|
||||
assert_false(c.shell.dark_mode)
|
||||
assert_eq(c.theme.name, "Moon Day")
|
||||
c.shell.set_session_setting(2, true)
|
||||
assert_false(read_state_edn().contains(":theme"))
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,30 @@ pub fn ThemeTokens::moon_night() -> ThemeTokens {
|
||||
}
|
||||
}
|
||||
|
||||
///| The light counterpart of `moon_night` (config/themes/moon-day.json): what the settings
|
||||
/// module's "Dark mode" switch turns to when off.
|
||||
pub fn ThemeTokens::moon_day() -> ThemeTokens {
|
||||
{
|
||||
name: "Moon Day",
|
||||
palette: {
|
||||
desktop_top: Rgba::from_hex("#cfe3ff"),
|
||||
desktop_bottom: Rgba::from_hex("#8fb4e8"),
|
||||
surface: Rgba::from_hex("#f4f6fbf2"),
|
||||
surface_hover: Rgba::from_hex("#dde3f0"),
|
||||
surface_popup: Rgba::from_hex("#fbfcfff5"),
|
||||
foreground: Rgba::from_hex("#1b2233"),
|
||||
foreground_muted: Rgba::from_hex("#5b6577"),
|
||||
accent: Rgba::from_hex("#3b6bff"),
|
||||
accent_foreground: Rgba::from_hex("#ffffff"),
|
||||
border: Rgba::from_hex("#b9c3d6"),
|
||||
},
|
||||
font_size: 14,
|
||||
radius: 6,
|
||||
spacing: 6,
|
||||
panel_height: 44,
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn json_str(obj : Map[String, Json], key : String, fallback : String) -> String {
|
||||
match obj.get(key) {
|
||||
|
||||
@@ -139,6 +139,8 @@ pub(all) enum ShellAction {
|
||||
FocusWindow(UInt64)
|
||||
/// A module (the logout button) asked to end the session.
|
||||
Logout
|
||||
/// The Dark mode setting changed: the compositor swaps the theme (see `dark_mode`).
|
||||
ThemeChanged
|
||||
} derive(Eq, Debug)
|
||||
|
||||
///| One wasm module loaded into the panel.
|
||||
@@ -206,6 +208,8 @@ pub(all) struct DesktopShell {
|
||||
/// last session's windows at the next start, and remember where floating windows were left.
|
||||
mut restore_session : Bool
|
||||
mut remember_windows : Bool
|
||||
/// Dark mode (the configured theme) or light (Moon Day); saved as `:theme :light` when off.
|
||||
mut dark_mode : Bool
|
||||
mut desk_set : Bool
|
||||
mut desk_x : Int
|
||||
mut desk_y : Int
|
||||
@@ -292,6 +296,7 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
|
||||
wallpaper_sel: 0,
|
||||
restore_session: true,
|
||||
remember_windows: true,
|
||||
dark_mode: true,
|
||||
desk_set: false,
|
||||
desk_x: 0,
|
||||
desk_y: 0,
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
/// :recent ["foot" "dolphin"] ; the launcher's recently started apps, newest first
|
||||
/// :windows {"foot" {:x 80 :y 60 :w 640 :h 480}} ; floating windows' last place, by app id
|
||||
/// :desktop-card {:x 900 :y 24} ; where the desktop card was dragged to (absent: default spot)
|
||||
/// :wallpaper :aurora ; the wallpaper module's choice (absent: :plasma-glow)
|
||||
/// :wallpaper :aurora ; the settings module's wallpaper (absent: :plasma-glow)
|
||||
/// :theme :light ; the settings module's Dark mode switch is off (absent: dark)
|
||||
/// :session [{:app "foot"} {:app "org.gnome.Nautilus" :minimized true}]
|
||||
/// ; the windows open when the last session ended, reopened at
|
||||
/// ; the next start (see session.mbt in compositor/host)
|
||||
@@ -31,6 +32,8 @@ pub(all) struct SavedState {
|
||||
/// Session settings; None when the file doesn't say (both default to on).
|
||||
restore_session : Bool?
|
||||
remember_windows : Bool?
|
||||
/// From `:theme`: true for :dark, false for :light.
|
||||
dark_mode : Bool?
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -44,6 +47,7 @@ let layout_names : Array[String] = ["tiling", "monocle", "floating"]
|
||||
///| The keys this build owns; everything else in the file is kept as it is.
|
||||
let owned_keys : Array[String] = [
|
||||
"layout", "recent", "desktop-card", "windows", "wallpaper", "restore-session", "remember-windows",
|
||||
"theme",
|
||||
]
|
||||
|
||||
///| How state.edn names each wallpaper, in `@libshell.wallpaper_names` order.
|
||||
@@ -87,6 +91,7 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
|
||||
wallpaper: None,
|
||||
restore_session: None,
|
||||
remember_windows: None,
|
||||
dark_mode: None,
|
||||
}
|
||||
}
|
||||
let entries = read_state_file()
|
||||
@@ -186,6 +191,11 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
|
||||
wallpaper,
|
||||
restore_session: flag("restore-session"),
|
||||
remember_windows: flag("remember-windows"),
|
||||
dark_mode: match lookup_key(entries, "theme") {
|
||||
Some(Keyword("light")) => Some(false)
|
||||
Some(Keyword("dark")) => Some(true)
|
||||
_ => None
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,6 +216,10 @@ pub fn DesktopShell::apply_state(self : DesktopShell, st : SavedState) -> Unit {
|
||||
Some(b) => self.remember_windows = b
|
||||
None => ()
|
||||
}
|
||||
match st.dark_mode {
|
||||
Some(b) => self.dark_mode = b
|
||||
None => ()
|
||||
}
|
||||
match st.desk {
|
||||
Some((x, y)) => {
|
||||
self.desk_set = true
|
||||
@@ -278,6 +292,9 @@ pub fn DesktopShell::save_state(self : DesktopShell) -> Unit {
|
||||
entries.insert(2, (@edn.Value::Keyword("wallpaper"), @edn.Value::Keyword(wallpaper_keys[self.wallpaper_sel])))
|
||||
}
|
||||
// Session settings are written only when off: absent means on, as for a hand-written file.
|
||||
if !self.dark_mode {
|
||||
entries.insert(2, (@edn.Value::Keyword("theme"), @edn.Value::Keyword("light")))
|
||||
}
|
||||
if !self.remember_windows {
|
||||
entries.insert(2, (@edn.Value::Keyword("remember-windows"), @edn.Value::Bool(false)))
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
|
||||
///| Modules loaded into a fresh panel, in order. `tasks` stretches, so what follows it packs right.
|
||||
let default_panel : Array[String] = [
|
||||
"launcher", "inspector", "layout", "tasks", "moon-disc", "clock-digital12", "wallpaper", "session-settings",
|
||||
"logout",
|
||||
"launcher", "inspector", "layout", "tasks", "moon-disc", "clock-digital12", "session-settings", "logout",
|
||||
]
|
||||
|
||||
///| The module whose popup is the wasm picker.
|
||||
@@ -172,6 +171,30 @@ fn wall_secs() -> Int {
|
||||
@sys.wall_time_field(3) * 3600 + @sys.wall_time_field(4) * 60 + @sys.wall_time_field(5)
|
||||
}
|
||||
|
||||
///| Panels saved before the wallpaper chooser moved into the settings module list "wallpaper":
|
||||
/// the settings module takes its place (once; a panel that already has it just drops it).
|
||||
fn migrate_panel(entries : Array[String]) -> Array[String] {
|
||||
let has_settings = entries.contains("session-settings")
|
||||
let out : Array[String] = []
|
||||
for e in entries {
|
||||
if e == "wallpaper" {
|
||||
if !has_settings && !out.contains("session-settings") {
|
||||
out.push("session-settings")
|
||||
}
|
||||
} else {
|
||||
out.push(e)
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
///|
|
||||
test "a saved panel's wallpaper button becomes the settings module" {
|
||||
assert_eq(migrate_panel(["launcher", "wallpaper", "logout"]), ["launcher", "session-settings", "logout"])
|
||||
assert_eq(migrate_panel(["wallpaper", "session-settings"]), ["session-settings"])
|
||||
assert_eq(migrate_panel(["clock"]), ["clock"])
|
||||
}
|
||||
|
||||
///| Load the panel on first use: the saved layout if there is one, else the default modules.
|
||||
fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
|
||||
if self.booted {
|
||||
@@ -180,7 +203,7 @@ fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
|
||||
self.booted = true
|
||||
self.scan_catalog()
|
||||
let entries = match self.load_panel_config() {
|
||||
Some(e) => e
|
||||
Some(e) => migrate_panel(e)
|
||||
None => default_panel
|
||||
}
|
||||
for e in entries {
|
||||
@@ -446,11 +469,15 @@ pub fn DesktopShell::set_wallpaper(self : DesktopShell, i : Int) -> Unit {
|
||||
}
|
||||
|
||||
///| The session settings the session settings module lists, in index order.
|
||||
let session_setting_names : Array[String] = ["Reopen windows at login", "Remember window positions"]
|
||||
let session_setting_names : Array[String] = [
|
||||
"Reopen windows at login", "Remember window positions", "Dark mode",
|
||||
]
|
||||
|
||||
///| Which session settings are on: bit i for `session_setting_names[i]`.
|
||||
fn DesktopShell::session_settings_bits(self : DesktopShell) -> Int {
|
||||
(if self.restore_session { 1 } else { 0 }) | (if self.remember_windows { 2 } else { 0 })
|
||||
(if self.restore_session { 1 } else { 0 }) |
|
||||
(if self.remember_windows { 2 } else { 0 }) |
|
||||
(if self.dark_mode { 4 } else { 0 })
|
||||
}
|
||||
|
||||
///| Turn session setting `i` on or off (ignored when out of range) and remember it in state.edn.
|
||||
@@ -458,6 +485,11 @@ pub fn DesktopShell::set_session_setting(self : DesktopShell, i : Int, on : Bool
|
||||
match i {
|
||||
0 => self.restore_session = on
|
||||
1 => self.remember_windows = on
|
||||
2 =>
|
||||
if self.dark_mode != on {
|
||||
self.dark_mode = on
|
||||
self.actions.push(ThemeChanged)
|
||||
}
|
||||
_ => return
|
||||
}
|
||||
@wasm.publish_session_settings(self.session_settings_bits())
|
||||
|
||||
Reference in new issue
Block a user