From a3edb9798cacf87dc89750a9554a6b37f8fe4c32 Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Sun, 20 Dec 2009 14:50:36 +0000 Subject: [PATCH] Added preliminary screensaver disable feature. Cleaned up Vista/Win7 DWM code a bit. Consolidated various win32 specific code into MSWstuff.cpp git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2370 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/Linux/pcsx2.cbp | 4 +- pcsx2/gui/AppConfig.cpp | 2 + pcsx2/gui/AppConfig.h | 1 + pcsx2/gui/AppInit.cpp | 7 +- pcsx2/gui/AppMain.cpp | 2 +- pcsx2/gui/ConsoleLogger.cpp | 33 +++------- pcsx2/gui/FrameForGS.cpp | 3 +- pcsx2/gui/MSWstuff.cpp | 62 +++++++++++++++++ pcsx2/gui/MSWstuff.h | 23 +++++++ pcsx2/gui/MainFrame.cpp | 9 +-- pcsx2/gui/MainFrame.h | 6 ++ pcsx2/gui/Panels/PluginSelectorPanel.cpp | 5 +- pcsx2/windows/DwmSetup.cpp | 77 +++++++++++++++------- pcsx2/windows/VCprojects/pcsx2_2008.vcproj | 8 +++ 14 files changed, 180 insertions(+), 62 deletions(-) create mode 100644 pcsx2/gui/MSWstuff.cpp create mode 100644 pcsx2/gui/MSWstuff.h diff --git a/pcsx2/Linux/pcsx2.cbp b/pcsx2/Linux/pcsx2.cbp index 3996d4d03d..6d11565a3c 100644 --- a/pcsx2/Linux/pcsx2.cbp +++ b/pcsx2/Linux/pcsx2.cbp @@ -361,7 +361,9 @@ - + + + diff --git a/pcsx2/gui/AppConfig.cpp b/pcsx2/gui/AppConfig.cpp index e36cb5c8fa..8992640087 100644 --- a/pcsx2/gui/AppConfig.cpp +++ b/pcsx2/gui/AppConfig.cpp @@ -548,6 +548,7 @@ AppConfig::GSWindowOptions::GSWindowOptions() DefaultToFullscreen = false; AlwaysHideMouse = false; DisableResizeBorders = false; + DisableScreenSaver = true; AspectRatio = AspectRatio_4_3; @@ -591,6 +592,7 @@ void AppConfig::GSWindowOptions::LoadSave( IniInterface& ini ) IniEntry( DefaultToFullscreen ); IniEntry( AlwaysHideMouse ); IniEntry( DisableResizeBorders ); + IniEntry( DisableScreenSaver ); IniEntry( WindowSize ); IniEntry( WindowPos ); diff --git a/pcsx2/gui/AppConfig.h b/pcsx2/gui/AppConfig.h index d8c69833a1..e5c01848a7 100644 --- a/pcsx2/gui/AppConfig.h +++ b/pcsx2/gui/AppConfig.h @@ -127,6 +127,7 @@ public: bool DefaultToFullscreen; bool AlwaysHideMouse; bool DisableResizeBorders; + bool DisableScreenSaver; AspectRatioType AspectRatio; diff --git a/pcsx2/gui/AppInit.cpp b/pcsx2/gui/AppInit.cpp index 5edb0bf61c..abf9949577 100644 --- a/pcsx2/gui/AppInit.cpp +++ b/pcsx2/gui/AppInit.cpp @@ -17,6 +17,8 @@ #include "IniInterface.h" #include "MainFrame.h" #include "ConsoleLogger.h" +#include "MSWstuff.h" + #include "DebugTools/Debug.h" #include "Dialogs/ModalPopups.h" @@ -347,8 +349,7 @@ bool Pcsx2App::OnInit() AppApplySettings(); #ifdef __WXMSW__ - extern void SetupDwmStuff(WXHWND hMainWindow); - SetupDwmStuff(m_MainFrame->GetHWND()); + pxDwm_Load(); #endif m_CoreAllocs = new SysCoreAllocations(); @@ -480,6 +481,8 @@ void Pcsx2App::CleanupMess() Console.Error( L"Runtime exception handled during CleanupMess:\n" ); Console.Indent().Error( ex.FormatDiagnosticMessage() ); } + + pxDwm_Unload(); // Notice: deleting the plugin manager (unloading plugins) here causes Lilypad to crash, // likely due to some pending message in the queue that references lilypad procs. diff --git a/pcsx2/gui/AppMain.cpp b/pcsx2/gui/AppMain.cpp index 0bf4756890..255e504520 100644 --- a/pcsx2/gui/AppMain.cpp +++ b/pcsx2/gui/AppMain.cpp @@ -27,7 +27,7 @@ #include "Utilities/HashMap.h" #ifdef __WXMSW__ -# include +# include // needed to implement the app! #endif IMPLEMENT_APP(Pcsx2App) diff --git a/pcsx2/gui/ConsoleLogger.cpp b/pcsx2/gui/ConsoleLogger.cpp index 8b181725c3..15383cb743 100644 --- a/pcsx2/gui/ConsoleLogger.cpp +++ b/pcsx2/gui/ConsoleLogger.cpp @@ -17,15 +17,13 @@ #include "App.h" #include "MainFrame.h" #include "ConsoleLogger.h" +#include "MSWstuff.h" + #include "Utilities/Console.h" #include "DebugTools/Debug.h" #include -#ifdef __WXMSW__ -# include // needed for OutputDebugString -#endif - BEGIN_DECLARE_EVENT_TYPES() DECLARE_EVENT_TYPE(wxEVT_LOG_Write, -1) DECLARE_EVENT_TYPE(wxEVT_LOG_Newline, -1) @@ -54,21 +52,7 @@ void pxLogConsole::DoLog( wxLogLevel level, const wxChar *szString, time_t t ) { wxString str; TimeStamp( &str ); - str += szString; - - #if defined(__WXMSW__) && !defined(__WXMICROWIN__) - // don't prepend debug/trace here: it goes to the - // debug window anyhow - str += wxT("\r\n"); - OutputDebugString(str); - #else - // send them to stderr - wxFprintf(stderr, wxT("[%s] %s\n"), - level == wxLOG_Trace ? wxT("Trace") - : wxT("Debug"), - str.c_str()); - fflush(stderr); - #endif + MSW_OutputDebugString( str + szString ); } break; @@ -87,15 +71,15 @@ void pxLogConsole::DoLog( wxLogLevel level, const wxChar *szString, time_t t ) // fallthrough! case wxLOG_Message: - Console.WriteLn( wxString(L"wx > ") + szString ); + Console.WriteLn( L"[wx] %s", szString ); break; case wxLOG_Error: - Console.Error( wxString(L"wx > ") + szString ); + Console.Error( L"[wx] %s", szString ); break; case wxLOG_Warning: - Console.Warning( wxString(L"wx > ") + szString ); + Console.Warning( L"[wx] %s", szString ); break; } } @@ -490,10 +474,9 @@ void ConsoleLogFrame::OnActivate( wxActivateEvent& evt ) // Special implementation to "connect" the console log window with the main frame // window. When one is clicked, the other is assured to be brought to the foreground // with it. (wxWidgets appears to have no equivalent to this) -#ifdef __WXMSW__ + if( MainEmuFrame* mainframe = GetMainFramePtr() ) - SetWindowPos( (HWND)mainframe->GetHWND(), (HWND)GetHWND(), 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE ); -#endif + MSW_SetWindowAfter( mainframe->GetHWND(), GetHWND() ); evt.Skip(); } diff --git a/pcsx2/gui/FrameForGS.cpp b/pcsx2/gui/FrameForGS.cpp index 679aaef28b..9296b0c00d 100644 --- a/pcsx2/gui/FrameForGS.cpp +++ b/pcsx2/gui/FrameForGS.cpp @@ -16,8 +16,9 @@ #include "PrecompiledHeader.h" #include "MainFrame.h" #include "GS.h" +#include "MSWstuff.h" -#include "wx/utils.h" +#include void GSPanel::InitDefaultAccelerators() diff --git a/pcsx2/gui/MSWstuff.cpp b/pcsx2/gui/MSWstuff.cpp new file mode 100644 index 0000000000..7ea33699c8 --- /dev/null +++ b/pcsx2/gui/MSWstuff.cpp @@ -0,0 +1,62 @@ +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2002-2009 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with PCSX2. + * If not, see . + */ + +#include "PrecompiledHeader.h" +#include "MainFrame.h" +#include "MSWstuff.h" + +#ifdef __WXMSW__ +# include // needed for OutputDebugString +#endif + +void MSW_SetWindowAfter( WXHWND hwnd, WXHWND hwndAfter ) +{ +#ifndef __WXMSW__ + SetWindowPos( (HWND)hwnd, (HWND)hwndAfter, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE ); +#endif +} + +// Writes text to the Visual Studio Output window (Microsoft Windows only). +// On all other platforms this pipes to StdErr instead. +void MSW_OutputDebugString( const wxString& text ) +{ +#if defined(__WXMSW__) && !defined(__WXMICROWIN__) + // don't prepend debug/trace here: it goes to the + // debug window anyhow + OutputDebugString( text + L"\r\n" ); +#else + // send them to stderr + wxFprintf(stderr, L"%s\n", text.c_str()); + fflush(stderr); +#endif +} + +#ifdef __WXMSW__ +WXLRESULT GSPanel::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) +{ + switch ( message ) + { + case SC_SCREENSAVE: + case SC_MONITORPOWER: + if( m_HasFocus && g_Conf->GSWindow.DisableScreenSaver) + { + DevCon.WriteLn("Omg Screensaver adverted!"); + return 0; + } + break; + } + return _parent::MSWWindowProc(message, wParam, lParam); +} +#endif diff --git a/pcsx2/gui/MSWstuff.h b/pcsx2/gui/MSWstuff.h new file mode 100644 index 0000000000..c0762016f1 --- /dev/null +++ b/pcsx2/gui/MSWstuff.h @@ -0,0 +1,23 @@ +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2002-2009 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with PCSX2. + * If not, see . + */ + +#pragma once + +extern void MSW_SetWindowAfter( WXWidget hwnd, WXWidget hwndAfter ); +extern void MSW_OutputDebugString( const wxString& text ); + +extern void pxDwm_Load(); +extern void pxDwm_Unload(); +extern void pxDwm_SetPresentParams( WXWidget wnd ); diff --git a/pcsx2/gui/MainFrame.cpp b/pcsx2/gui/MainFrame.cpp index 06d4caeed1..2e353b9c78 100644 --- a/pcsx2/gui/MainFrame.cpp +++ b/pcsx2/gui/MainFrame.cpp @@ -16,16 +16,13 @@ #include "PrecompiledHeader.h" #include "MainFrame.h" #include "ConsoleLogger.h" +#include "MSWstuff.h" #include "Dialogs/ModalPopups.h" #include "IsoDropTarget.h" #include -#ifdef __WXMSW__ -# include // needed for SetWindowPos (OnActivate) -#endif - #if _MSC_VER # include "svnrev.h" #endif @@ -458,10 +455,8 @@ void MainEmuFrame::OnActivate( wxActivateEvent& evt ) // Special implementation to "connect" the console log window with the main frame // window. When one is clicked, the other is assured to be brought to the foreground // with it. (wxWidgets appears to have no equivalent to this) -#ifdef __WXMSW__ if( ConsoleLogFrame* logframe = wxGetApp().GetProgramLog() ) - SetWindowPos( (HWND)logframe->GetHWND(), (HWND)GetHWND(), 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE ); -#endif + MSW_SetWindowAfter( logframe->GetHWND(), GetHWND() ); evt.Skip(); } diff --git a/pcsx2/gui/MainFrame.h b/pcsx2/gui/MainFrame.h index 40d18d5812..6e6a95e72c 100644 --- a/pcsx2/gui/MainFrame.h +++ b/pcsx2/gui/MainFrame.h @@ -26,6 +26,8 @@ // -------------------------------------------------------------------------------------- class GSPanel : public wxWindow { + typedef wxWindow _parent; + protected: AcceleratorDictionary m_Accels; EventListenerBinding m_Listener_SettingsApplied; @@ -43,6 +45,10 @@ public: protected: static void __evt_fastcall OnSettingsApplied( void* obj, int& evt ); +#ifdef __WXMSW__ + virtual WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam); +#endif + void InitDefaultAccelerators(); void OnCloseWindow( wxCloseEvent& evt ); diff --git a/pcsx2/gui/Panels/PluginSelectorPanel.cpp b/pcsx2/gui/Panels/PluginSelectorPanel.cpp index 7bad970c07..3532a2f2c0 100644 --- a/pcsx2/gui/Panels/PluginSelectorPanel.cpp +++ b/pcsx2/gui/Panels/PluginSelectorPanel.cpp @@ -242,9 +242,12 @@ void __evt_fastcall Panels::PluginSelectorPanel::OnCorePluginStatusChanged( void const PluginInfo* pi = tbl_PluginInfo; do { wxComboBox& box( panel.m_ComponentBoxes->Get(pi->id) ); + int sel = box.GetSelection(); + if( sel == wxNOT_FOUND ) continue; + panel.m_ComponentBoxes->GetConfigButton(pi->id).Enable( (panel.m_FileList==NULL || panel.m_FileList->Count() == 0) ? false : - g_Conf->FullpathMatchTest( pi->id,(*panel.m_FileList)[((int)box.GetClientData(box.GetSelection()))] ) + g_Conf->FullpathMatchTest( pi->id,(*panel.m_FileList)[((int)box.GetClientData(sel))] ) ); } while( ++pi, pi->shortname != NULL ); diff --git a/pcsx2/windows/DwmSetup.cpp b/pcsx2/windows/DwmSetup.cpp index 1d34b2811e..bea07a1791 100644 --- a/pcsx2/windows/DwmSetup.cpp +++ b/pcsx2/windows/DwmSetup.cpp @@ -1,15 +1,28 @@ + #include "PrecompiledHeader.h" -#include #include "Utilities/Console.h" +#include "MSWstuff.h" + +#include +#include + +#include + +typedef HRESULT WINAPI Fntype_DwmEnableMMCSS(DWORD enable); +typedef HRESULT WINAPI Fntype_DwmSetPresentParameters( HWND hwnd, DWM_PRESENT_PARAMETERS *pPresentParams ); + +static wxDynamicLibrary lib_dwmapi; // This could potentially reduce lag while running in Aero, // by telling the DWM the application requires // multimedia-class scheduling for smooth display. -void SetupDwmStuff(WXHWND hMainWindow) +void pxDwm_Load() { - HRESULT (WINAPI * pDwmEnableMMCSS)(DWORD); + wxDoNotLogInThisScope please; - OSVERSIONINFOEX info = {0}; + // Version test is not needed since we're using LoadLibrary. --air + + /*OSVERSIONINFOEX info = {0}; info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); info.dwMajorVersion = 6; @@ -22,27 +35,43 @@ void SetupDwmStuff(WXHWND hMainWindow) //info if(VerifyVersionInfo(&info, VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR, - mask)) + mask))*/ + + lib_dwmapi.Load( L"dwmapi.dll" ); + if( !lib_dwmapi.IsLoaded() ) return; + + if( Fntype_DwmEnableMMCSS* pDwmEnableMMCSS = (Fntype_DwmEnableMMCSS*)lib_dwmapi.GetSymbol(L"DwmEnableMMCSS") ) { - HMODULE hDwmapi = LoadLibrary(wxT("dwmapi.dll")); - if(hDwmapi) - { - pDwmEnableMMCSS = (HRESULT (WINAPI *)(DWORD))GetProcAddress(hDwmapi,"DwmEnableMMCSS"); - if(pDwmEnableMMCSS) - { - if(FAILED(pDwmEnableMMCSS(TRUE))) - { - Console.WriteLn("Warning: DwmEnableMMCSS returned a failure code (not an error)."); - } - else - { - Console.WriteLn("DwmEnableMMCSS successful."); - } - } + Console.WriteLn( "[Dwm] Desktop Window Manager detected." ); - //DwmSetDxFrameDuration(hMainWindow,1); - - FreeLibrary(hDwmapi); - } + if(FAILED(pDwmEnableMMCSS(TRUE))) + Console.WriteLn("[Dwm] DwmEnableMMCSS returned a failure code."); } +} + +// wnd - this parameter should be the GS display panel or the top level frame that holds it (not +// sure if it's supposed to be the actual gsPanel or the top level window/frame that the +// panel belongs to) +// +void pxDwm_SetPresentParams( WXWidget wnd ) +{ + if( !lib_dwmapi.IsLoaded() ) return; + Fntype_DwmSetPresentParameters* pDwmSetPresentParameters = (Fntype_DwmSetPresentParameters*)lib_dwmapi.GetSymbol(L"DwmSetPresentParameters"); + + if( pDwmSetPresentParameters == NULL ) return; + + DWM_PRESENT_PARAMETERS params; + + params.cbSize = sizeof(DWM_PRESENT_PARAMETERS); + params.fQueue = FALSE; + + if(FAILED(pDwmSetPresentParameters( (HWND)wnd, ¶ms ))) + Console.WriteLn("[Dwm] DwmSetPresentParameters returned a failure code."); + + //DwmSetDxFrameDuration(hMainWindow,1); +} + +void pxDwm_Unload() +{ + lib_dwmapi.Unload(); } \ No newline at end of file diff --git a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj index fe14ce1499..75a6010e92 100644 --- a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj +++ b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj @@ -1880,6 +1880,10 @@ RelativePath="..\..\gui\MessageBoxes.cpp" > + + @@ -1951,6 +1955,10 @@ RelativePath="..\..\gui\Dialogs\ModalPopups.h" > + +