summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorFilip Mikina <fm394471@students.mimuw.edu.pl>2025-10-24 21:18:39 +0200
committerGitHub <noreply@github.com>2025-10-24 20:18:39 +0100
commit34812c33dbfdac33093c84b3edf5076838cbf2a6 (patch)
tree8aa0ab0b23e6944175e9594ffe37e0a5d3ace1d0 /src/helpers
parent117e38db35a8bdd98f0210d41b83b4bb0e5e6a63 (diff)
hyprctl: include color management presets and sdr information (#12019)
* move string parsing for eCMType to its own namespace, similar to how `src/protocols/types/ContentType.cpp` is done * expose cm type and sdr settings in `hyprctl monitors`, format floats to .2f
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/CMType.cpp23
-rw-r--r--src/helpers/CMType.hpp20
-rw-r--r--src/helpers/Monitor.cpp26
-rw-r--r--src/helpers/Monitor.hpp19
4 files changed, 60 insertions, 28 deletions
diff --git a/src/helpers/CMType.cpp b/src/helpers/CMType.cpp
new file mode 100644
index 00000000..db2b7317
--- /dev/null
+++ b/src/helpers/CMType.cpp
@@ -0,0 +1,23 @@
+#include "CMType.hpp"
+#include <optional>
+#include <string>
+#include <unordered_map>
+
+static std::unordered_map<std::string, NCMType::eCMType> const table = {{"auto", NCMType::CM_AUTO}, {"srgb", NCMType::CM_SRGB}, {"wide", NCMType::CM_WIDE},
+ {"edid", NCMType::CM_EDID}, {"hdr", NCMType::CM_HDR}, {"hdredid", NCMType::CM_HDR_EDID},
+ {"dcip3", NCMType::CM_DCIP3}, {"dp3", NCMType::CM_DP3}, {"adobe", NCMType::CM_ADOBE}};
+
+std::optional<NCMType::eCMType> NCMType::fromString(const std::string cmType) {
+ auto it = table.find(cmType);
+ if (it == table.end())
+ return std::nullopt;
+ return it->second;
+}
+
+std::string NCMType::toString(eCMType cmType) {
+ for (const auto& [key, value] : table) {
+ if (value == cmType)
+ return key;
+ }
+ return "";
+}
diff --git a/src/helpers/CMType.hpp b/src/helpers/CMType.hpp
new file mode 100644
index 00000000..8802cca8
--- /dev/null
+++ b/src/helpers/CMType.hpp
@@ -0,0 +1,20 @@
+#include <cstdint>
+#include <string>
+#include <optional>
+
+namespace NCMType {
+ enum eCMType : uint8_t {
+ CM_AUTO = 0, // subject to change. srgb for 8bpc, wide for 10bpc if supported
+ CM_SRGB, // default, sRGB primaries
+ CM_WIDE, // wide color gamut, BT2020 primaries
+ CM_EDID, // primaries from edid (known to be inaccurate)
+ CM_HDR, // wide color gamut and HDR PQ transfer function
+ CM_HDR_EDID, // same as CM_HDR with edid primaries
+ CM_DCIP3, // movie theatre with greenish white point
+ CM_DP3, // applle P3 variant with blueish white point
+ CM_ADOBE, // adobe colorspace
+ };
+
+ std::optional<eCMType> fromString(const std::string cmType);
+ std::string toString(eCMType cmType);
+}
diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp
index 1bc1c0ba..1ec035fd 100644
--- a/src/helpers/Monitor.cpp
+++ b/src/helpers/Monitor.cpp
@@ -465,31 +465,31 @@ void CMonitor::onDisconnect(bool destroy) {
std::erase_if(g_pCompositor->m_monitors, [&](PHLMONITOR& el) { return el.get() == this; });
}
-void CMonitor::applyCMType(eCMType cmType) {
+void CMonitor::applyCMType(NCMType::eCMType cmType) {
auto oldImageDescription = m_imageDescription;
switch (cmType) {
- case CM_SRGB: m_imageDescription = {}; break; // assumes SImageDescirption defaults to sRGB
- case CM_WIDE:
+ case NCMType::CM_SRGB: m_imageDescription = {}; break; // assumes SImageDescirption defaults to sRGB
+ case NCMType::CM_WIDE:
m_imageDescription = {.primariesNameSet = true,
.primariesNamed = NColorManagement::CM_PRIMARIES_BT2020,
.primaries = NColorManagement::getPrimaries(NColorManagement::CM_PRIMARIES_BT2020)};
break;
- case CM_DCIP3:
+ case NCMType::CM_DCIP3:
m_imageDescription = {.primariesNameSet = true,
.primariesNamed = NColorManagement::CM_PRIMARIES_DCI_P3,
.primaries = NColorManagement::getPrimaries(NColorManagement::CM_PRIMARIES_DCI_P3)};
break;
- case CM_DP3:
+ case NCMType::CM_DP3:
m_imageDescription = {.primariesNameSet = true,
.primariesNamed = NColorManagement::CM_PRIMARIES_DISPLAY_P3,
.primaries = NColorManagement::getPrimaries(NColorManagement::CM_PRIMARIES_DISPLAY_P3)};
break;
- case CM_ADOBE:
+ case NCMType::CM_ADOBE:
m_imageDescription = {.primariesNameSet = true,
.primariesNamed = NColorManagement::CM_PRIMARIES_ADOBE_RGB,
.primaries = NColorManagement::getPrimaries(NColorManagement::CM_PRIMARIES_ADOBE_RGB)};
break;
- case CM_EDID:
+ case NCMType::CM_EDID:
m_imageDescription = {.primariesNameSet = false,
.primariesNamed = NColorManagement::CM_PRIMARIES_BT2020,
.primaries = {
@@ -499,14 +499,14 @@ void CMonitor::applyCMType(eCMType cmType) {
.white = {.x = m_output->parsedEDID.chromaticityCoords->white.x, .y = m_output->parsedEDID.chromaticityCoords->white.y},
}};
break;
- case CM_HDR:
+ case NCMType::CM_HDR:
m_imageDescription = {.transferFunction = NColorManagement::CM_TRANSFER_FUNCTION_ST2084_PQ,
.primariesNameSet = true,
.primariesNamed = NColorManagement::CM_PRIMARIES_BT2020,
.primaries = NColorManagement::getPrimaries(NColorManagement::CM_PRIMARIES_BT2020),
.luminances = {.min = 0, .max = 10000, .reference = 203}};
break;
- case CM_HDR_EDID:
+ case NCMType::CM_HDR_EDID:
m_imageDescription = {.transferFunction = NColorManagement::CM_TRANSFER_FUNCTION_ST2084_PQ,
.primariesNameSet = false,
.primariesNamed = NColorManagement::CM_PRIMARIES_BT2020,
@@ -861,10 +861,10 @@ bool CMonitor::applyMonitorRule(SMonitorRule* pMonitorRule, bool force) {
m_cmType = RULE->cmType;
switch (m_cmType) {
- case CM_AUTO: m_cmType = m_enabled10bit && supportsWideColor() ? CM_WIDE : CM_SRGB; break;
- case CM_EDID: m_cmType = m_output->parsedEDID.chromaticityCoords.has_value() ? CM_EDID : CM_SRGB; break;
- case CM_HDR:
- case CM_HDR_EDID: m_cmType = supportsHDR() ? m_cmType : CM_SRGB; break;
+ case NCMType::CM_AUTO: m_cmType = m_enabled10bit && supportsWideColor() ? NCMType::CM_WIDE : NCMType::CM_SRGB; break;
+ case NCMType::CM_EDID: m_cmType = m_output->parsedEDID.chromaticityCoords.has_value() ? NCMType::CM_EDID : NCMType::CM_SRGB; break;
+ case NCMType::CM_HDR:
+ case NCMType::CM_HDR_EDID: m_cmType = supportsHDR() ? m_cmType : NCMType::CM_SRGB; break;
default: break;
}
diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp
index d112f747..687fc049 100644
--- a/src/helpers/Monitor.hpp
+++ b/src/helpers/Monitor.hpp
@@ -8,6 +8,7 @@
#include "WLClasses.hpp"
#include <array>
#include "AnimatedVariable.hpp"
+#include "CMType.hpp"
#include <xf86drmMode.h>
#include "time/Timer.hpp"
@@ -35,18 +36,6 @@ enum eAutoDirs : uint8_t {
DIR_AUTO_CENTER_RIGHT
};
-enum eCMType : uint8_t {
- CM_AUTO = 0, // subject to change. srgb for 8bpc, wide for 10bpc if supported
- CM_SRGB, // default, sRGB primaries
- CM_WIDE, // wide color gamut, BT2020 primaries
- CM_EDID, // primaries from edid (known to be inaccurate)
- CM_HDR, // wide color gamut and HDR PQ transfer function
- CM_HDR_EDID, // same as CM_HDR with edid primaries
- CM_DCIP3, // movie theatre with greenish white point
- CM_DP3, // applle P3 variant with blueish white point
- CM_ADOBE, // adobe colorspace
-};
-
struct SMonitorRule {
eAutoDirs autoDir = DIR_AUTO_NONE;
std::string name = "";
@@ -58,7 +47,7 @@ struct SMonitorRule {
wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
std::string mirrorOf = "";
bool enable10bit = false;
- eCMType cmType = CM_SRGB;
+ NCMType::eCMType cmType = NCMType::CM_SRGB;
float sdrSaturation = 1.0f; // SDR -> HDR
float sdrBrightness = 1.0f; // SDR -> HDR
@@ -141,7 +130,7 @@ class CMonitor {
bool m_dpmsStatus = true;
bool m_vrrActive = false; // this can be TRUE even if VRR is not active in the case that this display does not support it.
bool m_enabled10bit = false; // as above, this can be TRUE even if 10 bit failed.
- eCMType m_cmType = CM_SRGB;
+ NCMType::eCMType m_cmType = NCMType::CM_SRGB;
float m_sdrSaturation = 1.0f;
float m_sdrBrightness = 1.0f;
float m_sdrMinLuminance = 0.2f;
@@ -283,7 +272,7 @@ class CMonitor {
// methods
void onConnect(bool noRule);
void onDisconnect(bool destroy = false);
- void applyCMType(eCMType cmType);
+ void applyCMType(NCMType::eCMType cmType);
bool applyMonitorRule(SMonitorRule* pMonitorRule, bool force = false);
void addDamage(const pixman_region32_t* rg);
void addDamage(const CRegion& rg);