///| fn apps(n : Int) -> Array[@types.AppEntry] { Array::makei(n, i => { id: "app" + i.to_string(), name: ["Files", "Firefox", "Konsole", "Kate", "Gimp", "Foot"][i % 6] + i.to_string(), comment: "", category: "", glyph: "A", }) } ///| fn desk() -> @icondesk.Desk { let d = @icondesk.Desk::new() // 1000 x 600 with a 40 px panel: medium cells (96) -> 10 columns, 5 rows. d.w = 1000 d.h = 600 d.bottom = 40 d } ///| test "icons fill the grid a column at a time" { let d = desk() assert_eq(d.grid(), (10, 5)) let a = apps(20) let cells = d.layout(a) assert_eq(cells.length(), 12) // "12" apps shown by default assert_eq(cells[0], (0, 0)) assert_eq(cells[4], (0, 4)) assert_eq(cells[5], (1, 0)) ignore(d.set_config("count", "All")) assert_eq(d.layout(a).length(), 20) } ///| test "click launches, drag moves and swaps, positions round-trip through the setting" { let d = desk() let a = apps(12) // Cell (0,0) holds app0 at x 20..116, y 20..116. assert_eq(d.app_at(a, 60, 60), "app0") assert_eq(d.app_at(a, 5, 5), "") ignore(d.handle(a, PointerDown({ x: 60, y: 60 }))) assert_eq(d.handle(a, PointerUp({ x: 61, y: 61 })), (true, Launch("app0"))) // Drag app0 onto app5's cell (1,0): they swap. ignore(d.handle(a, PointerDown({ x: 60, y: 60 }))) ignore(d.handle(a, PointerMove({ x: 120, y: 62 }))) assert_true(d.dragging) assert_eq(d.handle(a, PointerUp({ x: 160, y: 62 })), (true, NoAction)) let cells = d.layout(a) assert_eq(cells[0], (1, 0)) assert_eq(cells[5], (0, 0)) // Drag app1 to an empty cell far away. ignore(d.handle(a, PointerDown({ x: 60, y: 150 }))) ignore(d.handle(a, PointerMove({ x: 900, y: 400 }))) ignore(d.handle(a, PointerUp({ x: 900, y: 400 }))) assert_eq(d.layout(a)[1], (9, 3)) // The hidden setting keeps it. let saved = d.config_items().filter(c => c.key == "places")[0] assert_eq(saved.label, "") let d2 = desk() ignore(d2.set_config("places", saved.value)) assert_eq(d2.layout(a), d.layout(a)) // A place off the grid (a smaller screen) falls back to a free cell. d2.w = 400 assert_true(d2.layout(a)[1].0 < 3) } ///| test "keyboard moves the selection and launches" { let d = desk() let a = apps(12) ignore(d.handle(a, KeyDown("ArrowDown"))) assert_eq(d.selected, "app0") ignore(d.handle(a, KeyDown("ArrowDown"))) assert_eq(d.selected, "app1") ignore(d.handle(a, KeyDown("ArrowRight"))) assert_eq(d.selected, "app6") assert_eq(d.handle(a, KeyDown("Enter")), (false, Launch("app6"))) // A letter jumps to the next app with that initial. ignore(d.handle(a, KeyDown("k"))) assert_eq(d.selected, "app8") // Konsole8 (Kate9 comes after it) ignore(d.handle(a, KeyDown("Escape"))) assert_eq(d.selected, "") ignore(d.handle(a, FocusLost)) assert_false(d.focused) }