From 1a0d3c2e381bef8231aaee802a685519d43c5a90 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Thu, 29 May 2025 15:33:19 +0100 Subject: [PATCH] YESSS --- DockPhobia/DPSettings.swift | 8 ++++---- DockPhobia/MouseTracker.swift | 35 ++++++++++++++++++++++++++++++++++- DockPhobia/SkyHigh.swift | 2 +- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/DockPhobia/DPSettings.swift b/DockPhobia/DPSettings.swift index 389cfe6..a467e1d 100644 --- a/DockPhobia/DPSettings.swift +++ b/DockPhobia/DPSettings.swift @@ -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 ) } diff --git a/DockPhobia/MouseTracker.swift b/DockPhobia/MouseTracker.swift index 2bec440..2f361e0 100644 --- a/DockPhobia/MouseTracker.swift +++ b/DockPhobia/MouseTracker.swift @@ -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) { diff --git a/DockPhobia/SkyHigh.swift b/DockPhobia/SkyHigh.swift index b47a6ee..f50c173 100644 --- a/DockPhobia/SkyHigh.swift +++ b/DockPhobia/SkyHigh.swift @@ -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