mirror of
https://github.com/neon443/DockPhobia.git
synced 2026-03-11 14:56:16 +00:00
Compare commits
4 Commits
c099d4bec3
...
853fc2a2db
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
853fc2a2db | ||
|
|
6a68713ad5 | ||
|
|
b15116b292 | ||
|
|
e4c41c4a58 |
@@ -12,6 +12,8 @@
|
|||||||
A966B4F52DE0842500C721A5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A966B4EF2DE0842400C721A5 /* Assets.xcassets */; };
|
A966B4F52DE0842500C721A5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A966B4EF2DE0842400C721A5 /* Assets.xcassets */; };
|
||||||
A966B4F82DE0852900C721A5 /* MouseTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = A966B4F72DE0852900C721A5 /* MouseTracker.swift */; };
|
A966B4F82DE0852900C721A5 /* MouseTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = A966B4F72DE0852900C721A5 /* MouseTracker.swift */; };
|
||||||
A98C20C62DE614180008D61C /* DPSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98C20C52DE614180008D61C /* DPSettings.swift */; };
|
A98C20C62DE614180008D61C /* DPSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = A98C20C52DE614180008D61C /* DPSettings.swift */; };
|
||||||
|
A9C9AF812DE7776A0039D7A5 /* DockSide.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C9AF802DE777530039D7A5 /* DockSide.swift */; };
|
||||||
|
A9C9AF832DE77CB70039D7A5 /* SkyHigh.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C9AF822DE77CB70039D7A5 /* SkyHigh.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
@@ -23,6 +25,8 @@
|
|||||||
A966B4F72DE0852900C721A5 /* MouseTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MouseTracker.swift; sourceTree = "<group>"; };
|
A966B4F72DE0852900C721A5 /* MouseTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MouseTracker.swift; sourceTree = "<group>"; };
|
||||||
A97798072DE485F200B6CB13 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
|
A97798072DE485F200B6CB13 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
|
||||||
A98C20C52DE614180008D61C /* DPSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DPSettings.swift; sourceTree = "<group>"; };
|
A98C20C52DE614180008D61C /* DPSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DPSettings.swift; sourceTree = "<group>"; };
|
||||||
|
A9C9AF802DE777530039D7A5 /* DockSide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DockSide.swift; sourceTree = "<group>"; };
|
||||||
|
A9C9AF822DE77CB70039D7A5 /* SkyHigh.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkyHigh.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@@ -74,7 +78,9 @@
|
|||||||
children = (
|
children = (
|
||||||
A966B4EE2DE0842400C721A5 /* AppDelegate.swift */,
|
A966B4EE2DE0842400C721A5 /* AppDelegate.swift */,
|
||||||
A966B4F72DE0852900C721A5 /* MouseTracker.swift */,
|
A966B4F72DE0852900C721A5 /* MouseTracker.swift */,
|
||||||
|
A9C9AF822DE77CB70039D7A5 /* SkyHigh.swift */,
|
||||||
A98C20C52DE614180008D61C /* DPSettings.swift */,
|
A98C20C52DE614180008D61C /* DPSettings.swift */,
|
||||||
|
A9C9AF802DE777530039D7A5 /* DockSide.swift */,
|
||||||
A94BEC102DE23ECE00D4811D /* Views */,
|
A94BEC102DE23ECE00D4811D /* Views */,
|
||||||
A94BEC0A2DE21F8100D4811D /* Resources */,
|
A94BEC0A2DE21F8100D4811D /* Resources */,
|
||||||
A966B4F02DE0842400C721A5 /* DockPhobia.entitlements */,
|
A966B4F02DE0842400C721A5 /* DockPhobia.entitlements */,
|
||||||
@@ -156,8 +162,10 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
A98C20C62DE614180008D61C /* DPSettings.swift in Sources */,
|
A98C20C62DE614180008D61C /* DPSettings.swift in Sources */,
|
||||||
|
A9C9AF832DE77CB70039D7A5 /* SkyHigh.swift in Sources */,
|
||||||
A966B4F82DE0852900C721A5 /* MouseTracker.swift in Sources */,
|
A966B4F82DE0852900C721A5 /* MouseTracker.swift in Sources */,
|
||||||
A966B4F42DE0842500C721A5 /* AppDelegate.swift in Sources */,
|
A966B4F42DE0842500C721A5 /* AppDelegate.swift in Sources */,
|
||||||
|
A9C9AF812DE7776A0039D7A5 /* DockSide.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
import AppKit
|
import AppKit
|
||||||
|
|
||||||
@main
|
@NSApplicationMain
|
||||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
|
|
||||||
public var statusItem: NSStatusItem!
|
public var statusItem: NSStatusItem!
|
||||||
@@ -55,6 +55,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
keyEquivalent: ""
|
keyEquivalent: ""
|
||||||
)
|
)
|
||||||
menu.addItem(dockMoves)
|
menu.addItem(dockMoves)
|
||||||
|
menu.addItem(NSMenuItem.separator())
|
||||||
|
|
||||||
|
let moveMouseButton = NSMenuItem(
|
||||||
|
title: "Move cursor instead",
|
||||||
|
action: #selector(moveMouseToggle),
|
||||||
|
keyEquivalent: ""
|
||||||
|
)
|
||||||
|
moveMouseButton.state = NSControl.StateValue(rawValue: settings.settings.moveMouseInstead ? 1 : 0)
|
||||||
|
menu.addItem(moveMouseButton)
|
||||||
|
|
||||||
menu.addItem(NSMenuItem.separator())
|
menu.addItem(NSMenuItem.separator())
|
||||||
|
|
||||||
@@ -67,28 +76,18 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
menu.addItem(checkfullscreenButton)
|
menu.addItem(checkfullscreenButton)
|
||||||
menu.addItem(NSMenuItem.separator())
|
menu.addItem(NSMenuItem.separator())
|
||||||
|
|
||||||
menu.addItem(
|
menu.addItem(NSMenuItem(
|
||||||
NSMenuItem(
|
|
||||||
title: "Move Dock to left",
|
title: "Move Dock to left",
|
||||||
action: #selector(moveDockObjcLeft),
|
action: #selector(moveDockObjcLeft),
|
||||||
keyEquivalent: ""
|
keyEquivalent: ""))
|
||||||
)
|
menu.addItem(NSMenuItem(
|
||||||
)
|
|
||||||
menu.addItem(
|
|
||||||
NSMenuItem(
|
|
||||||
title: "Move Dock to bottom",
|
title: "Move Dock to bottom",
|
||||||
action: #selector(moveDockObjcBottom),
|
action: #selector(moveDockObjcBottom),
|
||||||
keyEquivalent: ""
|
keyEquivalent: ""))
|
||||||
)
|
menu.addItem(NSMenuItem(
|
||||||
)
|
title: "Move Dock to right",
|
||||||
menu.addItem(
|
action: #selector(moveDockObjcRight),
|
||||||
NSMenuItem(
|
keyEquivalent: ""))
|
||||||
title: "Move Dock to right",
|
|
||||||
action: #selector(moveDockObjcRight),
|
|
||||||
keyEquivalent: ""
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
menu.addItem(NSMenuItem.separator())
|
menu.addItem(NSMenuItem.separator())
|
||||||
|
|
||||||
let quit = NSMenuItem(title: "Quit", action: #selector(quit), keyEquivalent: "q")
|
let quit = NSMenuItem(title: "Quit", action: #selector(quit), keyEquivalent: "q")
|
||||||
@@ -124,6 +123,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
settings.settings.checkFullscreen.toggle()
|
settings.settings.checkFullscreen.toggle()
|
||||||
refreshMenus()
|
refreshMenus()
|
||||||
}
|
}
|
||||||
|
@objc func moveMouseToggle() {
|
||||||
|
settings.settings.moveMouseInstead.toggle()
|
||||||
|
refreshMenus()
|
||||||
|
}
|
||||||
func describeStartButton() -> String {
|
func describeStartButton() -> String {
|
||||||
if mouseTracker.running {
|
if mouseTracker.running {
|
||||||
return "Stop tracking"
|
return "Stop tracking"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import AppKit
|
|||||||
struct DPSettings: Codable {
|
struct DPSettings: Codable {
|
||||||
var dockMoves: Int = 0
|
var dockMoves: Int = 0
|
||||||
var checkFullscreen: Bool = false
|
var checkFullscreen: Bool = false
|
||||||
|
var moveMouseInstead: Bool = false
|
||||||
}
|
}
|
||||||
|
|
||||||
class DPSettingsModel {
|
class DPSettingsModel {
|
||||||
|
|||||||
59
DockPhobia/DockSide.swift
Normal file
59
DockPhobia/DockSide.swift
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
//
|
||||||
|
// DockSide.swift
|
||||||
|
// DockPhobia
|
||||||
|
//
|
||||||
|
// Created by neon443 on 28/05/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
enum DockSide: Int, RawRepresentable {
|
||||||
|
case left
|
||||||
|
case bottom
|
||||||
|
case right
|
||||||
|
|
||||||
|
public typealias RawValue = String
|
||||||
|
|
||||||
|
public var rawValue: RawValue {
|
||||||
|
switch self {
|
||||||
|
case .left:
|
||||||
|
return "left"
|
||||||
|
case .right:
|
||||||
|
return "right"
|
||||||
|
case .bottom:
|
||||||
|
return "bottom"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Random Dock Side
|
||||||
|
/// - will return a random Dock Side when calling DockSide()
|
||||||
|
public init() {
|
||||||
|
self = DockSide(rawValue: Int.random(in: 1...3))!
|
||||||
|
}
|
||||||
|
|
||||||
|
public init?(rawValue: String) {
|
||||||
|
switch rawValue {
|
||||||
|
case "left":
|
||||||
|
self = .left
|
||||||
|
case "right":
|
||||||
|
self = .right
|
||||||
|
case "bottom":
|
||||||
|
self = .bottom
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public init?(rawValue: Int) {
|
||||||
|
switch rawValue {
|
||||||
|
case 1:
|
||||||
|
self = .left
|
||||||
|
case 2:
|
||||||
|
self = .bottom
|
||||||
|
case 3:
|
||||||
|
self = .right
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,69 +15,15 @@ struct Screen {
|
|||||||
var height: CGFloat
|
var height: CGFloat
|
||||||
}
|
}
|
||||||
|
|
||||||
enum DockSide: Int, RawRepresentable {
|
|
||||||
case left
|
|
||||||
case bottom
|
|
||||||
case right
|
|
||||||
|
|
||||||
public typealias RawValue = String
|
|
||||||
|
|
||||||
public var rawValue: RawValue {
|
|
||||||
switch self {
|
|
||||||
case .left:
|
|
||||||
return "left"
|
|
||||||
case .right:
|
|
||||||
return "right"
|
|
||||||
case .bottom:
|
|
||||||
return "bottom"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Random Dock Side
|
|
||||||
/// - will return a random Dock Side when calling DockSide()
|
|
||||||
public init() {
|
|
||||||
self = DockSide(rawValue: Int.random(in: 1...3))!
|
|
||||||
}
|
|
||||||
|
|
||||||
public init?(rawValue: String) {
|
|
||||||
switch rawValue {
|
|
||||||
case "left":
|
|
||||||
self = .left
|
|
||||||
case "right":
|
|
||||||
self = .right
|
|
||||||
case "bottom":
|
|
||||||
self = .bottom
|
|
||||||
default:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public init?(rawValue: Int) {
|
|
||||||
switch rawValue {
|
|
||||||
case 1:
|
|
||||||
self = .left
|
|
||||||
case 2:
|
|
||||||
self = .bottom
|
|
||||||
case 3:
|
|
||||||
self = .right
|
|
||||||
default:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MouseTracker {
|
class MouseTracker {
|
||||||
var screen: Screen
|
var screen: Screen
|
||||||
|
|
||||||
var monitor: Any?
|
var monitor: Any?
|
||||||
|
|
||||||
var running: Bool = false
|
var running: Bool = false
|
||||||
|
|
||||||
var currentDockSide: DockSide
|
var currentDockSide: DockSide
|
||||||
|
|
||||||
var dockHeight: CGFloat = 0
|
var dockHeight: CGFloat = 0
|
||||||
|
|
||||||
var settings: DPSettingsModel
|
var settings: DPSettingsModel
|
||||||
|
var skyHigh = SkyHigh()
|
||||||
|
|
||||||
init(settings: DPSettingsModel) {
|
init(settings: DPSettingsModel) {
|
||||||
print(DockSide())
|
print(DockSide())
|
||||||
@@ -123,37 +69,63 @@ class MouseTracker {
|
|||||||
case .left:
|
case .left:
|
||||||
guard location.x < dockHeight else { return }
|
guard location.x < dockHeight else { return }
|
||||||
if location.y < screen.height/2 {
|
if location.y < screen.height/2 {
|
||||||
moveDock(.bottom)
|
moveDockOrMouse(.bottom)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
moveDock(.right)
|
moveDockOrMouse(.right)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case .bottom:
|
case .bottom:
|
||||||
guard location.y > screen.height - dockHeight else { return }
|
guard location.y > screen.height - dockHeight else { return }
|
||||||
if location.x < screen.width/2 {
|
if location.x < screen.width/2 {
|
||||||
moveDock(.right)
|
moveDockOrMouse(.right)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
moveDock(.left)
|
moveDockOrMouse(.left)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case .right:
|
case .right:
|
||||||
guard location.x > screen.width - dockHeight else { return }
|
guard location.x > screen.width - dockHeight else { return }
|
||||||
if location.y < screen.height/2 {
|
if location.y < screen.height/2 {
|
||||||
moveDock(.bottom)
|
moveDockOrMouse(.bottom)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
moveDock(.left)
|
moveDockOrMouse(.left)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func moveDockOrMouse(_ dockTo: DockSide) {
|
||||||
|
if settings.settings.moveMouseInstead {
|
||||||
|
moveMouse()
|
||||||
|
} else {
|
||||||
|
moveDock(dockTo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func start() {
|
func start() {
|
||||||
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() {
|
||||||
@@ -165,6 +137,14 @@ class MouseTracker {
|
|||||||
print("stop tracking")
|
print("stop tracking")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func moveMouse() {
|
||||||
|
let rangeW = screen.width*0.1...screen.width*0.9
|
||||||
|
let posX = CGFloat.random(in: rangeW)
|
||||||
|
let rangeH = screen.height*0.1...screen.height*0.9
|
||||||
|
let posY = CGFloat.random(in: rangeH)
|
||||||
|
CGDisplayMoveCursorToPoint(0, CGPoint(x: posX, y: posY))
|
||||||
|
}
|
||||||
|
|
||||||
func moveDock(_ toSide: DockSide) {
|
func moveDock(_ toSide: DockSide) {
|
||||||
guard currentDockSide != toSide else { return }
|
guard currentDockSide != toSide else { return }
|
||||||
// let scriptHide = """
|
// let scriptHide = """
|
||||||
|
|||||||
52
DockPhobia/SkyHigh.swift
Normal file
52
DockPhobia/SkyHigh.swift
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
//
|
||||||
|
// SkyHigh.swift
|
||||||
|
// DockPhobia
|
||||||
|
//
|
||||||
|
// Created by neon443 on 28/05/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import Cocoa
|
||||||
|
|
||||||
|
class SkyHigh {
|
||||||
|
private var window: NSWindow
|
||||||
|
private var x = 1
|
||||||
|
private var timer: Timer?
|
||||||
|
|
||||||
|
init() {
|
||||||
|
guard let screen = NSScreen.main?.frame else { fatalError() }
|
||||||
|
self.window = NSWindow(
|
||||||
|
contentRect: CGRect(
|
||||||
|
x: screen.width*0.05,
|
||||||
|
y: screen.height*0.1,
|
||||||
|
width: screen.width*0.9,
|
||||||
|
height: screen.height*0.8
|
||||||
|
),
|
||||||
|
styleMask: .borderless,
|
||||||
|
backing: .buffered,
|
||||||
|
defer: false
|
||||||
|
)
|
||||||
|
window.backgroundColor = .init(srgbRed: 1, green: 1, blue: 1, alpha: 0.1)
|
||||||
|
window.isOpaque = false
|
||||||
|
window.level = NSWindow.Level.statusBar + 1
|
||||||
|
window.ignoresMouseEvents = true
|
||||||
|
window.hasShadow = true
|
||||||
|
window.makeKeyAndOrderFront(nil)
|
||||||
|
window.setFrameOrigin(NSPoint(x: screen.width*0.05, y: screen.height*0.1))
|
||||||
|
}
|
||||||
|
|
||||||
|
func move() {
|
||||||
|
x = 1
|
||||||
|
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 += 1
|
||||||
|
}
|
||||||
|
RunLoop.current.add(timer!, forMode: .common)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user