workspace: unset brightness devices on outputs that didn't get one assigned

Otherwise, two outputs might end up having the same brightness device
This commit is contained in:
Xaver Hugl 2024-08-10 15:42:43 +02:00
parent fdff6588c6
commit b325555e18
2 changed files with 19 additions and 15 deletions

View file

@ -792,16 +792,7 @@ BrightnessDevice *Output::brightnessDevice() const
void Output::setBrightnessDevice(BrightnessDevice *device)
{
if (m_brightnessDevice == device) {
return;
}
if (m_brightnessDevice) {
m_brightnessDevice->setOutput(nullptr);
}
m_brightnessDevice = device;
if (device) {
device->setOutput(this);
}
}
} // namespace KWin

View file

@ -1368,17 +1368,30 @@ void Workspace::assignBrightnessDevices()
const auto devices = waylandServer()->externalBrightness()->devices();
for (BrightnessDevice *device : devices) {
// assign the device to the most fitting output
for (auto it = candidates.begin(); it != candidates.end(); it++) {
Output *output = *it;
const auto it = std::ranges::find_if(candidates, [device](Output *output) {
if (output->isInternal() != device->isInternal()) {
continue;
return false;
}
if (!output->isInternal() && (!output->edid().isValid() || device->edidBeginning().isEmpty() || !output->edid().raw().startsWith(device->edidBeginning()))) {
continue;
if (output->isInternal()) {
return true;
} else {
return output->edid().isValid() && !device->edidBeginning().isEmpty() && output->edid().raw().startsWith(device->edidBeginning());
}
});
Output *const oldOutput = device->output();
if (it != candidates.end()) {
Output *const output = *it;
if (oldOutput && oldOutput != output) {
oldOutput->setBrightnessDevice(nullptr);
}
output->setBrightnessDevice(device);
device->setOutput(output);
candidates.erase(it);
break;
} else if (oldOutput) {
device->setOutput(nullptr);
if (oldOutput->brightnessDevice() == device) {
oldOutput->setBrightnessDevice(nullptr);
}
}
}
}