(svn r10281) [0.5] -Backport from trunk (r10186, r10229, r10251): 0.5
authorglx
Fri, 22 Jun 2007 20:20:36 +0000
branch0.5
changeset 5514 f122a67b50fb
parent 5513 0d3227e250eb
child 5515 09bd10f069da
(svn r10281) [0.5] -Backport from trunk (r10186, r10229, r10251):
- Fix: [Windows] Do not mess desktop when using ALT-TAB [FS#876] (r10251, r10186)
- Cleanup: removed duplicate include (r10229)
landscape.c
video/win32_v.c
--- a/landscape.c	Fri Jun 22 20:12:09 2007 +0000
+++ b/landscape.c	Fri Jun 22 20:20:36 2007 +0000
@@ -19,7 +19,6 @@
 #include "water_map.h"
 #include "tgp.h"
 #include "genworld.h"
-#include "heightmap.h"
 
 extern const TileTypeProcs
 	_tile_type_clear_procs,
--- a/video/win32_v.c	Fri Jun 22 20:12:09 2007 +0000
+++ b/video/win32_v.c	Fri Jun 22 20:20:36 2007 +0000
@@ -24,6 +24,7 @@
 	int height;
 	int width_org;
 	int height_org;
+	bool minimized;
 	bool fullscreen;
 	bool double_size;
 	bool has_focus;
@@ -209,6 +210,82 @@
 	}
 }
 
+static void MakeWindow(bool full_screen)
+{
+	_fullscreen = full_screen;
+
+	_wnd.double_size = _double_size && !full_screen;
+
+	// recreate window?
+	if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) {
+		DestroyWindow(_wnd.main_wnd);
+		_wnd.main_wnd = 0;
+	}
+
+	if (full_screen) {
+		DEVMODE settings;
+
+		memset(&settings, 0, sizeof(settings));
+		settings.dmSize = sizeof(settings);
+		settings.dmFields =
+			(_fullscreen_bpp != 0 ? DM_BITSPERPEL : 0) |
+			DM_PELSWIDTH |
+			DM_PELSHEIGHT |
+			(_display_hz != 0 ? DM_DISPLAYFREQUENCY : 0);
+		settings.dmBitsPerPel = _fullscreen_bpp;
+		settings.dmPelsWidth  = _wnd.width_org;
+		settings.dmPelsHeight = _wnd.height_org;
+		settings.dmDisplayFrequency = _display_hz;
+
+		if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
+			MakeWindow(false);
+			return;
+		}
+	} else if (_wnd.fullscreen) {
+		// restore display?
+		ChangeDisplaySettings(NULL, 0);
+	}
+
+	{
+		RECT r;
+		DWORD style, showstyle;
+		int x, y, w, h;
+
+		showstyle = SW_SHOWNORMAL;
+		_wnd.fullscreen = full_screen;
+		if (_wnd.fullscreen) {
+			style = WS_POPUP;
+			SetRect(&r, 0, 0, _wnd.width_org, _wnd.height_org);
+		} else {
+			style = WS_OVERLAPPEDWINDOW;
+			/* On window creation, check if we were in maximize mode before */
+			if (_window_maximize) showstyle = SW_SHOWMAXIMIZED;
+			SetRect(&r, 0, 0, _wnd.width, _wnd.height);
+		}
+
+		AdjustWindowRect(&r, style, FALSE);
+		w = r.right - r.left;
+		h = r.bottom - r.top;
+		x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
+		y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
+
+		if (_wnd.main_wnd) {
+			ShowWindow(_wnd.main_wnd, SW_SHOWNORMAL); // remove maximize-flag
+			SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
+		} else {
+			extern const char _openttd_revision[];
+			TCHAR Windowtitle[50];
+
+			_sntprintf(Windowtitle, sizeof(Windowtitle), _T("OpenTTD %s"), MB_TO_WIDE(_openttd_revision));
+
+			_wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0);
+			if (_wnd.main_wnd == NULL) error("CreateWindow failed");
+			ShowWindow(_wnd.main_wnd, showstyle);
+		}
+	}
+	GameSizeChanged(); // invalidate all windows, force redraw
+}
+
 static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
 	static uint32 keycode = 0;
