feat: add laptop/display brightness modulation
This commit is contained in:
1 parent
ef1e69ae83
commit
7979acc2eb
34 files changed
+1308
-78
No files matched your search
@@ -12,4 +12,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MONTAUK_BUILD_NUMBER 283
|
||||
#define MONTAUK_BUILD_NUMBER 287
|
||||
@@ -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() {
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace montauk::abi {
|
||||
return Sys_DisplaySetMode((int)frame->arg1);
|
||||
case SYS_DISPLAYBRIGHTNESS:
|
||||
if ((int64_t)frame->arg1 >= 0 &&
|
||||
!Sched::Consent::Require(CAP_DISPLAY_ADMIN)) return CapabilityDenied;
|
||||
!Sched::Consent::Require(CAP_BRIGHTNESS)) return CapabilityDenied;
|
||||
return Sys_DisplayBrightness((int)frame->arg1);
|
||||
case SYS_GETEXECPATH:
|
||||
if (!UserMemory::Range(frame->arg2 ? frame->arg1 : frame->arg1, frame->arg2, true)) return BadPointer;
|
||||
|
||||
@@ -385,8 +385,14 @@ namespace montauk::abi {
|
||||
never part of a session mask, never part of "all", and never
|
||||
delegated by the compositor to what it launches. */
|
||||
static constexpr uint64_t CAP_COMPOSITOR = 1ULL << 13;
|
||||
static constexpr uint64_t CAP_ALL = (1ULL << 14) - 1;
|
||||
static constexpr uint64_t CAP_STANDARD_SESSION = CAP_POWER_REQUEST | CAP_SUSPEND;
|
||||
/* Set the backlight of the active display (SYS_DISPLAYBRIGHTNESS).
|
||||
A seat preference rather than display administration, so every
|
||||
session holds it; CAP_DISPLAY_ADMIN keeps mode setting. Reading the
|
||||
level needs nothing. */
|
||||
static constexpr uint64_t CAP_BRIGHTNESS = 1ULL << 14;
|
||||
static constexpr uint64_t CAP_ALL = (1ULL << 15) - 1;
|
||||
static constexpr uint64_t CAP_STANDARD_SESSION =
|
||||
CAP_POWER_REQUEST | CAP_SUSPEND | CAP_BRIGHTNESS;
|
||||
static constexpr uint64_t CAP_ADMIN_SESSION =
|
||||
CAP_STANDARD_SESSION | CAP_PROCESS_ADMIN | CAP_STORAGE_ADMIN |
|
||||
CAP_RAW_STORAGE | CAP_NETWORK_ADMIN | CAP_SET_TIME | CAP_USER_ADMIN |
|
||||
@@ -438,7 +444,7 @@ namespace montauk::abi {
|
||||
deferred delegation, not amplification. */
|
||||
static constexpr uint64_t CAP_CONSENT_ELIGIBLE =
|
||||
CAP_STORAGE_ADMIN | CAP_NETWORK_ADMIN | CAP_SET_TIME |
|
||||
CAP_DISPLAY_ADMIN | CAP_LOG_READ;
|
||||
CAP_DISPLAY_ADMIN | CAP_LOG_READ | CAP_BRIGHTNESS;
|
||||
static_assert((CAP_CONSENT_ELIGIBLE & ~CAP_ADMIN_SESSION) == 0,
|
||||
"consent can only hand out authority an admin session holds");
|
||||
|
||||
|
||||
Reference in new issue
Block a user