Skip to content
Open
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
3 changes: 3 additions & 0 deletions packages/wm-common/src/app_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ pub struct InvokeAdjustBordersCommand {

#[clap(long, allow_hyphen_values = true)]
pub left: Option<LengthValue>,

#[clap(long, allow_hyphen_values = true)]
pub class_name: Option<String>,
}

#[derive(Args, Clone, Debug, PartialEq, Serialize)]
Expand Down
11 changes: 5 additions & 6 deletions packages/wm-common/src/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ impl Rect {
/// original rectangle.
#[must_use]
pub fn clamp(&self, outer_rect: &Rect) -> Self {
Self::from_xy(
self.left.max(outer_rect.left),
self.top.max(outer_rect.top),
self.width().min(outer_rect.width()),
self.height().min(outer_rect.height()),
)
let x = self.left.max(outer_rect.left);
let y = self.top.max(outer_rect.top);
let width = self.width().min(outer_rect.right - x);
let height = self.height().min(outer_rect.bottom - y);
Self::from_xy(x, y, width, height)
}

#[must_use]
Expand Down
19 changes: 16 additions & 3 deletions packages/wm/src/commands/general/platform_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ fn redraw_containers(
let workspace =
window.workspace().context("Window has no workspace.")?;

let monitor = window.monitor().context("Window has no monitor.")?;

// Whether the window should be shown above all other windows.
let z_order = match window.state() {
WindowState::Floating(config) if config.shown_on_top => {
Expand Down Expand Up @@ -257,9 +259,20 @@ fn redraw_containers(
},
);

let rect = window
.to_rect()?
.apply_delta(&window.total_border_delta()?, None);
let rect = {
let adjusted_rect = window
.to_rect()?
.apply_delta(&window.total_border_delta()?, None);

// Clamp tiling windows within the bounds of the monitor to handle
// excessive shadow borders.
match window.state() {
WindowState::Tiling => {
adjusted_rect.clamp(monitor.native().working_rect()?)
}
_ => adjusted_rect,
}
};

let is_visible = matches!(
window.display_state(),
Expand Down
57 changes: 37 additions & 20 deletions packages/wm/src/wm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use crate::{
},
monitor::focus_monitor,
window::{
ignore_window, move_window_in_direction, move_window_to_workspace,
resize_window, set_window_position, set_window_size,
update_window_state, WindowPositionTarget,
ignore_window, move_window_in_direction,
move_window_to_workspace, resize_window, set_window_position,
set_window_size, update_window_state, WindowPositionTarget,
},
workspace::{focus_workspace, move_workspace_in_direction},
},
Expand All @@ -34,7 +34,7 @@ use crate::{
handle_window_moved_or_resized_start, handle_window_shown,
handle_window_title_changed,
},
models::{Container, WorkspaceTarget},
models::{Container, WindowContainer, WorkspaceTarget},
traits::{CommonGetters, WindowGetters},
user_config::UserConfig,
wm_state::WmState,
Expand Down Expand Up @@ -203,23 +203,40 @@ impl WindowManager {

match &command {
InvokeCommand::AdjustBorders(args) => {
match subject_container.as_window_container() {
Ok(window) => {
let args = args.clone();
let border_delta = RectDelta::new(
args.left.unwrap_or(LengthValue::from_px(0)),
args.top.unwrap_or(LengthValue::from_px(0)),
args.right.unwrap_or(LengthValue::from_px(0)),
args.bottom.unwrap_or(LengthValue::from_px(0)),
);

window.set_border_delta(border_delta);
state.pending_sync.queue_container_to_redraw(window);

Ok(())
}
_ => Ok(()),
let windows: Vec<WindowContainer> =
if let Some(class_name) = &args.class_name {
state
.windows()
.into_iter()
.filter(|w| {
w.native()
.class_name()
.ok()
.map(|c| c.starts_with(class_name))
== Some(true)
})
.collect::<Vec<_>>()
} else {
subject_container
.as_window_container()
.into_iter()
.collect::<Vec<_>>()
};

for window in windows {
let window: WindowContainer = window;
let args = args.clone();
let border_delta = RectDelta::new(
args.left.unwrap_or(LengthValue::from_px(0)),
args.top.unwrap_or(LengthValue::from_px(0)),
args.right.unwrap_or(LengthValue::from_px(0)),
args.bottom.unwrap_or(LengthValue::from_px(0)),
);

window.set_border_delta(border_delta);
state.pending_sync.queue_container_to_redraw(window);
}
Ok(())
}
InvokeCommand::Close => {
match subject_container.as_window_container() {
Expand Down