chore: upgrade to clang-format@21
This commit is contained in:
@@ -14,10 +14,10 @@ namespace {
|
||||
class FileDescriptor {
|
||||
public:
|
||||
explicit FileDescriptor(int fd) : fd_(fd) {}
|
||||
FileDescriptor(const FileDescriptor &other) = delete;
|
||||
FileDescriptor(FileDescriptor &&other) noexcept = delete;
|
||||
FileDescriptor &operator=(const FileDescriptor &other) = delete;
|
||||
FileDescriptor &operator=(FileDescriptor &&other) noexcept = delete;
|
||||
FileDescriptor(const FileDescriptor& other) = delete;
|
||||
FileDescriptor(FileDescriptor&& other) noexcept = delete;
|
||||
FileDescriptor& operator=(const FileDescriptor& other) = delete;
|
||||
FileDescriptor& operator=(FileDescriptor&& other) noexcept = delete;
|
||||
~FileDescriptor() {
|
||||
if (fd_ != -1) {
|
||||
if (close(fd_) != 0) {
|
||||
@@ -31,27 +31,27 @@ class FileDescriptor {
|
||||
int fd_;
|
||||
};
|
||||
|
||||
void check_eq(int rc, int expected, const char *message = "eq, rc was: ") {
|
||||
void check_eq(int rc, int expected, const char* message = "eq, rc was: ") {
|
||||
if (rc != expected) {
|
||||
throw std::runtime_error(fmt::format(fmt::runtime(message), rc));
|
||||
}
|
||||
}
|
||||
|
||||
void check_neq(int rc, int bad_rc, const char *message = "neq, rc was: ") {
|
||||
void check_neq(int rc, int bad_rc, const char* message = "neq, rc was: ") {
|
||||
if (rc == bad_rc) {
|
||||
throw std::runtime_error(fmt::format(fmt::runtime(message), rc));
|
||||
}
|
||||
}
|
||||
|
||||
void check0(int rc, const char *message = "rc wasn't 0") { check_eq(rc, 0, message); }
|
||||
void check0(int rc, const char* message = "rc wasn't 0") { check_eq(rc, 0, message); }
|
||||
|
||||
void check_gte(int rc, int gte, const char *message = "rc was: ") {
|
||||
void check_gte(int rc, int gte, const char* message = "rc was: ") {
|
||||
if (rc < gte) {
|
||||
throw std::runtime_error(fmt::format(fmt::runtime(message), rc));
|
||||
}
|
||||
}
|
||||
|
||||
void check_nn(const void *ptr, const char *message = "ptr was null") {
|
||||
void check_nn(const void* ptr, const char* message = "ptr was null") {
|
||||
if (ptr == nullptr) {
|
||||
throw std::runtime_error(message);
|
||||
}
|
||||
@@ -61,20 +61,20 @@ void check_nn(const void *ptr, const char *message = "ptr was null") {
|
||||
|
||||
namespace waybar::util {
|
||||
|
||||
static void upsert_device(std::vector<BacklightDevice> &devices, udev_device *dev) {
|
||||
const char *name = udev_device_get_sysname(dev);
|
||||
static void upsert_device(std::vector<BacklightDevice>& devices, udev_device* dev) {
|
||||
const char* name = udev_device_get_sysname(dev);
|
||||
check_nn(name);
|
||||
|
||||
const char *actual_brightness_attr =
|
||||
const char* actual_brightness_attr =
|
||||
strncmp(name, "amdgpu_bl", 9) == 0 || strcmp(name, "apple-panel-bl") == 0
|
||||
? "brightness"
|
||||
: "actual_brightness";
|
||||
|
||||
const char *actual = udev_device_get_sysattr_value(dev, actual_brightness_attr);
|
||||
const char *max = udev_device_get_sysattr_value(dev, "max_brightness");
|
||||
const char *power = udev_device_get_sysattr_value(dev, "bl_power");
|
||||
const char* actual = udev_device_get_sysattr_value(dev, actual_brightness_attr);
|
||||
const char* max = udev_device_get_sysattr_value(dev, "max_brightness");
|
||||
const char* power = udev_device_get_sysattr_value(dev, "bl_power");
|
||||
|
||||
auto found = std::find_if(devices.begin(), devices.end(), [name](const BacklightDevice &device) {
|
||||
auto found = std::find_if(devices.begin(), devices.end(), [name](const BacklightDevice& device) {
|
||||
return device.name() == name;
|
||||
});
|
||||
if (found != devices.end()) {
|
||||
@@ -95,14 +95,14 @@ static void upsert_device(std::vector<BacklightDevice> &devices, udev_device *de
|
||||
}
|
||||
}
|
||||
|
||||
static void enumerate_devices(std::vector<BacklightDevice> &devices, udev *udev) {
|
||||
static void enumerate_devices(std::vector<BacklightDevice>& devices, udev* udev) {
|
||||
std::unique_ptr<udev_enumerate, UdevEnumerateDeleter> enumerate{udev_enumerate_new(udev)};
|
||||
udev_enumerate_add_match_subsystem(enumerate.get(), "backlight");
|
||||
udev_enumerate_scan_devices(enumerate.get());
|
||||
udev_list_entry *enum_devices = udev_enumerate_get_list_entry(enumerate.get());
|
||||
udev_list_entry *dev_list_entry;
|
||||
udev_list_entry* enum_devices = udev_enumerate_get_list_entry(enumerate.get());
|
||||
udev_list_entry* dev_list_entry;
|
||||
udev_list_entry_foreach(dev_list_entry, enum_devices) {
|
||||
const char *path = udev_list_entry_get_name(dev_list_entry);
|
||||
const char* path = udev_list_entry_get_name(dev_list_entry);
|
||||
std::unique_ptr<udev_device, UdevDeviceDeleter> dev{udev_device_new_from_syspath(udev, path)};
|
||||
check_nn(dev.get(), "dev new failed");
|
||||
upsert_device(devices, dev.get());
|
||||
@@ -184,7 +184,7 @@ BacklightBackend::BacklightBackend(std::chrono::milliseconds interval,
|
||||
devices = devices_;
|
||||
}
|
||||
for (int i = 0; i < event_count; ++i) {
|
||||
const auto &event = events[i];
|
||||
const auto& event = events[i];
|
||||
check_eq(event.data.fd, udev_fd, "unexpected udev fd");
|
||||
std::unique_ptr<udev_device, UdevDeviceDeleter> dev{udev_monitor_receive_device(mon.get())};
|
||||
if (!dev) {
|
||||
@@ -206,27 +206,27 @@ BacklightBackend::BacklightBackend(std::chrono::milliseconds interval,
|
||||
};
|
||||
}
|
||||
|
||||
const BacklightDevice *BacklightBackend::best_device(const std::vector<BacklightDevice> &devices,
|
||||
const BacklightDevice* BacklightBackend::best_device(const std::vector<BacklightDevice>& devices,
|
||||
std::string_view preferred_device) {
|
||||
const auto found = std::find_if(
|
||||
devices.begin(), devices.end(),
|
||||
[preferred_device](const BacklightDevice &dev) { return dev.name() == preferred_device; });
|
||||
[preferred_device](const BacklightDevice& dev) { return dev.name() == preferred_device; });
|
||||
if (found != devices.end()) {
|
||||
return &(*found);
|
||||
}
|
||||
|
||||
const auto max = std::max_element(
|
||||
devices.begin(), devices.end(),
|
||||
[](const BacklightDevice &l, const BacklightDevice &r) { return l.get_max() < r.get_max(); });
|
||||
[](const BacklightDevice& l, const BacklightDevice& r) { return l.get_max() < r.get_max(); });
|
||||
|
||||
return max == devices.end() ? nullptr : &(*max);
|
||||
}
|
||||
|
||||
const BacklightDevice *BacklightBackend::get_previous_best_device() {
|
||||
const BacklightDevice* BacklightBackend::get_previous_best_device() {
|
||||
return previous_best_.has_value() ? &(*previous_best_) : nullptr;
|
||||
}
|
||||
|
||||
void BacklightBackend::set_previous_best_device(const BacklightDevice *device) {
|
||||
void BacklightBackend::set_previous_best_device(const BacklightDevice* device) {
|
||||
if (device == nullptr) {
|
||||
previous_best_ = std::nullopt;
|
||||
} else {
|
||||
@@ -234,7 +234,7 @@ void BacklightBackend::set_previous_best_device(const BacklightDevice *device) {
|
||||
}
|
||||
}
|
||||
|
||||
void BacklightBackend::set_scaled_brightness(const std::string &preferred_device, int brightness) {
|
||||
void BacklightBackend::set_scaled_brightness(const std::string& preferred_device, int brightness) {
|
||||
GET_BEST_DEVICE(best, (*this), preferred_device);
|
||||
|
||||
if (best != nullptr) {
|
||||
@@ -244,7 +244,7 @@ void BacklightBackend::set_scaled_brightness(const std::string &preferred_device
|
||||
}
|
||||
}
|
||||
|
||||
void BacklightBackend::set_brightness(const std::string &preferred_device, ChangeType change_type,
|
||||
void BacklightBackend::set_brightness(const std::string& preferred_device, ChangeType change_type,
|
||||
double step) {
|
||||
GET_BEST_DEVICE(best, (*this), preferred_device);
|
||||
|
||||
@@ -259,7 +259,7 @@ void BacklightBackend::set_brightness(const std::string &preferred_device, Chang
|
||||
}
|
||||
}
|
||||
|
||||
void BacklightBackend::set_brightness_internal(const std::string &device_name, int brightness,
|
||||
void BacklightBackend::set_brightness_internal(const std::string& device_name, int brightness,
|
||||
int max_brightness) {
|
||||
brightness = std::clamp(brightness, 0, max_brightness);
|
||||
|
||||
@@ -269,7 +269,7 @@ void BacklightBackend::set_brightness_internal(const std::string &device_name, i
|
||||
login_proxy_->call_sync("SetBrightness", call_args);
|
||||
}
|
||||
|
||||
int BacklightBackend::get_scaled_brightness(const std::string &preferred_device) {
|
||||
int BacklightBackend::get_scaled_brightness(const std::string& preferred_device) {
|
||||
GET_BEST_DEVICE(best, (*this), preferred_device);
|
||||
|
||||
if (best != nullptr) {
|
||||
|
||||
Reference in New Issue
Block a user