:windows {"app.id" {:x :y :w :h}} is written when a floating window is dragged or resized and
read at startup; an app opening later gets its last place (floating, clamped on screen).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4b99b0063e
commit
235f17cd70
4 files changed
+121
-6
No files matched your search
@@ -199,19 +199,32 @@ pub fn MoonPlasmaCompositor::step(self : MoonPlasmaCompositor) -> Unit {
|
||||
cfg_dirty: false,
|
||||
}
|
||||
self.windows.set(wid, win)
|
||||
// An app whose window was last left somewhere reopens there, floating, kept on screen.
|
||||
let saved = self.shell.saved_window(app_id)
|
||||
let g : @wm.Rect = match saved {
|
||||
Some((sx, sy, sw, sh)) => {
|
||||
let w = if sw > self.output_w { self.output_w } else { sw }
|
||||
let h = if sh > self.output_h { self.output_h } else { sh }
|
||||
let x = if sx + w > self.output_w { self.output_w - w } else if sx < 0 { 0 } else { sx }
|
||||
let y = if sy + h > self.output_h { self.output_h - h } else if sy < 32 { 32 } else { sy }
|
||||
{ x, y, w, h }
|
||||
}
|
||||
None => { x: 100, y: 100, w: 640, h: 480 }
|
||||
}
|
||||
win.geometry = @scene.Rect::new(g.x, g.y, g.w, g.h)
|
||||
let rec : @wm.WindowRecord = {
|
||||
id: wid,
|
||||
app_id,
|
||||
title,
|
||||
geometry: { x: 100, y: 100, w: 640, h: 480 },
|
||||
floating_geometry: { x: 100, y: 100, w: 640, h: 480 },
|
||||
geometry: g,
|
||||
floating_geometry: g,
|
||||
min_size: { w: min_w, h: min_h },
|
||||
max_size: None,
|
||||
focused: true,
|
||||
maximized: false,
|
||||
fullscreen: false,
|
||||
minimized: false,
|
||||
is_floating: false,
|
||||
is_floating: saved is Some(_),
|
||||
workspace: 0U,
|
||||
can_move: true,
|
||||
can_resize: true,
|
||||
@@ -983,7 +996,16 @@ pub fn MoonPlasmaCompositor::handle_input(
|
||||
return
|
||||
}
|
||||
if !pressed && self.wm.drag is Some(_) {
|
||||
let dragged = self.wm.drag.unwrap().win_id
|
||||
self.wm.end_drag()
|
||||
// Remember where a floating window was left.
|
||||
match (self.wm.windows.get(dragged), self.windows.get(dragged)) {
|
||||
(Some(r), Some(win)) =>
|
||||
if r.is_floating && !r.maximized && !r.fullscreen {
|
||||
self.shell.remember_window(win.app_id, win.geometry.x, win.geometry.y, win.geometry.w, win.geometry.h)
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
self.flush_configures()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -943,3 +943,38 @@ test "clicking a floating window brings it in front of the others" {
|
||||
assert_eq(after[1], back)
|
||||
assert_eq(after[0], front)
|
||||
}
|
||||
|
||||
///|
|
||||
test "a window dragged somewhere reopens there, saved per app in state.edn" {
|
||||
if @sys.getenv("MOON_PLASMA_TEST_CONFIG") == "1" {
|
||||
write_state_edn("{:note \"keep\"}\n")
|
||||
let sock1 = "/tmp/wayland-moon-wp1-" + @sys.getpid().to_string() + ".sock"
|
||||
let theme = @scene.ThemeTokens::moon_night()
|
||||
let a = @host.MoonPlasmaCompositor::new(sock1, theme, 1280, 720).unwrap()
|
||||
a.shell.persist = true
|
||||
a.set_layout_mode(@wm.LayoutMode::Floating)
|
||||
ignore(open_and_configure_client(a, sock1, "T", "org.test.app"))
|
||||
ignore(a.compose_frame())
|
||||
let g0 = a.windows.get(1UL).unwrap().geometry
|
||||
// Drag its title bar 120px right and 60px down.
|
||||
a.handle_input(@nested.InputEvent::PointerMove((g0.x + 20).to_double(), (g0.y - 16).to_double()), 10U)
|
||||
a.handle_input(@nested.InputEvent::PointerButton(272U, true), 11U)
|
||||
a.handle_input(@nested.InputEvent::PointerMove((g0.x + 140).to_double(), (g0.y + 44).to_double()), 12U)
|
||||
a.handle_input(@nested.InputEvent::PointerButton(272U, false), 13U)
|
||||
let g1 = a.windows.get(1UL).unwrap().geometry
|
||||
assert_true(g1.x != g0.x || g1.y != g0.y)
|
||||
let text = read_state_edn()
|
||||
assert_true(text.contains("\"org.test.app\"") && text.contains(":windows"))
|
||||
assert_true(text.contains(":note \"keep\""))
|
||||
// A new session: the same app opens where it was left.
|
||||
let sock2 = "/tmp/wayland-moon-wp2-" + @sys.getpid().to_string() + ".sock"
|
||||
let b = @host.MoonPlasmaCompositor::new(sock2, theme, 1280, 720).unwrap()
|
||||
b.shell.persist = true
|
||||
b.restore_state()
|
||||
ignore(open_and_configure_client(b, sock2, "T", "org.test.app"))
|
||||
ignore(b.compose_frame())
|
||||
let g2 = b.windows.get(1UL).unwrap().geometry
|
||||
assert_eq(g2.x, g1.x)
|
||||
assert_eq(g2.y, g1.y)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user