mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
DisplayServer: make display brightness actually work (Windows)
This commit is contained in:
+1
-2
@@ -463,7 +463,7 @@ elseif(WIN32)
|
||||
src/detection/cpuUsage/cpuUsage_windows.c
|
||||
src/detection/cursor/cursor_windows.c
|
||||
src/detection/disk/disk_windows.c
|
||||
src/detection/displayserver/displayserver_windows.c
|
||||
src/detection/displayserver/displayserver_windows.cpp
|
||||
src/detection/font/font_windows.c
|
||||
src/detection/gpu/gpu_windows.cpp
|
||||
src/detection/host/host_windows.c
|
||||
@@ -671,7 +671,6 @@ elseif(WIN32)
|
||||
PRIVATE "dxgi"
|
||||
PRIVATE "wtsapi32"
|
||||
PRIVATE "powrprof"
|
||||
PRIVATE "dxva2"
|
||||
)
|
||||
if(USE_WIN_NTAPI)
|
||||
target_compile_definitions(libfastfetch PRIVATE FF_USE_WIN_NTAPI)
|
||||
|
||||
+24
-33
@@ -1,36 +1,13 @@
|
||||
extern "C" {
|
||||
#include "displayserver.h"
|
||||
#include "detection/os/os.h"
|
||||
#include "util/mallocHelper.h"
|
||||
}
|
||||
#include "util/windows/wmi.hpp"
|
||||
|
||||
#include <dwmapi.h>
|
||||
#include <WinUser.h>
|
||||
#include <wchar.h>
|
||||
#include <highlevelmonitorconfigurationapi.h>
|
||||
|
||||
static WINBOOL enumMonitorProc(HMONITOR hMonitor, FF_UNUSED_PARAM HDC hDC, FF_UNUSED_PARAM LPRECT rc, LPARAM data)
|
||||
{
|
||||
MONITORINFOEXW mi = { .cbSize = sizeof(mi) };
|
||||
DISPLAY_DEVICEW* displayDevice = (DISPLAY_DEVICEW *) data;
|
||||
if(GetMonitorInfoW(hMonitor, (MONITORINFO *)&mi) && wcscmp(mi.szDevice, displayDevice->DeviceName) == 0)
|
||||
{
|
||||
DWORD arraySize;
|
||||
if(GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, &arraySize) && arraySize > 0)
|
||||
{
|
||||
PHYSICAL_MONITOR* FF_AUTO_FREE physicalMonitorArray = malloc(arraySize * sizeof(*physicalMonitorArray));
|
||||
if(GetPhysicalMonitorsFromHMONITOR(hMonitor, arraySize, physicalMonitorArray))
|
||||
{
|
||||
DWORD minValue, currentValue, maxValue;
|
||||
if(GetMonitorBrightness(physicalMonitorArray[0].hPhysicalMonitor, &minValue, ¤tValue, &maxValue))
|
||||
displayDevice->StateFlags = currentValue * 100 / maxValue;
|
||||
|
||||
DestroyPhysicalMonitors(arraySize, physicalMonitorArray);
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#include <winuser.h>
|
||||
|
||||
extern "C"
|
||||
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* instance)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
@@ -52,19 +29,33 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* ins
|
||||
ffStrbufInit(&ds->deVersion);
|
||||
ffListInit(&ds->resolutions, sizeof(FFResolutionResult));
|
||||
|
||||
DISPLAY_DEVICEW displayDevice = { .cb = sizeof(DISPLAY_DEVICEW) };
|
||||
DISPLAY_DEVICEW displayDevice;
|
||||
displayDevice.cb = sizeof(DISPLAY_DEVICEW);
|
||||
for(DWORD devNum = 0; EnumDisplayDevicesW(NULL, devNum, &displayDevice, 0) != 0; ++devNum)
|
||||
{
|
||||
if(!(displayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE))
|
||||
continue;
|
||||
DEVMODEW devMode = { .dmSize = sizeof(DEVMODEW) };
|
||||
DEVMODEW devMode;
|
||||
devMode.dmSize = sizeof(DEVMODEW);
|
||||
if(EnumDisplaySettingsW(displayDevice.DeviceName, ENUM_CURRENT_SETTINGS, &devMode) == 0)
|
||||
continue;
|
||||
|
||||
displayDevice.StateFlags = (DWORD) -1;
|
||||
EnumDisplayMonitors(NULL, NULL, enumMonitorProc, (LPARAM)(void*) &displayDevice);
|
||||
ffdsAppendResolution(ds, devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmDisplayFrequency, -1);
|
||||
}
|
||||
|
||||
ffdsAppendResolution(ds, devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmDisplayFrequency, (int) displayDevice.StateFlags);
|
||||
//TODO: support multiple monitors
|
||||
if(ds->resolutions.length == 1)
|
||||
{
|
||||
FFWmiQuery query(L"SELECT CurrentBrightness FROM WmiMonitorBrightness WHERE Active = true", nullptr, FFWmiNamespace::WMI);
|
||||
if(FFWmiRecord record = query.next())
|
||||
{
|
||||
uint64_t brightness;
|
||||
record.getUnsigned(L"CurrentBrightness", &brightness);
|
||||
FF_LIST_FOR_EACH(FFResolutionResult, resolution, ds->resolutions)
|
||||
{
|
||||
resolution->brightness = (int) brightness;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//https://github.com/hykilpikonna/hyfetch/blob/master/neofetch#L2067
|
||||
@@ -28,7 +28,7 @@ void ffPrintResolution(FFinstance* instance)
|
||||
printf(" @ %iHz", result->refreshRate);
|
||||
|
||||
if(result->brightness >= 0)
|
||||
printf(" (☀️ %d%%)", result->brightness);
|
||||
printf(" (Brightness %d%%)", result->brightness);
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
+18
-14
@@ -26,7 +26,7 @@ static void CoUninitializeWrap()
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
static BOOL CALLBACK InitHandleFunction(PINIT_ONCE, PVOID, PVOID *lpContext)
|
||||
static BOOL CALLBACK InitHandleFunction(PINIT_ONCE, PVOID lpParameter, PVOID* lpContext)
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
@@ -76,15 +76,15 @@ static BOOL CALLBACK InitHandleFunction(PINIT_ONCE, PVOID, PVOID *lpContext)
|
||||
// the current user and obtain pointer pSvc
|
||||
// to make IWbemServices calls.
|
||||
hres = pLoc->ConnectServer(
|
||||
bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace
|
||||
nullptr, // User name. nullptr = current user
|
||||
nullptr, // User password. nullptr = current
|
||||
0, // Locale. nullptr indicates current
|
||||
0, // Security flags.
|
||||
0, // Authority (for example, Kerberos)
|
||||
0, // Context object
|
||||
&pSvc // pointer to IWbemServices proxy
|
||||
);
|
||||
bstr_t((const wchar_t*) lpParameter), // Object path of WMI namespace
|
||||
nullptr, // User name. nullptr = current user
|
||||
nullptr, // User password. nullptr = current
|
||||
0, // Locale. nullptr indicates current
|
||||
0, // Security flags.
|
||||
0, // Authority (for example, Kerberos)
|
||||
0, // Context object
|
||||
&pSvc // pointer to IWbemServices proxy
|
||||
);
|
||||
pLoc->Release();
|
||||
pLoc = nullptr;
|
||||
|
||||
@@ -120,13 +120,17 @@ static BOOL CALLBACK InitHandleFunction(PINIT_ONCE, PVOID, PVOID *lpContext)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
FFWmiQuery::FFWmiQuery(const wchar_t* queryStr, FFstrbuf* error)
|
||||
FFWmiQuery::FFWmiQuery(const wchar_t* queryStr, FFstrbuf* error, FFWmiNamespace wmiNs)
|
||||
: pEnumerator(nullptr)
|
||||
{
|
||||
static INIT_ONCE s_InitOnce = INIT_ONCE_STATIC_INIT;
|
||||
static INIT_ONCE s_InitOnce[(int) FFWmiNamespace::LAST] = {};
|
||||
const char* context;
|
||||
if (InitOnceExecuteOnce(&s_InitOnce, &InitHandleFunction, nullptr, (void**)&context) == FALSE)
|
||||
{
|
||||
if (InitOnceExecuteOnce(
|
||||
&s_InitOnce[(int)wmiNs],
|
||||
&InitHandleFunction,
|
||||
(PVOID) (wmiNs == FFWmiNamespace::CIMV2 ? L"ROOT\\CIMV2" : L"ROOT\\WMI"),
|
||||
(void**)&context) == FALSE
|
||||
) {
|
||||
if(error)
|
||||
ffStrbufAppendS(error, context);
|
||||
return;
|
||||
|
||||
@@ -11,6 +11,12 @@ extern "C" {
|
||||
|
||||
#include <Wbemidl.h>
|
||||
|
||||
enum class FFWmiNamespace {
|
||||
CIMV2,
|
||||
WMI,
|
||||
LAST,
|
||||
};
|
||||
|
||||
struct FFWmiRecord
|
||||
{
|
||||
IWbemClassObject* obj;
|
||||
@@ -43,7 +49,7 @@ struct FFWmiQuery
|
||||
{
|
||||
IEnumWbemClassObject* pEnumerator = nullptr;
|
||||
|
||||
FFWmiQuery(const wchar_t* queryStr, FFstrbuf* error = nullptr);
|
||||
FFWmiQuery(const wchar_t* queryStr, FFstrbuf* error = nullptr, FFWmiNamespace wmiNs = FFWmiNamespace::CIMV2);
|
||||
explicit FFWmiQuery(IEnumWbemClassObject* pEnumerator): pEnumerator(pEnumerator) {}
|
||||
FFWmiQuery(const FFWmiQuery& other) = delete;
|
||||
FFWmiQuery(FFWmiQuery&& other) { *this = (FFWmiQuery&&)other; }
|
||||
|
||||
Reference in New Issue
Block a user