srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/crates/core
diff options
context:
space:
mode:
Diffstat (limited to 'crates/core')
-rw-r--r--crates/core/src/lib.rs2
-rw-r--r--crates/core/src/window.rs32
2 files changed, 33 insertions, 1 deletions
diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs
index 7b728d9..ed24e78 100644
--- a/crates/core/src/lib.rs
+++ b/crates/core/src/lib.rs
@@ -24,7 +24,7 @@ pub use regex::Regex;
pub use rules::{WindowMatch, WindowRule, WindowRuleActions};
pub use theme::{format_hex_color, parse_hex_color, ThemeConfig};
pub use window::{
- classify_menu_source, parse_button_order, ButtonOrder, GlobalMenu, MenuSource, ResizeEdge, TitlebarButton, TitlebarHit, Window, WindowId,
+ classify_menu_source, format_button_order, parse_button_order, ButtonOrder, GlobalMenu, MenuSource, ResizeEdge, TitlebarButton, TitlebarHit, Window, WindowId,
BUTTON_CLUSTER_MARGIN, BUTTON_PITCH, RESIZE_MARGIN, TITLEBAR_HEIGHT,
};
pub use workspace::{Workspace, WorkspaceId};
diff --git a/crates/core/src/window.rs b/crates/core/src/window.rs
index a8de352..21faeff 100644
--- a/crates/core/src/window.rs
+++ b/crates/core/src/window.rs
@@ -838,6 +838,23 @@ pub fn parse_button_order(s: &str) -> Option<ButtonOrder> {
Some(order)
}
+/// [`parse_button_order`]'s exact inverse - `"close,minimize,maximize"`,
+/// lowercase, comma-separated in the order the buttons actually render.
+/// Exists for settings readback, same reasoning as `format_hex_color`:
+/// a caller reading `button_order` back over IPC should get the identical
+/// string shape `srd set button_order` itself accepts.
+pub fn format_button_order(order: ButtonOrder) -> String {
+ order
+ .iter()
+ .map(|b| match b {
+ TitlebarButton::Close => "close",
+ TitlebarButton::Minimize => "minimize",
+ TitlebarButton::Maximize => "maximize",
+ })
+ .collect::<Vec<_>>()
+ .join(",")
+}
+
#[cfg(test)]
mod button_order_tests {
use super::*;
@@ -869,6 +886,21 @@ mod button_order_tests {
}
#[test]
+ fn format_button_order_round_trips_through_parse_button_order() {
+ for order in [
+ [TitlebarButton::Close, TitlebarButton::Minimize, TitlebarButton::Maximize],
+ [TitlebarButton::Maximize, TitlebarButton::Minimize, TitlebarButton::Close],
+ ] {
+ assert_eq!(parse_button_order(&format_button_order(order)), Some(order));
+ }
+ }
+
+ #[test]
+ fn format_button_order_matches_the_exact_shape_set_accepts() {
+ assert_eq!(format_button_order([TitlebarButton::Close, TitlebarButton::Minimize, TitlebarButton::Maximize]), "close,minimize,maximize");
+ }
+
+ #[test]
fn rejects_an_unknown_token() {
assert_eq!(parse_button_order("close,minimize,help"), None);
}