To: vim-dev@vim.org Subject: Patch 6.1.382 (extra) Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.382 (extra) Problem: Win32 GUI: When using two monitors, the code that checks/fixes the window size and position (e.g. when a font changes) doesn't work properly. (George Reilly) Solution: Handle a double monitor situation. (Helmut Stiegler) Files: src/gui_w32.c *** ../vim61.381/src/gui_w32.c Sat Feb 22 14:09:00 2003 --- src/gui_w32.c Sun Mar 9 16:13:10 2003 *************** *** 271,276 **** --- 271,293 ---- # define ETO_IGNORELANGUAGE 0x1000 #endif + /* multi monitor support */ + typedef struct _MONITORINFOstruct + { + DWORD cbSize; + RECT rcMonitor; + RECT rcWork; + DWORD dwFlags; + } _MONITORINFO; + + typedef HANDLE _HMONITOR; + typedef _HMONITOR (WINAPI *TMonitorFromWindow)(HWND, DWORD); + typedef BOOL (WINAPI *TGetMonitorInfo)(_HMONITOR, _MONITORINFO *); + + static TMonitorFromWindow pMonitorFromWindow = NULL; + static TGetMonitorInfo pGetMonitorInfo = NULL; + static HANDLE user32_lib = NULL; + /* * Return TRUE when running under Windows NT 3.x or Win32s, both of which have * less fancy GUI APIs. *************** *** 944,949 **** --- 961,979 ---- /* get the OS version info */ os_version.dwOSVersionInfoSize = sizeof(os_version); GetVersionEx(&os_version); /* this call works on Win32s, Win95 and WinNT */ + + /* try and load the user32.dll library and get the entry points for + * multi-monitor-support. */ + if ((user32_lib = LoadLibrary("User32.dll")) != NULL) + { + pMonitorFromWindow = (TMonitorFromWindow)GetProcAddress(user32_lib, + "MonitorFromWindow"); + + /* there are ...A and ...W version of GetMonitorInfo - looking at + * winuser.h, they have exactly the same declaration. */ + pGetMonitorInfo = (TGetMonitorInfo)GetProcAddress(user32_lib, + "GetMonitorInfoA"); + } } /* *************** *** 1128,1133 **** --- 1158,1191 ---- return OK; } + /* + * Get the size of the screen, taking position on multiple monitors into + * account (if supported). + */ + static void + get_work_area(RECT *spi_rect) + { + _HMONITOR mon; + _MONITORINFO moninfo; + + /* use these functions only if available */ + if (pMonitorFromWindow != NULL && pGetMonitorInfo != NULL) + { + /* work out which monitor the window is on, and get *it's* work area */ + mon = pMonitorFromWindow(s_hwnd, 1 /*MONITOR_DEFAULTTOPRIMARY*/); + if (mon != NULL) + { + moninfo.cbSize = sizeof(_MONITORINFO); + if (pGetMonitorInfo(mon, &moninfo)) + { + *spi_rect = moninfo.rcWork; + return; + } + } + } + /* this is the old method... */ + SystemParametersInfo(SPI_GETWORKAREA, 0, spi_rect, 0); + } /* * Set the size of the window to the given width and height in pixels. *************** *** 1143,1149 **** /* try to keep window completely on screen */ /* get size of the screen work area (excludes taskbar, appbars) */ ! SystemParametersInfo(SPI_GETWORKAREA, 0, &workarea_rect, 0); /* get current posision of our window */ wndpl.length = sizeof(WINDOWPLACEMENT); --- 1201,1207 ---- /* try to keep window completely on screen */ /* get size of the screen work area (excludes taskbar, appbars) */ ! get_work_area(&workarea_rect); /* get current posision of our window */ wndpl.length = sizeof(WINDOWPLACEMENT); *************** *** 1184,1192 **** if (win_ypos < workarea_rect.top) win_ypos = workarea_rect.top; ! /* set window position */ ! SetWindowPos(s_hwnd, NULL, win_xpos, win_ypos, win_width, win_height, ! SWP_NOZORDER | SWP_NOACTIVATE); #ifdef FEAT_MENU /* Menu may wrap differently now */ --- 1242,1256 ---- if (win_ypos < workarea_rect.top) win_ypos = workarea_rect.top; ! wndpl.rcNormalPosition.left = win_xpos; ! wndpl.rcNormalPosition.right = win_xpos + win_width; ! wndpl.rcNormalPosition.top = win_ypos; ! wndpl.rcNormalPosition.bottom = win_ypos + win_height; ! ! /* set window position - we should use SetWindowPlacement rather than ! * SetWindowPos as the MSDN docs say the coord systems returned by ! * these two are not compatible. */ ! SetWindowPlacement(s_hwnd, &wndpl); #ifdef FEAT_MENU /* Menu may wrap differently now */ *** ../vim61.381/src/version.c Sun Mar 9 15:48:31 2003 --- src/version.c Sun Mar 9 16:17:15 2003 *************** *** 613,614 **** --- 613,616 ---- { /* Add new patch number below this line */ + /**/ + 382, /**/ -- hundred-and-one symptoms of being an internet addict: 2. You kiss your girlfriend's home page. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///