mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-09-12 21:28:30 -04:00
Add framework for registering custom udev rules
This commit is contained in:
1 parent
33854f8886
commit
c5befc354b
6 files changed
+69
-1
No files matched your search
@@ -36,3 +36,5 @@ DetectedControllers DetectAsusTUFLaptopLinuxControllers()
|
||||
}
|
||||
|
||||
REGISTER_DETECTOR("ASUS TUF Laptop", DetectAsusTUFLaptopLinuxControllers);
|
||||
|
||||
REGISTER_CUSTOM_UDEV_RULE(asus_wmi, "ASUS TUF Laptops (asus-wmi)", "ACTION==\"add\", SUBSYSTEM==\"leds\", KERNEL==\"asus::kbd_backlight\", RUN+=\"/usr/bin/env chmod a+w /sys%p/kbd_rgb_mode\"\nACTION==\"add\", SUBSYSTEM==\"leds\", KERNEL==\"asus::kbd_backlight\", RUN+=\"/usr/bin/env chmod a+w /sys%p/brightness\"");
|
||||
@@ -197,3 +197,5 @@ DetectedControllers DetectFaustusControllers()
|
||||
}
|
||||
|
||||
REGISTER_DETECTOR("Faustus", DetectFaustusControllers);
|
||||
|
||||
REGISTER_CUSTOM_UDEV_RULE(faustus, "ASUS TUF Laptops (faustus)", "ACTION==\"add\", SUBSYSTEM==\"platform\", KERNEL==\"faustus\", RUN+=\"/usr/bin/env chmod a+w /sys/bus/platform/devices/%k/kbbl/kbbl_blue\"\nACTION==\"add\", SUBSYSTEM==\"platform\", KERNEL==\"faustus\", RUN+=\"/usr/bin/env chmod a+w /sys/bus/platform/devices/%k/kbbl/kbbl_flags\"\nACTION==\"add\", SUBSYSTEM==\"platform\", KERNEL==\"faustus\", RUN+=\"/usr/bin/env chmod a+w /sys/bus/platform/devices/%k/kbbl/kbbl_green\"\nACTION==\"add\", SUBSYSTEM==\"platform\", KERNEL==\"faustus\", RUN+=\"/usr/bin/env chmod a+w /sys/bus/platform/devices/%k/kbbl/kbbl_mode\"\nACTION==\"add\", SUBSYSTEM==\"platform\", KERNEL==\"faustus\", RUN+=\"/usr/bin/env chmod a+w /sys/bus/platform/devices/%k/kbbl/kbbl_red\"\nACTION==\"add\", SUBSYSTEM==\"platform\", KERNEL==\"faustus\", RUN+=\"/usr/bin/env chmod a+w /sys/bus/platform/devices/%k/kbbl/kbbl_set\"\nACTION==\"add\", SUBSYSTEM==\"platform\", KERNEL==\"faustus\", RUN+=\"/usr/bin/env chmod a+w /sys/bus/platform/devices/%k/kbbl/kbbl_speed\"");
|
||||
@@ -1711,6 +1711,8 @@ REGISTER_HID_DETECTOR_P_ONLY ("Logitech HID++ 2.0", DetectLogitechHIDPP20, 0xFF
|
||||
REGISTER_HID_DETECTOR_IP_ONLY ("Logitech HID++ 2.0", DetectLogitechHIDPP20, 1, 0xFF00);
|
||||
REGISTER_HID_DETECTOR_PU_ONLY ("Logitech HID++ 2.0", DetectLogitechHIDPP20, 0xFFA0, 1);
|
||||
|
||||
REGISTER_CUSTOM_UDEV_RULE(logitech_hidpp20, "Logitech HID++ 2.0", "SUBSYSTEM==\"hidraw\", ATTRS{idVendor}==\"046d\", TAG+=\"uaccess\", TAG+=\"Logitech_HID_20\"\nSUBSYSTEM==\"usb\", ATTR{idVendor}==\"046d\", TAG+=\"uaccess\", TAG+=\"Logitech_HID_20\"");
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------------------------------------------------------*\
|
||||
| Keyboards |
|
||||
\*-------------------------------------------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
@@ -139,4 +139,6 @@ DetectedControllers DetectValveSteamMachineControllers()
|
||||
return(detected_controllers);
|
||||
}
|
||||
|
||||
REGISTER_DETECTOR("Valve Steam Machine", DetectValveSteamMachineControllers);
|
||||
REGISTER_DETECTOR("Valve Steam Machine", DetectValveSteamMachineControllers);
|
||||
|
||||
REGISTER_CUSTOM_UDEV_RULE(valve_steam, "Valve Steam Machine", "SUBSYSTEM==\"leds\", KERNEL==\"valve-leds[0-9]*\", TAG+=\"uaccess\"");
|
||||
@@ -350,6 +350,21 @@ void DetectionManager::RegisterPreDetectionHook(PreDetectionHookFunction hook)
|
||||
pre_detection_hooks.push_back(hook);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
/*---------------------------------------------------------*\
|
||||
| Custom Udev Rules Registration Function |
|
||||
\*---------------------------------------------------------*/
|
||||
void DetectionManager::RegisterCustomUdevRule(std::string name, std::string rule)
|
||||
{
|
||||
CustomUdevRuleBlock block;
|
||||
|
||||
block.name = name;
|
||||
block.rule = rule;
|
||||
|
||||
custom_udev_rules.push_back(block);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Detection Callback Registration Functions |
|
||||
\*---------------------------------------------------------*/
|
||||
@@ -2168,6 +2183,18 @@ bool DetectionManager::GenerateUdevRules(const std::string& filepath)
|
||||
fprintf(output_file, "\n");
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Write custom udev rules |
|
||||
\*-----------------------------------------------------*/
|
||||
for(const CustomUdevRuleBlock& custom_rule : custom_udev_rules)
|
||||
{
|
||||
fprintf(output_file, "#---------------------------------------------------------------#\n");
|
||||
fprintf(output_file, "# %s\n", custom_rule.name.c_str());
|
||||
fprintf(output_file, "#---------------------------------------------------------------#\n");
|
||||
fprintf(output_file, "%s\n", custom_rule.rule.c_str());
|
||||
fprintf(output_file, "\n");
|
||||
}
|
||||
|
||||
fclose(output_file);
|
||||
|
||||
LOG_INFO("[%s] Successfully generated udev rules file: %s", DETECTIONMANAGER, filepath.c_str());
|
||||
|
||||
@@ -105,6 +105,12 @@ typedef struct
|
||||
uint8_t dram_type;
|
||||
} I2CDRAMDeviceDetectorBlock;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
std::string name;
|
||||
std::string rule;
|
||||
} CustomUdevRuleBlock;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Detection Callback Type |
|
||||
\*---------------------------------------------------------*/
|
||||
@@ -177,6 +183,13 @@ public:
|
||||
\*-----------------------------------------------------*/
|
||||
void RegisterPreDetectionHook(PreDetectionHookFunction hook);
|
||||
|
||||
#ifdef __linux__
|
||||
/*-----------------------------------------------------*\
|
||||
| Custom Udev Rules Registration Function |
|
||||
*------------------------------------------------------*/
|
||||
void RegisterCustomUdevRule(std::string name, std::string rule);
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Detection Callback Registration Functions |
|
||||
\*-----------------------------------------------------*/
|
||||
@@ -248,6 +261,10 @@ private:
|
||||
std::vector<std::string> dynamic_detector_strings;
|
||||
std::vector<PreDetectionHookFunction> pre_detection_hooks;
|
||||
|
||||
#ifdef __linux__
|
||||
std::vector<CustomUdevRuleBlock> custom_udev_rules;
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
#ifdef __GLIBC__
|
||||
/*-----------------------------------------------------*\
|
||||
@@ -459,6 +476,20 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class CustomUdevRule
|
||||
{
|
||||
public:
|
||||
CustomUdevRule(std::string name, std::string rule)
|
||||
{
|
||||
#ifdef __linux__
|
||||
DetectionManager::get()->RegisterCustomUdevRule(name, rule);
|
||||
#else
|
||||
(void)name;
|
||||
(void)rule;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Detector Registration Macros |
|
||||
\*---------------------------------------------------------*/
|
||||
@@ -500,3 +531,5 @@ public:
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_IPU(name, func, vid, pid, interface, page, usage) HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page##_##usage(name, func, vid, pid, interface, page, usage)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_P(name, func, vid, pid, page) HIDDeviceDetector device_detector_obj_##vid##pid##__##page(name, func, vid, pid, HID_INTERFACE_ANY, page, HID_USAGE_ANY)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_PU(name, func, vid, pid, page, usage) HIDDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage(name, func, vid, pid, HID_INTERFACE_ANY, page, usage)
|
||||
|
||||
#define REGISTER_CUSTOM_UDEV_RULE(id, name, rule) static CustomUdevRule device_detector_obj_##id(name, rule)
|
||||
Reference in new issue
Block a user