From 0d426e3972731684fd194354fd8a41aef18d8363 Mon Sep 17 00:00:00 2001
From: Glenn Rice <glennricster@gmail.com>
Date: Tue, 1 Feb 2011 04:35:25 +0000
Subject: [PATCH] Fix the auto window resize option to take into account if the
 log/console window is open.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7031 8ced0084-cf51-0410-be5f-012b33b47a6e
---
 Source/Core/DolphinWX/Src/Frame.cpp           | 36 +++++++++++++++----
 Source/Core/DolphinWX/Src/Globals.h           |  1 +
 Source/Core/DolphinWX/Src/Main.cpp            |  4 ++-
 .../Plugin_VideoSoftware/Src/GLUtil.cpp       |  6 ++--
 4 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/Source/Core/DolphinWX/Src/Frame.cpp b/Source/Core/DolphinWX/Src/Frame.cpp
index cdb5d8cc4e..2127027657 100644
--- a/Source/Core/DolphinWX/Src/Frame.cpp
+++ b/Source/Core/DolphinWX/Src/Frame.cpp
@@ -656,6 +656,14 @@ void CFrame::OnHostMessage(wxCommandEvent& event)
 			m_RenderParent->SetCursor(wxCURSOR_BLANK);
 		break;
 
+	case IDM_WINDOWSIZEREQUEST:
+		{
+			std::pair<int, int> *win_size = (std::pair<int, int> *)(event.GetClientData());
+			OnRenderWindowSizeRequest(win_size->first, win_size->second);
+			delete win_size;
+		}
+		break;
+
 #ifdef __WXGTK__
 	case IDM_PANIC:
 		bPanicResult = (wxYES == wxMessageBox(event.GetString(), 
@@ -684,18 +692,34 @@ void CFrame::GetRenderWindowSize(int& x, int& y, int& width, int& height)
 
 void CFrame::OnRenderWindowSizeRequest(int width, int height)
 {
-	if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderWindowAutoSize || 
+	if (Core::GetState() == Core::CORE_UNINITIALIZED ||
+			!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain ||
+			!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderWindowAutoSize || 
 			RendererIsFullscreen() || m_RenderFrame->IsMaximized())
 		return;
 
-	int old_width, old_height;
+	int old_width, old_height, log_width = 0, log_height = 0;
 	m_RenderFrame->GetClientSize(&old_width, &old_height);
-	if (old_width != width || old_height != height)
+
+	// Add space for the log/console/debugger window
+	if ((SConfig::GetInstance().m_InterfaceLogWindow || SConfig::GetInstance().m_InterfaceConsole) &&
+			!m_Mgr->GetPane(wxT("Pane 1")).IsFloating())
 	{
-		wxMutexGuiEnter();
-		m_RenderFrame->SetClientSize(width, height);
-		wxMutexGuiLeave();
+		switch (m_Mgr->GetPane(wxT("Pane 1")).dock_direction)
+		{
+			case wxAUI_DOCK_LEFT:
+			case wxAUI_DOCK_RIGHT:
+				log_width = m_Mgr->GetPane(wxT("Pane 1")).rect.GetWidth();
+				break;
+			case wxAUI_DOCK_TOP:
+			case wxAUI_DOCK_BOTTOM:
+				log_height = m_Mgr->GetPane(wxT("Pane 1")).rect.GetHeight();
+				break;
+		}
 	}
+
+	if (old_width != width + log_width || old_height != height + log_height)
+		m_RenderFrame->SetClientSize(width + log_width, height + log_height);
 }
 
 bool CFrame::RendererHasFocus()
diff --git a/Source/Core/DolphinWX/Src/Globals.h b/Source/Core/DolphinWX/Src/Globals.h
index 79e723acc2..b2da9eff88 100644
--- a/Source/Core/DolphinWX/Src/Globals.h
+++ b/Source/Core/DolphinWX/Src/Globals.h
@@ -239,6 +239,7 @@ enum
 	IDM_UPDATEBREAKPOINTS,
 	IDM_PANIC,
 	IDM_KEYSTATE,
+	IDM_WINDOWSIZEREQUEST,
 	IDM_HOST_MESSAGE,
 
 	IDM_MPANEL, ID_STATUSBAR,
diff --git a/Source/Core/DolphinWX/Src/Main.cpp b/Source/Core/DolphinWX/Src/Main.cpp
index 193c51729d..b0211226bb 100644
--- a/Source/Core/DolphinWX/Src/Main.cpp
+++ b/Source/Core/DolphinWX/Src/Main.cpp
@@ -587,7 +587,9 @@ void Host_GetRenderWindowSize(int& x, int& y, int& width, int& height)
 
 void Host_RequestRenderWindowSize(int width, int height)
 {
-	main_frame->OnRenderWindowSizeRequest(width, height);
+	wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_WINDOWSIZEREQUEST);
+	event.SetClientData(new std::pair<int, int>(width, height));
+	main_frame->GetEventHandler()->AddPendingEvent(event);
 }
 
 void Host_SetWaitCursor(bool enable)
diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/GLUtil.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/GLUtil.cpp
index ad25418d3d..c308dca87a 100644
--- a/Source/Plugins/Plugin_VideoSoftware/Src/GLUtil.cpp
+++ b/Source/Plugins/Plugin_VideoSoftware/Src/GLUtil.cpp
@@ -238,7 +238,7 @@ bool OpenGL_Create(int _twidth, int _theight)
 		None };
 
 	GLWin.dpy = XOpenDisplay(0);
-	GLWin.parent = (Window)g_VideoInitialize.pWindowHandle;
+	GLWin.parent = (Window)VideoWindowHandle();
 	GLWin.screen = DefaultScreen(GLWin.dpy);
 
 	// Get an appropriate visual
@@ -294,7 +294,7 @@ bool OpenGL_Create(int _twidth, int _theight)
 			"GPU", None, NULL, 0, NULL);
 	XMapRaised(GLWin.dpy, GLWin.win);
 
-	g_VideoInitialize.pWindowHandle = (void *)GLWin.win;
+	VideoWindowHandle() = (void *)GLWin.win;
 #endif
 	return true;
 }
@@ -370,7 +370,7 @@ void OpenGL_Update()
 				break;
 			case ClientMessage:
 				if ((unsigned long) event.xclient.data.l[0] == XInternAtom(GLWin.dpy, "WM_DELETE_WINDOW", False))
-					g_VideoInitialize.pCoreMessage(WM_USER_STOP);
+					Core::Callback_CoreMessage(WM_USER_STOP);
 				if ((unsigned long) event.xclient.data.l[0] == XInternAtom(GLWin.dpy, "RESIZE", False))
 					XMoveResizeWindow(GLWin.dpy, GLWin.win, event.xclient.data.l[1],
 							event.xclient.data.l[2], event.xclient.data.l[3], event.xclient.data.l[4]);