we have a square following the mouse

This commit is contained in:
neon443
2025-05-29 15:38:54 +01:00
parent 1a0d3c2e38
commit 4e55cc4516
2 changed files with 15 additions and 36 deletions

View File

@@ -54,8 +54,8 @@ class MouseTracker {
}
func checkMouse(_ event: NSEvent) {
var location = NSEvent.mouseLocation
location.y = screen.height - location.y
let location = event.mouseLocationCG
skyHigh.move(to: NSEvent.mouseLocation)
guard settings.settings.checkFullscreen else {
handleDockValue(dockIsAt: currentDockSide, location: location)
@@ -116,24 +116,6 @@ class MouseTracker {
self.monitor = NSEvent.addGlobalMonitorForEvents(matching: .mouseMoved, handler: checkMouse)
self.running = true
print("started tracking")
skyHigh.move()
}
func stop() {
@@ -156,6 +138,7 @@ class MouseTracker {
timer?.invalidate()
loopIteration = 0
skyHigh.move(to: prevPoint)
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 {
@@ -168,7 +151,9 @@ class MouseTracker {
}
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))
let cgpoint = CGPoint(x: newPosX, y: newPosY)
CGWarpMouseCursorPosition(cgpoint)
skyHigh.move(to: cgpoint)
self.loopIteration += 4
}

View File

@@ -18,12 +18,17 @@ class SkyHigh {
self.settings = settings
self.window = NSWindow(
contentRect: settings.settings.mouseMoveRect,
contentRect: CGRect(
x: NSScreen.mainFrameWidth/2,
y: NSScreen.mainFrameHeight/2,
width: 50,
height: 50
),
styleMask: .borderless,
backing: .buffered,
defer: false
)
window.backgroundColor = .init(srgbRed: 0.5, green: 0.5, blue: 0.5, alpha: 0.05)
window.backgroundColor = .init(srgbRed: 1, green: 1, blue: 1, alpha: 0.2)
window.isOpaque = false
window.level = NSWindow.Level.statusBar + 1
window.ignoresMouseEvents = true
@@ -32,18 +37,7 @@ class SkyHigh {
window.makeKeyAndOrderFront(nil)
}
func move() {
x = 5
timer?.invalidate()
timer = Timer(timeInterval: 0.01, repeats: true) { [weak self] _ in
guard let self = self else { return }
guard x < 1001 else {
timer?.invalidate()
return
}
self.window.setFrameOrigin(NSPoint(x: 1000-self.x, y: 1000-self.x))
self.x += 5
}
RunLoop.current.add(timer!, forMode: .common)
func move(to: CGPoint) {
self.window.setFrameOrigin(to)
}
}