rerwrote getDockHeight() & added calcDockFrom{Side} -> CGFloat

reduced minimum os reqs
This commit is contained in:
neon443
2025-03-19 15:01:40 +00:00
parent 96eec065b8
commit d4a3ab6ad0
5 changed files with 174 additions and 63 deletions

View File

@@ -282,7 +282,8 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0;
MACOSX_DEPLOYMENT_TARGET = 13;
MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = dev.neon443.DockPhobia;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -315,7 +316,8 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0;
MACOSX_DEPLOYMENT_TARGET = 13;
MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = dev.neon443.DockPhobia;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;

View File

@@ -14,8 +14,8 @@
filePath = "DockPhobia/DockPhobiaApp.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "181"
endingLineNumber = "181"
startingLineNumber = "196"
endingLineNumber = "196"
landmarkName = "getDockSide()"
landmarkType = "9">
</BreakpointContent>
@@ -30,8 +30,8 @@
filePath = "DockPhobia/DockPhobiaApp.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "262"
endingLineNumber = "262"
startingLineNumber = "315"
endingLineNumber = "315"
landmarkName = "moveDock(_:)"
landmarkType = "9">
</BreakpointContent>
@@ -46,8 +46,8 @@
filePath = "DockPhobia/DockPhobiaApp.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "173"
endingLineNumber = "173"
startingLineNumber = "188"
endingLineNumber = "188"
landmarkName = "osascript(_:)"
landmarkType = "9">
</BreakpointContent>
@@ -62,8 +62,8 @@
filePath = "DockPhobia/DockPhobiaApp.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "252"
endingLineNumber = "252"
startingLineNumber = "297"
endingLineNumber = "297"
landmarkName = "getScreenSize()"
landmarkType = "9">
</BreakpointContent>
@@ -78,11 +78,91 @@
filePath = "DockPhobia/DockPhobiaApp.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "258"
endingLineNumber = "258"
startingLineNumber = "311"
endingLineNumber = "311"
landmarkName = "getScreenSize()"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "F9F480ED-679E-42E3-9312-9C34C76E7492"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "DockPhobia/DockPhobiaApp.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "222"
endingLineNumber = "222"
landmarkName = "getDockHeight()"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "50D56294-D942-45E9-87BB-9D4D40B0E6AE"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "DockPhobia/DockPhobiaApp.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "228"
endingLineNumber = "228"
landmarkName = "calcDockFromBottom()"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "EFCDAC16-C458-4D10-A502-2009165C83FD"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "DockPhobia/DockPhobiaApp.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "234"
endingLineNumber = "234"
landmarkName = "calcDockFromRight()"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "ED43EB58-5195-4D34-AA9D-F580B9DAE105"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "DockPhobia/DockPhobiaApp.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "151"
endingLineNumber = "151"
landmarkName = "shell(_:)"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "FD129BB2-58E8-4631-AE52-B2E3CE8C7D0F"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "DockPhobia/DockPhobiaApp.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "152"
endingLineNumber = "152"
landmarkName = "shell(_:)"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>

View File

@@ -5,36 +5,12 @@
// Created by neon443 on 13/03/2025.
//
import SwiftUI
struct ContentView: View {
@Binding var isTracking: Bool
@State var mouseloc = NSEvent.mouseLocation
var body: some View {
VStack {
Text("Screen size: \(getScreenSize())")
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
Spacer()
Button("Start") {
startTrackingMouse()
}
Button("Stop") {
stopTrackingMouse()
}
Button() {
NSApp.terminate(nil)
} label: {
Text("Quit")
}
}
.padding()
}
}
#Preview {
ContentView(isTracking: .constant(true))
}
//import SwiftUI
//
//struct ContentView: View {
//
//}
//
//#Preview {
// ContentView(isTracking: .constant(true))
//}

View File

