From 5be6e9783d2ff1668e9ddb28bb386d5e55873ee1 Mon Sep 17 00:00:00 2001 From: jsmorley Date: Sat, 10 Jul 2010 12:56:37 +0000 Subject: [PATCH] Adding code to improve DesktopWorkArea with mulitple monitors. This is code from user Jott, with some minor tweaks by spx Adds DesktopWorkArea(x) where "x" is the desired monitor. DesktopWorkArea without a number is the primary monitor. --- Application/Application.rc | 8 +-- Library/Rainmeter.cpp | 128 +++++++++++++++++++++++++++++++++---- Library/Rainmeter.h | 4 +- revision-number.h | 2 +- 4 files changed, 122 insertions(+), 20 deletions(-) diff --git a/Application/Application.rc b/Application/Application.rc index 306e0f1d..6986928c 100644 --- a/Application/Application.rc +++ b/Application/Application.rc @@ -28,8 +28,8 @@ LANGUAGE LANG_FINNISH, SUBLANG_DEFAULT // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,3,0,455 - PRODUCTVERSION 1,3,0,455 + FILEVERSION 1,3,0,461 + PRODUCTVERSION 1,3,0,461 FILEFLAGSMASK 0x17L #ifdef _DEBUG FILEFLAGS 0x1L @@ -45,12 +45,12 @@ BEGIN BLOCK "040b04b0" BEGIN VALUE "FileDescription", "Rainmeter - A Customizable Resource Meter" - VALUE "FileVersion", "1, 3, 0, 455" + VALUE "FileVersion", "1, 3, 0, 461" VALUE "InternalName", "Rainmeter" VALUE "LegalCopyright", "Copyright (C) 2010 - Rainy" VALUE "OriginalFilename", "Rainmeter.exe" VALUE "ProductName", "Rainmeter" - VALUE "ProductVersion", "1, 3, 0, 455" + VALUE "ProductVersion", "1, 3, 0, 461" END END BLOCK "VarFileInfo" diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 3556055f..d7317d3b 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -747,7 +747,6 @@ CRainmeter::CRainmeter() m_Logging = false; m_DesktopWorkAreaChanged = false; - m_DesktopWorkArea.left = m_DesktopWorkArea.top = m_DesktopWorkArea.right = m_DesktopWorkArea.bottom = 0; m_DisableVersionCheck = FALSE; m_NewVersion = FALSE; @@ -775,12 +774,6 @@ CRainmeter::CRainmeter() */ CRainmeter::~CRainmeter() { - // Change the work area back - if (m_DesktopWorkAreaChanged) - { - SystemParametersInfo(SPI_SETWORKAREA, 0, &m_DesktopWorkArea, 0); - } - while (m_Meters.size() > 0) { DeleteMeterWindow((*m_Meters.begin()).second, false); // This removes the window from the vector @@ -798,6 +791,12 @@ CRainmeter::~CRainmeter() CMeterString::FreeFontCache(); + // Change the work area back + if (m_DesktopWorkAreaChanged) + { + UpdateDesktopWorkArea(true); + } + GdiplusShutdown(m_GDIplusToken); } @@ -1051,10 +1050,7 @@ int CRainmeter::Initialize(HWND Parent, HINSTANCE Instance, LPCSTR szPath) // Change the work area if necessary if (m_DesktopWorkAreaChanged) { - RECT rc; - rc = m_DesktopWorkArea; - SystemParametersInfo(SPI_GETWORKAREA, 0, &m_DesktopWorkArea, 0); // Store the old value - SystemParametersInfo(SPI_SETWORKAREA, 0, &rc, 0); + UpdateDesktopWorkArea(false); } // If we're running as Litestep's plugin, register the !bangs @@ -2084,6 +2080,9 @@ void CRainmeter::ExecuteCommand(const WCHAR* command, CMeterWindow* meterWindow) */ void CRainmeter::ReadGeneralSettings(std::wstring& iniFile) { + // Clear old settings + m_DesktopWorkAreas.clear(); + CConfigParser parser; parser.Initialize(iniFile.c_str(), this); @@ -2164,15 +2163,30 @@ void CRainmeter::ReadGeneralSettings(std::wstring& iniFile) m_TrayExecuteDM = parser.ReadString(L"Rainmeter", L"TrayExecuteDM", L"", false); m_DisableVersionCheck = parser.ReadInt(L"Rainmeter", L"DisableVersionCheck", 0); - + std::wstring area = parser.ReadString(L"Rainmeter", L"DesktopWorkArea", L""); if (!area.empty()) { - swscanf(area.c_str(), L"%i,%i,%i,%i", &m_DesktopWorkArea.left, &m_DesktopWorkArea.top, - &m_DesktopWorkArea.right, &m_DesktopWorkArea.bottom); + RECT r; + swscanf(area.c_str(), L"%i,%i,%i,%i", &r.left, &r.top, &r.right, &r.bottom); + m_DesktopWorkAreas[0] = r; m_DesktopWorkAreaChanged = true; } + for (UINT i = 1; i <= CSystem::GetMonitorCount(); ++i) + { + WCHAR buffer[256]; + wsprintf(buffer, L"DesktopWorkArea@%i", i); + area = parser.ReadString(L"Rainmeter", buffer, L""); + if (!area.empty()) + { + RECT r; + swscanf(area.c_str(), L"%i,%i,%i,%i", &r.left, &r.top, &r.right, &r.bottom); + m_DesktopWorkAreas[i] = r; + m_DesktopWorkAreaChanged = true; + } + } + // Check which configs are active if (!c_DummyLitestep) { @@ -2288,10 +2302,96 @@ void CRainmeter::RefreshAll() } } + if (m_DesktopWorkAreaChanged) + { + UpdateDesktopWorkArea(false); + } + // Clear order m_ConfigOrders.clear(); } +/* +** UpdateDesktopWorkArea +** +** Applies given DesktopWorkArea and DesktopWorkArea@n. +** +*/ +void CRainmeter::UpdateDesktopWorkArea(bool reset) +{ + bool changed = false; + + if (reset) + { + if (!m_OldDesktopWorkAreas.empty()) + { + for (size_t i = 0; i < m_OldDesktopWorkAreas.size(); ++i) + { + SystemParametersInfo(SPI_SETWORKAREA, 0, &m_OldDesktopWorkAreas[i], 0); + } + changed = true; + } + } + else + { + if (m_OldDesktopWorkAreas.empty()) + { + // Store old work areas for changing them back + for (UINT i = 0; i < CSystem::GetMonitorCount(); ++i) + { + m_OldDesktopWorkAreas.push_back(CSystem::GetMultiMonitorInfo().monitors[i].work); + } + } + + for (UINT i = 0; i <= CSystem::GetMonitorCount(); ++i) + { + std::map::const_iterator it = m_DesktopWorkAreas.find(i); + if (it != m_DesktopWorkAreas.end()) + { + RECT r = it->second; + if (i != 0) + { + // Move rect to correct offset + const RECT screenRect = CSystem::GetMultiMonitorInfo().monitors[i - 1].screen; + r.top += screenRect.top; + r.left += screenRect.left; + r.bottom += screenRect.top; + r.right += screenRect.left; + } + + BOOL result = SystemParametersInfo(SPI_SETWORKAREA, 0, &r, 0); + if (result) + { + changed = true; + } + + if (c_Debug) + { + std::wstring format = L"Applying DesktopWorkArea"; + if (i != 0) + { + WCHAR buffer[256]; + wsprintf(buffer, L"@%i", i); + format += buffer; + } + format += L": L=%i, T=%i, R=%i, B=%i"; + if (!result) + { + format += L" => FAIL."; + } + DebugLog(format.c_str(), r.left, r.top, r.right, r.bottom); + } + } + } + } + + if (changed) + { + // Broadcast all changes + SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETWORKAREA, 0, SMTO_ABORTIFHUNG, 1000, NULL); + } +} + /* ** ReadStats ** diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index c5b434cf..36c04a7e 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -201,6 +201,7 @@ private: void SetConfigOrder(const std::wstring& config, int index, int active); int GetLoadOrder(const std::wstring& config); bool SetActiveConfig(std::wstring& skinName, std::wstring& skinIni); + void UpdateDesktopWorkArea(bool reset); HMENU CreateSkinMenu(CMeterWindow* meterWindow, int index); void ChangeSkinIndex(HMENU subMenu, int index); int ScanForConfigsRecursive(std::wstring& path, std::wstring base, int index, std::vector& menu, bool DontRecurse); @@ -240,7 +241,8 @@ private: BOOL m_NewVersion; BOOL m_DesktopWorkAreaChanged; - RECT m_DesktopWorkArea; + std::map m_DesktopWorkAreas; + std::vector m_OldDesktopWorkAreas; bool m_Logging; diff --git a/revision-number.h b/revision-number.h index 89584d59..4aa641a8 100644 --- a/revision-number.h +++ b/revision-number.h @@ -1,2 +1,2 @@ #pragma once -const int revision_number = 455; \ No newline at end of file +const int revision_number = 461; \ No newline at end of file