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.
This commit is contained in:
jsmorley 2010-07-10 12:56:37 +00:00
parent d07e8665b0
commit 5be6e9783d
4 changed files with 122 additions and 20 deletions

View File

@ -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"

View File

@ -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);
@ -2168,11 +2167,26 @@ void CRainmeter::ReadGeneralSettings(std::wstring& iniFile)
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<UINT, RECT>::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
**

View File

@ -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<CONFIGMENU>& menu, bool DontRecurse);
@ -240,7 +241,8 @@ private:
BOOL m_NewVersion;
BOOL m_DesktopWorkAreaChanged;
RECT m_DesktopWorkArea;
std::map<UINT, RECT> m_DesktopWorkAreas;
std::vector<RECT> m_OldDesktopWorkAreas;
bool m_Logging;

View File

@ -1,2 +1,2 @@
#pragma once
const int revision_number = 455;
const int revision_number = 461;