@@ -435,7 +512,8 @@
 			break;
 
 		case WM_SIZE:
-			if (wParam != SIZE_MINIMIZED) {
+			_wnd.minimized = (wParam == SIZE_MINIMIZED);
+			if (!_wnd.minimized) {
 				/* Set maximized flag when we maximize (obviously), but also when we
 				 * switched to fullscreen from a maximized state */
 				_window_maximize = (wParam == SIZE_MAXIMIZED || (_window_maximize && _fullscreen));
@@ -534,7 +612,20 @@
 		}
 
 		case WM_ACTIVATEAPP:
-			_wnd.has_focus = (bool)wParam;
+			_wnd.has_focus = (wParam != 0);
+#if !defined(WINCE)
+			if (_wnd.fullscreen) {
+				if (_wnd.has_focus && _wnd.minimized) {
+					/* Restore the game window */
+					ShowWindow(hwnd, SW_RESTORE);
+					MakeWindow(true);
+				} else if (!_wnd.has_focus && !_wnd.minimized) {
+					/* Minimise the window and restore desktop */
+					ShowWindow(hwnd, SW_MINIMIZE);
+					ChangeDisplaySettings(NULL, 0);
+				}
+			}
+#endif
 			break;
 	}
 	return DefWindowProc(hwnd, msg, wParam, lParam);
@@ -564,82 +655,6 @@
 	}
 }
 
-static void MakeWindow(bool full_screen)
-{
-	_fullscreen = full_screen;
-
-	_wnd.double_size = _double_size && !full_screen;
-
-	// recreate window?
-	if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) {
-		DestroyWindow(_wnd.main_wnd);
-		_wnd.main_wnd = 0;
-	}
-
-	if (full_screen) {
-		DEVMODE settings;
-
-		memset(&settings, 0, sizeof(settings));
-		settings.dmSize = sizeof(settings);
-		settings.dmFields =
-			(_fullscreen_bpp != 0 ? DM_BITSPERPEL : 0) |
-			DM_PELSWIDTH |
-			DM_PELSHEIGHT |
-			(_display_hz != 0 ? DM_DISPLAYFREQUENCY : 0);
-		settings.dmBitsPerPel = _fullscreen_bpp;
-		settings.dmPelsWidth  = _wnd.width_org;
-		settings.dmPelsHeight = _wnd.height_org;
-		settings.dmDisplayFrequency = _display_hz;
-
-		if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
-			MakeWindow(false);
-			return;
-		}
-	} else if (_wnd.fullscreen) {
-		// restore display?
-		ChangeDisplaySettings(NULL, 0);
-	}
-
-	{
-		RECT r;
-		DWORD style, showstyle;
-		int x, y, w, h;
-
-		showstyle = SW_SHOWNORMAL;
-		_wnd.fullscreen = full_screen;
-		if (_wnd.fullscreen) {
-			style = WS_POPUP;
-			SetRect(&r, 0, 0, _wnd.width_org, _wnd.height_org);
-		} else {
-			style = WS_OVERLAPPEDWINDOW;
-			/* On window creation, check if we were in maximize mode before */
-			if (_window_maximize) showstyle = SW_SHOWMAXIMIZED;
-			SetRect(&r, 0, 0, _wnd.width, _wnd.height);
-		}
-
-		AdjustWindowRect(&r, style, FALSE);
-		w = r.right - r.left;
-		h = r.bottom - r.top;
-		x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
-		y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
-
-		if (_wnd.main_wnd) {
-			ShowWindow(_wnd.main_wnd, SW_SHOWNORMAL); // remove maximize-flag
-			SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
-		} else {
-			extern const char _openttd_revision[];
-			TCHAR Windowtitle[50];
-
-			_sntprintf(Windowtitle, sizeof(Windowtitle), _T("OpenTTD %s"), MB_TO_WIDE(_openttd_revision));
-
-			_wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0);
-			if (_wnd.main_wnd == NULL) error("CreateWindow failed");
-			ShowWindow(_wnd.main_wnd, showstyle);
-		}
-	}
-	GameSizeChanged(); // invalidate all windows, force redraw
-}
-
 static bool AllocateDibSection(int w, int h)
 {
 	BITMAPINFO *bi;