mirror of
https://github.com/neon443/DockPhobia.git
synced 2026-03-11 06:49:12 +00:00
large rewrite of dpsettings to use an init and handle failed decodes
make moveMouse() use dpsettings' values skyhigh moves faster skyhigh uses dpsettings' values extended NSScreen for safe access to main?.frame customising the width height of the mouse move rect should be possible? now just neeed a prefs windo
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
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 */; };
|
||||
A9C9B0682DE888B20039D7A5 /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C9B0672DE888B20039D7A5 /* Preferences.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@@ -27,6 +28,7 @@
|
||||
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>"; };
|
||||
A9C9B0672DE888B20039D7A5 /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -52,6 +54,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A94BEC0E2DE23E8500D4811D /* MainMenu.xib */,
|
||||
A9C9B0672DE888B20039D7A5 /* Preferences.swift */,
|
||||
);
|
||||
path = Views;
|
||||
sourceTree = "<group>";
|
||||
@@ -163,6 +166,7 @@
|
||||
files = (
|
||||
A98C20C62DE614180008D61C /* DPSettings.swift in Sources */,
|
||||
A9C9AF832DE77CB70039D7A5 /* SkyHigh.swift in Sources */,
|
||||
A9C9B0682DE888B20039D7A5 /* Preferences.swift in Sources */,
|
||||
A966B4F82DE0852900C721A5 /* MouseTracker.swift in Sources */,
|
||||
A966B4F42DE0842500C721A5 /* AppDelegate.swift in Sources */,
|
||||
A9C9AF812DE7776A0039D7A5 /* DockSide.swift in Sources */,
|
||||
|
||||
BIN
DockPhobia/.DS_Store
vendored
BIN
DockPhobia/.DS_Store
vendored
Binary file not shown.
@@ -8,10 +8,78 @@
|
||||
import Foundation
|
||||
import AppKit
|
||||
|
||||
extension NSScreen {
|
||||
static var mainFrame: CGRect {
|
||||
main?.frame ?? CGRect(x: 0, y: 0, width: 1920, height: 1080)
|
||||
}
|
||||
static var mainFrameWidth: CGFloat {
|
||||
main?.frame.width ?? 1920
|
||||
}
|
||||
static var mainFrameHeight: CGFloat {
|
||||
main?.frame.height ?? 1080
|
||||
}
|
||||
}
|
||||
|
||||
struct DPSettings: Codable {
|
||||
var dockMoves: Int = 0
|
||||
var checkFullscreen: Bool = false
|
||||
var moveMouseInstead: Bool = false
|
||||
var dockMoves: Int
|
||||
var checkFullscreen: Bool
|
||||
var moveMouseInstead: Bool
|
||||
|
||||
var mouseInsetLeading: CGFloat {
|
||||
NSScreen.mainFrameWidth*insetHorizontal
|
||||
}
|
||||
var mouseInsetBottom: CGFloat {
|
||||
NSScreen.mainFrameHeight*insetVertical
|
||||
}
|
||||
var mouseInsetTop: CGFloat {
|
||||
NSScreen.mainFrameHeight*(1-(2*insetVertical))
|
||||
}
|
||||
var mouseInsetTrailing: CGFloat {
|
||||
NSScreen.mainFrameWidth*(1-(2*insetHorizontal))
|
||||
}
|
||||
|
||||
var insetHorizontal: CGFloat
|
||||
var insetVertical: CGFloat
|
||||
|
||||
var mouseMoveRect: CGRect {
|
||||
return CGRect(
|
||||
x: mouseInsetLeading,
|
||||
y: mouseInsetBottom,
|
||||
width: mouseInsetTrailing,
|
||||
height: mouseInsetTop
|
||||
)
|
||||
}
|
||||
|
||||
init(
|
||||
dockMoves: Int = 0,
|
||||
checkFullscreen: Bool = false,
|
||||
moveMouseInstead: Bool = false,
|
||||
insetHorizontal: CGFloat = 0.05,
|
||||
insetVertical: CGFloat = 0.1
|
||||
) {
|
||||
self.dockMoves = dockMoves
|
||||
self.checkFullscreen = checkFullscreen
|
||||
self.moveMouseInstead = moveMouseInstead
|
||||
self.insetHorizontal = insetHorizontal
|
||||
self.insetVertical = insetVertical
|
||||
}
|
||||
|
||||
init(from decoder: any Decoder) throws {
|
||||
let defaults = DPSettings()
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
dockMoves = try container.decodeIfPresent(Int.self, forKey: .dockMoves)
|
||||
?? defaults.dockMoves
|
||||
|
||||
checkFullscreen = try container.decodeIfPresent(Bool.self, forKey: .checkFullscreen)
|
||||
?? defaults.checkFullscreen
|
||||
moveMouseInstead = try container.decodeIfPresent(Bool.self, forKey: .moveMouseInstead)
|
||||
?? defaults.moveMouseInstead
|
||||
|
||||
insetHorizontal = try container.decodeIfPresent(CGFloat.self, forKey: .insetHorizontal)
|
||||
?? defaults.insetHorizontal
|
||||
insetVertical = try container.decodeIfPresent(CGFloat.self, forKey: .insetVertical)
|
||||
?? defaults.insetVertical
|
||||
}
|
||||
}
|
||||
|
||||
class DPSettingsModel {
|
||||
|
||||
@@ -23,22 +23,19 @@ class MouseTracker {
|
||||
var dockHeight: CGFloat = 0
|
||||
|
||||
var settings: DPSettingsModel
|
||||
var skyHigh = SkyHigh()
|
||||
var skyHigh: SkyHigh
|
||||
|
||||
init(settings: DPSettingsModel) {
|
||||
print(DockSide())
|
||||
if let screen = NSScreen.main {
|
||||
let rect = screen.frame
|
||||
|
||||
self.screen = Screen(
|
||||
width: rect.width,
|
||||
height: rect.height
|
||||
width: NSScreen.mainFrameWidth,
|
||||
height: NSScreen.mainFrameHeight
|
||||
)
|
||||
print(self.screen)
|
||||
} else {
|
||||
fatalError("no screen wtf???")
|
||||
}
|
||||
|
||||
self.settings = settings
|
||||
self.skyHigh = SkyHigh(settings: settings)
|
||||
|
||||
self.currentDockSide = .left
|
||||
moveDock(.bottom)
|
||||
@@ -138,9 +135,9 @@ class MouseTracker {
|
||||
}
|
||||
|
||||
func moveMouse() {
|
||||
let rangeW = screen.width*0.1...screen.width*0.9
|
||||
let rangeW = settings.settings.mouseInsetLeading...settings.settings.mouseInsetTrailing
|
||||
let posX = CGFloat.random(in: rangeW)
|
||||
let rangeH = screen.height*0.1...screen.height*0.9
|
||||
let rangeH = settings.settings.mouseInsetBottom...settings.settings.mouseInsetTop
|
||||
let posY = CGFloat.random(in: rangeH)
|
||||
CGDisplayMoveCursorToPoint(0, CGPoint(x: posX, y: posY))
|
||||
}
|
||||
@@ -173,7 +170,6 @@ class MouseTracker {
|
||||
}
|
||||
|
||||
func getDockSize() {
|
||||
guard let screen = NSScreen.main?.frame else { fatalError() }
|
||||
guard let screenVisible = NSScreen.main?.visibleFrame else { fatalError() }
|
||||
self.dockHeight = screen.height - screenVisible.height
|
||||
}
|
||||
|
||||
@@ -12,16 +12,13 @@ class SkyHigh {
|
||||
private var window: NSWindow
|
||||
private var x = 1
|
||||
private var timer: Timer?
|
||||
var settings: DPSettingsModel
|
||||
|
||||
init(settings: DPSettingsModel) {
|
||||
self.settings = settings
|
||||
|
||||
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
|
||||
),
|
||||
contentRect: settings.settings.mouseMoveRect,
|
||||
styleMask: .borderless,
|
||||
backing: .buffered,
|
||||
defer: false
|
||||
@@ -31,12 +28,12 @@ class SkyHigh {
|
||||
window.level = NSWindow.Level.statusBar + 1
|
||||
window.ignoresMouseEvents = true
|
||||
window.hasShadow = true
|
||||
window.collectionBehavior = NSWindow.CollectionBehavior.canJoinAllSpaces.union(.stationary)
|
||||
window.makeKeyAndOrderFront(nil)
|
||||
window.setFrameOrigin(NSPoint(x: screen.width*0.05, y: screen.height*0.1))
|
||||
}
|
||||
|
||||
func move() {
|
||||
x = 1
|
||||
x = 5
|
||||
timer?.invalidate()
|
||||
timer = Timer(timeInterval: 0.01, repeats: true) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
@@ -45,7 +42,7 @@ class SkyHigh {
|
||||
return
|
||||
}
|
||||
self.window.setFrameOrigin(NSPoint(x: 1000-self.x, y: 1000-self.x))
|
||||
self.x += 1
|
||||
self.x += 5
|
||||
}
|
||||
RunLoop.current.add(timer!, forMode: .common)
|
||||
}
|
||||
|
||||
8
DockPhobia/Views/Preferences.swift
Normal file
8
DockPhobia/Views/Preferences.swift
Normal file
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// Preferences.swift
|
||||
// DockPhobia
|
||||
//
|
||||
// Created by neon443 on 29/05/2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
Reference in New Issue
Block a user