Drag windows by their title bar
CI / test (push) Failing after 17s

A press on a title bar (outside the buttons) focuses the window, floats it if it was
tiled (WmState::float_window) and starts a move drag; motion moves it, release ends it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Sonnet 5.5 committed 2026-11-25 00:42:38 -08:00
1 parent f05677178a
commit 8a3ea16b1c
3 files changed
+71 -1

No files matched your search

+24 -1
View File
@@ -119,7 +119,7 @@ fn MoonPlasmaCompositor::apply_actions(
match self.windows.get(wid) {
Some(win) => {
win.geometry = @scene.Rect::new(r.x, r.y, r.w, r.h)
if self.split_drag is Some(_) {
if self.split_drag is Some(_) || self.wm.drag is Some(_) {
// Dragging: send one configure per frame, not one per mouse event.
win.cfg_dirty = true
} else {
@@ -810,6 +810,13 @@ pub fn MoonPlasmaCompositor::handle_input(
self.shell.set_hover(id, xi, yi)
return
}
if self.wm.drag is Some(_) {
match self.wm.update_drag(xi, yi) {
Some(a) => self.apply_actions([a])
None => ()
}
return
}
if self.shell.pointer_move(xi, yi) || self.shell.hit(xi, yi) {
self.leave_pointer()
return
@@ -893,6 +900,11 @@ pub fn MoonPlasmaCompositor::handle_input(
self.split_drag = None
return
}
if !pressed && self.wm.drag is Some(_) {
self.wm.end_drag()
self.flush_configures()
return
}
// Right button over a swappable panel widget opens its alternatives menu.
if button == 273U && pressed && self.shell.right_click(xi, yi) {
return
@@ -910,6 +922,14 @@ pub fn MoonPlasmaCompositor::handle_input(
self.press_title_button(wid, btn)
return
}
if button == 272U {
// Drag the window by its title bar; a tiled window becomes floating first.
self.leave_pointer()
self.apply_actions([@wm.WmAction::Focus(wid), @wm.WmAction::Raise(wid)])
self.apply_actions(self.wm.float_window(wid, self.work_area))
ignore(self.wm.start_drag(wid, @wm.DragMode::Move, xi, yi))
return
}
}
_ => ()
}
@@ -1004,6 +1024,9 @@ pub fn MoonPlasmaCompositor::desired_cursor(self : MoonPlasmaCompositor) -> UInt
if shell_shape != 0U {
return shell_shape
}
if self.wm.drag is Some(_) {
return 4U
}
let handle = match self.split_drag {
Some(h) => Some(h)
None => self.handle_at(self.ptr_x.to_int(), self.ptr_y.to_int())
+24
View File
@@ -697,3 +697,27 @@ test "the dock module magnifies the tile under the pointer and shows nothing whe
comp.handle_input(@nested.InputEvent::PointerMove(640.0, 300.0), 2U)
assert_eq(comp.shell.hover_slot, "")
}
///|
test "dragging a title bar moves the window and floats it" {
let socket_path = "/tmp/wayland-moon-wdrag-" +
@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")
let g0 = comp.windows.get(2UL).unwrap().geometry
let sx = g0.x + g0.w / 3
let sy = g0.y - 16 // inside the title bar, clear of the buttons
comp.handle_input(@nested.InputEvent::PointerMove(sx.to_double(), sy.to_double()), 1U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
comp.handle_input(@nested.InputEvent::PointerMove((sx - 120).to_double(), (sy + 60).to_double()), 3U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 4U)
let g1 = comp.windows.get(2UL).unwrap().geometry
assert_eq(g1.x, g0.x - 120)
assert_eq(g1.y, g0.y + 60)
assert_eq(g1.w, g0.w)
// The other window now has the whole tiling area.
assert_true(comp.windows.get(1UL).unwrap().geometry.w > g0.w)
}