:desktop-card {:x N :y N} is written when the card is dropped (and kept on later saves),
and restored at startup; the existing clamp keeps it on screen if the resolution changed.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
61796b9f69
commit
69a163bc08
3 files changed
+74
-4
No files matched your search
@@ -900,3 +900,25 @@ test "the layout mode and recent apps are saved to state.edn and restored; other
|
||||
assert_eq(c.layout_mode, @wm.LayoutMode::Tiling)
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "the desktop card position is saved when dropped and restored" {
|
||||
if @sys.getenv("MOON_PLASMA_TEST_CONFIG") == "1" {
|
||||
write_state_edn("{:note \"keep\"}\n")
|
||||
let a = new_comp("card-a")
|
||||
a.shell.persist = true
|
||||
ignore(a.compose_frame())
|
||||
assert_true(a.shell.desk_press(a.shell.screen_w - 100, 40))
|
||||
ignore(a.shell.pointer_move(300, 200))
|
||||
assert_true(a.shell.pointer_up())
|
||||
let text = read_state_edn()
|
||||
assert_true(text.contains(":desktop-card"))
|
||||
assert_true(text.contains(":note \"keep\""))
|
||||
let b = new_comp("card-b")
|
||||
b.shell.persist = true
|
||||
b.restore_state()
|
||||
assert_true(b.shell.desk_set)
|
||||
assert_eq(b.shell.desk_x, a.shell.desk_x)
|
||||
assert_eq(b.shell.desk_y, a.shell.desk_y)
|
||||
}
|
||||
}
|
||||
@@ -617,6 +617,7 @@ fn DesktopShell::reorder_dragged(self : DesktopShell, x : Int) -> Unit {
|
||||
pub fn DesktopShell::pointer_up(self : DesktopShell) -> Bool {
|
||||
if self.desk_drag {
|
||||
self.desk_drag = false
|
||||
self.save_state() // remember where the card was dropped
|
||||
return true
|
||||
}
|
||||
let slot = self.drag_slot
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
/// $XDG_CONFIG_HOME/moon-plasma/state.edn (next to panel.edn, which holds the module list):
|
||||
///
|
||||
/// {:layout :tiling ; the Tile | Float switcher: :tiling, :monocle or :floating
|
||||
/// :recent ["foot" "dolphin"]} ; the launcher's recently started apps, newest first
|
||||
/// :recent ["foot" "dolphin"] ; the launcher's recently started apps, newest first
|
||||
/// :desktop-card {:x 900 :y 24}} ; where the desktop card was dragged to (absent: default spot)
|
||||
///
|
||||
/// Saving merges into what is already in the file, so keys this build doesn't know (a future
|
||||
/// widget's state, hand-written notes) survive. Everything is a no-op unless `persist` is on
|
||||
@@ -14,6 +15,8 @@ pub(all) struct SavedState {
|
||||
/// 0 tiling, 1 monocle, 2 floating (the order of the layout list).
|
||||
layout : Int?
|
||||
recent : Array[String]?
|
||||
/// Top-left of the desktop card, when it was moved.
|
||||
desk : (Int, Int)?
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -25,7 +28,7 @@ fn state_path() -> String {
|
||||
let layout_names : Array[String] = ["tiling", "monocle", "floating"]
|
||||
|
||||
///| The keys this build owns; everything else in the file is kept as it is.
|
||||
let owned_keys : Array[String] = ["layout", "recent"]
|
||||
let owned_keys : Array[String] = ["layout", "recent", "desktop-card"]
|
||||
|
||||
///|
|
||||
fn read_state_file() -> Array[(@edn.Value, @edn.Value)] {
|
||||
@@ -57,7 +60,7 @@ fn lookup_key(
|
||||
///| Read state.edn. Without `persist` nothing is read.
|
||||
pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
|
||||
if !self.persist {
|
||||
return { layout: None, recent: None }
|
||||
return { layout: None, recent: None, desk: None }
|
||||
}
|
||||
let entries = read_state_file()
|
||||
let layout = match lookup_key(entries, "layout") {
|
||||
@@ -97,11 +100,30 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
|
||||
None
|
||||
}
|
||||
}
|
||||
{ layout, recent }
|
||||
let desk = match lookup_key(entries, "desktop-card") {
|
||||
Some(Mapping(m)) =>
|
||||
match (lookup_key(m, "x"), lookup_key(m, "y")) {
|
||||
(Some(Integer(x)), Some(Integer(y))) => match (parse_int_str(x), parse_int_str(y)) {
|
||||
(Some(a), Some(b)) => Some((a, b))
|
||||
_ => None
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
{ layout, recent, desk }
|
||||
}
|
||||
|
||||
///| Take the saved recents (the layout is the compositor's to apply).
|
||||
pub fn DesktopShell::apply_state(self : DesktopShell, st : SavedState) -> Unit {
|
||||
match st.desk {
|
||||
Some((x, y)) => {
|
||||
self.desk_set = true
|
||||
self.desk_x = x
|
||||
self.desk_y = y
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
match st.recent {
|
||||
Some(r) => {
|
||||
self.recents.clear()
|
||||
@@ -141,6 +163,13 @@ pub fn DesktopShell::save_state(self : DesktopShell) -> Unit {
|
||||
}
|
||||
entries.insert(0, (@edn.Value::Keyword("layout"), @edn.Value::Keyword(layout)))
|
||||
entries.insert(1, (@edn.Value::Keyword("recent"), @edn.Value::Vector(recent)))
|
||||
if self.desk_set {
|
||||
let (x, y) = self.desk_pos()
|
||||
entries.insert(2, (@edn.Value::Keyword("desktop-card"), @edn.Value::Mapping([
|
||||
(@edn.Value::Keyword("x"), @edn.Value::Integer(x.to_string())),
|
||||
(@edn.Value::Keyword("y"), @edn.Value::Integer(y.to_string())),
|
||||
])))
|
||||
}
|
||||
let body : String? = try Some(@edn.pretty(@edn.Value::Mapping(entries), layout={ width: 100, indent: 1 })) catch { _ => None }
|
||||
match body {
|
||||
Some(b) => {
|
||||
@@ -153,3 +182,21 @@ pub fn DesktopShell::save_state(self : DesktopShell) -> Unit {
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| Parse an optionally negative decimal integer.
|
||||
fn parse_int_str(s : String) -> Int? {
|
||||
let neg = s.length() > 0 && s[0] == '-'
|
||||
let start = if neg { 1 } else { 0 }
|
||||
if s.length() <= start || s.length() > start + 6 {
|
||||
return None
|
||||
}
|
||||
let mut n = 0
|
||||
for i = start; i < s.length(); i = i + 1 {
|
||||
let d = s[i].to_int() - 48
|
||||
if d < 0 || d > 9 {
|
||||
return None
|
||||
}
|
||||
n = n * 10 + d
|
||||
}
|
||||
Some(if neg { -n } else { n })
|
||||
}
|
||||
Reference in new issue
Block a user