Dynamic Popup/Dropdown shortcut

This commit is contained in:
Hariharan Mudaliar 2025-08-12 22:17:23 +05:30
commit e29745f8f4
6 changed files with 139 additions and 19 deletions

View file

@ -450,8 +450,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
ClipboardManager.shared.startMonitoring()
}
// Check if window mode is enabled
if Defaults[.clipboardWindowMode] {
// Determine display mode based on user preference and context
let shouldUseWindow = self.shouldUseWindowMode()
if shouldUseWindow {
// Use window interface
ClipboardWindowManager.shared.toggleClipboardWindow()
} else {
@ -622,6 +624,60 @@ class AppDelegate: NSObject, NSApplicationDelegate {
NSApplication.shared.terminate(nil)
}
// MARK: - Clipboard Display Mode Logic
private func shouldUseWindowMode() -> Bool {
let displayMode = Defaults[.clipboardDisplayMode]
switch displayMode {
case .window:
return true
case .popover:
return false
case .auto:
// Auto mode: use window if any app is in fullscreen, otherwise use popover
return isAnyAppInFullscreen()
}
}
private func isAnyAppInFullscreen() -> Bool {
// Check if any running application is in fullscreen mode
let workspace = NSWorkspace.shared
// Get all visible applications
let apps = workspace.runningApplications.filter { app in
app.activationPolicy == .regular && !app.isTerminated
}
// Check each application's windows for fullscreen state
for app in apps {
if app.isActive {
// Check if the frontmost application has fullscreen windows
let windows = CGWindowListCopyWindowInfo(.optionOnScreenOnly, kCGNullWindowID) as? [[String: Any]] ?? []
for window in windows {
if let ownerPID = window[kCGWindowOwnerPID as String] as? Int32,
ownerPID == app.processIdentifier,
let bounds = window[kCGWindowBounds as String] as? [String: Any],
let width = bounds["Width"] as? CGFloat,
let height = bounds["Height"] as? CGFloat {
// Check if window dimensions match screen dimensions (indicating fullscreen)
for screen in NSScreen.screens {
let screenFrame = screen.frame
if abs(width - screenFrame.width) < 10 && abs(height - screenFrame.height) < 10 {
return true
}
}
}
}
}
}
return false
}
private func showOnboardingWindow() {
if onboardingWindowController == nil {
let window = NSWindow(