got a pinch lollll

This commit is contained in:
neon443
2025-05-29 16:00:21 +01:00
parent 4e55cc4516
commit d60d90bc60
6 changed files with 57 additions and 14 deletions

BIN
DockPhobia/.DS_Store vendored
View File

Binary file not shown.

View File

@@ -18,6 +18,15 @@ extension NSEvent {
} }
} }
extension CGPoint {
var invertedForScreen: CGPoint {
return CGPoint(
x: self.x,
y: NSScreen.mainFrameHeight - self.y
)
}
}
struct Screen { struct Screen {
var width: CGFloat var width: CGFloat
var height: CGFloat var height: CGFloat
@@ -55,7 +64,10 @@ class MouseTracker {
func checkMouse(_ event: NSEvent) { func checkMouse(_ event: NSEvent) {
let location = event.mouseLocationCG let location = event.mouseLocationCG
skyHigh.move(to: NSEvent.mouseLocation) // var cgpointForSkyHigh = NSEvent.mouseLocation
// cgpointForSkyHigh.x -= 10
// cgpointForSkyHigh.y -= 5
// skyHigh.move(to: cgpointForSkyHigh)
guard settings.settings.checkFullscreen else { guard settings.settings.checkFullscreen else {
handleDockValue(dockIsAt: currentDockSide, location: location) handleDockValue(dockIsAt: currentDockSide, location: location)
@@ -138,14 +150,12 @@ class MouseTracker {
timer?.invalidate() timer?.invalidate()
loopIteration = 0 loopIteration = 0
skyHigh.move(to: prevPoint) skyHigh.move(to: prevPoint.invertedForScreen)
timer = Timer(timeInterval: 0.001, repeats: true) { [weak self] _ in skyHigh.show()
timer = Timer(timeInterval: 0.005, repeats: true) { [weak self] _ in
guard let self = self else { return } guard let self = self else { return }
guard NSEvent().mouseLocationCG != CGPoint(x: posX, y: posX) else { guard loopIteration < 500 else {
timer?.invalidate() skyHigh.hide()
return
}
guard loopIteration < 1000 else {
timer?.invalidate() timer?.invalidate()
return return
} }
@@ -153,9 +163,12 @@ class MouseTracker {
let newPosY = (prevPoint.y > posY ? prevPoint.y-loopIteration : prevPoint.y+loopIteration) let newPosY = (prevPoint.y > posY ? prevPoint.y-loopIteration : prevPoint.y+loopIteration)
let cgpoint = CGPoint(x: newPosX, y: newPosY) let cgpoint = CGPoint(x: newPosX, y: newPosY)
CGWarpMouseCursorPosition(cgpoint) CGWarpMouseCursorPosition(cgpoint)
skyHigh.move(to: cgpoint) var cgpointForSkyHigh = cgpoint
cgpointForSkyHigh.x -= 10
cgpointForSkyHigh.y += 5
skyHigh.move(to: cgpointForSkyHigh.invertedForScreen)
self.loopIteration += 4 self.loopIteration += 1
} }
RunLoop.main.add(timer!, forMode: .common) RunLoop.main.add(timer!, forMode: .common)
} }

View File

@@ -0,0 +1,22 @@
{
"images" : [
{
"filename" : "pinch 1.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "pinch.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

@@ -21,23 +21,31 @@ class SkyHigh {
contentRect: CGRect( contentRect: CGRect(
x: NSScreen.mainFrameWidth/2, x: NSScreen.mainFrameWidth/2,
y: NSScreen.mainFrameHeight/2, y: NSScreen.mainFrameHeight/2,
width: 50, width: 100,
height: 50 height: 100
), ),
styleMask: .borderless, styleMask: .borderless,
backing: .buffered, backing: .buffered,
defer: false defer: false
) )
window.backgroundColor = .init(srgbRed: 1, green: 1, blue: 1, alpha: 0.2) window.backgroundColor = .init(srgbRed: 1, green: 1, blue: 1, alpha: 0)
window.contentView = NSImageView(image: NSImage(named: "pinch")!)
window.isOpaque = false window.isOpaque = false
window.level = NSWindow.Level.statusBar + 1 window.level = NSWindow.Level.statusBar + 1
window.ignoresMouseEvents = true window.ignoresMouseEvents = true
window.hasShadow = true window.hasShadow = true
window.collectionBehavior = NSWindow.CollectionBehavior.canJoinAllSpaces.union(.stationary) window.collectionBehavior = NSWindow.CollectionBehavior.canJoinAllSpaces.union(.stationary)
window.makeKeyAndOrderFront(nil)
} }
func move(to: CGPoint) { func move(to: CGPoint) {
self.window.setFrameOrigin(to) self.window.setFrameOrigin(to)
} }
func show() {
window.orderFront(nil)
}
func hide() {
window.orderOut(nil)
}
} }