diff --git a/kernel/trunk/gui/window.inc b/kernel/trunk/gui/window.inc
index a512fbdf9..87482cadf 100644
--- a/kernel/trunk/gui/window.inc
+++ b/kernel/trunk/gui/window.inc
@@ -653,11 +653,14 @@ align 4
         test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED
         jnz     .fix_maximized
 
+; box.width and box.height are a pixel less than the size: the window must
+; end on the last column and row of the screen, not a pixel past them
         mov     eax, [edi + WDATA.box.left]
         add     eax, [edi + WDATA.box.width]
         mov     ebx, [_display.width]
+        dec     ebx
         cmp     eax, ebx
-        jl      .fix_vertical
+        jle     .fix_vertical
         mov     eax, [edi + WDATA.box.width]
         sub     eax, ebx
         jl      @f
@@ -673,8 +676,9 @@ align 4
         mov     eax, [edi + WDATA.box.top]
         add     eax, [edi + WDATA.box.height]
         mov     ebx, [_display.height]
+        dec     ebx
         cmp     eax, ebx
-        jl      .fix_client_box
+        jle     .fix_client_box
         mov     eax, [edi + WDATA.box.height]
         sub     eax, ebx
         jl      @f
