mirror of
https://github.com/neon443/DockPhobia.git
synced 2026-03-11 06:49:12 +00:00
we have a square following the mouse
This commit is contained in:
@@ -54,8 +54,8 @@ class MouseTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkMouse(_ event: NSEvent) {
|
func checkMouse(_ event: NSEvent) {
|
||||||
var location = NSEvent.mouseLocation
|
let location = event.mouseLocationCG
|
||||||
location.y = screen.height - location.y
|
skyHigh.move(to: NSEvent.mouseLocation)
|
||||||
|
|
||||||
guard settings.settings.checkFullscreen else {
|
guard settings.settings.checkFullscreen else {
|
||||||
handleDockValue(dockIsAt: currentDockSide, location: location)
|
handleDockValue(dockIsAt: currentDockSide, location: location)
|
||||||
@@ -116,24 +116,6 @@ class MouseTracker {
|
|||||||
self.monitor = NSEvent.addGlobalMonitorForEvents(matching: .mouseMoved, handler: checkMouse)
|
self.monitor = NSEvent.addGlobalMonitorForEvents(matching: .mouseMoved, handler: checkMouse)
|
||||||
self.running = true
|
self.running = true
|
||||||
print("started tracking")
|
print("started tracking")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
skyHigh.move()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func stop() {
|
func stop() {
|
||||||
@@ -156,6 +138,7 @@ class MouseTracker {
|
|||||||
|
|
||||||
timer?.invalidate()
|
timer?.invalidate()
|
||||||
loopIteration = 0
|
loopIteration = 0
|
||||||
|
skyHigh.move(to: prevPoint)
|
||||||
timer = Timer(timeInterval: 0.001, repeats: true) { [weak self] _ in
|
timer = Timer(timeInterval: 0.001, 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 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 newPosX = (prevPoint.x > posX ? prevPoint.x-loopIteration : prevPoint.x+loopIteration)
|
||||||
let newPosY = (prevPoint.y > posY ? prevPoint.y-loopIteration : prevPoint.y+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
|
self.loopIteration += 4
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,17 @@ class SkyHigh {
|
|||||||
self.settings = settings
|
self.settings = settings
|
||||||
|
|
||||||
self.window = NSWindow(
|
self.window = NSWindow(
|
||||||
contentRect: settings.settings.mouseMoveRect,
|
contentRect: CGRect(
|
||||||
|
x: NSScreen.mainFrameWidth/2,
|
||||||
|
y: NSScreen.mainFrameHeight/2,
|
||||||
|
width: 50,
|
||||||
|
height: 50
|
||||||
|
),
|
||||||
styleMask: .borderless,
|
styleMask: .borderless,
|
||||||
backing: .buffered,
|
backing: .buffered,
|
||||||
defer: false
|
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.isOpaque = false
|
||||||
window.level = NSWindow.Level.statusBar + 1
|
window.level = NSWindow.Level.statusBar + 1
|
||||||
window.ignoresMouseEvents = true
|
window.ignoresMouseEvents = true
|
||||||
@@ -32,18 +37,7 @@ class SkyHigh {
|
|||||||
window.makeKeyAndOrderFront(nil)
|
window.makeKeyAndOrderFront(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func move() {
|
func move(to: CGPoint) {
|
||||||
x = 5
|
self.window.setFrameOrigin(to)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user