[ttssh2-commit] [10719] DPI調整がうまく行われない場合があったので修正

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2023年 5月 26日 (金) 21:59:12 JST


Revision: 10719
          https://osdn.net/projects/ttssh2/scm/svn/commits/10719
Author:   zmatsuo
Date:     2023-05-26 21:59:11 +0900 (Fri, 26 May 2023)
Log Message:
-----------
DPI調整がうまく行われない場合があったので修正

- 「ドラッグ中にウインドウの内容を表示する」がoff時
  - ドラッグ中に枠線だけを表示する状態
- DPIが異なるモニタをまたいでウィンドウを移動,リサイズしたとき
  - 修正前は移動すると端末のサイズ(縦横の文字数)が変化していた
  - リサイズ時、DPI変化+移動と区別できないため移動と同等の動作とした
- DPI変更時にOSが提案するウィンドウ位置に移動するように修正
  - なるべくOSが提案するウィンドウ位置に移動
  - マウスポインタの位置は参考にしないようにした

MFT: r10691, r10716
ticket 47978

Revision Links:
--------------
    https://osdn.net/projects/ttssh2/scm/svn/commits/10691
    https://osdn.net/projects/ttssh2/scm/svn/commits/10716

Modified Paths:
--------------
    branches/4-stable/doc/en/html/about/history.html
    branches/4-stable/doc/ja/html/about/history.html
    branches/4-stable/teraterm/common/compat_win.cpp
    branches/4-stable/teraterm/common/compat_win.h
    branches/4-stable/teraterm/teraterm/vtwin.cpp
    branches/4-stable/teraterm/teraterm/vtwin.h

-------------- next part --------------
Modified: branches/4-stable/doc/en/html/about/history.html
===================================================================
--- branches/4-stable/doc/en/html/about/history.html	2023-05-24 15:49:26 UTC (rev 10718)
+++ branches/4-stable/doc/en/html/about/history.html	2023-05-26 12:59:11 UTC (rev 10719)
@@ -71,7 +71,8 @@
       <!--li>Kermit \x82Ńt\x83@\x83C\x83\x8B\x82\xF0\x8E\xF3\x90M\x82ł\xAB\x82Ȃ\xA2\x82\xB1\x82Ƃ\xAA\x82\xA0\x82\xE9\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B</li-->
       <!--li>Kermit \x82̑\x97\x90M\x83p\x83P\x83b\x83g\x82̃T\x83C\x83Y\x82𒲐\xAE\x82\xB5\x82\xBD\x81B</li-->
       <li>Fixed current font name was empty in ChooseFont dialog when changing dialog fonts.</li>
-      <li>Fixed the area selected with the mouse does not disappear when the text is erased with the erase escape sequences.
+      <li>Fixed the area selected with the mouse does not disappear when the text is erased with the erase escape sequences.</li>
+      <li>Fixed DPI adjustment does not work correctly when VT Window is moved to different DPI monitor.</li>
     </ul>
   </li>
 

Modified: branches/4-stable/doc/ja/html/about/history.html
===================================================================
--- branches/4-stable/doc/ja/html/about/history.html	2023-05-24 15:49:26 UTC (rev 10718)
+++ branches/4-stable/doc/ja/html/about/history.html	2023-05-26 12:59:11 UTC (rev 10719)
@@ -72,6 +72,7 @@
       <li>Kermit \x82̑\x97\x90M\x83p\x83P\x83b\x83g\x82̃T\x83C\x83Y\x82𒲐\xAE\x82\xB5\x82\xBD\x81B</li>
       <li>\x83_\x83C\x83A\x83\x8D\x83O\x83t\x83H\x83\x93\x83g\x95ύX\x8E\x9E\x81A\x83t\x83H\x83\x93\x83g\x91I\x91\xF0\x83_\x83C\x83A\x83\x8D\x83O\x82Ɍ\xBB\x8D݂̃t\x83H\x83\x93\x83g\x96\xBC\x82\xAA\x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ȃ\xA2\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD</li>
       <li>\x8F\xC1\x8B\x8E\x83V\x81[\x83P\x83\x93\x83X\x82ŕ\xB6\x8E\x9A\x82\xAA\x8F\xC1\x82\xB3\x82ꂽ\x82Ƃ\xAB\x81A\x83}\x83E\x83X\x82őI\x91\xF0\x82\xB5\x82\xBD\x97̈悪\x8F\xC1\x82\xA6\x82Ȃ\xA2\x82悤\x82ɏC\x90\xB3\x82\xB5\x82\xBD</li>
