IMKCandidates // Simplify doSet().
This commit is contained in:
parent
cd20b97a7b
commit
2d44957e08
|
@ -163,40 +163,23 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func doSet(windowTopLeftPoint: NSPoint, bottomOutOfScreenAdjustmentHeight height: CGFloat) {
|
func doSet(windowTopLeftPoint: NSPoint, bottomOutOfScreenAdjustmentHeight heightDelta: CGFloat) {
|
||||||
var adjustedPoint = windowTopLeftPoint
|
var adjustedPoint = windowTopLeftPoint
|
||||||
var adjustedHeight = height
|
let windowSize = candidateFrame().size
|
||||||
|
var delta = heightDelta
|
||||||
var screenFrame = NSScreen.main?.visibleFrame ?? NSRect.seniorTheBeast
|
var screenFrame = NSScreen.main?.visibleFrame ?? NSRect.seniorTheBeast
|
||||||
for screen in NSScreen.screens {
|
for frame in NSScreen.screens.map(\.visibleFrame).filter({ !$0.contains(windowTopLeftPoint) }) {
|
||||||
let frame = screen.visibleFrame
|
|
||||||
if windowTopLeftPoint.x >= frame.minX, windowTopLeftPoint.x <= frame.maxX,
|
|
||||||
windowTopLeftPoint.y >= frame.minY, windowTopLeftPoint.y <= frame.maxY
|
|
||||||
{
|
|
||||||
screenFrame = frame
|
screenFrame = frame
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if delta > screenFrame.size.height / 2.0 { delta = 0.0 }
|
||||||
|
|
||||||
|
if adjustedPoint.y < screenFrame.minY + windowSize.height {
|
||||||
|
adjustedPoint.y = windowTopLeftPoint.y + windowSize.height + delta
|
||||||
}
|
}
|
||||||
|
adjustedPoint.y = min(adjustedPoint.y, screenFrame.maxY - 1.0)
|
||||||
if adjustedHeight > screenFrame.size.height / 2.0 { adjustedHeight = 0.0 }
|
adjustedPoint.x = min(max(adjustedPoint.x, screenFrame.minX), screenFrame.maxX - windowSize.width - 1.0)
|
||||||
|
|
||||||
let windowSize = candidateFrame().size
|
|
||||||
|
|
||||||
// bottom beneath the screen?
|
|
||||||
if adjustedPoint.y - windowSize.height < screenFrame.minY {
|
|
||||||
adjustedPoint.y = windowTopLeftPoint.y + adjustedHeight + windowSize.height
|
|
||||||
}
|
|
||||||
|
|
||||||
// top over the screen?
|
|
||||||
if adjustedPoint.y >= screenFrame.maxY { adjustedPoint.y = screenFrame.maxY - 1.0 }
|
|
||||||
|
|
||||||
// right
|
|
||||||
if adjustedPoint.x + windowSize.width >= screenFrame.maxX {
|
|
||||||
adjustedPoint.x = screenFrame.maxX - windowSize.width
|
|
||||||
}
|
|
||||||
|
|
||||||
// left
|
|
||||||
if adjustedPoint.x < screenFrame.minX { adjustedPoint.x = screenFrame.minX }
|
|
||||||
|
|
||||||
setCandidateFrameTopLeft(adjustedPoint)
|
setCandidateFrameTopLeft(adjustedPoint)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue