Skip to content

Commit

Permalink
Suspend when no active EXTERNAL displays
Browse files Browse the repository at this point in the history
  • Loading branch information
platofff committed Dec 7, 2024
1 parent 7679e0a commit cc26845
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions ClamshellMode/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cc26845

Please sign in to comment.