+      <li>VT \x83E\x83B\x83\x93\x83h\x83E\x82\xAA\x88قȂ郂\x83j\x83^\x82\xF0\x82܂\xBD\x82\xAE\x8E\x9E\x81ADPI\x92\xB2\x90\xAE\x82\xAA\x82\xA4\x82܂\xAD\x8Ds\x82\xED\x82\xEA\x82Ȃ\xA2\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD</li>
     </ul>
   </li>
 

Modified: branches/4-stable/teraterm/common/compat_win.cpp
===================================================================
--- branches/4-stable/teraterm/common/compat_win.cpp	2023-05-24 15:49:26 UTC (rev 10718)
+++ branches/4-stable/teraterm/common/compat_win.cpp	2023-05-26 12:59:11 UTC (rev 10719)
@@ -48,6 +48,7 @@
 HMONITOR (WINAPI *pMonitorFromRect)(LPCRECT lprc, DWORD dwFlags);
 BOOL (WINAPI *pAdjustWindowRectEx)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle);
 BOOL (WINAPI *pAdjustWindowRectExForDpi)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi);
+int (WINAPI *pGetSystemMetricsForDpi)(int nIndex, UINT dpi);
 
 // dwmapi.dll
 HRESULT (WINAPI *pDwmSetWindowAttribute)(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute);
@@ -61,6 +62,7 @@
 	{ "AdjustWindowRectEx", (void **)&pAdjustWindowRectEx },
 	{ "AdjustWindowRectExForDpi", (void **)&pAdjustWindowRectExForDpi },
 	{ "EnumDisplayMonitors", (void **)&pEnumDisplayMonitors },
+	{ "GetSystemMetricsForDpi", (void **)&pGetSystemMetricsForDpi },
 	{},
 };
 

Modified: branches/4-stable/teraterm/common/compat_win.h
===================================================================
--- branches/4-stable/teraterm/common/compat_win.h	2023-05-24 15:49:26 UTC (rev 10718)
+++ branches/4-stable/teraterm/common/compat_win.h	2023-05-26 12:59:11 UTC (rev 10719)
@@ -101,6 +101,9 @@
 #define pRemoveFontResourceEx	pRemoveFontResourceExA
 #endif // !UNICODE
 
+// user32
+extern int (WINAPI *pGetSystemMetricsForDpi)(int  nIndex, UINT dpi);
+
 // dwmapi.dll
 extern HRESULT (WINAPI *pDwmSetWindowAttribute)(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute);
 

Modified: branches/4-stable/teraterm/teraterm/vtwin.cpp
===================================================================
--- branches/4-stable/teraterm/teraterm/vtwin.cpp	2023-05-24 15:49:26 UTC (rev 10718)
+++ branches/4-stable/teraterm/teraterm/vtwin.cpp	2023-05-26 12:59:11 UTC (rev 10719)
@@ -145,6 +145,7 @@
 #define WM_IME_COMPOSITION              0x010F
 #endif
 
+static UINT monitor_DPI;			// \x83E\x83B\x83\x93\x83h\x83E\x82\xAA\x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82\xCCDPI
 static BOOL SendScpDoing;
 static TCHAR **DropListsSendScp;
 static int DropListCountSendScp;
@@ -670,7 +671,7 @@
 	FirstPaint = TRUE;
 	ScrollLock = FALSE;  // \x8F\x89\x8A\xFA\x92l\x82͖\xB3\x8C\xF8 (2006.11.14 yutaka)
 	Alpha = 255;
-	IgnoreSizeMessage = FALSE;
+	monitor_DPI = 0;
 
 	/* Initialize scroll buffer */
 	InitBuffer();
@@ -2540,6 +2541,12 @@
 void CVTWindow::OnMove(int x, int y)
 {
 	DispSetWinPos();
+
+	if (monitor_DPI == 0) {
+		// \x83E\x83B\x83\x93\x83h\x83E\x82\xAA\x8F\x89\x82߂ĕ\\x8E\xA6\x82\xB3\x82ꂽ
+		//	\x83\x82\x83j\x83^\x82\xCCDPI\x82\xF0\x95ۑ\xB6\x82\xB5\x82Ă\xA8\x82\xAD
+		monitor_DPI = GetMonitorDpiFromWindow(m_hWnd);
+	}
 }
 
 // \x83}\x83E\x83X\x83z\x83C\x81[\x83\x8B\x82̉\xF1\x93]
