mirror of
https://github.com/neon443/DockPhobia.git
synced 2026-03-11 06:49:12 +00:00
now programmatically can adapt to different screen sizes!!
next: multiple monitors
This commit is contained in:
@@ -73,6 +73,8 @@ class MouseTracker {
|
|||||||
|
|
||||||
var currentDockSide: DockSide
|
var currentDockSide: DockSide
|
||||||
|
|
||||||
|
var dockHeight: CGFloat = 0
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
print(DockSide())
|
print(DockSide())
|
||||||
if let screen = NSScreen.main {
|
if let screen = NSScreen.main {
|
||||||
@@ -87,7 +89,7 @@ class MouseTracker {
|
|||||||
}
|
}
|
||||||
self.currentDockSide = .left
|
self.currentDockSide = .left
|
||||||
moveDock(.bottom)
|
moveDock(.bottom)
|
||||||
currentDockSide = .bottom
|
getDockSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkMouse(_ event: NSEvent) {
|
func checkMouse(_ event: NSEvent) {
|
||||||
@@ -96,10 +98,9 @@ class MouseTracker {
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
print(location)
|
print(location)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch currentDockSide {
|
switch currentDockSide {
|
||||||
case .left:
|
case .left:
|
||||||
guard location.x < 100 else { return }
|
guard location.x < dockHeight else { return }
|
||||||
if location.y < screen.height/2 {
|
if location.y < screen.height/2 {
|
||||||
moveDock(.bottom)
|
moveDock(.bottom)
|
||||||
return
|
return
|
||||||
@@ -108,7 +109,7 @@ class MouseTracker {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
case .bottom:
|
case .bottom:
|
||||||
guard location.y > 1000 else { return }
|
guard location.y > screen.height - dockHeight else { return }
|
||||||
if location.x < screen.width/2 {
|
if location.x < screen.width/2 {
|
||||||
moveDock(.right)
|
moveDock(.right)
|
||||||
return
|
return
|
||||||
@@ -117,7 +118,7 @@ class MouseTracker {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
case .right:
|
case .right:
|
||||||
guard location.x > 1600 else { return }
|
guard location.x > screen.width - dockHeight else { return }
|
||||||
if location.y < screen.height/2 {
|
if location.y < screen.height/2 {
|
||||||
moveDock(.bottom)
|
moveDock(.bottom)
|
||||||
return
|
return
|
||||||
@@ -168,6 +169,12 @@ class MouseTracker {
|
|||||||
currentDockSide = toSide
|
currentDockSide = toSide
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getDockSize() {
|
||||||
|
guard let screen = NSScreen.main?.frame else { fatalError() }
|
||||||
|
guard let screenVisible = NSScreen.main?.visibleFrame else { fatalError() }
|
||||||
|
self.dockHeight = screen.height - screenVisible.height
|
||||||
|
}
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
func applescript(_ script: String) -> String? {
|
func applescript(_ script: String) -> String? {
|
||||||
var error: NSDictionary?
|
var error: NSDictionary?
|
||||||
@@ -180,19 +187,3 @@ class MouseTracker {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*- (void) startEventTap {
|
|
||||||
//eventTap is an ivar on this class of type CFMachPortRef
|
|
||||||
eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionListenOnly, kCGEventMaskForAllEvents, myCGEventCallback, NULL);
|
|
||||||
CGEventTapEnable(eventTap, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {
|
|
||||||
if (type == kCGEventMouseMoved) {
|
|
||||||
NSLog(@"%@", NSStringFromPoint([NSEvent mouseLocation]));
|
|
||||||
}
|
|
||||||
|
|
||||||
return event;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|||||||
Reference in New Issue
Block a user