fix: upower module selection with multiple devices

While looping over all the upower devices, the currently set device that will be rendered in the waybar, is overridden. Since the loop doesn't end when the device is found, the upDevice_ is overridden with NULL in the iteration for the next device.

Now we only override upDevice_ if the current device matches the constraints.

Fixes d2a719d67c ("Redo to minimize code duplication.")
Fixes #3267
This commit is contained in:
Leonard Cohnen 2024-08-31 20:33:52 +02:00
parent 5d184f74d8
commit 9b5c2dc7ed
1 changed files with 5 additions and 4 deletions

View File

@ -384,10 +384,11 @@ void UPower::setDisplayDevice() {
displayDevice = upDevice; displayDevice = upDevice;
} }
} }
// Unref current upDevice // Unref current upDevice if it exists
if (displayDevice.upDevice != NULL) g_object_unref(thisPtr->upDevice_.upDevice); if (displayDevice.upDevice != NULL) {
// Reassign new upDevice if (thisPtr->upDevice_.upDevice != NULL) g_object_unref(thisPtr->upDevice_.upDevice);
thisPtr->upDevice_ = displayDevice; thisPtr->upDevice_ = displayDevice;
}
}, },
this); this);
} }