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

Bring the line down: menu bar, new items and full screen apps (#14)

Anubhav-Rai6e1d2e844596
diff --git a/Sources/Tendedero/AppDelegate.swift b/Sources/Tendedero/AppDelegate.swift
index 800fa9c..ffd72d1 100644
--- a/Sources/Tendedero/AppDelegate.swift
+++ b/Sources/Tendedero/AppDelegate.swift
@@ -42,6 +42,23 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
/// Set when you open the line on purpose, so it stays up while empty.
private var keepOpen = false
+ // What brings the line down, from the menu bar's "Bring the line down".
+ // Out of the box, the first two are on and the third off.
+
+ /// Resting the pointer in the menu bar. Off, only the shortcut and the
+ /// menu open it.
+ static var opensFromMenuBar: Bool {
+ get { !UserDefaults.standard.bool(forKey: "menuBarRevealOff") }
+ set { UserDefaults.standard.set(!newValue, forKey: "menuBarRevealOff") }
+ }
+
+ /// Something new hanging shows itself for a moment. Off, it hangs
+ /// quietly and waits for you to bring the line down.
+ static var peeksAtNew: Bool {
+ get { !UserDefaults.standard.bool(forKey: "quietHang") }
+ set { UserDefaults.standard.set(!newValue, forKey: "quietHang") }
+ }
+
func applicationDidFinishLaunching(_ notification: Notification) {
let host = NSHostingView(rootView: LineView(line: line))
host.sizingOptions = []
@@ -201,7 +218,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
updateCapacity()
wanted = true
refresh()
- reveal(peekFor: 2.5)
+ if Self.peeksAtNew { reveal(peekFor: 2.5) }
}
// MARK: The capture flying to the line
@@ -274,8 +291,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
/// Decides whether the panel is ordered in at all: something to show,
/// and no full screen app on that screen.
private func refresh() {
- let blocked = panel.screen.map(FullScreen.isActive(on:))
- ?? LinePanel.screenUnderPointer().map(FullScreen.isActive(on:)) ?? false
+ let blocked = panel.screen.map(FullScreen.blocksLine(on:))
+ ?? LinePanel.screenUnderPointer().map(FullScreen.blocksLine(on:)) ?? false
if wanted && !blocked {
present()
} else {
@@ -417,8 +434,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
// 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.
- if let screen = screenUnderPointer, inMenuBar, !menuBarSuppressed,
- !FullScreen.isActive(on: screen) {
+ if Self.opensFromMenuBar, let screen = screenUnderPointer, inMenuBar, !menuBarSuppressed,
+ !FullScreen.blocksLine(on: screen) {
let since = hotZoneSince ?? now
hotZoneSince = since
if now.timeIntervalSince(since) >= Self.revealDelay {
@@ -527,6 +544,27 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
clipboard.toolTip = L("Images you copy hang on the line too")
menu.addItem(clipboard)
+ let bringDown = NSMenuItem(title: L("Bring the line down"), action: nil, keyEquivalent: "")
+ let options = NSMenu()
+ let hover = ClosureMenuItem(L("When the pointer rests in the menu bar")) {
+ AppDelegate.opensFromMenuBar.toggle()
+ }
+ hover.state = Self.opensFromMenuBar ? .on : .off
+ options.addItem(hover)
+ let peek = ClosureMenuItem(L("When something new hangs")) {
+ AppDelegate.peeksAtNew.toggle()
+ }
+ peek.state = Self.peeksAtNew ? .on : .off
+ options.addItem(peek)
+ let fullScreen = ClosureMenuItem(L("Over full screen apps")) { [weak self] in
+ FullScreen.showLineOver.toggle()
+ self?.refresh()
+ }
+ fullScreen.state = FullScreen.showLineOver ? .on : .off
+ options.addItem(fullScreen)
+ bringDown.submenu = options
+ menu.addItem(bringDown)
+
menu.addItem(ClosureMenuItem(L("Open screenshots folder")) { [weak self] in
guard let self else { return }
NSWorkspace.shared.open(self.watcher.folder)
diff --git a/Sources/Tendedero/CaptureFlight.swift b/Sources/Tendedero/CaptureFlight.swift
index 318ff0c..227efa0 100644
--- a/Sources/Tendedero/CaptureFlight.swift
+++ b/Sources/Tendedero/CaptureFlight.swift
@@ -93,7 +93,7 @@ final class CaptureFlight {
window.hasShadow = false
window.ignoresMouseEvents = true
window.level = NSWindow.Level(rawValue: NSWindow.Level.floating.rawValue + 1)
- window.collectionBehavior = [.canJoinAllSpaces, .stationary, .ignoresCycle]
+ window.collectionBehavior = [.canJoinAllSpaces, .stationary, .ignoresCycle, .fullScreenAuxiliary]
let host = NSView(frame: NSRect(origin: .zero, size: screen.frame.size))
host.wantsLayer = true
diff --git a/Sources/Tendedero/FullScreen.swift b/Sources/Tendedero/FullScreen.swift
index ab68248..aa1ce61 100644
--- a/Sources/Tendedero/FullScreen.swift
+++ b/Sources/Tendedero/FullScreen.swift
@@ -12,6 +12,19 @@ private func CGSCopyManagedDisplaySpaces(_ connection: Int32) -> CFArray
enum FullScreen {
private static let fullScreenSpaceType = 4
+ /// Whether the line also comes down over full screen apps, so screenshots
+ /// stay within reach while you work in one. Off unless turned on: a video
+ /// or a presentation should not get a clothesline across the top.
+ static var showLineOver: Bool {
+ get { UserDefaults.standard.bool(forKey: "showOverFullScreen") }
+ set { UserDefaults.standard.set(newValue, forKey: "showOverFullScreen") }
+ }
+
+ /// True when the line should keep away from the given screen.
+ static func blocksLine(on screen: NSScreen) -> Bool {
+ !showLineOver && isActive(on: screen)
+ }
+
/// True when the given screen is currently showing a full screen app,
/// like a video or a presentation.
static func isActive(on screen: NSScreen) -> Bool {
diff --git a/Sources/Tendedero/LinePanel.swift b/Sources/Tendedero/LinePanel.swift
index 613de7f..2729dc3 100644
--- a/Sources/Tendedero/LinePanel.swift
+++ b/Sources/Tendedero/LinePanel.swift
@@ -11,9 +11,9 @@ final class LinePanel: NSPanel {
backgroundColor = .clear
hasShadow = false
level = .floating
- // Every Space except full screen ones: a video or a presentation in full
- // screen should never get a clothesline across the top.
- collectionBehavior = [.canJoinAllSpaces, .stationary, .ignoresCycle]
+ // Every Space, full screen ones included. Whether the line comes down
+ // over a full screen app is up to the user, see FullScreen.showLineOver.
+ collectionBehavior = [.canJoinAllSpaces, .stationary, .ignoresCycle, .fullScreenAuxiliary]
hidesOnDeactivate = false
isMovable = false
becomesKeyOnlyIfNeeded = true
diff --git a/Sources/Tendedero/Resources/az.lproj/Localizable.strings b/Sources/Tendedero/Resources/az.lproj/Localizable.strings
index eeec7ab..61c6a4c 100644
--- a/Sources/Tendedero/Resources/az.lproj/Localizable.strings
+++ b/Sources/Tendedero/Resources/az.lproj/Localizable.strings
@@ -18,6 +18,10 @@
"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.";
+"Bring the line down" = "İpi endir";
+"When the pointer rests in the menu bar" = "Göstərici menyu panelində dayananda";
+"When something new hangs" = "Yeni bir şey asılanda";
+"Over full screen apps" = "Tam ekran proqramların üzərində";
"Hang copied images" = "Kopyalanmış şəkilləri as";
"Images you copy hang on the line too" = "Kopyaladığınız şəkillər də ipdən asılır";
"Tendedero, hanging copied images" = "Tendedero, kopyalanmış şəkilləri asır";
diff --git a/Sources/Tendedero/Resources/en.lproj/Localizable.strings b/Sources/Tendedero/Resources/en.lproj/Localizable.strings
index b91a0be..05fe13b 100644
--- a/Sources/Tendedero/Resources/en.lproj/Localizable.strings
+++ b/Sources/Tendedero/Resources/en.lproj/Localizable.strings
@@ -18,6 +18,10 @@
"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.";
+"Bring the line down" = "Bring the line down";
+"When the pointer rests in the menu bar" = "When the pointer rests in the menu bar";
+"When something new hangs" = "When something new hangs";
+"Over full screen apps" = "Over full screen apps";
"Hang copied images" = "Hang copied images";
"Images you copy hang on the line too" = "Images you copy hang on the line too";
"Tendedero, hanging copied images" = "Tendedero, hanging copied images";
diff --git a/Sources/Tendedero/Resources/es.lproj/Localizable.strings b/Sources/Tendedero/Resources/es.lproj/Localizable.strings
index 2b1f86e..5933053 100644
--- a/Sources/Tendedero/Resources/es.lproj/Localizable.strings
+++ b/Sources/Tendedero/Resources/es.lproj/Localizable.strings
@@ -16,6 +16,10 @@
"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.";
+"Bring the line down" = "Bajar la cuerda";
+"When the pointer rests in the menu bar" = "Al dejar el puntero en la barra de menús";
+"When something new hangs" = "Cuando se cuelga algo nuevo";
+"Over full screen apps" = "Sobre apps a pantalla completa";
"Hang copied images" = "Colgar imágenes copiadas";
"Images you copy hang on the line too" = "Las imágenes que copias también se cuelgan";
"Tendedero, hanging copied images" = "Tendedero, colgando imágenes copiadas";
diff --git a/Sources/Tendedero/Resources/tr.lproj/Localizable.strings b/Sources/Tendedero/Resources/tr.lproj/Localizable.strings
index 74e765e..e89c7a6 100644
--- a/Sources/Tendedero/Resources/tr.lproj/Localizable.strings
+++ b/Sources/Tendedero/Resources/tr.lproj/Localizable.strings
@@ -16,6 +16,10 @@
"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.";
+"Bring the line down" = "İpi indir";
+"When the pointer rests in the menu bar" = "İşaretçi menü çubuğunda durduğunda";
+"When something new hangs" = "Yeni bir şey asıldığında";
+"Over full screen apps" = "Tam ekran uygulamaların üzerinde";
"Hang copied images" = "Kopyalanan görselleri as";
"Images you copy hang on the line too" = "Kopyaladığınız görseller de ipe asılır";
"Tendedero, hanging copied images" = "Tendedero, kopyalanan görselleri asıyor";
diff --git a/Sources/Tendedero/Resources/zh-Hans.lproj/Localizable.strings b/Sources/Tendedero/Resources/zh-Hans.lproj/Localizable.strings
index 07033d9..9395ab6 100644
--- a/Sources/Tendedero/Resources/zh-Hans.lproj/Localizable.strings
+++ b/Sources/Tendedero/Resources/zh-Hans.lproj/Localizable.strings
@@ -16,6 +16,10 @@
"Quit Tendedero" = "退出 Tendedero";
"Could not change the login setting" = "无法更改登录项设置";
"Move Tendedero to the Applications folder and try again." = "请先把 Tendedero 移到「应用程序」文件夹,再试一次。";
+"Bring the line down" = "放下晾衣绳";
+"When the pointer rests in the menu bar" = "指针停在菜单栏时";
+"When something new hangs" = "有新内容挂上时";
+"Over full screen apps" = "在全屏 App 上";
"Hang copied images" = "挂上复制的图片";
"Images you copy hang on the line too" = "复制的图片也会挂上绳";
"Tendedero, hanging copied images" = "Tendedero,正在挂上复制的图片";