Changed: "Normal" z-position now stays on desktop by default

This commit is contained in:
Birunthan Mohanathas 2011-11-10 11:50:47 +00:00
parent 1e9d424c99
commit 8cb0a041e0
6 changed files with 136 additions and 81 deletions

View File

@ -41,6 +41,8 @@ using namespace Gdiplus;
#define SNAPDISTANCE 10 #define SNAPDISTANCE 10
#define ZPOS_FLAGS (SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOSENDCHANGING)
enum TIMER enum TIMER
{ {
TIMER_METER = 1, TIMER_METER = 1,
@ -431,7 +433,11 @@ void CMeterWindow::Refresh(bool init, bool all)
ScreenToWindow(); ScreenToWindow();
if (all || oldZPos != m_WindowZPosition) if (init)
{
ChangeSingleZPos(m_WindowZPosition, all);
}
else if (all || oldZPos != m_WindowZPosition)
{ {
ChangeZPos(m_WindowZPosition, all); ChangeZPos(m_WindowZPosition, all);
} }
@ -590,8 +596,6 @@ void CMeterWindow::MoveWindow(int x, int y)
*/ */
void CMeterWindow::ChangeZPos(ZPOSITION zPos, bool all) void CMeterWindow::ChangeZPos(ZPOSITION zPos, bool all)
{ {
#define ZPOS_FLAGS (SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOSENDCHANGING)
HWND winPos = HWND_NOTOPMOST; HWND winPos = HWND_NOTOPMOST;
m_WindowZPosition = zPos; m_WindowZPosition = zPos;
@ -622,12 +626,11 @@ void CMeterWindow::ChangeZPos(ZPOSITION zPos, bool all)
} }
break; break;
case ZPOSITION_NORMAL:
if (all || !Rainmeter->IsNormalStayDesktop()) break;
case ZPOSITION_ONDESKTOP: case ZPOSITION_ONDESKTOP:
if (CSystem::GetShowDesktop()) if (CSystem::GetShowDesktop())
{ {
// Set WS_EX_TOPMOST flag
SetWindowPos(m_Window, HWND_TOPMOST, 0, 0, 0, 0, ZPOS_FLAGS);
winPos = CSystem::GetHelperWindow(); winPos = CSystem::GetHelperWindow();
if (all) if (all)
@ -669,6 +672,30 @@ void CMeterWindow::ChangeZPos(ZPOSITION zPos, bool all)
SetWindowPos(m_Window, winPos, 0, 0, 0, 0, ZPOS_FLAGS); SetWindowPos(m_Window, winPos, 0, 0, 0, 0, ZPOS_FLAGS);
} }
/*
** ChangeSingleZPos
**
** Sets the window's z-position in proper order.
**
*/
void CMeterWindow::ChangeSingleZPos(ZPOSITION zPos, bool all)
{
if (zPos == ZPOSITION_NORMAL && m_Rainmeter->IsNormalStayDesktop() && (!all || CSystem::GetShowDesktop()))
{
m_WindowZPosition = zPos;
// Set window on top of all other ZPOSITION_ONDESKTOP, ZPOSITION_BOTTOM, and ZPOSITION_NORMAL windows
SetWindowPos(m_Window, CSystem::GetBackmostTopWindow(), 0, 0, 0, 0, ZPOS_FLAGS);
// Bring window on top of other application windows
BringWindowToTop(m_Window);
}
else
{
ChangeZPos(zPos, all);
}
}
/* /*
** RunBang ** RunBang
** **
@ -3812,7 +3839,7 @@ void CMeterWindow::SetWindowHide(HIDEMODE hide)
*/ */
void CMeterWindow::SetWindowZPosition(ZPOSITION zpos) void CMeterWindow::SetWindowZPosition(ZPOSITION zpos)
{ {
ChangeZPos(zpos); ChangeSingleZPos(zpos);
WriteConfig(SETTING_ALWAYSONTOP); WriteConfig(SETTING_ALWAYSONTOP);
} }
@ -3950,14 +3977,22 @@ LRESULT CMeterWindow::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam)
*/ */
LRESULT CMeterWindow::OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CMeterWindow::OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
LPWINDOWPOS wp=(LPWINDOWPOS)lParam; LPWINDOWPOS wp = (LPWINDOWPOS)lParam;
if (!m_Refreshing) if (!m_Refreshing)
{ {
if (m_WindowZPosition == ZPOSITION_ONBOTTOM || m_WindowZPosition == ZPOSITION_ONDESKTOP) if (m_WindowZPosition == ZPOSITION_NORMAL && m_Rainmeter->IsNormalStayDesktop() && CSystem::GetShowDesktop())
{ {
// do not change the z-order. This keeps the window on bottom. if (!(wp->flags & (SWP_NOOWNERZORDER | SWP_NOACTIVATE)))
wp->flags|=SWP_NOZORDER; {
// Set window on top of all other ZPOSITION_ONDESKTOP, ZPOSITION_BOTTOM, and ZPOSITION_NORMAL windows
wp->hwndInsertAfter = CSystem::GetBackmostTopWindow();
}
}
else if (m_WindowZPosition == ZPOSITION_ONDESKTOP || m_WindowZPosition == ZPOSITION_ONBOTTOM)
{
// Do not change the z-order. This keeps the window on bottom.
wp->flags |= SWP_NOZORDER;
} }
} }

View File

@ -188,6 +188,7 @@ public:
void MoveWindow(int x, int y); void MoveWindow(int x, int y);
void ChangeZPos(ZPOSITION zPos, bool all = false); void ChangeZPos(ZPOSITION zPos, bool all = false);
void ChangeSingleZPos(ZPOSITION zPos, bool all = false);
void FadeWindow(int from, int to); void FadeWindow(int from, int to);
void ResizeBlur(const WCHAR* arg, int mode); void ResizeBlur(const WCHAR* arg, int mode);

View File

@ -757,6 +757,7 @@ CRainmeter::CRainmeter() :
m_NewVersion(false), m_NewVersion(false),
m_DesktopWorkAreaChanged(false), m_DesktopWorkAreaChanged(false),
m_DesktopWorkAreaType(false), m_DesktopWorkAreaType(false),
m_NormalStayDesktop(true),
m_MenuActive(false), m_MenuActive(false),
m_DisableRDP(false), m_DisableRDP(false),
m_DisableDragging(false), m_DisableDragging(false),
@ -2220,6 +2221,8 @@ void CRainmeter::ReadGeneralSettings(const std::wstring& iniFile)
m_DesktopWorkAreaType = 0!=parser.ReadInt(L"Rainmeter", L"DesktopWorkAreaType", 0); m_DesktopWorkAreaType = 0!=parser.ReadInt(L"Rainmeter", L"DesktopWorkAreaType", 0);
m_NormalStayDesktop = 0!=parser.ReadInt(L"Rainmeter", L"NormalStayDesktop", 1);
for (int i = 0, isize = (int)m_ConfigStrings.size(); i < isize; ++i) for (int i = 0, isize = (int)m_ConfigStrings.size(); i < isize; ++i)
{ {
int active = parser.ReadInt(m_ConfigStrings[i].config.c_str(), L"Active", 0); int active = parser.ReadInt(m_ConfigStrings[i].config.c_str(), L"Active", 0);

View File

@ -143,6 +143,8 @@ public:
bool GetDisableDragging() { return m_DisableDragging; } bool GetDisableDragging() { return m_DisableDragging; }
void SetDisableDragging(bool dragging); void SetDisableDragging(bool dragging);
bool IsNormalStayDesktop() { return m_NormalStayDesktop; }
void AddAboutLogInfo(int level, LPCWSTR time, LPCWSTR message); void AddAboutLogInfo(int level, LPCWSTR time, LPCWSTR message);
const std::list<LOG_INFO>& GetAboutLogData() { return m_LogData; } const std::list<LOG_INFO>& GetAboutLogData() { return m_LogData; }
@ -242,6 +244,8 @@ private:
std::map<UINT, RECT> m_DesktopWorkAreas; std::map<UINT, RECT> m_DesktopWorkAreas;
std::vector<RECT> m_OldDesktopWorkAreas; std::vector<RECT> m_OldDesktopWorkAreas;
bool m_NormalStayDesktop;
bool m_MenuActive; bool m_MenuActive;
bool m_DisableRDP; bool m_DisableRDP;

View File

@ -102,6 +102,31 @@ void CSystem::Initialize(HINSTANCE instance)
SetWindowPos(c_Window, HWND_BOTTOM, 0, 0, 0, 0, ZPOS_FLAGS); SetWindowPos(c_Window, HWND_BOTTOM, 0, 0, 0, 0, ZPOS_FLAGS);
SetWindowPos(c_HelperWindow, HWND_BOTTOM, 0, 0, 0, 0, ZPOS_FLAGS); SetWindowPos(c_HelperWindow, HWND_BOTTOM, 0, 0, 0, 0, ZPOS_FLAGS);
OSVERSIONINFOEX osvi = {sizeof(OSVERSIONINFOEX)};
if (GetVersionEx((OSVERSIONINFO*)&osvi))
{
if (osvi.dwMajorVersion == 5)
{
// Not checking for osvi.dwMinorVersion >= 1 because Rainmeter won't run on pre-XP
c_Platform = OSPLATFORM_XP;
}
else if (osvi.dwMajorVersion == 6)
{
if (osvi.dwMinorVersion == 0)
{
c_Platform = OSPLATFORM_VISTA; // Vista, Server 2008
}
else
{
c_Platform = OSPLATFORM_7; // 7, Server 2008R2
}
}
else // newer OS
{
c_Platform = OSPLATFORM_7;
}
}
c_Monitors.monitors.reserve(8); c_Monitors.monitors.reserve(8);
SetMultiMonitorInfo(); SetMultiMonitorInfo();
@ -623,6 +648,33 @@ HWND CSystem::GetWorkerW()
return WorkerW; return WorkerW;
} }
/*
** GetBackmostTopWindow
**
** Returns the first window whose position is not ZPOSITION_ONDESKTOP,
** ZPOSITION_BOTTOM, or ZPOSITION_NORMAL.
**
*/
HWND CSystem::GetBackmostTopWindow()
{
HWND winPos = c_HelperWindow;
// Skip all ZPOSITION_ONDESKTOP, ZPOSITION_BOTTOM, and ZPOSITION_NORMAL windows
while (winPos = ::GetNextWindow(winPos, GW_HWNDPREV))
{
CMeterWindow* wnd = Rainmeter->GetMeterWindow(winPos);
if (!wnd ||
(wnd->GetWindowZPosition() != ZPOSITION_NORMAL &&
wnd->GetWindowZPosition() != ZPOSITION_ONDESKTOP &&
wnd->GetWindowZPosition() != ZPOSITION_ONBOTTOM))
{
break;
}
}
return winPos;
}
/* /*
** BelongToSameProcess ** BelongToSameProcess
** **
@ -657,7 +709,9 @@ BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lParam)
(Window = Rainmeter->GetMeterWindow(hwnd))) (Window = Rainmeter->GetMeterWindow(hwnd)))
{ {
ZPOSITION zPos = Window->GetWindowZPosition(); ZPOSITION zPos = Window->GetWindowZPosition();
if (zPos == ZPOSITION_ONDESKTOP || zPos == ZPOSITION_ONBOTTOM) if (zPos == ZPOSITION_ONDESKTOP ||
(zPos == ZPOSITION_NORMAL && Rainmeter->IsNormalStayDesktop()) ||
zPos == ZPOSITION_ONBOTTOM)
{ {
if (lParam) if (lParam)
{ {
@ -705,29 +759,31 @@ void CSystem::ChangeZPosInOrder()
// Retrieve the Rainmeter's meter windows in Z-order // Retrieve the Rainmeter's meter windows in Z-order
EnumWindows(MyEnumWindowsProc, (LPARAM)(&windowsInZOrder)); EnumWindows(MyEnumWindowsProc, (LPARAM)(&windowsInZOrder));
if (!c_ShowDesktop) auto resetZPos = [=](ZPOSITION zpos)
{ {
// Reset ZPos in Z-order (Bottom) // Reset ZPos in Z-order (Bottom)
std::vector<CMeterWindow*>::const_iterator iter = windowsInZOrder.begin(), iterEnd = windowsInZOrder.end(); std::vector<CMeterWindow*>::const_iterator iter = windowsInZOrder.begin(), iterEnd = windowsInZOrder.end();
for ( ; iter != iterEnd; ++iter) for ( ; iter != iterEnd; ++iter)
{ {
if ((*iter)->GetWindowZPosition() == ZPOSITION_ONBOTTOM) if ((*iter)->GetWindowZPosition() == zpos)
{ {
(*iter)->ChangeZPos(ZPOSITION_ONBOTTOM); // reset (*iter)->ChangeZPos(zpos); // reset
} }
} }
};
if (Rainmeter->IsNormalStayDesktop())
{
resetZPos(ZPOSITION_NORMAL);
} }
// Reset ZPos in Z-order (On Desktop) if (!c_ShowDesktop)
std::vector<CMeterWindow*>::const_iterator iter = windowsInZOrder.begin(), iterEnd = windowsInZOrder.end();
for ( ; iter != iterEnd; ++iter)
{ {
if ((*iter)->GetWindowZPosition() == ZPOSITION_ONDESKTOP) resetZPos(ZPOSITION_ONBOTTOM);
{
(*iter)->ChangeZPos(ZPOSITION_ONDESKTOP); // reset
}
} }
resetZPos(ZPOSITION_ONDESKTOP);
if (logging) if (logging)
{ {
Log(LOG_DEBUG, L"2: ----- AFTER -----"); Log(LOG_DEBUG, L"2: ----- AFTER -----");
@ -839,6 +895,17 @@ bool CSystem::CheckDesktopState(HWND WorkerW)
PrepareHelperWindow(WorkerW); PrepareHelperWindow(WorkerW);
ChangeZPosInOrder(); ChangeZPosInOrder();
if (c_ShowDesktop)
{
KillTimer(c_Window, TIMER_SHOWDESKTOP);
SetTimer(c_Window, TIMER_SHOWDESKTOP, 100, NULL);
}
else
{
KillTimer(c_Window, TIMER_SHOWDESKTOP);
SetTimer(c_Window, TIMER_SHOWDESKTOP, INTERVAL_SHOWDESKTOP, NULL);
}
} }
return stateChanged; return stateChanged;
@ -955,59 +1022,6 @@ LRESULT CALLBACK CSystem::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
return DefWindowProc(hWnd, uMsg, wParam, lParam); return DefWindowProc(hWnd, uMsg, wParam, lParam);
} }
/*
** GetOSPlatform
**
** Checks which OS you are running.
**
*/
OSPLATFORM CSystem::GetOSPlatform()
{
if (c_Platform == OSPLATFORM_UNKNOWN)
{
OSVERSIONINFOEX osvi = {sizeof(OSVERSIONINFOEX)};
if (!GetVersionEx((OSVERSIONINFO*)&osvi) || osvi.dwPlatformId != VER_PLATFORM_WIN32_NT)
{
c_Platform = OSPLATFORM_9X;
}
else
{
if (osvi.dwMajorVersion <= 4) // NT4 or older
{
c_Platform = OSPLATFORM_NT4;
}
else if (osvi.dwMajorVersion == 5) // 2000 / XP (x64 / Server 2003, R2)
{
if (osvi.dwMinorVersion == 0)
{
c_Platform = OSPLATFORM_2K;
}
else
{
c_Platform = OSPLATFORM_XP;
}
}
else if (osvi.dwMajorVersion == 6) // Vista (Server 2008) / 7 (Server 2008R2)
{
if (osvi.dwMinorVersion == 0)
{
c_Platform = OSPLATFORM_VISTA;
}
else
{
c_Platform = OSPLATFORM_7;
}
}
else // newer OS
{
c_Platform = OSPLATFORM_7;
}
}
}
return c_Platform;
}
/* /*
** GetTickCount64 ** GetTickCount64
** **

View File

@ -25,9 +25,6 @@
enum OSPLATFORM enum OSPLATFORM
{ {
OSPLATFORM_UNKNOWN = 0, OSPLATFORM_UNKNOWN = 0,
OSPLATFORM_9X,
OSPLATFORM_NT4,
OSPLATFORM_2K,
OSPLATFORM_XP, OSPLATFORM_XP,
OSPLATFORM_VISTA, OSPLATFORM_VISTA,
OSPLATFORM_7 OSPLATFORM_7
@ -59,17 +56,18 @@ public:
static void Initialize(HINSTANCE instance); static void Initialize(HINSTANCE instance);
static void Finalize(); static void Finalize();
static HWND GetWindow() { return c_Window; }
static const MULTIMONITOR_INFO& GetMultiMonitorInfo() { return c_Monitors; } static const MULTIMONITOR_INFO& GetMultiMonitorInfo() { return c_Monitors; }
static size_t GetMonitorCount(); static size_t GetMonitorCount();
static bool GetShowDesktop() { return c_ShowDesktop; } static bool GetShowDesktop() { return c_ShowDesktop; }
static HWND GetWindow() { return c_Window; }
static HWND GetBackmostTopWindow();
static HWND GetHelperWindow() { return c_HelperWindow; } static HWND GetHelperWindow() { return c_HelperWindow; }
static void PrepareHelperWindow(HWND WorkerW = GetWorkerW()); static void PrepareHelperWindow(HWND WorkerW = GetWorkerW());
static OSPLATFORM GetOSPlatform(); static OSPLATFORM GetOSPlatform() { return c_Platform; }
static ULONGLONG GetTickCount64(); static ULONGLONG GetTickCount64();
static bool IsPathSeparator(WCHAR ch) { return (ch == L'\\' || ch == L'/'); } static bool IsPathSeparator(WCHAR ch) { return (ch == L'\\' || ch == L'/'); }