Skip to content

Commit

Permalink
win32: Support snapping on the edges of the screen
Browse files Browse the repository at this point in the history
Starting from Windows 7, MS-Windows supports Aero Snap (and it is now
called just Snap). It can snap windows on the edges of the screen.

If a gVim window is snapped, and then the window size is changed by a
command like `:vsp` or `:tabe`, snapping will be cancelled. This might
be annoying for some people.
Actually this can be avoided by setting `:set go+=k`, but this also
changes the behavior when the window is not snapped.

This patch detects if the gVim window is snapped, and acts like if the
window is maximized. So, if the window is snapped, and even if a command
like `:vsp` is executed, snapping will be kept. But if the window size
is explicitly specified (e.g. `:set lines=30`), the size will be changed.

Related: vim#123, vim#703, vim#2180
  • Loading branch information
k-takata committed Jul 17, 2020
1 parent 98af99f commit 1dd4da2
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/gui_w32.c
Original file line number Diff line number Diff line change
Expand Up @@ -3320,19 +3320,33 @@ gui_mch_init_font(char_u *font_name, int fontset UNUSED)

/*
* Return TRUE if the GUI window is maximized, filling the whole screen.
* Also return TRUE if the window is snapped.
*/
int
gui_mch_maximized(void)
{
WINDOWPLACEMENT wp;
RECT rc;

wp.length = sizeof(WINDOWPLACEMENT);
if (GetWindowPlacement(s_hwnd, &wp))
return wp.showCmd == SW_SHOWMAXIMIZED
{
if (wp.showCmd == SW_SHOWMAXIMIZED
|| (wp.showCmd == SW_SHOWMINIMIZED
&& wp.flags == WPF_RESTORETOMAXIMIZED);

return 0;
&& wp.flags == WPF_RESTORETOMAXIMIZED))
return TRUE;
if (wp.showCmd == SW_SHOWMINIMIZED)
return FALSE;

// Assume the window is snapped when the sizes from two APIs differ.
GetWindowRect(s_hwnd, &rc);
if ((rc.right - rc.left !=
wp.rcNormalPosition.right - wp.rcNormalPosition.left)
|| (rc.bottom - rc.top !=
wp.rcNormalPosition.bottom - wp.rcNormalPosition.top))
return TRUE;
}
return FALSE;
}

/*
Expand Down

0 comments on commit 1dd4da2

Please sign in to comment.