Architecture discussion for brightness control in KWin
As part of my SoK project, I am creating this issue to discuss the proposed architecture for implementing brightness control in KWin
Current Status
The current architecture looks like this:
graph TB
Action -- "DBus" --> Kact
Enum -- "DBus" --> plasma-workspace/applets/brightness
subgraph plasma-workspace/applets/brightness
Action[User Action]
end
subgraph powerdevil/daemon
Kact("KAuth Action (backlightbrightness.cpp)")
Enum("Screen Enumeration (backlighthelper_linux.cpp)")
end
Proposals
There are a few different ways we could implement brightness control in KWin:
Wayland only (1)
If X11 support can be dropped, we could move the brightness handling code to kwin completely. the architecture could look like this:
graph TB
Action -- "DBus/Wayland API" --> HDR
Enum -- "DBus/Wayland API" --> plasma-workspace/applets/brightness
HDR --> Kact
subgraph plasma-workspace/applets/brightness
Action[User Action]
end
subgraph kwin/new_code
HDR("HDR handling")
Kact("KAuth/logind/sysfs call")
Enum("Screen Enumeration")
end
Benefits
- Simple architecture
- No code duplication
Drawbacks
- No X11 support
- More code changes required
Wayland + X11 (2)
If X11 support needs to be retained, we need to support the scenario where a different window manager is used, so brightness control can't depend on KWin. Xaver proposed that we use the existing backlight helper from powerdevil and use a new wayland protocol for communication between kwin and powerdevil as DBus may not be responsive enough.
The architecture could look like this:
graph TB
Action -- "DBus" --> Kact
Enum -- "DBus" --> plasma-workspace/applets/brightness
Kact -- "Yes\n\nWayland Protocol" --> HDR
Kact -- "No (X11)" --> X11
HDR -- "Wayland Protocol" --> Help
subgraph plasma-workspace/applets/brightness
Action[User Action]
end
subgraph powerdevil/daemon
Kact{"Kwin present?"}
Enum("Screen Enumeration (backlighthelper_linux.cpp)")
X11("Existing code")
Help("Backlight Helper")
end
subgraph Kwin
HDR("HDR etc. handling")
end
Benefits
- Less code changes required
- Support for X11 retained
Drawbacks
- Complicated architecture
- Possible performance penalty
Wayland + X11 (3)
Alternatively, KWin can provide the DBus interface for the brightness applet on wayland and powerdevil can continue to provide it on X11.
graph TB
Action -- "DBus" --> Chk
Chk -- "Wayland" --> Kwin
Chk -- "X11" --> Control
Kwin --> ncnt
Enum -- "DBus (X11)" --> plasma-workspace/applets/brightness
Enum2 -- "DBus (Wayland)" --> plasma-workspace/applets/brightness
subgraph plasma-workspace/applets/brightness
Action[User Action]
Chk{"Session Type"}
end
subgraph kwin
Kwin("DBus API provider")
ncnt("HDR handling + backlight control")
Enum2("Screen Enumeration")
end
subgraph powerdevil
Control("Existing control")
Enum("Screen Enumeration")
end
Benefits
- Basically (1) with X11 support retained
- Kwin code can be improved independently of powerdevil and X11
- Later if X11 support is dropped, it would become the same as (1)
Drawbacks
- Slight code duplication
- More code changes required
Please share your insights and mention if I missed/misunderstood anything.