@@ -795,33 +795,48 @@ export class CodeWindow extends Disposable implements ICodeWindow {
795795 }
796796
797797 // Single Monitor: be strict about x/y positioning
798+ // macOS & Linux: these OS seem to be pretty good in ensuring that a window is never outside of it's bounds.
799+ // Windows: it is possible to have a window with a size that makes it fall out of the window. our strategy
800+ // is to try as much as possible to keep the window in the monitor bounds. we are not as strict as
801+ // macOS and Linux and allow the window to exceed the monitor bounds as long as the window is still
802+ // some pixels (128) visible on the screen for the user to drag it back.
798803 if ( displays . length === 1 ) {
799804 const displayWorkingArea = this . getWorkingArea ( displays [ 0 ] ) ;
800805 if ( displayWorkingArea ) {
801806 this . logService . trace ( 'window#validateWindowState: 1 monitor working area' , displayWorkingArea ) ;
802807
803808 if ( state . x < displayWorkingArea . x ) {
804- state . x = displayWorkingArea . x ; // prevent window from falling out of the screen to the left
809+ // prevent window from falling out of the screen to the left
810+ state . x = displayWorkingArea . x ;
805811 }
806812
807813 if ( state . y < displayWorkingArea . y ) {
808- state . y = displayWorkingArea . y ; // prevent window from falling out of the screen to the top
814+ // prevent window from falling out of the screen to the top
815+ state . y = displayWorkingArea . y ;
809816 }
810817
811- if ( state . x > ( displayWorkingArea . x + displayWorkingArea . width ) ) {
812- state . x = displayWorkingArea . x ; // prevent window from falling out of the screen to the right
818+ if ( state . width > displayWorkingArea . width ) {
819+ // prevent window from exceeding display bounds width
820+ state . width = displayWorkingArea . width ;
813821 }
814822
815- if ( state . y > ( displayWorkingArea . y + displayWorkingArea . height ) ) {
816- state . y = displayWorkingArea . y ; // prevent window from falling out of the screen to the bottom
823+ if ( state . height > displayWorkingArea . height ) {
824+ // prevent window from exceeding display bounds height
825+ state . height = displayWorkingArea . height ;
817826 }
818827
819- if ( state . width > displayWorkingArea . width ) {
820- state . width = displayWorkingArea . width ; // prevent window from exceeding display bounds width
828+ if ( state . x > ( displayWorkingArea . x + displayWorkingArea . width - 128 ) ) {
829+ // prevent window from falling out of the screen to the right with
830+ // 128px margin by positioning the window to the far right edge of
831+ // the screen
832+ state . x = displayWorkingArea . x + displayWorkingArea . width - state . width ;
821833 }
822834
823- if ( state . height > displayWorkingArea . height ) {
824- state . height = displayWorkingArea . height ; // prevent window from exceeding display bounds height
835+ if ( state . y > ( displayWorkingArea . y + displayWorkingArea . height - 128 ) ) {
836+ // prevent window from falling out of the screen to the bottom with
837+ // 128px margin by positioning the window to the far bottom edge of
838+ // the screen
839+ state . y = displayWorkingArea . y + displayWorkingArea . height - state . height ;
825840 }
826841 }
827842
0 commit comments