@@ -82,25 +82,36 @@ struct DockPhobiaApp: App {
.keyboardShortcut(",")
Divider()
Button("try shell") {
print(shell("echo hello"))
print(shell("echo hello") as Any)
}
Divider()
Button("Move Dock to Right") {
moveDock("right")
}
Divider()
Button("Move Dock to Left") {
moveDock("left")
}
Button("Move Dock to Bottom") {
moveDock("bottom")
}
Divider()
Button("Get Dock orientation") {
print(getDockSide())
}
Button("Get Dock Height Percentage") {
print(getDockHeightPercentage())
print(getDockHeight())
}
Divider()
Button("calcdockFromBottom") {
print(calcDockFromBottom())
}
Button("calc dock from right") {
print(calcDockFromRight())
}
Button("calc dock from left") {
print(calcDockFromLeft())
}
Divider()
Button("Quit") {
NSApplication.shared.terminate(nil)
}
@@ -109,7 +120,7 @@ struct DockPhobiaApp: App {
}
}
func shell(_ command: String) -> (output: String?, error: String?) {
func shell(_ command: String) -> String? {
let process = Process()
let pipe = Pipe()
let pipeError = Pipe()
@@ -136,7 +147,11 @@ func shell(_ command: String) -> (output: String?, error: String?) {
data: dataError,
encoding: .utf8
)?.trimmingCharacters(in: .whitespacesAndNewlines)
return (output: output, error: outputError)
if outputError != "" {
print(outputError as Any)
}
return output
}
func osascript(_ script: String) -> String? {
@@ -177,23 +192,52 @@ func osascript(_ script: String) -> String? {
func getDockSide() -> String {
let result = shell("defaults read com.apple.Dock orientation")
print("dock is on the \(result.output ?? "idk")")
return result.output ?? "unknown"
print("dock is on the \(result ?? "idk")")
return result ?? "unknown"
}
// global event tap
var eventTap: CFMachPort?
func getDockHeightPercentage() -> Double {
guard let screen = NSScreen.main else { return 0 }
func getDockHeight() -> Double {
guard let screen = NSScreen.main else {
return 0
}
let fullHeight = screen.frame.height
let dockSide = getDockSide()
let screenDimensions = getScreenSize()
let width = screenDimensions.x
let height = screenDimensions.y
let visibleHeight = screen.visibleFrame.height
let dockHeight = fullHeight - visibleHeight
let percentage = (dockHeight / fullHeight) * 100
let perpendicularToDock: CGFloat
if dockSide == "bottom" {
perpendicularToDock = height
} else {
perpendicularToDock = width
}
return percentage
let dockHeight = CGFloat(height) - visibleHeight
let percentage = (dockHeight / perpendicularToDock)
return Double(percentage)
}
func calcDockFromBottom() -> CGFloat {
let screenSize = getScreenSize()
let dockHeight = getDockHeight()
return screenSize.y - (screenSize.y * dockHeight)
}
func calcDockFromRight() -> CGFloat {
let screenSize = getScreenSize()
let dockHeight = getDockHeight()
return screenSize.x - (screenSize.x * dockHeight)
}
func calcDockFromLeft() -> CGFloat {
let screenSize = getScreenSize()
let dockHeight = getDockHeight()
return screenSize.x * dockHeight
}
func startTrackingMouse() {
@@ -206,8 +250,9 @@ func startTrackingMouse() {
options: CGEventTapOptions.defaultTap,
eventsOfInterest: mask,
callback: { (proxy, type, event, userInfo) -> Unmanaged<CGEvent>? in
let location = event.location
// let location = event.location
// print("mouse at \(location)")
// print("mouse at \(event.location)")
//TODO: add Dock moving here
return Unmanaged.passRetained(event)
},
@@ -243,7 +288,7 @@ func stopTrackingMouse() {
}
}
func getScreenSize() -> (x: Int, y: Int) {
func getScreenSize() -> (x: CGFloat, y: CGFloat) {
let script = """
tell application "Finder"
get bounds of window of desktop
@@ -252,8 +297,16 @@ func getScreenSize() -> (x: Int, y: Int) {
let result = osascript(script)?.dropFirst(6).split(separator: ", ")
// removes the "0, 0, " and splits into an arr
let resultTuple = (
Int( result![0] )!,
Int( result![1] )!
CGFloat(
Int(
result![0]
)!
),
CGFloat(
Int(
result![1]
)!
)
)
return resultTuple
}
@@ -271,6 +324,6 @@ func moveDock(_ to: String) {
end tell
end tell
"""
let result = osascript(script)
osascript(script)
return
}

View File

Binary file not shown.