@@ -2723,7 +2730,19 @@
 
 void CVTWindow::OnSize(WPARAM nType, int cx, int cy)
 {
-	if (IgnoreSizeMessage) {
+	if (GetMonitorDpiFromWindow(m_hWnd) != monitor_DPI) {
+		// DPI\x82̈قȂ\xE9\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82\xF0\x82܂\xBD\x82\xAE\x82\xC6 WM_DPICHANGE \x82\xAA\x94\xAD\x90\xB6\x82\xB7\x82\xE9
+		//
+		// \x81u\x83h\x83\x89\x83b\x83O\x92\x86\x82ɃE\x83B\x83\x93\x83h\x83E\x82̓\xE0\x97e\x82\xF0\x95\\x8E\xA6\x82\xB7\x82\xE9=OFF\x81v\x90ݒ莞
+		// \x83}\x83E\x83X\x82̃{\x83^\x83\x93\x82𗣂\xB5\x82\xBD\x82Ƃ\xAB\x82ɁA\x8E\x9F\x82\xCC2\x8E\xED\x97ނ̔\xAD\x90\xB6\x83p\x83^\x81[\x83\x93\x82\xAA\x82\xA0\x82\xE9
+		// 1. \x83E\x83B\x83\x93\x83h\x83E\x82\xAA\x88ړ\xAE\x82\xB5\x82\xBD\x82Ƃ\xAB
+		//    WM_MOVE, WM_SIZE, WM_DPICHANGED \x82̏\x87\x82Ń\x81\x83b\x83Z\x81[\x83W\x82\xAA\x94\xAD\x90\xB6\x82\xB7\x82\xE9
+		// 2. \x83E\x83B\x83\x93\x83h\x83E\x82\xAA\x83\x8A\x83T\x83C\x83Y\x82\xB5\x82\xBD\x82Ƃ\xAB
+		//    (WM_MOVE,)WM_SIZE, WM_DPICHANGED \x82̏\x87\x82Ń\x81\x83b\x83Z\x81[\x83W\x82\xAA\x94\xAD\x90\xB6\x82\xB7\x82\xE9
+		//
+		// \x83\x81\x83b\x83Z\x81[\x83W\x82\xA9\x82\xE7\x82́A\x83Z\x83\x8B\x90\x94\x82\xA9\x83t\x83H\x83\x93\x83g\x83T\x83C\x83Y\x82\xA9\x81A
+		// \x82ǂ\xBF\x82\xE7\x82\xF0\x95ύX\x82\xB7\x82ׂ\xAB\x82\xA9\x94\xBB\x92f\x82ł\xAB\x82Ȃ\xA2
+		// \x82\xB1\x82\xB1\x82ł\xCD 1 \x82\xAA\x91Ó\x96\x82ƂȂ\xE9\x82悤\x8E\xC0\x91\x95\x82\xB5\x82\xBD
 		return;
 	}
 	RECT R;
@@ -6358,27 +6377,18 @@
 	FreeTTDLG();
 }
 
-LRESULT CVTWindow::OnDpiChanged(WPARAM wp, LPARAM)
+LRESULT CVTWindow::OnDpiChanged(WPARAM wp, LPARAM lp)
 {
 	const UINT NewDPI = LOWORD(wp);
-	// \x8C\xBB\x8D݂̃E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y
-	RECT CurrentWindowRect;
-	::GetWindowRect(m_hWnd, &CurrentWindowRect);
-	const int CurrentWindowWidth = CurrentWindowRect.right - CurrentWindowRect.left;
-	const int CurrentWindowHeight = CurrentWindowRect.bottom - CurrentWindowRect.top;
+	const RECT SuggestedWindowRect = *(RECT *)lp;
+	const int SuggestedWindowWidth = SuggestedWindowRect.right - SuggestedWindowRect.left;
+	const int SuggestedWindowHeight = SuggestedWindowRect.bottom - SuggestedWindowRect.top;
 
-	// \x83|\x83C\x83\x93\x83^\x82̈ʒu
-	POINT MouseCursorScreen;
-	GetCursorPos(&MouseCursorScreen);
-	POINT MouseCursorInWindow = MouseCursorScreen;
-	MouseCursorInWindow.x -= CurrentWindowRect.left;
-	MouseCursorInWindow.y -= CurrentWindowRect.top;
-
 	// \x90V\x82\xB5\x82\xA2DPI\x82ɍ\x87\x82킹\x82ăt\x83H\x83\x93\x83g\x82𐶐\xAC\x81A
 	// \x83N\x83\x89\x83C\x83A\x83\x93\x83g\x97̈\xE6\x82̃T\x83C\x83Y\x82\xF0\x8C\x88\x92肷\x82\xE9
 	ChangeFont();
-	ScreenWidth = WinWidth*FontWidth;
-	ScreenHeight = WinHeight*FontHeight;
+	ScreenWidth = WinWidth * FontWidth;
+	ScreenHeight = WinHeight * FontHeight;
 	//AdjustScrollBar();
 
 	// \x83X\x83N\x83\x8A\x81[\x83\x93\x83T\x83C\x83Y(=Client Area\x82̃T\x83C\x83Y)\x82\xA9\x82\xE7\x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82\xF0\x8EZ\x8Fo
@@ -6385,9 +6395,23 @@
 	int NewWindowWidth;
 	int NewWindowHeight;
 	if (pAdjustWindowRectExForDpi != NULL || pAdjustWindowRectEx != NULL) {
-		const LONG_PTR Style = ::GetWindowLongPtr(m_hWnd, GWL_STYLE);
-		const LONG_PTR ExStyle = ::GetWindowLongPtr(m_hWnd, GWL_EXSTYLE);
+		const DWORD Style = (DWORD)::GetWindowLongPtr(m_hWnd, GWL_STYLE);
+		const DWORD ExStyle = (DWORD)::GetWindowLongPtr(m_hWnd, GWL_EXSTYLE);
 		const BOOL bMenu = (ts.PopupMenu != 0) ? FALSE : TRUE;
+		if (pGetSystemMetricsForDpi != NULL) {
+			// \x83X\x83N\x83\x8D\x81[\x83\x8B\x83o\x81[\x82\xAA\x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x8Fꍇ\x82́A
+			// \x83X\x83N\x83\x8A\x81[\x83\x93\x83T\x83C\x83Y(\x83N\x83\x89\x83C\x83A\x83\x93\x83g\x83G\x83\x8A\x83A\x82̃T\x83C\x83Y)\x82ɒlj\xC1\x82\xB7\x82\xE9
+			int min_pos;
+			int max_pos;
+			GetScrollRange(m_hWnd, SB_VERT, &min_pos, &max_pos);
+			if (min_pos != max_pos) {
+				ScreenWidth += pGetSystemMetricsForDpi(SM_CXVSCROLL, NewDPI);
+			}
+			GetScrollRange(m_hWnd, SB_HORZ, &min_pos, &max_pos);
+			if (min_pos != max_pos) {
+				ScreenHeight += pGetSystemMetricsForDpi(SM_CXHSCROLL, NewDPI);
+			}
+		}
 		RECT Rect = {0, 0, ScreenWidth, ScreenHeight};
 		if (pAdjustWindowRectExForDpi != NULL) {
 			// Windows 10, version 1607+
@@ -6415,47 +6439,35 @@
 	}
 
 	// \x90V\x82\xB5\x82\xA2\x83E\x83B\x83\x93\x83h\x83E\x97̈\xE6\x8C\xF3\x95\xE2
-	RECT NewWindowRect[5];
+	RECT NewWindowRect[4];
 
-	// \x83^\x83C\x83g\x83\x8B\x83o\x81[\x8F\xE3\x82̃|\x83C\x83\x93\x83^\x88ʒu\x82\xAA\x82Ȃ\xE9\x82ׂ\xAD\x82\xB8\x82\xEA\x82Ȃ\xA2\x90V\x82\xB5\x82\xA2\x88ʒu
-	int t1 = (int)MouseCursorInWindow.y * (int)NewWindowHeight / (int)CurrentWindowHeight;
-	NewWindowRect[0].top =
-		CurrentWindowRect.top -
-		(t1 - (int)MouseCursorInWindow.y);
-	t1 = (int)MouseCursorInWindow.x * (int)NewWindowWidth / (int)CurrentWindowWidth;
-	NewWindowRect[0].left =
-		CurrentWindowRect.left -
-		(t1 - (int)MouseCursorInWindow.x);
-	NewWindowRect[0].bottom = NewWindowRect[0].top + NewWindowHeight;
-	NewWindowRect[0].right = NewWindowRect[0].left + NewWindowWidth;
+	// \x90\x84\x8F\xA7\x97̈\xE6\x82ɉE\x8F\xE3\x8A\xF1\x82\xB9
+	NewWindowRect[0].top = SuggestedWindowRect.top;
+	NewWindowRect[0].bottom = SuggestedWindowRect.top + NewWindowHeight;
+	NewWindowRect[0].left = SuggestedWindowRect.right - NewWindowWidth;
+	NewWindowRect[0].right = SuggestedWindowRect.right;
 
-	// \x8C\xBB\x8D݈ʒu\x82\xA9\x82\xE7\x8F\xE3\x89E\x8A\xF1\x82\xB9
-	NewWindowRect[1].top = CurrentWindowRect.top;
-	NewWindowRect[1].bottom = CurrentWindowRect.top + NewWindowHeight;
-	NewWindowRect[1].left = CurrentWindowRect.right - NewWindowWidth;
-	NewWindowRect[1].right = CurrentWindowRect.right;
+	// \x90\x84\x8F\xA7\x97̈\xE6\x82ɍ\xB6\x8F\xE3\x8A\xF1\x82\xB9
+	NewWindowRect[1].top = SuggestedWindowRect.top;
+	NewWindowRect[1].bottom = SuggestedWindowRect.top + NewWindowHeight;
+	NewWindowRect[1].left = SuggestedWindowRect.left;
+	NewWindowRect[1].right = SuggestedWindowRect.left + NewWindowWidth;
 
-	// \x8C\xBB\x8D݈ʒu\x82\xA9\x82\xE7\x8F㍶\x8A\xF1\x82\xB9
-	NewWindowRect[2].top = CurrentWindowRect.top;
-	NewWindowRect[2].bottom = CurrentWindowRect.top + NewWindowHeight;
-	NewWindowRect[2].left = CurrentWindowRect.left;
-	NewWindowRect[2].right = CurrentWindowRect.left + NewWindowWidth;
+	// \x90\x84\x8F\xA7\x88ʒu\x82ɉE\x89\xBA\x8A\xF1\x82\xB9
+	NewWindowRect[2].top = SuggestedWindowRect.bottom - NewWindowHeight;
+	NewWindowRect[2].bottom = SuggestedWindowRect.top;
+	NewWindowRect[2].left = SuggestedWindowRect.right - NewWindowWidth;
+	NewWindowRect[2].right = SuggestedWindowRect.right;
 
-	// \x8C\xBB\x8D݈ʒu\x82\xA9\x82牺\x89E\x8A\xF1\x82\xB9
-	NewWindowRect[3].top = CurrentWindowRect.bottom - NewWindowHeight;
-	NewWindowRect[3].bottom = CurrentWindowRect.top;
-	NewWindowRect[3].left = CurrentWindowRect.right - NewWindowWidth;
-	NewWindowRect[3].right = CurrentWindowRect.right;
+	// \x90\x84\x8F\xA7\x88ʒu\x82ɍ\xB6\x89\xBA\x8A\xF1\x82\xB9
+	NewWindowRect[3].top = SuggestedWindowRect.bottom - NewWindowHeight;
+	NewWindowRect[3].bottom = SuggestedWindowRect.top;
+	NewWindowRect[3].left = SuggestedWindowRect.left;
+	NewWindowRect[3].right = SuggestedWindowRect.left + NewWindowWidth;
 
-	// \x8C\xBB\x8D݈ʒu\x82\xA9\x82牺\x8D\xB6\x8A\xF1\x82\xB9
-	NewWindowRect[4].top = CurrentWindowRect.bottom - NewWindowHeight;
-	NewWindowRect[4].bottom = CurrentWindowRect.top;
-	NewWindowRect[4].left = CurrentWindowRect.left;
-	NewWindowRect[4].right = CurrentWindowRect.left + NewWindowWidth;
-
 	// \x8Am\x94F
 	const RECT *NewRect = &NewWindowRect[0];
-	for (size_t i=0; i < _countof(NewWindowRect); i++) {
+	for (size_t i = 0; i < _countof(NewWindowRect); i++) {
 		const RECT *r = &NewWindowRect[i];
 		HMONITOR hMonitor = pMonitorFromRect(r, MONITOR_DEFAULTTONULL);
 		UINT dpiX;
@@ -6467,12 +6479,11 @@
 		}
 	}
 
-	IgnoreSizeMessage = TRUE;
 	::SetWindowPos(m_hWnd, NULL,
 				   NewRect->left, NewRect->top,
 				   NewWindowWidth, NewWindowHeight,
 				   SWP_NOZORDER);
-	IgnoreSizeMessage = FALSE;
+	monitor_DPI = NewDPI;
 
 	ChangeCaret();
 

Modified: branches/4-stable/teraterm/teraterm/vtwin.h
===================================================================
--- branches/4-stable/teraterm/teraterm/vtwin.h	2023-05-24 15:49:26 UTC (rev 10718)
+++ branches/4-stable/teraterm/teraterm/vtwin.h	2023-05-26 12:59:11 UTC (rev 10719)
@@ -61,9 +61,6 @@
   BYTE Alpha;
   void SetWindowAlpha(BYTE alpha);
 
-  // DPI
-  BOOL IgnoreSizeMessage;
-
   // TipWin
   CTipWin* TipWin;
 


ttssh2-commit メーリングリストの案内
Back to archive index