File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
durian-swt/src/main/java/com/diffplug/common/swt Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -397,7 +397,33 @@ private void setupShell(Shell shell) {
397
397
398
398
// constrain the position by the Display's bounds (getClientArea() takes the Start bar into account)
399
399
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
+ }
401
427
402
428
// set the location and open it up!
403
429
shell .setBounds (bounds );
You can’t perform that action at this time.
0 commit comments