Skip to content

Screenshots, hung out to dry. A tiny native macOS app that hangs every screenshot on a line at the top of your screen.

Swift

Keep the gaps while discarding, close them after a pause (#86)

profesorj13c155308f2d66
diff --git a/Sources/Tendedero/AppDelegate.swift b/Sources/Tendedero/AppDelegate.swift
index fccb970..5fbb5f1 100644
--- a/Sources/Tendedero/AppDelegate.swift
+++ b/Sources/Tendedero/AppDelegate.swift
@@ -526,6 +526,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
guard isRevealed else {
holdPutBackKey(false)
+ line.closeGaps()
// Resting in the menu bar brings the line down on that screen.
// Pushing against the top edge is part of it, and it also works
// when another display sits above and the pointer never stops.
@@ -559,6 +560,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
let inside = NSMouseInRect(mouse, zone, false)
if inside && pinned { pinned = false }
holdPutBackKey(inside)
+ // Gaps left by discarded photos close once the pointer moves away.
+ if !inside { line.closeGaps() }
let busy = pinned || GrabView.isDragging || GrabView.isShowingMenu
|| line.pressedID != nil || now < peekUntil
diff --git a/Sources/Tendedero/Line.swift b/Sources/Tendedero/Line.swift
index 500f5b2..9f1d832 100644
--- a/Sources/Tendedero/Line.swift
+++ b/Sources/Tendedero/Line.swift
@@ -81,6 +81,8 @@ final class Line: ObservableObject {
let thumb = makeThumbnail(url) else { return nil }
var item = Pegged(url: url, thumb: thumb)
item.flying = flying
+ // The line moves anyway for a new photo, so the gaps close with it.
+ sweepFallen()
items.append(item)
scroll = 0
// A full line lets the oldest photo fall off the far end. Only one: a
@@ -111,9 +113,25 @@ final class Line: ObservableObject {
hitRects[id] = nil
save()
if !quietly { play("Pop", volume: 0.25) }
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) { [weak self] in
- self?.items.removeAll { $0.id == id }
- }
+ lastFall = Date()
+ }
+
+ /// When the last photo started falling. A fallen photo keeps its empty
+ /// place while the pointer stays on the line, so the next cross stays
+ /// under it while discarding several in a row.
+ private var lastFall = Date.distantPast
+
+ /// The pointer left the line: the gaps close, once the last photo has
+ /// finished falling.
+ func closeGaps() {
+ guard items.contains(where: { $0.falling }),
+ Date().timeIntervalSince(lastFall) >= 0.6 else { return }
+ sweepFallen()
+ }
+
+ /// The fallen photos leave their places and the rest close up.
+ private func sweepFallen() {
+ items.removeAll { $0.falling }
}
/// "Take everything down": every photo goes the way of its corner cross.