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: move window by dragging them with the mouse #635

Merged
merged 36 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
612940c
feat: detect if window moved or resized
LucaCoduriV Jul 23, 2024
561df52
feat: utility functions & get window under mouse position
LucaCoduriV Jul 26, 2024
28eb5d1
feat: log
LucaCoduriV Jul 26, 2024
ad9c396
feature: moving window with mouse WIP
LucaCoduriV Jul 28, 2024
0508c08
fix: window moving logic
LucaCoduriV Jul 28, 2024
be9679e
refactor: removed duplicated code
LucaCoduriV Jul 28, 2024
b9c0ad1
feature: added window move start event
LucaCoduriV Jul 28, 2024
37ddc09
feat: When drag start, sets window to floating
LucaCoduriV Jul 28, 2024
d3f0c46
fix: bug when moving window to a target on the right side
LucaCoduriV Jul 28, 2024
ec7a335
feat: Added a way to know if a floating window was created by dragging
LucaCoduriV Jul 29, 2024
63caa2a
fix: revert changes and fixed imports
LucaCoduriV Jul 29, 2024
26e3709
comment: todo
LucaCoduriV Jul 30, 2024
3fb3d57
feat: check state of floating window
LucaCoduriV Jul 30, 2024
3ef0155
refactor
LucaCoduriV Jul 30, 2024
1414229
fix: bug of moving window when alone in split
LucaCoduriV Jul 30, 2024
74ff51e
fix: bug window not splitting in the right place
LucaCoduriV Jul 30, 2024
fc77d47
fix: bug when dragged on no window
LucaCoduriV Jul 30, 2024
e263886
feat: Deleting split when only 1 container in it
LucaCoduriV Jul 31, 2024
3e988e8
feat: resizing with the mouse works as before
LucaCoduriV Jul 31, 2024
30cadf0
refactor: get containers mouse position
LucaCoduriV Jul 31, 2024
5e06c97
feat: doc comments
LucaCoduriV Jul 31, 2024
d5e7a7b
refactor
LucaCoduriV Jul 31, 2024
5c8b85f
comments
LucaCoduriV Jul 31, 2024
e195c28
refactor: simplified code
LucaCoduriV Jul 31, 2024
4dada73
Merge remote-tracking branch 'origin/quick-test' into feature/window_…
LucaCoduriV Aug 1, 2024
5aa1bc8
fix: pr review
LucaCoduriV Aug 1, 2024
704650a
fix: pr review
LucaCoduriV Aug 1, 2024
c8f4842
fix: pr review
LucaCoduriV Aug 1, 2024
3753637
fix: pr review
LucaCoduriV Aug 1, 2024
6067dcd
fix: pr review
LucaCoduriV Aug 1, 2024
98757c4
fix: pr review
LucaCoduriV Aug 1, 2024
49bdb8c
fix: bug resize considered as a drag
LucaCoduriV Aug 1, 2024
16f7ffb
fix: moving window into an empty workspace
LucaCoduriV Aug 1, 2024
3a47a58
refactor
LucaCoduriV Aug 1, 2024
6bf4528
refactor: use option for active_drag
LucaCoduriV Aug 1, 2024
1082f29
style: linting fixes
lars-berger Aug 1, 2024
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
2 changes: 2 additions & 0 deletions packages/wm/src/app_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ impl InvokeCommand {
centered: centered.unwrap_or(floating_defaults.centered),
shown_on_top: shown_on_top
.unwrap_or(floating_defaults.shown_on_top),
is_tiling_drag: false,
}),
state,
config,
Expand Down Expand Up @@ -478,6 +479,7 @@ impl InvokeCommand {
centered: centered.unwrap_or(floating_defaults.centered),
shown_on_top: shown_on_top
.unwrap_or(floating_defaults.shown_on_top),
is_tiling_drag: false,
});

update_window_state(
Expand Down
100 changes: 94 additions & 6 deletions packages/wm/src/common/events/handle_window_location_changed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ use anyhow::Context;
use tracing::info;

use crate::{
common::platform::NativeWindow,
common::{platform::NativeWindow, Rect},
containers::{
commands::move_container_within_tree, traits::CommonGetters,
WindowContainer,
commands::{
attach_container, detach_container, move_container_within_tree,
},
traits::{CommonGetters, PositionGetters},
Container, WindowContainer,
},
user_config::{FullscreenStateConfig, UserConfig},
user_config::{FloatingStateConfig, FullscreenStateConfig, UserConfig},
windows::{
commands::update_window_state, traits::WindowGetters, WindowState,
commands::update_window_state, traits::WindowGetters,
window_operation::WindowOperation, TilingWindow, WindowState,
},
wm_state::WmState,
};
Expand All @@ -23,7 +27,17 @@ pub fn handle_window_location_changed(

// Update the window's state to be fullscreen or toggled from fullscreen.
if let Some(window) = found_window {
let frame_position = window.native().refresh_frame_position()?;
let frame_position: Rect = window.native().refresh_frame_position()?;
let old_frame_position: Rect = window.to_rect()?;

update_window_operation(
state,
config,
&window,
&frame_position,
&old_frame_position,
)?;

let is_minimized = window.native().refresh_is_minimized()?;

let old_is_maximized = window.native().is_maximized()?;
Expand Down Expand Up @@ -131,3 +145,77 @@ pub fn handle_window_location_changed(

Ok(())
}

/// Updates the window operation based on changes in frame position.
///
/// This function determines whether a window is being moved or resized and
/// updates its operation state accordingly. If the window is being moved,
/// it's set to floating mode.
fn update_window_operation(
state: &mut WmState,
config: &UserConfig,
window: &WindowContainer,
frame_position: &Rect,
old_frame_position: &Rect,
) -> anyhow::Result<()> {
if let Some(tiling_window) = window.as_tiling_window() {
let window_operation = window.window_operation();
if window_operation == WindowOperation::Waiting {
if frame_position.height() == old_frame_position.height()
&& frame_position.width() == old_frame_position.width()
{
window.set_window_operation(WindowOperation::Moving);
set_into_floating(tiling_window.clone(), state, config)?;
} else {
window.set_window_operation(WindowOperation::Resizing);
}
}
}
Ok(())
}

/// Converts a tiling window to a floating window and updates the window
/// hierarchy.
///
/// This function handles the process of transitioning a tiling window to a
/// floating state, including necessary adjustments to the window hierarchy
/// and updating the window's state.
fn set_into_floating(
moved_window: TilingWindow,
state: &mut WmState,
config: &UserConfig,
) -> anyhow::Result<()> {
let moved_window_parent = moved_window
.parent()
.context("Tiling window has no parent")?;

if let Some(Container::Split(split)) = moved_window.parent() {
lars-berger marked this conversation as resolved.
Show resolved Hide resolved
if split.child_count() == 2 {
let split_parent = split.parent().unwrap();
let split_index = split.index();
let children = split.children();

// Looping in reversed order to reattach them in the right order
for child in children.into_iter().rev() {
detach_container(child.clone())?;
attach_container(&child, &split_parent, Some(split_index))?;
}
}
}

update_window_state(
moved_window.as_window_container().unwrap(),
WindowState::Floating(FloatingStateConfig {
centered: true,
shown_on_top: true,
is_tiling_drag: true,
}),
state,
config,
)?;
state
.pending_sync
.containers_to_redraw
.push(moved_window_parent);
Ok(())
}
Loading