mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-19 23:28:34 +01:00
fix(workspace): make scrolling-layout-columns work with other options
The command only set the column count when the workspace had no layout options at all, or already had scrolling options. A workspace with options for something else (column_ratios, say) and no scrolling options matched the second arm and was left unchanged, so the command silently did nothing. Move the logic to Workspace::set_scrolling_columns, which creates the scrolling options when they are missing and keeps every other option, and test all three cases.
This commit is contained in:
1 parent
1098dfc6ec
commit
0fb5de3c0e
2 files changed
+82
-24
No files matched your search
@@ -29,7 +29,6 @@ use crate::core::MonocleFocusBehaviour;
|
||||
use crate::core::MoveBehaviour;
|
||||
use crate::core::OperationDirection;
|
||||
use crate::core::Rect;
|
||||
use crate::core::ScrollingLayoutOptions;
|
||||
use crate::core::SocketMessage;
|
||||
use crate::core::StateQuery;
|
||||
use crate::core::WindowContainerBehaviour;
|
||||
@@ -1493,28 +1492,8 @@ impl WindowManager {
|
||||
self.adjust_workspace_padding(sizing, adjustment)?;
|
||||
}
|
||||
SocketMessage::ScrollingLayoutColumns(count) => {
|
||||
let focused_workspace = self.focused_workspace_mut()?;
|
||||
|
||||
let options = match focused_workspace.layout_options {
|
||||
Some(mut opts) => {
|
||||
if let Some(scrolling) = &mut opts.scrolling {
|
||||
scrolling.columns = count.into();
|
||||
}
|
||||
|
||||
opts
|
||||
}
|
||||
None => LayoutOptions {
|
||||
scrolling: Some(ScrollingLayoutOptions {
|
||||
columns: count.into(),
|
||||
center_focused_column: Default::default(),
|
||||
}),
|
||||
grid: None,
|
||||
column_ratios: None,
|
||||
row_ratios: None,
|
||||
},
|
||||
};
|
||||
|
||||
focused_workspace.layout_options = Some(options);
|
||||
self.focused_workspace_mut()?
|
||||
.set_scrolling_columns(count.into());
|
||||
self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
SocketMessage::LayoutRatios(ref columns, ref rows) => {
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::core::LayoutDefaultEntry;
|
||||
use crate::core::LayoutOptions;
|
||||
use crate::core::OperationDirection;
|
||||
use crate::core::Rect;
|
||||
use crate::core::ScrollingLayoutOptions;
|
||||
use crate::core::SocketMessage;
|
||||
use crate::core::WindowContainerBehaviour;
|
||||
use crate::core::WindowHidingPosition;
|
||||
@@ -1310,6 +1311,28 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
/// Set how many columns the Scrolling layout shows at once, keeping every other layout option.
|
||||
pub fn set_scrolling_columns(&mut self, columns: usize) {
|
||||
let mut options = self.layout_options.unwrap_or(LayoutOptions {
|
||||
scrolling: None,
|
||||
grid: None,
|
||||
column_ratios: None,
|
||||
row_ratios: None,
|
||||
});
|
||||
|
||||
match &mut options.scrolling {
|
||||
Some(scrolling) => scrolling.columns = columns,
|
||||
None => {
|
||||
options.scrolling = Some(ScrollingLayoutOptions {
|
||||
columns,
|
||||
center_focused_column: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
self.layout_options = Some(options);
|
||||
}
|
||||
|
||||
/// Ask the layout for where every container goes, before the result is clamped to the work area.
|
||||
fn calculate_layouts(
|
||||
&mut self,
|
||||
@@ -2936,11 +2959,67 @@ mod tests {
|
||||
assert!(layout.right <= 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_scrolling_columns() {
|
||||
let columns_of = |workspace: &Workspace| {
|
||||
workspace
|
||||
.layout_options
|
||||
.and_then(|options| options.scrolling)
|
||||
.map(|scrolling| scrolling.columns)
|
||||
};
|
||||
|
||||
// a workspace that has no layout options at all
|
||||
let mut workspace = Workspace::default();
|
||||
workspace.set_scrolling_columns(4);
|
||||
assert_eq!(columns_of(&workspace), Some(4));
|
||||
|
||||
// layout options for something else must not swallow the change
|
||||
let ratios = crate::core::validate_ratios(&[0.6]);
|
||||
let mut workspace = Workspace {
|
||||
layout_options: Some(LayoutOptions {
|
||||
scrolling: None,
|
||||
grid: None,
|
||||
column_ratios: Some(ratios),
|
||||
row_ratios: None,
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
workspace.set_scrolling_columns(4);
|
||||
assert_eq!(columns_of(&workspace), Some(4));
|
||||
assert_eq!(
|
||||
workspace.layout_options.and_then(|o| o.column_ratios),
|
||||
Some(ratios)
|
||||
);
|
||||
|
||||
// existing scrolling options keep their other settings
|
||||
let mut workspace = Workspace {
|
||||
layout_options: Some(LayoutOptions {
|
||||
scrolling: Some(ScrollingLayoutOptions {
|
||||
columns: 2,
|
||||
center_focused_column: Some(true),
|
||||
}),
|
||||
grid: None,
|
||||
column_ratios: None,
|
||||
row_ratios: None,
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
workspace.set_scrolling_columns(5);
|
||||
assert_eq!(columns_of(&workspace), Some(5));
|
||||
assert_eq!(
|
||||
workspace
|
||||
.layout_options
|
||||
.and_then(|o| o.scrolling)
|
||||
.and_then(|s| s.center_focused_column),
|
||||
Some(true)
|
||||
);
|
||||
}
|
||||
|
||||
fn scrolling_workspace(containers: usize, columns: usize) -> Workspace {
|
||||
let mut workspace = Workspace {
|
||||
layout: Layout::Default(DefaultLayout::Scrolling),
|
||||
layout_options: Some(LayoutOptions {
|
||||
scrolling: Some(crate::core::ScrollingLayoutOptions {
|
||||
scrolling: Some(ScrollingLayoutOptions {
|
||||
columns,
|
||||
center_focused_column: None,
|
||||
}),
|
||||
|
||||
Reference in new issue
Block a user