Skip to content

Commit

Permalink
feat(wm): allow f32 width % for custom layouts
Browse files Browse the repository at this point in the history
This commit allows users to provide an f32 value for the WidthPercentage
on the primary column of a custom layout.
  • Loading branch information
LGUG2Z committed Jun 22, 2023
1 parent c4be063 commit 087b086
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions komorebi-core/src/custom_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl CustomLayout {
}

#[must_use]
pub fn primary_width_percentage(&self) -> Option<usize> {
pub fn primary_width_percentage(&self) -> Option<f32> {
for column in self.iter() {
if let Column::Primary(Option::Some(ColumnWidth::WidthPercentage(percentage))) = column
{
Expand All @@ -83,7 +83,7 @@ impl CustomLayout {
None
}

pub fn set_primary_width_percentage(&mut self, percentage: usize) {
pub fn set_primary_width_percentage(&mut self, percentage: f32) {
for column in self.iter_mut() {
if let Column::Primary(Option::Some(ColumnWidth::WidthPercentage(current))) = column {
*current = percentage;
Expand Down Expand Up @@ -262,7 +262,7 @@ pub enum Column {

#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)]
pub enum ColumnWidth {
WidthPercentage(usize),
WidthPercentage(f32),
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)]
Expand Down
10 changes: 5 additions & 5 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,15 +683,15 @@ impl WindowManager {
if matches!(axis, Axis::Horizontal) {
let percentage = custom
.primary_width_percentage()
.unwrap_or(100 / custom.len());
.unwrap_or(100.0 / (custom.len() as f32));

if no_layout_rules {
match sizing {
Sizing::Increase => {
custom.set_primary_width_percentage(percentage + 5);
custom.set_primary_width_percentage(percentage + 5.0);
}
Sizing::Decrease => {
custom.set_primary_width_percentage(percentage - 5);
custom.set_primary_width_percentage(percentage - 5.0);
}
}
} else {
Expand All @@ -700,10 +700,10 @@ impl WindowManager {
if let Layout::Custom(ref mut custom) = rule.1 {
match sizing {
Sizing::Increase => {
custom.set_primary_width_percentage(percentage + 5);
custom.set_primary_width_percentage(percentage + 5.0);
}
Sizing::Decrease => {
custom.set_primary_width_percentage(percentage - 5);
custom.set_primary_width_percentage(percentage - 5.0);
}
}
}
Expand Down

0 comments on commit 087b086

Please sign in to comment.