Skip to content

Commit 28ab4c1

Browse files
committed
Improved shell positioning, fixed a bug introduced in 265608b
1 parent 0135722 commit 28ab4c1

File tree

1 file changed

+27
-1
lines changed
  • durian-swt/src/main/java/com/diffplug/common/swt

1 file changed

+27
-1
lines changed

durian-swt/src/main/java/com/diffplug/common/swt/Shells.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,33 @@ private void setupShell(Shell shell) {
397397

398398
// constrain the position by the Display's bounds (getClientArea() takes the Start bar into account)
399399
Rectangle monitorBounds = SwtMisc.monitorFor(Corner.CENTER.getPosition(bounds)).orElse(SwtMisc.assertUI().getMonitors()[0]).getClientArea();
400-
bounds.intersect(monitorBounds);
400+
Rectangle inbounds = monitorBounds.intersection(bounds);
401+
if (!inbounds.equals(bounds)) {
402+
// push left if needed
403+
if (inbounds.x > bounds.x) {
404+
bounds.x = inbounds.x;
405+
}
406+
// push down if needed
407+
if (inbounds.y > bounds.y) {
408+
bounds.y = inbounds.y;
409+
}
410+
// push right, but not past the edge of the monitor (better to hang off to the right)
411+
int pushRight = bounds.x + bounds.width - (inbounds.x + inbounds.width);
412+
if (pushRight > 0) {
413+
bounds.x -= pushRight;
414+
if (bounds.x < monitorBounds.x) {
415+
bounds.x = monitorBounds.x;
416+
}
417+
}
418+
// push up, but not past the edge of the monitor (better to hang off to the bottom)
419+
int pushUp = bounds.y + bounds.height - (inbounds.y + inbounds.height);
420+
if (pushUp > 0) {
421+
bounds.y -= pushUp;
422+
if (bounds.y < monitorBounds.y) {
423+
bounds.y = monitorBounds.y;
424+
}
425+
}
426+
}
401427

402428
// set the location and open it up!
403429
shell.setBounds(bounds);

0 commit comments

Comments
 (0)