add mouse moves count

tweak the aligment of the pinch
added mouse move count to menu bar,
grammar fix
This commit is contained in:
neon443
2025-05-29 16:11:41 +01:00
parent 83efb14bd5
commit d943415b98
4 changed files with 27 additions and 10 deletions

View File

@@ -55,6 +55,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
keyEquivalent: "" keyEquivalent: ""
) )
menu.addItem(dockMoves) menu.addItem(dockMoves)
let mouseMoves = NSMenuItem(
title: "Moved the cursor \(settings.settings.mouseMoves) time\(settings.settings.mouseMoves.plural)",
action: nil,
keyEquivalent: ""
)
menu.addItem(mouseMoves)
menu.addItem(NSMenuItem.separator()) menu.addItem(NSMenuItem.separator())
let moveMouseButton = NSMenuItem( let moveMouseButton = NSMenuItem(
@@ -77,15 +84,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
menu.addItem(NSMenuItem.separator()) menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem( menu.addItem(NSMenuItem(
title: "Move Dock to left", title: "Move Dock to the left",
action: #selector(moveDockObjcLeft), action: #selector(moveDockObjcLeft),
keyEquivalent: "")) keyEquivalent: ""))
menu.addItem(NSMenuItem( menu.addItem(NSMenuItem(
title: "Move Dock to bottom", title: "Move Dock to the bottom",
action: #selector(moveDockObjcBottom), action: #selector(moveDockObjcBottom),
keyEquivalent: "")) keyEquivalent: ""))
menu.addItem(NSMenuItem( menu.addItem(NSMenuItem(
title: "Move Dock to right", title: "Move Dock to the right",
action: #selector(moveDockObjcRight), action: #selector(moveDockObjcRight),
keyEquivalent: "")) keyEquivalent: ""))
menu.addItem(NSMenuItem.separator()) menu.addItem(NSMenuItem.separator())

View File

@@ -22,6 +22,7 @@ extension NSScreen {
struct DPSettings: Codable { struct DPSettings: Codable {
var dockMoves: Int var dockMoves: Int
var mouseMoves: Int
var checkFullscreen: Bool var checkFullscreen: Bool
var moveMouseInstead: Bool var moveMouseInstead: Bool
@@ -52,12 +53,14 @@ struct DPSettings: Codable {
init( init(
dockMoves: Int = 0, dockMoves: Int = 0,
mouseMoves: Int = 0,
checkFullscreen: Bool = false, checkFullscreen: Bool = false,
moveMouseInstead: Bool = false, moveMouseInstead: Bool = false,
insetHorizontal: CGFloat = 0.05, insetHorizontal: CGFloat = 0.05,
insetVertical: CGFloat = 0.1 insetVertical: CGFloat = 0.1
) { ) {
self.dockMoves = dockMoves self.dockMoves = dockMoves
self.mouseMoves = mouseMoves
self.checkFullscreen = checkFullscreen self.checkFullscreen = checkFullscreen
self.moveMouseInstead = moveMouseInstead self.moveMouseInstead = moveMouseInstead
self.insetHorizontal = insetHorizontal self.insetHorizontal = insetHorizontal
@@ -69,6 +72,8 @@ struct DPSettings: Codable {
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
dockMoves = try container.decodeIfPresent(Int.self, forKey: .dockMoves) dockMoves = try container.decodeIfPresent(Int.self, forKey: .dockMoves)
?? defaults.dockMoves ?? defaults.dockMoves
mouseMoves = try container.decodeIfPresent(Int.self, forKey: .mouseMoves)
?? defaults.mouseMoves
checkFullscreen = try container.decodeIfPresent(Bool.self, forKey: .checkFullscreen) checkFullscreen = try container.decodeIfPresent(Bool.self, forKey: .checkFullscreen)
?? defaults.checkFullscreen ?? defaults.checkFullscreen

View File

@@ -64,10 +64,12 @@ class MouseTracker {
func checkMouse(_ event: NSEvent) { func checkMouse(_ event: NSEvent) {
let location = event.mouseLocationCG let location = event.mouseLocationCG
// var cgpointForSkyHigh = NSEvent.mouseLocation #if DEBUG
// cgpointForSkyHigh.x -= 10 var cgpointForSkyHigh = NSEvent.mouseLocation
// cgpointForSkyHigh.y -= 5 cgpointForSkyHigh.x -= 20
// skyHigh.move(to: cgpointForSkyHigh) cgpointForSkyHigh.y -= 5
skyHigh.move(to: cgpointForSkyHigh)
#endif
guard settings.settings.checkFullscreen else { guard settings.settings.checkFullscreen else {
handleDockValue(dockIsAt: currentDockSide, location: location) handleDockValue(dockIsAt: currentDockSide, location: location)
@@ -145,8 +147,6 @@ class MouseTracker {
let posX = CGFloat.random(in: rangeW) let posX = CGFloat.random(in: rangeW)
let rangeH = settings.settings.mouseInsetBottom...settings.settings.mouseInsetTop let rangeH = settings.settings.mouseInsetBottom...settings.settings.mouseInsetTop
let posY = CGFloat.random(in: rangeH) let posY = CGFloat.random(in: rangeH)
print(prevPoint)
print(posX, posY)
timer?.invalidate() timer?.invalidate()
loopIteration = 0 loopIteration = 0
@@ -156,6 +156,8 @@ class MouseTracker {
guard let self = self else { return } guard let self = self else { return }
guard loopIteration < 500 else { guard loopIteration < 500 else {
skyHigh.hide() skyHigh.hide()
settings.settings.mouseMoves += 1
refreshMenus()
timer?.invalidate() timer?.invalidate()
return return
} }
@@ -164,7 +166,7 @@ class MouseTracker {
let cgpoint = CGPoint(x: newPosX, y: newPosY) let cgpoint = CGPoint(x: newPosX, y: newPosY)
CGWarpMouseCursorPosition(cgpoint) CGWarpMouseCursorPosition(cgpoint)
var cgpointForSkyHigh = cgpoint var cgpointForSkyHigh = cgpoint
cgpointForSkyHigh.x -= 10 cgpointForSkyHigh.x -= 20
cgpointForSkyHigh.y += 5 cgpointForSkyHigh.y += 5
skyHigh.move(to: cgpointForSkyHigh.invertedForScreen) skyHigh.move(to: cgpointForSkyHigh.invertedForScreen)

View File

@@ -35,6 +35,9 @@ class SkyHigh {
window.ignoresMouseEvents = true window.ignoresMouseEvents = true
window.hasShadow = true window.hasShadow = true
window.collectionBehavior = NSWindow.CollectionBehavior.canJoinAllSpaces.union(.stationary) window.collectionBehavior = NSWindow.CollectionBehavior.canJoinAllSpaces.union(.stationary)
#if DEBUG
show()
#endif
} }
func move(to: CGPoint) { func move(to: CGPoint) {