Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
cdcafd8
✨ List windows and screens through loop:// URLs, with JSON results
mrkai77 Mar 18, 2026
271f6a5
✨ Add an installable loop command-line tool
mrkai77 Mar 18, 2026
2ad8f6f
♻️ Rewrite the CLI and URL commands around shared code
mrkai77 Oct 9, 2026
c5bc13c
🐞 Keep the CLI socket across relaunches and time out stalled clients
mrkai77 Nov 22, 2026
c50abc6
✨ Run any action, keybind, gesture or radial menu action from the CLI
mrkai77 Nov 22, 2026
3e538d6
🐞 Harden the privileged helper
mrkai77 Nov 22, 2026
507e4f5
✨ Print CLI lists as tables, and tab-separated lines when piped
mrkai77 Nov 22, 2026
56d036c
📝 Lead with the loop command, and show URLs as links for other apps
mrkai77 Nov 22, 2026
0fd0698
🐞 Fix --version through the installed symlink
mrkai77 Nov 22, 2026
f1c3520
📝 List every list subject in the README
mrkai77 Nov 22, 2026
70733c1
🐞 Fix edge cases in running and listing actions
mrkai77 Nov 22, 2026
cd9ca98
💄 Say when the command-line tool points to a copy of Loop that was mo…
mrkai77 Nov 22, 2026
89d73b1
🐞 Fix moving windows to another screen
mrkai77 Nov 23, 2026
7b76696
🐞 Don't show a Dock icon or Settings when a loop:// URL opens Loop
mrkai77 Nov 23, 2026
98ff944
🌐 Localize the new strings that match Apple's own translations
mrkai77 Nov 23, 2026
aadabb7
🌐 Add French and Japanese for the CLI and helper strings
mrkai77 Nov 23, 2026
7df3d83
🌐 Give the new strings consistent translator comments
mrkai77 Nov 23, 2026
9b64a40
♻️ Remove duplicated logic and split shared files
mrkai77 Nov 23, 2026
3ff78e3
🐞 Run CLI actions under the same conditions as keybinds, and share Bu…
mrkai77 Nov 23, 2026
39c55b0
🐞 Settle CLI and URL contract
mrkai77 Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 175 additions & 28 deletions Loop.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

39 changes: 27 additions & 12 deletions Loop/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import UserNotifications

