This commit is contained in:
neon443
2025-05-29 15:33:19 +01:00
parent e46edecec7
commit 1a0d3c2e38
3 changed files with 39 additions and 6 deletions

View File

@@ -32,10 +32,10 @@ struct DPSettings: Codable {
NSScreen.mainFrameHeight*insetVertical
}
var mouseInsetTop: CGFloat {
NSScreen.mainFrameHeight*(1-(2*insetVertical))
NSScreen.mainFrameHeight*(1-(insetVertical))
}
var mouseInsetTrailing: CGFloat {
NSScreen.mainFrameWidth*(1-(2*insetHorizontal))
NSScreen.mainFrameWidth*(1-(insetHorizontal))
}
var insetHorizontal: CGFloat
@@ -45,8 +45,8 @@ struct DPSettings: Codable {
return CGRect(
x: mouseInsetLeading,
y: mouseInsetBottom,
width: mouseInsetTrailing,
height: mouseInsetTop
width: mouseInsetTrailing - mouseInsetLeading,
height: mouseInsetTop - mouseInsetBottom
)
}

View File

@@ -10,6 +10,14 @@ import AppKit
import Cocoa
import ApplicationServices
extension NSEvent {
var mouseLocationCG: CGPoint {
var loc = NSEvent.mouseLocation
loc.y = NSScreen.mainFrameHeight - loc.y
return loc
}
}
struct Screen {
var width: CGFloat
var height: CGFloat
@@ -25,6 +33,9 @@ class MouseTracker {
var settings: DPSettingsModel
var skyHigh: SkyHigh
private var timer: Timer?
private var loopIteration: Double = 0
init(settings: DPSettingsModel) {
print(DockSide())
@@ -135,11 +146,33 @@ class MouseTracker {
}
func moveMouse() {
let prevPoint = NSEvent().mouseLocationCG
let rangeW = settings.settings.mouseInsetLeading...settings.settings.mouseInsetTrailing
let posX = CGFloat.random(in: rangeW)
let rangeH = settings.settings.mouseInsetBottom...settings.settings.mouseInsetTop
let posY = CGFloat.random(in: rangeH)
CGDisplayMoveCursorToPoint(0, CGPoint(x: posX, y: posY))
print(prevPoint)
print(posX, posY)
timer?.invalidate()
loopIteration = 0
timer = Timer(timeInterval: 0.001, repeats: true) { [weak self] _ in
guard let self = self else { return }
guard NSEvent().mouseLocationCG != CGPoint(x: posX, y: posX) else {
timer?.invalidate()
return
}
guard loopIteration < 1000 else {
timer?.invalidate()
return
}
let newPosX = (prevPoint.x > posX ? prevPoint.x-loopIteration : prevPoint.x+loopIteration)
let newPosY = (prevPoint.y > posY ? prevPoint.y-loopIteration : prevPoint.y+loopIteration)
CGWarpMouseCursorPosition(CGPoint(x: newPosX, y: newPosY))
self.loopIteration += 4
}
RunLoop.main.add(timer!, forMode: .common)
}
func moveDock(_ toSide: DockSide) {

View File

@@ -23,7 +23,7 @@ class SkyHigh {
backing: .buffered,
defer: false
)
window.backgroundColor = .init(srgbRed: 1, green: 1, blue: 1, alpha: 0.1)
window.backgroundColor = .init(srgbRed: 0.5, green: 0.5, blue: 0.5, alpha: 0.05)
window.isOpaque = false
window.level = NSWindow.Level.statusBar + 1
window.ignoresMouseEvents = true