diff --git a/src/state.rs b/src/state.rs index 7a513a32..682b0bfd 100644 --- a/src/state.rs +++ b/src/state.rs @@ -454,14 +454,7 @@ pub fn client_is_privileged(client: &Client) -> bool { } fn enable_wayland_security() -> bool { - std::env::var("COSMIC_ENABLE_WAYLAND_SECURITY") - .map(|x| { - x == "1" - || x.to_lowercase() == "true" - || x.to_lowercase() == "yes" - || x.to_lowercase() == "y" - }) - .unwrap_or(false) + crate::utils::env::bool_var("COSMIC_ENABLE_WAYLAND_SECURITY").unwrap_or(false) } impl State { @@ -524,8 +517,8 @@ impl State { let idle_inhibit_manager_state = IdleInhibitManagerState::new::(&dh); let idle_inhibiting_surfaces = HashSet::new(); - let data_control_state = std::env::var("COSMIC_DATA_CONTROL_ENABLED") - .is_ok_and(|value| value == "1") + let data_control_state = crate::utils::env::bool_var("COSMIC_DATA_CONTROL_ENABLED") + .unwrap_or(false) .then(|| { DataControlState::new::(dh, Some(&primary_selection_state), |_| true) }); diff --git a/src/utils/env.rs b/src/utils/env.rs new file mode 100644 index 00000000..7e55aed7 --- /dev/null +++ b/src/utils/env.rs @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0-only + +pub fn bool_var(name: &str) -> Option { + let value = std::env::var(name).ok()?.to_lowercase(); + Some(["1", "true", "yes", "y"].contains(&value.as_str())) +} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 4da680ef..ac1df019 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only +pub mod env; mod ids; pub(crate) use self::ids::id_gen; pub mod geometry;