Skip to content

Commit

Permalink
Separate background config options into a section
Browse files Browse the repository at this point in the history
**Breaking changes**:
- The `background` option is now `background.path`
- The `background_fit` option is now `background.fit`
  • Loading branch information
rharish101 committed Apr 3, 2023
1 parent e8a57f8 commit 1353d2a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
5 changes: 3 additions & 2 deletions regreet.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
19 changes: 13 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
#[serde(default)]
fit: BgFit,
}

/// Struct for reboot/poweroff commands
#[derive(Deserialize, Serialize)]
pub struct SystemCommands {
Expand Down Expand Up @@ -69,9 +78,7 @@ pub struct Config {
#[serde(default)]
env: HashMap<String, String>,
#[serde(default)]
background: Option<String>,
#[serde(default)]
pub background_fit: Option<BgFit>,
background: Background,
#[serde(default, rename = "GTK")]
gtk: Option<GtkSettings>,
#[serde(default)]
Expand All @@ -88,12 +95,12 @@ impl Config {
}

pub fn get_background(&self) -> &Option<String> {
&self.background
&self.background.path
}

#[cfg(feature = "gtk4_8")]
pub fn get_background_fit(&self) -> &Option<BgFit> {
&self.background_fit
pub fn get_background_fit(&self) -> &BgFit {
&self.background.fit
}

pub fn get_gtk_settings(&self) -> &Option<GtkSettings> {
Expand Down
7 changes: 4 additions & 3 deletions src/gui/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 1353d2a

Please sign in to comment.