Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

fix: always drop dragged windows into the workspace under the cursor (#1156)

Miitto4e2de6bd8e9f
diff --git a/packages/wm/src/events/handle_display_settings_changed.rs b/packages/wm/src/events/handle_display_settings_changed.rs
index e4b50fcf..c4822aca 100644
--- a/packages/wm/src/events/handle_display_settings_changed.rs
+++ b/packages/wm/src/events/handle_display_settings_changed.rs
@@ -121,9 +121,7 @@ pub fn handle_display_settings_changed(
// display dictates the position of 0,0.
let workspace = window.workspace().context("No workspace.")?;
- let should_recenter = if !window.has_custom_floating_placement() {
- true
- } else {
+ let should_recenter = if window.has_custom_floating_placement() {
let workspace_rect = workspace.to_rect()?;
// Keep the placement if it still intersects the workspace, since
@@ -131,6 +129,8 @@ pub fn handle_display_settings_changed(
// non-monitor changes (e.g. unplugging a USB device).
!window.floating_placement().has_overlap_x(&workspace_rect)
|| !window.floating_placement().has_overlap_y(&workspace_rect)
+ } else {
+ true
};
if should_recenter {
diff --git a/packages/wm/src/events/handle_window_moved_or_resized_end.rs b/packages/wm/src/events/handle_window_moved_or_resized_end.rs
index aad8f9c6..522b503b 100644
--- a/packages/wm/src/events/handle_window_moved_or_resized_end.rs
+++ b/packages/wm/src/events/handle_window_moved_or_resized_end.rs
@@ -87,6 +87,7 @@ pub fn handle_window_moved_or_resized_end(
/// Handles transition from temporary floating window to tiling window on
/// drag end.
+#[allow(clippy::too_many_lines)]
fn drop_as_tiling_window(
moved_window: &NonTilingWindow,
state: &mut WmState,
@@ -98,19 +99,23 @@ fn drop_as_tiling_window(
);
let mouse_pos = Platform::mouse_position()?;
- let workspace = moved_window.workspace().context("No workspace.")?;
+ let mouse_workspace = state
+ .monitor_at_point(&mouse_pos)
+ .and_then(|monitor| monitor.displayed_workspace())
+ .or_else(|| moved_window.workspace())
+ .context("Couldn't find workspace for window drop.")?;
// Get the workspace, split containers, and other windows under the
// dragged window.
let containers_at_pos = state
- .containers_at_point(&workspace.clone().into(), &mouse_pos)
+ .containers_at_point(&mouse_workspace.clone().into(), &mouse_pos)
.into_iter()
.filter(|container| container.id() != moved_window.id());
// Get the deepest direction container under the dragged window.
let target_parent: DirectionContainer = containers_at_pos
.filter_map(|container| container.as_direction_container().ok())
- .fold(workspace.into(), |acc, container| {
+ .fold(mouse_workspace.into(), |acc, container| {
if container.ancestors().count() > acc.ancestors().count() {
container
} else {
@@ -121,8 +126,17 @@ fn drop_as_tiling_window(
// If the target parent has no children (i.e. an empty workspace), then
// add the window directly.
if target_parent.tiling_children().count() == 0 {
+ move_container_within_tree(
+ &moved_window.clone().into(),
+ &target_parent.clone().into(),
+ 0,
+ state,
+ )?;
+
+ moved_window.set_insertion_target(None);
+
update_window_state(
- moved_window.clone().into(),
+ moved_window.as_window_container()?,
WindowState::Tiling,
state,
config,