-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathWindowUtils.swift
More file actions
59 lines (50 loc) · 2.09 KB
/
WindowUtils.swift
File metadata and controls
59 lines (50 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import Cocoa
import Foundation
func createWindow(x: CGFloat, y: CGFloat, width: CGFloat,
height: CGFloat) -> NSWindow {
// Create the window with titled style
let window = NSWindow(
contentRect: NSRect(x: x, y: y, width: width, height: height),
styleMask: [.titled], // or isKeyWindow can't be true
backing: .buffered,
defer: false
)
// Set window properties for visibility and focus
window.isOpaque = true
window.backgroundColor = NSColor.purple // Set background to purple
window.titlebarAppearsTransparent = true // Transparent title
window.level = .screenSaver // High window level for visibility
window.collectionBehavior = [.canJoinAllSpaces, .stationary]
// Make window visible, bring it to front, and make it key
window.makeKeyAndOrderFront(nil)
return window
}
// Function to show a temporary window with text input focus
func showTemporaryInputWindow(waitTimeMs: Int) {
// skip
if waitTimeMs == 0 {
return
}
// Handle wait time and app termination
let waitTime = waitTimeMs < 0 ? 1 : waitTimeMs
let app = NSApplication.shared
app.setActivationPolicy(.accessory)
// Get main screen dimensions to position window in bottom-right
guard let screen = NSScreen.main else { return }
let screenRect = screen.visibleFrame
// Calculate bottom-right position with larger window size
let windowWidth: CGFloat = 3 // Increased width for visibility
let windowHeight: CGFloat = 3 // Increased height for visibility
let xPos = screenRect.maxX - windowWidth - 8 // Margin from right
let yPos = screenRect.minY + 8 // Margin from bottom
let _ = createWindow(x: xPos, y: yPos, width: windowWidth,
height: windowHeight)
// Force app to activate and take focus, ignoring other apps
app.activate(ignoringOtherApps: true)
let waitTimeSeconds = TimeInterval(waitTime) / 1000.0
DispatchQueue.main.asyncAfter(deadline: .now() + waitTimeSeconds) {
// Terminate the application
app.terminate(nil)
}
app.run()
}