minor refactoring

This commit is contained in:
Nihaal Sharma committed 2026-10-17 00:35:34 +01:00
1 parent 93a02f9a48
commit 49cf17b99a
5 files changed
+32 -20

No files matched your search

+4 -2
View File
@@ -1,6 +1,6 @@
//
// AppDelegate.swift
// s
// DesktopDuck
//
// Created by neon443 on 11/09/2025.
//
@@ -9,12 +9,14 @@ import Cocoa
@main
class AppDelegate: NSObject, NSApplicationDelegate {
var gooseWindow: GooseWindow?
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
// let window = NSWindow(contentRect: NSScreen.main!.frame, styleMask: .borderless, backing: .buffered, defer: false)
// window.backgroundColor = .init(srgbRed: 1, green: 1, blue: 1, alpha: 0.1)
// window.orderFront(nil)
let x = GooseWindow()
gooseWindow = GooseWindow()
}
func applicationWillTerminate(_ aNotification: Notification) {
+9 -3
View File
@@ -25,7 +25,8 @@ class Goose: NSViewController {
}
func setup() {
gooseView.frame = NSRect(x: 100, y: 100, width: 25, height: 25)
gooseView.translatesAutoresizingMaskIntoConstraints = false
gooseView.frame = NSRect(x: 100, y: 100, width: 50, height: 50)
self.view.addSubview(gooseView)
let bodyView = NSImageView(image: NSImage(named: "body")!)
@@ -41,10 +42,15 @@ class Goose: NSViewController {
gooseView.addSubview(neckView)
neckView.translatesAutoresizingMaskIntoConstraints = false
neckView.rotate(byDegrees: 90)
neckView.frame = NSRect(x: 0, y: 0, width: 30, height: 30)
NSLayoutConstraint.activate([
neckView.widthAnchor.constraint(equalToConstant: 25),
neckView.heightAnchor.constraint(equalToConstant: 25)
neckView.leftAnchor.constraint(equalTo: bodyView.leftAnchor),
neckView.bottomAnchor.constraint(equalTo: bodyView.bottomAnchor),
neckView.widthAnchor.constraint(equalToConstant: 30),
neckView.heightAnchor.constraint(equalToConstant: 30)
])
bodyView.alphaValue = 0.5
neckView.alphaValue = 0.5
}
}
+13 -13
View File
@@ -8,8 +8,7 @@
import Foundation
import Cocoa
class GooseWindow {
private var window: NSWindow
class GooseWindow: NSWindow {
private var goose: Goose
private var angle: CGFloat = 90
var shown: Bool = false
@@ -18,30 +17,31 @@ class GooseWindow {
init() {
goose = Goose()
self.window = NSWindow(
contentRect: CGRect(x: 0, y: 0, width: NSScreen.main!.frame.width, height: NSScreen.main!.frame.width),
super.init(
contentRect: NSRect(x: 0, y: 0, width: NSScreen.main!.frame.width, height: NSScreen.main!.frame.height),
styleMask: .borderless,
backing: .buffered,
defer: false
)
window.backgroundColor = .init(srgbRed: 1, green: 1, blue: 1, alpha: 0.1)
window.isOpaque = false
window.level = NSWindow.Level.screenSaver + 1
window.ignoresMouseEvents = true
window.hasShadow = false
window.collectionBehavior = NSWindow.CollectionBehavior.canJoinAllApplications.union(.stationary).union(.canJoinAllSpaces)
self.backgroundColor = .init(srgbRed: 1, green: 1, blue: 1, alpha: 0.1)
self.isOpaque = false
self.level = NSWindow.Level.screenSaver + 1
self.ignoresMouseEvents = true
self.hasShadow = false
self.collectionBehavior = NSWindow.CollectionBehavior.canJoinAllApplications.union(.stationary).union(.canJoinAllSpaces)
showHide()
// window.contentView?.addSubview(NSTextField(labelWithString: "hi"))
window.contentView?.addSubview(goose.view)
self.contentView?.addSubview(goose.view)
}
func showHide() {
if shown {
window.orderOut(nil)
self.orderOut(nil)
} else {
window.orderFront(nil)
self.orderFront(nil)
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.