diff --git a/src/logid/backend/hidpp/Device.cpp b/src/logid/backend/hidpp/Device.cpp index ef46cd0..31c4d47 100644 --- a/src/logid/backend/hidpp/Device.cpp +++ b/src/logid/backend/hidpp/Device.cpp @@ -302,12 +302,12 @@ void Device::sendReportNoACK(const Report& report) { void Device::reportFixup(Report& report) const { switch (report.type()) { case Report::Type::Short: - if (!(supported_reports & HIDPP_REPORT_SHORT_SUPPORTED)) + if (!(supported_reports & ShortReportSupported)) report.setType(Report::Type::Long); break; case Report::Type::Long: /* Report can be truncated, but that isn't a good idea. */ - assert(supported_reports & HIDPP_REPORT_LONG_SUPPORTED); + assert(supported_reports & LongReportSupported); } } diff --git a/src/logid/backend/hidpp/Report.cpp b/src/logid/backend/hidpp/Report.cpp index d1606ee..68797e5 100644 --- a/src/logid/backend/hidpp/Report.cpp +++ b/src/logid/backend/hidpp/Report.cpp @@ -93,7 +93,7 @@ uint8_t hidpp::getSupportedReports(const std::vector& report_desc) { it = std::search(report_desc.begin(), report_desc.end(), ShortReportDesc2.begin(), ShortReportDesc2.end()); if (it != report_desc.end()) - ret |= HIDPP_REPORT_SHORT_SUPPORTED; + ret |= ShortReportSupported; it = std::search(report_desc.begin(), report_desc.end(), LongReportDesc.begin(), LongReportDesc.end()); @@ -101,7 +101,7 @@ uint8_t hidpp::getSupportedReports(const std::vector& report_desc) { it = std::search(report_desc.begin(), report_desc.end(), LongReportDesc2.begin(), LongReportDesc2.end()); if (it != report_desc.end()) - ret |= HIDPP_REPORT_LONG_SUPPORTED; + ret |= LongReportSupported; return ret; } diff --git a/src/logid/backend/hidpp/Report.h b/src/logid/backend/hidpp/Report.h index 38f155e..2c8e587 100644 --- a/src/logid/backend/hidpp/Report.h +++ b/src/logid/backend/hidpp/Report.h @@ -23,14 +23,14 @@ #include #include -/* Some devices only support a subset of these reports */ -#define HIDPP_REPORT_SHORT_SUPPORTED 1U -#define HIDPP_REPORT_LONG_SUPPORTED 1U<<1U -/* Very long reports exist, however they have not been encountered so far */ - namespace logid::backend::hidpp { uint8_t getSupportedReports(const std::vector& report_desc); + /* Some devices only support a subset of these reports */ + static constexpr uint8_t ShortReportSupported = 1U; + static constexpr uint8_t LongReportSupported = (1U<<1); + /* Very long reports exist, however they have not been encountered so far */ + namespace Offset { static constexpr uint8_t Type = 0; static constexpr uint8_t DeviceIndex = 1; diff --git a/src/logid/features/RemapButton.cpp b/src/logid/features/RemapButton.cpp index 9fa0cb7..9a52d78 100644 --- a/src/logid/features/RemapButton.cpp +++ b/src/logid/features/RemapButton.cpp @@ -25,8 +25,13 @@ using namespace logid::features; using namespace logid::backend; using namespace logid::actions; -#define HIDPP20_REPROG_REBIND (hidpp20::ReprogControls::ChangeTemporaryDivert \ -| hidpp20::ReprogControls::ChangeRawXYDivert) +#define REPROG_FLAG(x) (control.second.flags & hidpp20::ReprogControls::x ? "YES" : "") +#define REPROG_FLAG_ADDITIONAL(x) (control.second.additionalFlags & \ + hidpp20::ReprogControls::x ? "YES" : "") + +static constexpr auto hidpp20_reprog_rebind = + (hidpp20::ReprogControls::ChangeTemporaryDivert | + hidpp20::ReprogControls::ChangeRawXYDivert); RemapButton::RemapButton(Device* dev) : DeviceFeature(dev), _config(dev->activeProfile().buttons), @@ -49,7 +54,7 @@ RemapButton::RemapButton(Device* dev) : DeviceFeature(dev), const std::shared_ptr& action) { hidpp20::ReprogControls::ControlInfo report{}; report.controlID = info.controlID; - report.flags = HIDPP20_REPROG_REBIND; + report.flags = hidpp20_reprog_rebind; if (action) { if ((action->reprogFlags() & @@ -72,11 +77,6 @@ RemapButton::RemapButton(Device* dev) : DeviceFeature(dev), _ipc_interface = _device->ipcNode()->make_interface(this); if (global_loglevel <= DEBUG) { -#define FLAG(x) (control.second.flags & hidpp20::ReprogControls::x ? \ - "YES" : "") -#define ADDITIONAL_FLAG(x) (control.second.additionalFlags & \ - hidpp20::ReprogControls::x ? "YES" : "") - // Print CIDs, originally by zv0n logPrintf(DEBUG, "%s:%d remappable buttons:", dev->hidpp20().devicePath().c_str(), @@ -85,10 +85,8 @@ RemapButton::RemapButton(Device* dev) : DeviceFeature(dev), "gesture support?"); for (const auto& control: _reprog_controls->getControls()) logPrintf(DEBUG, "0x%02x | %-7s | %-7s | %-10s | %s", - control.first, FLAG(TemporaryDivertable), FLAG(FKey), - FLAG(MouseButton), ADDITIONAL_FLAG(RawXY)); -#undef ADDITIONAL_FLAG -#undef FLAG + control.first, REPROG_FLAG(TemporaryDivertable), REPROG_FLAG(FKey), + REPROG_FLAG(MouseButton), REPROG_FLAG_ADDITIONAL(RawXY)); } } diff --git a/src/logid/features/ThumbWheel.cpp b/src/logid/features/ThumbWheel.cpp index d49b2ea..d945034 100644 --- a/src/logid/features/ThumbWheel.cpp +++ b/src/logid/features/ThumbWheel.cpp @@ -25,8 +25,7 @@ using namespace logid::features; using namespace logid::backend; using namespace logid; -#define FLAG_STR(b) (_wheel_info.capabilities & _thumb_wheel->b ? "YES" : \ - "NO") +#define FLAG_STR(b) (_wheel_info.capabilities & _thumb_wheel->b ? "YES" : "NO") namespace { std::shared_ptr _genAction( diff --git a/src/logid/logid.cpp b/src/logid/logid.cpp index c1b454b..efa9a9c 100644 --- a/src/logid/logid.cpp +++ b/src/logid/logid.cpp @@ -21,18 +21,18 @@ #include #include -#define LOGID_VIRTUAL_INPUT_NAME "LogiOps Virtual Input" -#define DEFAULT_CONFIG_FILE "/etc/logid.cfg" - #ifndef LOGIOPS_VERSION #define LOGIOPS_VERSION "null" #warning Version is undefined! #endif +static constexpr auto virtual_input_name = "LogiOps Virtual Input"; +static constexpr auto default_config = "/etc/logid.cfg"; + using namespace logid; struct CmdlineOptions { - std::string config_file = DEFAULT_CONFIG_FILE; + std::string config_file = default_config; }; LogLevel logid::global_loglevel = INFO; @@ -115,7 +115,7 @@ Possible options are: -V,--version Print version number -c,--config [file path] Change config file from default at %s -h,--help Print this message. -)", LOGIOPS_VERSION, argv[0], DEFAULT_CONFIG_FILE); +)", LOGIOPS_VERSION, argv[0], default_config); exit(EXIT_SUCCESS); case Option::Version: printf("%s\n", LOGIOPS_VERSION); @@ -147,7 +147,7 @@ int main(int argc, char** argv) { //Create a virtual input device try { - virtual_input = std::make_unique(LOGID_VIRTUAL_INPUT_NAME); + virtual_input = std::make_unique(virtual_input_name); } catch (std::system_error& e) { logPrintf(ERROR, "Could not create input device: %s", e.what()); return EXIT_FAILURE;