@Loggable
final class AppDelegate: NSObject, NSApplicationDelegate {
private let urlCommandHandler = URLCommandHandler()

private static let terminateNotificationName = Notification.Name("com.MrKai77.Loop.terminate")
private var terminateObserver: Any?

private var launchedAsLoginItem: Bool {
guard let event = NSAppleEventManager.shared().currentAppleEvent else { return false }
return
event.eventID == kAEOpenApplication &&
event.paramDescriptor(forKeyword: keyAEPropData)?.enumCodeValue == keyAELaunchedAsLogInItem
/// Launched from Finder, the Dock or `open`, rather than at login or to open a `loop://` URL, which has no open-application event
private var launchedByUser: Bool {
guard let event = NSAppleEventManager.shared().currentAppleEvent, event.eventID == kAEOpenApplication else {
return false
}

return event.paramDescriptor(forKeyword: keyAEPropData)?.enumCodeValue != keyAELaunchedAsLogInItem
}

func applicationDidFinishLaunching(_: Notification) {
Expand All @@ -37,8 +37,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
DataPatcher.run()
}

// Show settings window only if not launched as login item AND startHidden is disabled
if !launchedAsLoginItem, !Defaults[.startHidden] {
// Show settings window only if launched by the user AND startHidden is disabled
if launchedByUser, !Defaults[.startHidden] {
SettingsWindowManager.shared.show()
} else {
// Closing also hides the dock icon if needed.
Expand Down Expand Up @@ -66,6 +66,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
let stalePIDs = broadcastTerminateToOtherInstances()
await waitForInstancesToExit(pids: stalePIDs, timeout: .seconds(3))
LoopManager.shared.start()
// After older instances exit, as they remove their socket file while quitting
LoopSocketManager.shared.start()
WindowDragManager.shared.addObservers()
StashManager.shared.start()
AccessibilityManager.requestAccess()
Expand Down Expand Up @@ -159,8 +161,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
return
}

log.info("Received URL: \(url)")
urlCommandHandler.handle(url)
processIncomingURL(url)
}

func applicationShouldTerminateAfterLastWindowClosed(_: NSApplication) -> Bool {
Expand All @@ -179,12 +180,26 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
LoopManager.shared.shutdown()
WindowDragManager.shared.shutdown()
StashManager.shared.shutdown()
LoopSocketManager.shared.shutdown()
return .terminateNow
}

func application(_: NSApplication, open urls: [URL]) {
for url in urls {
urlCommandHandler.handle(url)
processIncomingURL(url)
}
}

private func processIncomingURL(_ url: URL) {
log.info("Received URL: \(url)")

Task { @MainActor in
// macOS gives Loop a Dock icon before handing it a URL, as Loop isn't an `LSUIElement` app
SettingsWindowManager.shared.hideDockIconIfUnused()

let result = await LoopCommandHandler.shared.handle(url)
log.debug("Response: \(result.jsonResponse)")
result.presentIfNeeded()
}
}
}
131 changes: 57 additions & 74 deletions Loop/Core/LoopManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -416,22 +416,25 @@ extension LoopManager {

let originatingContext = resizeContext

guard
isLoopActive,
let currentScreen = originatingContext.screen ?? resolveAndStoreTargetScreen(
action: newAction,
window: originatingContext.window
)
else {
guard isLoopActive else {
return
}

let incomingAllowsRepeatedSelection = newAction.allowsRepeatedSelection

// Before choosing a screen, so the "no selection" Loop opens with doesn't choose it for the first real action.
// Screen switching actions start from the window's screen, which only the first real action can pick.
guard originatingContext.action.id != newAction.id || incomingAllowsRepeatedSelection else {
return
}

guard let currentScreen = originatingContext.screen ?? resolveAndStoreTargetScreen(
action: newAction,
window: originatingContext.window
) else {
return
}

actionRevision += 1
let originatingRevision = actionRevision

Expand Down Expand Up @@ -505,78 +508,13 @@ extension LoopManager {
}

if newAction.direction.willChangeScreen {
var newScreen: NSScreen = currentScreen

if newAction.direction == .nextScreen,
let nextScreen = ScreenUtility.nextScreen(from: currentScreen) {
newScreen = nextScreen
}

if newAction.direction == .previousScreen,
let previousScreen = ScreenUtility.previousScreen(from: currentScreen) {
newScreen = previousScreen
}

if newAction.direction == .leftScreen,
let leftScreen = ScreenUtility.directionalScreen(from: currentScreen, direction: .left) {
newScreen = leftScreen
}

if newAction.direction == .rightScreen,
let rightScreen = ScreenUtility.directionalScreen(from: currentScreen, direction: .right) {
newScreen = rightScreen
}

if newAction.direction == .topScreen,
let topScreen = ScreenUtility.directionalScreen(from: currentScreen, direction: .top) {
newScreen = topScreen
}

if newAction.direction == .bottomScreen,
let bottomScreen = ScreenUtility.directionalScreen(from: currentScreen, direction: .bottom) {
newScreen = bottomScreen
}
let newScreen = ScreenUtility.targetScreen(for: newAction.direction, from: currentScreen) ?? currentScreen

// If the current action is either `.noAction`/`.noSelection`, or `.smaller`/`.larger` etc,
// then we will preserve the window's proportional frame relative to the current screen on the new screen.
if resizeContext.action.direction.isNoOp || resizeContext.action.willManipulateExistingWindowFrame {
if let targetWindow = resizeContext.window {
let screenSwitchingCustomActionName = "autogenerated_screen_switching_action"

if let lastAction = await WindowRecords.shared.getCurrentAction(for: targetWindow),
lastAction.getName() != screenSwitchingCustomActionName,
!lastAction.forceProportionalFrameOnScreenChange {
setResizeAction(to: lastAction, parent: nil)
} else {
let currentFrame = targetWindow.frame

let adjustedBounds = PaddingConfiguration
.getConfiguredPadding(for: currentScreen)
.applyToBounds(currentScreen.cgSafeScreenFrame, screen: currentScreen)

let proportionalSize = CGRect(
x: (currentFrame.minX - adjustedBounds.minX) / adjustedBounds.width,
y: (currentFrame.minY - adjustedBounds.minY) / adjustedBounds.height,
width: currentFrame.width / adjustedBounds.width,
height: currentFrame.height / adjustedBounds.height
)

setResizeAction(
to: .init(
.custom,
keybind: [],
name: screenSwitchingCustomActionName,
unit: .percentage,
width: proportionalSize.width * 100,
height: proportionalSize.height * 100,
xPoint: proportionalSize.minX * 100,
yPoint: proportionalSize.minY * 100,
positionMode: .coordinates,
sizeMode: .custom
),
parent: nil
)
}
await setResizeAction(to: Self.actionAfterScreenSwitch(for: targetWindow, from: currentScreen), parent: nil)
} else {
setResizeAction(to: .init(.center), parent: nil)
}
Expand Down Expand Up @@ -714,3 +652,48 @@ extension LoopManager {
return targetScreen
}
}

// MARK: - Screen Switching

extension LoopManager {
/// What a screen switching action applies on the new screen: the window's last action,
/// or its current frame in proportion to the screen. Screen switching actions have no frame of their own.
static func actionAfterScreenSwitch(for window: Window, from currentScreen: NSScreen) async -> WindowAction {
let screenSwitchingCustomActionName = "autogenerated_screen_switching_action"

if let lastAction = await WindowRecords.shared.getCurrentAction(for: window),
lastAction.getName() != screenSwitchingCustomActionName,
!lastAction.forceProportionalFrameOnScreenChange {
return lastAction
}

let currentFrame = window.frame

// Measured on the screen the window is actually on. The screen Loop started from can be another one,
// and measuring against it gives proportions outside the screen.
let windowScreen = ScreenUtility.screenContaining(window) ?? currentScreen
let adjustedBounds = PaddingConfiguration
.getConfiguredPadding(for: windowScreen)
.applyToBounds(windowScreen.cgSafeScreenFrame, screen: windowScreen)

let proportionalSize = CGRect(
x: (currentFrame.minX - adjustedBounds.minX) / adjustedBounds.width,
y: (currentFrame.minY - adjustedBounds.minY) / adjustedBounds.height,
width: currentFrame.width / adjustedBounds.width,
height: currentFrame.height / adjustedBounds.height
)

return .init(
.custom,
keybind: [],
name: screenSwitchingCustomActionName,
unit: .percentage,
width: proportionalSize.width * 100,
height: proportionalSize.height * 100,
xPoint: proportionalSize.minX * 100,
yPoint: proportionalSize.minY * 100,
positionMode: .coordinates,
sizeMode: .custom
)
}
}
Loading
Loading