diff --git a/DockPhobia/.DS_Store b/DockPhobia/.DS_Store index 6a748ff..30ec3dc 100644 Binary files a/DockPhobia/.DS_Store and b/DockPhobia/.DS_Store differ diff --git a/DockPhobia/MouseTracker.swift b/DockPhobia/MouseTracker.swift index 45b333d..65a7348 100644 --- a/DockPhobia/MouseTracker.swift +++ b/DockPhobia/MouseTracker.swift @@ -18,6 +18,15 @@ extension NSEvent { } } +extension CGPoint { + var invertedForScreen: CGPoint { + return CGPoint( + x: self.x, + y: NSScreen.mainFrameHeight - self.y + ) + } +} + struct Screen { var width: CGFloat var height: CGFloat @@ -55,7 +64,10 @@ class MouseTracker { func checkMouse(_ event: NSEvent) { 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 { handleDockValue(dockIsAt: currentDockSide, location: location) @@ -138,14 +150,12 @@ class MouseTracker { timer?.invalidate() loopIteration = 0 - skyHigh.move(to: prevPoint) - timer = Timer(timeInterval: 0.001, repeats: true) { [weak self] _ in + skyHigh.move(to: prevPoint.invertedForScreen) + skyHigh.show() + timer = Timer(timeInterval: 0.005, 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 { + guard loopIteration < 500 else { + skyHigh.hide() timer?.invalidate() return } @@ -153,9 +163,12 @@ class MouseTracker { let newPosY = (prevPoint.y > posY ? prevPoint.y-loopIteration : prevPoint.y+loopIteration) let cgpoint = CGPoint(x: newPosX, y: newPosY) 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) } diff --git a/DockPhobia/Resources/Assets.xcassets/pinch.imageset/Contents.json b/DockPhobia/Resources/Assets.xcassets/pinch.imageset/Contents.json new file mode 100644 index 0000000..84e6a4f --- /dev/null +++ b/DockPhobia/Resources/Assets.xcassets/pinch.imageset/Contents.json @@ -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 + } +} diff --git a/DockPhobia/Resources/Assets.xcassets/pinch.imageset/pinch 1.png b/DockPhobia/Resources/Assets.xcassets/pinch.imageset/pinch 1.png new file mode 100644 index 0000000..10c089c Binary files /dev/null and b/DockPhobia/Resources/Assets.xcassets/pinch.imageset/pinch 1.png differ diff --git a/DockPhobia/Resources/Assets.xcassets/pinch.imageset/pinch.png b/DockPhobia/Resources/Assets.xcassets/pinch.imageset/pinch.png new file mode 100644 index 0000000..10c089c Binary files /dev/null and b/DockPhobia/Resources/Assets.xcassets/pinch.imageset/pinch.png differ diff --git a/DockPhobia/SkyHigh.swift b/DockPhobia/SkyHigh.swift index c76203c..d4d29a1 100644 --- a/DockPhobia/SkyHigh.swift +++ b/DockPhobia/SkyHigh.swift @@ -21,23 +21,31 @@ class SkyHigh { contentRect: CGRect( x: NSScreen.mainFrameWidth/2, y: NSScreen.mainFrameHeight/2, - width: 50, - height: 50 + width: 100, + height: 100 ), styleMask: .borderless, backing: .buffered, 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.level = NSWindow.Level.statusBar + 1 window.ignoresMouseEvents = true window.hasShadow = true window.collectionBehavior = NSWindow.CollectionBehavior.canJoinAllSpaces.union(.stationary) - window.makeKeyAndOrderFront(nil) } func move(to: CGPoint) { self.window.setFrameOrigin(to) } + + func show() { + window.orderFront(nil) + } + + func hide() { + window.orderOut(nil) + } }