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

fix: regression in layouting with taskbar alignments #836

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 13 additions & 5 deletions packages/wm/src/common/commands/platform_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tokio::task;
use tracing::warn;

use crate::{
common::{platform::Platform, DisplayState},
common::{platform::Platform, DisplayState, Rect},
containers::{
traits::{CommonGetters, PositionGetters},
Container, WindowContainer,
Expand Down Expand Up @@ -125,9 +125,17 @@ fn redraw_containers(state: &mut WmState) -> anyhow::Result<()> {
},
);

let rect = window
.to_rect()?
.apply_delta(&window.total_border_delta()?, None);
let current_rect = window.to_rect()?;
let current_rect_width = current_rect.width();
let current_rect_height = current_rect.height();

let total_border_delta = &window.total_border_delta()?;
let new_rect = Rect::from_ltrb(
current_rect.left - total_border_delta.left.to_px(current_rect_width, None),
current_rect.top - total_border_delta.top.to_px(current_rect_height, None),
current_rect.right + total_border_delta.right.to_px(current_rect_width, None),
current_rect.bottom + total_border_delta.bottom.to_px(current_rect_height, None),
);

let is_visible = matches!(
window.display_state(),
Expand All @@ -136,7 +144,7 @@ fn redraw_containers(state: &mut WmState) -> anyhow::Result<()> {

if let Err(err) = window.native().set_position(
&window.state(),
&rect,
&new_rect,
is_visible,
window.has_pending_dpi_adjustment(),
) {
Expand Down
26 changes: 0 additions & 26 deletions packages/wm/src/common/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,6 @@ impl Rect {
}
}

pub fn apply_delta(
&self,
delta: &RectDelta,
scale_factor: Option<f32>,
) -> Self {
Self::from_ltrb(
self.left - delta.left.to_px(self.width(), scale_factor),
self.top - delta.top.to_px(self.height(), scale_factor),
self.right + delta.right.to_px(self.width(), scale_factor),
self.bottom + delta.bottom.to_px(self.height(), scale_factor),
)
}

pub fn apply_inverse_delta(
&self,
delta: &RectDelta,
scale_factor: Option<f32>,
) -> Self {
Self::from_ltrb(
self.left + delta.left.to_px(self.width(), scale_factor),
self.top + delta.top.to_px(self.height(), scale_factor),
self.right - delta.right.to_px(self.width(), scale_factor),
self.bottom - delta.bottom.to_px(self.height(), scale_factor),
)
}

// Gets whether the x-coordinate overlaps with the x-coordinate of the
// other rect.
pub fn has_overlap_x(&self, other: &Rect) -> bool {
Expand Down
44 changes: 29 additions & 15 deletions packages/wm/src/workspaces/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,42 @@ impl_tiling_direction_getters!(Workspace);

impl PositionGetters for Workspace {
fn to_rect(&self) -> anyhow::Result<Rect> {
let monitor =
self.monitor().context("Workspace has no parent monitor.")?;
let monitor = self.monitor()
.context("Workspace has no parent monitor.")?;

let gaps_config = &self.0.borrow().gaps_config;
let scale_factor = match &gaps_config.scale_with_dpi {
true => monitor.native().scale_factor()?,
false => 1.,
};
let monitor_rect = monitor.to_rect()?;
let native_monitor = monitor.native();

// Get delta between monitor bounds and its working area.
let working_delta = monitor
.native()
let working_area_delta = native_monitor
.working_rect()
.context("Failed to get working area of parent monitor.")?
.delta(&monitor.to_rect()?);
.delta(&monitor_rect);

let gaps_config = &self.0.borrow().gaps_config;
let outer_gap_delta = &gaps_config.outer_gap;
let scale_factor = Some(match &gaps_config.scale_with_dpi {
true => native_monitor.scale_factor()?,
false => 1.,
});

let monitor_width = monitor_rect.width();
let monitor_height = monitor_rect.height();
Ok(
monitor
.to_rect()?
// Scale the gaps if `scale_with_dpi` is enabled.
.apply_inverse_delta(&gaps_config.outer_gap, Some(scale_factor))
.apply_delta(&working_delta, None),
Rect::from_ltrb(
monitor_rect.left
+ working_area_delta.left.to_px(monitor_width, scale_factor)
+ outer_gap_delta.left.to_px(monitor_width, scale_factor),
monitor_rect.top
+ working_area_delta.top.to_px(monitor_height, scale_factor)
+ outer_gap_delta.top.to_px(monitor_height, scale_factor),
monitor_rect.right
+ working_area_delta.right.to_px(monitor_width, scale_factor)
- outer_gap_delta.right.to_px(monitor_width, scale_factor),
monitor_rect.bottom
+ working_area_delta.bottom.to_px(monitor_height, scale_factor)
- outer_gap_delta.bottom.to_px(monitor_height, scale_factor),
)
)
}
}