Screenshot module after Spectacle (Super+Shift+S), with a screen recorder
CI / test (push) Failing after 16s
CI / test (push) Failing after 16s
- Super+Shift+S (or Super+Shift+Print) freezes the screen under a selection overlay, like Spectacle's Rectangular Region: drag a rectangle (size readout under it, magnifier while drawing), drag inside to move it, drag its handles to resize, or click a window to select it. Enter or a double-click takes it, Escape or right-click cancels; F full screen, W active window, arrows nudge (Shift+arrows resize). Print takes the full screen, Super+Print the active window, Super+Ctrl+Print the window under the pointer. - Saved as ~/Pictures/Screenshots/Screenshot_YYYYMMDD_HHMMSS.png (XDG_PICTURES_DIR honoured), put on the clipboard as image/png (compositor-owned wl_data selection, written to the paste pipe without blocking), and confirmed by a notification with a thumbnail. - Screen recording: Super+Shift+R picks a region on the same overlay, Super+Alt+R the screen, Super+Ctrl+R a window; the same shortcut or the REC pill (top centre) stops. Raw frames (<= 30 fps, wall-clock stamped) stream into ffmpeg over a unix socket; it writes H.264 MP4 to ~/Videos/Screencasts/Screencast_*.mp4. The pointer is drawn in unless switched off. - renderer: encode_png_compressed (per-row filters + LZ77/fixed-Huffman deflate): a 1280x720 desktop is ~90 KB instead of 3.7 MB. - New 'screenshot' capability and 'screenshot' panel module (in the default panel): Spectacle's modes and the recording modes with their shortcuts, and a pointer switch; the button becomes Stop while recording. Served by both hosts (wasmer stub request 12 / host int 4; host-wasm publish-screenshot and a screenshot request). Panel requests wait for a frame without the module's popup. - sys: pwrite with a negative offset is a non-blocking write (pipes, sockets), SIGPIPE ignored. - Tests: native overlay, shortcuts, window pick, module, recording (with ffmpeg); host-wasm module test; renderer compression test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hjMGSLc5tHuzjsxGVa
This commit is contained in:
45 files changed
+3177
-57
No files matched your search
@@ -251,6 +251,12 @@ pub(all) struct WaylandServer {
|
||||
/// Area a popup must stay inside, as (x, y, w, h) relative to its parent's content origin
|
||||
/// (the parent window id is passed). The host sets this; the default never constrains.
|
||||
mut popup_bounds : (UInt64) -> (Int, Int, Int, Int)
|
||||
/// What the compositor itself offers on the clipboard (a screenshot) while `selection` is
|
||||
/// `Some((0, 0))`: its mime types and bytes.
|
||||
mut own_mimes : Array[String]
|
||||
mut own_data : Bytes
|
||||
/// Clipboard pastes of `own_data` still being written: (pipe fd, bytes written, give up at ms).
|
||||
transfers : Array[(Int, Int, UInt64)]
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -277,11 +283,18 @@ pub fn WaylandServer::listen(
|
||||
selection: None,
|
||||
kbd_client: None,
|
||||
popup_bounds: fn(_) { (-1000000, -1000000, 2000000, 2000000) },
|
||||
own_mimes: [],
|
||||
own_data: Bytes::from_array([]),
|
||||
transfers: [],
|
||||
})
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn WaylandServer::close(self : WaylandServer) -> Unit {
|
||||
for t in self.transfers {
|
||||
@sys.close_fd(t.0)
|
||||
}
|
||||
self.transfers.clear()
|
||||
for c in self.clients {
|
||||
c.close_all()
|
||||
}
|
||||
@@ -688,7 +701,16 @@ fn WaylandServer::dispatch_msg(
|
||||
// receive(mime_type, fd): ask the owner to write the data into the fd
|
||||
let mime = reader.str()
|
||||
let fd = c.take_fd()
|
||||
if fd >= 0 {
|
||||
if fd >= 0 && ocid == 0U {
|
||||
// The compositor's own clipboard: write it out a piece at a time (pump_transfers),
|
||||
// so a client that is slow to read can't stall the desktop.
|
||||
if self.selection == Some((0U, 0U)) && self.own_mimes.contains(mime) {
|
||||
self.transfers.push((fd, 0, @sys.monotonic_ms() + 10000UL))
|
||||
self.pump_transfers()
|
||||
} else {
|
||||
@sys.close_fd(fd)
|
||||
}
|
||||
} else if fd >= 0 {
|
||||
match self.find_client(ocid) {
|
||||
Some(oc) =>
|
||||
if oc.data_sources.contains(osid) {
|
||||
@@ -1105,6 +1127,7 @@ pub fn WaylandServer::poll_events(
|
||||
self : WaylandServer,
|
||||
) -> Array[CompositorEvent] {
|
||||
let events : Array[CompositorEvent] = []
|
||||
self.pump_transfers()
|
||||
|
||||
// Accept any pending connections
|
||||
while true {
|
||||
@@ -1683,6 +1706,7 @@ pub fn WaylandServer::popup_done(self : WaylandServer, win_id : UInt64) -> Unit
|
||||
///| Offer the current clipboard to `c`'s data devices (or clear it if there is none).
|
||||
fn WaylandServer::send_selection(self : WaylandServer, c : ClientConn) -> Unit {
|
||||
let mimes : Array[String] = match self.selection {
|
||||
Some((0U, 0U)) => self.own_mimes
|
||||
Some((ocid, osid)) =>
|
||||
match self.find_client(ocid) {
|
||||
Some(oc) =>
|
||||
@@ -1732,3 +1756,72 @@ fn WaylandServer::notify_selection(self : WaylandServer) -> Unit {
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| Put `data` on the clipboard as the compositor's own selection, offered as `mime_types`
|
||||
/// (a screenshot: image/png). Whoever owned the clipboard is told it was replaced, and the
|
||||
/// focused client gets the new offer at once.
|
||||
pub fn WaylandServer::set_own_selection(
|
||||
self : WaylandServer,
|
||||
mime_types : Array[String],
|
||||
data : Bytes,
|
||||
) -> Unit {
|
||||
match self.selection {
|
||||
Some((ocid, osid)) =>
|
||||
if ocid != 0U {
|
||||
match self.find_client(ocid) {
|
||||
Some(oc) => oc.send_msg(WireWriter::new().finish_msg(osid, 2U)) // cancelled
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
self.own_mimes = mime_types
|
||||
self.own_data = data
|
||||
self.selection = Some((0U, 0U))
|
||||
self.notify_selection()
|
||||
}
|
||||
|
||||
///| Whether the clipboard holds the compositor's own data (no client has replaced it since).
|
||||
pub fn WaylandServer::owns_selection(self : WaylandServer) -> Bool {
|
||||
self.selection == Some((0U, 0U))
|
||||
}
|
||||
|
||||
///| Write what the pipes of pending pastes can take without blocking; close the finished ones
|
||||
/// and any a reader stopped taking for ten seconds.
|
||||
pub fn WaylandServer::pump_transfers(self : WaylandServer) -> Unit {
|
||||
if self.transfers.length() == 0 {
|
||||
return
|
||||
}
|
||||
let total = self.own_data.length()
|
||||
let now = @sys.monotonic_ms()
|
||||
let keep : Array[(Int, Int, UInt64)] = []
|
||||
for t in self.transfers {
|
||||
let (fd, sent0, deadline) = t
|
||||
let mut sent = sent0
|
||||
let mut ok = true
|
||||
while sent < total {
|
||||
let len = if total - sent > 65536 { 65536 } else { total - sent }
|
||||
let n = @sys.write_nonblock(fd, self.own_data[sent:sent + len].to_bytes())
|
||||
if n < 0 {
|
||||
ok = false
|
||||
break
|
||||
}
|
||||
if n == 0 {
|
||||
break // the pipe is full: the rest goes out on a later turn
|
||||
}
|
||||
sent = sent + n
|
||||
}
|
||||
if ok && sent < total && now < deadline {
|
||||
keep.push((fd, sent, deadline))
|
||||
} else {
|
||||
@sys.close_fd(fd)
|
||||
}
|
||||
}
|
||||
self.transfers.clear()
|
||||
self.transfers.append(keep)
|
||||
}
|
||||
|
||||
///| Pastes of the compositor's clipboard still being written.
|
||||
pub fn WaylandServer::pending_transfers(self : WaylandServer) -> Int {
|
||||
self.transfers.length()
|
||||
}
|
||||
Reference in new issue
Block a user