After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 762629 - GDK W32: Wrong MINMAXINFO calculation
GDK W32: Wrong MINMAXINFO calculation
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Backend: Win32
unspecified
Other All
: Normal normal
: ---
Assigned To: gtk-win32 maintainers
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2016-02-24 17:26 UTC by LRN
Modified: 2016-02-26 08:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GDK W32: Fix the filling of MINMAXINFO (2.20 KB, patch)
2016-02-24 17:27 UTC, LRN
none Details | Review
GDK W32: Fix the filling of MINMAXINFO (3.21 KB, patch)
2016-02-24 21:02 UTC, LRN
committed Details | Review

Description LRN 2016-02-24 17:26:59 UTC
This was discovered while fixing bug 761629.
Comment 1 LRN 2016-02-24 17:27:11 UTC
Created attachment 322261 [details] [review]
GDK W32: Fix the filling of MINMAXINFO

1) MSDN says that the primary display should be used to calculate
   maximized window size, while we were using the display that
   is "closest" to the window
2) MSDN says that max tracking size is a system property, we
   should just call GetSystemMetrics() and use that.
Comment 2 Ignacio Casal Quinteiro (nacho) 2016-02-24 17:29:41 UTC
Review of attachment 322261 [details] [review]:

Looks good to me.
Comment 3 LRN 2016-02-24 21:02:26 UTC
Created attachment 322283 [details] [review]
GDK W32: Fix the filling of MINMAXINFO

v2:
* Finally sorted it out. The source of the problem was the fact
  that we used work area of the nearest display as-is, whereas
  W32 expected it the minmax info to be set in terms of the
  primary display.
Comment 4 Fan, Chun-wei 2016-02-25 00:58:53 UTC
Review of attachment 322283 [details] [review]:

Hi LRN,

I think the code looks good to me.  We could however use GetMonitorInfo() instead of GetMonitorInfoA(), which will select the appropriate function (GetMonitorInfoA() or GetMonitorInfoW()) at compile time depending on whether UNICODE is defined during the build though (unsure about it on MinGW, which I presume you are using some variant of it, let me know)
Comment 5 LRN 2016-02-25 01:15:47 UTC
(In reply to Fan, Chun-wei from comment #4)
> We could however use GetMonitorInfo()
> instead of GetMonitorInfoA(), which will select the appropriate function
> (GetMonitorInfoA() or GetMonitorInfoW()) at compile time depending on
> whether UNICODE is defined during the build though

I absolutely hate this Unicode/ANSI switch that MS uses. All modern applications must use UTF-8 and (when necessary) UTF-16. ANSI function can be used when no string data is involved (such as GetMonitorInfo() - MONITORINFO structure doesn't have strings, only MONITORINFOEX does). TCHAR, UNICODE and FunctionNameWithoutAOrWSuffix() are absolutely unacceptable, IMO.

> (unsure about it on
> MinGW, which I presume you are using some variant of it, let me know)

MinGW-w64 has:
  typedef struct tagMONITORINFO {
    DWORD cbSize;
    RECT rcMonitor;
    RECT rcWork;
    DWORD dwFlags;
  } MONITORINFO,*LPMONITORINFO;

#define GetMonitorInfo __MINGW_NAME_AW(GetMonitorInfo)

  WINUSERAPI WINBOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor,LPMONITORINFO lpmi);
  WINUSERAPI WINBOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor,LPMONITORINFO lpmi);

so while using GetMonitorInfo() would /technically/ work, i would rather explicitly call GetMonitorInfoA() or GetMonitorInfoW().

If MS PSDK has MONITORINFOA and MONITORINFOW, then i would see why this code could be problematic for you. If that is the case, i would suggest switching to explicit GetMonitorInfoExW() and MONITORINFOEXW.
Comment 6 LRN 2016-02-25 18:40:24 UTC
Okay, that was a bit misinformed. There's no GetMonitorInfoEx[A|W]() function. GetMonitorInfoA() and GetMonitorInfoW() simply accept a pointer to MONITORINFOEXA or MONITORINFOEXW, with cbSize set appropriately. That explains why there's no MONITORINFO[A|W] where GetMonitorInfo[A|W]() does exist.
Comment 7 Fan, Chun-wei 2016-02-26 02:39:27 UTC
Hi LRN,
(In reply to LRN from comment #5)
> I absolutely hate this Unicode/ANSI switch that MS uses. All modern
> applications must use UTF-8 and (when necessary) UTF-16. ANSI function can
> be used when no string data is involved (such as GetMonitorInfo() -
> MONITORINFO structure doesn't have strings, only MONITORINFOEX does). TCHAR,
> UNICODE and FunctionNameWithoutAOrWSuffix() are absolutely unacceptable, IMO.

I agree with you on this, totally... I think this has to blame on the backward compatibility of Windows.

As mentioned, though, in the previous comment, I think the patch looks good.

The reason I talked about simply using GetMonitorInfo() is because we don't involve ourselves with strings here (i.e., only MONITORINFO, as you mentioned in the other bug that led to this sub-bug-report), so it's safe for our case here, whether or not we use [/DUNICODE|-DUNICODE].  The [/DUNICODE|-DUNICODE] issue though, would be more like a universal compile-time cflag (i.e. the one we would set in the project file settings or in AMCFLAGS (if I got that name right) in configure.ac).  There is no MONITORINFOA nor MONITORINFOW in the Windows SDK.  As no device name is involved there in our case, so we don't need to use the additional space involved with MONITORINFOEXW.

MS is deprecating the ANSI variants of the Windows APIs though, so that's why I am bringing it up here, but as you mentioned, we could still use A variant to be safer still, and switch to the W variant later to make sure things are clear and ok when we do the transition.  Warning C4133 in Visual Studio would be our friend to find the char<->wchar_t issues when using the Windows APIs when we switch form the ANSI versions to the wide versions, but obviously that would be an issue for another series of bug reports for the transitions...

Thanks though, with blessings, and cheers!
Comment 8 LRN 2016-02-26 08:06:43 UTC
Attachment 322283 [details] pushed as c61764b - GDK W32: Fix the filling of MINMAXINFO