CI / test (push) Canceled after 52s
The default frame now follows codegod100/kde aurorae (Flatkit / Flatkit Dark): the kit's neutral title bar, a 1px outline with 10px top corners, a hairline under the title, a soft 16px shadow all round, a centred title and 24px flat buttons with hover and pressed fills (close turns red). 38px title bar, 1px border. Maximized: no shadow, square corners. - scene: WindowStyle (frame sizes, button layout, hit test) and build_window_decoration; the shadow is part of the decoration ops, so the three rasterisers lost their own offset shadow and redraw 18px around a changed window. - host: the frame size follows the style (work area, wm title-bar room, CSD client boxes, hit zones, screenshots); title-bar buttons track hover, show pressed, act on release. - Settings > Session > Flat window frames (off: the old Breeze-like frame), saved as :window-style :breeze; an unknown value is logged. - docs/window-frames.md; tests for both styles' pixels, button states and switching. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hmKDDLLES2aBrrnPxT
229 lines
8.9 KiB
MoonBit
229 lines
8.9 KiB
MoonBit
///| Screenshots (Super+Shift+S overlay, Print shortcuts, the panel module's requests) and screen
|
|
/// recording.
|
|
|
|
///| A fresh compositor whose pictures and videos go to a temporary folder.
|
|
fn shot_comp(tag : String) -> (@host.ChandraCompositor, String) {
|
|
let comp = new_comp("shot-" + tag)
|
|
let dir = "/tmp/chandra-shot-" + tag + "-" + @sys.getpid().to_string()
|
|
comp.shot_dir = dir
|
|
(comp, dir)
|
|
}
|
|
|
|
///| Press or release a key.
|
|
fn key(comp : @host.ChandraCompositor, code : UInt, down : Bool, t : UInt) -> Unit {
|
|
comp.handle_input(@nested.InputEvent::Key(code, down), t)
|
|
}
|
|
|
|
///| Press `code` with modifier keys held (evdev codes) and the matching xkb mask, then let go.
|
|
fn chord(comp : @host.ChandraCompositor, mods : Array[UInt], mask : UInt, code : UInt, t : UInt) -> Unit {
|
|
for m in mods {
|
|
key(comp, m, true, t)
|
|
}
|
|
comp.handle_input(@nested.InputEvent::Modifiers(mask, 0U, 0U, 0U), t)
|
|
key(comp, code, true, t + 1U)
|
|
key(comp, code, false, t + 2U)
|
|
for m in mods {
|
|
key(comp, m, false, t + 3U)
|
|
}
|
|
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), t + 3U)
|
|
}
|
|
|
|
///| Width and height in a PNG's IHDR.
|
|
fn png_size(png : Bytes) -> (Int, Int) {
|
|
let be = fn(o : Int) {
|
|
(png[o].to_int() << 24) | (png[o + 1].to_int() << 16) | (png[o + 2].to_int() << 8) | png[o + 3].to_int()
|
|
}
|
|
(be(16), be(20))
|
|
}
|
|
|
|
///| Drag with the left button from (x0, y0) to (x1, y1).
|
|
fn drag(comp : @host.ChandraCompositor, x0 : Int, y0 : Int, x1 : Int, y1 : Int, t : UInt) -> Unit {
|
|
comp.handle_input(@nested.InputEvent::PointerMove(x0.to_double(), y0.to_double()), t)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), t + 1U)
|
|
comp.handle_input(@nested.InputEvent::PointerMove(((x0 + x1) / 2).to_double(), ((y0 + y1) / 2).to_double()), t + 2U)
|
|
comp.handle_input(@nested.InputEvent::PointerMove(x1.to_double(), y1.to_double()), t + 3U)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), t + 4U)
|
|
}
|
|
|
|
///|
|
|
test "super+shift+s: drag a region, Enter saves it as a PNG and puts it on the clipboard" {
|
|
let (comp, dir) = shot_comp("region")
|
|
// Super+Shift+S opens the overlay; nothing is saved yet and the launcher stays shut.
|
|
chord(comp, [125U, 42U], 64U | 1U, 31U, 1U)
|
|
assert_true(comp.screenshot_active())
|
|
assert_false(comp.shell.popup_open())
|
|
assert_eq(comp.last_screenshot(), "")
|
|
ignore(comp.compose_frame())
|
|
// Drag out 300 x 200 at (100, 80): the selection follows (either way round).
|
|
drag(comp, 400, 280, 100, 80, 10U)
|
|
assert_eq(comp.screenshot_selection(), Some(@scene.Rect::new(100, 80, 300, 200)))
|
|
ignore(comp.compose_frame())
|
|
// Drag inside it to move it by (20, 10).
|
|
drag(comp, 200, 150, 220, 160, 20U)
|
|
assert_eq(comp.screenshot_selection(), Some(@scene.Rect::new(120, 90, 300, 200)))
|
|
// The bottom-right handle resizes it.
|
|
drag(comp, 420, 290, 440, 300, 30U)
|
|
assert_eq(comp.screenshot_selection(), Some(@scene.Rect::new(120, 90, 320, 210)))
|
|
// Shift+Right grows it a pixel.
|
|
comp.handle_input(@nested.InputEvent::Modifiers(1U, 0U, 0U, 0U), 40U)
|
|
key(comp, 106U, true, 41U)
|
|
key(comp, 106U, false, 42U)
|
|
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), 43U)
|
|
assert_eq(comp.screenshot_selection(), Some(@scene.Rect::new(120, 90, 321, 210)))
|
|
ignore(comp.compose_frame())
|
|
// Enter takes it.
|
|
key(comp, 28U, true, 50U)
|
|
key(comp, 28U, false, 51U)
|
|
assert_false(comp.screenshot_active())
|
|
let path = comp.last_screenshot()
|
|
assert_true(path.has_prefix(dir + "/Screenshot_"))
|
|
assert_true(path.has_suffix(".png"))
|
|
let png = @sys.read_file_bytes(path)
|
|
assert_eq(png[1], b'P')
|
|
assert_eq(png_size(png), (321, 210))
|
|
assert_true(comp.server.owns_selection())
|
|
assert_true(comp.screenshot_toast_shown())
|
|
ignore(comp.compose_frame())
|
|
}
|
|
|
|
///|
|
|
test "print takes the full screen at once; a second one gets its own name" {
|
|
let (comp, _) = shot_comp("full")
|
|
key(comp, 99U, true, 1U)
|
|
key(comp, 99U, false, 2U)
|
|
assert_false(comp.screenshot_active())
|
|
let first = comp.last_screenshot()
|
|
assert_eq(png_size(@sys.read_file_bytes(first)), (1280, 720))
|
|
key(comp, 99U, true, 3U)
|
|
key(comp, 99U, false, 4U)
|
|
let second = comp.last_screenshot()
|
|
assert_true(second.length() > 0 && second != first)
|
|
}
|
|
|
|
///|
|
|
test "escape cancels the overlay; a click on a window selects it; W takes the active window" {
|
|
let socket_path = "/tmp/wayland-moon-shotwin-" + @sys.getpid().to_string() + ".sock"
|
|
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
|
|
comp.shot_dir = "/tmp/chandra-shot-win-" + @sys.getpid().to_string()
|
|
ignore(open_and_configure_client(comp, socket_path, "A", "a"))
|
|
ignore(open_and_configure_client(comp, socket_path, "B", "b"))
|
|
ignore(comp.compose_frame())
|
|
chord(comp, [125U, 42U], 65U, 31U, 1U)
|
|
assert_true(comp.screenshot_active())
|
|
key(comp, 1U, true, 5U)
|
|
key(comp, 1U, false, 6U)
|
|
assert_false(comp.screenshot_active())
|
|
assert_eq(comp.last_screenshot(), "")
|
|
// A click (no drag) inside window 1 selects it with its title bar and borders.
|
|
let g = comp.windows.get(1UL).unwrap().geometry
|
|
chord(comp, [125U, 42U], 65U, 31U, 10U)
|
|
click_at(comp, g.x + 20, g.y + 20, 20U)
|
|
assert_eq(comp.screenshot_selection(), Some(@scene.Rect::new(g.x - 1, g.y - 38, g.w + 2, g.h + 39)))
|
|
// W takes the active window (B) instead.
|
|
key(comp, 17U, true, 30U)
|
|
key(comp, 17U, false, 31U)
|
|
let gb = comp.windows.get(2UL).unwrap().geometry
|
|
assert_eq(png_size(@sys.read_file_bytes(comp.last_screenshot())), (gb.w + 2, gb.h + 39))
|
|
}
|
|
|
|
///|
|
|
test "the screenshot module's request waits for a frame, then opens the overlay" {
|
|
let (comp, _) = shot_comp("request")
|
|
comp.screenshot_request(0)
|
|
comp.step()
|
|
assert_false(comp.screenshot_active()) // no frame drawn since the request yet
|
|
ignore(comp.compose_frame())
|
|
comp.step()
|
|
assert_true(comp.screenshot_active())
|
|
comp.cancel_screenshot()
|
|
comp.screenshot_request(1)
|
|
ignore(comp.compose_frame())
|
|
comp.step()
|
|
assert_eq(png_size(@sys.read_file_bytes(comp.last_screenshot())), (1280, 720))
|
|
}
|
|
|
|
///|
|
|
test "super+alt+r records the screen to a video with ffmpeg; the REC pill stops it" {
|
|
let (comp, dir) = shot_comp("rec")
|
|
chord(comp, [125U, 56U], 64U | 8U, 19U, 1U)
|
|
if !@sys.has_exe("ffmpeg") {
|
|
assert_false(comp.recording())
|
|
assert_true(comp.screenshot_toast_shown())
|
|
return
|
|
}
|
|
assert_true(comp.recording())
|
|
assert_eq(comp.recording_rect(), Some(@scene.Rect::new(0, 0, 1280, 720)))
|
|
// Run the loop for a little over a second.
|
|
let t0 = @sys.monotonic_ms()
|
|
while @sys.monotonic_ms() - t0 < 1500UL {
|
|
comp.step()
|
|
ignore(comp.compose_frame())
|
|
@sys.sleep_ms(10)
|
|
}
|
|
assert_true(comp.recorded_frames() >= 5)
|
|
// A click on the pill stops it; ffmpeg then finishes the file.
|
|
click_at(comp, 640, 15, 100U)
|
|
assert_false(comp.recording())
|
|
let path = comp.last_recording()
|
|
assert_true(path.has_prefix(dir + "/Screencast_"))
|
|
let mut size = 0
|
|
let t1 = @sys.monotonic_ms()
|
|
while @sys.monotonic_ms() - t1 < 10000UL {
|
|
size = @sys.read_file_bytes(path).length()
|
|
if size > 0 {
|
|
@sys.sleep_ms(300) // let ffmpeg finish writing
|
|
size = @sys.read_file_bytes(path).length()
|
|
break
|
|
}
|
|
@sys.sleep_ms(50)
|
|
}
|
|
assert_true(size > 1000)
|
|
}
|
|
|
|
///|
|
|
test "super+shift+r records a region picked on the overlay" {
|
|
let (comp, _) = shot_comp("recregion")
|
|
if !@sys.has_exe("ffmpeg") {
|
|
return
|
|
}
|
|
chord(comp, [125U, 42U], 65U, 19U, 1U)
|
|
assert_true(comp.screenshot_active())
|
|
drag(comp, 100, 100, 301, 251, 10U)
|
|
key(comp, 28U, true, 20U)
|
|
key(comp, 28U, false, 21U)
|
|
assert_false(comp.screenshot_active())
|
|
// Made even-sized for the encoder.
|
|
assert_eq(comp.recording_rect(), Some(@scene.Rect::new(100, 100, 200, 150)))
|
|
// The same shortcut again stops it.
|
|
chord(comp, [125U, 42U], 65U, 19U, 30U)
|
|
assert_false(comp.recording())
|
|
}
|
|
|
|
///|
|
|
test "the screenshot panel module takes a full-screen shot without its popup in it" {
|
|
let (comp, _) = shot_comp("module")
|
|
let slot = comp.shell.slot_of("screenshot")
|
|
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
|
|
click_module(comp, "screenshot", 1U)
|
|
let pr = comp.shell.slot_popup_rect(slot)
|
|
assert_true(pr.h >= 6 * 2 + 10 * 30)
|
|
// Row 2: Full Screen. The popup closes; the picture is taken after the next frame.
|
|
click_at(comp, pr.x + 40, pr.y + 6 + 2 * 30 + 5, 5U)
|
|
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
|
|
comp.step()
|
|
assert_eq(png_size(@sys.read_file_bytes(comp.last_screenshot())), (1280, 720))
|
|
// Row 1: Rectangular Region opens the overlay.
|
|
click_module(comp, "screenshot", 10U)
|
|
click_at(comp, pr.x + 40, pr.y + 6 + 1 * 30 + 5, 15U)
|
|
comp.step()
|
|
assert_true(comp.screenshot_active())
|
|
key(comp, 1U, true, 20U)
|
|
key(comp, 1U, false, 21U)
|
|
assert_false(comp.screenshot_active())
|
|
// The pointer switch (last row) flips whether recordings show the pointer.
|
|
assert_true(comp.record_pointer())
|
|
click_module(comp, "screenshot", 30U)
|
|
click_at(comp, pr.x + 40, pr.y + 6 + 9 * 30 + 5, 35U)
|
|
assert_false(comp.record_pointer())
|
|
}
|