mirror of
https://github.com/neon443/DockPhobia.git
synced 2026-03-11 06:49:12 +00:00
rerwrote getDockHeight() & added calcDockFrom{Side} -> CGFloat
reduced minimum os reqs
This commit is contained in:
@@ -282,7 +282,8 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0;
|
MACOSX_DEPLOYMENT_TARGET = 13;
|
||||||
|
MARKETING_VERSION = 2.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = dev.neon443.DockPhobia;
|
PRODUCT_BUNDLE_IDENTIFIER = dev.neon443.DockPhobia;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
@@ -315,7 +316,8 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0;
|
MACOSX_DEPLOYMENT_TARGET = 13;
|
||||||
|
MARKETING_VERSION = 2.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = dev.neon443.DockPhobia;
|
PRODUCT_BUNDLE_IDENTIFIER = dev.neon443.DockPhobia;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
filePath = "DockPhobia/DockPhobiaApp.swift"
|
filePath = "DockPhobia/DockPhobiaApp.swift"
|
||||||
startingColumnNumber = "9223372036854775807"
|
startingColumnNumber = "9223372036854775807"
|
||||||
endingColumnNumber = "9223372036854775807"
|
endingColumnNumber = "9223372036854775807"
|
||||||
startingLineNumber = "181"
|
startingLineNumber = "196"
|
||||||
endingLineNumber = "181"
|
endingLineNumber = "196"
|
||||||
landmarkName = "getDockSide()"
|
landmarkName = "getDockSide()"
|
||||||
landmarkType = "9">
|
landmarkType = "9">
|
||||||
</BreakpointContent>
|
</BreakpointContent>
|
||||||
@@ -30,8 +30,8 @@
|
|||||||
filePath = "DockPhobia/DockPhobiaApp.swift"
|
filePath = "DockPhobia/DockPhobiaApp.swift"
|
||||||
startingColumnNumber = "9223372036854775807"
|
startingColumnNumber = "9223372036854775807"
|
||||||
endingColumnNumber = "9223372036854775807"
|
endingColumnNumber = "9223372036854775807"
|
||||||
startingLineNumber = "262"
|
startingLineNumber = "315"
|
||||||
endingLineNumber = "262"
|
endingLineNumber = "315"
|
||||||
landmarkName = "moveDock(_:)"
|
landmarkName = "moveDock(_:)"
|
||||||
landmarkType = "9">
|
landmarkType = "9">
|
||||||
</BreakpointContent>
|
</BreakpointContent>
|
||||||
@@ -46,8 +46,8 @@
|
|||||||
filePath = "DockPhobia/DockPhobiaApp.swift"
|
filePath = "DockPhobia/DockPhobiaApp.swift"
|
||||||
startingColumnNumber = "9223372036854775807"
|
startingColumnNumber = "9223372036854775807"
|
||||||
endingColumnNumber = "9223372036854775807"
|
endingColumnNumber = "9223372036854775807"
|
||||||
startingLineNumber = "173"
|
startingLineNumber = "188"
|
||||||
endingLineNumber = "173"
|
endingLineNumber = "188"
|
||||||
landmarkName = "osascript(_:)"
|
landmarkName = "osascript(_:)"
|
||||||
landmarkType = "9">
|
landmarkType = "9">
|
||||||
</BreakpointContent>
|
</BreakpointContent>
|
||||||
@@ -62,8 +62,8 @@
|
|||||||
filePath = "DockPhobia/DockPhobiaApp.swift"
|
filePath = "DockPhobia/DockPhobiaApp.swift"
|
||||||
startingColumnNumber = "9223372036854775807"
|
startingColumnNumber = "9223372036854775807"
|
||||||
endingColumnNumber = "9223372036854775807"
|
endingColumnNumber = "9223372036854775807"
|
||||||
startingLineNumber = "252"
|
startingLineNumber = "297"
|
||||||
endingLineNumber = "252"
|
endingLineNumber = "297"
|
||||||
landmarkName = "getScreenSize()"
|
landmarkName = "getScreenSize()"
|
||||||
landmarkType = "9">
|
landmarkType = "9">
|
||||||
</BreakpointContent>
|
</BreakpointContent>
|
||||||
@@ -78,11 +78,91 @@
|
|||||||
filePath = "DockPhobia/DockPhobiaApp.swift"
|
filePath = "DockPhobia/DockPhobiaApp.swift"
|
||||||
startingColumnNumber = "9223372036854775807"
|
startingColumnNumber = "9223372036854775807"
|
||||||
endingColumnNumber = "9223372036854775807"
|
endingColumnNumber = "9223372036854775807"
|
||||||
startingLineNumber = "258"
|
startingLineNumber = "311"
|
||||||
endingLineNumber = "258"
|
endingLineNumber = "311"
|
||||||
landmarkName = "getScreenSize()"
|
landmarkName = "getScreenSize()"
|
||||||
landmarkType = "9">
|
landmarkType = "9">
|
||||||
</BreakpointContent>
|
</BreakpointContent>
|
||||||
</BreakpointProxy>
|
</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>
|
</Breakpoints>
|
||||||
</Bucket>
|
</Bucket>
|
||||||
|
|||||||
@@ -5,36 +5,12 @@
|
|||||||
// Created by neon443 on 13/03/2025.
|
// Created by neon443 on 13/03/2025.
|
||||||
//
|
//
|
||||||
|
|
||||||
import SwiftUI
|
//import SwiftUI
|
||||||
|
//
|
||||||
struct ContentView: View {
|
//struct ContentView: View {
|
||||||
@Binding var isTracking: Bool
|
//
|
||||||
@State var mouseloc = NSEvent.mouseLocation
|
//}
|
||||||
|
//
|
||||||
var body: some View {
|
//#Preview {
|
||||||
VStack {
|
// ContentView(isTracking: .constant(true))
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -82,25 +82,36 @@ struct DockPhobiaApp: App {
|
|||||||
.keyboardShortcut(",")
|
.keyboardShortcut(",")
|
||||||
Divider()
|
Divider()
|
||||||
Button("try shell") {
|
Button("try shell") {
|
||||||
print(shell("echo hello"))
|
print(shell("echo hello") as Any)
|
||||||
}
|
}
|
||||||
Divider()
|
Divider()
|
||||||
Button("Move Dock to Right") {
|
Button("Move Dock to Right") {
|
||||||
moveDock("right")
|
moveDock("right")
|
||||||
}
|
}
|
||||||
Divider()
|
|
||||||
Button("Move Dock to Left") {
|
Button("Move Dock to Left") {
|
||||||
moveDock("left")
|
moveDock("left")
|
||||||
}
|
}
|
||||||
Button("Move Dock to Bottom") {
|
Button("Move Dock to Bottom") {
|
||||||
moveDock("bottom")
|
moveDock("bottom")
|
||||||
}
|
}
|
||||||
|
Divider()
|
||||||
Button("Get Dock orientation") {
|
Button("Get Dock orientation") {
|
||||||
print(getDockSide())
|
print(getDockSide())
|
||||||
}
|
}
|
||||||
Button("Get Dock Height Percentage") {
|
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") {
|
Button("Quit") {
|
||||||
NSApplication.shared.terminate(nil)
|
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 process = Process()
|
||||||
let pipe = Pipe()
|
let pipe = Pipe()
|
||||||
let pipeError = Pipe()
|
let pipeError = Pipe()
|
||||||
@@ -136,7 +147,11 @@ func shell(_ command: String) -> (output: String?, error: String?) {
|
|||||||
data: dataError,
|
data: dataError,
|
||||||
encoding: .utf8
|
encoding: .utf8
|
||||||
)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
return (output: output, error: outputError)
|
|
||||||
|
if outputError != "" {
|
||||||
|
print(outputError as Any)
|
||||||
|
}
|
||||||
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func osascript(_ script: String) -> String? {
|
func osascript(_ script: String) -> String? {
|
||||||
@@ -177,23 +192,52 @@ func osascript(_ script: String) -> String? {
|
|||||||
|
|
||||||
func getDockSide() -> String {
|
func getDockSide() -> String {
|
||||||
let result = shell("defaults read com.apple.Dock orientation")
|
let result = shell("defaults read com.apple.Dock orientation")
|
||||||
print("dock is on the \(result.output ?? "idk")")
|
print("dock is on the \(result ?? "idk")")
|
||||||
return result.output ?? "unknown"
|
return result ?? "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
// global event tap
|
// global event tap
|
||||||
var eventTap: CFMachPort?
|
var eventTap: CFMachPort?
|
||||||
|
|
||||||
func getDockHeightPercentage() -> Double {
|
func getDockHeight() -> Double {
|
||||||
guard let screen = NSScreen.main else { return 0 }
|
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 visibleHeight = screen.visibleFrame.height
|
||||||
|
|
||||||
let dockHeight = fullHeight - visibleHeight
|
let perpendicularToDock: CGFloat
|
||||||
let percentage = (dockHeight / fullHeight) * 100
|
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() {
|
func startTrackingMouse() {
|
||||||
@@ -206,8 +250,9 @@ func startTrackingMouse() {
|
|||||||
options: CGEventTapOptions.defaultTap,
|
options: CGEventTapOptions.defaultTap,
|
||||||
eventsOfInterest: mask,
|
eventsOfInterest: mask,
|
||||||
callback: { (proxy, type, event, userInfo) -> Unmanaged<CGEvent>? in
|
callback: { (proxy, type, event, userInfo) -> Unmanaged<CGEvent>? in
|
||||||
let location = event.location
|
// let location = event.location
|
||||||
// print("mouse at \(location)")
|
// print("mouse at \(location)")
|
||||||
|
// print("mouse at \(event.location)")
|
||||||
//TODO: add Dock moving here
|
//TODO: add Dock moving here
|
||||||
return Unmanaged.passRetained(event)
|
return Unmanaged.passRetained(event)
|
||||||
},
|
},
|
||||||
@@ -243,7 +288,7 @@ func stopTrackingMouse() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getScreenSize() -> (x: Int, y: Int) {
|
func getScreenSize() -> (x: CGFloat, y: CGFloat) {
|
||||||
let script = """
|
let script = """
|
||||||
tell application "Finder"
|
tell application "Finder"
|
||||||
get bounds of window of desktop
|
get bounds of window of desktop
|
||||||
@@ -252,8 +297,16 @@ func getScreenSize() -> (x: Int, y: Int) {
|
|||||||
let result = osascript(script)?.dropFirst(6).split(separator: ", ")
|
let result = osascript(script)?.dropFirst(6).split(separator: ", ")
|
||||||
// removes the "0, 0, " and splits into an arr
|
// removes the "0, 0, " and splits into an arr
|
||||||
let resultTuple = (
|
let resultTuple = (
|
||||||
Int( result![0] )!,
|
CGFloat(
|
||||||
Int( result![1] )!
|
Int(
|
||||||
|
result![0]
|
||||||
|
)!
|
||||||
|
),
|
||||||
|
CGFloat(
|
||||||
|
Int(
|
||||||
|
result![1]
|
||||||
|
)!
|
||||||
|
)
|
||||||
)
|
)
|
||||||
return resultTuple
|
return resultTuple
|
||||||
}
|
}
|
||||||
@@ -271,6 +324,6 @@ func moveDock(_ to: String) {
|
|||||||
end tell
|
end tell
|
||||||
end tell
|
end tell
|
||||||
"""
|
"""
|
||||||
let result = osascript(script)
|
osascript(script)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user