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 on line: up to 100 photos on a line you can scroll (#13)
Anubhav-Rai952adc8b6080
diff --git a/Sources/Tendedero/AppDelegate.swift b/Sources/Tendedero/AppDelegate.swiftindex caed6cf..df74707 100644--- a/Sources/Tendedero/AppDelegate.swift+++ b/Sources/Tendedero/AppDelegate.swift@@ -83,6 +83,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {Markup.shared.onSaved = { [weak self] url in self?.line.reloadThumbnail(for: url) }Trim.shared.onSaved = { [weak self] url in self?.line.reloadThumbnail(for: url) }+ panel.onScroll = { [weak self] event in+ // Sideways on a trackpad, or the wheel of a mouse.+ let delta = abs(event.scrollingDeltaX) >= abs(event.scrollingDeltaY)+ ? event.scrollingDeltaX : event.scrollingDeltaY+ self?.line.scroll(by: event.hasPreciseScrollingDeltas ? delta : delta * 12)+ }line.onFall = { [weak self] item in self?.fall(item) }line.$items@@ -325,7 +331,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {private func cardFrame(for id: UUID) -> CGRect? {guard let index = line.items.firstIndex(where: { $0.id == id }) else { return nil }let width = panel.frame.width- let x = Layout.x(index: index, count: line.items.count, width: width)+ let x = Layout.x(index: index, count: line.items.count, width: width,+ visible: line.visibleCount, scroll: line.scroll)let viewTop = Layout.ropeY(x: x, width: width) - Layout.pinAbovelet cardTop = viewTop + PeggedView.cardOffsetBelowToplet size = PeggedView.cardSize(for: line.items[index].thumb.size)@@ -379,6 +386,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {guard on != isRevealed else { return }isRevealed = online.revealed = on+ // It always comes down showing the newest.+ if on { line.scroll = 0 }// Tucked away, the line leaves no window behind: an invisible strip// over the top of the screen would still sit above other apps for// anything that checks what is on top, like screen automation.@@ -528,7 +537,13 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {guard !GrabView.isDragging else { return }let local = panel.convertPoint(fromScreen: mouse)let flipped = CGPoint(x: local.x, y: panel.frame.height - local.y)- let overPhoto = line.hitRects.values.contains { $0.insetBy(dx: -4, dy: -4).contains(flipped) }+ var overPhoto = line.hitRects.values.contains { $0.insetBy(dx: -4, dy: -4).contains(flipped) }+ // A line longer than the screen also takes the band the photos hang+ // in, gaps included, so a swipe anywhere along it moves it.+ if !overPhoto, line.items.count > line.visibleCount, Line.keepOnLine != nil {+ let band = line.hitRects.values.reduce(CGRect.null) { $0.union($1) }+ overPhoto = !band.isNull && flipped.y >= band.minY - 4 && flipped.y <= band.maxY + 4+ }if panel.ignoresMouseEvents == overPhoto {panel.ignoresMouseEvents = !overPhoto}@@ -562,6 +577,13 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {}}+ private func setKeep(_ n: Int?) {+ guard n != Line.keepOnLine else { return }+ Line.keepOnLine = n+ updateCapacity()+ line.trim()+ }+private func setSize(_ size: Layout.Size) {guard size != Layout.size else { return }Layout.size = size@@ -572,7 +594,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {private func updateCapacity() {let usable = panel.frame.width - 200- line.maxItems = max(3, min(12, Int(usable / Layout.spacing)))+ let fits = max(3, min(12, Int(usable / Layout.spacing)))+ line.visibleCount = fits+ line.maxItems = max(fits, Line.keepOnLine ?? fits)}// MARK: Menu bar@@ -682,6 +706,19 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {folderItem.submenu = folderMenumenu.addItem(folderItem)+ let keepItem = NSMenuItem(title: L("Keep on line"), action: nil, keyEquivalent: "")+ let keeps = NSMenu()+ let fit = ClosureMenuItem(L("As many as fit")) { [weak self] in self?.setKeep(nil) }+ fit.state = Line.keepOnLine == nil ? .on : .off+ keeps.addItem(fit)+ for n in Line.keepChoices {+ let item = ClosureMenuItem(String(format: L("%d photos"), n)) { [weak self] in self?.setKeep(n) }+ item.state = Line.keepOnLine == n ? .on : .off+ keeps.addItem(item)+ }+ keepItem.submenu = keeps+ menu.addItem(keepItem)+let sizeItem = NSMenuItem(title: L("Size"), action: nil, keyEquivalent: "")let sizes = NSMenu()for (size, title) in [(Layout.Size.small, L("Small")), (.medium, L("Medium")), (.large, L("Large"))] {diff --git a/Sources/Tendedero/Line.swift b/Sources/Tendedero/Line.swiftindex 3610d47..7b75fe7 100644--- a/Sources/Tendedero/Line.swift+++ b/Sources/Tendedero/Line.swift@@ -40,6 +40,23 @@ final class Line: ObservableObject {var hitRects: [UUID: CGRect] = [:]var maxItems = 8+ /// How many photos fit across the screen. With Keep on line set, the+ /// line can hold more, and the rest are reached by scrolling.+ var visibleCount = 8+ /// How far the line is scrolled towards older photos, in points; 0 shows+ /// the newest.+ @Published var scroll: CGFloat = 0++ /// Keep on line, from the menu bar: how many photos the line keeps, or+ /// nil for as many as fit across the screen.+ nonisolated static let keepChoices = [25, 50, 100]+ nonisolated static var keepOnLine: Int? {+ get {+ let n = UserDefaults.standard.integer(forKey: "keepOnLine")+ return keepChoices.contains(n) ? n : nil+ }+ set { UserDefaults.standard.set(newValue ?? 0, forKey: "keepOnLine") }+ }var soundOn: Bool {@@ -65,6 +82,7 @@ final class Line: ObservableObject {var item = Pegged(url: url, thumb: thumb)item.flying = flyingitems.append(item)+ scroll = 0// A full line lets the oldest photo fall off the far end. Only one: a// line hung on a wider screen keeps its length here instead of losing// several photos to a single capture.@@ -177,6 +195,22 @@ final class Line: ObservableObject {/// The oldest photo falling off a full line. Like the cross, a file from/// Tendedero's folder goes to the Trash, or nothing would ever take it out/// of that folder. If the Trash refuses it, it still leaves the line.+ /// Moves along a line that holds more than fit, from a scroll gesture.+ func scroll(by delta: CGFloat) {+ let most = CGFloat(max(0, items.count - visibleCount)) * Layout.spacing+ let next = min(most, max(0, scroll + delta))+ if next != scroll { scroll = next }+ }++ /// After Keep on line is lowered, the oldest photos past it go the way+ /// of a full line.+ func trim() {+ while liveCount > maxItems, let oldest = items.first(where: { !$0.falling }) {+ letGo(oldest.id)+ }+ scroll = 0+ }+private func letGo(_ id: UUID) {if isInInbox(id), trash(id, quietly: true) { return }drop(id, quietly: true)diff --git a/Sources/Tendedero/LinePanel.swift b/Sources/Tendedero/LinePanel.swiftindex 2729dc3..22ffc44 100644--- a/Sources/Tendedero/LinePanel.swift+++ b/Sources/Tendedero/LinePanel.swift@@ -21,6 +21,17 @@ final class LinePanel: NSPanel {contentView = content}+ /// Two-finger swipes and the scroll wheel, for moving along a long line.+ var onScroll: ((NSEvent) -> Void)?++ override func sendEvent(_ event: NSEvent) {+ if event.type == .scrollWheel, let onScroll {+ onScroll(event)+ } else {+ super.sendEvent(event)+ }+ }+override var canBecomeKey: Bool { false }override var canBecomeMain: Bool { false }diff --git a/Sources/Tendedero/LineView.swift b/Sources/Tendedero/LineView.swiftindex 9132361..359bfe4 100644--- a/Sources/Tendedero/LineView.swift+++ b/Sources/Tendedero/LineView.swift@@ -37,10 +37,16 @@ enum Layout {return ropeTop + 4 * sag(width: width) * f * (1 - f)}- /// Photos hang `spacing` apart. A line hung on a wider screen can hold- /// more than this one has room for, and then they move closer together- /// so that none ends up past the edge.- static func x(index: Int, count: Int, width: CGFloat) -> CGFloat {+ /// Photos hang `spacing` apart, centred. When there are more than the+ /// `visible` that fit: with Keep on line set, they keep their spacing,+ /// the newest stays where the last one would hang on a full line, and+ /// `scroll` brings older ones in from the left. Otherwise (a line hung+ /// on a wider screen) they move closer together so none is past the edge.+ static func x(index: Int, count: Int, width: CGFloat, visible: Int, scroll: CGFloat) -> CGFloat {+ if Line.keepOnLine != nil && count > visible {+ let newest = width / 2 + CGFloat(visible - 1) * spacing / 2+ return newest - CGFloat(count - 1 - index) * spacing + scroll+ }let gaps = CGFloat(max(count - 1, 0))let step = gaps > 0 ? min(spacing, max(0, width - 200) / gaps) : spacingreturn width / 2 - gaps * step / 2 + CGFloat(index) * step@@ -63,10 +69,13 @@ struct LineView: View {}ForEach(Array(line.items.enumerated()), id: \.element.id) { index, item in- let x = Layout.x(index: index, count: line.items.count, width: width)+ let x = Layout.x(index: index, count: line.items.count, width: width,+ visible: line.visibleCount, scroll: line.scroll)let ropeY = Layout.ropeY(x: x, width: width)PeggedView(item: item, line: line).frame(width: Layout.cardWidth, height: Layout.panelHeight - ropeY, alignment: .top)+ // Photos scrolled towards an edge fade out before they reach it.+ .opacity(min(1, max(0, min(x, width - x) / 90))).position(x: x, y: ropeY - Layout.pinAbove + (Layout.panelHeight - ropeY) / 2)}}diff --git a/Sources/Tendedero/Resources/az.lproj/Localizable.strings b/Sources/Tendedero/Resources/az.lproj/Localizable.stringsindex 7a8a05f..e1dfd22 100644--- a/Sources/Tendedero/Resources/az.lproj/Localizable.strings+++ b/Sources/Tendedero/Resources/az.lproj/Localizable.strings@@ -19,6 +19,9 @@"Quit Tendedero" = "Tendedero-dan çıx";"Could not change the login setting" = "Giriş ayarını dəyişmək alınmadı";"Move Tendedero to the Applications folder and try again." = "Tendedero-nu Applications (Proqramlar) qovluğuna köçürün və yenidən cəhd edin.";+"Keep on line" = "İpdə saxla";+"As many as fit" = "Sığdığı qədər";+"%d photos" = "%d şəkil";"Also watch folders" = "Qovluqları da izlə";"Add Folder…" = "Qovluq əlavə et…";"Stop Watching" = "İzləməyi dayandır";diff --git a/Sources/Tendedero/Resources/en.lproj/Localizable.strings b/Sources/Tendedero/Resources/en.lproj/Localizable.stringsindex 2eacb1f..03b346f 100644--- a/Sources/Tendedero/Resources/en.lproj/Localizable.strings+++ b/Sources/Tendedero/Resources/en.lproj/Localizable.strings@@ -19,6 +19,9 @@"Quit Tendedero" = "Quit Tendedero";"Could not change the login setting" = "Could not change the login setting";"Move Tendedero to the Applications folder and try again." = "Move Tendedero to the Applications folder and try again.";+"Keep on line" = "Keep on line";+"As many as fit" = "As many as fit";+"%d photos" = "%d photos";"Also watch folders" = "Also watch folders";"Add Folder…" = "Add Folder…";"Stop Watching" = "Stop Watching";diff --git a/Sources/Tendedero/Resources/es.lproj/Localizable.strings b/Sources/Tendedero/Resources/es.lproj/Localizable.stringsindex 097cc18..d218dcf 100644--- a/Sources/Tendedero/Resources/es.lproj/Localizable.strings+++ b/Sources/Tendedero/Resources/es.lproj/Localizable.strings@@ -17,6 +17,9 @@"Quit Tendedero" = "Salir de Tendedero";"Could not change the login setting" = "No se pudo cambiar el inicio de sesión";"Move Tendedero to the Applications folder and try again." = "Mueve Tendedero a la carpeta Aplicaciones y vuelve a intentarlo.";+"Keep on line" = "Guardar en la cuerda";+"As many as fit" = "Las que quepan";+"%d photos" = "%d fotos";"Also watch folders" = "Vigilar también carpetas";"Add Folder…" = "Añadir carpeta…";"Stop Watching" = "Dejar de vigilar";diff --git a/Sources/Tendedero/Resources/tr.lproj/Localizable.strings b/Sources/Tendedero/Resources/tr.lproj/Localizable.stringsindex 63b1255..81f7e47 100644--- a/Sources/Tendedero/Resources/tr.lproj/Localizable.strings+++ b/Sources/Tendedero/Resources/tr.lproj/Localizable.strings@@ -17,6 +17,9 @@"Quit Tendedero" = "Tendedero'yu kapat";"Could not change the login setting" = "Giriş ayarı değiştirilemedi";"Move Tendedero to the Applications folder and try again." = "Tendedero'yu Uygulamalar klasörüne taşıyın ve tekrar deneyin.";+"Keep on line" = "İpte tut";+"As many as fit" = "Sığdığı kadar";+"%d photos" = "%d fotoğraf";"Also watch folders" = "Klasörleri de izle";"Add Folder…" = "Klasör ekle…";"Stop Watching" = "İzlemeyi durdur";diff --git a/Sources/Tendedero/Resources/zh-Hans.lproj/Localizable.strings b/Sources/Tendedero/Resources/zh-Hans.lproj/Localizable.stringsindex a28a3bf..913f708 100644--- a/Sources/Tendedero/Resources/zh-Hans.lproj/Localizable.strings+++ b/Sources/Tendedero/Resources/zh-Hans.lproj/Localizable.strings@@ -17,6 +17,9 @@"Quit Tendedero" = "退出 Tendedero";"Could not change the login setting" = "无法更改登录项设置";"Move Tendedero to the Applications folder and try again." = "请先把 Tendedero 移到「应用程序」文件夹,再试一次。";+"Keep on line" = "绳上保留";+"As many as fit" = "放得下的数量";+"%d photos" = "%d 张";"Also watch folders" = "同时监视文件夹";"Add Folder…" = "添加文件夹…";"Stop Watching" = "停止监视";