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:
parent
fdff6588c6
commit
b325555e18
2 changed files with 19 additions and 15 deletions
|
@ -792,16 +792,7 @@ BrightnessDevice *Output::brightnessDevice() const
|
||||||
|
|
||||||
void Output::setBrightnessDevice(BrightnessDevice *device)
|
void Output::setBrightnessDevice(BrightnessDevice *device)
|
||||||
{
|
{
|
||||||
if (m_brightnessDevice == device) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (m_brightnessDevice) {
|
|
||||||
m_brightnessDevice->setOutput(nullptr);
|
|
||||||
}
|
|
||||||
m_brightnessDevice = device;
|
m_brightnessDevice = device;
|
||||||
if (device) {
|
|
||||||
device->setOutput(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} // namespace KWin
|
} // namespace KWin
|
||||||
|
|
||||||
|
|
|
@ -1368,17 +1368,30 @@ void Workspace::assignBrightnessDevices()
|
||||||
const auto devices = waylandServer()->externalBrightness()->devices();
|
const auto devices = waylandServer()->externalBrightness()->devices();
|
||||||
for (BrightnessDevice *device : devices) {
|
for (BrightnessDevice *device : devices) {
|
||||||
// assign the device to the most fitting output
|
// assign the device to the most fitting output
|
||||||
for (auto it = candidates.begin(); it != candidates.end(); it++) {
|
const auto it = std::ranges::find_if(candidates, [device](Output *output) {
|
||||||
Output *output = *it;
|
|
||||||
if (output->isInternal() != device->isInternal()) {
|
if (output->isInternal() != device->isInternal()) {
|
||||||
continue;
|
return false;
|
||||||
}
|
}
|
||||||
if (!output->isInternal() && (!output->edid().isValid() || device->edidBeginning().isEmpty() || !output->edid().raw().startsWith(device->edidBeginning()))) {
|
if (output->isInternal()) {
|
||||||
continue;
|
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);
|
output->setBrightnessDevice(device);
|
||||||
|
device->setOutput(output);
|
||||||
candidates.erase(it);
|
candidates.erase(it);
|
||||||
break;
|
} else if (oldOutput) {
|
||||||
|
device->setOutput(nullptr);
|
||||||
|
if (oldOutput->brightnessDevice() == device) {
|
||||||
|
oldOutput->setBrightnessDevice(nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue