Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: scale inner and outer gaps by monitor DPI #756

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/wm/src/common/length_value.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::str::FromStr;
use std::{ops::Mul, str::FromStr};

use anyhow::{bail, Context};
use regex::Regex;
Expand Down Expand Up @@ -104,3 +104,13 @@ impl<'de> Deserialize<'de> for LengthValue {
}
}
}

impl Mul<f32> for LengthValue {
type Output = Self;
fn mul(self, rhs: f32) -> Self {
Self {
amount: self.amount * rhs,
unit: self.unit,
}
}
}
14 changes: 14 additions & 0 deletions packages/wm/src/common/rect_delta.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Mul;

use serde::{Deserialize, Serialize};

use super::LengthValue;
Expand Down Expand Up @@ -32,3 +34,15 @@ impl RectDelta {
}
}
}

impl Mul<f32> for RectDelta {
type Output = Self;
fn mul(self, rhs: f32) -> Self {
Self::new(
self.left * rhs,
self.top * rhs,
self.right * rhs,
self.bottom * rhs,
)
}
}
9 changes: 8 additions & 1 deletion packages/wm/src/containers/traits/tiling_size_getters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ macro_rules! impl_tiling_size_getters {
}

fn inner_gap(&self) -> LengthValue {
self.0.borrow().inner_gap.clone()
let scale = match self.monitor() {
None => 1_f32,
Some(monitor) => match monitor.native().dpi() {
Ok(dpi) => dpi,
Err(_) => 1_f32,
},
};
self.0.borrow().inner_gap.clone() * scale
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like in the Zebar PR, think we should only be scaling pixels here

would suggest adding a new field:

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all(serialize = "camelCase"))]
pub struct GapsConfig {
  /// Whether to scale the gaps with the DPI of the monitor.
  #[serde(default = "default_bool::<true>")]
  pub scale_with_dpi: bool,
  
// sample-config.yaml:
// gaps:
//   # Whether to scale the gaps with the DPI of the monitor.
//   scale_with_dpi: true

that way, we can make it more explicit that this gets scaled, since all other px values in the config deal with physical pixels.

would then have to change TilingSizeGetters::inner_gap, TilingSizeGetters::set_inner_gap, Workspace::set_outer_gap to instead get/set the GapsConfig struct.

to deal with only scaling px values and not %, maybe we could add something like LengthValue::to_px_scaled(&self, total_px: i32, scale_factor: f32)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

}

fn set_inner_gap(&self, inner_gap: LengthValue) {
Expand Down
8 changes: 6 additions & 2 deletions packages/wm/src/workspaces/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ impl PositionGetters for Workspace {
.cloned()
.context("Failed to get working area of parent monitor.")?;

let outer_gap = &self.0.borrow().outer_gap;
Ok(working_rect.apply_inverse_delta(outer_gap))
let scale = match self.monitor() {
None => 1_f32,
Some(monitor) => monitor.native().dpi()?,
};
let outer_gap = self.0.borrow().outer_gap.clone() * scale;
Ok(working_rect.apply_inverse_delta(&outer_gap))
}
}