Resize floating windows by dragging their corners and side edges
CI / test (push) Failing after 15s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Sonnet 5.5 committed 2026-11-25 00:44:34 -08:00
1 parent 8a3ea16b1c
commit a9417fbccf
2 files changed
+117 -21

No files matched your search

+87 -21
View File
@@ -614,6 +614,66 @@ fn MoonPlasmaCompositor::window_at(self : MoonPlasmaCompositor, x : Int, y : Int
None None
} }
///| Resize zone under (x, y) on a floating window: its corners (12px) and left/right/bottom
/// edges. The first window whose outer box contains the point decides; tiled windows resize
/// through the dividers instead.
fn MoonPlasmaCompositor::resize_at(
self : MoonPlasmaCompositor,
x : Int,
y : Int,
) -> (UInt64, @wm.DragMode)? {
let order = self.wm.stacking_order()
let mut i = order.length() - 1
while i >= 0 {
let id = order[i]
match (self.windows.get(id), self.wm.windows.get(id)) {
(Some(win), Some(rec)) => {
let g = win.geometry
let l = g.x
let r = g.x + g.w
let t = g.y - 32
let b = g.y + g.h
if x >= l - 6 && x < r + 6 && y >= t - 6 && y < b + 6 {
if !rec.is_floating || rec.maximized || rec.fullscreen {
return None
}
let nl = x < l + 12
let nr = x >= r - 12
let in_l = x < l + 2
let in_r = x >= r - 2
let in_b = y >= b - 2
let in_t = y < t + 4
if in_t && nl {
return Some((id, @wm.DragMode::ResizeNW))
}
if in_t && nr {
return Some((id, @wm.DragMode::ResizeNE))
}
if in_b && nl {
return Some((id, @wm.DragMode::ResizeSW))
}
if in_b && nr {
return Some((id, @wm.DragMode::ResizeSE))
}
if in_b {
return Some((id, @wm.DragMode::ResizeS))
}
if in_l {
return Some((id, if y >= b - 12 { @wm.DragMode::ResizeSW } else { @wm.DragMode::ResizeW }))
}
if in_r {
return Some((id, if y >= b - 12 { @wm.DragMode::ResizeSE } else { @wm.DragMode::ResizeE }))
}
return None
}
}
_ => ()
}
i = i - 1
}
None
}
///| Title-bar button under (x, y) for window `wid`: 1 minimize, 2 maximize, 3 close, 0 none. ///| Title-bar button under (x, y) for window `wid`: 1 minimize, 2 maximize, 3 close, 0 none.
/// Mirrors the layout in `build_breeze_decoration` (18px buttons, 8px apart, 10px from the right edge). /// Mirrors the layout in `build_breeze_decoration` (18px buttons, 8px apart, 10px from the right edge).
fn MoonPlasmaCompositor::title_button_at( fn MoonPlasmaCompositor::title_button_at(
@@ -828,18 +888,7 @@ pub fn MoonPlasmaCompositor::handle_input(
} }
None => () None => ()
} }
if self.handle_at(xi, yi) is Some(_) { if self.handle_at(xi, yi) is Some(_) || self.resize_at(xi, yi) is Some(_) {
self.leave_pointer()
return
}
match self.split_drag {
Some(h) => {
self.apply_actions(self.wm.drag_split(h, xi, yi, self.work_area))
return
}
None => ()
}
if self.handle_at(xi, yi) is Some(_) {
self.leave_pointer() self.leave_pointer()
return return
} }
@@ -922,7 +971,7 @@ pub fn MoonPlasmaCompositor::handle_input(
self.press_title_button(wid, btn) self.press_title_button(wid, btn)
return return
} }
if button == 272U { if button == 272U && self.resize_at(xi, yi) is None {
// Drag the window by its title bar; a tiled window becomes floating first. // Drag the window by its title bar; a tiled window becomes floating first.
self.leave_pointer() self.leave_pointer()
self.apply_actions([@wm.WmAction::Focus(wid), @wm.WmAction::Raise(wid)]) self.apply_actions([@wm.WmAction::Focus(wid), @wm.WmAction::Raise(wid)])
@@ -933,13 +982,16 @@ pub fn MoonPlasmaCompositor::handle_input(
} }
_ => () _ => ()
} }
match self.handle_at(xi, yi) { if button == 272U {
Some(h) => { match self.resize_at(xi, yi) {
self.split_drag = Some(h) Some((wid, mode)) => {
self.leave_pointer() self.leave_pointer()
return self.apply_actions([@wm.WmAction::Focus(wid), @wm.WmAction::Raise(wid)])
ignore(self.wm.start_drag(wid, mode, xi, yi))
return
}
None => ()
} }
None => ()
} }
match self.handle_at(xi, yi) { match self.handle_at(xi, yi) {
Some(h) => { Some(h) => {
@@ -1024,8 +1076,22 @@ pub fn MoonPlasmaCompositor::desired_cursor(self : MoonPlasmaCompositor) -> UInt
if shell_shape != 0U { if shell_shape != 0U {
return shell_shape return shell_shape
} }
if self.wm.drag is Some(_) { fn mode_cursor(m : @wm.DragMode) -> UInt {
return 4U match m {
Move => 4U
ResizeE | ResizeW => 26U
ResizeN | ResizeS => 27U
ResizeNW | ResizeSE => 29U
ResizeNE | ResizeSW => 28U
}
}
match self.wm.drag {
Some(d) => return mode_cursor(d.mode)
None => ()
}
match self.resize_at(self.ptr_x.to_int(), self.ptr_y.to_int()) {
Some((_, m)) => return mode_cursor(m)
None => ()
} }
let handle = match self.split_drag { let handle = match self.split_drag {
Some(h) => Some(h) Some(h) => Some(h)
+30
View File
@@ -721,3 +721,33 @@ test "dragging a title bar moves the window and floats it" {
// The other window now has the whole tiling area. // The other window now has the whole tiling area.
assert_true(comp.windows.get(1UL).unwrap().geometry.w > g0.w) assert_true(comp.windows.get(1UL).unwrap().geometry.w > g0.w)
} }
///|
test "dragging a floating window's corner resizes it" {
let socket_path = "/tmp/wayland-moon-rsz-" +
@sys.getpid().to_string() +
".sock"
let theme = @scene.ThemeTokens::moon_night()
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
let _a = open_and_configure_client(comp, socket_path, "A", "a")
let _b = open_and_configure_client(comp, socket_path, "B", "b")
// Float window 2 by dragging its title bar a little.
let g = comp.windows.get(2UL).unwrap().geometry
comp.handle_input(@nested.InputEvent::PointerMove((g.x + 40).to_double(), (g.y - 16).to_double()), 1U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
comp.handle_input(@nested.InputEvent::PointerMove((g.x + 40).to_double(), (g.y - 6).to_double()), 3U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 4U)
let g0 = comp.windows.get(2UL).unwrap().geometry
let cx = g0.x + g0.w - 1
let cy = g0.y + g0.h - 1
comp.handle_input(@nested.InputEvent::PointerMove(cx.to_double(), cy.to_double()), 5U)
assert_eq(comp.desired_cursor(), 29U) // nwse-resize on the bottom-right corner
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 6U)
comp.handle_input(@nested.InputEvent::PointerMove((cx - 50).to_double(), (cy - 40).to_double()), 7U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 8U)
let g1 = comp.windows.get(2UL).unwrap().geometry
assert_eq(g1.x, g0.x)
assert_eq(g1.y, g0.y)
assert_eq(g1.w, g0.w - 50)
assert_eq(g1.h, g0.h - 40)
}