From 1353d2a0a73d93542b0be995cfaf1e3e7040b4f3 Mon Sep 17 00:00:00 2001 From: Harish Rajagopal Date: Mon, 3 Apr 2023 21:31:10 +0200 Subject: [PATCH] Separate background config options into a section **Breaking changes**: - The `background` option is now `background.path` - The `background_fit` option is now `background.fit` --- regreet.sample.toml | 5 +++-- src/config.rs | 19 +++++++++++++------ src/gui/component.rs | 7 ++++--- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/regreet.sample.toml b/regreet.sample.toml index 1cbc72f..bc79455 100644 --- a/regreet.sample.toml +++ b/regreet.sample.toml @@ -2,14 +2,15 @@ # # SPDX-License-Identifier: GPL-3.0-or-later +[background] # Path to the background image -background = "/usr/share/backgrounds/greeter.jpg" +path = "/usr/share/backgrounds/greeter.jpg" # How the background image covers the screen if the aspect ratio doesn't match # Available values: "Fill", "Contain", "Cover", "ScaleDown" # Refer to: https://docs.gtk.org/gtk4/enum.ContentFit.html # NOTE: This is ignored if ReGreet isn't compiled with GTK v4.8 support. -background_fit = "Contain" +fit = "Contain" # The entries defined in this section will be passed to the session as environment variables when it is started [env] diff --git a/src/config.rs b/src/config.rs index 58293ea..6de5457 100644 --- a/src/config.rs +++ b/src/config.rs @@ -37,6 +37,15 @@ pub enum BgFit { ScaleDown, } +/// Struct for info about the background image +#[derive(Default, Deserialize, Serialize)] +struct Background { + #[serde(default)] + path: Option, + #[serde(default)] + fit: BgFit, +} + /// Struct for reboot/poweroff commands #[derive(Deserialize, Serialize)] pub struct SystemCommands { @@ -69,9 +78,7 @@ pub struct Config { #[serde(default)] env: HashMap, #[serde(default)] - background: Option, - #[serde(default)] - pub background_fit: Option, + background: Background, #[serde(default, rename = "GTK")] gtk: Option, #[serde(default)] @@ -88,12 +95,12 @@ impl Config { } pub fn get_background(&self) -> &Option { - &self.background + &self.background.path } #[cfg(feature = "gtk4_8")] - pub fn get_background_fit(&self) -> &Option { - &self.background_fit + pub fn get_background_fit(&self) -> &BgFit { + &self.background.fit } pub fn get_gtk_settings(&self) -> &Option { diff --git a/src/gui/component.rs b/src/gui/component.rs index 8bb17af..72caa8d 100644 --- a/src/gui/component.rs +++ b/src/gui/component.rs @@ -330,14 +330,15 @@ impl Component for Greeter { // cfg directives don't work inside Relm4 view! macro. #[cfg(feature = "gtk4_8")] - if let Some(fit) = model.config.get_background_fit() { - widgets.ui.background.set_content_fit(match fit { + widgets + .ui + .background + .set_content_fit(match model.config.get_background_fit() { BgFit::Fill => gtk4::ContentFit::Fill, BgFit::Contain => gtk4::ContentFit::Contain, BgFit::Cover => gtk4::ContentFit::Cover, BgFit::ScaleDown => gtk4::ContentFit::ScaleDown, }); - }; // Cancel any previous session, just in case someone started one. if let Err(err) = model.greetd_client.lock().unwrap().cancel_session() {