mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Improved "show desktop" detection.
Some cosmetic changes.
This commit is contained in:
parent
b9cdc53430
commit
8522a15bf9
@ -108,6 +108,10 @@ void CSystem::Initialize(HINSTANCE instance)
|
|||||||
c_Monitors.monitors.reserve(8);
|
c_Monitors.monitors.reserve(8);
|
||||||
SetMultiMonitorInfo();
|
SetMultiMonitorInfo();
|
||||||
|
|
||||||
|
WCHAR directory[MAX_PATH] = {0};
|
||||||
|
GetCurrentDirectory(MAX_PATH, directory);
|
||||||
|
c_WorkingDirectory = directory;
|
||||||
|
|
||||||
c_WinEventHook = SetWinEventHook(
|
c_WinEventHook = SetWinEventHook(
|
||||||
EVENT_SYSTEM_FOREGROUND,
|
EVENT_SYSTEM_FOREGROUND,
|
||||||
EVENT_SYSTEM_FOREGROUND,
|
EVENT_SYSTEM_FOREGROUND,
|
||||||
@ -117,11 +121,10 @@ void CSystem::Initialize(HINSTANCE instance)
|
|||||||
0,
|
0,
|
||||||
WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
|
WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
|
||||||
|
|
||||||
WCHAR directory[MAX_PATH] = {0};
|
if (c_WinEventHook == NULL)
|
||||||
GetCurrentDirectory(MAX_PATH, directory);
|
{
|
||||||
c_WorkingDirectory = directory;
|
SetTimer(c_Window, TIMER_SHOWDESKTOP, INTERVAL_SHOWDESKTOP, NULL);
|
||||||
|
}
|
||||||
SetTimer(c_Window, TIMER_SHOWDESKTOP, INTERVAL_SHOWDESKTOP, NULL);
|
|
||||||
SetTimer(c_Window, TIMER_NETSTATS, INTERVAL_NETSTATS, NULL);
|
SetTimer(c_Window, TIMER_NETSTATS, INTERVAL_NETSTATS, NULL);
|
||||||
SetTimer(c_Window, TIMER_DELETELATER, INTERVAL_DELETELATER, NULL);
|
SetTimer(c_Window, TIMER_DELETELATER, INTERVAL_DELETELATER, NULL);
|
||||||
}
|
}
|
||||||
@ -209,8 +212,7 @@ BOOL CALLBACK MyInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonit
|
|||||||
wcsncpy_s(monitor.deviceName, info.szDevice, _TRUNCATE); // E.g. "\\.\DISPLAY1"
|
wcsncpy_s(monitor.deviceName, info.szDevice, _TRUNCATE); // E.g. "\\.\DISPLAY1"
|
||||||
|
|
||||||
// Get the monitor name (E.g. "Generic Non-PnP Monitor")
|
// Get the monitor name (E.g. "Generic Non-PnP Monitor")
|
||||||
DISPLAY_DEVICE ddm = {0};
|
DISPLAY_DEVICE ddm = {sizeof(DISPLAY_DEVICE)};
|
||||||
ddm.cb = sizeof(DISPLAY_DEVICE);
|
|
||||||
DWORD dwMon = 0;
|
DWORD dwMon = 0;
|
||||||
while (EnumDisplayDevices(info.szDevice, dwMon++, &ddm, 0))
|
while (EnumDisplayDevices(info.szDevice, dwMon++, &ddm, 0))
|
||||||
{
|
{
|
||||||
@ -273,8 +275,7 @@ void CSystem::SetMultiMonitorInfo()
|
|||||||
Log(LOG_DEBUG, L"* EnumDisplayDevices / EnumDisplaySettings API");
|
Log(LOG_DEBUG, L"* EnumDisplayDevices / EnumDisplaySettings API");
|
||||||
}
|
}
|
||||||
|
|
||||||
DISPLAY_DEVICE dd = {0};
|
DISPLAY_DEVICE dd = {sizeof(DISPLAY_DEVICE)};
|
||||||
dd.cb = sizeof(DISPLAY_DEVICE);
|
|
||||||
|
|
||||||
if (EnumDisplayDevices(NULL, 0, &dd, 0))
|
if (EnumDisplayDevices(NULL, 0, &dd, 0))
|
||||||
{
|
{
|
||||||
@ -334,8 +335,7 @@ void CSystem::SetMultiMonitorInfo()
|
|||||||
wcsncpy_s(monitor.deviceName, dd.DeviceName, _TRUNCATE); // E.g. "\\.\DISPLAY1"
|
wcsncpy_s(monitor.deviceName, dd.DeviceName, _TRUNCATE); // E.g. "\\.\DISPLAY1"
|
||||||
|
|
||||||
// Get the monitor name (E.g. "Generic Non-PnP Monitor")
|
// Get the monitor name (E.g. "Generic Non-PnP Monitor")
|
||||||
DISPLAY_DEVICE ddm = {0};
|
DISPLAY_DEVICE ddm = {sizeof(DISPLAY_DEVICE)};
|
||||||
ddm.cb = sizeof(DISPLAY_DEVICE);
|
|
||||||
DWORD dwMon = 0;
|
DWORD dwMon = 0;
|
||||||
while (EnumDisplayDevices(dd.DeviceName, dwMon++, &ddm, 0))
|
while (EnumDisplayDevices(dd.DeviceName, dwMon++, &ddm, 0))
|
||||||
{
|
{
|
||||||
@ -377,8 +377,7 @@ void CSystem::SetMultiMonitorInfo()
|
|||||||
|
|
||||||
if (monitor.handle != NULL)
|
if (monitor.handle != NULL)
|
||||||
{
|
{
|
||||||
MONITORINFO info = {0};
|
MONITORINFO info = {sizeof(MONITORINFO)};
|
||||||
info.cbSize = sizeof(MONITORINFO);
|
|
||||||
GetMonitorInfo(monitor.handle, &info);
|
GetMonitorInfo(monitor.handle, &info);
|
||||||
|
|
||||||
monitor.screen = info.rcMonitor;
|
monitor.screen = info.rcMonitor;
|
||||||
@ -529,8 +528,7 @@ void CSystem::UpdateWorkareaInfo()
|
|||||||
{
|
{
|
||||||
if (monitors[i].active && monitors[i].handle != NULL)
|
if (monitors[i].active && monitors[i].handle != NULL)
|
||||||
{
|
{
|
||||||
MONITORINFO info = {0};
|
MONITORINFO info = {sizeof(MONITORINFO)};
|
||||||
info.cbSize = sizeof(MONITORINFO);
|
|
||||||
GetMonitorInfo(monitors[i].handle, &info);
|
GetMonitorInfo(monitors[i].handle, &info);
|
||||||
|
|
||||||
monitors[i].work = info.rcWork;
|
monitors[i].work = info.rcWork;
|
||||||
@ -777,19 +775,33 @@ void CSystem::PrepareHelperWindow(HWND WorkerW)
|
|||||||
** Changes the "Show Desktop" state.
|
** Changes the "Show Desktop" state.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void CSystem::CheckDesktopState(HWND WorkerW)
|
bool CSystem::CheckDesktopState(HWND WorkerW)
|
||||||
{
|
{
|
||||||
HWND hwnd = NULL;
|
HWND hwnd = NULL;
|
||||||
|
|
||||||
if (WorkerW)
|
if (WorkerW && IsWindowVisible(WorkerW))
|
||||||
{
|
{
|
||||||
hwnd = FindWindowEx(NULL, WorkerW, L"RainmeterSystemClass", L"SystemWindow");
|
hwnd = FindWindowEx(NULL, WorkerW, L"RainmeterSystemClass", L"SystemWindow");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((hwnd && !c_ShowDesktop) || (!hwnd && c_ShowDesktop)) // State changed
|
bool stateChanged = (hwnd && !c_ShowDesktop) || (!hwnd && c_ShowDesktop);
|
||||||
|
|
||||||
|
if (stateChanged)
|
||||||
{
|
{
|
||||||
c_ShowDesktop = !c_ShowDesktop;
|
c_ShowDesktop = !c_ShowDesktop;
|
||||||
|
|
||||||
|
if (c_WinEventHook)
|
||||||
|
{
|
||||||
|
if (c_ShowDesktop)
|
||||||
|
{
|
||||||
|
SetTimer(c_Window, TIMER_SHOWDESKTOP, INTERVAL_SHOWDESKTOP, NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
KillTimer(c_Window, TIMER_SHOWDESKTOP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (CRainmeter::GetDebug())
|
if (CRainmeter::GetDebug())
|
||||||
{
|
{
|
||||||
LogWithArgs(LOG_DEBUG, L"System: %s",
|
LogWithArgs(LOG_DEBUG, L"System: %s",
|
||||||
@ -800,6 +812,8 @@ void CSystem::CheckDesktopState(HWND WorkerW)
|
|||||||
|
|
||||||
ChangeZPosInOrder();
|
ChangeZPosInOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return stateChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -817,10 +831,30 @@ void CALLBACK CSystem::MyWinEventProc(HWINEVENTHOOK hWinEventHook, DWORD event,
|
|||||||
WCHAR className[16];
|
WCHAR className[16];
|
||||||
if (GetClassName(hwnd, className, 16) > 0 &&
|
if (GetClassName(hwnd, className, 16) > 0 &&
|
||||||
_wcsicmp(className, L"WorkerW") == 0 &&
|
_wcsicmp(className, L"WorkerW") == 0 &&
|
||||||
BelongToSameProcess(GetDefaultShellWindow(), hwnd) &&
|
BelongToSameProcess(GetDefaultShellWindow(), hwnd))
|
||||||
FindWindowEx(hwnd, NULL, L"SHELLDLL_DefView", L""))
|
|
||||||
{
|
{
|
||||||
CheckDesktopState(hwnd);
|
const int max = 5;
|
||||||
|
int loop = 0;
|
||||||
|
while (loop < max && FindWindowEx(hwnd, NULL, L"SHELLDLL_DefView", L"") == NULL)
|
||||||
|
{
|
||||||
|
Sleep(2); // Wait for 2-16 ms before retrying
|
||||||
|
++loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loop < max)
|
||||||
|
{
|
||||||
|
loop = 0;
|
||||||
|
while (loop < max && !CheckDesktopState(hwnd))
|
||||||
|
{
|
||||||
|
Sleep(2); // Wait for 2-16 ms before retrying
|
||||||
|
++loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loop >= max) // detection failed
|
||||||
|
{
|
||||||
|
SetTimer(c_Window, TIMER_SHOWDESKTOP, INTERVAL_SHOWDESKTOP, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ private:
|
|||||||
static HWND GetDefaultShellWindow();
|
static HWND GetDefaultShellWindow();
|
||||||
static void ChangeZPosInOrder();
|
static void ChangeZPosInOrder();
|
||||||
|
|
||||||
static void CheckDesktopState(HWND WorkerW);
|
static bool CheckDesktopState(HWND WorkerW);
|
||||||
static bool BelongToSameProcess(HWND hwndA, HWND hwndB);
|
static bool BelongToSameProcess(HWND hwndA, HWND hwndB);
|
||||||
|
|
||||||
static HWND c_Window;
|
static HWND c_Window;
|
||||||
|
Loading…
Reference in New Issue
Block a user