feat: add laptop/display brightness modulation

This commit is contained in:
daniel committed 2026-10-02 12:14:40 +02:00
1 parent ef1e69ae83
commit 7979acc2eb
34 files changed
+1308 -78

No files matched your search

+29 -2
View File
@@ -11,6 +11,7 @@
#include <Memory/HHDM.hpp>
#include <Graphics/Framebuffer.hpp>
#include <Drivers/Graphics/IntelGPU.hpp>
#include <ACPI/AcpiVideo.hpp>
#include <Terminal/Terminal.hpp>
#include "Syscall.hpp"
@@ -128,8 +129,30 @@ namespace montauk::abi {
return GPU::Flip((int)index, (flags & 1) != 0, proc->pid);
}
// The firmware's ACPI brightness methods drive the built-in panel, so
// they stand in only when that panel is what is on screen (or no native
// driver knows what is): never for an external monitor without DDC/CI.
static bool AcpiBrightnessApplies() {
if (!Drivers::Graphics::IntelGPU::IsInitialized()) return true;
uint8_t type = Drivers::Graphics::IntelGPU::ActiveConnectorType();
return type == DISPLAY_CONNECTOR_EDP || type == DISPLAY_CONNECTOR_LVDS;
}
static int DisplayBrightness(int percent) {
int rc = Drivers::Graphics::IntelGPU::Brightness(percent);
if (rc == -1 && AcpiBrightnessApplies())
rc = Hal::AcpiVideo::Brightness(percent);
return rc;
}
static int64_t Sys_DisplayInfo(DisplayInfo* out) {
return Drivers::Graphics::IntelGPU::GetDisplayInfo(out) ? Success : NoDevice;
if (!Drivers::Graphics::IntelGPU::GetDisplayInfo(out)) return NoDevice;
if (out->brightness < 0 && AcpiBrightnessApplies()) {
out->brightness = Hal::AcpiVideo::Brightness(-1);
if (out->brightness >= 0) out->capabilities |= DISPLAY_CAP_BRIGHTNESS;
else out->brightness = -1;
}
return Success;
}
static int64_t Sys_DisplayModes(DisplayModeInfo* out, int maxCount) {
@@ -145,8 +168,12 @@ namespace montauk::abi {
return rc;
}
// percent < 0 queries. Returns 0..100, NoDevice when the active output
// has no controllable backlight, IoFailure when the hardware refused.
static int64_t Sys_DisplayBrightness(int percent) {
return Drivers::Graphics::IntelGPU::Brightness(percent);
int rc = DisplayBrightness(percent);
if (rc >= 0) return rc;
return rc == -1 ? NoDevice : IoFailure;
}
static uint64_t Sys_TermSize() {