Skip to content

Commit d922726

Browse files
committed
fix fallback + add trying requested as custom fallback
1 parent 39444a9 commit d922726

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/helpers/Monitor.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ bool CMonitor::applyMonitorRule(SMonitorRule* pMonitorRule, bool force) {
440440
// () use preferred mode, which is already last fallback
441441
// (-1,-1) preference to refreshrate over resolution
442442
// (-1,-2) preference to resolution
443-
// otherwise its a user provided mode
443+
// otherwise its a user requested mode
444444
if (RULE->resolution == Vector2D(-1, -1)) {
445445
for (auto const& mode : output->modes) {
446446
if ((mode->pixelSize.x >= currentWidth && mode->pixelSize.y >= currentHeight && mode->refreshRate >= (currentRefresh - 1000.f)) ||
@@ -456,10 +456,6 @@ bool CMonitor::applyMonitorRule(SMonitorRule* pMonitorRule, bool force) {
456456
}
457457
}
458458
} else if (RULE->resolution != Vector2D()) {
459-
// user requested a mode
460-
// try it regardless as custom if the next ones dont work
461-
requestedModes.push_back(makeShared<Aquamarine::SOutputMode>(Aquamarine::SOutputMode{.pixelSize = RULE->resolution, .refreshRate = WLRREFRESHRATE}));
462-
463459
// try any supported modes that are close first
464460
for (auto const& mode : output->modes) {
465461
// if delta of refresh rate, w and h chosen and mode is < 1 we accept it
@@ -494,8 +490,6 @@ bool CMonitor::applyMonitorRule(SMonitorRule* pMonitorRule, bool force) {
494490

495491
for (auto const& mode : requestedModes | std::views::reverse) {
496492
if (mode->modeInfo.has_value() && mode->modeInfo->type == DRM_MODE_TYPE_USERDEF) {
497-
// TODO: this ignores when requested mode is used as a custom mode as a fallback, since theres no modeinfo
498-
// maybe just add a custom flag
499493
output->state->setCustomMode(mode);
500494

501495
if (!state.test()) {
@@ -536,6 +530,27 @@ bool CMonitor::applyMonitorRule(SMonitorRule* pMonitorRule, bool force) {
536530
break;
537531
}
538532

533+
if (!success && RULE->resolution != Vector2D() && RULE->resolution != Vector2D(-1, -1) && RULE->resolution != Vector2D(-1, -2)) {
534+
// try requested as custom regardless
535+
auto mode = makeShared<Aquamarine::SOutputMode>(Aquamarine::SOutputMode{.pixelSize = RULE->resolution, .refreshRate = WLRREFRESHRATE});
536+
537+
output->state->setCustomMode(mode);
538+
539+
if (!state.test()) {
540+
Debug::log(ERR, "Monitor {}: REJECTED custom mode {:X0}@{:.2f}Hz!", szName, mode->pixelSize, mode->refreshRate / 1000.f);
541+
} else {
542+
Debug::log(LOG, "Monitor {}: requested {:X0}@{:.2f}Hz, using custom mode {:X0}@{:.2f}Hz", szName, RULE->resolution, RULE->refreshRate, mode->pixelSize,
543+
mode->refreshRate / 1000.f);
544+
545+
refreshRate = mode->refreshRate / 1000.f;
546+
vecSize = mode->pixelSize;
547+
currentMode = mode;
548+
customDrmMode = {};
549+
550+
success = true;
551+
}
552+
}
553+
539554
// try any the modes if none of the above work
540555
if (!success) {
541556
for (auto const& mode : output->modes) {
@@ -549,6 +564,11 @@ bool CMonitor::applyMonitorRule(SMonitorRule* pMonitorRule, bool force) {
549564
Debug::log(WARN, errorMessage);
550565
g_pHyprNotificationOverlay->addNotification(errorMessage, CHyprColor(0xff0000ff), 5000, ICON_WARNING);
551566

567+
refreshRate = mode->refreshRate / 1000.f;
568+
vecSize = mode->pixelSize;
569+
currentMode = mode;
570+
customDrmMode = {};
571+
552572
success = true;
553573

554574
break;

0 commit comments

Comments
 (0)