From cc26845d26261e06426de9e52dc646dd88bac0bd Mon Sep 17 00:00:00 2001 From: platofff <42435266+platofff@users.noreply.github.com> Date: Sat, 7 Dec 2024 20:04:38 +0300 Subject: [PATCH] Suspend when no active EXTERNAL displays --- ClamshellMode/main.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/ClamshellMode/main.c b/ClamshellMode/main.c index be1fa99..92cb33d 100644 --- a/ClamshellMode/main.c +++ b/ClamshellMode/main.c @@ -120,24 +120,6 @@ static BOOL ExternalDisplayConnected() { return FALSE; } -static BOOL HasAnyActiveDisplays() { - DISPLAY_DEVICE device = { .cb = sizeof(DISPLAY_DEVICE) }; - DWORD i = 0; - - while (EnumDisplayDevicesW(NULL, i++, &device, 0) != 0) { - DISPLAY_DEVICE device2 = { .cb = sizeof(DISPLAY_DEVICE) }; - DWORD j = 0; - - while (EnumDisplayDevicesW(device.DeviceName, j++, &device2, 0) != 0) { - if (device2.StateFlags & DISPLAY_DEVICE_ACTIVE) { - return TRUE; - } - } - } - - return FALSE; -} - static void PopulateDisplayDevices(HWND hComboBox) { DISPLAY_DEVICE device = { .cb = sizeof(DISPLAY_DEVICE) }; DWORD i = 0; @@ -249,7 +231,7 @@ static LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg, WPARAM wParam, LPAR { break; } - if (HasAnyActiveDisplays()) { // if any monitor is active + if (ExternalDisplayConnected()) { // if any monitor is active break; } if (lidState != 0) { // if lid is not closed @@ -347,7 +329,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, { #if NDEBUG == 0 AllocConsole(); - FILE* file; + FILE* file = NULL; freopen_s(&file, "CONOUT$", "w", stdout); freopen_s(&file, "CONIN$", "r", stdin); freopen_s(&file, "CONOUT$", "w", stderr);